github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/migration/interface.go (about) 1 // Copyright 2023 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migration 5 6 import ( 7 "github.com/juju/names/v5" 8 "github.com/juju/replicaset/v3" 9 "github.com/juju/version/v2" 10 11 "github.com/juju/juju/core/presence" 12 "github.com/juju/juju/core/status" 13 environscloudspec "github.com/juju/juju/environs/cloudspec" 14 "github.com/juju/juju/state" 15 "github.com/juju/juju/tools" 16 ) 17 18 // PrecheckBackend defines the interface to query Juju's state 19 // for migration prechecks. 20 type PrecheckBackend interface { 21 AgentVersion() (version.Number, error) 22 NeedsCleanup() (bool, error) 23 Model() (PrecheckModel, error) 24 AllModelUUIDs() ([]string, error) 25 IsUpgrading() (bool, error) 26 IsMigrationActive(string) (bool, error) 27 AllMachines() ([]PrecheckMachine, error) 28 AllApplications() ([]PrecheckApplication, error) 29 AllRelations() ([]PrecheckRelation, error) 30 AllCharmURLs() ([]*string, error) 31 ControllerBackend() (PrecheckBackend, error) 32 CloudCredential(tag names.CloudCredentialTag) (state.Credential, error) 33 HasUpgradeSeriesLocks() (bool, error) 34 MachineCountForBase(base ...state.Base) (map[string]int, error) 35 MongoCurrentStatus() (*replicaset.Status, error) 36 } 37 38 // Pool defines the interface to a StatePool used by the migration 39 // prechecks. 40 type Pool interface { 41 GetModel(string) (PrecheckModel, func(), error) 42 } 43 44 // PrecheckModel describes the state interface a model as needed by 45 // the migration prechecks. 46 type PrecheckModel interface { 47 UUID() string 48 Name() string 49 Type() state.ModelType 50 Owner() names.UserTag 51 Life() state.Life 52 MigrationMode() state.MigrationMode 53 AgentVersion() (version.Number, error) 54 CloudCredentialTag() (names.CloudCredentialTag, bool) 55 } 56 57 // PrecheckMachine describes the state interface for a machine needed 58 // by migration prechecks. 59 type PrecheckMachine interface { 60 Id() string 61 AgentTools() (*tools.Tools, error) 62 Life() state.Life 63 Status() (status.StatusInfo, error) 64 InstanceStatus() (status.StatusInfo, error) 65 ShouldRebootOrShutdown() (state.RebootAction, error) 66 } 67 68 // PrecheckApplication describes the state interface for an 69 // application needed by migration prechecks. 70 type PrecheckApplication interface { 71 Name() string 72 Life() state.Life 73 CharmURL() (*string, bool) 74 AllUnits() ([]PrecheckUnit, error) 75 MinUnits() int 76 } 77 78 // PrecheckUnit describes state interface for a unit needed by 79 // migration prechecks. 80 type PrecheckUnit interface { 81 Name() string 82 AgentTools() (*tools.Tools, error) 83 Life() state.Life 84 CharmURL() *string 85 AgentStatus() (status.StatusInfo, error) 86 Status() (status.StatusInfo, error) 87 ShouldBeAssigned() bool 88 IsSidecar() (bool, error) 89 } 90 91 // PrecheckRelation describes the state interface for relations needed 92 // for prechecks. 93 type PrecheckRelation interface { 94 String() string 95 Endpoints() []state.Endpoint 96 Unit(PrecheckUnit) (PrecheckRelationUnit, error) 97 AllRemoteUnits(appName string) ([]PrecheckRelationUnit, error) 98 RemoteApplication() (string, bool, error) 99 } 100 101 // PrecheckRelationUnit describes the interface for relation units 102 // needed for migration prechecks. 103 type PrecheckRelationUnit interface { 104 Valid() (bool, error) 105 InScope() (bool, error) 106 UnitName() string 107 } 108 109 // ModelPresence represents the API server connections for a model. 110 type ModelPresence interface { 111 // For a given non controller agent, return the Status for that agent. 112 AgentStatus(agent string) (presence.Status, error) 113 } 114 115 type environsCloudSpecGetter func(names.ModelTag) (environscloudspec.CloudSpec, error)