Skip to content

Commit

Permalink
Rename core/resource to core/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed May 26, 2022
1 parent b72909e commit 74448a9
Show file tree
Hide file tree
Showing 112 changed files with 774 additions and 779 deletions.
22 changes: 11 additions & 11 deletions api/agent/uniter/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/juju/juju/api/base"
api "github.com/juju/juju/api/client/resources"
apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/core/resource"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/rpc/params"
)

Expand Down Expand Up @@ -62,51 +62,51 @@ type ResourcesFacadeClient struct {
// GetResource opens the resource (metadata/blob), if it exists, via
// the HTTP API and returns it. If it does not exist or hasn't been
// uploaded yet then errors.NotFound is returned.
func (c *ResourcesFacadeClient) GetResource(resourceName string) (resource.Resource, io.ReadCloser, error) {
func (c *ResourcesFacadeClient) GetResource(resourceName string) (resources.Resource, io.ReadCloser, error) {
var response *http.Response
req, err := api.NewHTTPDownloadRequest(resourceName)
if err != nil {
return resource.Resource{}, nil, errors.Annotate(err, "failed to build API request")
return resources.Resource{}, nil, errors.Annotate(err, "failed to build API request")
}
if err := c.Do(c.ctx, req, &response); err != nil {
return resource.Resource{}, nil, errors.Annotate(err, "HTTP request failed")
return resources.Resource{}, nil, errors.Annotate(err, "HTTP request failed")
}

// HACK(katco): Combine this into one request?
resourceInfo, err := c.getResourceInfo(resourceName)
if err != nil {
return resource.Resource{}, nil, errors.Trace(err)
return resources.Resource{}, nil, errors.Trace(err)
}

// TODO(katco): Check headers against resource info
// TODO(katco): Check in on all the response headers
return resourceInfo, response.Body, nil
}

func (c *ResourcesFacadeClient) getResourceInfo(resourceName string) (resource.Resource, error) {
func (c *ResourcesFacadeClient) getResourceInfo(resourceName string) (resources.Resource, error) {
var response params.UnitResourcesResult

args := params.ListUnitResourcesArgs{
ResourceNames: []string{resourceName},
}
if err := c.FacadeCall("GetResourceInfo", &args, &response); err != nil {
return resource.Resource{}, errors.Annotate(err, "could not get resource info")
return resources.Resource{}, errors.Annotate(err, "could not get resource info")
}
if response.Error != nil {
err := apiservererrors.RestoreError(response.Error)
return resource.Resource{}, errors.Annotate(err, "request failed on server")
return resources.Resource{}, errors.Annotate(err, "request failed on server")
}

if len(response.Resources) != 1 {
return resource.Resource{}, errors.New("got bad response from API server")
return resources.Resource{}, errors.New("got bad response from API server")
}
if response.Resources[0].Error != nil {
err := apiservererrors.RestoreError(response.Error)
return resource.Resource{}, errors.Annotate(err, "request failed for resource")
return resources.Resource{}, errors.Annotate(err, "request failed for resource")
}
res, err := api.API2Resource(response.Resources[0].Resource)
if err != nil {
return resource.Resource{}, errors.Annotate(err, "got bad data from API server")
return resources.Resource{}, errors.Annotate(err, "got bad data from API server")
}
return res, nil
}
Expand Down
6 changes: 3 additions & 3 deletions api/agent/uniter/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/juju/juju/api/agent/uniter"
"github.com/juju/juju/api/base"
api "github.com/juju/juju/api/client/resources"
"github.com/juju/juju/core/resource"
resourcetesting "github.com/juju/juju/core/resource/testing"
"github.com/juju/juju/core/resources"
resourcetesting "github.com/juju/juju/core/resources/testing"
"github.com/juju/juju/rpc/params"
)

Expand Down Expand Up @@ -79,7 +79,7 @@ type stubAPI struct {
ReturnDo *http.Response
}

func (s *stubAPI) setResource(info resource.Resource, reader io.ReadCloser) {
func (s *stubAPI) setResource(info resources.Resource, reader io.ReadCloser) {
s.ReturnFacadeCall = params.UnitResourcesResult{
Resources: []params.UnitResourceResult{{
Resource: api.Resource2API(info),
Expand Down
16 changes: 8 additions & 8 deletions api/client/resources/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/juju/juju/api/base/mocks"
"github.com/juju/juju/api/client/resources"
"github.com/juju/juju/core/resource"
resourcetesting "github.com/juju/juju/core/resource/testing"
coreresources "github.com/juju/juju/core/resources"
resourcetesting "github.com/juju/juju/core/resources/testing"
"github.com/juju/juju/rpc/params"
)

Expand Down Expand Up @@ -45,19 +45,19 @@ func (s *BaseSuite) setUpMocks(c *gc.C) *gomock.Controller {
return ctrl
}

func newResourceResult(c *gc.C, names ...string) ([]resource.Resource, params.ResourcesResult) {
var resources []resource.Resource
func newResourceResult(c *gc.C, names ...string) ([]coreresources.Resource, params.ResourcesResult) {
var res []coreresources.Resource
var apiResult params.ResourcesResult
for _, name := range names {
data := name + "...spamspamspam"
res, apiRes := newResource(c, name, "a-user", data)
resources = append(resources, res)
newRes, apiRes := newResource(c, name, "a-user", data)
res = append(res, newRes)
apiResult.Resources = append(apiResult.Resources, apiRes)
}
return resources, apiResult
return res, apiResult
}

func newResource(c *gc.C, name, username, data string) (resource.Resource, params.Resource) {
func newResource(c *gc.C, name, username, data string) (coreresources.Resource, params.Resource) {
opened := resourcetesting.NewResource(c, nil, name, "a-application", data)
res := opened.Resource
res.Revision = 1
Expand Down
6 changes: 3 additions & 3 deletions api/client/resources/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/juju/juju/api/base"
apicharm "github.com/juju/juju/api/common/charm"
apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/core/resource"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/rpc/params"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func NewClient(apiCaller base.APICallCloser) (*Client, error) {

// ListResources calls the ListResources API server method with
// the given application names.
func (c Client) ListResources(applications []string) ([]resource.ApplicationResources, error) {
func (c Client) ListResources(applications []string) ([]resources.ApplicationResources, error) {
args, err := newListResourcesArgs(applications)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -64,7 +64,7 @@ func (c Client) ListResources(applications []string) ([]resource.ApplicationReso
}

var errs []error
results := make([]resource.ApplicationResources, len(applications))
results := make([]resources.ApplicationResources, len(applications))
for i := range applications {
apiResult := apiResults.Results[i]

Expand Down
6 changes: 3 additions & 3 deletions api/client/resources/client_listresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/core/resource"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/rpc/params"
)

Expand All @@ -36,7 +36,7 @@ func (s *ListResourcesSuite) TestListResources(c *gc.C) {

results, err := s.client.ListResources([]string{"a-application", "other-application"})
c.Assert(err, jc.ErrorIsNil)
c.Check(results, jc.DeepEquals, []resource.ApplicationResources{
c.Check(results, jc.DeepEquals, []resources.ApplicationResources{
{Resources: expected1},
{Resources: expected2},
})
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *ListResourcesSuite) TestEmptyResources(c *gc.C) {

results, err := s.client.ListResources([]string{"a-application", "other-application"})
c.Assert(err, jc.ErrorIsNil)
c.Check(results, jc.DeepEquals, []resource.ApplicationResources{{}, {}})
c.Check(results, jc.DeepEquals, []resources.ApplicationResources{{}, {}})
}

func (s *ListResourcesSuite) TestServerError(c *gc.C) {
Expand Down
34 changes: 17 additions & 17 deletions api/client/resources/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/juju/names/v4"

apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/core/resource"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/rpc/params"
)

// Resource2API converts a resource.Resource into
// a Resource struct.
func Resource2API(res resource.Resource) params.Resource {
func Resource2API(res resources.Resource) params.Resource {
return params.Resource{
CharmResource: CharmResource2API(res.Resource),
ID: res.ID,
Expand All @@ -26,14 +26,14 @@ func Resource2API(res resource.Resource) params.Resource {
}
}

// apiResult2ApplicationResources converts a ResourcesResult into a resource.ApplicationResources.
func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resource.ApplicationResources, error) {
var result resource.ApplicationResources
// apiResult2ApplicationResources converts a ResourcesResult into a resources.ApplicationResources.
func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resources.ApplicationResources, error) {
var result resources.ApplicationResources

if apiResult.Error != nil {
// TODO(ericsnow) Return the resources too?
err := apiservererrors.RestoreError(apiResult.Error)
return resource.ApplicationResources{}, errors.Trace(err)
return resources.ApplicationResources{}, errors.Trace(err)
}

for _, apiRes := range apiResult.Resources {
Expand All @@ -42,22 +42,22 @@ func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resource.
// This could happen if the server is misbehaving
// or non-conforming.
// TODO(ericsnow) Aggregate errors?
return resource.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
return resources.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
}
result.Resources = append(result.Resources, res)
}

for _, unitRes := range apiResult.UnitResources {
tag, err := names.ParseUnitTag(unitRes.Tag)
if err != nil {
return resource.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
return resources.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
}
resNames := map[string]bool{}
unitResources := resource.UnitResources{Tag: tag}
unitResources := resources.UnitResources{Tag: tag}
for _, apiRes := range unitRes.Resources {
res, err := API2Resource(apiRes)
if err != nil {
return resource.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
return resources.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
}
resNames[res.Name] = true
unitResources.Resources = append(unitResources.Resources, res)
Expand All @@ -67,7 +67,7 @@ func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resource.
for resName, progress := range unitRes.DownloadProgress {
if _, ok := resNames[resName]; !ok {
err := errors.Errorf("got progress from unrecognized resource %q", resName)
return resource.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
return resources.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
}
unitResources.DownloadProgress[resName] = progress
}
Expand All @@ -78,15 +78,15 @@ func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resource.
for _, chRes := range apiResult.CharmStoreResources {
res, err := API2CharmResource(chRes)
if err != nil {
return resource.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
return resources.ApplicationResources{}, errors.Annotate(err, "got bad data from server")
}
result.CharmStoreResources = append(result.CharmStoreResources, res)
}

return result, nil
}

func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params.ResourcesResult {
func ApplicationResources2APIResult(svcRes resources.ApplicationResources) params.ResourcesResult {
var result params.ResourcesResult
for _, res := range svcRes.Resources {
result.Resources = append(result.Resources, Resource2API(res))
Expand Down Expand Up @@ -118,15 +118,15 @@ func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params

// API2Resource converts an API Resource struct into
// a resource.Resource.
func API2Resource(apiRes params.Resource) (resource.Resource, error) {
var res resource.Resource
func API2Resource(apiRes params.Resource) (resources.Resource, error) {
var res resources.Resource

charmRes, err := API2CharmResource(apiRes.CharmResource)
if err != nil {
return res, errors.Trace(err)
}

res = resource.Resource{
res = resources.Resource{
Resource: charmRes,
ID: apiRes.ID,
PendingID: apiRes.PendingID,
Expand Down Expand Up @@ -172,7 +172,7 @@ func API2CharmResource(apiInfo params.CharmResource) (charmresource.Resource, er
return res, errors.Trace(err)
}

fp, err := resource.DeserializeFingerprint(apiInfo.Fingerprint)
fp, err := resources.DeserializeFingerprint(apiInfo.Fingerprint)
if err != nil {
return res, errors.Trace(err)
}
Expand Down
Loading

0 comments on commit 74448a9

Please sign in to comment.