diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java index 715e012cb2..275dfdd3db 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java @@ -16,6 +16,7 @@ */ package org.apache.dolphinscheduler.api.controller; +import org.apache.commons.lang3.StringUtils; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.utils.Result; @@ -31,6 +32,9 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -436,7 +440,32 @@ public class ProcessDefinitionController extends BaseController{ try{ logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}", loginUser.getUserName(), projectName, processDefinitionIds); - Map result = processDefinitionService.batchDeleteProcessDefinitionByIds(loginUser, projectName, processDefinitionIds); + + Map result = new HashMap<>(5); + List deleteFailedIdList = new ArrayList(); + if(StringUtils.isNotEmpty(processDefinitionIds)){ + String[] processDefinitionIdArray = processDefinitionIds.split(","); + + for (String strProcessDefinitionId:processDefinitionIdArray) { + int processDefinitionId = Integer.parseInt(strProcessDefinitionId); + try { + Map deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); + if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ + deleteFailedIdList.add(processDefinitionId); + logger.error((String)deleteResult.get(Constants.MSG)); + } + } catch (Exception e) { + deleteFailedIdList.add(processDefinitionId); + } + } + } + + if(deleteFailedIdList.size() > 0){ + putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR,StringUtils.join(deleteFailedIdList.toArray(),",")); + }else{ + putMsg(result, Status.SUCCESS); + } + return returnDataList(result); }catch (Exception e){ logger.error(Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(),e); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java index 1c61475729..743be7bd04 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java @@ -16,6 +16,7 @@ */ package org.apache.dolphinscheduler.api.controller; +import org.apache.commons.lang3.StringUtils; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; import org.apache.dolphinscheduler.api.utils.Result; @@ -34,6 +35,9 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.apache.dolphinscheduler.api.enums.Status.*; @@ -365,7 +369,32 @@ public class ProcessInstanceController extends BaseController{ try{ logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}", loginUser.getUserName(), projectName, processInstanceIds); - Map result = processInstanceService.batchDeleteProcessInstanceByIds(loginUser, projectName, processInstanceIds); + // task queue + ITaskQueue tasksQueue = TaskQueueFactory.getTaskQueueInstance(); + Map result = new HashMap<>(5); + List deleteFailedIdList = new ArrayList(); + if(StringUtils.isNotEmpty(processInstanceIds)){ + String[] processInstanceIdArray = processInstanceIds.split(","); + + for (String strProcessInstanceId:processInstanceIdArray) { + int processInstanceId = Integer.parseInt(strProcessInstanceId); + try { + Map deleteResult = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId,tasksQueue); + if(!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))){ + deleteFailedIdList.add(processInstanceId); + logger.error((String)deleteResult.get(Constants.MSG)); + } + } catch (Exception e) { + deleteFailedIdList.add(processInstanceId); + } + } + } + if(deleteFailedIdList.size() > 0){ + putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR,StringUtils.join(deleteFailedIdList.toArray(),",")); + }else{ + putMsg(result, Status.SUCCESS); + } + return returnDataList(result); }catch (Exception e){ logger.error(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getMsg(),e); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java index aea35ced38..cdd579ae8d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java @@ -39,7 +39,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.dolphinscheduler.api.utils.CheckUtils; import org.apache.dolphinscheduler.dao.entity.*; import org.apache.dolphinscheduler.dao.mapper.*; @@ -419,55 +418,6 @@ public class ProcessDefinitionService extends BaseDAGService { return result; } - /** - * batch delete process definition by ids - * - * @param loginUser login user - * @param projectName project name - * @param processDefinitionIds process definition id - * @return delete result code - */ - public Map batchDeleteProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds) { - - Map result = new HashMap<>(5); - - Map deleteReuslt = new HashMap<>(5); - - List deleteFailedIdList = new ArrayList(); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; - } - - - if(StringUtils.isNotEmpty(processDefinitionIds)){ - String[] processInstanceIdArray = processDefinitionIds.split(","); - - for (String strProcessInstanceId:processInstanceIdArray) { - int processInstanceId = Integer.parseInt(strProcessInstanceId); - try { - deleteReuslt = deleteProcessDefinitionById(loginUser, projectName, processInstanceId); - if(!Status.SUCCESS.equals(deleteReuslt.get(Constants.STATUS))){ - deleteFailedIdList.add(processInstanceId); - logger.error((String)deleteReuslt.get(Constants.MSG)); - } - } catch (Exception e) { - deleteFailedIdList.add(processInstanceId); - } - } - } - - if(deleteFailedIdList.size() > 0){ - putMsg(result, Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR,StringUtils.join(deleteFailedIdList.toArray(),",")); - }else{ - putMsg(result, Status.SUCCESS); - } - return result; - } - /** * release process definition: online / offline * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java index 1419ed8258..db9a6ef8ff 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java @@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.common.model.TaskNode; import org.apache.dolphinscheduler.common.model.TaskNodeRelation; import org.apache.dolphinscheduler.common.process.Property; import org.apache.dolphinscheduler.common.queue.ITaskQueue; -import org.apache.dolphinscheduler.common.queue.TaskQueueFactory; import org.apache.dolphinscheduler.common.utils.*; import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; import org.apache.dolphinscheduler.dao.ProcessDao; @@ -556,50 +555,6 @@ public class ProcessInstanceService extends BaseDAGService { return result; } - /** - * batch delete process instance by ids, at the same timeļ¼Œdelete task instance and their mapping relation data - * - * @param loginUser login user - * @param projectName project name - * @param processInstanceIds process instance id - * @return delete result code - */ - public Map batchDeleteProcessInstanceByIds(User loginUser, String projectName, String processInstanceIds) { - // task queue - ITaskQueue tasksQueue = TaskQueueFactory.getTaskQueueInstance(); - - Map result = new HashMap<>(5); - List deleteFailedIdList = new ArrayList(); - - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultEnum = (Status) checkResult.get(Constants.STATUS); - if (resultEnum != Status.SUCCESS) { - return checkResult; - } - - if(StringUtils.isNotEmpty(processInstanceIds)){ - String[] processInstanceIdArray = processInstanceIds.split(","); - - for (String strProcessInstanceId:processInstanceIdArray) { - int processInstanceId = Integer.parseInt(strProcessInstanceId); - try { - deleteProcessInstanceById(loginUser, projectName, processInstanceId,tasksQueue); - } catch (Exception e) { - deleteFailedIdList.add(processInstanceId); - } - } - } - if(deleteFailedIdList.size() > 0){ - putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR,StringUtils.join(deleteFailedIdList.toArray(),",")); - }else{ - putMsg(result, Status.SUCCESS); - } - - return result; - } - /** * view process instance variables * diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index 0b13ba732b..90c800fcaa 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -76,15 +76,4 @@ public class ProcessDefinitionServiceTest { Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); logger.info(JSON.toJSONString(map)); } - - @Test - public void batchDeleteProcessDefinitionByIds() throws Exception { - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - Map map = processDefinitionService.batchDeleteProcessDefinitionByIds(loginUser, "li_test_1", "2,3"); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); - logger.info(JSON.toJSONString(map)); - } } \ No newline at end of file diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index e6d3cb9def..e0a52bb3a7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -80,16 +80,4 @@ public class ProcessInstanceServiceTest { Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); logger.info(JSON.toJSONString(map)); } - - @Test - public void batchDeleteProcessInstanceByIds() throws Exception { - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - Map map = processInstanceService.batchDeleteProcessInstanceByIds(loginUser, "li_test_1", "4,2,300"); - - Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); - logger.info(JSON.toJSONString(map)); - } } \ No newline at end of file