diff --git a/core/build.gradle b/core/build.gradle index d76aa71402..8067be8885 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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}" diff --git a/core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java b/core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java index 506ded2211..07e922ff88 100644 --- a/core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java +++ b/core/src/main/java/com/netflix/conductor/core/events/ScriptEvaluator.java @@ -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() {} diff --git a/core/src/main/java/com/netflix/conductor/core/execution/tasks/DoWhile.java b/core/src/main/java/com/netflix/conductor/core/execution/tasks/DoWhile.java index 3dbc72eb9e..501ce28fd2 100644 --- a/core/src/main/java/com/netflix/conductor/core/execution/tasks/DoWhile.java +++ b/core/src/main/java/com/netflix/conductor/core/execution/tasks/DoWhile.java @@ -261,7 +261,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; diff --git a/dependencies.gradle b/dependencies.gradle index 5f44fb740c..fc125ca841 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -53,4 +53,5 @@ ext { revSpock = '1.3-groovy-2.5' revSpotifyCompletableFutures = '0.3.3' revTestContainer = '1.15.3' + revGraalVM = '22.3.3' } diff --git a/docs/docs/reference-docs/do-while-task.md b/docs/docs/reference-docs/do-while-task.md index 80e249c6a4..68154251b8 100644 --- a/docs/docs/reference-docs/do-while-task.md +++ b/docs/docs/reference-docs/do-while-task.md @@ -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 diff --git a/java-sdk/build.gradle b/java-sdk/build.gradle index 5e1d986b35..c49b72a52f 100644 --- a/java-sdk/build.gradle +++ b/java-sdk/build.gradle @@ -12,6 +12,9 @@ dependencies { implementation "javax.ws.rs:javax.ws.rs-api:${revJAXRS}" implementation "org.glassfish.jersey.core:jersey-common:${revJerseyCommon}" + 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}" diff --git a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/def/tasks/Javascript.java b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/def/tasks/Javascript.java index 6468faa8a9..9986e6b53a 100644 --- a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/def/tasks/Javascript.java +++ b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/def/tasks/Javascript.java @@ -43,7 +43,9 @@ public class Javascript extends Task { private static final String EVALUATOR_TYPE_PARAMETER = "evaluatorType"; - private static final String ENGINE = "nashorn"; + private static final String ENGINE = "graal.js"; + + private static final String POLYGLOT_JS_ALLOW_HOST_ACCESS = "polyglot.js.allowHostAccess"; /** * Javascript tasks are executed on the Conductor server without having to write worker code @@ -105,6 +107,7 @@ public Javascript validate() { LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM"); return this; } + scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true); try { @@ -133,6 +136,7 @@ public Object test(Map input) { LOGGER.error("missing " + ENGINE + " engine. Ensure you are running supported JVM"); return this; } + scriptEngine.put(POLYGLOT_JS_ALLOW_HOST_ACCESS, true); try {