All Projects → apache → openwhisk-runtime-java

apache / openwhisk-runtime-java

Licence: Apache-2.0 license
Apache OpenWhisk Runtime Java supports Apache OpenWhisk functions written in Java and other JVM-hosted languages

Programming Languages

java
68154 projects - #9 most used programming language
scala
5932 projects
python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to openwhisk-runtime-java

openwhisk-runtime-dotnet
Apache OpenWhisk Runtime .Net supports Apache OpenWhisk functions written in .Net languages
Stars: ✭ 23 (-46.51%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service, openwhisk-runtime
openwhisk-runtime-python
Apache OpenWhisk Runtime Python supports Apache OpenWhisk functions written in Python
Stars: ✭ 39 (-9.3%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service, openwhisk-runtime
openwhisk-runtime-go
Apache OpenWhisk Runtime Go supports Apache OpenWhisk functions written in Go
Stars: ✭ 31 (-27.91%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service, openwhisk-runtime
openwhisk-runtime-docker
Apache OpenWhisk SDK for building Docker "blackbox" runtimes
Stars: ✭ 23 (-46.51%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service, openwhisk-runtime
Openwhisk
Apache OpenWhisk is an open source serverless cloud platform
Stars: ✭ 5,499 (+12688.37%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service
Openwhisk Runtime Nodejs
Apache OpenWhisk Runtime NodeJS supports Apache OpenWhisk functions written in JavaScript for NodeJS
Stars: ✭ 43 (+0%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, functions-as-a-service
openwhisk-catalog
Curated catalog of Apache OpenWhisk packages to interface with event producers and consumers
Stars: ✭ 30 (-30.23%)
Mutual labels:  apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service
Openwhisk Runtime Php
Apache OpenWhisk Runtime PHP supports Apache OpenWhisk functions written in PHP
Stars: ✭ 26 (-39.53%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, functions-as-a-service
Openwhisk Deploy Kube
The Apache OpenWhisk Kubernetes Deployment repository supports deploying the Apache OpenWhisk system on Kubernetes and OpenShift clusters.
Stars: ✭ 231 (+437.21%)
Mutual labels:  functions, apache, faas, serverless-functions, serverless-architectures, functions-as-a-service
openwhisk-package-kafka
Apache OpenWhisk package for communicating with Kafka or Message Hub
Stars: ✭ 35 (-18.6%)
Mutual labels:  apache, faas, serverless-functions, serverless-architectures, openwhisk, functions-as-a-service
Openwhisk Cli
Apache OpenWhisk Command Line Interface (CLI)
Stars: ✭ 73 (+69.77%)
Mutual labels:  functions, apache, faas, serverless-functions, functions-as-a-service
Openwhisk Apigateway
Apache OpenWhisk API Gateway service for exposing actions as REST interfaces.
Stars: ✭ 56 (+30.23%)
Mutual labels:  apache, faas, serverless-functions, serverless-architectures, functions-as-a-service
Openwhisk Devtools
Development tools for building and deploying Apache OpenWhisk
Stars: ✭ 141 (+227.91%)
Mutual labels:  functions, apache, faas, serverless-functions, functions-as-a-service
Faas
OpenFaaS - Serverless Functions Made Simple
Stars: ✭ 20,820 (+48318.6%)
Mutual labels:  functions, faas, serverless-functions, functions-as-a-service
Fission
Fast and Simple Serverless Functions for Kubernetes
Stars: ✭ 6,646 (+15355.81%)
Mutual labels:  functions, faas, serverless-functions, functions-as-a-service
Jazz
Platform to develop and manage serverless applications at an enterprise scale!
Stars: ✭ 254 (+490.7%)
Mutual labels:  faas, serverless-architectures, functions-as-a-service
openfaas-rstats-templates
OpenFaaS templates for R
Stars: ✭ 17 (-60.47%)
Mutual labels:  functions, faas, functions-as-a-service
Gofn
Function process via docker provider (serverless minimalist)
Stars: ✭ 134 (+211.63%)
Mutual labels:  functions, faas, functions-as-a-service
Microcule
SDK and CLI for spawning streaming stateless HTTP microservices in multiple programming languages
Stars: ✭ 454 (+955.81%)
Mutual labels:  functions, faas
Nuclio
High-Performance Serverless event and data processing platform
Stars: ✭ 4,213 (+9697.67%)
Mutual labels:  functions, faas

Apache OpenWhisk runtimes for java

Build Status

Changelogs

Quick Java Action

A Java action is a Java program with a method called main that has the exact signature as follows:

public static com.google.gson.JsonObject main(com.google.gson.JsonObject);

For example, create a Java file called Hello.java with the following content:

import com.google.gson.JsonObject;

public class Hello {
    public static JsonObject main(JsonObject args) {
        String name = "stranger";
        if (args.has("name"))
            name = args.getAsJsonPrimitive("name").getAsString();
        JsonObject response = new JsonObject();
        response.addProperty("greeting", "Hello " + name + "!");
        return response;
    }
}

In order to compile, test and archive Java files, you must have a JDK 8 installed locally.

Then, compile Hello.java into a JAR file hello.jar as follows:

javac Hello.java
jar cvf hello.jar Hello.class

Note: google-gson must exist in your Java CLASSPATH when compiling the Java file.

You need to specify the name of the main class using --main. An eligible main class is one that implements a static main method as described above. If the class is not in the default package, use the Java fully-qualified class name, e.g., --main com.example.MyMain.

If needed you can also customize the method name of your Java action. This can be done by specifying the Java fully-qualified method name of your action, e.q., --main com.example.MyMain#methodName

Not only support return JsonObject but also support return JsonArray, the main function would be:

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class HelloArray {
    public static JsonArray main(JsonObject args) {
        JsonArray jsonArray = new JsonArray();
        jsonArray.add("a");
        jsonArray.add("b");
        return jsonArray;
    }
}

And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.

So the function would be:

import com.google.gson.JsonArray;

public class Sort {
    public static JsonArray main(JsonArray args) {
        return args;
    }
}

Create the Java Action

To use as a docker action:

wsk action update helloJava hello.jar --main Hello --docker openwhisk/java8action

This works on any deployment of Apache OpenWhisk

To use on a deployment of OpenWhisk that contains the runtime as a kind:

wsk action update helloJava hello.jar --main Hello --kind java:8

Invoke the Java Action

Action invocation is the same for Java actions as it is for Swift and JavaScript actions:

wsk action invoke --result helloJava --param name World
  {
      "greeting": "Hello World!"
  }

Local development

Pre-requisites

  • Gradle
  • Docker Desktop (local builds)

Build and Push image to a local Docker registry

  1. Start Docker Desktop (i.e., Docker daemon)

  2. Build the Docker runtime image locally using Gradle:

./gradlew core:java8:distDocker

This will produce the image whisk/java8action and push it to the local Docker Desktop registry with the latest tag.

  1. Verify the image was registered:
$ docker images whisk/*
REPOSITORY           TAG     IMAGE ID            CREATED             SIZE
whisk/java8action    latest  35f90453905a        7 minutes ago       521MB

Build and Push image to a remote Docker registry

Build the Docker runtime image locally using Gradle supplying the image Prefix and Registry domain (default port):

docker login
./gradlew core:java8:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io

Deploying the Java runtime image to OpenWhisk

Deploy OpenWhisk using ansible environment that contains the kind java:8 Assuming you have OpenWhisk already deployed locally and OPENWHISK_HOME pointing to root directory of OpenWhisk core repository.

Set ROOTDIR to the root directory of this repository.

Redeploy OpenWhisk

cd $OPENWHISK_HOME/ansible
ANSIBLE_CMD="ansible-playbook -i ${ROOTDIR}/ansible/environments/local"
$ANSIBLE_CMD setup.yml
$ANSIBLE_CMD couchdb.yml
$ANSIBLE_CMD initdb.yml
$ANSIBLE_CMD wipe.yml
$ANSIBLE_CMD openwhisk.yml

Or you can use wskdev and create a soft link to the target ansible environment, for example:

ln -s ${ROOTDIR}/ansible/environments/local ${OPENWHISK_HOME}/ansible/environments/local-java
wskdev fresh -t local-java

Testing

Install dependencies from the root directory on $OPENWHISK_HOME repository

pushd $OPENWHISK_HOME
./gradlew install
popd $OPENWHISK_HOME

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

Using container image to test

To use as docker action push to your own dockerhub account

docker tag whisk/java8action $user_prefix/java8action
docker push $user_prefix/java8action

Then create the action using your the image from dockerhub

wsk action update helloJava hello.jar --main Hello --docker $user_prefix/java8action

The $user_prefix is usually your dockerhub user id.


Troubleshooting

Gradle build fails with "Too many files open"

This may occur on MacOS as the default maximum # of file handles per session is 256. The gradle build requires many more and is unable to open more files (e.g., java.io.FileNotFoundException). For example, you may see something like:

> java.io.FileNotFoundException: /Users/XXX/.gradle/caches/4.6/scripts-remapped/build_4mpzm2wl8gipqoxzlms7n6ctq/7gdodk7z6t5iivcgfvflmhqsm/cp_projdf5583fde4f7f1f2f3f5ea117e2cdff1/cache.properties (Too many open files)

You can see this limit by issuing:

$ ulimit -a
open files                      (-n) 256

In order to increase the limit, open a new terminal session and issue the command (and verify):

$ ulimit -n 10000

$ ulimit -a
open files                      (-n) 10000

Gradle Task fails on :core:java8:tagImage

Docker daemon is not started and the Task is not able to push the image to your local registry.

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].