Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Resources export, serialisation & deserialisation #6492
Conversation
|
!!try!! |
|
!!build!! |
| @@ -45,6 +45,8 @@ type application struct { | ||
| // unit count will be assumed by the number of units associated. | ||
| Units_ units `yaml:"units"` | ||
| + Resources_ resources `yaml:"resources,omitempty"` |
| @@ -71,6 +77,7 @@ func minimalApplication(args ...ApplicationArgs) *application { | ||
| u.SetAgentStatus(minimalStatusArgs()) | ||
| u.SetWorkloadStatus(minimalStatusArgs()) | ||
| u.SetTools(minimalAgentToolsArgs()) | ||
| + s.setResources([]*resource{minimalResource()}) |
| + | ||
| +func (s *ApplicationSerializationSuite) TestResourcesAreValidated(c *gc.C) { | ||
| + application := minimalApplication() | ||
| + application.setResources([]*resource{ |
| + Name() string | ||
| + Revision() int | ||
| + CharmStoreRevision() int | ||
| + AddRevision(ResourceRevisionArgs) |
| + Revision() int | ||
| + CharmStoreRevision() int | ||
| + AddRevision(ResourceRevisionArgs) | ||
| + Revisions() map[int]ResourceRevision |
howbazaar
Oct 25, 2016
Owner
Does it need to be a map? If the ResourceRevision contains the Revision value itself, perhaps we just have a sorted sequence of ResourceRevision?
mjs
Oct 25, 2016
Contributor
They're stored and serialised as a sequence but it's more convenient to return them as a map. The Validate method ensures that each revision only appears once.
| + Path() string | ||
| + Description() string | ||
| + Origin() string | ||
| + FingerprintHex() string |
mjs
Oct 25, 2016
Contributor
I did this because on resource.Resource the fingerprint is stored as a raw []byte but here we convert it to a hex representation of that. The name is a reminder that a conversion has been performed.
| + Origin() string | ||
| + FingerprintHex() string | ||
| + Size() int64 | ||
| + AddTimestamp() time.Time |
| + Name_: args.Name, | ||
| + Revision_: args.Revision, | ||
| + CharmStoreRevision_: args.CharmStoreRevision, | ||
| + Revisions_: make([]*resourceRevision, 0), |
| + "username": schema.String(), | ||
| + } | ||
| + defaults := schema.Defaults{ | ||
| + "add-timestamp": time.Time{}, |
howbazaar
Oct 25, 2016
Owner
It would be easier to have schema.Omit for the timestamp, and then only set it below if it exists, rather than go through zero.
mjs
Oct 27, 2016
Contributor
Yep, that's slightly better. I'll make a helper and change all the other places in the package that have time pointers going via the zero value.
| + } | ||
| +} | ||
| + | ||
| +func minimalResourceMap() map[interface{}]interface{} { |
mjs
Oct 27, 2016
Contributor
Close enough :) One revision and one charm store revision is fairly small and exercises most of the functionality.
| coretesting "github.com/juju/juju/testing" | ||
| ) | ||
| var runFeatureTests = flag.Bool("featuretests", true, "Run long-running feature tests.") | ||
| func init() { | ||
| + // Required for anything requiring components (e.g. resources). | ||
| + if err := all.RegisterForServer(); err != nil { |
| @@ -81,6 +81,7 @@ func newResource(c *gc.C, name, username, data string) (resource.Resource, api.R | ||
| apiRes := api.Resource{ | ||
| CharmResource: api.CharmResource{ | ||
| Name: name, | ||
| + Description: name + " description", |
mjs
Oct 25, 2016
Contributor
I wanted the resources in tests to have a description so that I could see the description being handled. Predictably basing it off the name was an easy way to achieve that.
| for _, application := range applications { | ||
| applicationUnits := e.units[application.Name()] | ||
| leader := leaders[application.Name()] | ||
| + resources, err := resourcesSt.ListResources(application.Name()) |
howbazaar
Oct 25, 2016
Owner
Bah humbug. The only part of export where we do more than one query per collection.
mjs
Oct 25, 2016
Contributor
I might be able to avoid the extra lookups but it'll mean extending or going around the many levels of resources state API.
| @@ -5,8 +5,7 @@ package state_test | ||
| import ( | ||
| "fmt" | ||
| - "time" // Only used for time types. | ||
| - | ||
| + // Only used for time types. |
mjs
added some commits
Oct 18, 2016
| + | ||
| +import "time" | ||
| + | ||
| +func fieldToTimePtr(fields map[string]interface{}, name string) *time.Time { |
mjs
added some commits
Oct 27, 2016
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
|
Build failed: Tests failed |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
|
Build failed: Tests failed |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
mjs commentedOct 25, 2016
•
Edited 1 time
-
mjs
Oct 25, 2016
This pull request covers the export, serialisation and deserialisation of application resources.
Still to come:
QA
Visual inspection of
juju dump-modeloutput for a model with a charm which uses resources. More involved QA will be done once the above items have been handled.Also tested a standard migration to ensure there's no regressions.