Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ballerina 0.990.2 runtime. #4239

Merged
merged 2 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ansible/files/runtimes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 2 additions & 1 deletion core/controller/src/main/resources/apiv1swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
75 changes: 75 additions & 0 deletions docs/actions-ballerina.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 16 additions & 19 deletions docs/actions-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/dat/actions/unicode.tests/src/ballerina/unicode.bal
Original file line number Diff line number Diff line change
@@ -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;
}