OpenWhisk supports actions written in JavaScript, Swift, Java and Python. In this talk, we explore the internals of OpenWhisk to learn how these actions are created, stored, and executed. We dive into the (internal) specification that makes supporting such a variety of runtimes feasible, and illustrate it by implementing, as a running example, support for a new language.
This material was first presented at the New York City Cloud Foundry Meetup http://www.meetup.com/nyc-cloud-foundry/events/231908970/
Supporting code is available from the branch https://github.com/psuter/openwhisk/tree/meetup-0721
1. OpenWhisk Deep
Dive
The
action
container
model
Philippe
Suter
OpenWhisk Meetup,
July
21st,
NYC
@psuter
2. Please
Note
• IBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s sole discretion.
• Information regarding potential future products is intended to outline our general product direction and it should not be relied on in
making a purchasing decision.
• The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any
material, code or functionality. Information about potential future products may not be incorporated into any contract.
• The development, release, and timing of any future features or functionality described for our products remains at our sole discretion.
• Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual
throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the
amount of multiprogramming in the user’s job stream, the I/O configuration, the storage configuration, and the workload processed.
Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.
3. On
the
menu
tonight
1. “What
happens
when
I
create
and
invoke
actions?”
• Action
containers
• Lifecycle
• (Internal)
action
API
2. Hands-‐on!
Adding
new
language
support
to
OpenWhisk.
• (in
addition
to
JavaScript,
Swift,
Java,
Python,
Docker containers)
4. OpenWhisk Core
– System
Architecture
4
Edge
Proxy
Log
Forwarder
UI
Consul
Registrator
Log Forwarder
EntitlementController
Slave
ESlave
Execution
Engine
E
Registrator
Log Forwarder
Invoker Executor
Executor
Executor
Master
7. Action
invocation
(blocking)
Controller Invoker
DB
/$
POST /api/v1/…/hello
{ “name”: “…” }
OK
{ “greeting”: … }
Invoke: user:hello
Params: { “name”: “…” }
GET OK
{ … “exec”: “…” }
• Locate
or
initialize
container
for
action
• Run
container
with
input
parameters
PUT
{ “greeting” : “hello” }
Result: { “greeting”: … }
/$ wsk -‐v action invoke –b hello-‐js -‐p ...
8. Action
invocation
(non-‐blocking)
Controller Invoker
DB
/$
POST /api/v1/…/hello
{ “name”: “…” }
OK
Invoke: user:hello
Params: { “name”: “…” }
GET OK
{ … “exec”: “…” }
• Locate
or
initialize
container
for
action
• Run
container
with
input
parameters
PUT
{ “greeting” : “hello” }
/$ wsk -‐v action invoke hello-‐js -‐p ...
9. Action
containers
input
(JSON
object) output
(JSON
object)
stdout(strings)
stderr(strings)
Function
Action
container
• Host
user-‐written
function
• Maintain
the
illusion
that
“action
≈
function”
• Provide
a
simple
REST
API
to:
• Initialize
the
container
• Run
the
function
10. Action
container
lifecycle
docker run POST /init
POST /run
(Additionally:
docker unpause /
docker pause before
/
after
each
POST.)
docker rm
11. Action
container
API
POST /init POST /run
Input
{
“value” : {
“name” : “action-‐name”,
“code” : “function main …”
“main” : “main”
}
}
OK
(status code
should
be
200,
output
is
ignored)
Output
{
“value” : {
“name” : ”Mike”,
...
}
}
{
“greeting” : “hello...”,
...
}
Not
publicly
documented,
may
and
will
change
without
notice.
12. Action
containers
implementation
overview
HTTP
proxy JSON /init /run
Node.js Express Native
eval(…) script, keep
function
object
in
memory.
Function
invocation.
Swift Flask
(Python)
Implicit:
Foundation
(NSJSONSerialization)
Compile
script,
store
binary.
Run binary
with
subprocess.
Java
com.sun.net.httpserver.
HttpServer
Explicit:
Google
GSON
Dynamic
classloading,
reflection
to
get
handle
to
main.
Reflective invoke.
Python Flask Implicit:
stdlib
(import json)
Store
script
in
memory.
Evaluatescript
with
exec(…).
13. Hands
on!
• Let’s
add
support
for
PHP
to
OpenWhisk.
• Steps:
1. Build
a
PHP
action
container
2. Unit-‐test
the
action
container
3. Add
CLI
support
for
PHP
action
creation
4. Add
internal
representation
of
PHP
actions
5. Add
invoker
support
14. Carpe
Diem
• OpenWhisk evolves:
these
slides
may
be
outdated
at
any
time
• Works
as
of
28fd62a3 (07/21/2016,
10am
Eastern)
• All code
is
available at:
• https://github.com/psuter/openwhiskbranch meetup-‐0721
15. Action
containers
overview
HTTP
proxy JSON /init /run
Node.js Express Native
eval(…) script, keep
function
object
in
memory.
Function
invocation.
Swift Flask
(Python)
Implicit:
Foundation
(NSJSONSerialization)
Compile
script,
store
binary.
Run binary
with
subprocess.
Java
com.sun.net.httpserver.
HttpServer
Explicit:
Google
GSON
Dynamic
classloading,
reflection
to
get
handle
to
main.
Reflective invoke.
Python Flask Implicit:
stdlib
(import json)
Store
script
in
memory.
Evaluatescript
with
exec(…).
PHP
Built-‐in
web
server
(php –S …)
Implicit:
stdlib
(json_decode/json_encode)
Store
script
in file.
Evaluate
script
with
eval(…).
19. CLI
support
• Auto-‐detect
action
kind
based
on
file
extension
• Same
technique
as
for
JavaScript,
Swift,
Python
20. Controller
&
invoker
changes
• Support
php kind
in
whisk.core.entity.Exec
• Internal
Scala
representation
+
JSON
(de)serialization
for
REST
API
and
DB
• Lets
the
controller
accept
PHP
action
creations
• Lets
the
invoker
accept
PHP
action
invocation
requests
• Add
PHP
case
in
whisk.core.entity.WhiskAction
• Tells
the
invoker
how
to
craft
the
/init payload
for
PHP
actions.
24. Notices
and
Disclaimers
Continued
Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not
tested those products in connection with this publication and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products.
Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. IBM does not warrant the quality of any third-party products, or the
ability of any such third-party products to interoperate with IBM’s products. IBM EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The provision of the information contained h erein is not intended to, and does not, grant any right or license under any IBM patents, copyrights, trademarks or other intellectual
property right.
IBM, the IBM logo, ibm.com, Aspera®, Bluemix, Blueworks Live, CICS, Clearcase, Cognos®, DOORS®, Emptoris®, Enterprise Document Management System™, FASP®,
FileNet®, Global Business Services ®, Global Technology Services ®, IBM ExperienceOne™, IBM SmartCloud®, IBM Social Business®, Information on Demand, ILOG,
Maximo®, MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™, PureApplication®, pureCluster™, PureCoverage®, PureData®,
PureExperience®, PureFlex®, pureQuery®, pureScale®, PureSystems®, QRadar®, Rational®, Rhapsody®, Smarter Commerce®, SoDA, SPSS, Sterling Commerce®,
StoredIQ, Tealeaf®, Tivoli®, Trusteer®, Unica®, urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and System z® Z/OS, are trademarks of International Business
Machines Corporation, registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM
trademarks is available on the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.