438
441
func (w *entitiesWatcher) Changes() watcher.StringsChannel {
445
// NewMigrationMasterWatcher takes the NotifyWatcherId returns by the
446
// MigrationMaster.Watch API and returns a watcher which will report
447
// details about a model migration (if and when it exists).
448
func NewMigrationMasterWatcher(caller base.APICaller, watcherId string) watcher.MigrationMasterWatcher {
449
w := &migrationMasterWatcher{
452
out: make(chan migration.TargetInfo),
456
w.tomb.Kill(w.loop())
461
type migrationMasterWatcher struct {
463
caller base.APICaller
465
out chan migration.TargetInfo
468
func (w *migrationMasterWatcher) loop() error {
469
w.newResult = func() interface{} { return new(params.ModelMigrationTargetInfo) }
470
w.call = makeWatcherAPICaller(w.caller, "MigrationMasterWatcher", w.id)
471
w.commonWatcher.init()
479
case data, ok = <-w.in:
481
// The tomb is already killed with the correct error
482
// at this point, so just return.
485
case <-w.tomb.Dying():
489
info := data.(*params.ModelMigrationTargetInfo)
490
controllerTag, err := names.ParseModelTag(info.ControllerTag)
492
return errors.Annotatef(err, "unable to parse %q", info.ControllerTag)
494
authTag, err := names.ParseUserTag(info.AuthTag)
496
return errors.Annotatef(err, "unable to parse %q", info.AuthTag)
498
outInfo := migration.TargetInfo{
499
ControllerTag: controllerTag,
503
Password: info.Password,
506
case w.out <- outInfo:
507
case <-w.tomb.Dying():
513
// Changes returns a channel that reports the details of an active
514
// migration for the model associated with the API connection.
515
func (w *migrationMasterWatcher) Changes() <-chan migration.TargetInfo {