1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package migrationmaster
7
"github.com/juju/errors"
9
"github.com/juju/juju/apiserver/common"
10
"github.com/juju/juju/apiserver/params"
11
coremigration "github.com/juju/juju/core/migration"
12
"github.com/juju/juju/migration"
13
"github.com/juju/juju/state"
17
common.RegisterStandardFacade("MigrationMaster", 1, NewAPI)
20
// API implements the API required for the model migration
24
authorizer common.Authorizer
25
resources *common.Resources
28
// NewAPI creates a new API server endpoint for the model migration
32
resources *common.Resources,
33
authorizer common.Authorizer,
35
if !authorizer.AuthModelManager() {
36
return nil, common.ErrPerm
39
backend: getBackend(st),
40
authorizer: authorizer,
45
// Watch starts watching for an active migration for the model
46
// associated with the API connection. The returned id should be used
47
// with Next on the MigrationMasterWatcher endpoint to receive deltas.
48
func (api *API) Watch() (params.NotifyWatchResult, error) {
49
w, err := api.backend.WatchForModelMigration()
51
return params.NotifyWatchResult{}, errors.Trace(err)
53
return params.NotifyWatchResult{
54
NotifyWatcherId: api.resources.Register(w),
58
// SetPhase sets the phase of the active model migration. The provided
59
// phase must be a valid phase value, for example QUIESCE" or
60
// "ABORT". See the core/migration package for the complete list.
61
func (api *API) SetPhase(args params.SetMigrationPhaseArgs) error {
62
mig, err := api.backend.GetModelMigration()
64
return errors.Annotate(err, "could not get migration")
67
phase, ok := coremigration.ParsePhase(args.Phase)
69
return errors.Errorf("invalid phase: %q", args.Phase)
72
err = mig.SetPhase(phase)
73
return errors.Annotate(err, "failed to set phase")
76
var exportModel = migration.ExportModel
78
// Export serializes the model associated with the API connection.
79
func (api *API) Export() (params.SerializedModel, error) {
80
var serialized params.SerializedModel
82
bytes, err := exportModel(api.backend)
84
return serialized, err
87
serialized.Bytes = bytes
88
return serialized, nil