| OLD | NEW |
| 1 // launchpad.net/juju/state | 1 // launchpad.net/juju/state |
| 2 // | 2 // |
| 3 // Copyright (c) 2011-2012 Canonical Ltd. | 3 // Copyright (c) 2011-2012 Canonical Ltd. |
| 4 | 4 |
| 5 package state | 5 package state |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "launchpad.net/goyaml" | 10 "launchpad.net/goyaml" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 units = append(units, &Unit{ | 213 units = append(units, &Unit{ |
| 214 st: s.st, | 214 st: s.st, |
| 215 key: key, | 215 key: key, |
| 216 serviceName: s.name, | 216 serviceName: s.name, |
| 217 isPrincipal: tunit.isPrincipal(), | 217 isPrincipal: tunit.isPrincipal(), |
| 218 }) | 218 }) |
| 219 } | 219 } |
| 220 return units, nil | 220 return units, nil |
| 221 } | 221 } |
| 222 | 222 |
| 223 // Relations returns a ServiceRelation for every relation the service is in. | 223 // RelatedServices returns all services currently related to this service. |
| 224 func (s *Service) Relations() (serviceRelation []*ServiceRelation, err error) { | 224 func (s *Service) RelatedServices() (services []*RelatedService, err error) { |
| 225 defer errorContextf(&err, "can't get relations for service %q", s.name) | 225 defer errorContextf(&err, "can't get relations for service %q", s.name) |
| 226 t, err := readTopology(s.st.zk) | 226 t, err := readTopology(s.st.zk) |
| 227 if err != nil { | 227 if err != nil { |
| 228 » » return nil, err | 228 » » return |
| 229 } | 229 } |
| 230 relations, err := t.RelationsForService(s.key) | 230 relations, err := t.RelationsForService(s.key) |
| 231 if err != nil { | 231 if err != nil { |
| 232 » » return nil, err | 232 » » return |
| 233 } | 233 } |
| 234 serviceRelations := []*ServiceRelation{} | |
| 235 for key, relation := range relations { | 234 for key, relation := range relations { |
| 236 rs := relation.Services[s.key] | 235 rs := relation.Services[s.key] |
| 237 » » serviceRelations = append(serviceRelations, &ServiceRelation{ | 236 » » services = append(services, &RelatedService{ |
| 238 st: s.st, serviceKey: s.key, relationKey: key, | 237 st: s.st, serviceKey: s.key, relationKey: key, |
| 239 » » » relationName: rs.Name, scope: relation.Scope, role: rs.R
ole, | 238 » » » relationName: rs.Name, scope: relation.Scope, |
| 239 » » » role: rs.Role.RelatedRole(), |
| 240 }) | 240 }) |
| 241 } | 241 } |
| 242 » return serviceRelations, nil | 242 » return |
| 243 } | 243 } |
| 244 | 244 |
| 245 // IsExposed returns whether this service is exposed. | 245 // IsExposed returns whether this service is exposed. |
| 246 // The explicitly open ports (with open-port) for exposed | 246 // The explicitly open ports (with open-port) for exposed |
| 247 // services may be accessed from machines outside of the | 247 // services may be accessed from machines outside of the |
| 248 // local deployment network. See SetExposed and ClearExposed. | 248 // local deployment network. See SetExposed and ClearExposed. |
| 249 func (s *Service) IsExposed() (bool, error) { | 249 func (s *Service) IsExposed() (bool, error) { |
| 250 stat, err := s.st.zk.Exists(s.zkExposedPath()) | 250 stat, err := s.st.zk.Exists(s.zkExposedPath()) |
| 251 if err != nil { | 251 if err != nil { |
| 252 return false, err | 252 return false, err |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // zkConfigPath returns the ZooKeeper path for the service configuration. | 293 // zkConfigPath returns the ZooKeeper path for the service configuration. |
| 294 func (s *Service) zkConfigPath() string { | 294 func (s *Service) zkConfigPath() string { |
| 295 return s.zkPath() + "/config" | 295 return s.zkPath() + "/config" |
| 296 } | 296 } |
| 297 | 297 |
| 298 // zkExposedPath, if exists in ZooKeeper, indicates, that a | 298 // zkExposedPath, if exists in ZooKeeper, indicates, that a |
| 299 // service is exposed. | 299 // service is exposed. |
| 300 func (s *Service) zkExposedPath() string { | 300 func (s *Service) zkExposedPath() string { |
| 301 return s.zkPath() + "/exposed" | 301 return s.zkPath() + "/exposed" |
| 302 } | 302 } |
| OLD | NEW |