github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/api/migrationminion/client.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migrationminion 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/api/base" 10 apiwatcher "github.com/juju/juju/api/watcher" 11 "github.com/juju/juju/apiserver/params" 12 "github.com/juju/juju/core/migration" 13 "github.com/juju/juju/watcher" 14 ) 15 16 // NewClient returns a new Client based on an existing API connection. 17 func NewClient(caller base.APICaller) *Client { 18 return &Client{base.NewFacadeCaller(caller, "MigrationMinion")} 19 } 20 21 type Client struct { 22 caller base.FacadeCaller 23 } 24 25 // Watch returns a watcher which reports when the status changes for 26 // the migration for the model associated with the API connection. 27 func (c *Client) Watch() (watcher.MigrationStatusWatcher, error) { 28 var result params.NotifyWatchResult 29 err := c.caller.FacadeCall("Watch", nil, &result) 30 if err != nil { 31 return nil, errors.Trace(err) 32 } 33 if result.Error != nil { 34 return nil, result.Error 35 } 36 w := apiwatcher.NewMigrationStatusWatcher(c.caller.RawAPICaller(), result.NotifyWatcherId) 37 return w, nil 38 } 39 40 // Report allows a migration minion to report if it successfully 41 // completed its activities for a given migration phase. 42 func (c *Client) Report(migrationId string, phase migration.Phase, success bool) error { 43 args := params.MinionReport{ 44 MigrationId: migrationId, 45 Phase: phase.String(), 46 Success: success, 47 } 48 err := c.caller.FacadeCall("Report", args, nil) 49 return errors.Trace(err) 50 }