jvm-jersey-env (#1677)
A new Jersey framework based JVM environment which is lightweight and simpler.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
target/
|
||||
@@ -0,0 +1,60 @@
|
||||
# Hello World in JVM/Java on Fission
|
||||
|
||||
The `io.fission.HelloWorld.java` class is a very simple fission function that implements `io.fission.Function` and says "Hello, World!" .
|
||||
|
||||
## Building and deploying using Fission
|
||||
|
||||
Fission's builder can be used to create the binary artifact from source code. Create an environment with builder image and then create a package.
|
||||
|
||||
```
|
||||
$ zip -r java-src-pkg.zip *
|
||||
$ fission env create --name java --image fission/jvm-env --version 2 --keeparchive --builder fission/jvm-builder
|
||||
$ fission package create --sourcearchive java-src-pkg.zip --env java
|
||||
java-src-pkg-zip-tvd0
|
||||
$ fission package info --name java-src-pkg-zip-tvd0
|
||||
Name: java-src-pkg-zip-tvd0
|
||||
Environment: java
|
||||
Status: succeeded
|
||||
Build Logs:
|
||||
[INFO] Scanning for projects...
|
||||
[INFO]
|
||||
[INFO] -----------------------< io.fission:hello-world >-----------------------
|
||||
[INFO] Building hello-world 1.0-SNAPSHOT
|
||||
[INFO] --------------------------------[ jar ]---------------------------------
|
||||
```
|
||||
|
||||
Once package's status is `succeeded` then that package can be used to create and execute a function.
|
||||
|
||||
```
|
||||
$ fission fn create --name hello --pkg java-src-pkg-zip-tvd0 --env java --entrypoint io.fission.HelloWorld
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
|
||||
## Building locally and deploying with Fission
|
||||
|
||||
You can build the jar file in one of the two ways below based on your setup:
|
||||
|
||||
- You can use docker without the need to install JDK and Maven to build the jar file from source code:
|
||||
|
||||
```bash
|
||||
$ bash -x ./build.sh
|
||||
|
||||
```
|
||||
- If you have JDK and Maven installed, you can directly build the JAR file using command:
|
||||
|
||||
```
|
||||
$ mvn clean package
|
||||
```
|
||||
|
||||
Both of above steps will generate a target subdirectory which has the archive `target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar` which will be used for creating function.
|
||||
|
||||
- The archive created above will be used as a deploy package when creating the function.
|
||||
|
||||
```
|
||||
$ fission env create --name jvm --image fission/jvm-env --version 2 --keeparchive=true
|
||||
$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld
|
||||
$ fission route create --function hello --url /hellop --method GET
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# This script allows you to build the jar without needing Maven & JDK installed locally.
|
||||
# You need docker, as it uses a Docker image to build source code
|
||||
set -eou pipefail
|
||||
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package
|
||||
@@ -0,0 +1,76 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>jersey-hello-world</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>hello-world</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>fission-jvm-jersey</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet-core</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
Fission Specs
|
||||
=============
|
||||
|
||||
This is a set of specifications for a Fission app. This includes functions,
|
||||
environments, and triggers; we collectively call these things "resources".
|
||||
|
||||
How to use these specs
|
||||
----------------------
|
||||
|
||||
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
|
||||
|
||||
'fission spec apply' will "apply" all resources specified in this directory to your
|
||||
cluster. That means it checks what resources exist on your cluster, what resources are
|
||||
specified in the specs directory, and reconciles the difference by creating, updating or
|
||||
deleting resources on the cluster.
|
||||
|
||||
'fission spec apply' will also package up your source code (or compiled binaries) and
|
||||
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
|
||||
this directory to figure out which files to archive.
|
||||
|
||||
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
|
||||
the cluster updated.
|
||||
|
||||
You can add YAMLs to this directory by writing them manually, but it's easier to generate
|
||||
them. Use 'fission function create --spec' to generate a function spec,
|
||||
'fission environment create --spec' to generate an environment spec, and so on.
|
||||
|
||||
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
|
||||
which contains a UID that you should never change. To apply your changes simply use
|
||||
'fission spec apply'.
|
||||
|
||||
fission-deployment-config.yaml
|
||||
------------------------------
|
||||
|
||||
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
|
||||
resources on the cluster to resources in this directory.
|
||||
|
||||
All resources created by 'fission spec apply' are annotated with this UID. Resources on
|
||||
the cluster that are _not_ annotated with this UID are never modified or deleted by
|
||||
fission.
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Environment
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
spec:
|
||||
builder:
|
||||
command: build
|
||||
image: fission/jvm-jersey-builder
|
||||
imagepullsecret: ""
|
||||
keeparchive: true
|
||||
poolsize: 3
|
||||
resources: {}
|
||||
runtime:
|
||||
image: fission/jvm-jersey-env
|
||||
version: 2
|
||||
@@ -0,0 +1,7 @@
|
||||
# This file is generated by the 'fission spec init' command.
|
||||
# See the README in this directory for background and usage information.
|
||||
# Do not edit the UID below: that will break 'fission spec apply'
|
||||
apiVersion: fission.io/v1
|
||||
kind: DeploymentConfig
|
||||
name: java-jersey
|
||||
uid: 908a303a-bf23-4bae-a22c-b1db9a1f71a9
|
||||
@@ -0,0 +1,27 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Function
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hello
|
||||
namespace: default
|
||||
spec:
|
||||
InvokeStrategy:
|
||||
ExecutionStrategy:
|
||||
ExecutorType: poolmgr
|
||||
MaxScale: 0
|
||||
MinScale: 0
|
||||
SpecializationTimeout: 120
|
||||
TargetCPUPercent: 0
|
||||
StrategyType: execution
|
||||
configmaps: null
|
||||
environment:
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: io.fission.HelloWorld
|
||||
packageref:
|
||||
name: hellojava
|
||||
namespace: default
|
||||
resources: {}
|
||||
secrets: null
|
||||
@@ -0,0 +1,26 @@
|
||||
include:
|
||||
- src
|
||||
- pom.xml
|
||||
kind: ArchiveUploadSpec
|
||||
name: src-URlE
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Package
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hellojavajersey
|
||||
namespace: default
|
||||
spec:
|
||||
deployment:
|
||||
checksum: {}
|
||||
environment:
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
source:
|
||||
checksum: {}
|
||||
type: url
|
||||
url: archive://src-URlE
|
||||
status:
|
||||
buildstatus: pending
|
||||
lastUpdateTimestamp: "2020-01-29T09:43:56Z"
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.fission;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import io.fission.Function;
|
||||
import java.io.BufferedReader;
|
||||
import java.util.stream.Collectors;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class HelloWorld implements Function<ContainerRequestContext,Response> {
|
||||
|
||||
public static final String RETURN_STRING = "Hello World!";
|
||||
|
||||
@Override
|
||||
public Response call(ContainerRequestContext request, Context arg1) {
|
||||
if(request.getMethod().equals("GET")) {
|
||||
return Response.ok(RETURN_STRING).build();
|
||||
}
|
||||
else {
|
||||
String body = new BufferedReader(new InputStreamReader(request.getEntityStream())).lines()
|
||||
.parallel().collect(Collectors.joining("\n"));
|
||||
return Response.ok("Echo: " + body).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.fission;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class HelloWorldTest {
|
||||
|
||||
@Test
|
||||
public void testResponse() {
|
||||
HelloWorld hw = new HelloWorld();
|
||||
ContainerRequest request = null;
|
||||
try {
|
||||
request = new ContainerRequest(new URI("http://example.com/"),new URI("/hello"),"GET",null,null);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Response response = hw.call(request, null);
|
||||
Assert.assertTrue(response.getEntity().toString().equals(HelloWorld.RETURN_STRING));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user