github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/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 "time" 8 9 "github.com/juju/charm/v12" 10 "github.com/juju/names/v5" 11 "gopkg.in/macaroon.v2" 12 13 "github.com/juju/juju/core/crossmodel" 14 "github.com/juju/juju/core/network" 15 "github.com/juju/juju/core/permission" 16 coresecrets "github.com/juju/juju/core/secrets" 17 "github.com/juju/juju/core/status" 18 "github.com/juju/juju/environs/config" 19 "github.com/juju/juju/state" 20 ) 21 22 type Backend interface { 23 // ModelUUID returns the model UUID for the model 24 // controlled by this state instance. 25 ModelUUID() string 26 27 // ModelTag the tag of the model on which we are operating. 28 ModelTag() names.ModelTag 29 30 // ModelConfig returns the complete config for the model 31 ModelConfig() (*config.Config, error) 32 33 // AllModelUUIDs returns the UUIDs of all models in the controller. 34 AllModelUUIDs() ([]string, error) 35 36 // ControllerTag the tag of the controller in which we are operating. 37 ControllerTag() names.ControllerTag 38 39 // KeyRelation returns the existing relation with the given key (which can 40 // be derived unambiguously from the relation's endpoints). 41 KeyRelation(string) (Relation, error) 42 43 // Application returns a local application by name. 44 Application(string) (Application, error) 45 46 // GetOfferAccess gets the access permission for the specified user on an offer. 47 GetOfferAccess(offerUUID string, user names.UserTag) (permission.Access, error) 48 49 // UserPermission returns the access permission for the passed subject and target. 50 UserPermission(subject names.UserTag, target names.Tag) (permission.Access, error) 51 52 // RemoteApplication returns a remote application by name. 53 RemoteApplication(string) (RemoteApplication, error) 54 55 // AddRelation adds a relation between the specified endpoints and returns the relation info. 56 AddRelation(...state.Endpoint) (Relation, error) 57 58 // EndpointsRelation returns the existing relation with the given endpoints. 59 EndpointsRelation(...state.Endpoint) (Relation, error) 60 61 // OfferConnectionForRelation get the offer connection for a cross model relation. 62 OfferConnectionForRelation(string) (OfferConnection, error) 63 64 // AddRemoteApplication creates a new remote application record, having the supplied relation endpoints, 65 // with the supplied name (which must be unique across all applications, local and remote). 66 AddRemoteApplication(state.AddRemoteApplicationParams) (RemoteApplication, error) 67 68 // OfferUUIDForRelation gets the uuid of the offer for the 69 // specified cross-model relation key. 70 OfferUUIDForRelation(string) (string, error) 71 72 // GetRemoteEntity returns the tag of the entity associated with the given token. 73 GetRemoteEntity(string) (names.Tag, error) 74 75 // GetToken returns the token associated with the entity with the given tag. 76 GetToken(entity names.Tag) (string, error) 77 78 // ExportLocalEntity adds an entity to the remote entities collection, 79 // returning an opaque token that uniquely identifies the entity within 80 // the model. 81 ExportLocalEntity(names.Tag) (string, error) 82 83 // ImportRemoteEntity adds an entity to the remote entities collection 84 // with the specified opaque token. 85 ImportRemoteEntity(entity names.Tag, token string) error 86 87 // SaveIngressNetworks stores in state the ingress networks for the relation. 88 SaveIngressNetworks(relationKey string, cidrs []string) (state.RelationNetworks, error) 89 90 // IngressNetworks returns the networks for the specified relation. 91 IngressNetworks(relationKey string) (state.RelationNetworks, error) 92 93 // ApplicationOfferForUUID returns the application offer for the UUID. 94 ApplicationOfferForUUID(offerUUID string) (*crossmodel.ApplicationOffer, error) 95 96 // WatchOfferStatus returns a watcher that notifies of changes to the status 97 // of the offer. 98 WatchOfferStatus(offerUUID string) (state.NotifyWatcher, error) 99 100 // WatchOffer returns a watcher that notifies of changes to the 101 // lifecycle of the offer. 102 WatchOffer(offerName string) state.NotifyWatcher 103 104 // ApplyOperation applies a model operation to the state. 105 ApplyOperation(op state.ModelOperation) error 106 107 // RemoveSecretConsumer removes secret references for the specified consumer. 108 RemoveSecretConsumer(consumer names.Tag) error 109 110 // UpdateSecretConsumerOperation returns an operation for updating the latest revision 111 // for any consumers of the secret. 112 UpdateSecretConsumerOperation(uri *coresecrets.URI, latestRevision int) (state.ModelOperation, error) 113 } 114 115 // OfferConnection provides access to an offer connection in state. 116 type OfferConnection interface { 117 UserName() string 118 OfferUUID() string 119 } 120 121 // Relation provides access a relation in global state. 122 type Relation interface { 123 status.StatusGetter 124 status.StatusSetter 125 // Destroy ensures that the relation will be removed at some point; if 126 // no units are currently in scope, it will be removed immediately. 127 Destroy() error 128 129 // DestroyWithForce may force the destruction of the relation. 130 // In addition, this function also returns all non-fatal operational errors 131 // encountered. 132 DestroyWithForce(force bool, maxWait time.Duration) ([]error, error) 133 134 // Id returns the integer internal relation key. 135 Id() int 136 137 // Life returns the relation's current life state. 138 Life() state.Life 139 140 // Tag returns the relation's tag. 141 Tag() names.Tag 142 143 // UnitCount is the number of units still in relation scope. 144 UnitCount() int 145 146 // RemoteUnit returns a RelationUnit for the remote application unit 147 // with the supplied ID. 148 RemoteUnit(unitId string) (RelationUnit, error) 149 150 // AllRemoteUnits returns all the RelationUnits for the remote 151 // application units for a given application. 152 AllRemoteUnits(appName string) ([]RelationUnit, error) 153 154 // Endpoints returns the endpoints that constitute the relation. 155 Endpoints() []state.Endpoint 156 157 // Endpoint returns the endpoint of the relation for the named application. 158 Endpoint(appName string) (state.Endpoint, error) 159 160 // Unit returns a RelationUnit for the unit with the supplied ID. 161 Unit(unitId string) (RelationUnit, error) 162 163 // WatchUnits returns a watcher that notifies of changes to the units of the 164 // specified application in the relation. 165 WatchUnits(applicationName string) (state.RelationUnitsWatcher, error) 166 167 // WatchLifeSuspendedStatus returns a watcher that notifies of changes to the life 168 // or suspended status of the relation. 169 WatchLifeSuspendedStatus() state.StringsWatcher 170 171 // Suspended returns the suspended status of the relation. 172 Suspended() bool 173 174 // SuspendedReason returns the reason why the relation is suspended. 175 SuspendedReason() string 176 177 // SetSuspended sets the suspended status of the relation. 178 SetSuspended(bool, string) error 179 180 // ReplaceApplicationSettings replaces the application's settings within the 181 // relation. 182 ReplaceApplicationSettings(appName string, settings map[string]interface{}) error 183 184 // ApplicationSettings returns the settings for the specified 185 // application in the relation. 186 ApplicationSettings(appName string) (map[string]interface{}, error) 187 } 188 189 // RelationUnit provides access to the settings of a single unit in a relation, 190 // and methods for modifying the unit's involvement in the relation. 191 type RelationUnit interface { 192 // EnterScope ensures that the unit has entered its scope in the 193 // relation. When the unit has already entered its scope, EnterScope 194 // will report success but make no changes to state. 195 EnterScope(settings map[string]interface{}) error 196 197 // InScope returns whether the relation unit has entered scope and 198 // not left it. 199 InScope() (bool, error) 200 201 // LeaveScope signals that the unit has left its scope in the relation. 202 // After the unit has left its relation scope, it is no longer a member 203 // of the relation; if the relation is dying when its last member unit 204 // leaves, it is removed immediately. It is not an error to leave a 205 // scope that the unit is not, or never was, a member of. 206 LeaveScope() error 207 208 // Settings returns the relation unit's settings within the relation. 209 Settings() (map[string]interface{}, error) 210 211 // ReplaceSettings replaces the relation unit's settings within the 212 // relation. 213 ReplaceSettings(map[string]interface{}) error 214 } 215 216 // Application represents the state of a application hosted in the local model. 217 type Application interface { 218 // Name is the name of the application. 219 Name() string 220 221 // Life returns the lifecycle state of the application. 222 Life() state.Life 223 224 // Endpoints returns the application's currently available relation endpoints. 225 Endpoints() ([]state.Endpoint, error) 226 227 // Charm returns the application's charm and whether units should upgrade to that 228 // charm even if they are in an error state. 229 Charm() (ch Charm, force bool, err error) 230 231 // CharmURL returns a string representation the application's charm URL, 232 // and whether units should upgrade to the charm with that URL even if 233 // they are in an error state. 234 CharmURL() (curl *string, force bool) 235 236 // EndpointBindings returns the Bindings object for this application. 237 EndpointBindings() (Bindings, error) 238 239 // Status returns the status of the application. 240 Status() (status.StatusInfo, error) 241 242 // AllUnits returns all units of the application. 243 AllUnits() ([]Unit, error) 244 } 245 246 // Unit represents the state of a unit hosted in the local model. 247 type Unit interface { 248 // Status returns the status of the unit. 249 Status() (status.StatusInfo, error) 250 } 251 252 // Bindings defines a subset of the functionality provided by the 253 // state.Bindings type, as required by the application facade. For 254 // details on the methods, see the methods on state.Bindings with 255 // the same names. 256 type Bindings interface { 257 MapWithSpaceNames(network.SpaceInfos) (map[string]string, error) 258 } 259 260 type Charm interface { 261 // Meta returns the metadata of the charm. 262 Meta() *charm.Meta 263 264 // StoragePath returns the storage path of the charm bundle. 265 StoragePath() string 266 } 267 268 // RemoteApplication represents the state of an application hosted in an external 269 // (remote) model. 270 type RemoteApplication interface { 271 // DestroyWithForce in addition to doing what Destroy() does, 272 // when force is passed in as 'true', forces th destruction of remote application, 273 // ignoring errors. 274 DestroyWithForce(force bool, maxWait time.Duration) (opErrs []error, err error) 275 276 // Name returns the name of the remote application. 277 Name() string 278 279 // Tag returns the remote applications's tag. 280 Tag() names.Tag 281 282 // URL returns the offer URL, at which the application is offered. 283 URL() (string, bool) 284 285 // OfferUUID returns the UUID of the offer. 286 OfferUUID() string 287 288 // SourceModel returns the tag of the model hosting the remote application. 289 SourceModel() names.ModelTag 290 291 // Macaroon returns the macaroon used for authentication. 292 Macaroon() (*macaroon.Macaroon, error) 293 294 // Status returns the status of the remote application. 295 Status() (status.StatusInfo, error) 296 297 // IsConsumerProxy returns whether application is created 298 // from a registration operation by a consuming model. 299 IsConsumerProxy() bool 300 301 // ConsumeVersion increments each time a new saas proxy 302 // for the same offer is created. 303 ConsumeVersion() int 304 305 // Life returns the lifecycle state of the application. 306 Life() state.Life 307 308 // SetStatus sets the status of the remote application. 309 SetStatus(info status.StatusInfo) error 310 311 // TerminateOperation returns an operation that will set this 312 // remote application to terminated and leave it in a state 313 // enabling it to be removed cleanly. 314 TerminateOperation(string) state.ModelOperation 315 316 // DestroyOperation returns a model operation to destroy remote application. 317 DestroyOperation(bool) state.ModelOperation 318 }