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