You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/11/07 08:07:00 UTC

[GitHub] [dolphinscheduler] github-code-scanning[bot] commented on a diff in pull request #12693: [Feature-12456][task plugin] Add new task plugin for apache linkis

github-code-scanning[bot] commented on code in PR #12693:
URL: https://github.com/apache/dolphinscheduler/pull/12693#discussion_r1015107089


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-linkis/src/main/java/org/apache/dolphinscheduler/plugin/task/linkis/LinkisTask.java:
##########
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.task.linkis;
+
+import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.*;
+
+import org.apache.dolphinscheduler.plugin.task.api.AbstractRemoteTask;
+import org.apache.dolphinscheduler.plugin.task.api.ShellCommandExecutor;
+import org.apache.dolphinscheduler.plugin.task.api.TaskException;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+import org.apache.dolphinscheduler.plugin.task.api.model.TaskResponse;
+import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
+import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils;
+import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * linkis task
+ */
+public class LinkisTask extends AbstractRemoteTask {
+
+    /**
+     * linkis parameters
+     */
+    private LinkisParameters linkisParameters;
+
+    /**
+     * shell command executor
+     */
+    private ShellCommandExecutor shellCommandExecutor;
+
+    /**
+     * taskExecutionContext
+     */
+    protected final TaskExecutionContext taskExecutionContext;
+
+    private String taskId;
+
+    protected static final Pattern LINKIS_TASK_ID_REGEX = Pattern.compile(Constants.LINKIS_TASK_ID_REGEX);
+
+    protected static final Pattern LINKIS_STATUS_REGEX = Pattern.compile(Constants.LINKIS_STATUS_REGEX);
+
+    /**
+     * constructor
+     *
+     * @param taskExecutionContext taskExecutionContext
+     */
+    public LinkisTask(TaskExecutionContext taskExecutionContext) {
+        super(taskExecutionContext);
+
+        this.taskExecutionContext = taskExecutionContext;
+        this.shellCommandExecutor = new ShellCommandExecutor(this::logHandle,
+                taskExecutionContext,
+                logger);
+    }
+
+    @Override
+    public List<String> getApplicationIds() throws TaskException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public void init() {
+        logger.info("Linkis task params {}", taskExecutionContext.getTaskParams());
+        if (!linkisParameters.checkParameters()) {
+            throw new RuntimeException("Linkis task params is not valid");
+        }
+    }
+
+    @Override
+    public void submitApplication() throws TaskException {
+        try {
+            // construct process
+            String command = buildCommand();
+            TaskResponse commandExecuteResult = shellCommandExecutor.run(command);
+            setExitStatusCode(commandExecuteResult.getExitStatusCode());
+            setAppIds(findTaskId(commandExecuteResult.getResultString()));
+            setProcessId(commandExecuteResult.getProcessId());
+            linkisParameters.dealOutParam(shellCommandExecutor.getVarPool());
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            logger.error("The current Linkis task has been interrupted", e);
+            setExitStatusCode(EXIT_CODE_FAILURE);
+            throw new TaskException("The current Linkis task has been interrupted", e);
+        } catch (Exception e) {
+            logger.error("Linkis task error", e);
+            setExitStatusCode(EXIT_CODE_FAILURE);
+            throw new TaskException("Execute Linkis task failed", e);
+        }
+    }
+
+    @Override
+    public void trackApplicationStatus() throws TaskException {
+        initTaskId();
+        try {
+            List<String> args = new ArrayList<>();
+            args.add(Constants.SHELL_CLI_OPTIONS);
+            args.add(Constants.STATUS_OPTIONS);
+            args.add(taskId);
+            String command = String.join(Constants.SPACE, args);
+            TaskResponse commandExecuteResult = shellCommandExecutor.run(command);
+            String status = findStatus(commandExecuteResult.getResultString());
+            LinkisJobStatus jobStatus = LinkisJobStatus.convertFromJobStatusString(status);
+            switch (jobStatus) {

Review Comment:
   ## Missing enum case in switch
   
   Switch statement does not have a case for [SHUTTINGDOWN](1).
   Switch statement does not have a case for [UNKNOWN](2).
   Switch statement does not have a case for [TIMEOUT](3).
   Switch statement does not have a case for [RUNNING](4).
   Switch statement does not have a case for [SCHEDULED](5).
   Switch statement does not have a case for [WAIT_FOR_RETRY](6).
   Switch statement does not have a case for [INITED](7).
   Switch statement does not have a case for [SUBMITTING](8).
   Switch statement does not have a case for [UNSUBMITTED](9).
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2245)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org