github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/state/interface.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package state 5 6 import ( 7 "github.com/juju/names" 8 9 "github.com/juju/juju/environs/config" 10 "github.com/juju/juju/instance" 11 "github.com/juju/juju/tools" 12 "github.com/juju/juju/version" 13 ) 14 15 // EntityFinder is implemented by *State. See State.FindEntity 16 // for documentation on the method. 17 type EntityFinder interface { 18 FindEntity(tag names.Tag) (Entity, error) 19 } 20 21 var _ EntityFinder = (*State)(nil) 22 23 // Entity represents any entity that can be returned 24 // by State.FindEntity. All entities have a tag. 25 type Entity interface { 26 Tag() names.Tag 27 } 28 29 var ( 30 _ Entity = (*Machine)(nil) 31 _ Entity = (*Unit)(nil) 32 _ Entity = (*Service)(nil) 33 _ Entity = (*Environment)(nil) 34 _ Entity = (*User)(nil) 35 _ Entity = (*Action)(nil) 36 ) 37 38 // Lifer represents an entity with a life. 39 type Lifer interface { 40 Life() Life 41 } 42 43 var ( 44 _ Lifer = (*Machine)(nil) 45 _ Lifer = (*Unit)(nil) 46 _ Lifer = (*Service)(nil) 47 _ Lifer = (*Relation)(nil) 48 ) 49 50 // AgentTooler is implemented by entities 51 // that have associated agent tools. 52 type AgentTooler interface { 53 AgentTools() (*tools.Tools, error) 54 SetAgentVersion(version.Binary) error 55 } 56 57 // EnsureDeader with an EnsureDead method. 58 type EnsureDeader interface { 59 EnsureDead() error 60 } 61 62 var ( 63 _ EnsureDeader = (*Machine)(nil) 64 _ EnsureDeader = (*Unit)(nil) 65 ) 66 67 // Remover represents entities with a Remove method. 68 type Remover interface { 69 Remove() error 70 } 71 72 var ( 73 _ Remover = (*Machine)(nil) 74 _ Remover = (*Unit)(nil) 75 ) 76 77 // Authenticator represents entites capable of handling password 78 // authentication. 79 type Authenticator interface { 80 Refresh() error 81 SetPassword(pass string) error 82 PasswordValid(pass string) bool 83 } 84 85 var ( 86 _ Authenticator = (*Machine)(nil) 87 _ Authenticator = (*Unit)(nil) 88 _ Authenticator = (*User)(nil) 89 ) 90 91 // NotifyWatcherFactory represents an entity that 92 // can be watched. 93 type NotifyWatcherFactory interface { 94 Watch() NotifyWatcher 95 } 96 97 var ( 98 _ NotifyWatcherFactory = (*Machine)(nil) 99 _ NotifyWatcherFactory = (*Unit)(nil) 100 _ NotifyWatcherFactory = (*Service)(nil) 101 _ NotifyWatcherFactory = (*Environment)(nil) 102 ) 103 104 // AgentEntity represents an entity that can 105 // have an agent responsible for it. 106 type AgentEntity interface { 107 Entity 108 Lifer 109 Authenticator 110 AgentTooler 111 StatusSetter 112 EnsureDeader 113 Remover 114 NotifyWatcherFactory 115 } 116 117 var ( 118 _ AgentEntity = (*Machine)(nil) 119 _ AgentEntity = (*Unit)(nil) 120 ) 121 122 // EnvironAccessor defines the methods needed to watch for environment 123 // config changes, and read the environment config. 124 type EnvironAccessor interface { 125 WatchForEnvironConfigChanges() NotifyWatcher 126 EnvironConfig() (*config.Config, error) 127 } 128 129 var _ EnvironAccessor = (*State)(nil) 130 131 // UnitsWatcher defines the methods needed to retrieve an entity (a 132 // machine or a service) and watch its units. 133 type UnitsWatcher interface { 134 Entity 135 WatchUnits() StringsWatcher 136 } 137 138 var _ UnitsWatcher = (*Machine)(nil) 139 var _ UnitsWatcher = (*Service)(nil) 140 141 // EnvironMachinesWatcher defines a single method - 142 // WatchEnvironMachines. 143 type EnvironMachinesWatcher interface { 144 WatchEnvironMachines() StringsWatcher 145 } 146 147 var _ EnvironMachinesWatcher = (*State)(nil) 148 149 // InstanceIdGetter defines a single method - InstanceId. 150 type InstanceIdGetter interface { 151 InstanceId() (instance.Id, error) 152 } 153 154 var _ InstanceIdGetter = (*Machine)(nil) 155 156 // ActionsWatcher defines the methods an entity exposes to watch Actions 157 // queued up for itself 158 type ActionsWatcher interface { 159 Entity 160 WatchActionNotifications() StringsWatcher 161 } 162 163 var ( 164 _ ActionsWatcher = (*Unit)(nil) 165 // TODO(jcw4): when we implement service level Actions 166 // _ ActionsWatcher = (*Service)(nil) 167 ) 168 169 // ActionReceiver describes Entities that can have Actions queued for 170 // them, and that can get ActionRelated information about those actions. 171 // TODO(jcw4) consider implementing separate Actor classes for this 172 // interface; for example UnitActor that implements this interface, and 173 // takes a Unit and performs all these actions. 174 type ActionReceiver interface { 175 Entity 176 177 // AddAction queues an action with the given name and payload for this 178 // ActionReceiver. 179 AddAction(name string, payload map[string]interface{}) (*Action, error) 180 181 // CancelAction removes a pending Action from the queue for this 182 // ActionReceiver and marks it as cancelled. 183 CancelAction(action *Action) (*Action, error) 184 185 // WatchActionNotifications returns a StringsWatcher that will notify 186 // on changes to the queued actions for this ActionReceiver. 187 WatchActionNotifications() StringsWatcher 188 189 // Actions returns the list of Actions queued and completed for this 190 // ActionReceiver. 191 Actions() ([]*Action, error) 192 193 // CompletedActions returns the list of Actions completed for this 194 // ActionReceiver. 195 CompletedActions() ([]*Action, error) 196 197 // PendingActions returns the list of Actions queued for this 198 // ActionReceiver. 199 PendingActions() ([]*Action, error) 200 201 // RunningActions returns the list of Actions currently running for 202 // this ActionReceiver. 203 RunningActions() ([]*Action, error) 204 } 205 206 var ( 207 _ ActionReceiver = (*Unit)(nil) 208 // TODO(jcw4) - use when Actions can be queued for Services. 209 //_ ActionReceiver = (*Service)(nil) 210 ) 211 212 // GlobalEntity specifies entity. 213 type GlobalEntity interface { 214 globalKey() string 215 Tag() names.Tag 216 } 217 218 var ( 219 _ GlobalEntity = (*Machine)(nil) 220 _ GlobalEntity = (*Unit)(nil) 221 _ GlobalEntity = (*Service)(nil) 222 _ GlobalEntity = (*Charm)(nil) 223 _ GlobalEntity = (*Environment)(nil) 224 )