Search in sources :

Example 1 with Status

use of org.apache.dolphinscheduler.api.enums.Status in project dolphinscheduler by apache.

the class ProcessDefinitionService method queryProcessDefinitionListPaging.

/**
 * query process definition list paging
 *
 * @param loginUser login user
 * @param projectName project name
 * @param searchVal search value
 * @param pageNo page number
 * @param pageSize page size
 * @param userId user id
 * @return process definition page
 */
public Map<String, Object> queryProcessDefinitionListPaging(User loginUser, String projectName, String searchVal, Integer pageNo, Integer pageSize, Integer userId) {
    Map<String, Object> result = new HashMap<>(5);
    Project project = projectMapper.queryByName(projectName);
    Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
    Status resultStatus = (Status) checkResult.get(Constants.STATUS);
    if (resultStatus != Status.SUCCESS) {
        return checkResult;
    }
    Page<ProcessDefinition> page = new Page(pageNo, pageSize);
    IPage<ProcessDefinition> processDefinitionIPage = processDefineMapper.queryDefineListPaging(page, searchVal, userId, project.getId(), isAdmin(loginUser));
    PageInfo pageInfo = new PageInfo<ProcessData>(pageNo, pageSize);
    pageInfo.setTotalCount((int) processDefinitionIPage.getTotal());
    pageInfo.setLists(processDefinitionIPage.getRecords());
    result.put(Constants.DATA_LIST, pageInfo);
    putMsg(result, Status.SUCCESS);
    return result;
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) Project(org.apache.dolphinscheduler.dao.entity.Project) PageInfo(org.apache.dolphinscheduler.api.utils.PageInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 2 with Status

use of org.apache.dolphinscheduler.api.enums.Status in project dolphinscheduler by apache.

the class ProcessDefinitionService method batchExportProcessDefinitionByIds.

/**
 * batch export process definition by ids
 * @param loginUser
 * @param projectName
 * @param processDefinitionIds
 * @param response
 */
public void batchExportProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds, HttpServletResponse response) {
    if (StringUtils.isEmpty(processDefinitionIds)) {
        return;
    }
    // export project info
    Project project = projectMapper.queryByName(projectName);
    // check user access for project
    Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
    Status resultStatus = (Status) checkResult.get(Constants.STATUS);
    if (resultStatus != Status.SUCCESS) {
        return;
    }
    List<ProcessMeta> processDefinitionList = getProcessDefinitionList(processDefinitionIds);
    if (CollectionUtils.isNotEmpty(processDefinitionList)) {
        downloadProcessDefinitionFile(response, processDefinitionList);
    }
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) Project(org.apache.dolphinscheduler.dao.entity.Project) JSONObject(com.alibaba.fastjson.JSONObject) ProcessMeta(org.apache.dolphinscheduler.api.dto.ProcessMeta)

Example 3 with Status

use of org.apache.dolphinscheduler.api.enums.Status in project dolphinscheduler by apache.

the class ProcessDefinitionService method deleteProcessDefinitionById.

/**
 * delete process definition by id
 *
 * @param loginUser login user
 * @param projectName project name
 * @param processDefinitionId process definition id
 * @return delete result code
 */
@Transactional(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.selectById(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() && loginUser.getUserType() != UserType.ADMIN_USER) {
        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);
        return result;
    }
    // get the timing according to the process definition
    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);
        return result;
    } else if (schedules.size() == 1) {
        Schedule schedule = schedules.get(0);
        if (schedule.getReleaseState() == ReleaseState.OFFLINE) {
            scheduleMapper.deleteById(schedule.getId());
        } else if (schedule.getReleaseState() == ReleaseState.ONLINE) {
            putMsg(result, Status.SCHEDULE_CRON_STATE_ONLINE, schedule.getId());
            return result;
        }
    }
    int delete = processDefineMapper.deleteById(processDefinitionId);
    if (delete > 0) {
        putMsg(result, Status.SUCCESS);
    } else {
        putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
    }
    return result;
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) Project(org.apache.dolphinscheduler.dao.entity.Project) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Schedule(org.apache.dolphinscheduler.dao.entity.Schedule) JSONObject(com.alibaba.fastjson.JSONObject) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Status

use of org.apache.dolphinscheduler.api.enums.Status in project dolphinscheduler by apache.

the class BaseController method returnDataListPaging.

/**
 * return data list with paging
 * @param result result code
 * @return result code
 */
public Result returnDataListPaging(Map<String, Object> result) {
    Status status = (Status) result.get(Constants.STATUS);
    if (status == Status.SUCCESS) {
        result.put(Constants.MSG, Status.SUCCESS.getMsg());
        PageInfo<Resource> pageInfo = (PageInfo<Resource>) result.get(Constants.DATA_LIST);
        return success(pageInfo.getLists(), pageInfo.getCurrentPage(), pageInfo.getTotalCount(), pageInfo.getTotalPage());
    } else {
        Integer code = status.getCode();
        String msg = (String) result.get(Constants.MSG);
        return error(code, msg);
    }
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) PageInfo(org.apache.dolphinscheduler.api.utils.PageInfo) Resource(org.apache.dolphinscheduler.dao.entity.Resource)

Example 5 with Status

use of org.apache.dolphinscheduler.api.enums.Status in project dolphinscheduler by apache.

the class ProjectServiceTest method testCheckProjectAndAuth.

@Test
public void testCheckProjectAndAuth() {
    Mockito.when(projectUserMapper.queryProjectRelation(1, 1)).thenReturn(getProjectUser());
    User loginUser = getLoginUser();
    Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, null, projectName);
    logger.info(result.toString());
    Status status = (Status) result.get(Constants.STATUS);
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS));
    Project project = getProject();
    // USER_NO_OPERATION_PROJECT_PERM
    project.setUserId(2);
    result = projectService.checkProjectAndAuth(loginUser, project, projectName);
    logger.info(result.toString());
    Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS));
    // success
    project.setUserId(1);
    result = projectService.checkProjectAndAuth(loginUser, project, projectName);
    logger.info(result.toString());
    Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
}
Also used : Status(org.apache.dolphinscheduler.api.enums.Status) Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) ProjectUser(org.apache.dolphinscheduler.dao.entity.ProjectUser) Test(org.junit.Test)

Aggregations

Status (org.apache.dolphinscheduler.api.enums.Status)29 Project (org.apache.dolphinscheduler.dao.entity.Project)14 JSONObject (com.alibaba.fastjson.JSONObject)11 HashMap (java.util.HashMap)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 ProcessDefinition (org.apache.dolphinscheduler.dao.entity.ProcessDefinition)9 ExecutionStatus (org.apache.dolphinscheduler.common.enums.ExecutionStatus)8 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 Property (org.apache.dolphinscheduler.common.process.Property)3 Schedule (org.apache.dolphinscheduler.dao.entity.Schedule)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ProcessData (org.apache.dolphinscheduler.dao.entity.ProcessData)2 User (org.apache.dolphinscheduler.dao.entity.User)2 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1