Commit 13e31da0 authored by baoliang's avatar baoliang
Browse files

Merge remote-tracking branch 'upstream/branch-1.0.2' into 102

parents 0bf8e270 5956409a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -350,4 +350,29 @@ public class ProcessDefinitionController extends BaseController{
        }
    }

    /**
     * batch delete process definition by ids
     *
     * @param loginUser
     * @param projectName
     * @param processDefinitionIds
     * @return
     */
    @GetMapping(value="/batch-delete")
    @ResponseStatus(HttpStatus.OK)
    public Result batchDeleteProcessDefinitionByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                              @PathVariable String projectName,
                                              @RequestParam("processDefinitionIds") String processDefinitionIds
    ){
        try{
            logger.info("delete process definition by ids, login user:{}, project name:{}, process definition ids:{}",
                    loginUser.getUserName(), projectName, processDefinitionIds);
            Map<String, Object> result = processDefinitionService.batchDeleteProcessDefinitionByIds(loginUser, projectName, processDefinitionIds);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(),e);
            return error(Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getCode(), Status.BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR.getMsg());
        }
    }

}
+31 −1
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.common.enums.Flag;
import cn.escheduler.common.queue.ITaskQueue;
import cn.escheduler.common.queue.TaskQueueFactory;
import cn.escheduler.common.utils.ParameterUtils;
import cn.escheduler.dao.model.User;
import org.slf4j.Logger;
@@ -189,7 +191,9 @@ public class ProcessInstanceController extends BaseController{
        try{
            logger.info("delete process instance by id, login user:{}, project name:{}, process instance id:{}",
                    loginUser.getUserName(), projectName, processInstanceId);
            Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId);
            // task queue
            ITaskQueue tasksQueue = TaskQueueFactory.getTaskQueueInstance();
            Map<String, Object> result = processInstanceService.deleteProcessInstanceById(loginUser, projectName, processInstanceId,tasksQueue);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getMsg(),e);
@@ -282,4 +286,30 @@ public class ProcessInstanceController extends BaseController{
            return error(Status.ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getCode(),ENCAPSULATION_PROCESS_INSTANCE_GANTT_STRUCTURE_ERROR.getMsg());
        }
    }

    /**
     * batch delete process instance by ids, at the same time,
     * delete task instance and their mapping relation data
     *
     * @param loginUser
     * @param projectName
     * @param processInstanceIds
     * @return
     */
    @GetMapping(value="/batch-delete")
    @ResponseStatus(HttpStatus.OK)
    public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                            @PathVariable String projectName,
                                            @RequestParam("processInstanceIds") String processInstanceIds
    ){
        try{
            logger.info("delete process instance by ids, login user:{}, project name:{}, process instance ids :{}",
                    loginUser.getUserName(), projectName, processInstanceIds);
            Map<String, Object> result = processInstanceService.batchDeleteProcessInstanceByIds(loginUser, projectName, processInstanceIds);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getMsg(),e);
            return error(Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getCode(), Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR.getMsg());
        }
    }
}
+25 −0
Original line number Diff line number Diff line
@@ -232,4 +232,29 @@ public class SchedulerController extends BaseController{
          return error(Status.QUERY_SCHEDULE_LIST_ERROR.getCode(), Status.QUERY_SCHEDULE_LIST_ERROR.getMsg());
      }
  }

    /**
     * delete schedule by id
     *
     * @param loginUser
     * @param projectName
     * @param scheduleId
     * @return
     */
    @GetMapping(value="/delete")
    @ResponseStatus(HttpStatus.OK)
    public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser,
                                              @PathVariable String projectName,
                                              @RequestParam("scheduleId") Integer scheduleId
    ){
        try{
            logger.info("delete schedule by id, login user:{}, project name:{}, schedule id:{}",
                    loginUser.getUserName(), projectName, scheduleId);
            Map<String, Object> result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId);
            return returnDataList(result);
        }catch (Exception e){
            logger.error(DELETE_SCHEDULE_CRON_BY_ID_ERROR.getMsg(),e);
            return error(Status.DELETE_SCHEDULE_CRON_BY_ID_ERROR.getCode(), Status.DELETE_SCHEDULE_CRON_BY_ID_ERROR.getMsg());
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ public enum Status {
    NAME_EXIST(10135, "name {0} already exists"),
    SAVE_ERROR(10136, "save error"),
    DELETE_PROJECT_ERROR_DEFINES_NOT_NULL(10137, "please delete the process definitions in project first!"),
    BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR(10117,"batch delete process instance by ids {0} error"),



@@ -204,8 +205,13 @@ public enum Status {
    PROCESS_DEFINE_STATE_ONLINE(50021, "process definition {0} is already on line"),
    DELETE_PROCESS_DEFINE_BY_ID_ERROR(50022,"delete process definition by id error"),
    SCHEDULE_CRON_STATE_ONLINE(50023,"the status of schedule {0} is already on line"),
    DELETE_SCHEDULE_CRON_BY_ID_ERROR(50024,"delete schedule by id error"),
    BATCH_DELETE_PROCESS_DEFINE_ERROR(50025,"batch delete process definition error"),
    BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR(50026,"batch delete process definition by ids {0} error"),

    HDFS_NOT_STARTUP(60001,"hdfs not startup"),
    HDFS_TERANT_RESOURCES_FILE_EXISTS(60002,"resource file exists,please delete resource first"),
    HDFS_TERANT_UDFS_FILE_EXISTS(60003,"udf file exists,please delete resource first"),

    /**
     * for monitor
+58 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import cn.escheduler.dao.mapper.*;
import cn.escheduler.dao.model.*;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -356,13 +357,19 @@ public class ProcessDefinitionService extends BaseDAGService {
            return checkResult;
        }


        ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefinitionId);

        if (processDefinition == null) {
            putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId);
            return result;
        }

        // Determine if the login user is the owner of the process definition
        if (loginUser.getId() != processDefinition.getUserId()) {
            putMsg(result, Status.USER_NO_OPERATION_PERM);
            return result;
        }

        // check process definition is already online
        if (processDefinition.getReleaseState() == ReleaseState.ONLINE) {
            putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE,processDefinitionId);
@@ -370,7 +377,7 @@ public class ProcessDefinitionService extends BaseDAGService {
        }

        // get the timing according to the process definition
        List<Schedule> schedules = scheduleMapper.selectAllByProcessDefineArray(new int[processDefinitionId]);
        List<Schedule> schedules = scheduleMapper.queryByProcessDefinitionId(processDefinitionId);
        if (!schedules.isEmpty() && schedules.size() > 1) {
            logger.warn("scheduler num is {},Greater than 1",schedules.size());
            putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
@@ -395,6 +402,55 @@ public class ProcessDefinitionService extends BaseDAGService {
        return result;
    }

    /**
     * batch delete process definition by ids
     *
     * @param loginUser
     * @param projectName
     * @param processDefinitionIds
     * @return
     */
    public Map<String, Object> batchDeleteProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds) {

        Map<String, Object> result = new HashMap<>(5);

        Map<String, Object> deleteReuslt = new HashMap<>(5);

        List<Integer> deleteFailedIdList = new ArrayList<Integer>();
        Project project = projectMapper.queryByName(projectName);

        Map<String, Object> 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
     *
Loading