- Notifications
You must be signed in to change notification settings - Fork3
⛔️ DEPRECATED - IBM Functions (OpenWhisk) runtime for Kotlin Actions
License
ibm-functions/runtime-kotlin
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
IBM Cloud Functions reached end of life and this repository is no longer active.
For Apache OpenWhisk visit:https://github.com/apache/openwhisk.
This runtime provides Kotlin running on the following OpenJDK/OpenJ9 image fromAdoptOpenJDK:
The Runtime for Kotlin supports two APIs for creating actions:
- JSON based.
The action receives parameters as a JSON object and returns a JSON object, using theGoogle GSON library library. - Data Class based.
The action receives parameters as a user defined data Class, and returns a user defined data Class.
The following shows how to build a "HelloWorld" action using the JSON API:
Create a file called
main.ktcontaining:importcom.google.gson.JsonObjectfunmain(args:JsonObject) :JsonObject {val name= args.getAsJsonPrimitive("name").getAsString();val hello=JsonObject(); hello.addProperty("greeting","Hello"+ name+"!");return hello}
Compile the action into a JAR file:
kotlinc -classpath ./gson-2.6.2.jar main.kt -d myAction.jar
This provides the action contained in myAction.jar, ready to be deployed and run.
The following shows how to build a "HelloWorld" action using the Data Class API:
Create a file called
main.ktcontaining:data classUser (valname:String)data classHello (valgreeting:String)funmain(user:User) :Hello {val hello=Hello("Hello"+ user.name+"!")return hello}
Compile the action into a JAR file:
kotlinc main.kt -d myAction.jar
This provides the action contained in myAction.jar, ready to be deployed and run.
The Kotlin action can be deployed for use as a Docker action using the following, works on any deployment of Apache OpenWhisk or IBM Cloud Functions"
bx wsk action update myAction myAction.jar --docker ibmfunctions/action-kotlin
This assumes that you have used the default file name ofmain.kt and the default main function name ofmain.
You can specify alternative package, file and main function names using the--main option towsk action update. For example:
Using a file name of
hello.kt:bx wsk action update myAction myAction.jar --main"hello" --docker ibmfunctions/action-kotlinUsing a main function name of
action:bx wsk action update myAction myAction.jar --main"#action" --docker ibmfunctions/action-kotlinUsing a file name of
hello.ktand a main function name ofaction:bx wsk action update myAction myAction.jar --main"hello#action" --docker ibmfunctions/action-kotlinUsing a package of
myfunctionswith file name ofhello.ktand a main function name ofaction:bx wsk action update myAction myAction.jar --main"myfunctions.hello#action" --docker ibmfunctions/action-kotlin
The Kotlin action can be run in the same way as any other action. The following will execute the Hello World example with a parameter ofCloud Functions:
bx wsk action invoke myAction -b -p name"Cloud Functions"This should return the following in theresponse section of the output:
"response": {"result": {"greeting":"Hello Cloud Functions!" },"status":"success","success":true }
Areas of future work for the Runtime for Kotlin include:
- Async APIs.
The Runtime for Kotlin currently only provides synchronous, blocking APIs, however it is well suited for asynchronous programming, and is used extensively in that way on Android. - Client SDK.
The implementation of the data Class API makes it easy to share data type definitions with Kotlin clients. Having a client SDK that accepts data Classes when calling the action, particular for Android, would make adoption and usage much easier.
The following information describes how to build and deploy the Runtime for Kotlin from a local Git repository.
The following builds an image from the project:
./gradlew core:kotlin:distDocker
This will produce the imageibmfunctions/action-kotlin
The following builds an image, and pushes it to Dockerhub for use by OpenWhisk or IBM Cloud Functions:
docker login ./gradlew kotlin:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.ioYou can then create actions using your the image from dockerhub
wsk action update myAction myAction.jar --docker $user_prefix/action-kotlinThe$user_prefix is usually your dockerhub user id.
Install dependencies from the root directory on $OPENWHISK_HOME repository
./gradlew installUsing gradle to run all tests
./gradlew :tests:testUsing gradle to run some tests
./gradlew :tests:test --tests *ActionContainerTests*Using IntelliJ:
- Import project as gradle project.
- Make sure working directory is root of the project/repo
About
⛔️ DEPRECATED - IBM Functions (OpenWhisk) runtime for Kotlin Actions
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.