github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/common/crossmodel/interface.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package crossmodel 5 6 import ( 7 "gopkg.in/juju/charm.v6" 8 "gopkg.in/juju/names.v2" 9 "gopkg.in/macaroon.v2-unstable" 10 11 "github.com/juju/juju/core/crossmodel" 12 "github.com/juju/juju/core/status" 13 "github.com/juju/juju/permission" 14 "github.com/juju/juju/state" 15 ) 16 17 type Backend interface { 18 // ModelUUID returns the model UUID for the model 19 // controlled by this state instance. 20 ModelUUID() string 21 22 // ModelTag the tag of the model on which we are operating. 23 ModelTag() names.ModelTag 24 25 // AllModelUUIDs returns the UUIDs of all models in the controller. 26 AllModelUUIDs() ([]string, error) 27 28 // ControllerTag the tag of the controller in which we are operating. 29 ControllerTag() names.ControllerTag 30 31 // KeyRelation returns the existing relation with the given key (which can 32 // be derived unambiguously from the relation's endpoints). 33 KeyRelation(string) (Relation, error) 34 35 // Application returns a local application by name. 36 Application(string) (Application, error) 37 38 // GetOfferAccess gets the access permission for the specified user on an offer. 39 GetOfferAccess(offerUUID string, user names.UserTag) (permission.Access, error) 40 41 // UserPermission returns the access permission for the passed subject and target. 42 UserPermission(subject names.UserTag, target names.Tag) (permission.Access, error) 43 44 // RemoteApplication returns a remote application by name. 45 RemoteApplication(string) (RemoteApplication, error) 46 47 // AddRelation adds a relation between the specified endpoints and returns the relation info. 48 AddRelation(...state.Endpoint) (Relation, error) 49 50 // EndpointsRelation returns the existing relation with the given endpoints. 51 EndpointsRelation(...state.Endpoint) (Relation, error) 52 53 // AddRemoteApplication creates a new remote application record, having the supplied relation endpoints, 54 // with the supplied name (which must be unique across all applications, local and remote). 55 AddRemoteApplication(state.AddRemoteApplicationParams) (RemoteApplication, error) 56 57 // GetRemoteEntity returns the tag of the entity associated with the given token. 58 GetRemoteEntity(string) (names.Tag, error) 59 60 // GetToken returns the token associated with the entity with the given tag. 61 GetToken(entity names.Tag) (string, error) 62 63 // ExportLocalEntity adds an entity to the remote entities collection, 64 // returning an opaque token that uniquely identifies the entity within 65 // the model. 66 ExportLocalEntity(names.Tag) (string, error) 67 68 // ImportRemoteEntity adds an entity to the remote entities collection 69 // with the specified opaque token. 70 ImportRemoteEntity(entity names.Tag, token string) error 71 72 // SaveIngressNetworks stores in state the ingress networks for the relation. 73 SaveIngressNetworks(relationKey string, cidrs []string) (state.RelationNetworks, error) 74 75 // Networks returns the networks for the specified relation. 76 IngressNetworks(relationKey string) (state.RelationNetworks, error) 77 78 // ApplicationOfferForUUID returns the application offer for the UUID. 79 ApplicationOfferForUUID(offerUUID string) (*crossmodel.ApplicationOffer, error) 80 81 // WatchStatus returns a watcher that notifies of changes to the status 82 // of the offer. 83 WatchOfferStatus(offerUUID string) (state.NotifyWatcher, error) 84 85 // FirewallRule returns the firewall rule for the specified service. 86 FirewallRule(service state.WellKnownServiceType) (*state.FirewallRule, error) 87 } 88 89 // Relation provides access a relation in global state. 90 type Relation interface { 91 status.StatusGetter 92 status.StatusSetter 93 // Destroy ensures that the relation will be removed at some point; if 94 // no units are currently in scope, it will be removed immediately. 95 Destroy() error 96 97 // Id returns the integer internal relation key. 98 Id() int 99 100 // Life returns the relation's current life state. 101 Life() state.Life 102 103 // Tag returns the relation's tag. 104 Tag() names.Tag 105 106 // RemoteUnit returns a RelationUnit for the remote application unit 107 // with the supplied ID. 108 RemoteUnit(unitId string) (RelationUnit, error) 109 110 // AllRemoteUnits returns all the RelationUnits for the remote 111 // application units for a given application. 112 AllRemoteUnits(appName string) ([]RelationUnit, error) 113 114 // Endpoints returns the endpoints that constitute the relation. 115 Endpoints() []state.Endpoint 116 117 // Endpoint returns the endpoint of the relation for the named application. 118 Endpoint(appName string) (state.Endpoint, error) 119 120 // Unit returns a RelationUnit for the unit with the supplied ID. 121 Unit(unitId string) (RelationUnit, error) 122 123 // WatchUnits returns a watcher that notifies of changes to the units of the 124 // specified application in the relation. 125 WatchUnits(applicationName string) (state.RelationUnitsWatcher, error) 126 127 // WatchLifeSuspendedStatus returns a watcher that notifies of changes to the life 128 // or suspended status of the relation. 129 WatchLifeSuspendedStatus() state.StringsWatcher 130 131 // Suspended returns the suspended status of the relation. 132 Suspended() bool 133 134 // SuspendedReason returns the reason why the relation is suspended. 135 SuspendedReason() string 136 137 // SetSuspended sets the suspended status of the relation. 138 SetSuspended(bool, string) error 139 } 140 141 // RelationUnit provides access to the settings of a single unit in a relation, 142 // and methods for modifying the unit's involvement in the relation. 143 type RelationUnit interface { 144 // EnterScope ensures that the unit has entered its scope in the 145 // relation. When the unit has already entered its scope, EnterScope 146 // will report success but make no changes to state. 147 EnterScope(settings map[string]interface{}) error 148 149 // InScope returns whether the relation unit has entered scope and 150 // not left it. 151 InScope() (bool, error) 152 153 // LeaveScope signals that the unit has left its scope in the relation. 154 // After the unit has left its relation scope, it is no longer a member 155 // of the relation; if the relation is dying when its last member unit 156 // leaves, it is removed immediately. It is not an error to leave a 157 // scope that the unit is not, or never was, a member of. 158 LeaveScope() error 159 160 // Settings returns the relation unit's settings within the relation. 161 Settings() (map[string]interface{}, error) 162 163 // ReplaceSettings replaces the relation unit's settings within the 164 // relation. 165 ReplaceSettings(map[string]interface{}) error 166 } 167 168 // Application represents the state of a application hosted in the local model. 169 type Application interface { 170 // Name is the name of the application. 171 Name() string 172 173 // Life returns the lifecycle state of the application. 174 Life() state.Life 175 176 // Endpoints returns the application's currently available relation endpoints. 177 Endpoints() ([]state.Endpoint, error) 178 179 // Charm returns the application's charm and whether units should upgrade to that 180 // charm even if they are in an error state. 181 Charm() (ch Charm, force bool, err error) 182 183 // CharmURL returns the application's charm URL, and whether units should upgrade 184 // to the charm with that URL even if they are in an error state. 185 CharmURL() (curl *charm.URL, force bool) 186 187 // EndpointBindings returns the mapping for each endpoint name and the space 188 // name it is bound to (or empty if unspecified). When no bindings are stored 189 // for the application, defaults are returned. 190 EndpointBindings() (map[string]string, error) 191 192 // Status returns the status of the application. 193 Status() (status.StatusInfo, error) 194 } 195 196 type Charm interface { 197 // Meta returns the metadata of the charm. 198 Meta() *charm.Meta 199 200 // StoragePath returns the storage path of the charm bundle. 201 StoragePath() string 202 } 203 204 // RemoteApplication represents the state of an application hosted in an external 205 // (remote) model. 206 type RemoteApplication interface { 207 // Destroy ensures that this remote application reference and all its relations 208 // will be removed at some point; if no relation involving the 209 // application has any units in scope, they are all removed immediately. 210 Destroy() error 211 212 // Name returns the name of the remote application. 213 Name() string 214 215 // Tag returns the remote applications's tag. 216 Tag() names.Tag 217 218 // URL returns the offer URL, at which the application is offered. 219 URL() (string, bool) 220 221 // OfferUUID returns the UUID of the offer. 222 OfferUUID() string 223 224 // SourceModel returns the tag of the model hosting the remote application. 225 SourceModel() names.ModelTag 226 227 // Macaroon returns the macaroon used for authentication. 228 Macaroon() (*macaroon.Macaroon, error) 229 230 // Status returns the status of the remote application. 231 Status() (status.StatusInfo, error) 232 233 // IsConsumerProxy returns whether application is created 234 // from a registration operation by a consuming model. 235 IsConsumerProxy() bool 236 237 // Life returns the lifecycle state of the application. 238 Life() state.Life 239 240 // SetStatus sets the status of the remote application. 241 SetStatus(info status.StatusInfo) error 242 }