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

Commit c7cfd7f

Browse files
authored
Use conductor actions to implement compositions (#37)
Composer now generates conductor actions to implement compositions. This resolves double billing and restores substitution. Compositions support blocking invocations and may be designated as web actions. Redis is no longer required to run compositions.
 The JSON serialization format has evolved to retain the original code structure (sequences, conditionals...). The compilation to finite state machines now happens when the action container is initialized.
 The scheduling code is now stitched to the composition JSON to produce a self-contained action that implements the composition, resolving possible versioning or dangling reference issues. New constructs have been added including finally and dowhile. A composition may now include the definition of component actions and compositions. 
A compose shell script is provided to serialize compositions to the JSON format and deploy them. An extension of the Javascript client for OpenWhisk can do the same. Deployment takes care of nested actions and compositions. The composer module now regroups the client-side and server-side code in one file.
1 parent f3f2e5e commit c7cfd7f

File tree

12 files changed

+1169
-1127
lines changed

12 files changed

+1169
-1127
lines changed

README.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
Composer is a new programming model from [IBM
66
Research](https://ibm.biz/serverless-research) for composing [IBM
77
Cloud Functions](https://ibm.biz/openwhisk), built on [Apache
8-
OpenWhisk](https://github.com/apache/incubator-openwhisk). Composer
9-
extends Functions and sequences with more powerful control flow and
10-
automatic state management. With it, developers can build even more
8+
OpenWhisk](https://github.com/apache/incubator-openwhisk).
9+
With composer, developers can build even more
1110
serverless applications including using it for IoT, with workflow
1211
orchestration, conversation services, and devops automation, to name a
1312
few examples.
1413

15-
Composer helps you express cloud-native apps that are serverless by
16-
construction: scale automatically, and pay as you go and not for idle
17-
time. Programming compositions for IBM Cloud Functions is done via the
18-
[functions shell](https://github.com/ibm-functions/shell), which
14+
Composer extends Functions and sequences with more powerful control
15+
flow and automatic state management.
16+
Composer helps express cloud-native apps that are serverless by
17+
construction: scale automatically, pay as you go and not for idle time.
18+
19+
The [IBM Cloud functions shell](https://github.com/ibm-functions/shell)
1920
offers a CLI and graphical interface for fast, incremental, iterative,
2021
and local development of serverless apps. Some additional highlights
2122
of the shell include:
2223

23-
* Edit your code and program using your favorite text editor, rather than using a drag-n-drop UI
24-
* Validate your compositions with readily accessible visualizations, without switching tools or using a browser
25-
* Deploy and invoke compositions using familiar CLI commands
26-
* Debug your invocations with either familiar CLI commands or readily accessible visualizations
24+
* Edit your code and program using your favorite text editor, rather than using a drag-n-drop UI.
25+
* Validate compositions with readily accessible visualizations, without switching tools or using a browser.
26+
* Deploy and invoke compositions using familiar CLI commands.
27+
* Debug invocations with either familiar CLI commands or readily accessible visualizations.
2728

2829
Composer and shell are currently available as IBM Research
2930
previews. We are excited about both and are looking forward to what
@@ -39,11 +40,9 @@ you to [join us on slack](http://ibm.biz/composer-users).
3940

4041
This repository includes:
4142

42-
* [tutorial](docs) for getting started with Composer in the [docs](docs) folder,
43-
* [composer](composer.js) node.js module to author compositions using JavaScript,
44-
* [conductor](conductor.js) action code to orchestrate the execution of compositions,
45-
* [manager](manager.js) node.js module to query the state of compositions,
46-
* [test-harness](test-harness.js) helper module for testing composer,
47-
* [redis-promise](redis-promise.js) helper module that implements a promisified redis client for node.js,
43+
* a [composer](composer.js) node.js module to author compositions using JavaScript,
44+
* a [compose](bin/compose) shell script for deploying compositions,
45+
* a [tutorial](docs/README.md),
46+
* a [reference manual](docs/COMPOSER.md),
4847
* example compositions in the [samples](samples) folder,
49-
* unit tests in the [test](test) folder.
48+
* tests in the [test](test) folder.

bin/compose

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
const fs = require('fs')
6+
const vm = require('vm')
7+
const minimist = require('minimist')
8+
const composer = require('../composer')
9+
10+
const argv = minimist(process.argv.slice(2), { string: ['apihost', 'auth', 'deploy'], boolean: 'insecure', alias: { auth: 'u', insecure: 'i' } })
11+
12+
if (argv._.length !== 1) {
13+
console.error('Usage: compose <composition.js[on]> [--deploy <name>] [--apihost <host>] [--auth <key>] [--insecure]')
14+
return
15+
}
16+
17+
const filename = argv._[0]
18+
const source = fs.readFileSync(filename, { encoding: 'utf8' })
19+
const composition = filename.slice(filename.lastIndexOf('.')) === '.js' ? vm.runInNewContext(source, { composer, require, console, process }) : composer.deserialize(JSON.parse(source))
20+
if (argv.deploy) {
21+
const options = { ignore_certs: argv.insecure }
22+
if (argv.apihost) options.apihost = argv.apihost
23+
if (argv.auth) options.api_key = argv.auth
24+
composer.openwhisk(options).compositions.deploy(composition,argv.deploy).catch(console.error)
25+
} else {
26+
console.log(JSON.stringify(composition, null, 4))
27+
}

0 commit comments

Comments
 (0)