|
|
@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.plugin.task.python; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskException; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskException; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskResponse; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskResponse; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.util.MapUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.task.AbstractParameters; |
|
|
|
import org.apache.dolphinscheduler.spi.task.AbstractParameters; |
|
|
|
import org.apache.dolphinscheduler.spi.task.Property; |
|
|
|
import org.apache.dolphinscheduler.spi.task.Property; |
|
|
|
import org.apache.dolphinscheduler.spi.task.TaskConstants; |
|
|
|
import org.apache.dolphinscheduler.spi.task.TaskConstants; |
|
|
@ -27,6 +28,8 @@ import org.apache.dolphinscheduler.spi.task.paramparser.ParamUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.task.paramparser.ParameterUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.task.paramparser.ParameterUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.TaskRequest; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.TaskRequest; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -51,7 +54,6 @@ public class PythonTask extends AbstractTaskExecutor { |
|
|
|
|
|
|
|
|
|
|
|
private TaskRequest taskRequest; |
|
|
|
private TaskRequest taskRequest; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* constructor |
|
|
|
* constructor |
|
|
|
* |
|
|
|
* |
|
|
@ -101,7 +103,7 @@ public class PythonTask extends AbstractTaskExecutor { |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("python task failure", e); |
|
|
|
logger.error("python task failure", e); |
|
|
|
setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); |
|
|
|
setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); |
|
|
|
throw new TaskException("run python task error",e); |
|
|
|
throw new TaskException("run python task error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -150,6 +152,7 @@ public class PythonTask extends AbstractTaskExecutor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* build command |
|
|
|
* build command |
|
|
|
|
|
|
|
* |
|
|
|
* @return raw python script |
|
|
|
* @return raw python script |
|
|
|
* @throws Exception exception |
|
|
|
* @throws Exception exception |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -157,10 +160,14 @@ public class PythonTask extends AbstractTaskExecutor { |
|
|
|
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n"); |
|
|
|
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n"); |
|
|
|
|
|
|
|
|
|
|
|
// replace placeholder
|
|
|
|
// replace placeholder
|
|
|
|
Map<String, Property> paramsMap = ParamUtils.convert(taskRequest,pythonParameters); |
|
|
|
Map<String, Property> paramsMap = ParamUtils.convert(taskRequest, pythonParameters); |
|
|
|
if (paramsMap != null){ |
|
|
|
if (MapUtils.isEmpty(paramsMap)) { |
|
|
|
rawPythonScript = ParameterUtils.convertParameterPlaceholders(rawPythonScript, ParamUtils.convert(paramsMap)); |
|
|
|
paramsMap = new HashMap<>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (MapUtils.isNotEmpty(taskRequest.getParamsMap())) { |
|
|
|
|
|
|
|
paramsMap.putAll(taskRequest.getParamsMap()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rawPythonScript = ParameterUtils.convertParameterPlaceholders(rawPythonScript, ParamUtils.convert(paramsMap)); |
|
|
|
|
|
|
|
|
|
|
|
logger.info("raw python script : {}", pythonParameters.getRawScript()); |
|
|
|
logger.info("raw python script : {}", pythonParameters.getRawScript()); |
|
|
|
logger.info("task dir : {}", taskDir); |
|
|
|
logger.info("task dir : {}", taskDir); |
|
|
@ -168,5 +175,4 @@ public class PythonTask extends AbstractTaskExecutor { |
|
|
|
return rawPythonScript; |
|
|
|
return rawPythonScript; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|