Browse Source

Merge pull request #533 from qiaozhanwei/dev-1.1.0

python task env variables and task submit update
pull/2/head
乔占卫 6 years ago committed by GitHub
parent
commit
1b1e8e85cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      escheduler-server/src/main/java/cn/escheduler/server/worker/task/PythonCommandExecutor.java
  2. 29
      escheduler-server/src/main/java/cn/escheduler/server/worker/task/python/PythonTask.java

9
escheduler-server/src/main/java/cn/escheduler/server/worker/task/PythonCommandExecutor.java

@ -18,6 +18,7 @@ package cn.escheduler.server.worker.task;
import cn.escheduler.common.Constants;
import cn.escheduler.common.utils.FileUtils;
import cn.escheduler.common.utils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,11 +72,11 @@ public class PythonCommandExecutor extends AbstractCommandExecutor {
if (!Files.exists(Paths.get(commandFile))) {
logger.info("generate command file:{}", commandFile);
StringBuilder sb = new StringBuilder(200);
StringBuilder sb = new StringBuilder();
sb.append("#-*- encoding=utf8 -*-\n");
sb.append("\n\n");
sb.append(String.format("import py_%s_node\n",taskAppId));
sb.append(execCommand);
logger.info(sb.toString());
// write data to file
@ -86,8 +87,8 @@ public class PythonCommandExecutor extends AbstractCommandExecutor {
@Override
protected String commandType() {
String envPath = System.getProperty("user.dir") + Constants.SINGLE_SLASH + "conf"+
Constants.SINGLE_SLASH +"env" + Constants.SINGLE_SLASH + Constants.ESCHEDULER_ENV_SH;
String envPath = PropertyUtils.getString(Constants.ESCHEDULER_ENV_PATH);
String pythonHome = getPythonHome(envPath);
if (StringUtils.isEmpty(pythonHome)){
return PYTHON;

29
escheduler-server/src/main/java/cn/escheduler/server/worker/task/python/PythonTask.java

@ -112,14 +112,14 @@ public class PythonTask extends AbstractTask {
*/
private String buildCommand() throws Exception {
// generate scripts
String fileName = String.format("%s/py_%s_node.py", taskDir, taskProps.getTaskAppId());
Path path = new File(fileName).toPath();
// String fileName = String.format("%s/py_%s_node.py", taskDir, taskProps.getTaskAppId());
// Path path = new File(fileName).toPath();
if (Files.exists(path)) {
return fileName;
}
// if (Files.exists(path)) {
// return fileName;
// }
String rawScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n");
@ -140,19 +140,20 @@ public class PythonTask extends AbstractTask {
}
pythonParameters.setRawScript(rawScript);
// pythonParameters.setRawScript(rawScript);
logger.info("raw script : {}", pythonParameters.getRawScript());
logger.info("task dir : {}", taskDir);
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
Files.createFile(path, attr);
Files.write(path, pythonParameters.getRawScript().getBytes(), StandardOpenOption.APPEND);
return fileName;
// Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
// FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
//
// Files.createFile(path, attr);
//
// Files.write(path, pythonParameters.getRawScript().getBytes(), StandardOpenOption.APPEND);
//
// return fileName;
return rawScript;
}
@Override

Loading…
Cancel
Save