Skip to content

Commit

Permalink
feat(Netflix#2312): replace Nashorn with GraalVM JS Engine
Browse files Browse the repository at this point in the history
this is required for JDK 15+ compatibility
(Nashorn was removed in JDK 15)
  • Loading branch information
BlasiusSecundus committed Sep 11, 2022
1 parent b843af4 commit daacd21
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {

implementation "com.github.ben-manes.caffeine:caffeine"

implementation "org.graalvm.js:js:${revGraalVM}"
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"

// JAXB is not bundled with Java 11, dependencies added explicitly
// These are needed by Apache BVAL
implementation "jakarta.xml.bind:jakarta.xml.bind-api:${revJAXB}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

public class ScriptEvaluator {

private static final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
private static final ScriptEngine engine =
new ScriptEngineManager().getEngineByName("graal.js");

static {
engine.put("polyglot.js.allowHostAccess", true);
}

private ScriptEvaluator() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ boolean evaluateCondition(WorkflowModel workflow, TaskModel task) throws ScriptE
boolean result = false;
if (condition != null) {
LOGGER.debug("Condition: {} is being evaluated", condition);
// Evaluate the expression by using the Nashorn based script evaluator
// Evaluate the expression by using the GraalVM based script evaluator
result = ScriptEvaluator.evalBool(condition, conditionInput);
}
return result;
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ ext {
revSpock = '1.3-groovy-2.5'
revSpotifyCompletableFutures = '0.3.3'
revTestContainer = '1.15.3'
revGraalVM = '22.2.0'
}
8 changes: 4 additions & 4 deletions docs/docs/reference-docs/do-while-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Branching inside loopOver task is supported.

### Input Parameters:

| name | type | description |
|---------------|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| loopCondition | String | Condition to be evaluated after every iteration. This is a Javascript expression, evaluated using the Nashorn engine. If an exception occurs during evaluation, the DO_WHILE task is set to FAILED_WITH_TERMINAL_ERROR. |
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |
| name | type | description |
|---------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| loopCondition | String | Condition to be evaluated after every iteration. This is a Javascript expression, evaluated using the GraalVM JS engine. If an exception occurs during evaluation, the DO_WHILE task is set to FAILED_WITH_TERMINAL_ERROR. |
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |

### Output Parameters

Expand Down
3 changes: 3 additions & 0 deletions java-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies {
implementation "cglib:cglib:3.3.0"
implementation "com.sun.jersey:jersey-client:${revJersey}"

implementation "org.graalvm.js:js:${revGraalVM}"
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"

testImplementation "org.springframework:spring-web"
testImplementation "org.spockframework:spock-core:${revSpock}"
testImplementation "org.spockframework:spock-spring:${revSpock}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Javascript extends Task<Javascript> {

private static final String EVALUATOR_TYPE_PARAMETER = "evaluatorType";

private static final String ENGINE = "nashorn";
private static final String ENGINE = "graal.js";

/**
* Javascript tasks are executed on the Conductor server without having to write worker code
Expand Down Expand Up @@ -105,6 +105,7 @@ public Javascript validate() {
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
return this;
}
scriptEngine.put("polyglot.js.allowHostAccess", true);

try {

Expand Down Expand Up @@ -133,6 +134,7 @@ public Object test(Map<String, Object> input) {
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
return this;
}
scriptEngine.put("polyglot.js.allowHostAccess", true);

try {

Expand Down

0 comments on commit daacd21

Please sign in to comment.