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