Community Blog Serverless Engineering Practices | The Self-Built Apache OpenWhisk Platform

Serverless Engineering Practices | The Self-Built Apache OpenWhisk Platform

This article explains the deployment and testing of the OpenWhisk project.

An Introduction to OpenWhisk

OpenWhisk is a cloud-based distributed event-driven programming service. OpenWhisk provides a programming model to register event handlers with cloud services to handle various services. It can support thousands of triggers and calls and can respond to events of different sizes. OpenWhisk contains many components that make OpenWhisk an excellent open-source FaaS platform.

Component Structure of Apache OpenWhisk

OpenWhisk Deployment

The operating system of the experimental machine is Ubuntu 18.04 Desktop. Use the incubator-openwhisk provided on GitHub to install it. If Git is not installed on this machine, install it first:

apt install git

Next, clone the repo to the local directory:

git clone https://github.com/apache/incubator-openwhisk.git openwhisk

After cloning is completed, it is displayed as shown in the figure below:

Apache OpenWhisk Project Clone

Go to the OpenWhisk directory and execute the script. OpenWhisk is developed by Scala and requires a Java environment to run. The following script implements the installation of the Java environment and other required software:

cd openwhisk && cd tools/ubuntu-setup && ./all.sh

The Apache OpenWhisk installation and configuration is shown in the figure below:

Apache OpenWhisk Installation and Configuration

OpenWhisk uses ansible for deployment. Environment variables are defined under ansible/environments/group_vars/all:

limits:invocationsPerMinute: "{{ limit_invocations_per_minute | default(60) }}"concurrentInvocations: "{{ limit_invocations_concurrent | default(30) }}"concurrentInvocationsSystem:  "{{ limit_invocations_concurrent_system | default    (5000) }}"firesPerMinute: "{{ limit_fires_per_minute | default(60) }}"sequenceMaxLength: "{{ limit_sequence_max_length | default(50) }}"

The preceding program defines the limitations of OpenWhisk in the system.

invocationsPerMinute indicates the number of Actions called per minute for the same Namespace.
concurrentInvocations indicates the number of concurrent calls for the same Namespace.
concurrentInvocationsSystem indicates the number of concurrent calls for all Namespaces in the system.
firesPerMinute indicates the number of triggers called per minute in the same Namespace.
sequenceMaxLength indicates the maximum sequence length of an Action.

If you need to modify the preceding default values, you can add the modified values to the file.

The end of the ansible/environments/local/group_vars/all.

For example, if the maximum sequence length of an Action is 100, you can add sequenceMaxLength: 120 to the end of the file. Next, configure a database with persistent storage for OpenWhisk; CouchDB and Cloudant are optional. Use CouchDB as an example to configure the environment:

export OW_DB=CouchDBexport OW_DB_USERNAME=rootexport OW_DB_PASSWORD=PASSWORDexport OW_DB_PROTOCOL=httpexport OW_DB_HOST= OW_DB_PORT=5984

In the openwhisk/ansible directory, run the script, as shown in the image below:

ansible-playbook -i environments/local/ setup.yml

Script Execution Procedure

Next, use CouchDB to deploy OpenWhisk to ensure that you have db_local.ini locally. Run the following command in the openwhisk/directory:

./gradlew distDocker

If problems occur during deployment (as shown in the following figure), it may be caused by not installing npm. In this case, you can execute the following instructions:

Examples of Possible Error Reports during Deployment

apt install npm

Wait a moment and you can see the Build success page, as shown in the image below:

Build Success Example

Next, go to the openwhisk/ansible directory:

ansible-playbook -i environments/local/ couchdb.ymlansible-playbook -i environments/local/ initdb.ymlansible-playbook -i environments/local/ wipe.ymlansible-playbook -i environments/local/ apigateway.ymlansible-playbook -i environments/local/ openwhisk.ymlansible-playbook -i environments/local/ postdeploy.yml

The process of executing the script is shown in the figure:

Script Execution Procedure

After successful deployment, OpenWhisk starts several Docker containers in the system. We can use docker ps to view:

docker ps --format "{{.Image}} \t {{.Names }}"

The list of containers after successful installation is shown in the figure below:

The List of Containers after Successful Installation

Developer Tools

OpenWhisk provides a unified command line interface wsk. The generated wsk is under openwhisk/bin. It has two properties that need to be configured:

  1. The API host is used to deploy the host name or IP address of OpenWhisk.
  2. The Authorization key (username or password) is used to authorize the API to operate OpenWhisk.

Set the API host. The IP in the standalone configuration should be, as shown in the figure below:

./bin/wsk property set --apihost ''

Set API Host

Set key:

./bin/wsk property set --auth `cat ansible/files/auth.guest

The permission settings are shown in the figure below:

Set Permissions

OpenWhisk stores the configuration information of the CLI in ~/.wskprops. The location of this file can also be specified by the environment variable WSK_CONFIG_FILE.

Verify the CLI:

wsk action invoke /whisk.system/utils/echo –p message hello –result{    "message": "hello"}

Experience Tests

Create a simple action with the following code:

# test.pydef main(args):    num = args.get("number", "30")    return {"fibonacci": F(int(num))}def F(n):    if n == 0:        return 0    elif n == 1:        return 1    else:        return F(n - 1) + F(n - 2)

Create an action:

/bin/wsk action create myfunction ./test.py  --insecure

Function creation is shown in the figure below:

Create a Function

Trigger action:

./bin/wsk -i action invoke myfunction --result --blocking --param nember 20

The result is shown below:

Execute a Function

So far, we have completed the deployment and testing of the OpenWhisk project.

0 0 0
Share on

Alibaba Cloud Serverless

49 posts | 6 followers

You may also like


Alibaba Cloud Serverless

49 posts | 6 followers

Related Products

  • Message Queue for Apache Kafka

    A fully-managed Apache Kafka service to help you quickly build data pipelines for your big data analytics.

    Learn More
  • Link IoT Edge

    Link IoT Edge allows for the management of millions of edge nodes by extending the capabilities of the cloud, thus providing users with services at the nearest location.

    Learn More
  • AlibabaMQ for Apache RocketMQ

    AlibabaMQ for Apache RocketMQ is a distributed message queue service that supports reliable message-based asynchronous communication among microservices, distributed systems, and serverless applications.

    Learn More
  • Elastic High Performance Computing Solution

    High Performance Computing (HPC) and AI technology helps scientific research institutions to perform viral gene sequencing, conduct new drug research and development, and shorten the research and development cycle.

    Learn More