Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 55da066

Browse files
feat(#2312): replace Nashorn with GraalVM JS Engine
this is required for JDK 15+ compatibility (Nashorn was removed in JDK 15)
1 parent 6359617 commit 55da066

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ dependencies {
4141

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

44+
implementation "org.graalvm.js:js:${revGraalVM}"
45+
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"
46+
4447
// JAXB is not bundled with Java 11, dependencies added explicitly
4548
// These are needed by Apache BVAL
4649
implementation "jakarta.xml.bind:jakarta.xml.bind-api:${revJAXB}"

core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919

2020
public class ScriptEvaluator {
2121

22-
private static final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
22+
private static final ScriptEngine engine =
23+
new ScriptEngineManager().getEngineByName("graal.js");
24+
25+
static {
26+
engine.put("polyglot.js.allowHostAccess", true);
27+
}
2328

2429
private ScriptEvaluator() {}
2530

core/src/main/java/com/netflix/conductor/core/execution/tasks/DoWhile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ boolean evaluateCondition(WorkflowModel workflow, TaskModel task) throws ScriptE
261261
boolean result = false;
262262
if (condition != null) {
263263
LOGGER.debug("Condition: {} is being evaluated", condition);
264-
// Evaluate the expression by using the Nashorn based script evaluator
264+
// Evaluate the expression by using the GraalVM based script evaluator
265265
result = ScriptEvaluator.evalBool(condition, conditionInput);
266266
}
267267
return result;

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ ext {
5353
revSpock = '1.3-groovy-2.5'
5454
revSpotifyCompletableFutures = '0.3.3'
5555
revTestContainer = '1.15.3'
56+
revGraalVM = '22.3.3'
5657
}

docs/docs/reference-docs/do-while-task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Branching inside loopOver task is supported.
3030

3131
### Input Parameters:
3232

33-
| name | type | description |
34-
|---------------|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
35-
| 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. |
36-
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |
33+
| name | type | description |
34+
|---------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
35+
| 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. |
36+
| loopOver | List[Task] | List of tasks that needs to be executed as long as the condition is true. |
3737

3838
### Output Parameters
3939

java-sdk/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ dependencies {
1212
implementation "javax.ws.rs:javax.ws.rs-api:${revJAXRS}"
1313
implementation "org.glassfish.jersey.core:jersey-common:${revJerseyCommon}"
1414

15+
implementation "org.graalvm.js:js:${revGraalVM}"
16+
implementation "org.graalvm.js:js-scriptengine:${revGraalVM}"
17+
1518
testImplementation "org.springframework:spring-web"
1619
testImplementation "org.spockframework:spock-core:${revSpock}"
1720
testImplementation "org.spockframework:spock-spring:${revSpock}"

java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/def/tasks/Javascript.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
*/
1313
package com.netflix.conductor.sdk.workflow.def.tasks;
1414

15-
import java.io.IOException;
16-
import java.io.InputStream;
17-
import java.util.HashMap;
18-
import java.util.Map;
15+
import com.google.common.base.Strings;
16+
import com.netflix.conductor.common.metadata.tasks.TaskType;
17+
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
18+
import com.netflix.conductor.sdk.workflow.def.ValidationError;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
1921

2022
import javax.script.Bindings;
2123
import javax.script.ScriptEngine;
2224
import javax.script.ScriptEngineManager;
2325
import javax.script.ScriptException;
24-
25-
import org.slf4j.Logger;
26-
import org.slf4j.LoggerFactory;
27-
28-
import com.netflix.conductor.common.metadata.tasks.TaskType;
29-
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
30-
import com.netflix.conductor.sdk.workflow.def.ValidationError;
31-
32-
import com.google.common.base.Strings;
26+
import java.io.IOException;
27+
import java.io.InputStream;
28+
import java.util.HashMap;
29+
import java.util.Map;
3330

3431
/**
3532
* JQ Transformation task See https://stedolan.github.io/jq/ for how to form the queries to parse
@@ -43,7 +40,9 @@ public class Javascript extends Task<Javascript> {
4340

4441
private static final String EVALUATOR_TYPE_PARAMETER = "evaluatorType";
4542

46-
private static final String ENGINE = "nashorn";
43+
private static final String ENGINE = "graal.js";
44+
45+
private static final String POLYGLOT_JS_ALLOW_HOST_ACCESS = "polyglot.js.allowHostAccess";
4746

4847
/**
4948
* Javascript tasks are executed on the Conductor server without having to write worker code
@@ -105,6 +104,7 @@ public Javascript validate() {
105104
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
106105
return this;
107106
}
107+
scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true);
108108

109109
try {
110110

@@ -133,6 +133,7 @@ public Object test(Map<String, Object> input) {
133133
LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM");
134134
return this;
135135
}
136+
scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true);
136137

137138
try {
138139

0 commit comments

Comments
 (0)