You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2018/01/11 01:46:07 UTC
[incubator-openwhisk-cli] branch master updated: Handle namespace
API listing on the client. (#191)
This is an automated email from the ASF dual-hosted git repository.
dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git
The following commit(s) were added to refs/heads/master by this push:
new 7b78091 Handle namespace API listing on the client. (#191)
7b78091 is described below
commit 7b7809143c926132cd507f34c164c337bad5528c
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Wed Jan 10 20:46:04 2018 -0500
Handle namespace API listing on the client. (#191)
* Handle namespace API listing on the client.
Replaces call to GET /namespace/_ with calls to GET /namespace/_/[actions, triggers, rules, packages]
Also updates wsk list/wsk namespace get to reject positional argument.
* Update .gitignore.
* Preserve wsk list /_ compatibility to break circular dependence.
Remove redundant test.
Fix go integration test.
* Pick up changes in client lib.
---
.gitignore | 3 ++
Godeps/Godeps.json | 2 +-
commands/namespace.go | 62 ++++++++++------------
commands/shared.go | 9 ++++
tests/src/integration/integration_test.go | 4 +-
.../test/scala/system/basic/WskBasicTests.scala | 10 +---
.../whisk/core/cli/test/WskBasicUsageTests.scala | 2 +-
wski18n/resources/en_US.all.json | 4 +-
8 files changed, 46 insertions(+), 50 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0f85d25..fa48daa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@ javascript/
wsk
scripts
Godeps/_workspace
+.idea/
+*.iml
+.gradle
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 10c886e..dc56dda 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -65,7 +65,7 @@
},
{
"ImportPath": "github.com/apache/incubator-openwhisk-client-go/whisk",
- "Rev": "a67e8509a92beb6c68f0c9da43562af1f5d2b13c"
+ "Rev": "ba3bbee442357a239667ef6de378d5b7d33e0ceb"
}
]
}
diff --git a/commands/namespace.go b/commands/namespace.go
index 35240ca..6c1727b 100644
--- a/commands/namespace.go
+++ b/commands/namespace.go
@@ -61,50 +61,35 @@ var namespaceListCmd = &cobra.Command{
}
var namespaceGetCmd = &cobra.Command{
- Use: "get [NAMESPACE]",
- Short: wski18n.T("get triggers, actions, and rules in the registry for a namespace"),
+ Use: "get",
+ Short: wski18n.T("get triggers, actions, and rules in the registry for namespace"),
SilenceUsage: true,
SilenceErrors: true,
PreRunE: SetupClientConfig,
RunE: func(cmd *cobra.Command, args []string) error {
- var qualifiedName = new(QualifiedName)
var err error
+ var namespace string = getClientNamespace()
- if whiskErr := CheckArgs(args, 0, 1, "Namespace get",
- wski18n.T("An optional namespace is the only valid argument.")); whiskErr != nil {
- return whiskErr
- }
-
- // Namespace argument is optional; defaults to configured property namespace
- if len(args) == 1 {
- if qualifiedName, err = NewQualifiedName(args[0]); err != nil {
- return NewQualifiedNameError(args[0], err)
- }
-
- if len(qualifiedName.GetEntityName()) > 0 {
- return entityNameError(qualifiedName.GetEntityName())
+ if (!(len(args) == 1 && args[0] == "/_")) {
+ if whiskErr := CheckArgs(args, 0, 0, "Namespace get",
+ wski18n.T("No arguments are required.")); whiskErr != nil {
+ return whiskErr
}
}
- namespace, _, err := Client.Namespaces.Get(qualifiedName.GetNamespace())
+ actions, _, err := Client.Actions.List("", &whisk.ActionListOptions{ Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Actions") }
- if err != nil {
- whisk.Debug(whisk.DbgError, "Client.Namespaces.Get(%s) error: %s\n", getClientNamespace(), err)
- errStr := wski18n.T("Unable to obtain the list of entities for namespace '{{.namespace}}': {{.err}}",
- map[string]interface{}{"namespace": getClientNamespace(), "err": err})
- werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_NETWORK,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return werr
- }
+ packages, _, err := Client.Packages.List(&whisk.PackageListOptions{ Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Packages") }
- fmt.Fprintf(color.Output, wski18n.T("Entities in namespace: {{.namespace}}\n",
- map[string]interface{}{"namespace": boldString(getClientNamespace())}))
- sortByName := Flags.common.nameSort
- printList(namespace.Contents.Packages, sortByName)
- printList(namespace.Contents.Actions, sortByName)
- printList(namespace.Contents.Triggers, sortByName)
- //No errors, lets attempt to retrieve the status of each rule #312
- for index, rule := range namespace.Contents.Rules {
+ triggers, _, err := Client.Triggers.List(&whisk.TriggerListOptions{ Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Triggers") }
+
+ rules, _, err := Client.Rules.List(&whisk.RuleListOptions{ Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Rules") }
+ //No errors, lets attempt to retrieve the status of each rule
+ for index, rule := range rules {
ruleStatus, _, err := Client.Rules.Get(rule.Name)
if err != nil {
errStr := wski18n.T("Unable to get status of rule '{{.name}}': {{.err}}",
@@ -113,9 +98,16 @@ var namespaceGetCmd = &cobra.Command{
werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return werr
}
- namespace.Contents.Rules[index].Status = ruleStatus.Status
+ rules[index].Status = ruleStatus.Status
}
- printList(namespace.Contents.Rules, sortByName)
+
+ fmt.Fprintf(color.Output, wski18n.T("Entities in namespace: {{.namespace}}\n",
+ map[string]interface{}{"namespace": boldString(getClientNamespace())}))
+ sortByName := Flags.common.nameSort
+ printList(packages, sortByName)
+ printList(actions, sortByName)
+ printList(triggers, sortByName)
+ printList(rules, sortByName)
return nil
},
diff --git a/commands/shared.go b/commands/shared.go
index b380d5b..5082e05 100644
--- a/commands/shared.go
+++ b/commands/shared.go
@@ -33,3 +33,12 @@ func entityNameError(entityName string) (error) {
return whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
}
+
+func entityListError(err error, namespace string, kind string) error {
+ whisk.Debug(whisk.DbgError, "Client.%s.List(%s) error: %s\n", kind, namespace, err)
+ errStr := wski18n.T("Unable to obtain the list of entities for namespace '{{.namespace}}': {{.err}}",
+ map[string]interface{}{"namespace": namespace, "err": err})
+ return whisk.MakeWskErrorFromWskError(errors.New(errStr), err,
+ whisk.EXIT_CODE_ERR_NETWORK, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+}
+
diff --git a/tests/src/integration/integration_test.go b/tests/src/integration/integration_test.go
index 7c377b9..ab368a2 100644
--- a/tests/src/integration/integration_test.go
+++ b/tests/src/integration/integration_test.go
@@ -139,8 +139,8 @@ func initInvalidArgs() {
Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
common.InvalidArg {
- Cmd: []string{"namespace", "get", "namespace", invalidArg},
- Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
+ Cmd: []string{"namespace", "get", invalidArg},
+ Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
common.InvalidArg {
Cmd: []string{"package", "create"},
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala
index 1142414..19e7b81 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -776,18 +776,10 @@ class WskBasicTests extends TestHelpers with WskTestHelpers {
}
it should "list entities in default namespace" in {
- // use a fresh wsk props instance that is guaranteed to use
- // the default namespace
+ // use a fresh wsk props instance that is guaranteed to use the default namespace
wsk.namespace.get(expectedExitCode = SUCCESS_EXIT)(WskProps()).stdout should include("default")
}
- it should "not list entities with an invalid namespace" in {
- val namespace = "fakeNamespace"
- val stderr = wsk.namespace.get(Some(s"/${namespace}"), expectedExitCode = FORBIDDEN).stderr
-
- stderr should include(s"Unable to obtain the list of entities for namespace '${namespace}'")
- }
-
behavior of "Wsk Activation CLI"
it should "create a trigger, and fire a trigger to get its individual fields from an activation" in withAssetCleaner(
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index af9f299..58a476e 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -1632,7 +1632,7 @@ class WskBasicUsageTests extends TestHelpers with WskTestHelpers {
(Seq("activation", "result", "activationID", invalidArg), s"${tooManyArgsMsg}${invalidArg}."),
(Seq("activation", "poll", "activationID", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${optNamespaceMsg}"),
(Seq("namespace", "list", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${noArgsReqMsg}"),
- (Seq("namespace", "get", "namespace", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${optNamespaceMsg}"),
+ (Seq("namespace", "get", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${noArgsReqMsg}"),
(Seq("package", "create"), s"${tooFewArgsMsg} ${packageNameReqMsg}"),
(Seq("package", "create", "packageName", invalidArg), s"${tooManyArgsMsg}${invalidArg}."),
(Seq("package", "create", "packageName", "--shared", invalidArg), invalidShared),
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 0777312..2748280 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -72,8 +72,8 @@
"translation": "Unable to obtain the list of available namespaces: {{.err}}"
},
{
- "id": "get triggers, actions, and rules in the registry for a namespace",
- "translation": "get triggers, actions, and rules in the registry for a namespace"
+ "id": "get triggers, actions, and rules in the registry for namespace",
+ "translation": "get triggers, actions, and rules in the registry for namespace"
},
{
"id": "'{{.name}}' is not a valid qualified name: {{.err}}",
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].