~themue/pyjuju/go-state-auth

« back to all changes in this revision

Viewing changes to state/service.go

  • Committer: Frank Mueller
  • Date: 2011-12-20 10:52:07 UTC
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: frank.mueller@canonical.com-20111220105207-4trmfrtjxzqu3nq5
Initial adding of state for review.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// launchpad.net/juju/state
 
2
//
 
3
// Copyright (c) 2011 Canonical Ltd.
 
4
 
 
5
package state
 
6
 
 
7
// --------------------
 
8
// IMPORT
 
9
// --------------------
 
10
 
 
11
import (
 
12
        "fmt"
 
13
)
 
14
 
 
15
// --------------------
 
16
// SERVICE
 
17
// --------------------
 
18
 
 
19
// Service represents the state of one service and
 
20
// provides also the access to the subordinate parts.
 
21
type Service struct {
 
22
        topology *topology
 
23
        id       string
 
24
        name     string
 
25
}
 
26
 
 
27
func newService(t *topology, id, name string) *Service {
 
28
        return &Service{t, id, name}
 
29
}
 
30
 
 
31
// Id returns the service id.
 
32
func (s Service) Id() string {
 
33
        return s.id
 
34
}
 
35
 
 
36
// Name returns the service name.
 
37
func (s Service) Name() string {
 
38
        return s.name
 
39
}
 
40
 
 
41
// CharmId returns the charm id this service is supposed to use.
 
42
func (s Service) CharmId() string {
 
43
        cid, err := s.topology.getString(s.zookeeperPath() + "/charm")
 
44
 
 
45
        if err != nil {
 
46
                // TODO: Ouch! Error handling.
 
47
                panic("TODO: Error handling!")
 
48
        }
 
49
 
 
50
        return cid
 
51
}
 
52
 
 
53
// zookeeperPath returns the path within ZooKeeper.
 
54
func (s Service) zookeeperPath() string {
 
55
        return fmt.Sprintf("/services/%s", s.id)
 
56
}
 
57
 
 
58
// configPath returns the ZooKeeper path to the configuration.
 
59
func (s Service) configPath() string {
 
60
        return fmt.Sprintf("%s/config", s.zookeeperPath())
 
61
}
 
62
 
 
63
// exposedPath, if exists in ZooKeeper, indicates, that a
 
64
// service is exposed.
 
65
func (s Service) exposedPath() string {
 
66
        return fmt.Sprintf("/services/%s/exposed", s.id)
 
67
}
 
68
 
 
69
// EOF