Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 package state | 1 package state |
2 | 2 |
3 import () | 3 import () |
4 | 4 |
5 // RelationRole defines the role of a relation endpoint. | 5 // RelationRole defines the role of a relation endpoint. |
6 type RelationRole string | 6 type RelationRole string |
7 | 7 |
8 const ( | 8 const ( |
9 » RoleNone RelationRole = "" | 9 » RoleProvider RelationRole = "provider" |
10 » RoleServer RelationRole = "server" | 10 » RoleRequirer RelationRole = "requirer" |
11 » RoleClient RelationRole = "client" | 11 » RolePeer RelationRole = "peer" |
12 » RolePeer RelationRole = "peer" | |
13 ) | 12 ) |
14 | 13 |
15 // RelationScope describes the scope of a relation endpoint. | 14 // RelationScope describes the scope of a relation endpoint. |
16 type RelationScope string | 15 type RelationScope string |
17 | 16 |
18 const ( | 17 const ( |
19 ScopeNone RelationScope = "" | |
20 ScopeGlobal RelationScope = "global" | 18 ScopeGlobal RelationScope = "global" |
21 ScopeContainer RelationScope = "container" | 19 ScopeContainer RelationScope = "container" |
22 ) | 20 ) |
23 | 21 |
24 // RelationEndpoint represents one endpoint of a relation. | 22 // RelationEndpoint represents one endpoint of a relation. |
25 type RelationEndpoint struct { | 23 type RelationEndpoint struct { |
26 » ServiceName string `yaml:"service-name"` | 24 » ServiceName string |
27 Interface string | 25 Interface string |
28 » RelationRole RelationRole `yaml:"relation-role"` | 26 » RelationName string |
29 » RelationScope RelationScope `yaml:"relation-scope"` | 27 » RelationRole RelationRole |
28 » RelationScope RelationScope | |
30 } | 29 } |
31 | 30 |
32 // CanRelateTo tests whether the "other"`" endpoint can be used in a common· | 31 // CanRelateTo returns whether a relation may be established between e and other . |
33 // relation. | |
34 //· | |
35 // RelationEndpoints can be related if they share the same interface | |
36 // and one is a 'server' while the other is a 'client'; or if both endpoints· | |
37 // have a role of 'peers'. | |
38 func (e *RelationEndpoint) CanRelateTo(other *RelationEndpoint) bool { | 32 func (e *RelationEndpoint) CanRelateTo(other *RelationEndpoint) bool { |
39 if e.Interface != other.Interface { | 33 if e.Interface != other.Interface { |
40 return false | 34 return false |
41 } | 35 } |
42 switch e.RelationRole { | 36 switch e.RelationRole { |
43 » case RoleServer: | 37 » case RoleProvider: |
44 » » return other.RelationRole == RoleClient | 38 » » return other.RelationRole == RoleRequirer |
45 » case RoleClient: | 39 » case RoleRequirer: |
46 » » return other.RelationRole == RoleServer | 40 » » return other.RelationRole == RoleProvider |
47 » case RolePeer: | |
48 » » return other.RelationRole == RolePeer | |
49 } | 41 } |
50 » panic("invalid endpoint role") | 42 » panic("endpoint role is undefined") |
51 } | 43 } |
52 | 44 |
53 // Relation represents a connection between one or more services. | 45 // String returns the unique identifier of the relation endpoint. |
46 func (e RelationEndpoint) String() string { | |
47 » return e.ServiceName + ":" + e.RelationName | |
48 } | |
49 | |
50 // Relation represents a link between services, or within a | |
51 // service (in the case of peer relations). | |
54 type Relation struct { | 52 type Relation struct { |
55 st *State | 53 st *State |
56 key string | 54 key string |
57 } | 55 } |
58 | 56 |
59 // Key returns the internal key of a relation. | 57 // ServiceRelation represents an established relation from |
60 func (r *Relation) Key() string { | 58 // the viewpoint of a participant service. |
niemeyer
2012/05/21 20:07:48
The internal key is internal. :-)
TheMue
2012/05/29 15:55:13
Done.
| |
61 » return r.key | 59 type ServiceRelation struct { |
60 » st *State | |
61 » relationKey string | |
62 » serviceKey string | |
63 » relationScope RelationScope | |
64 » relationRole RelationRole | |
65 » relationName string | |
62 } | 66 } |
63 | 67 |
64 // ServiceRelation represents a relation between one or more services. | 68 // RelationScope returns the scope of the relation. |
65 type ServiceRelation struct { | 69 func (r *ServiceRelation) RelationScope() RelationScope { |
66 » st *State | 70 » return r.relationScope |
67 » key string | |
68 » serviceKey string | |
69 » scope RelationScope | |
70 » role RelationRole | |
71 } | 71 } |
72 | 72 |
73 // Key returns the internal key of a relation. | 73 // RelationRole returns the service role within the relation. |
niemeyer
2012/05/21 20:07:48
Ditto.
TheMue
2012/05/29 15:55:13
Done.
| |
74 func (r *ServiceRelation) Key() string { | 74 func (r *ServiceRelation) RelationRole() RelationRole { |
75 » return r.key | 75 » return r.relationRole |
76 } | 76 } |
77 | 77 |
78 // ServiceKey returns the service key of a relation. | 78 // RelationName returns the name this relation has within the service. |
niemeyer
2012/05/21 20:07:48
Ditto.
TheMue
2012/05/29 15:55:13
Done.
| |
79 func (r *ServiceRelation) ServiceKey() string { | 79 func (r *ServiceRelation) RelationName() string { |
80 » return r.serviceKey | 80 » return r.relationName |
81 } | 81 } |
82 | |
83 // Scope returns the scope of a relation. | |
84 func (r *ServiceRelation) Scope() RelationScope { | |
85 return r.scope | |
86 } | |
87 | |
88 // Role returns the role of a relation. | |
89 func (r *ServiceRelation) Role() RelationRole { | |
90 return r.role | |
91 } | |
LEFT | RIGHT |