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


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java:
##########
@@ -2045,6 +2046,75 @@
         }
     }
 
+    /**
+     * clear related data if command of process instance is EXECUTE_TASK
+     * 1. find all task code from sub dag (only contains related task)
+     * 2. set the flag of tasks to Flag.NO
+     * 3. clear varPool data from re-execute task instance in process instance
+     * 4. remove related task instance from taskInstanceMap, completeTaskMap, 
validTaskMap
+     *
+     * @return task instance
+     */
+    private void clearDataIfExecuteTask() {
+        // only clear data if command is EXECUTE_TASK
+        if 
(!processInstance.getCommandType().equals(CommandType.EXECUTE_TASK)) {
+            return;
+        }
+
+        // if dag is null, do nothing
+        if (dag == null) {
+            return;
+        }
+
+        // Records the key of varPool data to be removed
+        Set<String> removeSet = new HashSet<>();
+        Set<String> taskCodesString = dag.getAllNodesList();
+
+        for (String taskCodeString : taskCodesString) {
+            long taskCode = Long.parseLong(taskCodeString);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2379)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java:
##########
@@ -487,6 +491,108 @@
         return execute(loginUser, processDefinition.getProjectCode(), 
workflowInstanceId, executeType);
     }
 
+    /**
+     * do action to execute task in process instance
+     *
+     * @param loginUser login user
+     * @param projectCode project code
+     * @param processInstanceId process instance id
+     * @param startNodeList start node list
+     * @param taskDependType task depend type
+     * @return execute result code
+     */
+    @Override
+    public Map<String, Object> executeTask(User loginUser, long projectCode, 
Integer processInstanceId,
+                                           String startNodeList, 
TaskDependType taskDependType) {
+
+        Project project = projectMapper.queryByCode(projectCode);
+        // check user access for project
+
+        Map<String, Object> result = 
projectService.checkProjectAndAuth(loginUser, project, projectCode,
+                
ApiFuncIdentificationConstant.map.get(ExecuteType.EXECUTE_TASK));
+
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return result;
+        }
+
+        // check master exists
+        if (!checkMasterExists(result)) {
+            return result;
+        }
+
+        ProcessInstance processInstance = 
processService.findProcessInstanceDetailById(processInstanceId)
+                .orElseThrow(() -> new 
ServiceException(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceId));
+
+        ProcessDefinition processDefinition =
+                
processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
+                        processInstance.getProcessDefinitionVersion());
+        processDefinition.setReleaseState(ReleaseState.ONLINE);
+        this.checkProcessDefinitionValid(projectCode, processDefinition, 
processInstance.getProcessDefinitionCode(),
+                processInstance.getProcessDefinitionVersion());
+
+        if (!checkTenantSuitable(processDefinition)) {
+            logger.error(
+                    "There is not any valid tenant for the process definition, 
processDefinitionId:{}, processDefinitionCode:{}, ",
+                    processDefinition.getId(), processDefinition.getName());
+            putMsg(result, Status.TENANT_NOT_SUITABLE);
+        }
+
+        // get the startParams user specified at the first starting while 
repeat running is needed
+
+        if 
(taskDefinitionLogMapper.queryMaxVersionForDefinition(Long.parseLong(startNodeList))
 == null) {

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2378)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java:
##########
@@ -450,4 +450,38 @@
                 warningGroupId, workerGroup, environmentCode, startParamMap, 
dryRun);
         return returnDataList(result);
     }
+
+    /**
+     * do action to process instance: pause, stop, repeat, recover from pause, 
recover from stop
+     *
+     * @param loginUser login user
+     * @param projectCode project code
+     * @param processInstanceId process instance id
+     * @param startNodeList start node list
+     * @param taskDependType task depend type
+     * @return execute result code
+     */
+    @Operation(summary = "execute-task", description = 
"EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES")
+    @Parameters({
+            @Parameter(name = "processInstanceId", description = 
"PROCESS_INSTANCE_ID", required = true, schema = @Schema(implementation = 
int.class, example = "100")),
+            @Parameter(name = "startNodeList", description = 
"START_NODE_LIST", required = true, schema = @Schema(implementation = 
String.class)),
+            @Parameter(name = "taskDependType", description = 
"TASK_DEPEND_TYPE", required = true, schema = @Schema(implementation = 
TaskDependType.class))
+    })
+    @PostMapping(value = "/execute-task")
+    @ResponseStatus(HttpStatus.OK)
+    @ApiException(EXECUTE_PROCESS_INSTANCE_ERROR)
+    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
+    public Result executeTask(@Parameter(hidden = true) 
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
+                              @Parameter(name = "projectCode", description = 
"PROJECT_CODE", required = true) @PathVariable long projectCode,
+                              @RequestParam("processInstanceId") Integer 
processInstanceId,
+                              @RequestParam("startNodeList") String 
startNodeList,
+                              @RequestParam("taskDependType") TaskDependType 
taskDependType) {
+        logger.info("Start to execute task in process instance, 
projectCode:{}, processInstanceId:{}, taskCode: {}.",
+                projectCode,
+                processInstanceId, startNodeList);

Review Comment:
   ## Log Injection
   
   This log entry depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2380)



-- 
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: [email protected]

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

Reply via email to