This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 12f121e  Add Ballerina 0.990 runtime. (#4239)
12f121e is described below

commit 12f121ed4d3ec4d1aa78fd29d7223b573b7dadd5
Author: rodric rabbah <[email protected]>
AuthorDate: Sat Jan 26 10:19:04 2019 -0500

    Add Ballerina 0.990 runtime. (#4239)
---
 ansible/files/runtimes.json                        |  16 +++++
 .../src/main/resources/apiv1swagger.json           |   3 +-
 docs/actions-ballerina.md                          |  75 +++++++++++++++++++++
 docs/actions-new.md                                |  35 +++++-----
 docs/actions.md                                    |   1 +
 .../dat/actions/unicode.tests/ballerina-0.990.bin  | Bin 0 -> 1775 bytes
 .../unicode.tests/src/ballerina/unicode.bal        |  26 +++++++
 7 files changed, 136 insertions(+), 20 deletions(-)

diff --git a/ansible/files/runtimes.json b/ansible/files/runtimes.json
index 88f14f3..e5989db 100644
--- a/ansible/files/runtimes.json
+++ b/ansible/files/runtimes.json
@@ -283,6 +283,22 @@
                     "attachmentType": "text/plain"
                 }
             }
+        ],
+        "ballerina": [
+            {
+                "kind": "ballerina:0.990",
+                "default": true,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-ballerina-v0.990.2",
+                    "tag": "latest"
+                },
+                "deprecated": false,
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
+            }
         ]
     },
     "blackboxes": [
diff --git a/core/controller/src/main/resources/apiv1swagger.json 
b/core/controller/src/main/resources/apiv1swagger.json
index 1cd8ebc..72c0efc 100644
--- a/core/controller/src/main/resources/apiv1swagger.json
+++ b/core/controller/src/main/resources/apiv1swagger.json
@@ -1905,7 +1905,8 @@
                         "swift:3.1.1",
                         "swift:4.1",
                         "swift:4.2",
-                        "dotnet:2.2"
+                        "dotnet:2.2",
+                        "ballerina:0.990"
                     ],
                     "description": "the type of action"
                 },
diff --git a/docs/actions-ballerina.md b/docs/actions-ballerina.md
new file mode 100644
index 0000000..044ee11
--- /dev/null
+++ b/docs/actions-ballerina.md
@@ -0,0 +1,75 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## Creating and invoking Ballerina actions
+
+The process of creating Ballerina actions is similar to that of [other 
actions](actions.md#the-basics).
+The following sections guide you through creating and invoking a Ballerina 
action.
+
+Ballerina actions are executed using Ballerina 
[0.990.2](https://ballerina.io/downloads). You will need
+a compatible version of the compiler locally available to generate the 
executable. Without the Ballerina compiler,
+you cannot create an OpenWhisk action.
+
+An action is simply a top-level Ballerina function which accepts and returns a 
JSON object. For example, create a file called `hello.bal`
+with the following source code:
+
+```ballerina
+import ballerina/io;
+
+public function main(json data) returns json {
+  json? name = data.name;
+  if (name == null) {
+    return { greeting: "Hello stranger!" };
+  } else {
+    return { greeting: "Hello " + name.toString() + "!" };
+  }
+}
+```
+
+The entry method for the action is `main` by default but may be specified 
explicitly when creating
+the action with the `wsk` CLI using `--main`, as with any other action type. 
It is important to note
+that the Ballerina compiler expects the presence of a function called `main` 
to generate the executable.
+Hence, when using alternate entry points, your source file must still include 
a place holder called `main`.
+
+You can create an OpenWhisk action called `bello` from the function above as 
follows:
+
+```
+# generate the .balx file first
+ballerina build hello.bal
+
+# use the .balx file to create the action
+wsk action create bello hello.balx --kind ballerina:0.990
+```
+
+The CLI does not yet automatically infer the type of the action from the 
source file extension.
+So you must specify the kind explicitly. For `.balx` source files, the action 
currently runs using the Ballerina 0.990.2 runtime.
+
+Action invocation is the same for Ballerina actions as it is for [any other 
action](actions.md#the-basics).
+
+```
+wsk action invoke --result bello --param name World
+```
+
+```json
+{
+  "greeting": "Hello World!"
+}
+```
+
+Find out more about parameters in the [Working with 
parameters](./parameters.md) section.
diff --git a/docs/actions-new.md b/docs/actions-new.md
index afbf13c..11c72d2 100644
--- a/docs/actions-new.md
+++ b/docs/actions-new.md
@@ -40,24 +40,21 @@ The specifics of the [Action interface](#action-interface) 
and its functions are
 
 ### Platform requirements
 
-In order for your language runtime to be properly recognized by the OpenWhisk 
platform, the following additional requirments must be fulfilled:
-
-1. introduce the runtime specification into the [runtimes 
manifest](../ansible/files/runtimes.json),
-2. add the runtime to the [Swagger 
file](../core/controller/src/main/resources/apiv1swagger.json)
-
-### Project requirements
-
-If you wish to have your runtime officially recognized by the Apache OpenWhisk 
project, please follow these
-additional rqeuirements and best practices:
-
-1. implement the runtime in its own repository to permit a management 
lifecycle independent of the rest of the OpenWhisk platform,
-    - The repository should conform to the [Canonical runtime 
repository](#canonical-runtime-repository) layout (as shown below).
-2. add a standard [test action](#the-test-action) to the [tests artifacts 
directory](../tests/dat/actions/unicode.tests) (as shown below),
-3. automate and pass the following test suites:
-    - [Action Interface tests](#action-interface-tests)
-    - [Runtime proxy tests](#runtime-proxy-tests)
-4. add a new `actions-<your runtime>.md` file to the [docs](.) directory,
-5. add a link to your new language or runtime to the [top level 
index](actions.md#languages-and-runtimes).
+In order for your language runtime to be properly recognized by the OpenWhisk 
platform,
+and officially recognized by the Apache OpenWhisk project, please follow these
+requirements and best practices:
+
+1. Implement the runtime in its own repository to permit a management 
lifecycle independent of the rest of the OpenWhisk platform.
+2. Introduce the runtime specification into the [runtimes 
manifest](../ansible/files/runtimes.json),
+3. Add the runtime to the [Swagger 
file](../core/controller/src/main/resources/apiv1swagger.json)
+4. Add a new `actions-<your runtime>.md` file to the [docs](.) directory,
+5. Add a link to your new runtime doc to the [top level actions 
index](actions.md#languages-and-runtimes).
+6. Add a standard [test action](#the-test-action) to the [tests artifacts 
directory](../tests/dat/actions/unicode.tests) (as shown below),
+
+The new runtime repository should conform to the [Canonical runtime 
repository](#canonical-runtime-repository) layout (as shown below).
+Further, you should automate and pass the following test suites:
+- [Action Interface tests](#action-interface-tests)
+- [Runtime proxy tests](#runtime-proxy-tests)
 
 ### The runtimes manifest
 
@@ -109,7 +106,7 @@ The runtime repository should follow the canonical 
structure used by other runti
 The [Docker skeleton 
repository](https://github.com/apache/incubator-openwhisk-runtime-docker)
 is an example starting point to fork and modify for your new runtime.
 
-#### The test action
+### The test action
 
 The standard test action is shown below in JavaScript. It should be adapted 
for the
 new language and added to the [test artifacts 
directory](../tests/dat/actions/unicode.tests)
diff --git a/docs/actions.md b/docs/actions.md
index f03e708..3153090 100644
--- a/docs/actions.md
+++ b/docs/actions.md
@@ -54,6 +54,7 @@ into a language-specific tutorial. If your preferred language 
isn't supported di
 the [Docker](actions-docker.md) action or [native 
binary](actions-docker.md#creating-native-actions)
 paths more suitable. Or, you can [create a new runtime](actions-new.md).
 
+* [Ballerina](actions-ballerina.md)
 * [Go](actions-go.md)
 * [Java](actions-java.md)
 * [JavaScript](actions-nodejs.md)
diff --git a/tests/dat/actions/unicode.tests/ballerina-0.990.bin 
b/tests/dat/actions/unicode.tests/ballerina-0.990.bin
new file mode 100644
index 0000000..d1bc61b
Binary files /dev/null and 
b/tests/dat/actions/unicode.tests/ballerina-0.990.bin differ
diff --git a/tests/dat/actions/unicode.tests/src/ballerina/unicode.bal 
b/tests/dat/actions/unicode.tests/src/ballerina/unicode.bal
new file mode 100644
index 0000000..ff239e7
--- /dev/null
+++ b/tests/dat/actions/unicode.tests/src/ballerina/unicode.bal
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import ballerina/io;
+
+public function main(json jsonInput) returns json {
+    string delimiter = <string> jsonInput.delimiter;
+    string str = delimiter + " ☃ " + delimiter;
+    io:println(str);
+    jsonInput.winter = str;
+    return jsonInput;
+}

Reply via email to