Apache OpenWhisk provides a powerful and flexible environment for deploying cloud-native applications driven by data, message, and API call events. We will show how and why we integrated Apache OpenWhisk and GitHub to make deployment as easy and transparent as `git push`. We will also discuss the benefit of using an open source cloud platform and explain how serverless allows developers to focus on writing value-adding code.
8. Apache OpenWhisk
Apache OpenWhisk is a serverless, open source cloud platform
that allows you to execute code in response to events at any scale.
OpenWhisk handles the infrastructure and servers so you can
focus on building amazing things.
- http://openwhisk.incubator.apache.org/about.html -
13. Manage the system
OpenWhisk offer:
●
Command line interface to mangare all the aspect of the system
IBM BlueMix offer:
●
Graphic editor
14. Activate the CLI
There are two required properties to configure in order to use the CLI:
●
API host (name or IP address) for the OpenWhisk deployment you
want to use.
●
Authorization key (username and password) which grants you access
to the OpenWhisk API.
./bin/wsk property set --apihost <openwhisk_baseurl>
./bin/wsk property set --auth `auth.guest`
15. wskadmin
Tool to generate a new namespace and authentication, manage
application servers as well as the configuration, application
deployment, and server runtime operations.
It can provide below functions:
●
management for users and limitations
●
query of db and system log
16. Actions
●
Actions are stateless code snippets that run on the OpenWhisk
●
Can be explicitly invoked, or run in response to an event
●
The result of an action are a dictionary of key-value pairs
17. Triggers
●
Let you specify outside sources as a way to kick off an action
●
Can be fired by using a dictionary of key-value pairs
●
Can be explicitly fired by a user or by an external event source
18. Rules
●
Allow actions to react to the events
●
Associates one trigger with one action
●
Can be explicitly fired by a user or by an external event source
19. Show me the code 1/2
/**
* main() will be invoked when you Run This Action
* @param OpenWhisk actions accept a single parameter, which must be a JSON object.
* @return The output of this action, which must be a JSON object.
*/
const request = require('request-promise');
function main(params) {
return request({
url: "http://myhost.mybluemix.net/addtoimc",
method: "POST",
headers: {"Content-Type": "text/plain"}
}).then(response => {
if(response.success) {
return Promise.resolved({message: "nice"});
} else {
return Promise.rejected({error: "it broke"});
} }); }
20. Show me the code 2/2
$ wsk trigger create trgexample
ok: created trigger trgeample
$ wsk action create actexample index.js
ok: created action actexample
$ wsk rule create rulexample trgexample actexmple
ok: created rule rulexample
$wsk action invoke actexample--blocking --result main
curl -u "yourUserName":"yourPassword" -H "Content-Type: application/json" -X POST
https://MyIPAddress/api/v1/namespaces/myaccount/actions/actexample/main?
blocking=true
21. Packages
●
It's a combination of other actions/triggers/rules that you can
link to your own stuff
●
Can include actions and feeds.
– Actions: a piece of code that runs on OpenWhisk
– Feeds: configure external event or fire trigger event