launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 "launchpad.net/juju-core/environs/config" 8 "launchpad.net/juju-core/instance" 9 "launchpad.net/juju-core/state/api/params" 10 "launchpad.net/juju-core/tools" 11 "launchpad.net/juju-core/version" 12 ) 13 14 // EntityFinder is implemented by *State. See State.FindEntity 15 // for documentation on the method. 16 type EntityFinder interface { 17 FindEntity(tag string) (Entity, error) 18 } 19 20 var _ EntityFinder = (*State)(nil) 21 22 // Entity represents any entity that can be returned 23 // by State.FindEntity. All entities have a tag. 24 type Entity interface { 25 Tag() string 26 } 27 28 var ( 29 _ Entity = (*Machine)(nil) 30 _ Entity = (*Unit)(nil) 31 _ Entity = (*Service)(nil) 32 _ Entity = (*Environment)(nil) 33 _ Entity = (*User)(nil) 34 ) 35 36 type StatusSetter interface { 37 SetStatus(status params.Status, info string, data params.StatusData) error 38 } 39 40 var ( 41 _ StatusSetter = (*Machine)(nil) 42 _ StatusSetter = (*Unit)(nil) 43 ) 44 45 // Lifer represents an entity with a life. 46 type Lifer interface { 47 Life() Life 48 } 49 50 var ( 51 _ Lifer = (*Machine)(nil) 52 _ Lifer = (*Unit)(nil) 53 _ Lifer = (*Service)(nil) 54 _ Lifer = (*Relation)(nil) 55 ) 56 57 // AgentTooler is implemented by entities 58 // that have associated agent tools. 59 type AgentTooler interface { 60 AgentTools() (*tools.Tools, error) 61 SetAgentVersion(version.Binary) error 62 } 63 64 // EnsureDeader with an EnsureDead method. 65 type EnsureDeader interface { 66 EnsureDead() error 67 } 68 69 var ( 70 _ EnsureDeader = (*Machine)(nil) 71 _ EnsureDeader = (*Unit)(nil) 72 ) 73 74 // Remover represents entities with a Remove method. 75 type Remover interface { 76 Remove() error 77 } 78 79 var ( 80 _ Remover = (*Machine)(nil) 81 _ Remover = (*Unit)(nil) 82 ) 83 84 // Authenticator represents entites capable of handling password 85 // authentication. 86 type Authenticator interface { 87 Refresh() error 88 SetPassword(pass string) error 89 PasswordValid(pass string) bool 90 } 91 92 var ( 93 _ Authenticator = (*Machine)(nil) 94 _ Authenticator = (*Unit)(nil) 95 _ Authenticator = (*User)(nil) 96 ) 97 98 // MongoPassworder represents an entity that can 99 // have a mongo password set for it. 100 type MongoPassworder interface { 101 SetMongoPassword(password string) error 102 } 103 104 var ( 105 _ MongoPassworder = (*Machine)(nil) 106 _ MongoPassworder = (*Unit)(nil) 107 ) 108 109 // Annotator represents entities capable of handling annotations. 110 type Annotator interface { 111 Annotation(key string) (string, error) 112 Annotations() (map[string]string, error) 113 SetAnnotations(pairs map[string]string) error 114 } 115 116 var ( 117 _ Annotator = (*Machine)(nil) 118 _ Annotator = (*Unit)(nil) 119 _ Annotator = (*Service)(nil) 120 _ Annotator = (*Environment)(nil) 121 ) 122 123 // NotifyWatcherFactory represents an entity that 124 // can be watched. 125 type NotifyWatcherFactory interface { 126 Watch() NotifyWatcher 127 } 128 129 var ( 130 _ NotifyWatcherFactory = (*Machine)(nil) 131 _ NotifyWatcherFactory = (*Unit)(nil) 132 _ NotifyWatcherFactory = (*Service)(nil) 133 _ NotifyWatcherFactory = (*Environment)(nil) 134 ) 135 136 // AgentEntity represents an entity that can 137 // have an agent responsible for it. 138 type AgentEntity interface { 139 Entity 140 Lifer 141 Authenticator 142 MongoPassworder 143 AgentTooler 144 StatusSetter 145 EnsureDeader 146 Remover 147 NotifyWatcherFactory 148 } 149 150 var ( 151 _ AgentEntity = (*Machine)(nil) 152 _ AgentEntity = (*Unit)(nil) 153 ) 154 155 // EnvironAccessor defines the methods needed to watch for environment 156 // config changes, and read the environment config. 157 type EnvironAccessor interface { 158 WatchForEnvironConfigChanges() NotifyWatcher 159 EnvironConfig() (*config.Config, error) 160 } 161 162 var _ EnvironAccessor = (*State)(nil) 163 164 // UnitsWatcher defines the methods needed to retrieve an entity (a 165 // machine or a service) and watch its units. 166 type UnitsWatcher interface { 167 Entity 168 WatchUnits() StringsWatcher 169 } 170 171 var _ UnitsWatcher = (*Machine)(nil) 172 var _ UnitsWatcher = (*Service)(nil) 173 174 // EnvironMachinesWatcher defines a single method - 175 // WatchEnvironMachines. 176 type EnvironMachinesWatcher interface { 177 WatchEnvironMachines() StringsWatcher 178 } 179 180 var _ EnvironMachinesWatcher = (*State)(nil) 181 182 // InstanceIdGetter defines a single method - InstanceId. 183 type InstanceIdGetter interface { 184 InstanceId() (instance.Id, error) 185 } 186 187 var _ InstanceIdGetter = (*Machine)(nil)