CalvinKirs commented on a change in pull request #4216:
URL: 
https://github.com/apache/incubator-dolphinscheduler/pull/4216#discussion_r542130758



##########
File path: 
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java
##########
@@ -43,136 +42,137 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.slf4j.Logger;
+
 /**
  * shell task
  */
 public class ShellTask extends AbstractTask {
 
-  /**
-   * shell parameters
-   */
-  private ShellParameters shellParameters;
-
-  /**
-   * shell command executor
-   */
-  private ShellCommandExecutor shellCommandExecutor;
-
-  /**
-   *  taskExecutionContext
-   */
-  private TaskExecutionContext taskExecutionContext;
-
-  /**
-   * constructor
-   * @param taskExecutionContext taskExecutionContext
-   * @param logger    logger
-   */
-  public ShellTask(TaskExecutionContext taskExecutionContext, Logger logger) {
-    super(taskExecutionContext, logger);
-
-    this.taskExecutionContext = taskExecutionContext;
-    this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle,
+    /**
+     * shell parameters
+     */
+    private ShellParameters shellParameters;
+
+    /**
+     * shell command executor
+     */
+    private ShellCommandExecutor shellCommandExecutor;
+
+    /**
+     * taskExecutionContext
+     */
+    private TaskExecutionContext taskExecutionContext;
+
+    /**
+     * constructor
+     *
+     * @param taskExecutionContext taskExecutionContext
+     * @param logger               logger
+     */
+    public ShellTask(TaskExecutionContext taskExecutionContext, Logger logger) 
{
+        super(taskExecutionContext, logger);
+
+        this.taskExecutionContext = taskExecutionContext;
+        this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle,
             taskExecutionContext,
             logger);
-  }
+    }
 
-  @Override
-  public void init() {
-    logger.info("shell task params {}", taskExecutionContext.getTaskParams());
+    @Override
+    public void init() {
+        logger.info("shell task params {}", 
taskExecutionContext.getTaskParams());
 
-    shellParameters = 
JSONUtils.parseObject(taskExecutionContext.getTaskParams(), 
ShellParameters.class);
+        shellParameters = 
JSONUtils.parseObject(taskExecutionContext.getTaskParams(), 
ShellParameters.class);
 
-    if (!shellParameters.checkParameters()) {
-      throw new RuntimeException("shell task params is not valid");
-    }
-  }
-
-  @Override
-  public void handle() throws Exception {
-    try {
-      // construct process
-      CommandExecuteResult commandExecuteResult = 
shellCommandExecutor.run(buildCommand());
-      setExitStatusCode(commandExecuteResult.getExitStatusCode());
-      setAppIds(commandExecuteResult.getAppIds());
-      setProcessId(commandExecuteResult.getProcessId());
-    } catch (Exception e) {
-      logger.error("shell task error", e);
-      setExitStatusCode(Constants.EXIT_CODE_FAILURE);
-      throw e;
+        if (!shellParameters.checkParameters()) {
+            throw new RuntimeException("shell task params is not valid");
+        }
     }
-  }
-
-  @Override
-  public void cancelApplication(boolean cancelApplication) throws Exception {
-    // cancel process
-    shellCommandExecutor.cancelApplication();
-  }
-
-  /**
-   * create command
-   * @return file name
-   * @throws Exception exception
-   */
-  private String buildCommand() throws Exception {
-    // generate scripts
-    String fileName = String.format("%s/%s_node.%s",
-            taskExecutionContext.getExecutePath(),
-            taskExecutionContext.getTaskAppId(), OSUtils.isWindows() ? "bat" : 
"sh");
 
-    Path path = new File(fileName).toPath();
+    @Override
+    public void handle() throws Exception {
+        try {
+            // construct process
+            CommandExecuteResult commandExecuteResult = 
shellCommandExecutor.run(buildCommand());
+            setExitStatusCode(commandExecuteResult.getExitStatusCode());
+            setAppIds(commandExecuteResult.getAppIds());
+            setProcessId(commandExecuteResult.getProcessId());
+        } catch (Exception e) {
+            logger.error("shell task error", e);
+            setExitStatusCode(Constants.EXIT_CODE_FAILURE);
+            throw e;
+        }
+    }
 
-    if (Files.exists(path)) {
-      return fileName;
+    @Override
+    public void cancelApplication(boolean cancelApplication) throws Exception {
+        // cancel process
+        shellCommandExecutor.cancelApplication();
     }
 
-    String script = shellParameters.getRawScript().replaceAll("\\r\\n", "\n");
     /**
-     *  combining local and global parameters
+     * create command
+     *
+     * @return file name
+     * @throws Exception exception
      */
-    Map<String, Property> paramsMap = 
ParamUtils.convert(ParamUtils.getUserDefParamsMap(taskExecutionContext.getDefinedParams()),
+    private String buildCommand() throws Exception {
+        // generate scripts
+        String fileName = String.format("%s/%s_node.%s",
+            taskExecutionContext.getExecutePath(),
+            taskExecutionContext.getTaskAppId(), OSUtils.isWindows() ? "bat" : 
"sh");
+
+        Path path = new File(fileName).toPath();
+
+        if (Files.exists(path)) {
+            return fileName;
+        }
+
+        String script = shellParameters.getRawScript().replaceAll("\\r\\n", 
"\n");
+        /**
+         *  combining local and global parameters
+         */
+        Map<String, Property> paramsMap = 
ParamUtils.convert(ParamUtils.getUserDefParamsMap(taskExecutionContext.getDefinedParams()),
             taskExecutionContext.getDefinedParams(),
             shellParameters.getLocalParametersMap(),
             CommandType.of(taskExecutionContext.getCmdTypeIfComplement()),
             taskExecutionContext.getScheduleTime());
-    if (paramsMap != null){
-      script = ParameterUtils.convertParameterPlaceholders(script, 
ParamUtils.convert(paramsMap));
-    }

Review comment:
       I only deleted these three lines of code, the others is formatted.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to