Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit ae308c7

Browse files
authored
Update README.md
1 parent 490b82e commit ae308c7

File tree

1 file changed

+72
-21
lines changed

1 file changed

+72
-21
lines changed

README.md

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ tool called [IBM Cloud Shell](https://github.com/ibm-functions/shell), or just
1818
_Shell_. Shell offers a CLI and graphical interface for fast, incremental,
1919
iterative, and local development of serverless applications. While we recommend
2020
using Shell, Shell is not required to work with compositions. Compositions may
21-
be managed using a combination of the Composer [compose](bin/compose) shell
22-
script (for deployment) and the [OpenWhisk
21+
be managed using a combination of the Composer [compose](bin/compose) command
22+
(for deployment) and the [OpenWhisk
2323
CLI](https://console.bluemix.net/openwhisk/learn/cli) (for configuration,
2424
invocation, and life-cycle management).
2525

26-
**In contrast to earlier releases of Composer, a REDIS server is not required to
26+
**In contrast to earlier releases of Composer, a Redis server is not required to
2727
run compositions**. Composer now synthesizes OpenWhisk [conductor
2828
actions](https://github.com/apache/incubator-openwhisk/blob/master/docs/conductors.md)
2929
to implement compositions. Compositions have all the attributes and capabilities
@@ -33,7 +33,7 @@ export).
3333
This repository includes:
3434
* the [composer](composer.js) Node.js module for authoring compositions using
3535
JavaScript,
36-
* the [compose](bin/compose) shell script for deploying compositions,
36+
* the [compose](bin/compose) command for deploying compositions,
3737
* [documentation](docs), [examples](samples), and [tests](test).
3838

3939
Composer and Shell are currently available as _IBM Research previews_. As
@@ -43,26 +43,30 @@ compositions should continue to run fine without redeployment.
4343

4444
## Installation
4545

46-
To install the `composer` module use the Node Package Manager:
46+
Composer is distributed as Node.js package. To install this package, use the
47+
Node Package Manager:
4748
```
4849
npm -g install @ibm-functions/composer
4950
```
50-
We recommend to install the module globally (with `-g` option) so the `compose`
51-
command is added to the path. Otherwise, it can be found in the `bin` folder of
52-
the module installation.
51+
We recommend to install the package globally (with `-g` option) if you intend to
52+
use the `compose` command to define and deploy compositions. Use a local install
53+
(without `-g` option) if you intend to use `node` instead. The two installations
54+
can coexist. Shell embeds the Composer package, so there is no need to install
55+
Composer explicitly when using Shell.
5356

54-
## Example
57+
## Defining a composition
5558

56-
A composition is typically defined by means of a Javascript file as illustrated
57-
in [samples/demo.js](samples/demo.js):
59+
A composition is typically defined by means of a Javascript expression as
60+
illustrated in [samples/demo.js](samples/demo.js):
5861
```javascript
5962
composer.if(
6063
composer.action('authenticate', { action: function main({ password }) { return { value: password === 'abc123' } } }),
6164
composer.action('success', { action: function main() { return { message: 'success' } } }),
6265
composer.action('failure', { action: function main() { return { message: 'failure' } } }))
6366
```
64-
Composer offers traditional control-flow concepts as methods. These methods
65-
are called _combinators_. This example composition composes three actions named
67+
Compositions compose actions using _combinator_ methods. These methods
68+
implement the typical control-flow constructs of a sequential imperative
69+
programming language. This example composition composes three actions named
6670
`authenticate`, `success`, and `failure` using the `composer.if` combinator,
6771
which implements the usual conditional construct. It take three actions (or
6872
compositions) as parameters. It invokes the first one and, depending on the
@@ -74,35 +78,78 @@ result of this invocation, invokes either the second or third action.
7478
```javascript
7579
composer.if('authenticate', 'success', 'failure')
7680
```
77-
To deploy this composition use the `compose` command:
81+
82+
## Deploying a composition
83+
84+
One way to deploy a composition is to use the `compose` command:
7885
```
7986
compose demo.js --deploy demo
8087
```
81-
The `compose` command synthesizes and deploy an action named `demo` that
88+
```
89+
ok: created /_/authenticate,/_/success,/_/failure,/_/demo
90+
```
91+
The `compose` command synthesizes and deploys an action named `demo` that
8292
implements the composition. It also deploys the composed actions if definitions
8393
are provided for them.
8494

95+
## Running a composition
96+
8597
The `demo` composition may be invoked like any action, for instance using the
8698
OpenWhisk CLI:
8799
```
88-
wsk action invoke demo -r -p password passw0rd
100+
wsk action invoke demo -p password passw0rd
101+
```
102+
```
103+
ok: invoked /_/demo with id 4f91f9ed0d874aaa91f9ed0d87baaa07
104+
```
105+
The result of this invocation is the result of the last action in the
106+
composition, in this case the `failure` action since the password in incorrect:
107+
```
108+
wsk activation result 4f91f9ed0d874aaa91f9ed0d87baaa07
89109
```
90110
```json
91111
{
92112
"message": "failure"
93113
}
94114
```
115+
## Execution traces
116+
117+
This invocation creates a trace, i.e., a series of activation records:
118+
```
119+
wsk activation list
120+
```
121+
```
122+
activations
123+
fd89b99a90a1462a89b99a90a1d62a8e demo
124+
eaec119273d94087ac119273d90087d0 failure
125+
3624ad829d4044afa4ad829d40e4af60 demo
126+
a1f58ade9b1e4c26b58ade9b1e4c2614 authenticate
127+
3624ad829d4044afa4ad829d40e4af60 demo
128+
4f91f9ed0d874aaa91f9ed0d87baaa07 demo
129+
```
130+
The entry with the earliest start time (`4f91f9ed0d874aaa91f9ed0d87baaa07`)
131+
summarizes the invocation of the composition while other entries record later
132+
activations caused by the composition invocation. There is one entry for each
133+
invocation of a composed action (`a1f58ade9b1e4c26b58ade9b1e4c2614` and
134+
`eaec119273d94087ac119273d90087d0`). The remaining entries record the beginning
135+
and end of the composition as well as the transitions between the composed
136+
actions.
137+
138+
Compositions are implemented by means of OpenWhisk conductor actions. The
139+
[documentation of conductor
140+
actions](https://github.com/apache/incubator-openwhisk/blob/master/docs/conductors.md)
141+
explains execution traces in greater details.
95142

96143
## Getting started
97-
* [Introduction to Serverless Composition](docs/tutorials/introduction/README.md):
98-
Setting up your programming environment and getting started with Shell and
99-
Composer.
144+
* [Introduction to Serverless
145+
Composition](docs/tutorials/introduction/README.md): Setting up your
146+
programming environment and getting started with Shell and Composer.
100147
* [Building a Translation Slack Bot with Serverless
101148
Composition](docs/tutorials/translateBot/README.md): A more advanced tutorial
102149
using Composition to build a serverless Slack chatbot that does language
103150
translation.
104-
* [Composer Reference](docs/README.md): A comprehensive reference manual for
105-
the Node.js programmer.
151+
* [Composer Reference](docs/README.md): A comprehensive reference manual for the
152+
Node.js programmer.
106153

107154
## Videos
108155
* The [IBM Cloud Shell YouTube
@@ -133,6 +180,10 @@ wsk action invoke demo -r -p password passw0rd
133180
applications](https://medium.com/openwhisk/composing-functions-into-applications-70d3200d0fac)
134181
* [A composition story: using IBM Cloud Functions to relay SMS to
135182
email](https://medium.com/openwhisk/a-composition-story-using-ibm-cloud-functions-to-relay-sms-to-email-d67fc65d29c)
183+
* [Data Flows in Serverless Cloud-Native
184+
Applications](http://heidloff.net/article/serverless-data-flows)
185+
* [Transforming JSON Data in Serverless
186+
Applications](http://heidloff.net/article/transforming-json-serverless)
136187

137188
## Contributions
138189
We are looking forward to your feedback and criticism. We encourage you to [join

0 commit comments

Comments
 (0)