0% found this document useful (0 votes)
81 views

Apache Openwhisk

Openwhisk is an open source cloud platform that executes code in response to events from external sources. It uses a serverless and event-driven programming model where developers write actions - stateless functions in any supported language - that are dynamically run when associated triggers are fired by events. Openwhisk includes tools to easily create, deploy and manage actions, triggers, rules and APIs using its REST API and command line interface.

Uploaded by

VB SS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Apache Openwhisk

Openwhisk is an open source cloud platform that executes code in response to events from external sources. It uses a serverless and event-driven programming model where developers write actions - stateless functions in any supported language - that are dynamically run when associated triggers are fired by events. Openwhisk includes tools to easily create, deploy and manage actions, triggers, rules and APIs using its REST API and command line interface.

Uploaded by

VB SS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Apache Openwhisk

Dr.S.Padmavathi
About..
• Openwhisk is a cloud platform that executes code
in response to events
• The OpenWhisk programming model...
• Is Event-driven
• Flexible, extensible, polyglot programming model
• Open source and open ecosytem(Apache
Incubator)
• Ability to run in public, private and in hybrid
models
The OpenWhisk platform
• supports a programming model in which
developers write functional logic (called Actions),
in any supported programming language, that
can be dynamically scheduled and run in
response to associated events (via Triggers) from
external sources (Feeds) or from HTTP requests.
• includes a REST API-based Command Line
Interface (CLI) along with other tooling to support
packaging, catalog services and many popular
container deployment options.
Programming model
Working Principle
Deployment with actions in
multiple programming languages
Components
• Events drive the Serverless execution of
functional code called Actions.
• Events can come from any Event Source or
Feed service including:
– Datastores, Message Queues, Mobile and Web
Applications, Sensors, Chatbots, Scheduled tasks
(via Alarms), etc.
What is a trigger?
• Triggers are named channels for classes or
kinds of events sent from Event Sources.
What is an Action?
• Actions are stateless functions (code snippets)
that run on the OpenWhisk platform.
• Actions encapsulate application logic to be
executed in response to events.
• Actions can be invoked manually by the
OpenWhisk REST API, OpenWhisk CLI, simple
and user-created APIs or automated
What is a Rule?

• Rules are used to associate one trigger with


one action. After this kind of association is
created, each time a trigger event is fired, the
action is invoked.
What are Event Sources?
• These are services that generate events that
often indicate changes in data or carry data
themselves. Some examples of common Event
Sources include:
– Messages arriving on Message Queues
– Changes in Databases
– Changes in Document Stores
– Website or Web Application interactions
– Service APIs being invoked
– IoT Frameworks forwarding device sensor data
– etc.
Why do I need to connect actions to
event sources?
• OpenWhisk is based on an event-driven
architecture where most Actions are executed as
events happen.
• The Trigger itself is "fired" with a dictionary of key-
value pairs (i.e., the parameters) coming from the
Event Source and allows the configuration of
optional default values thus helping assure the
data is compatible with any associated Actions.
• Rules allow for the same Trigger to be associated
with multiple Actions, as well as allow for specific
automation to be enabled or disabled dynamically
without destroying the Trigger definition.
Openwhisk action execution
constraints
Runtime environments
Java EE Openwhisk environment
Scenario
Own Components..
• Controller
– Managing entities, handling trigger fires, and
routing actions invocations
• Invoker
– Launching the containers to execute the actions
• Action Containers
– Actually executing the actions
Uses..
• Ngnix-A high-performance web server and
reverse proxy
• Couch DB-A scalable, document-oriented
NoSQL database
• Kafka-A distributed, high-performing
publish/subscribe messaging system
– as Docker containers
References
• https://openwhisk.apache.org/documentation
.html
• https://www.youtube.com/watch?v=RHzQf5e
oAwc
• easiest way to start using OpenWhisk is to
install the "Standalone" OpenWhisk stack.
• a full-featured OpenWhisk stack running as a
Java process for convenience.
• Serverless functions run within Docker
containers. You will need Docker, Java and
Node.js available on your machine.
• $ git clone
https://github.com/apache/openwhisk.git
• $ cd openwhisk
• $ ./gradlew core:standalone:bootRun
• When the OpenWhisk stack is up, it will open
your browser to a functions Playground,
typically served from http://localhost:3232.
• The Playground allows you create and run
functions directly from your browser. To make
use of all OpenWhisk features, you will need
the OpenWhisk command line tool called wsk
details
• wsk property set \ --apihost
'http://localhost:3233' \ --auth
'23bc46b1-71f6-4ed5-8c54-
816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFp
XlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMD
GIwP'
Docker Compose

• $ git clone
https://github.com/apache/openwhisk-
devtools.git
• $ cd openwhisk-devtools/docker-compose
• $ make quick-start
OpenWhisk CLI (wsk)

• OpenWhisk offers the wsk Command Line


Interface (CLI) to easily create, run, and
manage OpenWhisk entities.
Whisk Deploy (wskdeploy)

• Whisk Deploy is a utility, named wskdeploy, to


help deploy and manage all your OpenWhisk
Packages, Actions, Triggers, Rules and APIs
from a single command using an application
manifest.
hello.js (Action)
• function main(params)
{
return {payload: 'Hello, ' + params.name + '
from ' + params.place};
}
Create an action called hello using hello.js:
• $ wsk action create hello hello.js
– Output:
• ok: created action hello
Invoke an action hello
• $ wsk action invoke --result hello --param
name Bernie --param place Vermont
• Output:
{ "payload": "Hello, Bernie from Vermont" }
Associate the Trigger and Action using a
Rule

Create the rule (i.e., an association):

• $ wsk rule create myRule locationUpdate hello

ok: created rule myRule


Invoke the Action by Firing the Trigger

Fire the locationUpdate trigger:

• $ wsk trigger fire locationUpdate --param name


Bob --param place NYC
ok: triggered /_/locationUpdate with id abcd...
• Verify that the action was invoked by checking
the activations list:
• $ wsk activation list --limit 2
• Output:
activations 1234.... hello abcd…locationUpdate
• Retrieving the trigger activation record:

• $ wsk activation result 1234....


Output:
{ "payload": "Hello, Bob from NYC" }

You might also like