Slide 1

Slide 1 text

Functions as a Service with Apache OpenWhisk and OpenShift Brendan McAdams [email protected] 1

Slide 2

Slide 2 text

Functions as a Service (aka "serverless") — Deploy code functions easily - no server setup1 — Event Driven - respond to events by invoking functions — Functions are loaded and executed On Demand — BYO Programming Language — Use a hosted platform with AWS Lambda, Red Hat Cloud Functions2, etc… — or, be adventurous: build your own OpenWhisk install! 2 Red Hat's OpenShift based version of OpenWhisk 1 Once your serverless platform is running 2

Slide 3

Slide 3 text

Introducing Apache OpenWhisk — Fully Open Source, Apache 2 Licensed — Functions (Actions) are the centerpiece of your code — Deploy on the cloud (public or private!) of your choice 3

Slide 4

Slide 4 text

Introducing Apache OpenWhisk Functions — Functions can be written in any supported language including Node, Java, and Python — Use your functions for cool stuff — Event Triggers (e.g., call it when the contents of an S3 bucket change) — Chain them, composing small functions together for larger behavior 4

Slide 5

Slide 5 text

OpenWhisk & Red Hat — Red Hat is working to improve and expand upon Apache OpenWhisk, including the integration of our software portfolio — Recently contributed Kubernetes support upstream — Needed to run OpenWhisk on OpenShift — Created templates to simplify setup of OpenWhisk on OpenShift https:// github.com/projectodd/openwhisk-openshift — Working on AMQP Feed Support for OpenWhisk 5

Slide 6

Slide 6 text

Loading OpenWhisk on OpenShift — We provide a template for loading OpenWhisk into OpenShift, which installs and configures all of the components: oc process -f https://git.io/openwhisk-template | oc create -f - 6

Slide 7

Slide 7 text

OpenWhisk Actions — An Action is the basic unit of work with OpenWhisk, containing your function — Actions are stateless — Invoking an action generations an "activation id" that can be used to retrieve results — Actions can be chained together using sequences 7

Slide 8

Slide 8 text

Sample Action hello.py def main(args): name = args.get('name', 'stranger') greeting = 'Hello ' + name + '!' return {'greeting': greeting} 8

Slide 9

Slide 9 text

Sample Action hello.py def main(args): name = args.get('name', 'stranger') greeting = 'Hello ' + name + '!' return {'greeting': greeting} 9

Slide 10

Slide 10 text

Sample Action hello.py def main(args): name = args.get('name', 'stranger') greeting = 'Hello ' + name + '!' return {'greeting': greeting} 10

Slide 11

Slide 11 text

Creating an Action hello.py To create an action, we need to give it a name and configure it in OpenWhisk: $ wsk -i action create helloPy hello.py ok: created action helloPy 11

Slide 12

Slide 12 text

Invoking an Action hello.py Once it has a name, an action can be invoked directly: $ wsk -i action invoke --result helloPy --param name "Brendan McAdams" { "greeting": "Hello Brendan McAdams!" } 12

Slide 13

Slide 13 text

Action Sequences mungeHello Multiple functions can be chained together using sequences where the output of a function is the input to a subsequent function*. Let's use this function to change the input name before calling hello… def main(args): name = args.get('name', 'Nosuch Person').split(" ") name.reverse() return {'name': ", ".join(name)} * Make sure your output and input parameter names match up! 13

Slide 14

Slide 14 text

Action Sequences mungeHello Our new function just splits the input name into "Surname, First Name": $ wsk -i action invoke --result alphaName --param name "Brendan McAdams" { "name": "McAdams, Brendan" } 14

Slide 15

Slide 15 text

Action Sequences mungeHello To create a sequence, the individual actions must already be created. Their names are the keys for the new sequence. With this setup, alphaName is called first, with its output being fed to helloPy. The response from OpenWhisk is the output of helloPy. $ wsk -i action create mungeHello --sequence alphaName,helloPy ok: created action mungeHello 15

Slide 16

Slide 16 text

Action Sequences mungeHello Invoking a sequence is no different than a normal action: just call it by the sequence name: $ wsk -i action invoke --result mungeHello --param name "Brendan McAdams" { "greeting": "Hello McAdams, Brendan!" } 16

Slide 17

Slide 17 text

Triggers & Rules — Triggers are channels for events — Triggers can be linked, via rules, to one or more actions — Example - A trigger named uploadPhoto might, when invoked, call several actions: nsfwFilter, generateThumbnail, and parseLocation — When the uploadPhoto trigger is called, the rule forwards the invocation parameters to each of the 3 linked actions. 17

Slide 18

Slide 18 text

Feeds & Packages — OpenWhisk supports the idea of pre-packaging functionality in a package — Packages bundle together Actions and Feeds, allowing us to bundle related code to deploy an event driven workflow — Feeds are similar to Triggers, but act as a stream receiving multiple event types — Packages allow us to bundle together related code to easily deploy a event driven workflow — Prebuilt packages include support for Alarms, RSS Feeds, Kafka Integration, and more. 18

Slide 19

Slide 19 text

Feeds & Packages Feeds — Packages can also provide feeds, which configure external event sources. — Example: OpenWhisk includes a prebuilt 'alarms' package which can let us create cron-like repeating behaviors. wsk trigger create interval \ --feed /whisk.system/alarms/interval \ --param minutes 2 \ --param trigger_payload "{\"name\":\"Odin\",\"place\":\"Asgard\"}" \ --param stopDate "2019-01-31T23:59:00.000Z" 19

Slide 20

Slide 20 text

Questions? Brendan McAdams 20