Unverified Commit 1b1e8e85 authored by 乔占卫's avatar 乔占卫 Committed by GitHub
Browse files

Merge pull request #533 from qiaozhanwei/dev-1.1.0

python task env variables and task submit update
parents 3916f463 92c21362
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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;
+15 −14
Original line number Diff line number Diff line
@@ -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