diff --git a/core/build.gradle b/core/build.gradle index beef8f7a2..4b4330ade 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -43,6 +43,11 @@ dependencies { implementation "org.openjdk.nashorn:nashorn-core:15.4" + //gralVm dependencies for executing python + implementation("org.graalvm.polyglot:polyglot:24.1.0") + implementation("org.graalvm.polyglot:python:24.1.0") + implementation "org.graalvm.sdk:graal-sdk:24.1.0" + // 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/execution/evaluators/PythonEvaluator.java b/core/src/main/java/com/netflix/conductor/core/execution/evaluators/PythonEvaluator.java new file mode 100644 index 000000000..1a71ee9b8 --- /dev/null +++ b/core/src/main/java/com/netflix/conductor/core/execution/evaluators/PythonEvaluator.java @@ -0,0 +1,78 @@ +/* + * Copyright 2024 Conductor Authors. + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package com.netflix.conductor.core.execution.evaluators;
+
+import java.util.Map;
+
+import org.graalvm.polyglot.Context;
+import org.graalvm.polyglot.Value;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import com.netflix.conductor.core.exception.TerminateWorkflowException;
+
+@Component(PythonEvaluator.NAME)
+public class PythonEvaluator implements Evaluator {
+ public static final String NAME = "python";
+ private static final Logger LOGGER = LoggerFactory.getLogger(PythonEvaluator.class);
+
+ @Override
+ public Object evaluate(String expression, Object input) {
+ try (Context context = Context.newBuilder("python").allowAllAccess(true).build()) {
+ if (input instanceof Map) {
+ Map
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package com.netflix.conductor.sdk.workflow.def.tasks;
+
+import com.netflix.conductor.common.metadata.tasks.TaskType;
+
+public class Python extends Task