Repository: brooklyn-client
Updated Branches:
  refs/heads/master 48e9f40d1 -> 052522181


Invoke effector: support timeout


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/782af9dd
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/782af9dd
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/782af9dd

Branch: refs/heads/master
Commit: 782af9dd00a67b74f9ef5bdbb39db39e2bb318e6
Parents: 48e9f40
Author: Aled Sage <aled.s...@gmail.com>
Authored: Fri Feb 2 08:56:49 2018 +0000
Committer: Aled Sage <aled.s...@gmail.com>
Committed: Fri Feb 2 08:56:49 2018 +0000

----------------------------------------------------------------------
 cli/api/entity_effectors/effectors.go |  5 ++++-
 cli/commands/invoke.go                | 22 +++++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/782af9dd/cli/api/entity_effectors/effectors.go
----------------------------------------------------------------------
diff --git a/cli/api/entity_effectors/effectors.go 
b/cli/api/entity_effectors/effectors.go
index 557928d..939f8ce 100644
--- a/cli/api/entity_effectors/effectors.go
+++ b/cli/api/entity_effectors/effectors.go
@@ -42,11 +42,14 @@ func EffectorList(network *net.Network, application, entity 
string) ([]models.Ef
        return effectorList, err
 }
 
-func TriggerEffector(network *net.Network, application, entity, effector 
string, params []string, args []string) (string, error) {
+func TriggerEffector(network *net.Network, application, entity, effector 
string, timeout string, params []string, args []string) (string, error) {
        if len(params) != len(args) {
                return "", errors.New(strings.Join([]string{"Parameters not 
supplied:", strings.Join(params, ", ")}, " "))
        }
        path := fmt.Sprintf("/v1/applications/%s/entities/%s/effectors/%s", 
application, entity, effector)
+       if (timeout != "") {
+               path = fmt.Sprintf("%s?timeout=%s", path, 
url.QueryEscape(timeout))
+       }
        data := url.Values{}
        for i := range params {
                data.Set(params[i], args[i])

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/782af9dd/cli/commands/invoke.go
----------------------------------------------------------------------
diff --git a/cli/commands/invoke.go b/cli/commands/invoke.go
index 61a4edc..ee49ccb 100644
--- a/cli/commands/invoke.go
+++ b/cli/commands/invoke.go
@@ -77,13 +77,17 @@ var paramFlags = []cli.Flag{
                Usage: "Parameter and value separated by '=', e.g. -P x=y. If 
the parameter value is complex or multi-" +
                       "lined it may be provided in a file and referenced as: 
'@<file>', e.g. -P x=@/path/to/file.",
        },
+       cli.StringFlag{
+               Name:  "timeout",
+               Usage: "Timeout for waiting for effector (e.g. '1s' for one 
second, '0' for forever); defaults to forever.",
+       },
 }
 
 func (cmd *Invoke) Metadata() command_metadata.CommandMetadata {
        return command_metadata.CommandMetadata{
                Name:        "invoke",
                Description: "Invoke an effector of an application and entity",
-               Usage:       "BROOKLYN_NAME EFF-SCOPE invoke [ 
parameter-options ]",
+               Usage:       "BROOKLYN_NAME EFF-SCOPE invoke [ --timeout <val> 
] [ parameter-options ]",
                Flags:       paramFlags,
        }
 }
@@ -119,8 +123,9 @@ func (cmd *Invoke) Run(scope scope.Scope, c *cli.Context) {
        if err := net.VerifyLoginURL(cmd.network); err != nil {
                error_handler.ErrorExit(err)
        }
+       timeout := c.String("timeout")
        parms := c.StringSlice("param")
-       invoke(cmd.network, scope.Application, scope.Entity, scope.Effector, 
parms)
+       invoke(cmd.network, scope.Application, scope.Entity, scope.Effector, 
timeout, parms)
 }
 
 const stopEffector = "stop"
@@ -129,8 +134,9 @@ func (cmd *Stop) Run(scope scope.Scope, c *cli.Context) {
        if err := net.VerifyLoginURL(cmd.network); err != nil {
                error_handler.ErrorExit(err)
        }
+       timeout := c.String("timeout")
        parms := c.StringSlice("param")
-       invoke(cmd.network, scope.Application, scope.Entity, stopEffector, 
parms)
+       invoke(cmd.network, scope.Application, scope.Entity, stopEffector, 
timeout, parms)
 }
 
 const startEffector = "start"
@@ -139,8 +145,9 @@ func (cmd *Start) Run(scope scope.Scope, c *cli.Context) {
        if err := net.VerifyLoginURL(cmd.network); err != nil {
                error_handler.ErrorExit(err)
        }
+       timeout := c.String("timeout")
        parms := c.StringSlice("param")
-       invoke(cmd.network, scope.Application, scope.Entity, startEffector, 
parms)
+       invoke(cmd.network, scope.Application, scope.Entity, startEffector, 
timeout, parms)
 }
 
 const restartEffector = "restart"
@@ -149,13 +156,14 @@ func (cmd *Restart) Run(scope scope.Scope, c 
*cli.Context) {
        if err := net.VerifyLoginURL(cmd.network); err != nil {
                error_handler.ErrorExit(err)
        }
+       timeout := c.String("timeout")
        parms := c.StringSlice("param")
-       invoke(cmd.network, scope.Application, scope.Entity, restartEffector, 
parms)
+       invoke(cmd.network, scope.Application, scope.Entity, restartEffector, 
timeout, parms)
 }
 
-func invoke(network *net.Network, application, entity, effector string, parms 
[]string) {
+func invoke(network *net.Network, application, entity, effector string, 
timeout string, parms []string) {
        names, vals, err := extractParams(parms)
-       result, err := entity_effectors.TriggerEffector(network, application, 
entity, effector, names, vals)
+       result, err := entity_effectors.TriggerEffector(network, application, 
entity, effector, timeout, names, vals)
        if nil != err {
                error_handler.ErrorExit(err)
        } else {

Reply via email to