github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/action/action.go (about) 1 // Copyright 2014, 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package action 5 6 import ( 7 "io" 8 9 "github.com/juju/errors" 10 "gopkg.in/juju/charm.v6-unstable" 11 12 "github.com/juju/juju/api/action" 13 "github.com/juju/juju/apiserver/params" 14 "github.com/juju/juju/cmd/modelcmd" 15 ) 16 17 // type APIClient represents the action API functionality. 18 type APIClient interface { 19 io.Closer 20 21 // Enqueue takes a list of Actions and queues them up to be executed by 22 // the designated ActionReceiver, returning the params.Action for each 23 // queued Action, or an error if there was a problem queueing up the 24 // Action. 25 Enqueue(params.Actions) (params.ActionResults, error) 26 27 // ListAll takes a list of Tags representing ActionReceivers and returns 28 // all of the Actions that have been queued or run by each of those 29 // Entities. 30 ListAll(params.Entities) (params.ActionsByReceivers, error) 31 32 // ListPending takes a list of Tags representing ActionReceivers 33 // and returns all of the Actions that are queued for each of those 34 // Entities. 35 ListPending(params.Entities) (params.ActionsByReceivers, error) 36 37 // ListCompleted takes a list of Tags representing ActionReceivers 38 // and returns all of the Actions that have been run on each of those 39 // Entities. 40 ListCompleted(params.Entities) (params.ActionsByReceivers, error) 41 42 // Cancel attempts to cancel a queued up Action from running. 43 Cancel(params.Actions) (params.ActionResults, error) 44 45 // ServiceCharmActions is a single query which uses ServicesCharmActions to 46 // get the charm.Actions for a single Service by tag. 47 ServiceCharmActions(params.Entity) (*charm.Actions, error) 48 49 // Actions fetches actions by tag. These Actions can be used to get 50 // the ActionReceiver if necessary. 51 Actions(params.Entities) (params.ActionResults, error) 52 53 // FindActionTagsByPrefix takes a list of string prefixes and finds 54 // corresponding ActionTags that match that prefix. 55 FindActionTagsByPrefix(params.FindTags) (params.FindTagsResults, error) 56 57 // FindActionsByNames takes a list of names and finds a corresponding list of 58 // Actions for every name. 59 FindActionsByNames(params.FindActionsByNames) (params.ActionsByNames, error) 60 } 61 62 // ActionCommandBase is the base type for action sub-commands. 63 type ActionCommandBase struct { 64 modelcmd.ModelCommandBase 65 } 66 67 // NewActionAPIClient returns a client for the action api endpoint. 68 func (c *ActionCommandBase) NewActionAPIClient() (APIClient, error) { 69 return newAPIClient(c) 70 } 71 72 var newAPIClient = func(c *ActionCommandBase) (APIClient, error) { 73 root, err := c.NewAPIRoot() 74 if err != nil { 75 return nil, errors.Trace(err) 76 } 77 return action.NewClient(root), nil 78 }