sla, meter-status: Added sla and meter status to model description #5

Merged
merged 2 commits into from Mar 22, 2017

Conversation

Projects
None yet
3 participants
Member

mattyw commented Mar 20, 2017

This pr adds SLAs and MeterStatus to the model description. This supports the ability to perform model migrations on models with an SLA and meter status

interfaces.go
+type SLA interface {
+ // Level returns the level of the sla.
+ Level() string
+ // Level returns the credentials of the sla.
@cmars

cmars Mar 20, 2017

Owner

// Credentials

Normally you would need to bump the version number of the wire format for the model, but since it has already been bumped from 1 to 2 for the 2.2 release, I think we can skip this for now. However, you do need to add the parsing code, and tests.

interfaces.go
@@ -424,3 +424,19 @@ type StorageConstraint interface {
// Count is the required number of storage instances.
Count() uint64
}
+
+// SLA represents the sla for the model.
@howbazaar

howbazaar Mar 20, 2017

Owner

We have been moving interfaces out of the generic file and into the files that implement them. Please move the SLA interface into sla.go

model.go
@@ -89,6 +89,12 @@ type Model interface {
AddRemoteApplication(RemoteApplicationArgs) RemoteApplication
Validate() error
+
+ SetSLA(level string, credentials []byte)
@howbazaar

howbazaar Mar 20, 2017

Owner

All of the other set methods also return the new thing set. So SetSLA should return the SLA, and SetMeterStatus should return the MeterStatus

model.go
@@ -1225,6 +1284,8 @@ func importModelV1(source map[string]interface{}) (*model, error) {
func importModelV2(source map[string]interface{}) (*model, error) {
fields, defaults := modelV1Fields()
fields["remote-applications"] = schema.StringMap(schema.Any())
+ fields["sla"] = schema.StringMap(schema.Any())
@howbazaar

howbazaar Mar 22, 2017

Owner

Since we are tying the sla and meter-status formats to the model version, this schema should be fully explicit, not Any.

fields["sla"] = schema.FieldMap(
    schema.Fields{
        "level": schema.String(),
        "credentials":schema.String(),
    }, nil) // no defaults

And similarly for the meter-status.

Since you have not versioned the individual SLA and MeterStatus formats, keep the serialization close to the model code, not in a separate file.

Then your constructor funcs can assume a valid map.

func importSLA(source map[string]interface{}) sla {
	return sla{
		Level_:       source["level"].(string),
		Credentials_: source["credentials"].(string),
	}
}
model_test.go
+ c.Assert(model.MeterStatus().Info(), gc.Equals, "info message")
+}
+
+func (*ModelSerializationSuite) TestSLASerializes(c *gc.C) {
@howbazaar

howbazaar Mar 22, 2017

Owner

You don't need this test or the following one if you have the tests above using yaml.Marshal and Deserialize.

@howbazaar howbazaar merged commit 76acbf1 into juju:master Mar 22, 2017

jujubot added a commit to juju/juju that referenced this pull request Mar 23, 2017

Merge pull request #7128 from mattyw/55-model-migration
state: Model migration for sla and meter status

Also depends on juju/description#5

## Description of change

Adds model migration for slas and meter status.
## QA steps

```
juju bootstrap
juju sla essential
# Do model migration
juju sla
essential
```
## Documentation changes

The SLA feature needs documenting. The model migration support is part of that feature, however it should be invisible to the user
## Bug reference

n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment