github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/controller/undertaker/state.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package undertaker 5 6 import ( 7 "gopkg.in/juju/names.v2" 8 9 "github.com/juju/juju/environs/config" 10 "github.com/juju/juju/state" 11 ) 12 13 // State defines the needed methods of state.State 14 // for the work of the undertaker API. 15 type State interface { 16 state.EntityFinder 17 18 // Model returns the model entity. 19 Model() (Model, error) 20 21 // IsController returns true if this state instance has the bootstrap 22 // model UUID. 23 IsController() bool 24 25 // ProcessDyingModel checks if there are any machines or services left in 26 // state. If there are none, the model's life is changed from dying to dead. 27 ProcessDyingModel() (err error) 28 29 // RemoveDyingModel sets current model to dead then removes all documents from 30 // multi-model collections. 31 RemoveDyingModel() error 32 33 // ModelConfig retrieves the model configuration. 34 ModelConfig() (*config.Config, error) 35 36 // WatchModelEntityReferences gets a watcher capable of monitoring 37 // model entity references changes. 38 WatchModelEntityReferences(mUUID string) state.NotifyWatcher 39 40 // ModelUUID returns the model UUID for the model controlled 41 // by this state instance. 42 ModelUUID() string 43 } 44 45 // TODO - CAAS(ericclaudejones): This should contain state alone, model will be 46 // removed once all relevant methods are moved from state to model. 47 type stateShim struct { 48 *state.State 49 model *state.Model 50 } 51 52 func (s *stateShim) Model() (Model, error) { 53 return s.State.Model() 54 } 55 56 func (s *stateShim) ModelConfig() (*config.Config, error) { 57 return s.model.Config() 58 } 59 60 // Model defines the needed methods of state.Model for 61 // the work of the undertaker API. 62 type Model interface { 63 64 // Owner returns tag representing the owner of the model. 65 // The owner is the user that created the model. 66 Owner() names.UserTag 67 68 // Life returns whether the model is Alive, Dying or Dead. 69 Life() state.Life 70 71 // Name returns the human friendly name of the model. 72 Name() string 73 74 // UUID returns the universally unique identifier of the model. 75 UUID() string 76 }