51
51
"EntityWatcher", 2, newEntitiesWatcher,
52
52
reflect.TypeOf((*srvEntitiesWatcher)(nil)),
54
common.RegisterFacade(
55
"MigrationMasterWatcher", 1, newMigrationMasterWatcher,
56
reflect.TypeOf((*srvMigrationMasterWatcher)(nil)),
56
60
// NewAllModelWatcher returns a new API server endpoint for interacting
371
375
func (w *srvEntitiesWatcher) Stop() error {
372
376
return w.resources.Stop(w.id)
379
func newMigrationMasterWatcher(
381
resources *common.Resources,
382
auth common.Authorizer,
384
) (interface{}, error) {
385
if !auth.AuthModelManager() {
386
return nil, common.ErrPerm
388
w, ok := resources.Get(id).(state.NotifyWatcher)
390
return nil, common.ErrUnknownWatcher
392
return &srvMigrationMasterWatcher{
395
resources: resources,
396
st: migrationGetter(st),
400
type srvMigrationMasterWatcher struct {
401
watcher state.NotifyWatcher
403
resources *common.Resources
404
st modelMigrationGetter
407
var migrationGetter = func(st *state.State) modelMigrationGetter {
411
type modelMigrationGetter interface {
412
GetModelMigration() (state.ModelMigration, error)
415
// Next returns when a model migration is active for the associated
416
// model. The details for the migration's target controller are
418
func (w *srvMigrationMasterWatcher) Next() (params.ModelMigrationTargetInfo, error) {
419
empty := params.ModelMigrationTargetInfo{}
421
if _, ok := <-w.watcher.Changes(); !ok {
422
err := w.watcher.Err()
424
err = common.ErrStoppedWatcher
429
mig, err := w.st.GetModelMigration()
431
return empty, errors.Annotate(err, "migration lookup")
433
info, err := mig.TargetInfo()
435
return empty, errors.Trace(err)
437
return params.ModelMigrationTargetInfo{
438
ControllerTag: info.ControllerTag.String(),
441
AuthTag: info.AuthTag.String(),
442
Password: info.Password,
446
// Stop stops the watcher.
447
func (w *srvMigrationMasterWatcher) Stop() error {
448
return w.resources.Stop(w.id)