LEFT | RIGHT |
(no file at all) | |
1 package state | 1 package state |
2 | 2 |
3 import () | 3 import ( |
| 4 » "fmt" |
| 5 ) |
4 | 6 |
5 // RelationRole defines the role of a relation endpoint. | 7 // RelationRole defines the role of a relation endpoint. |
6 type RelationRole string | 8 type RelationRole string |
7 | 9 |
8 const ( | 10 const ( |
9 RoleProvider RelationRole = "provider" | 11 RoleProvider RelationRole = "provider" |
10 RoleRequirer RelationRole = "requirer" | 12 RoleRequirer RelationRole = "requirer" |
11 RolePeer RelationRole = "peer" | 13 RolePeer RelationRole = "peer" |
12 ) | 14 ) |
13 | 15 |
(...skipping 26 matching lines...) Expand all Loading... |
40 return other.RelationRole == RoleProvider | 42 return other.RelationRole == RoleProvider |
41 } | 43 } |
42 panic("endpoint role is undefined") | 44 panic("endpoint role is undefined") |
43 } | 45 } |
44 | 46 |
45 // String returns the unique identifier of the relation endpoint. | 47 // String returns the unique identifier of the relation endpoint. |
46 func (e RelationEndpoint) String() string { | 48 func (e RelationEndpoint) String() string { |
47 return e.ServiceName + ":" + e.RelationName | 49 return e.ServiceName + ":" + e.RelationName |
48 } | 50 } |
49 | 51 |
| 52 // checkValues performs basic tests on the endpoint data without |
| 53 // checking the validity of identifiers. |
| 54 func (e *RelationEndpoint) checkValues() error { |
| 55 switch { |
| 56 case e.ServiceName == "": |
| 57 return fmt.Errorf("endpoint has empty service name") |
| 58 case e.Interface == "": |
| 59 return fmt.Errorf("endpoint has empty interface") |
| 60 case e.RelationName == "": |
| 61 return fmt.Errorf("endpoint has empty relation name") |
| 62 case e.RelationRole != RoleProvider && e.RelationRole != RoleRequirer &&
e.RelationRole != RolePeer: |
| 63 return fmt.Errorf("endpoint has invalid role: %q", e.RelationRol
e) |
| 64 case e.RelationScope != ScopeGlobal && e.RelationScope != ScopeContainer
: |
| 65 return fmt.Errorf("endpoint has invalid scope: %q", e.RelationSc
ope) |
| 66 } |
| 67 return nil |
| 68 } |
| 69 |
50 // Relation represents a link between services, or within a | 70 // Relation represents a link between services, or within a |
51 // service (in the case of peer relations). | 71 // service (in the case of peer relations). |
52 type Relation struct { | 72 type Relation struct { |
53 st *State | 73 st *State |
54 key string | 74 key string |
55 } | 75 } |
56 | 76 |
57 // ServiceRelation represents an established relation from | 77 // ServiceRelation represents an established relation from |
58 // the viewpoint of a participant service. | 78 // the viewpoint of a participant service. |
59 type ServiceRelation struct { | 79 type ServiceRelation struct { |
(...skipping 12 matching lines...) Expand all Loading... |
72 | 92 |
73 // RelationRole returns the service role within the relation.· | 93 // RelationRole returns the service role within the relation.· |
74 func (r *ServiceRelation) RelationRole() RelationRole { | 94 func (r *ServiceRelation) RelationRole() RelationRole { |
75 return r.relationRole | 95 return r.relationRole |
76 } | 96 } |
77 | 97 |
78 // RelationName returns the name this relation has within the service. | 98 // RelationName returns the name this relation has within the service. |
79 func (r *ServiceRelation) RelationName() string { | 99 func (r *ServiceRelation) RelationName() string { |
80 return r.relationName | 100 return r.relationName |
81 } | 101 } |
LEFT | RIGHT |