/openwhisk-runtime-ballerina

Apache OpenWhisk runtime for Ballerina

Primary LanguageJava

Apache OpenWhisk Runtime for Ballerina

License Build Status

This repository contains the Ballerina runtime for the Apache OpenWhisk serverless platform.

Prerequisites

The following prerequisites are needed to try this out:

Creating a Ballerina function

Create a file hello.bal for your Ballerina function with the following code:

import ballerina/io;
function main(string... args) {
  io:println("started");
}
function run(json jsonInput) returns json {
  io:println(jsonInput);
  json output = { "response": "hello-world"};
  return output;
}

The Ballerina file should include:

  • main(string... args) and
  • run(json jsonInput).

The first is necessary to compile the function but does not execute when you invoke the action.

Compiling your function

Run the Ballerina compiler to build your function.

ballerina build hello.bal

This generates an executable hello.balx. You will use this binary to create the OpenWhisk action.

Creating and invoking your Ballerina action

Use the OpenWhisk wsk CLI to create your Ballerina action.

wsk action create hello hello.balx --docker mpmunasinghe/balaction

Now you're ready to invoke the action:

wsk action invoke hello --result
{
  "response": "hello-world"
}

You can learn more about working with OpenWhisk Actions here.

Developing the Ballerina runtime for OpenWhisk

To build the Ballerina runtime, you need an OpenWhisk snapshot release which you can install as follows:

pushd $OPENWHISK_HOME
./gradlew install
podd $OPENWHISK_HOME

where $OPENWHISK_HOME is an environment variable that points to your OpenWhisk directory.

The Ballerina runtime is built with the Gradle wrapper gradlew.

./gradlew distDocker

You can also use gradlew to run all the unit tests.

./gradlew :tests:test

Or to run a specific test.

./gradlew :tests:test --tests *ActionContainerTests*

This project can be imported into IntelliJ for development and testing. Import the project as a Gradle project, and make sure your working directory is the root directory for this repository.