~themue/juju-core/053-env-more-script-friendly

« back to all changes in this revision

Viewing changes to state/service.go

Merge trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        "launchpad.net/juju-core/charm"
11
11
        "launchpad.net/juju-core/constraints"
12
12
        "launchpad.net/juju-core/state/api/params"
13
 
        "launchpad.net/juju-core/trivial"
 
13
        "launchpad.net/juju-core/utils"
14
14
        "sort"
15
15
        "strconv"
16
16
)
63
63
        return "service-" + s.Name()
64
64
}
65
65
 
 
66
// serviceGlobalKey returns the global database key for the service
 
67
// with the given name.
 
68
func serviceGlobalKey(svcName string) string {
 
69
        return "s#" + svcName
 
70
}
 
71
 
66
72
// globalKey returns the global database key for the service.
67
73
func (s *Service) globalKey() string {
68
 
        return "s#" + s.doc.Name
 
74
        return serviceGlobalKey(s.doc.Name)
69
75
}
70
76
 
71
77
func serviceSettingsKey(serviceName string, curl *charm.URL) string {
89
95
// some point; if the service has no units, and no relation involving the
90
96
// service has any units in scope, they are all removed immediately.
91
97
func (s *Service) Destroy() (err error) {
92
 
        defer trivial.ErrorContextf(&err, "cannot destroy service %q", s)
 
98
        defer utils.ErrorContextf(&err, "cannot destroy service %q", s)
93
99
        defer func() {
94
100
                if err == nil {
95
101
                        // This is a white lie; the document might actually be removed.
527
533
                Principal: principalName,
528
534
        }
529
535
        sdoc := statusDoc{
530
 
                Status: string(params.UnitPending),
 
536
                Status: params.StatusPending,
531
537
        }
532
538
        ops := []txn.Op{
533
539
                {
569
575
 
570
576
// AddUnit adds a new principal unit to the service.
571
577
func (s *Service) AddUnit() (unit *Unit, err error) {
572
 
        defer trivial.ErrorContextf(&err, "cannot add unit to service %q", s)
 
578
        defer utils.ErrorContextf(&err, "cannot add unit to service %q", s)
573
579
        name, ops, err := s.addUnitOps("")
574
580
        if err != nil {
575
581
                return nil, err
670
676
 
671
677
// Relations returns a Relation for every relation the service is in.
672
678
func (s *Service) Relations() (relations []*Relation, err error) {
673
 
        defer trivial.ErrorContextf(&err, "can't get relations for service %q", s)
 
679
        defer utils.ErrorContextf(&err, "can't get relations for service %q", s)
674
680
        docs := []relationDoc{}
675
681
        err = s.st.relations.Find(D{{"endpoints.servicename", s.doc.Name}}).All(&docs)
676
682
        if err != nil {
777
783
        if s.doc.Subordinate {
778
784
                return ErrSubordinateConstraints
779
785
        }
780
 
        defer trivial.ErrorContextf(&err, "cannot set constraints")
 
786
        defer utils.ErrorContextf(&err, "cannot set constraints")
781
787
        if s.doc.Life != Alive {
782
788
                return errNotAlive
783
789
        }