github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 "time" 8 9 "github.com/juju/names" 10 "github.com/juju/version" 11 12 "github.com/juju/juju/environs/config" 13 "github.com/juju/juju/instance" 14 "github.com/juju/juju/status" 15 "github.com/juju/juju/tools" 16 ) 17 18 // EntityFinder is implemented by *State. See State.FindEntity 19 // for documentation on the method. 20 type EntityFinder interface { 21 FindEntity(tag names.Tag) (Entity, error) 22 } 23 24 // Entity represents any entity that can be returned 25 // by State.FindEntity. All entities have a tag. 26 type Entity interface { 27 Tag() names.Tag 28 } 29 30 // EntityWithService is implemented by Units it is intended 31 // for anything that can return its Service. 32 type EntityWithService interface { 33 Service() (*Service, error) 34 } 35 36 // Lifer represents an entity with a life. 37 type Lifer interface { 38 Life() Life 39 } 40 41 // LifeBinder represents an entity whose lifespan is bindable 42 // to that of another entity. 43 type LifeBinder interface { 44 Lifer 45 46 // LifeBinding either returns the tag of an entity to which this 47 // entity's lifespan is bound; the result may be nil, indicating 48 // that the entity's lifespan is not bound to anything. 49 // 50 // The types of tags that may be returned are depdendent on the 51 // entity type. For example, a Volume may be bound to a Filesystem, 52 // but a Filesystem may not be bound to a Filesystem. 53 LifeBinding() names.Tag 54 } 55 56 // AgentTooler is implemented by entities 57 // that have associated agent tools. 58 type AgentTooler interface { 59 AgentTools() (*tools.Tools, error) 60 SetAgentVersion(version.Binary) error 61 } 62 63 // EnsureDeader with an EnsureDead method. 64 type EnsureDeader interface { 65 EnsureDead() error 66 } 67 68 // Remover represents entities with a Remove method. 69 type Remover interface { 70 Remove() error 71 } 72 73 // Authenticator represents entites capable of handling password 74 // authentication. 75 type Authenticator interface { 76 Refresh() error 77 SetPassword(pass string) error 78 PasswordValid(pass string) bool 79 } 80 81 // NotifyWatcherFactory represents an entity that 82 // can be watched. 83 type NotifyWatcherFactory interface { 84 Watch() NotifyWatcher 85 } 86 87 // AgentEntity represents an entity that can 88 // have an agent responsible for it. 89 type AgentEntity interface { 90 Entity 91 Lifer 92 Authenticator 93 AgentTooler 94 status.StatusSetter 95 EnsureDeader 96 Remover 97 NotifyWatcherFactory 98 } 99 100 // ModelAccessor defines the methods needed to watch for model 101 // config changes, and read the model config. 102 type ModelAccessor interface { 103 WatchForModelConfigChanges() NotifyWatcher 104 ModelConfig() (*config.Config, error) 105 } 106 107 // UnitsWatcher defines the methods needed to retrieve an entity (a 108 // machine or a service) and watch its units. 109 type UnitsWatcher interface { 110 Entity 111 WatchUnits() StringsWatcher 112 } 113 114 // ModelMachinesWatcher defines a single method - 115 // WatchModelMachines. 116 type ModelMachinesWatcher interface { 117 WatchModelMachines() StringsWatcher 118 } 119 120 // InstanceIdGetter defines a single method - InstanceId. 121 type InstanceIdGetter interface { 122 InstanceId() (instance.Id, error) 123 } 124 125 // ActionsWatcher defines the methods an entity exposes to watch Actions 126 // queued up for itself 127 type ActionsWatcher interface { 128 Entity 129 WatchActionNotifications() StringsWatcher 130 } 131 132 // ActionReceiver describes Entities that can have Actions queued for 133 // them, and that can get ActionRelated information about those actions. 134 // TODO(jcw4) consider implementing separate Actor classes for this 135 // interface; for example UnitActor that implements this interface, and 136 // takes a Unit and performs all these actions. 137 type ActionReceiver interface { 138 Entity 139 140 // AddAction queues an action with the given name and payload for this 141 // ActionReceiver. 142 AddAction(name string, payload map[string]interface{}) (Action, error) 143 144 // CancelAction removes a pending Action from the queue for this 145 // ActionReceiver and marks it as cancelled. 146 CancelAction(action Action) (Action, error) 147 148 // WatchActionNotifications returns a StringsWatcher that will notify 149 // on changes to the queued actions for this ActionReceiver. 150 WatchActionNotifications() StringsWatcher 151 152 // Actions returns the list of Actions queued and completed for this 153 // ActionReceiver. 154 Actions() ([]Action, error) 155 156 // CompletedActions returns the list of Actions completed for this 157 // ActionReceiver. 158 CompletedActions() ([]Action, error) 159 160 // PendingActions returns the list of Actions queued for this 161 // ActionReceiver. 162 PendingActions() ([]Action, error) 163 164 // RunningActions returns the list of Actions currently running for 165 // this ActionReceiver. 166 RunningActions() ([]Action, error) 167 } 168 169 // GlobalEntity specifies entity. 170 type GlobalEntity interface { 171 globalKey() string 172 Tag() names.Tag 173 } 174 175 // Action represents an instance of an action designated for a unit or machine 176 // in the model. 177 type Action interface { 178 Entity 179 180 // Id returns the local id of the Action. 181 Id() string 182 183 // Receiver returns the Name of the ActionReceiver for which this action 184 // is enqueued. Usually this is a Unit Name(). 185 Receiver() string 186 187 // Name returns the name of the action, as defined in the charm. 188 Name() string 189 190 // Parameters will contain a structure representing arguments or parameters to 191 // an action, and is expected to be validated by the Unit using the Charm 192 // definition of the Action. 193 Parameters() map[string]interface{} 194 195 // Enqueued returns the time the action was added to state as a pending 196 // Action. 197 Enqueued() time.Time 198 199 // Started returns the time that the Action execution began. 200 Started() time.Time 201 202 // Completed returns the completion time of the Action. 203 Completed() time.Time 204 205 // Status returns the final state of the action. 206 Status() ActionStatus 207 208 // Results returns the structured output of the action and any error. 209 Results() (map[string]interface{}, string) 210 211 // ActionTag returns an ActionTag constructed from this action's 212 // Prefix and Sequence. 213 ActionTag() names.ActionTag 214 215 // Begin marks an action as running, and logs the time it was started. 216 // It asserts that the action is currently pending. 217 Begin() (Action, error) 218 219 // Finish removes action from the pending queue and captures the output 220 // and end state of the action. 221 Finish(results ActionResults) (Action, error) 222 }