This is an automated email from the ASF dual-hosted git repository.
kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 0715be3 [Fix-6166][task-plugin]Fix Python Task Execution Error (#6167)
0715be3 is described below
commit 0715be34d5b4c553396374679ccb23fedc4c27a0
Author: Martin Huang <[email protected]>
AuthorDate: Sat Sep 11 12:25:24 2021 +0800
[Fix-6166][task-plugin]Fix Python Task Execution Error (#6167)
* fix python task execution error
* delete AbstractTask#setCommand
---
.../dolphinscheduler/spi/task/AbstractTask.java | 3 --
.../plugin/task/api/AbstractCommandExecutor.java | 2 +-
.../plugin/task/python/PythonTask.java | 36 ++++++++++++++++------
3 files changed, 28 insertions(+), 13 deletions(-)
diff --git
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractTask.java
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractTask.java
index a94adff..b9c2632 100644
---
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractTask.java
+++
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractTask.java
@@ -79,9 +79,6 @@ public abstract class AbstractTask {
return null;
}
- public void setCommand(String command) throws Exception {
-
- }
/**
* task handle
diff --git
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
index 54b51c0..c360846 100644
---
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
+++
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
@@ -127,7 +127,7 @@ public abstract class AbstractCommandExecutor {
command.add("sudo");
command.add("-u");
command.add(taskRequest.getTenantCode());
- command.add(SH);
+ command.add(commandInterpreter());
command.addAll(Collections.emptyList());
command.add(commandFile);
diff --git
a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java
b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java
index 6d77d45..03462b8 100644
---
a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java
+++
b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java
@@ -21,9 +21,13 @@ import
org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor;
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
import org.apache.dolphinscheduler.plugin.task.api.TaskResponse;
import org.apache.dolphinscheduler.spi.task.AbstractParameters;
+import org.apache.dolphinscheduler.spi.task.Property;
import org.apache.dolphinscheduler.spi.task.TaskConstants;
+import org.apache.dolphinscheduler.spi.task.paramparser.ParamUtils;
+import org.apache.dolphinscheduler.spi.task.paramparser.ParameterUtils;
import org.apache.dolphinscheduler.spi.task.request.TaskRequest;
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
+import java.util.Map;
/**
* python task
@@ -48,8 +52,6 @@ public class PythonTask extends AbstractTaskExecutor {
private TaskRequest taskRequest;
- private String command;
-
/**
* constructor
*
@@ -87,16 +89,11 @@ public class PythonTask extends AbstractTaskExecutor {
}
@Override
- public void setCommand(String command) {
- this.command = command;
- }
-
- @Override
public void handle() throws Exception {
try {
- // construct process
+ // construct process
+ String command = buildCommand();
TaskResponse taskResponse = pythonCommandExecutor.run(command);
-
setExitStatusCode(taskResponse.getExitStatusCode());
setAppIds(taskResponse.getAppIds());
setProcessId(taskResponse.getProcessId());
@@ -151,4 +148,25 @@ public class PythonTask extends AbstractTaskExecutor {
return rawScript;
}
+ /**
+ * build command
+ * @return raw python script
+ * @throws Exception exception
+ */
+ private String buildCommand() throws Exception {
+ String rawPythonScript =
pythonParameters.getRawScript().replaceAll("\\r\\n", "\n");
+
+ // replace placeholder
+ Map<String, Property> paramsMap =
ParamUtils.convert(taskRequest,pythonParameters);
+ if (paramsMap != null){
+ rawPythonScript =
ParameterUtils.convertParameterPlaceholders(rawPythonScript,
ParamUtils.convert(paramsMap));
+ }
+
+ logger.info("raw python script : {}", pythonParameters.getRawScript());
+ logger.info("task dir : {}", taskDir);
+
+ return rawPythonScript;
+ }
+
+
}