github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/agent/migrationflag/shim.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migrationflag 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/apiserver/facade" 10 "github.com/juju/juju/core/migration" 11 "github.com/juju/juju/state" 12 ) 13 14 // NewFacade wraps New to express the supplied *state.State as a Backend. 15 func NewFacade(st *state.State, resources facade.Resources, auth facade.Authorizer) (*Facade, error) { 16 facade, err := New(&backend{st}, resources, auth) 17 if err != nil { 18 return nil, errors.Trace(err) 19 } 20 return facade, nil 21 } 22 23 // backend implements Backend by wrapping a *state.State. 24 type backend struct { 25 st *state.State 26 } 27 28 // ModelUUID is part of the Backend interface. 29 func (shim *backend) ModelUUID() string { 30 return shim.st.ModelUUID() 31 } 32 33 // WatchMigrationPhase is part of the Backend interface. 34 func (shim *backend) WatchMigrationPhase() state.NotifyWatcher { 35 return shim.st.WatchMigrationStatus() 36 } 37 38 // MigrationPhase is part of the Backend interface. 39 func (shim *backend) MigrationPhase() (migration.Phase, error) { 40 mig, err := shim.st.LatestMigration() 41 if errors.IsNotFound(err) { 42 return migration.NONE, nil 43 } else if err != nil { 44 return migration.UNKNOWN, errors.Trace(err) 45 } 46 phase, err := mig.Phase() 47 if err != nil { 48 return migration.UNKNOWN, errors.Trace(err) 49 } 50 return phase, nil 51 }