You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by da...@apache.org on 2017/09/19 05:04:03 UTC
[incubator-openwhisk-wskdeploy] branch master updated: Fix
single-line parameter to look for Type names (and default with proper
value) (#511)
This is an automated email from the ASF dual-hosted git repository.
daisyguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git
The following commit(s) were added to refs/heads/master by this push:
new 0eda06c Fix single-line parameter to look for Type names (and default with proper value) (#511)
0eda06c is described below
commit 0eda06cd62c4981d253df1fca5a016dfd3706253
Author: Matt Rutkowski <mr...@us.ibm.com>
AuthorDate: Tue Sep 19 00:04:01 2017 -0500
Fix single-line parameter to look for Type names (and default with proper value) (#511)
* Update guide to include hello world variants, improve intrapage links.
* Update guide to include hello world variants, improve intrapage links.
* Update guide to include hello world variants, improve intrapage links.
* Update guide to include hello world variants, improve intrapage links.
* fix some docs; assure single-line parms works.
* fix some docs; assure single-line parms works.
* fix some docs; assure single-line parms works.
---
docs/examples/manifest_hello_world.yaml | 9 +++++++++
docs/examples/src/hello.js | 4 ++++
docs/programming_guide.md | 23 ++++++++++++-----------
docs/wskdeploy_debugging.md | 11 +++++++++++
parsers/manifest_parser.go | 27 ++++++++++++++++++++++-----
5 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/docs/examples/manifest_hello_world.yaml b/docs/examples/manifest_hello_world.yaml
new file mode 100644
index 0000000..80f60f0
--- /dev/null
+++ b/docs/examples/manifest_hello_world.yaml
@@ -0,0 +1,9 @@
+# Example 1: Basic Hello World using NodeJS (JavaScript)
+package:
+ hello_world_package:
+ # name: hello_world_package
+ version: 1.0
+ license: Apache-2.0
+ actions:
+ hello_world:
+ function: src/hello.js
diff --git a/docs/examples/src/hello.js b/docs/examples/src/hello.js
new file mode 100644
index 0000000..55d282f
--- /dev/null
+++ b/docs/examples/src/hello.js
@@ -0,0 +1,4 @@
+function main(params) {
+ msg = "Hello, " + params.name + " from " + params.place;
+ return { payload: msg };
+}
diff --git a/docs/programming_guide.md b/docs/programming_guide.md
index 41c827f..b447f7e 100644
--- a/docs/programming_guide.md
+++ b/docs/programming_guide.md
@@ -1,32 +1,33 @@
# ```wskdeploy``` utility by example
_A step-by-step guide for deploying Apache OpenWhisk applications using Package Manifest files._
-This guide will walk you through how to describe OpenWhisk applications using the [OpenWhisk Packaging Specification](https://github.com/apache/incubator-openwhisk-wskdeploy/tree/master/specification) and deploy them through the Whisk Deploy utility.
+This guide will walk you through how to describe OpenWhisk applications using the [OpenWhisk Packaging Specification](https://github.com/apache/incubator-openwhisk-wskdeploy/tree/master/specification#openwhisk-packaging-specification) and deploy them through the Whisk Deploy utility. Please use the specification as the ultimate reference for all Manifest file grammar and syntax.
### Setting up your Host and Credentials
-In order to deply your OpenWhisk package, at minimum, the wskdeploy utility needs valid OpenWhisk APIHOST and AUTH variable to attempt deployment. Please read the [Configuring wskdeploy](wskdeploy_configuring.md)
+In order to deploy your OpenWhisk package, at minimum, the ```wskdeploy``` utility needs valid OpenWhisk APIHOST and AUTH variable to attempt deployment. Please read the [Configuring wskdeploy](wskdeploy_configuring.md#configuring-wskdeploy)
# Debugging your package
-In addition to the normal output the wskdeploy utility provides, you may enable additional information that may further assist you in debugging. Please read the [Debugging Whisk Deploy](wskdeploy_debugging.md) document.
+In addition to the normal output the wskdeploy utility provides, you may enable additional information that may further assist you in debugging. Please read the [Debugging Whisk Deploy](wskdeploy_debugging.md#debugging-wskdeploy) document.
# Creating a "hello world" application
As with most language introductions, here we show a minimal "hello world" application as encoded in an OpenWhisk Package Manifest YAML file:
```
-helloworld:
- version: 1.0
- license: Apache-2.0
- actions:
- hello:
- version: 1.0
- function: src/hello/hello.js
+package:
+ helloworld:
+ version: 1.0
+ license: Apache-2.0
+ actions:
+ hello:
+ version: 1.0
+ function: src/hello/hello.js
```
where "hello.js" contains the following JavaScript code:
```
function main(params) {
- console.log('hello', params.payload+'!');
+ msg = "Hello, " + params.name + " from " + params.place;
return { payload: msg };
}
```
diff --git a/docs/wskdeploy_debugging.md b/docs/wskdeploy_debugging.md
index 767de72..1f4fbe7 100644
--- a/docs/wskdeploy_debugging.md
+++ b/docs/wskdeploy_debugging.md
@@ -10,6 +10,17 @@ The first thing you should do is turn on _"verbose mode"_ using the flag ```-v``
$ wskdeploy -v -m manifest.yaml
```
+## Enable console logging in your Action
+
+You may call ```console.log(<text>)`` within your Action (function) code to aid in debugging. For example, in NodeJS (JavaScript) you could output your entire JSON payload before returning it:
+```
+function main(params) {
+ msg = "Hello, " + params.name + " from " + params.place;
+ console.log(msg)
+ return { payload: msg };
+}
+```
+
## Enable additional trace in Go Client
Wskdeploy uses the OpenWhisk GoLang Client to format and invoke OpenWhisk's APIs which has additional debug tracing available.
diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index ff9afb5..2b6a9a4 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -536,8 +536,11 @@ func ResolveParamTypeFromValue(value interface{}, filePath string) (string, erro
} else {
// raise an error if param is not a known type
- lines := []string{"Line Unknown"}
- msgs := []string{"Parameter value is not a known type. ["+actualType+"]"}
+ // TODO(): We have information to display to user on an error or warning here
+ // TODO(): specifically, we have the parameter name, its value to show on error/warning
+ // TODO(): perhaps this is a different Class of error? e.g., ErrorParameterMismatchError
+ lines := []string{"Line Unknown"}
+ msgs := []string{"Parameter value is not a known type. ["+actualType+"]"}
err = utils.NewParserErr(filePath, lines, msgs)
}
} else {
@@ -567,6 +570,20 @@ func ResolveParameter(paramName string, param *Parameter, filePath string) (inte
// We need to identify parameter Type here for later validation
param.Type, errorParser = ResolveParamTypeFromValue(param.Value, filePath)
+ // In single-line format, the param's <value> can be a "Type name" and NOT an actual value.
+ // if this is the case, we must detect it and set the value to the default for that type name.
+ //if param.Type == "string" {
+ // // The value is a <string>; now we must test if is the name of a known Type
+ // var tempValue = param.Value.(string)
+ // if isValidParameterType(tempValue) {
+ // // If the value is indeed the name of a Type, we must change BOTH its
+ // // Type to be that type and its value to that Type's default value
+ // // (which happens later by setting it to nil here
+ // param.Type = param.Value.(string)
+ // param.Value = nil
+ // }
+ //}
+
} else {
// we have a multi-line parameter declaration
@@ -581,8 +598,8 @@ func ResolveParameter(paramName string, param *Parameter, filePath string) (inte
// if we do not have a value or default, but have a type, find its default and use it for the value
if param.Type != "" && !isValidParameterType(param.Type) {
- lines := []string{"Line Unknown"}
- msgs := []string{"Invalid Type for parameter. ["+param.Type+"]"}
+ lines := []string{"Line Unknown"}
+ msgs := []string{"Invalid Type for parameter. ["+param.Type+"]"}
return value, utils.NewParserErr(filePath, lines, msgs)
} else if param.Type == "" {
param.Type = tempType
@@ -595,7 +612,7 @@ func ResolveParameter(paramName string, param *Parameter, filePath string) (inte
typ := param.Type
// TODO(Priti): need to validate type is one of the supported primitive types with unit testing
- // TODO(): with the new logic, when would the fpllowing Unmarhsall() call be used?
+ // TODO(): with the new logic, when would the following Unmarhsall() call be used?
// if value is of type 'string' and its not empty <OR> if type is not 'string'
if str, ok := value.(string); ok && (len(typ) == 0 || typ != "string") {
var parsed interface{}
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].