apache / apache/openwhisk-runtime-java

Support Scala Actions

Đang mở
#41 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
47
Fork
58
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

One person on Slack, and now a customer using IBM Cloud Functions want to use Scala to write their OpenWhisk Actions.

It looks like the java runtime can be use to run Scala actions.

What's need it to support it a bit better than today is
1. Add automation test cases with some scala examples, including process to generate the jar
2. Docs explaining how an user can get started with a simple hello world example code and steps to build jar.
3. (bonus) The runtime image can be use to compile the scala and produce the jar

### Here is an example:
## Create Directory structure
```
$ tree
.
├── Hello.scala
├── build.sbt
└── project
└── plugins.sbt
```

## Create Action `Hello.scala`
```
$ cat Hello.scala
```
```scala
import com.google.gson.JsonObject
object Hello {
def main(args: JsonObject): JsonObject = {
println("Log something")
val name = if (args.has("name")) args.getAsJsonPrimitive("name").getAsString() else "stranger"
val response = new JsonObject()
response.addProperty("greeting", "Hello " + name + "!")
response
}
}
```

## Setup Project
```
$ cat build.sbt

scalaVersion := "2.11.8"
libraryDependencies ++= Seq (
"com.google.code.gson" % "gson" % "latest.integration"
)
```

```
$ cat project/plugins.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
```

## Build Jar
```
$ sbt assembly
[info] Loading global plugins from /Users/csantanapr/.sbt/0.13/plugins
[info] Loading project definition from /Users/csantanapr/Documents/dev/whisk/demos/scala_action/project
[info] Set current project to scala_action (in build file:/Users/csantana23/Documents/dev/whisk/demos/scala_action/)
[info] Including from cache: gson-2.8.2.jar
[info] Including from cache: scala-library-2.11.8.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF/maven/com.google.code.gson/gson/pom.properties' with strategy 'discard'
[warn] Merging 'META-INF/maven/com.google.code.gson/gson/pom.xml' with strategy 'discard'
[warn] Strategy 'discard' was applied to 3 files
[info] Assembly up to date: /Users/csantanapr/Documents/dev/whisk/demos/scala_action/target/scala-2.11/scala_action-assembly-0.1-SNAPSHOT.jar
[success] Total time: 1 s, completed Apr 23, 2018 8:53:44 PM
```

## Deploy Action
```
$ wsk action update scala target/scala-2.11/scala_action-assembly-0.1-SNAPSHOT.jar --kind java --main Hello
ok: updated action scala
```

## Run Action
```
$ wsk action invoke scala -p name Carlos -r
{
"greeting": "Hello Carlos!"
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.