OpenWhisk: Event-driven Design

Post on 16-Apr-2017

601 views 0 download

Transcript of OpenWhisk: Event-driven Design

@eljuanchosf | @altoros

OpenWhiskEvent-driven software design

by Juan Pablo Genovese, Field Cloud Foundry Engineer at Altoroswww.altoros.com

*WHAT WE DO

Altoros helps Global 2000 organizations digitize revenue streams by

integrating solutions offered by Predix and its partner ecosystem

NEW PRODUCT DEVELOPMENT USING PREDIX CATALOG AND

MICROSERVICES ARCHITECTURE

MIGRATING APPLICATIONS TO

PREDIX, PORTABILITY ASSESSMENTS

PREDIX TRAINING: FOR OPERATORS FOR DEVELOPERS

48 HR APPS& 90 DAY PROOF OF

CONCEPTS

Popular!Popular!

Delivered by GE & GE Partners

Delivered by Altoros

Predix Service Catalog

Time Series

Machine

Asset Service

Analytics

Key value

UAA

...

Service N

...

Service from partner N...

*

Buenos Aires

Oslo

London

Zurich

Sunnyvale, CA

Copenhagen

Minsk

Santa Fe

Boston

30%Female

70%Male

+5Join us on an

average month

Full Time EnablersDevOps Software Engineers

256+

FACTS ON ALTOROS

@renatco

Customers

We highly recommendAltoros to rapidly build complex applications using

cutting edge technologies. Again, great job!

Christopher Adorna, Sony Design Center, LA

“ ”

NEW PRODUCT DEVELOPMENT USING PREDIX CATALOG AND

MICROSERVICES ARCHITECTURE

MIGRATING APPLICATIONS TO PREDIX, PORTABILITY

ASSESSMENTS

PREDIX TRAINING: FOR OPERATORS FOR DEVELOPERS

48 HR APPS& 90 DAY PROOF OF

CONCEPTS

@renatco

* Altoros is Gold sponsor of Cloud Foundry Summits since 2014

Juan Pablo Genovese (JPG – No pun intended)

19+ years in IT

Mostly software development … but lots of DevOps

too.

Specialized in HA and HPLove to tango, play blues guitar &

sing

S/390 to large Cloud Computing deployments

@eljuanchosf | @altoros

It’s going to be LEGEND… (wait for it!)

@eljuanchosf | @altoros

Everybody reacts to something

@eljuanchosf | @altoros

… so, what is a reaction?Merriam Webster defines it as:

The way someone acts or feels in response to something that happens, is said, etc.

Reactions: the ability to act and move quickly in order to avoid sudden danger

@eljuanchosf | @altoros

Reactions are natural

@eljuanchosf | @altoros

Reactions… to what??

E V E N T S

@eljuanchosf | @altoros

Old is newAn event-driven architecture (EDA) is a framework that orchestrates behavior around the production, detection and consumption of events as well as the responses they evoke. An event is any identifiable occurrence that has significance for system hardware or software.

SOARESTMicroservices

CORBA - 1991!RPC

@eljuanchosf | @altoros

Back to the future?

-da

@eljuanchosf | @altoros

At least!!

(OpenWhisk)

@eljuanchosf | @altoros

Yeah. this drawing, again

@eljuanchosf | @altoros

Why?• Open Source ->https://github.com/openwhisk/openwhisk

• Easy to understand

• Integration with many of Bluemix’s services

• Swift and Javascript support

• Run Docker containers!

• Download it and run it yourself. :)

@eljuanchosf | @altoros

ConceptsTriggers

A named channel for a class of events.

Fired by using a list of k,v pairs. -> EVENT!

Can be explicitly fired by a user or by an external event source.

Rules:

Associates one trigger with one action

Actions:

Stateless code snippets that run inside OpenWhisk

Can be invoked or respond to an event

Actions can call more actions, setting chains of actions

@eljuanchosf | @altoros

Concepts / 2Feeds

A external event source that fires a trigger

Packages

A bundle of actions and feeds

Can be used together with other actions and packages

Can be explicitly fired by a user or by an external event source.

Polling:

$ wsk activation poll

@eljuanchosf | @altoros

Running it locallygit clone https://github.com/openwhisk/openwhisk.git

# Change the ansible version:sed -i -- 's/ansible=2.0.1.0-1ppa~trusty/ansible/g' openwhisk/tools/ubuntu-setup/ansible.sh

# Install docker GPGcurl -fsSL https://get.docker.com/gpg | sudo apt-key add -

# Add your username to the docker groupsudo usermod -aG docker your_username

# Install all required software(cd openwhisk/tools/ubuntu-setup && source all.sh)

@eljuanchosf | @altoros

Install CouchDB# Add repossudo add-apt-repository ppa:couchdb/stable -ysudo apt-get updatesudo apt-get install couchdb -y

# Create an admin usercurl -X PUT http://localhost:5984/_config/admins/lagavulin -d '"singlemalt"'curl -X GET http://lagavulin:singlemalt@localhost:5984/_config

# Configure the databasecp template-couchdb-local.env couchdb-local.envVim couchdb-local.env

# Initialize the databasetools/db/createImmortalDBs.sh

@eljuanchosf | @altoros

Deploy!$ ant build$ ant deploy$ ant run

… there you go!!

@eljuanchosf | @altoros

Basic usage$ echo away.js > ‘function main() { return { payload: "I just went out for lunch. Be back in a century or

so." }; }’

$ wsk action update away away.js

$ wsk action invoke --blocking away

# => ok: invoked away with id abfcdb37efe94b1a8f1807e76385027d

# => response:

# => {

# => "result": {

# => "payload": "I just went out for lunch. Be back in a century or so."

# => },

# => "status": "success",

# => "success": true

# => }

@eljuanchosf | @altoros

Async calling$ wsk action invoke away

# => ok: invoked away with id 6cf984e1fbb74f69a54f07eec508f5e3

$ wsk activation result 6cf984e1fbb74f69a54f07eec508f5e3

# => {

# => "payload": "I just went out for lunch. Be back in a century or so."

# => }

@eljuanchosf | @altoros

Parametersfunction main(params) { var name = params.name || "dude"; return { payload: "Hey, " + name + " please, I’m having lunch! DON’T BOTHER ME!" };}

@eljuanchosf | @altoros

Yessss… It supports docker.$ wsk action create --docker trying-docker hi-from-docker# => ok: created action trying-docker

$ wsk action invoke --blocking --result trying-docker# => error: {# => …# => "logs": [# => "2016-03-05T13:48:39.220147731Z stdout: ",# => "2016-03-05T13:48:39.220213883Z stdout: Hi from Docker.",# => "2016-03-05T13:48:39.220227211Z stdout: Awesome. Responses from Docker containers!",# => …# => ],# => …# => "response": {# => "result": {# => "error": "the action did not produce a valid JSON response"# => },# => "status": "action developer error",# => "success": false# => },# => …# => }

@eljuanchosf | @altoros

…DARY!!

@eljuanchosf | @altoros

27

Questions?

@eljuanchosf | @altoros

Thank you!

More tutorials and blog posts on OpenWhisk:

blog.altoros.com/tag/openwhisk