Skip to content

Commit c6dd868

Browse files
committed
Add serialisation specifications to the multiwatcher structures.
Also add specific structures to mirror network.Port and network.PortRange and charm.Relation.
1 parent 6a1a316 commit c6dd868

File tree

11 files changed

+394
-316
lines changed

11 files changed

+394
-316
lines changed

api/controller/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (s *controllerSuite) TestWatchAllModels(c *gc.C) {
156156
c.Assert(modelInfo.Name, gc.Equals, env.Name())
157157
c.Assert(modelInfo.Life, gc.Equals, multiwatcher.Life("alive"))
158158
c.Assert(modelInfo.Owner, gc.Equals, env.Owner().Id())
159-
c.Assert(modelInfo.ServerUUID, gc.Equals, env.ControllerUUID())
159+
c.Assert(modelInfo.ControllerUUID, gc.Equals, env.ControllerUUID())
160160
case <-time.After(testing.LongWait):
161161
c.Fatal("timed out")
162162
}

api/uniter/relation.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ package uniter
66
import (
77
"fmt"
88

9+
"gopkg.in/juju/charm.v6-unstable"
910
"gopkg.in/juju/names.v2"
1011

1112
"github.com/juju/juju/apiserver/params"
13+
"github.com/juju/juju/state/multiwatcher"
1214
)
1315

1416
// This module implements a subset of the interface provided by
@@ -62,6 +64,17 @@ func (r *Relation) Refresh() error {
6264
return nil
6365
}
6466

67+
func (r *Relation) toCharmRelation(cr multiwatcher.CharmRelation) charm.Relation {
68+
return charm.Relation{
69+
Name: cr.Name,
70+
Role: charm.RelationRole(cr.Role),
71+
Interface: cr.Interface,
72+
Optional: cr.Optional,
73+
Limit: cr.Limit,
74+
Scope: charm.RelationScope(cr.Scope),
75+
}
76+
}
77+
6578
// Endpoint returns the endpoint of the relation for the application the
6679
// uniter's managed unit belongs to.
6780
func (r *Relation) Endpoint() (*Endpoint, error) {
@@ -72,7 +85,7 @@ func (r *Relation) Endpoint() (*Endpoint, error) {
7285
if err != nil {
7386
return nil, err
7487
}
75-
return &Endpoint{result.Endpoint.Relation}, nil
88+
return &Endpoint{r.toCharmRelation(result.Endpoint.Relation)}, nil
7689
}
7790

7891
// Unit returns a RelationUnit for the supplied unit.
@@ -87,7 +100,7 @@ func (r *Relation) Unit(u *Unit) (*RelationUnit, error) {
87100
return &RelationUnit{
88101
relation: r,
89102
unit: u,
90-
endpoint: Endpoint{result.Endpoint.Relation},
103+
endpoint: Endpoint{r.toCharmRelation(result.Endpoint.Relation)},
91104
st: r.st,
92105
}, nil
93106
}

apiserver/client/client_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,18 @@ func (s *clientSuite) TestClientWatchAll(c *gc.C) {
644644
c.Assert(len(deltas), gc.Equals, 1)
645645
d0, ok := deltas[0].Entity.(*multiwatcher.MachineInfo)
646646
c.Assert(ok, jc.IsTrue)
647-
d0.JujuStatus.Since = nil
648-
d0.MachineStatus.Since = nil
649-
if !c.Check(deltas, gc.DeepEquals, []multiwatcher.Delta{{
647+
d0.AgentStatus.Since = nil
648+
d0.InstanceStatus.Since = nil
649+
if !c.Check(deltas, jc.DeepEquals, []multiwatcher.Delta{{
650650
Entity: &multiwatcher.MachineInfo{
651651
ModelUUID: s.State.ModelUUID(),
652652
Id: m.Id(),
653653
InstanceId: "i-0",
654-
JujuStatus: multiwatcher.StatusInfo{
654+
AgentStatus: multiwatcher.StatusInfo{
655655
Current: status.StatusPending,
656-
Data: map[string]interface{}{},
657656
},
658-
MachineStatus: multiwatcher.StatusInfo{
657+
InstanceStatus: multiwatcher.StatusInfo{
659658
Current: status.StatusPending,
660-
Data: map[string]interface{}{},
661659
},
662660
Life: multiwatcher.Life("alive"),
663661
Series: "quantal",

apiserver/params/params_test.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ var marshalTestCases = []struct {
4343
ModelUUID: "uuid",
4444
Id: "Benji",
4545
InstanceId: "Shazam",
46-
JujuStatus: multiwatcher.StatusInfo{
46+
AgentStatus: multiwatcher.StatusInfo{
4747
Current: status.StatusError,
4848
Message: "foo",
4949
},
50-
MachineStatus: multiwatcher.StatusInfo{
50+
InstanceStatus: multiwatcher.StatusInfo{
5151
Current: status.StatusPending,
5252
},
5353
Life: multiwatcher.Life("alive"),
@@ -58,7 +58,7 @@ var marshalTestCases = []struct {
5858
HardwareCharacteristics: &instance.HardwareCharacteristics{},
5959
},
6060
},
61-
json: `["machine","change",{"ModelUUID":"uuid","Id":"Benji","InstanceId":"Shazam","JujuStatus":{"Err":null,"Current":"error","Message":"foo","Since":null,"Version":"","Data":null},"MachineStatus":{"Err":null,"Current":"pending","Message":"","Since":null,"Version":"","Data":null},"Life":"alive","Series":"trusty","SupportedContainers":["lxd"],"SupportedContainersKnown":false,"HardwareCharacteristics":{},"Jobs":["JobManageModel"],"Addresses":[],"HasVote":false,"WantsVote":false}]`,
61+
json: `["machine","change",{"model-uuid":"uuid","id":"Benji","instance-id":"Shazam","agent-status":{"current":"error","message":"foo","version":""},"instance-status":{"current":"pending","message":"","version":""},"life":"alive","series":"trusty","supported-containers":["lxd"],"supported-containers-known":false,"hardware-characteristics":{},"jobs":["JobManageModel"],"addresses":[],"has-vote":false,"wants-vote":false}]`,
6262
}, {
6363
about: "ApplicationInfo Delta",
6464
value: multiwatcher.Delta{
@@ -81,7 +81,7 @@ var marshalTestCases = []struct {
8181
},
8282
},
8383
},
84-
json: `["application","change",{"ModelUUID": "uuid", "CharmURL": "cs:quantal/name","Name":"Benji","Exposed":true,"Life":"dying","OwnerTag":"test-owner","MinUnits":42,"Constraints":{"arch":"armhf", "mem": 1024},"Config": {"hello":"goodbye","foo":false},"Subordinate":false,"Status":{"Current":"active", "Message":"all good", "Version": "", "Err": null, "Data": null, "Since": null}}]`,
84+
json: `["application","change",{"model-uuid": "uuid", "charm-url": "cs:quantal/name","name":"Benji","exposed":true,"life":"dying","owner-tag":"test-owner","min-units":42,"constraints":{"arch":"armhf", "mem": 1024},"config": {"hello":"goodbye","foo":false},"subordinate":false,"status":{"current":"active", "message":"all good", "version": ""}}]`,
8585
}, {
8686
about: "UnitInfo Delta",
8787
value: multiwatcher.Delta{
@@ -91,11 +91,11 @@ var marshalTestCases = []struct {
9191
Application: "Shazam",
9292
Series: "precise",
9393
CharmURL: "cs:~user/precise/wordpress-42",
94-
Ports: []network.Port{{
94+
Ports: []multiwatcher.Port{{
9595
Protocol: "http",
9696
Number: 80,
9797
}},
98-
PortRanges: []network.PortRange{{
98+
PortRanges: []multiwatcher.PortRange{{
9999
FromPort: 80,
100100
ToPort: 80,
101101
Protocol: "http",
@@ -107,12 +107,12 @@ var marshalTestCases = []struct {
107107
Current: status.StatusActive,
108108
Message: "all good",
109109
},
110-
JujuStatus: multiwatcher.StatusInfo{
110+
AgentStatus: multiwatcher.StatusInfo{
111111
Current: status.StatusIdle,
112112
},
113113
},
114114
},
115-
json: `["unit","change",{"ModelUUID":"uuid","Name":"Benji","Application":"Shazam","Series":"precise","CharmURL":"cs:~user/precise/wordpress-42","PublicAddress":"testing.invalid","PrivateAddress":"10.0.0.1","MachineId":"1","Ports":[{"Protocol":"http","Number":80}],"PortRanges":[{"FromPort":80,"ToPort":80,"Protocol":"http"}],"Subordinate":false,"WorkloadStatus":{"Err":null,"Current":"active","Message":"all good","Since":null,"Version":"","Data":null},"JujuStatus":{"Err":null,"Current":"idle","Message":"","Since":null,"Version":"","Data":null}}]`,
115+
json: `["unit","change",{"model-uuid":"uuid","name":"Benji","application":"Shazam","series":"precise","charm-url":"cs:~user/precise/wordpress-42","public-address":"testing.invalid","private-address":"10.0.0.1","machine-id":"1","ports":[{"protocol":"http","number":80}],"port-ranges":[{"from-port":80,"to-port":80,"protocol":"http"}],"subordinate":false,"workload-status":{"current":"active","message":"all good","version":""},"agent-status":{"current":"idle","message":"","version":""}}]`,
116116
}, {
117117
about: "RelationInfo Delta",
118118
value: multiwatcher.Delta{
@@ -121,11 +121,30 @@ var marshalTestCases = []struct {
121121
Key: "Benji",
122122
Id: 4711,
123123
Endpoints: []multiwatcher.Endpoint{
124-
{ApplicationName: "logging", Relation: charm.Relation{Name: "logging-directory", Role: "requirer", Interface: "logging", Optional: false, Limit: 1, Scope: "container"}},
125-
{ApplicationName: "wordpress", Relation: charm.Relation{Name: "logging-dir", Role: "provider", Interface: "logging", Optional: false, Limit: 0, Scope: "container"}}},
124+
{
125+
ApplicationName: "logging",
126+
Relation: multiwatcher.CharmRelation{
127+
Name: "logging-directory",
128+
Role: "requirer",
129+
Interface: "logging",
130+
Optional: false,
131+
Limit: 1,
132+
Scope: "container"},
133+
},
134+
{
135+
ApplicationName: "wordpress",
136+
Relation: multiwatcher.CharmRelation{
137+
Name: "logging-dir",
138+
Role: "provider",
139+
Interface: "logging",
140+
Optional: false,
141+
Limit: 0,
142+
Scope: "container"},
143+
},
144+
},
126145
},
127146
},
128-
json: `["relation","change",{"ModelUUID": "uuid", "Key":"Benji", "Id": 4711, "Endpoints": [{"ApplicationName":"logging", "Relation":{"Name":"logging-directory", "Role":"requirer", "Interface":"logging", "Optional":false, "Limit":1, "Scope":"container"}}, {"ApplicationName":"wordpress", "Relation":{"Name":"logging-dir", "Role":"provider", "Interface":"logging", "Optional":false, "Limit":0, "Scope":"container"}}]}]`,
147+
json: `["relation","change",{"model-uuid": "uuid", "key":"Benji", "id": 4711, "endpoints": [{"application-name":"logging", "relation":{"name":"logging-directory", "role":"requirer", "interface":"logging", "optional":false, "limit":1, "scope":"container"}}, {"application-name":"wordpress", "relation":{"name":"logging-dir", "role":"provider", "interface":"logging", "optional":false, "limit":0, "scope":"container"}}]}]`,
129148
}, {
130149
about: "AnnotationInfo Delta",
131150
value: multiwatcher.Delta{
@@ -138,7 +157,7 @@ var marshalTestCases = []struct {
138157
},
139158
},
140159
},
141-
json: `["annotation","change",{"ModelUUID": "uuid", "Tag":"machine-0","Annotations":{"foo":"bar","arble":"2 4"}}]`,
160+
json: `["annotation","change",{"model-uuid": "uuid", "tag":"machine-0","annotations":{"foo":"bar","arble":"2 4"}}]`,
142161
}, {
143162
about: "Delta Removed True",
144163
value: multiwatcher.Delta{
@@ -148,7 +167,7 @@ var marshalTestCases = []struct {
148167
Key: "Benji",
149168
},
150169
},
151-
json: `["relation","remove",{"ModelUUID": "uuid", "Key":"Benji", "Id": 0, "Endpoints": null}]`,
170+
json: `["relation","remove",{"model-uuid": "uuid", "key":"Benji", "id": 0, "endpoints": null}]`,
152171
}}
153172

154173
func (s *MarshalSuite) TestDeltaMarshalJSON(c *gc.C) {
@@ -175,7 +194,7 @@ func (s *MarshalSuite) TestDeltaUnmarshalJSON(c *gc.C) {
175194
var unmarshalled multiwatcher.Delta
176195
err := json.Unmarshal([]byte(t.json), &unmarshalled)
177196
c.Check(err, jc.ErrorIsNil)
178-
c.Check(unmarshalled, gc.DeepEquals, t.value)
197+
c.Check(unmarshalled, jc.DeepEquals, t.value)
179198
}
180199
}
181200

apiserver/uniter/uniter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ func (u *UniterAPIV3) prepareRelationResult(rel *state.Relation, unit *state.Uni
13171317
Life: params.Life(rel.Life().String()),
13181318
Endpoint: multiwatcher.Endpoint{
13191319
ApplicationName: ep.ApplicationName,
1320-
Relation: ep.Relation,
1320+
Relation: multiwatcher.NewCharmRelation(ep.Relation),
13211321
},
13221322
}, nil
13231323
}

apiserver/uniter/uniter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ func (s *uniterSuite) TestRelation(c *gc.C) {
14031403
Life: params.Life(rel.Life().String()),
14041404
Endpoint: multiwatcher.Endpoint{
14051405
ApplicationName: wpEp.ApplicationName,
1406-
Relation: wpEp.Relation,
1406+
Relation: multiwatcher.NewCharmRelation(wpEp.Relation),
14071407
},
14081408
},
14091409
{Error: apiservertesting.ErrUnauthorized},
@@ -1440,7 +1440,7 @@ func (s *uniterSuite) TestRelationById(c *gc.C) {
14401440
Life: params.Life(rel.Life().String()),
14411441
Endpoint: multiwatcher.Endpoint{
14421442
ApplicationName: wpEp.ApplicationName,
1443-
Relation: wpEp.Relation,
1443+
Relation: multiwatcher.NewCharmRelation(wpEp.Relation),
14441444
},
14451445
},
14461446
{Error: apiservertesting.ErrUnauthorized},

0 commit comments

Comments
 (0)