launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/worker/uniter/hook/hook.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // hook provides types that define the hooks known to the Uniter 5 package hook 6 7 import ( 8 "launchpad.net/errgo/errors" 9 "launchpad.net/juju-core/charm/hooks" 10 ) 11 12 // Info holds details required to execute a hook. Not all fields are 13 // relevant to all Kind values. 14 type Info struct { 15 Kind hooks.Kind 16 17 // RelationId identifies the relation associated with the hook. It is 18 // only set when Kind indicates a relation hook. 19 RelationId int `yaml:"relation-id,omitempty"` 20 21 // RemoteUnit is the name of the unit that triggered the hook. It is only 22 // set when Kind inicates a relation hook other than relation-broken. 23 RemoteUnit string `yaml:"remote-unit,omitempty"` 24 25 // ChangeVersion identifies the most recent unit settings change 26 // associated with RemoteUnit. It is only set when RemoteUnit is set. 27 ChangeVersion int64 `yaml:"change-version,omitempty"` 28 } 29 30 // Validate returns an error if the info is not valid. 31 func (hi Info) Validate() error { 32 switch hi.Kind { 33 case hooks.RelationJoined, hooks.RelationChanged, hooks.RelationDeparted: 34 if hi.RemoteUnit == "" { 35 return errors.Newf("%q hook requires a remote unit", hi.Kind) 36 } 37 fallthrough 38 case hooks.Install, hooks.Start, hooks.ConfigChanged, hooks.UpgradeCharm, hooks.Stop, hooks.RelationBroken: 39 return nil 40 } 41 return errors.Newf("unknown hook kind %q", hi.Kind) 42 }