Search in sources :

Example 1 with Project

use of org.apache.dolphinscheduler.dao.entity.Project 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 Project

use of org.apache.dolphinscheduler.dao.entity.Project 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 Project

use of org.apache.dolphinscheduler.dao.entity.Project 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 Project

use of org.apache.dolphinscheduler.dao.entity.Project in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testQueryProcessDefinitionById.

@Test
public void testQueryProcessDefinitionById() {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    Map<String, Object> result = new HashMap<>(5);
    putMsg(result, Status.PROJECT_NOT_FOUNT, projectName);
    // project check auth fail
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Map<String, Object> map = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 1);
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
    // project check auth success, instance not exist
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Mockito.when(processDefineMapper.selectById(1)).thenReturn(null);
    Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 1);
    Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
    // instance exit
    Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition());
    Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 46);
    Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with Project

use of org.apache.dolphinscheduler.dao.entity.Project in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testVerifyProcessDefinitionName.

@Test
public void testVerifyProcessDefinitionName() {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    // project check auth fail
    Map<String, Object> result = new HashMap<>(5);
    putMsg(result, Status.PROJECT_NOT_FOUNT, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
    // project check auth success, process not exist
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(processDefineMapper.verifyByDefineName(project.getId(), "test_pdf")).thenReturn(null);
    Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
    // process exist
    Mockito.when(processDefineMapper.verifyByDefineName(project.getId(), "test_pdf")).thenReturn(getProcessDefinition());
    Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR, processExistRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

Project (org.apache.dolphinscheduler.dao.entity.Project)62 Test (org.junit.Test)29 User (org.apache.dolphinscheduler.dao.entity.User)28 ProcessDefinition (org.apache.dolphinscheduler.dao.entity.ProcessDefinition)25 JSONObject (com.alibaba.fastjson.JSONObject)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 HashMap (java.util.HashMap)21 Status (org.apache.dolphinscheduler.api.enums.Status)17 Schedule (org.apache.dolphinscheduler.dao.entity.Schedule)14 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)12 IPage (com.baomidou.mybatisplus.core.metadata.IPage)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)8 ArrayList (java.util.ArrayList)7 ProjectUser (org.apache.dolphinscheduler.dao.entity.ProjectUser)7 Transactional (org.springframework.transaction.annotation.Transactional)7 IOException (java.io.IOException)5 Date (java.util.Date)5 JSONArray (com.alibaba.fastjson.JSONArray)4 HashSet (java.util.HashSet)4