github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/remotestate/state.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package remotestate 5 6 import ( 7 "gopkg.in/juju/charm.v6-unstable" 8 "gopkg.in/juju/names.v2" 9 10 "github.com/juju/juju/api/uniter" 11 "github.com/juju/juju/apiserver/params" 12 "github.com/juju/juju/watcher" 13 ) 14 15 type State interface { 16 Relation(names.RelationTag) (Relation, error) 17 StorageAttachment(names.StorageTag, names.UnitTag) (params.StorageAttachment, error) 18 StorageAttachmentLife([]params.StorageAttachmentId) ([]params.LifeResult, error) 19 Unit(names.UnitTag) (Unit, error) 20 WatchRelationUnits(names.RelationTag, names.UnitTag) (watcher.RelationUnitsWatcher, error) 21 WatchStorageAttachment(names.StorageTag, names.UnitTag) (watcher.NotifyWatcher, error) 22 } 23 24 type Unit interface { 25 Life() params.Life 26 Refresh() error 27 Resolved() (params.ResolvedMode, error) 28 Application() (Application, error) 29 Tag() names.UnitTag 30 Watch() (watcher.NotifyWatcher, error) 31 WatchAddresses() (watcher.NotifyWatcher, error) 32 WatchConfigSettings() (watcher.NotifyWatcher, error) 33 WatchStorage() (watcher.StringsWatcher, error) 34 WatchActionNotifications() (watcher.StringsWatcher, error) 35 } 36 37 type Application interface { 38 // CharmModifiedVersion returns a revision number for the charm that 39 // increments whenever the charm or a resource for the charm changes. 40 CharmModifiedVersion() (int, error) 41 // CharmURL returns the url for the charm for this service. 42 CharmURL() (*charm.URL, bool, error) 43 // Life returns whether the service is alive. 44 Life() params.Life 45 // Refresh syncs this value with the api server. 46 Refresh() error 47 // Tag returns the tag for this service. 48 Tag() names.ApplicationTag 49 // Watch returns a watcher that fires when this service changes. 50 Watch() (watcher.NotifyWatcher, error) 51 // WatchLeadershipSettings returns a watcher that fires when the leadership 52 // settings for this service change. 53 WatchLeadershipSettings() (watcher.NotifyWatcher, error) 54 // WatchRelation returns a watcher that fires when the relations on this 55 // service change. 56 WatchRelations() (watcher.StringsWatcher, error) 57 } 58 59 type Relation interface { 60 Id() int 61 Life() params.Life 62 } 63 64 func NewAPIState(st *uniter.State) State { 65 return apiState{st} 66 } 67 68 type apiState struct { 69 *uniter.State 70 } 71 72 type apiUnit struct { 73 *uniter.Unit 74 } 75 76 type apiService struct { 77 *uniter.Application 78 } 79 80 type apiRelation struct { 81 *uniter.Relation 82 } 83 84 func (st apiState) Relation(tag names.RelationTag) (Relation, error) { 85 r, err := st.State.Relation(tag) 86 return apiRelation{r}, err 87 } 88 89 func (st apiState) Unit(tag names.UnitTag) (Unit, error) { 90 u, err := st.State.Unit(tag) 91 return apiUnit{u}, err 92 } 93 94 func (u apiUnit) Application() (Application, error) { 95 s, err := u.Unit.Application() 96 return apiService{s}, err 97 }