Commit 995706f0 authored by ligang's avatar ligang
Browse files

update create and upgrade function

parent 45886e46
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -323,4 +323,29 @@ public class ProcessDefinitionController extends BaseController{
        }
    }

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

}
+3 −0
Original line number Diff line number Diff line
@@ -200,6 +200,9 @@ public enum Status {
    DATA_IS_NULL(50018,"data %s is null"),
    PROCESS_NODE_HAS_CYCLE(50019,"process node has cycle"),
    PROCESS_NODE_S_PARAMETER_INVALID(50020,"process node %s parameter invalid"),
    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"),

    HDFS_NOT_STARTUP(60001,"hdfs not startup"),

+59 −0
Original line number Diff line number Diff line
@@ -336,6 +336,65 @@ public class ProcessDefinitionService extends BaseDAGService {
        return result;
    }

    /**
     * delete process definition by id
     *
     * @param loginUser
     * @param projectName
     * @param processDefinitionId
     * @return
     */
    @Transactional(value = "TransactionManager", rollbackFor = Exception.class)
    public Map<String, Object> deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) {

        Map<String, Object> result = new HashMap<>(5);
        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;
        }


        ProcessDefinition processDefinition = processDefineMapper.queryByDefineId(processDefinitionId);

        if (processDefinition == null) {
            putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId);
            return result;
        }
        // check process definition is already online
        if (processDefinition.getReleaseState() == ReleaseState.ONLINE) {
            putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE,processDefinitionId);
            return result;
        }

        // get the timing according to the process definition
        List<Schedule> schedules = scheduleMapper.selectAllByProcessDefineArray(new int[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);
            return result;
        }else if(schedules.size() == 1){
            Schedule schedule = schedules.get(0);
            if(schedule.getReleaseState() == ReleaseState.OFFLINE){
                scheduleMapper.delete(schedule.getId());
            }else if(schedule.getReleaseState() == ReleaseState.ONLINE){
                putMsg(result, Status.SCHEDULE_CRON_STATE_ONLINE,schedule.getId());
                return result;
            }
        }

        int delete = processDefineMapper.delete(processDefinitionId);

        if (delete > 0) {
            putMsg(result, Status.SUCCESS);
        } else {
            putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
        }
        return result;
    }

    /**
     * release process definition: online / offline
     *
+12 −0
Original line number Diff line number Diff line
@@ -63,4 +63,16 @@ public class ProcessDefinitionServiceTest {
        Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
        logger.info(JSON.toJSONString(map));
    }

    @Test
    public void deleteProcessDefinitionByIdTest() throws Exception {

        User loginUser = new User();
        loginUser.setId(2);
        loginUser.setUserType(UserType.GENERAL_USER);
        Map<String, Object> map = processDefinitionService.deleteProcessDefinitionById(loginUser, "li_sql_test", 6);

        Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
        logger.info(JSON.toJSONString(map));
    }
}
 No newline at end of file
+7 −1
Original line number Diff line number Diff line
@@ -173,6 +173,12 @@ public interface ScheduleMapper {
  @SelectProvider(type = ScheduleMapperProvider.class, method = "selectAllByProcessDefineArray")
  List<Schedule> selectAllByProcessDefineArray(@Param("processDefineIds") int[] processDefineIds);


  /**
   * delete schedule by id
   * @param scheduleId
   * @return
   */
  @DeleteProvider(type = ScheduleMapperProvider.class, method = "delete")
  int delete(@Param("scheduleId") int scheduleId);

}
Loading