1
// Copyright 2016 Canonical Ltd.
2
// Copyright 2016 Cloudbase Solutions
3
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
11
"gopkg.in/juju/names.v2"
13
"github.com/juju/juju/api/base"
14
apiwatcher "github.com/juju/juju/api/watcher"
15
"github.com/juju/juju/apiserver/params"
16
"github.com/juju/juju/watcher"
19
// Client provides access to the retry strategy api
21
facade base.FacadeCaller
24
// NewClient creates a client for accessing the retry strategy api
25
func NewClient(apiCaller base.APICaller) *Client {
26
return &Client{base.NewFacadeCaller(apiCaller, "RetryStrategy")}
29
// RetryStrategy returns the configuration for the agent specified by the agentTag.
30
func (c *Client) RetryStrategy(agentTag names.Tag) (params.RetryStrategy, error) {
31
var results params.RetryStrategyResults
32
args := params.Entities{
33
Entities: []params.Entity{{Tag: agentTag.String()}},
35
err := c.facade.FacadeCall("RetryStrategy", args, &results)
37
return params.RetryStrategy{}, errors.Trace(err)
39
if len(results.Results) != 1 {
40
return params.RetryStrategy{}, fmt.Errorf("expected 1 result, got %d", len(results.Results))
42
result := results.Results[0]
43
if result.Error != nil {
44
return params.RetryStrategy{}, errors.Trace(result.Error)
46
return *result.Result, nil
49
// WatchRetryStrategy returns a notify watcher that looks for changes in the
50
// retry strategy config for the agent specified by agentTag
51
// Right now only the boolean that decides whether we retry can be modified.
52
func (c *Client) WatchRetryStrategy(agentTag names.Tag) (watcher.NotifyWatcher, error) {
53
var results params.NotifyWatchResults
54
args := params.Entities{
55
Entities: []params.Entity{{Tag: agentTag.String()}},
57
err := c.facade.FacadeCall("WatchRetryStrategy", args, &results)
59
return nil, errors.Trace(err)
61
if len(results.Results) != 1 {
62
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
64
result := results.Results[0]
65
if result.Error != nil {
66
return nil, errors.Trace(result.Error)
68
w := apiwatcher.NewNotifyWatcher(c.facade.RawAPICaller(), result)