Skip to content

Commit

Permalink
Logs and tests (#63)
Browse files Browse the repository at this point in the history
1. Emit log markers as expected by managed runtimes.
2. Handle missing code more graciously.
3. Adopt runtime tests upstream (which exposed the missing markers)
4. Move the proxy under core to match canonical structure of repo
5. Update CHANGELOG
  • Loading branch information
rabbah authored and dgrove-oss committed Jul 9, 2018
1 parent d5caa45 commit 93dc2ee
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 232 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ wsk action invoke --result helloJava --param name World

## Local development
```
./gradlew java8:distDocker
./gradlew core:java8:distDocker
```
This will produce the image `whisk/java8action`

Build and Push image
```
docker login
./gradlew java8:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
./gradlew core:java8:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
```

Deploy OpenWhisk using ansible environment that contains the kind `java:8`
Expand Down
5 changes: 5 additions & 0 deletions java8/CHANGELOG.md → core/java8/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
# Java 8 OpenWhisk Runtime Container


## 1.1.1
Changes:
- Adds log markers.
- Improve error handling for improper initialization.

## 1.1.0
Changes:
- Replaced oracle [jdk8u131-b11](http://download.oracle.com/otn-pub/java/jdk/"${VERSION}"u"${UPDATE}"-b"${BUILD}"/d54c1d3a095b4ff2b6607d096fa80163/server-jre-"${VERSION}"u"${UPDATE}"-linux-x64.tar.gz) with OpenJDK [adoptopenjdk/openjdk8-openj9:jdk8u162-b12_openj9-0.8.0](https://hub.docker.com/r/adoptopenjdk/openjdk8-openj9)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion java8/build.gradle → core/java8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
*/

ext.dockerImageName = 'java8action'
apply from: '../gradle/docker.gradle'
apply from: '../../gradle/docker.gradle'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ private static void writeError(HttpExchange t, String errorMessage) throws IOExc
writeResponse(t, 502, message.toString());
}

private static void writeLogMarkers() {
System.out.println("XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX");
System.err.println("XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX");
System.out.flush();
System.err.flush();
}

private class InitHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
if (loader != null) {
Proxy.writeError(t, "Cannot initialize the action more than once.");
String errorMessage = "Cannot initialize the action more than once.";
System.err.println(errorMessage);
Proxy.writeError(t, errorMessage);
return;
}

Expand All @@ -80,26 +89,34 @@ public void handle(HttpExchange t) throws IOException {
JsonElement ie = parser.parse(new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)));
JsonObject inputObject = ie.getAsJsonObject();

JsonObject message = inputObject.getAsJsonObject("value");
String mainClass = message.getAsJsonPrimitive("main").getAsString();
String base64Jar = message.getAsJsonPrimitive("code").getAsString();
if (inputObject.has("value")) {
JsonObject message = inputObject.getAsJsonObject("value");
if (message.has("main") && message.has("code")) {
String mainClass = message.getAsJsonPrimitive("main").getAsString();
String base64Jar = message.getAsJsonPrimitive("code").getAsString();

// FIXME: this is obviously not very useful. The idea is that we
// will implement/use a streaming parser for the incoming JSON object so that we
// can stream the contents of the jar straight to a file.
InputStream jarIs = new ByteArrayInputStream(base64Jar.getBytes(StandardCharsets.UTF_8));
// FIXME: this is obviously not very useful. The idea is that we
// will implement/use a streaming parser for the incoming JSON object so that we
// can stream the contents of the jar straight to a file.
InputStream jarIs = new ByteArrayInputStream(base64Jar.getBytes(StandardCharsets.UTF_8));

// Save the bytes to a file.
Path jarPath = JarLoader.saveBase64EncodedFile(jarIs);
// Save the bytes to a file.
Path jarPath = JarLoader.saveBase64EncodedFile(jarIs);

// Start up the custom classloader. This also checks that the
// main method exists.
loader = new JarLoader(jarPath, mainClass);
// Start up the custom classloader. This also checks that the
// main method exists.
loader = new JarLoader(jarPath, mainClass);

Proxy.writeResponse(t, 200, "OK");
return;
}
}

Proxy.writeResponse(t, 200, "OK");
Proxy.writeError(t, "Missing main/no code to execute.");
return;
} catch (Exception e) {
e.printStackTrace(System.err);
writeLogMarkers();
Proxy.writeError(t, "An error has occurred (see logs for details): " + e);
return;
}
Expand Down Expand Up @@ -137,7 +154,7 @@ public void handle(HttpExchange t) throws IOException {
JsonObject output = loader.invokeMain(inputObject, env);
// User code finished running here.

if(output == null) {
if (output == null) {
throw new NullPointerException("The action returned null");
}

Expand All @@ -154,6 +171,7 @@ public void handle(HttpExchange t) throws IOException {
e.printStackTrace(System.err);
Proxy.writeError(t, "An error has occurred (see logs for details): " + e);
} finally {
writeLogMarkers();
System.setSecurityManager(sm);
Thread.currentThread().setContextClassLoader(cl);
}
Expand Down
5 changes: 2 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

include 'tests'

include 'java8'
include 'java8:proxy'

include 'core:java8'
include 'core:java8:proxy'

rootProject.name = 'runtime-java'

Expand Down

0 comments on commit 93dc2ee

Please sign in to comment.