This is an automated email from the ASF dual-hosted git repository. mrutkowski 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 1db40db Programming Guide updates - part9 (#570) 1db40db is described below commit 1db40dbcd36d2093110959a80f82675037b8aaed Author: Matt Rutkowski <mrutk...@us.ibm.com> AuthorDate: Fri Sep 29 10:28:42 2017 -0500 Programming Guide updates - part9 (#570) * Trigger-Rule example with Deployment File. * Trigger-Rule example with Deployment File. * Trigger-Rule example with Deployment File. * Update Trigger Rule example with Trigger param bindings. * Update Trigger Rule example with Trigger param bindings. * Update Trigger Rule example with Trigger param bindings. * Update Trigger Rule example with Trigger param bindings. * Update Trigger Rule example with Trigger param bindings. * cleanup new Trigger Rule example with Depl. file. * fix unbound depl. file for trigger rule. * Add new triggerrule example to example index in guide .md file. * fix source code links. * fix source code links. * fix source code links. * fix source code links. * fix source code links. * fix source code links. --- .../deployment_hello_world_triggerrule.yaml | 9 -- ...eployment_hello_world_triggerrule_bindings.yaml | 10 ++ ...deployment_hello_world_triggerrule_unbound.yaml | 10 ++ .../manifest_hello_world_triggerrule_unbound.yaml | 28 +++++ docs/programming_guide.md | 1 + docs/wskdeploy_triggerrule_basic.md | 21 ++-- docs/wskdeploy_triggerrule_trigger_bindings.md | 117 +++++++++++++++++++++ 7 files changed, 176 insertions(+), 20 deletions(-) diff --git a/docs/examples/deployment_hello_world_triggerrule.yaml b/docs/examples/deployment_hello_world_triggerrule.yaml deleted file mode 100644 index 597eff8..0000000 --- a/docs/examples/deployment_hello_world_triggerrule.yaml +++ /dev/null @@ -1,9 +0,0 @@ -package: - hello_world: - triggers: - meetPerson: - inputs: - name: Sam - place: the Shire. - children: 13 - height: 1.2 diff --git a/docs/examples/deployment_hello_world_triggerrule_bindings.yaml b/docs/examples/deployment_hello_world_triggerrule_bindings.yaml new file mode 100644 index 0000000..b35b778 --- /dev/null +++ b/docs/examples/deployment_hello_world_triggerrule_bindings.yaml @@ -0,0 +1,10 @@ +application: + packages: + hello_world_package: + triggers: + meetPerson: + inputs: + name: Elrond + place: Rivendell + children: 3 + height: 1.88 diff --git a/docs/examples/deployment_hello_world_triggerrule_unbound.yaml b/docs/examples/deployment_hello_world_triggerrule_unbound.yaml new file mode 100644 index 0000000..f325753 --- /dev/null +++ b/docs/examples/deployment_hello_world_triggerrule_unbound.yaml @@ -0,0 +1,10 @@ +application: + package: + hello_world_package: + triggers: + meetPerson: + inputs: + name: string + place: string + children: integer + height: float diff --git a/docs/examples/manifest_hello_world_triggerrule_unbound.yaml b/docs/examples/manifest_hello_world_triggerrule_unbound.yaml new file mode 100644 index 0000000..81a07a9 --- /dev/null +++ b/docs/examples/manifest_hello_world_triggerrule_unbound.yaml @@ -0,0 +1,28 @@ +package: + name: hello_world_package + version: 1.0 + license: Apache-2.0 + actions: + hello_world_triggerrule: + function: src/hello_plus.js + inputs: + name: string + place: string + children: integer + height: float + outputs: + greeting: string + details: string + + triggers: + meetPerson: + inputs: + name: string + place: string + children: integer + height: float + + rules: + meetPersonRule: + trigger: meetPerson + action: hello_world_triggerrule diff --git a/docs/programming_guide.md b/docs/programming_guide.md index 77a48bd..aff2dbf 100644 --- a/docs/programming_guide.md +++ b/docs/programming_guide.md @@ -31,6 +31,7 @@ Each example shows the "code", that is the Package Manifest, Deployment file and - [Advanced Parameters](wskdeploy_action_advanced_parms.md#actions) - input and output parameter declarations with types, descriptions, defaults and more. - Trigger and Rule examples. - [Basic Trigger and Rule](wskdeploy_triggerrule_basic.md#triggers-and-rules) - adding a basic trigger and rule to the advanced Parameter "hello world". + - [Binding parameters in a Deployment file](wskdeploy_triggerrule_trigger_bindings.md#triggers-and-rules) - using a deployment file to bind values to a Trigger’s parameters and applying them to a compatible manifest file. <!-- - [Declaring Runtime version]() - TBD --> diff --git a/docs/wskdeploy_triggerrule_basic.md b/docs/wskdeploy_triggerrule_basic.md index 1d0d628..d5f62cf 100644 --- a/docs/wskdeploy_triggerrule_basic.md +++ b/docs/wskdeploy_triggerrule_basic.md @@ -1,7 +1,7 @@ # Triggers and Rules ## Creating a Trigger for an Action -This example shows how to create a Trigger that is compatible with the previous, more advanced "Hello world" Action, which has multiple input parameters of different types, and connect them together using a Rule. +This example shows how to create a Trigger that is compatible with the previous, more [advanced "Hello world" Action example](wskdeploy_action_advanced_parms.md#actions), which has multiple input parameters of different types, and connect them together using a Rule. ### Manifest File #### _Example: “Hello world” Action with a compatible Trigger and Rule_ @@ -43,19 +43,19 @@ $ wskdeploy -m docs/examples/manifest_hello_world_triggerrule.yaml ``` ### Invoking -First, let's try _"invoking"_ the hello_world_triggerrule' Action directly without the Trigger. +First, let's try _"invoking"_ the '```hello_world_triggerrule```' Action directly without the Trigger. ```sh $ wsk action invoke hello_world_package/hello_world_triggerrule --blocking ``` #### Result -```sh +```json "result": { "details": "You have 0 children and are 0 m. tall.", "greeting": "Hello, from " }, ``` -As you can see, the results verify that the default values (i.e., empty strings and zeros) for the input parameters on the '```hello_world_triggerrule```' Action were used to compose the '```greeting```' and '```details```' output parameters. This is as expected since we did not bind any values or provide any defaults when we defined the '```hello_world_triggerrule```' Action in the manifest file. +As you can see, the results verify that the default values (i.e., empty strings and zeros) for the input parameters on the '```hello_world_triggerrule```' Action were used to compose the '```greeting```' and '```details```' output parameters. This result is expected since we did not bind any values or provide any defaults when we defined the '```hello_world_triggerrule```' Action in the manifest file. ### Triggering @@ -70,7 +70,7 @@ which results in an Activation ID: ok: triggered /_/meetPerson with id a8e9246777a7499b85c4790280318404 ``` -The '```meetPerson```' Trigger is associated with '```hello_world_triggerrule```' Action the via the '```meetPersonRule```' Rule. We can verify that firing the Trigger indeed cause the Rule to be activated which in turn casues the Action to be invoked: +The '```meetPerson```' Trigger is associated with '```hello_world_triggerrule```' Action the via the '```meetPersonRule```' Rule. We can verify that firing the Trigger indeed cause the Rule to be activated which in turn causes the Action to be invoked: ```sh $ wsk activation list @@ -83,23 +83,22 @@ we can then use the '```hello_world_triggerrule```' Action's Activation ID to se ```sh $ wsk activation get d03ee729428d4f31bd7f61d8d3ecc043 ``` - -```yaml +to view the actual results from the action: +```json "result": { "details": "You have 13 children and are 1.2 m. tall.", "greeting": "Hello, Sam from the Shire" } ``` -which verifies that the paramters bindings of the values _"Sam"_ (name), _"the Shire"_ (place), '13' (age) and '1.2' (height) on the Trigger were passed to the Action's corresponding input parameters correctly. +which verifies that the parameter bindings of the values (i.e, _"Sam"_ (name), _"the Shire"_ (place), _'13'_ (age) and _'1.2'_ (height)) on the Trigger were passed to the Action's corresponding input parameters correctly. ### Discussion -- Firing the '```meetPerson```' Trigger correctly causes non-serialized "activations" of the associated ```meetPersonRule```' Rule and subsequently the '```hello_world_triggerrule```' Action. +- Firing the '```meetPerson```' Trigger correctly causes a series of non-blocking "activations" of the associated '```meetPersonRule```' Rule and subsequently the '```hello_world_triggerrule```' Action. - The Trigger's parameter bindings were correctly passed to the corresponding input parameters on the '```hello_world_triggerrule```' Action. ### Source code - [manifest_hello_world_triggerrule.yaml](examples/manifest_hello_world_triggerrule.yaml) -- [deployment_hello_world_triggerrule.yaml](examples/deployment_hello_world_triggerrule.yaml) - [hello_plus.js](examples/src/hello_plus.js) ### Specification @@ -116,7 +115,7 @@ For convenience, the Actions and Parameters grammar can be found here: <tr> <td><a href="wskdeploy_action_advanced_parms.md#actions"><< previous</a></td> <td><a href="programming_guide.md#guided-examples">Example Index</a></td> -<!-- <td><a href="">next >></a></td> --> + <td><a href="wskdeploy_triggerrule_trigger_bindings.md#triggers-and-rules">next >></a></td> </tr> </table> </div> diff --git a/docs/wskdeploy_triggerrule_trigger_bindings.md b/docs/wskdeploy_triggerrule_trigger_bindings.md new file mode 100644 index 0000000..31f0755 --- /dev/null +++ b/docs/wskdeploy_triggerrule_trigger_bindings.md @@ -0,0 +1,117 @@ +# Triggers and Rules + +## Using a Deployment file to bind Trigger parameters +This example builds on the previous [Trigger and Rule example](wskdeploy_triggerrule_basic.md#triggers-and-rules) and will demonstrate how to use a Deployment File to bind values to a Trigger’s input parameters and apply them against a compatible Manifest File. + +### Manifest File +Let’s use a variant of the [Manifest file from the previous example](examples/manifest_hello_world_triggerrule.yaml); however, we will leave the parameters on the ‘```meetPerson```’ Trigger unbound and having only Type declarations for each. + +#### _Example: “Hello world” Action, Trigger and Rule with no Parameter bindings_ +```yaml +package: + name: hello_world_package + ... # Package keys omitted for brevity + actions: + hello_world_triggerrule: + function: src/hello_plus.js + runtime: nodejs + inputs: + name: string + place: string + children: integer + height: float + outputs: + greeting: string + details: string + + triggers: + meetPerson: + inputs: + name: string + place: string + children: integer + height: float + + rules: + meetPersonRule: + trigger: meetPerson + action: hello_world_triggerrule +``` + +### Deployment file +Let’s create a Deployment file that is designed to be applied to the Manifest file (above) which will contain the parameter bindings (i.e., the values) for the '```meetPerson```' Trigger. + +#### _Example: Deployment file that binds parameters to the '```meetPerson```' Trigger_ +```yaml +application: + packages: + hello_world_package: + triggers: + meetPerson: + inputs: + name: Elrond + place: Rivendell + children: 3 + height: 1.88 +``` +As you can see, the package name '```hello_world_package```' and the trigger name '```meetPerson```' both match the names in the corresponding Manifest file. + +### Deploying +Provide the Manifest file and the Deployment file to the wskdeploy utility: +```sh +$ wskdeploy -m docs/examples/manifest_hello_world_triggerrule_unbound.yaml -d docs/examples/deployment_hello_world_triggerrule_bindings.yaml +``` + +### Triggering +Fire the '```meetPerson```' Trigger: +```sh +$ wsk trigger fire meetPerson +``` + +#### Result +Find the activation ID for the “```hello_world_triggerrule```’ Action that firing the Trigger initiated and get the results from the activation record: + +``` +$ wsk activation list + +3a7c92468b4e4170bc92468b4eb170f1 hello_world_triggerrule +afb2c02bb686484cb2c02bb686084cab meetPersonRule +9dc9324c601a4ebf89324c601a1ebf4b meetPerson + +$ wsk activation get 3a7c92468b4e4170bc92468b4eb170f1 + +"result": { + "details": "You have 3 children and are 1.88 m. tall.", + "greeting": "Hello, Elrond from Rivendell" +} +``` + +### Discussion +- The '```hello_world_triggerrule```' Action and the '```meetPerson```' Trigger in the Manifest file both had input parameter declarations that had no values assigned to them (only Types). +- The matching '```meetPerson```' Trigger in the Deployment file had values bound its parameters. +- The ```wskdeploy``` utility applied the parameter values (after checking for Type compatibility) from the Deployment file to the matching (by name) parameters within the Manifest file. + +### Source code +- [manifest_hello_world_triggerrule_unbound.yaml](examples/manifest_hello_world_triggerrule_unbound.yaml) +- [deployment_hello_world_triggerrule_bindings.yaml](examples/deployment_hello_world_triggerrule_bindings.yaml) +- [hello_plus.js](examples/src/hello_plus.js) + +### Specification +For convenience, the Actions and Parameters grammar can be found here: +- **[Triggers and Rules](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/specification/html/spec_trigger_rule.md#triggers-and-rules)** + +--- +<!-- + Bottom Navigation +--> +<html> +<div align="center"> +<table align="center"> + <tr> + <td><a href="wskdeploy_triggerrule_basic.md#triggers-and-rules"><< previous</a></td> + <td><a href="programming_guide.md#guided-examples">Example Index</a></td> +<!-- <td><a href="">next >></a></td> --> + </tr> +</table> +</div> +</html> -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].