Skip to content
Open
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 jvm-11/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM maven:3.6-jdk-11 as BUILD
WORKDIR /usr/src/myapp/

# To reuse the build cache, here we split maven dependency
# download and package into two RUN commands to avoid cache invalidation.
COPY pom.xml .
RUN mvn dependency:go-offline

COPY src /usr/src/myapp/src/
RUN mvn package

FROM openjdk:11-jre
VOLUME /tmp
COPY --from=BUILD /usr/src/myapp/target/env-java-0.0.2-SNAPSHOT.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar --server.port=8888
EXPOSE 8888
6 changes: 6 additions & 0 deletions jvm-11/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-include ../rules.mk

.PHONY: all
all: jvm-builder jvm-env-img

jvm-env-img: Dockerfile
70 changes: 70 additions & 0 deletions jvm-11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Fission: Java and JVM Environment

This is the JVM environment for Fission.

It's a Docker image containing a OpenJDK8 runtime, along with a
dynamic loader. A few dependencies are included in the
pom.xml file.

Looking for ready-to-run examples? See the [JVM examples directory](../../examples/jvm).

## Customizing this image

To add package dependencies, edit pom.xml to add what you
need, and rebuild this image (instructions below).

## Rebuilding and pushing the image

You'll need access to a Docker registry to push the image: you can
sign up for Docker hub at hub.docker.com, or use registries from
gcr.io, quay.io, etc. Let's assume you're using a docker hub account
called USER. Build and push the image to the the registry:

```
docker build -t USER/jvm-env . && docker push USER/jvm-env
```

## Using the image in fission

You can add this customized image to fission with "fission env
create":

```
fission env create --name jvm --image USER/jvm-env
```

Or, if you already have an environment, you can update its image:

```
fission env update --name jvm --image USER/jvm-env
```

After this, fission functions that have the env parameter set to the
same environment name as this command will use this environment.

## Web Server Framework

JVM environment uses Tomcat HTTP server by default as it is included in spring web. You can choose to use jetty or undertow by changing the dependency in pom.xml file as shown below.

```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
```

## Java and JVM builder

JVM environment builder is based on OpenJDK8 and Maven 3.5.4 version. The default build command runs `mvn clean package` and uses the target/*with-dependencies.jar file for function. The default build command can be overridden as long as the uber jar file is copied to ${DEPLOY_PKG}.
4 changes: 2 additions & 2 deletions jvm-jersey/Dockerfile-11
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ COPY src /usr/src/myapp/src/
RUN mvn package

FROM openjdk:11-jre
COPY --from=BUILD /usr/src/myapp/target/env-jvm-jersey-0.0.1.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar --server.port=8888
COPY --from=BUILD /usr/src/myapp/target/env-jvm-jersey-0.0.2.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar 8888
EXPOSE 8888
16 changes: 8 additions & 8 deletions jvm-jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

<groupId>io.fission</groupId>
<artifactId>env-jvm-jersey</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>

<properties>
<java.source.level>1.6</java.source.level>
<java.target.level>1.6</java.target.level>
<java.source.level>1.8</java.source.level>
<java.target.level>1.8</java.target.level>
</properties>

<dependencies>
Expand Down Expand Up @@ -38,16 +38,16 @@
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.34</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.34</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.fission;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class FunctionLoadRequest {
Expand Down
16 changes: 16 additions & 0 deletions jvm/Dockerfile-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM maven:3.6-jdk-11 as BUILD
WORKDIR /usr/src/myapp/

# To reuse the build cache, here we split maven dependency
# download and package into two RUN commands to avoid cache invalidation.
COPY pom.xml .
RUN mvn dependency:go-offline

COPY src /usr/src/myapp/src/
RUN mvn package

FROM openjdk:11-jre
VOLUME /tmp
COPY --from=BUILD /usr/src/myapp/target/env-java-0.0.2-SNAPSHOT.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar --server.port=8888
EXPOSE 8888
9 changes: 2 additions & 7 deletions jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<groupId>io.fission</groupId>
<artifactId>env-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<version>2.7.3</version>
</parent>

<dependencies>
Expand All @@ -24,12 +24,7 @@
<artifactId>fission-java-core</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
22 changes: 6 additions & 16 deletions jvm/src/main/java/io/fission/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ ResponseEntity<String> specialize(@RequestBody FunctionLoadRequest req) {

// TODO Check if the classloading can be improved for ex. use something like:
// Thread.currentThread().setContextClassLoader(cl);
if (this.getClass().getClassLoader() == null) {
URLClassLoader currentLoader = (URLClassLoader) this.getClass().getClassLoader();
if (currentLoader == null ) { // this.getClass().getClassLoader() == null) {
cl = URLClassLoader.newInstance(urls);
} else {
cl = URLClassLoader.newInstance(urls, this.getClass().getClassLoader());
Expand All @@ -72,21 +73,7 @@ ResponseEntity<String> specialize(@RequestBody FunctionLoadRequest req) {
if (cl == null) {
return ResponseEntity.status(500).body("Failed to initialize the classloader");
}

// Load all dependent classes from libraries etc.
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class")) {
continue;
}
String className = je.getName().substring(0, je.getName().length() - CLASS_LENGTH);
className = className.replace('/', '.');
cl.loadClass(className);
}

// Instantiate the function class
fn = (Function) cl.loadClass(entryPoint).newInstance();

fn = (Function)Class.forName(entryPoint, true, cl).newInstance();
} catch (MalformedURLException e) {
e.printStackTrace();
return ResponseEntity.badRequest().body("Error loading the Function class file");
Expand All @@ -102,6 +89,9 @@ ResponseEntity<String> specialize(@RequestBody FunctionLoadRequest req) {
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.badRequest().body("Error reading the JAR file");
} catch (NoClassDefFoundError e) {
e.printStackTrace();
return ResponseEntity.badRequest().body("Class Dependency Missing");
} finally {
try {
// cl.close();
Expand Down