Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

⛔️ DEPRECATED - IBM Functions (OpenWhisk) runtime for Kotlin Actions

License

NotificationsYou must be signed in to change notification settings

ibm-functions/runtime-kotlin

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.


IBM Cloud Functions (OpenWhisk) runtime for Kotlin

⚠️ The Runtime for Kotlin is currently experimental. Feedback is welcome.⚠️

Build Status

This runtime provides Kotlin running on the following OpenJDK/OpenJ9 image fromAdoptOpenJDK:

Creating a Kotlin Action

The Runtime for Kotlin supports two APIs for creating actions:

  1. JSON based.
    The action receives parameters as a JSON object and returns a JSON object, using theGoogle GSON library library.
  2. Data Class based.
    The action receives parameters as a user defined data Class, and returns a user defined data Class.

"Hello World" using the JSON API

The following shows how to build a "HelloWorld" action using the JSON API:

  1. Create a file calledmain.kt containing:

    importcom.google.gson.JsonObjectfunmain(args:JsonObject) :JsonObject {val name= args.getAsJsonPrimitive("name").getAsString();val hello=JsonObject();    hello.addProperty("greeting","Hello"+ name+"!");return hello}
  2. 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.

"Hello World" using the Data Class API

The following shows how to build a "HelloWorld" action using the Data Class API:

  1. Create a file calledmain.kt containing:

    data classUser (valname:String)data classHello (valgreeting:String)funmain(user:User) :Hello {val hello=Hello("Hello"+ user.name+"!")return hello}
  2. 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.

Deploying the Kotlin Action

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 ofhello.kt:

     bx wsk action update myAction myAction.jar --main"hello" --docker ibmfunctions/action-kotlin
  • Using a main function name ofaction:

     bx wsk action update myAction myAction.jar --main"#action" --docker ibmfunctions/action-kotlin
  • Using a file name ofhello.kt and a main function name ofaction:

     bx wsk action update myAction myAction.jar --main"hello#action" --docker ibmfunctions/action-kotlin
  • Using a package ofmyfunctions with file name ofhello.kt and a main function name ofaction:

     bx wsk action update myAction myAction.jar --main"myfunctions.hello#action" --docker ibmfunctions/action-kotlin

Running the Kotlin Action

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    }

Future Work:

Areas of future work for the Runtime for Kotlin include:

  1. 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.
  2. 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.

Developing for the Runtime for Kotlin

The following information describes how to build and deploy the Runtime for Kotlin from a local Git repository.

Building an image from the repository

The following builds an image from the project:

./gradlew core:kotlin:distDocker

This will produce the imageibmfunctions/action-kotlin

Building and Pushing an image to Dockerhub:

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.io

You can then create actions using your the image from dockerhub

wsk action update myAction myAction.jar --docker $user_prefix/action-kotlin

The$user_prefix is usually your dockerhub user id.

Testing

Install dependencies from the root directory on $OPENWHISK_HOME repository

./gradlew install

Using gradle to run all tests

./gradlew :tests:test

Using 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

License

Apache 2.0

About

⛔️ DEPRECATED - IBM Functions (OpenWhisk) runtime for Kotlin Actions

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp