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

« back to all changes in this revision

Viewing changes to worker/uniter/relation/relation.go

Merge trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
        "fmt"
7
7
        "io/ioutil"
8
8
        "launchpad.net/juju-core/charm/hooks"
9
 
        "launchpad.net/juju-core/trivial"
 
9
        "launchpad.net/juju-core/utils"
10
10
        "launchpad.net/juju-core/worker/uniter/hook"
11
11
        "os"
12
12
        "path/filepath"
48
48
// against the current state before they are run, to ensure that the system
49
49
// meets its guarantees about hook execution order.
50
50
func (s *State) Validate(hi hook.Info) (err error) {
51
 
        defer trivial.ErrorContextf(&err, "inappropriate %q for %q", hi.Kind, hi.RemoteUnit)
 
51
        defer utils.ErrorContextf(&err, "inappropriate %q for %q", hi.Kind, hi.RemoteUnit)
52
52
        if hi.RelationId != s.RelationId {
53
53
                return fmt.Errorf("expected relation %d, got relation %d", s.RelationId, hi.RelationId)
54
54
        }
100
100
                filepath.Join(dirPath, strconv.Itoa(relationId)),
101
101
                State{relationId, map[string]int64{}, ""},
102
102
        }
103
 
        defer trivial.ErrorContextf(&err, "cannot load relation state from %q", d.path)
 
103
        defer utils.ErrorContextf(&err, "cannot load relation state from %q", d.path)
104
104
        if _, err := os.Stat(d.path); os.IsNotExist(err) {
105
105
                return d, nil
106
106
        } else if err != nil {
125
125
                }
126
126
                unitName := svcName + "/" + unitId
127
127
                var info diskInfo
128
 
                if err = trivial.ReadYaml(filepath.Join(d.path, name), &info); err != nil {
 
128
                if err = utils.ReadYaml(filepath.Join(d.path, name), &info); err != nil {
129
129
                        return nil, fmt.Errorf("invalid unit file %q: %v", name, err)
130
130
                }
131
131
                if info.ChangeVersion == nil {
145
145
// ReadAllStateDirs loads and returns every StateDir persisted directly inside
146
146
// the supplied dirPath. If dirPath does not exist, no error is returned.
147
147
func ReadAllStateDirs(dirPath string) (dirs map[int]*StateDir, err error) {
148
 
        defer trivial.ErrorContextf(&err, "cannot load relations state from %q", dirPath)
 
148
        defer utils.ErrorContextf(&err, "cannot load relations state from %q", dirPath)
149
149
        if _, err := os.Stat(dirPath); os.IsNotExist(err) {
150
150
                return nil, nil
151
151
        } else if err != nil {
183
183
// Write doesn't validate hi but guarantees that successive writes of
184
184
// the same hi are idempotent.
185
185
func (d *StateDir) Write(hi hook.Info) (err error) {
186
 
        defer trivial.ErrorContextf(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.RemoteUnit)
 
186
        defer utils.ErrorContextf(&err, "failed to write %q hook info for %q on state directory", hi.Kind, hi.RemoteUnit)
187
187
        if hi.Kind == hooks.RelationBroken {
188
188
                return d.Remove()
189
189
        }
198
198
                return nil
199
199
        }
200
200
        di := diskInfo{&hi.ChangeVersion, hi.Kind == hooks.RelationJoined}
201
 
        if err := trivial.WriteYaml(path, &di); err != nil {
 
201
        if err := utils.WriteYaml(path, &di); err != nil {
202
202
                return err
203
203
        }
204
204
        // If write was successful, update own state.