github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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/watcher"
    13  )
    14  
    15  // Client describes the client side API for the MigrationMinion facade
    16  // (used by the migration minion worker).
    17  type Client interface {
    18  	// Watch returns a watcher which reports when the status changes
    19  	// for the migration for the model associated with the API
    20  	// connection.
    21  	Watch() (watcher.MigrationStatusWatcher, error)
    22  }
    23  
    24  // NewClient returns a new Client based on an existing API connection.
    25  func NewClient(caller base.APICaller) Client {
    26  	return &client{base.NewFacadeCaller(caller, "MigrationMinion")}
    27  }
    28  
    29  // client implements Client.
    30  type client struct {
    31  	caller base.FacadeCaller
    32  }
    33  
    34  // Watch implements Client.
    35  func (c *client) Watch() (watcher.MigrationStatusWatcher, error) {
    36  	var result params.NotifyWatchResult
    37  	err := c.caller.FacadeCall("Watch", nil, &result)
    38  	if err != nil {
    39  		return nil, errors.Trace(err)
    40  	}
    41  	if result.Error != nil {
    42  		return nil, result.Error
    43  	}
    44  	w := apiwatcher.NewMigrationStatusWatcher(c.caller.RawAPICaller(), result.NotifyWatcherId)
    45  	return w, nil
    46  }