[Feature][jsonsplit] replace processDefinitionVersion with processDefinitionLog (#4942)
* Modify Project and ProjectUser Mapper * project_code is bigint(20) * modify saveProcessDefine, remove the duplicate code with createTaskAndRelation * modify import/export processdefinition, add genProcessData * modify listResources mothod and remove getResourceIds mothod * 1 * conflicts solve * modify listResources mothod and remove getResourceIds mothod * modify listResources mothod and remove getResourceIds mothod * replace processDefinitionVersion with processDefinitionLogjson_split
parent
779596cf05
commit
8b35e21390
|
|
@ -37,7 +37,6 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_PROCESS_DEFINI
|
|||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.exceptions.ApiException;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
|
||||
import org.apache.dolphinscheduler.api.utils.RegexUtils;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
|
|
@ -90,9 +89,6 @@ public class ProcessDefinitionController extends BaseController {
|
|||
@Autowired
|
||||
private ProcessDefinitionService processDefinitionService;
|
||||
|
||||
@Autowired
|
||||
private ProcessDefinitionVersionService processDefinitionVersionService;
|
||||
|
||||
/**
|
||||
* create process definition
|
||||
*
|
||||
|
|
@ -297,8 +293,9 @@ public class ProcessDefinitionController extends BaseController {
|
|||
@RequestParam(value = "pageSize") int pageSize,
|
||||
@RequestParam(value = "processDefinitionId") int processDefinitionId) {
|
||||
|
||||
Map<String, Object> result = processDefinitionVersionService.queryProcessDefinitionVersions(loginUser
|
||||
Map<String, Object> result = processDefinitionService.queryProcessDefinitionVersions(loginUser
|
||||
, projectName, pageNo, pageSize, processDefinitionId);
|
||||
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +348,7 @@ public class ProcessDefinitionController extends BaseController {
|
|||
@RequestParam(value = "processDefinitionId") int processDefinitionId,
|
||||
@RequestParam(value = "version") long version) {
|
||||
|
||||
Map<String, Object> result = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version);
|
||||
Map<String, Object> result = processDefinitionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version);
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -274,5 +274,30 @@ public interface ProcessDefinitionService {
|
|||
*/
|
||||
Map<String, Object> switchProcessDefinitionVersion(User loginUser, String projectName
|
||||
, int processDefinitionId, long version);
|
||||
|
||||
/**
|
||||
* query the pagination versions info by one certain process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the pagination process definition versions info of the certain process definition
|
||||
*/
|
||||
Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName,
|
||||
int pageNo, int pageSize, int processDefinitionId);
|
||||
|
||||
/**
|
||||
* delete one certain process definition by version number and process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return delele result code
|
||||
*/
|
||||
Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName,
|
||||
int processDefinitionId, long version);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* process definition version service
|
||||
*/
|
||||
public interface ProcessDefinitionVersionService {
|
||||
|
||||
/**
|
||||
* add the newest version of one process definition
|
||||
*
|
||||
* @param processDefinition the process definition that need to record version
|
||||
* @return the newest version number of this process definition
|
||||
*/
|
||||
int addProcessDefinitionVersion(ProcessDefinition processDefinition);
|
||||
|
||||
/**
|
||||
* query the pagination versions info by one certain process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the pagination process definition versions info of the certain process definition
|
||||
*/
|
||||
Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName,
|
||||
int pageNo, int pageSize, int processDefinitionId);
|
||||
|
||||
/**
|
||||
* query one certain process definition version by version number and process definition id
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return the process definition version info
|
||||
*/
|
||||
ProcessDefinitionVersion queryByProcessDefinitionIdAndVersion(int processDefinitionId,
|
||||
long version);
|
||||
|
||||
/**
|
||||
* delete one certain process definition by version number and process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return delele result code
|
||||
*/
|
||||
Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName,
|
||||
int processDefinitionId, long version);
|
||||
}
|
||||
|
|
@ -101,6 +101,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* process definition service impl
|
||||
|
|
@ -1701,4 +1702,85 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* query the pagination versions info by one certain process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the pagination process definition versions info of the certain process definition
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, int processDefinitionId) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// check the if pageNo or pageSize less than 1
|
||||
if (pageNo <= 0 || pageSize <= 0) {
|
||||
putMsg(result
|
||||
, Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
|
||||
, pageNo
|
||||
, pageSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
|
||||
// check project auth
|
||||
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
||||
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
|
||||
if (resultStatus != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
|
||||
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId);
|
||||
|
||||
PageInfo<ProcessDefinitionLog> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
Page<ProcessDefinitionLog> page = new Page<>(pageNo, pageSize);
|
||||
IPage<ProcessDefinitionLog> processDefinitionVersionsPaging = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, processDefinition.getCode());
|
||||
List<ProcessDefinitionLog> processDefinitionLogs = processDefinitionVersionsPaging.getRecords();
|
||||
|
||||
ProcessData processData = processService.genProcessData(processDefinition);
|
||||
processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData));
|
||||
pageInfo.setLists(processDefinitionLogs);
|
||||
pageInfo.setTotalCount((int) processDefinitionVersionsPaging.getTotal());
|
||||
return ImmutableMap.of(
|
||||
Constants.MSG, Status.SUCCESS.getMsg()
|
||||
, Constants.STATUS, Status.SUCCESS
|
||||
, Constants.DATA_LIST, pageInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete one certain process definition by version number and process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return delele result code
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, int processDefinitionId, long version) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
// check project auth
|
||||
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
||||
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
|
||||
if (resultStatus != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId);
|
||||
|
||||
if (processDefinition == null) {
|
||||
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionId);
|
||||
} else {
|
||||
processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(processDefinition.getCode(), version);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,184 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProjectService;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
import org.apache.dolphinscheduler.dao.entity.Project;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionVersionMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* process definition version service impl
|
||||
*/
|
||||
@Service
|
||||
public class ProcessDefinitionVersionServiceImpl extends BaseServiceImpl implements ProcessDefinitionVersionService {
|
||||
|
||||
@Autowired
|
||||
private ProcessDefinitionVersionMapper processDefinitionVersionMapper;
|
||||
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
/**
|
||||
* add the newest version of one process definition
|
||||
*
|
||||
* @param processDefinition the process definition that need to record version
|
||||
* @return the newest version number of this process definition
|
||||
*/
|
||||
@Override
|
||||
public int addProcessDefinitionVersion(ProcessDefinition processDefinition) {
|
||||
|
||||
long version = this.queryMaxVersionByProcessDefinitionId(processDefinition.getId()) + 1;
|
||||
|
||||
ProcessDefinitionVersion processDefinitionVersion = ProcessDefinitionVersion
|
||||
.newBuilder()
|
||||
.processDefinitionId(processDefinition.getId())
|
||||
.version(version)
|
||||
.description(processDefinition.getDescription())
|
||||
.locations(processDefinition.getLocations())
|
||||
.connects(processDefinition.getConnects())
|
||||
.timeout(processDefinition.getTimeout())
|
||||
.globalParams(processDefinition.getGlobalParams())
|
||||
.createTime(processDefinition.getUpdateTime())
|
||||
.warningGroupId(processDefinition.getWarningGroupId())
|
||||
.resourceIds(processDefinition.getResourceIds())
|
||||
.build();
|
||||
|
||||
processDefinitionVersionMapper.insert(processDefinitionVersion);
|
||||
|
||||
return Integer.parseInt(String.valueOf(version));
|
||||
}
|
||||
|
||||
/**
|
||||
* query the max version number by the process definition id
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the max version number of this id
|
||||
*/
|
||||
private long queryMaxVersionByProcessDefinitionId(int processDefinitionId) {
|
||||
Long maxVersion = processDefinitionVersionMapper.queryMaxVersionByProcessDefinitionId(processDefinitionId);
|
||||
if (Objects.isNull(maxVersion)) {
|
||||
return 0L;
|
||||
} else {
|
||||
return maxVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* query the pagination versions info by one certain process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param pageNo page number
|
||||
* @param pageSize page size
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the pagination process definition versions info of the certain process definition
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, int processDefinitionId) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// check the if pageNo or pageSize less than 1
|
||||
if (pageNo <= 0 || pageSize <= 0) {
|
||||
putMsg(result
|
||||
, Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
|
||||
, pageNo
|
||||
, pageSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
|
||||
// check project auth
|
||||
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
||||
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
|
||||
if (resultStatus != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
|
||||
PageInfo<ProcessDefinitionVersion> pageInfo = new PageInfo<>(pageNo, pageSize);
|
||||
Page<ProcessDefinitionVersion> page = new Page<>(pageNo, pageSize);
|
||||
IPage<ProcessDefinitionVersion> processDefinitionVersionsPaging = processDefinitionVersionMapper.queryProcessDefinitionVersionsPaging(page, processDefinitionId);
|
||||
List<ProcessDefinitionVersion> processDefinitionVersions = processDefinitionVersionsPaging.getRecords();
|
||||
pageInfo.setLists(processDefinitionVersions);
|
||||
pageInfo.setTotalCount((int) processDefinitionVersionsPaging.getTotal());
|
||||
return ImmutableMap.of(
|
||||
Constants.MSG, Status.SUCCESS.getMsg()
|
||||
, Constants.STATUS, Status.SUCCESS
|
||||
, Constants.DATA_LIST, pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* query one certain process definition version by version number and process definition id
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return the process definition version info
|
||||
*/
|
||||
@Override
|
||||
public ProcessDefinitionVersion queryByProcessDefinitionIdAndVersion(int processDefinitionId, long version) {
|
||||
return processDefinitionVersionMapper.queryByProcessDefinitionIdAndVersion(processDefinitionId, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete one certain process definition by version number and process definition id
|
||||
*
|
||||
* @param loginUser login user info to check auth
|
||||
* @param projectName process definition project name
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return delele result code
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, int processDefinitionId, long version) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
// check project auth
|
||||
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
||||
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
|
||||
if (resultStatus != Status.SUCCESS) {
|
||||
return checkResult;
|
||||
}
|
||||
processDefinitionVersionMapper.deleteByProcessDefinitionIdAndVersion(processDefinitionId, version);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,6 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|||
import org.apache.dolphinscheduler.api.service.ExecutorService;
|
||||
import org.apache.dolphinscheduler.api.service.LoggerService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessInstanceService;
|
||||
import org.apache.dolphinscheduler.api.service.ProjectService;
|
||||
import org.apache.dolphinscheduler.api.service.UsersService;
|
||||
|
|
@ -122,9 +121,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
|
|||
@Autowired
|
||||
ProcessDefinitionService processDefinitionService;
|
||||
|
||||
@Autowired
|
||||
ProcessDefinitionVersionService processDefinitionVersionService;
|
||||
|
||||
@Autowired
|
||||
ExecutorService execService;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.dolphinscheduler.api.controller;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
|
||||
import org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
|
|
@ -26,7 +25,7 @@ import org.apache.dolphinscheduler.common.Constants;
|
|||
import org.apache.dolphinscheduler.common.enums.ReleaseState;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog;
|
||||
import org.apache.dolphinscheduler.dao.entity.Resource;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
|
||||
|
|
@ -64,9 +63,6 @@ public class ProcessDefinitionControllerTest {
|
|||
@Mock
|
||||
private ProcessDefinitionServiceImpl processDefinitionService;
|
||||
|
||||
@Mock
|
||||
private ProcessDefinitionVersionService processDefinitionVersionService;
|
||||
|
||||
protected User user;
|
||||
|
||||
@Before
|
||||
|
|
@ -392,8 +388,8 @@ public class ProcessDefinitionControllerTest {
|
|||
String projectName = "test";
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
putMsg(resultMap, Status.SUCCESS);
|
||||
resultMap.put(Constants.DATA_LIST, new PageInfo<ProcessDefinitionVersion>(1, 10));
|
||||
Mockito.when(processDefinitionVersionService.queryProcessDefinitionVersions(
|
||||
resultMap.put(Constants.DATA_LIST, new PageInfo<ProcessDefinitionLog>(1, 10));
|
||||
Mockito.when(processDefinitionService.queryProcessDefinitionVersions(
|
||||
user
|
||||
, projectName
|
||||
, 1
|
||||
|
|
@ -435,7 +431,7 @@ public class ProcessDefinitionControllerTest {
|
|||
String projectName = "test";
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
putMsg(resultMap, Status.SUCCESS);
|
||||
Mockito.when(processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
|
||||
Mockito.when(processDefinitionService.deleteByProcessDefinitionIdAndVersion(
|
||||
user
|
||||
, projectName
|
||||
, 1
|
||||
|
|
|
|||
|
|
@ -253,8 +253,6 @@ public class ProcessDefinitionServiceTest {
|
|||
private ProcessInstanceService processInstanceService;
|
||||
@Mock
|
||||
private TaskInstanceMapper taskInstanceMapper;
|
||||
@Mock
|
||||
private ProcessDefinitionVersionService processDefinitionVersionService;
|
||||
|
||||
@Test
|
||||
public void testQueryProcessDefinitionList() {
|
||||
|
|
|
|||
|
|
@ -1,276 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionVersionServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
import org.apache.dolphinscheduler.dao.entity.Project;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionVersionMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* process definition version service test
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProcessDefinitionVersionServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private ProcessDefinitionVersionServiceImpl processDefinitionVersionService;
|
||||
|
||||
@Mock
|
||||
private ProcessDefinitionVersionMapper processDefinitionVersionMapper;
|
||||
|
||||
@Mock
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
@Mock
|
||||
private ProjectServiceImpl projectService;
|
||||
|
||||
@Test
|
||||
public void testAddProcessDefinitionVersion() {
|
||||
long expectedVersion = 5L;
|
||||
ProcessDefinition processDefinition = getProcessDefinition();
|
||||
Mockito.when(processDefinitionVersionMapper
|
||||
.queryMaxVersionByProcessDefinitionId(processDefinition.getId()))
|
||||
.thenReturn(expectedVersion);
|
||||
|
||||
int version = processDefinitionVersionService.addProcessDefinitionVersion(processDefinition);
|
||||
|
||||
Assert.assertEquals(expectedVersion + 1, version);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testQueryProcessDefinitionVersions() {
|
||||
// pageNo <= 0
|
||||
int pageNo = -1;
|
||||
int pageSize = 10;
|
||||
int processDefinitionId = 66;
|
||||
|
||||
String projectName = "project_test1";
|
||||
User loginUser = new User();
|
||||
loginUser.setId(-1);
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
Map<String, Object> resultMap1 = processDefinitionVersionService.queryProcessDefinitionVersions(
|
||||
loginUser
|
||||
, projectName
|
||||
, pageNo
|
||||
, pageSize
|
||||
, processDefinitionId);
|
||||
Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
|
||||
, resultMap1.get(Constants.STATUS));
|
||||
|
||||
// pageSize <= 0
|
||||
pageNo = 1;
|
||||
pageSize = -1;
|
||||
Map<String, Object> resultMap2 = processDefinitionVersionService.queryProcessDefinitionVersions(
|
||||
loginUser
|
||||
, projectName
|
||||
, pageNo
|
||||
, pageSize
|
||||
, processDefinitionId);
|
||||
Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR
|
||||
, resultMap2.get(Constants.STATUS));
|
||||
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
putMsg(res, Status.PROJECT_NOT_FOUNT);
|
||||
Project project = getProject(projectName);
|
||||
Mockito.when(projectMapper.queryByName(projectName))
|
||||
.thenReturn(project);
|
||||
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName))
|
||||
.thenReturn(res);
|
||||
|
||||
// project auth fail
|
||||
pageNo = 1;
|
||||
pageSize = 10;
|
||||
Map<String, Object> resultMap3 = processDefinitionVersionService.queryProcessDefinitionVersions(
|
||||
loginUser
|
||||
, projectName
|
||||
, pageNo
|
||||
, pageSize
|
||||
, processDefinitionId);
|
||||
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, resultMap3.get(Constants.STATUS));
|
||||
|
||||
putMsg(res, Status.SUCCESS);
|
||||
|
||||
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName))
|
||||
.thenReturn(res);
|
||||
|
||||
ProcessDefinitionVersion processDefinitionVersion = getProcessDefinitionVersion(getProcessDefinition());
|
||||
|
||||
Mockito.when(processDefinitionVersionMapper
|
||||
.queryProcessDefinitionVersionsPaging(Mockito.any(Page.class), Mockito.eq(processDefinitionId)))
|
||||
.thenReturn(new Page<ProcessDefinitionVersion>()
|
||||
.setRecords(Lists.newArrayList(processDefinitionVersion)));
|
||||
|
||||
Map<String, Object> resultMap4 = processDefinitionVersionService.queryProcessDefinitionVersions(
|
||||
loginUser
|
||||
, projectName
|
||||
, pageNo
|
||||
, pageSize
|
||||
, processDefinitionId);
|
||||
Assert.assertEquals(Status.SUCCESS, resultMap4.get(Constants.STATUS));
|
||||
Assert.assertEquals(processDefinitionVersion
|
||||
, ((PageInfo<ProcessDefinitionVersion>) resultMap4.get(Constants.DATA_LIST))
|
||||
.getLists().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByProcessDefinitionIdAndVersion() {
|
||||
|
||||
ProcessDefinitionVersion expectedProcessDefinitionVersion =
|
||||
getProcessDefinitionVersion(getProcessDefinition());
|
||||
|
||||
int processDefinitionId = 66;
|
||||
long version = 10;
|
||||
Mockito.when(processDefinitionVersionMapper.queryByProcessDefinitionIdAndVersion(processDefinitionId, version))
|
||||
.thenReturn(expectedProcessDefinitionVersion);
|
||||
|
||||
ProcessDefinitionVersion processDefinitionVersion = processDefinitionVersionService
|
||||
.queryByProcessDefinitionIdAndVersion(processDefinitionId, version);
|
||||
|
||||
Assert.assertEquals(expectedProcessDefinitionVersion, processDefinitionVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteByProcessDefinitionIdAndVersion() {
|
||||
String projectName = "project_test1";
|
||||
int processDefinitionId = 66;
|
||||
long version = 10;
|
||||
Project project = getProject(projectName);
|
||||
Mockito.when(projectMapper.queryByName(projectName))
|
||||
.thenReturn(project);
|
||||
|
||||
User loginUser = new User();
|
||||
loginUser.setId(-1);
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
|
||||
// project auth fail
|
||||
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName))
|
||||
.thenReturn(new HashMap<>());
|
||||
|
||||
Map<String, Object> resultMap1 = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
|
||||
loginUser
|
||||
, projectName
|
||||
, processDefinitionId
|
||||
, version);
|
||||
|
||||
Assert.assertEquals(0, resultMap1.size());
|
||||
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
putMsg(res, Status.SUCCESS);
|
||||
|
||||
Mockito.when(processDefinitionVersionMapper.deleteByProcessDefinitionIdAndVersion(processDefinitionId, version))
|
||||
.thenReturn(1);
|
||||
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName))
|
||||
.thenReturn(res);
|
||||
|
||||
Map<String, Object> resultMap2 = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
|
||||
loginUser
|
||||
, projectName
|
||||
, processDefinitionId
|
||||
, version);
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS, resultMap2.get(Constants.STATUS));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get mock processDefinitionVersion by processDefinition
|
||||
*
|
||||
* @return processDefinitionVersion
|
||||
*/
|
||||
private ProcessDefinitionVersion getProcessDefinitionVersion(ProcessDefinition processDefinition) {
|
||||
return ProcessDefinitionVersion
|
||||
.newBuilder()
|
||||
.processDefinitionId(processDefinition.getId())
|
||||
.version(1)
|
||||
.processDefinitionJson(processDefinition.getProcessDefinitionJson())
|
||||
.description(processDefinition.getDescription())
|
||||
.locations(processDefinition.getLocations())
|
||||
.connects(processDefinition.getConnects())
|
||||
.timeout(processDefinition.getTimeout())
|
||||
.globalParams(processDefinition.getGlobalParams())
|
||||
.createTime(processDefinition.getUpdateTime())
|
||||
.warningGroupId(processDefinition.getWarningGroupId())
|
||||
.resourceIds(processDefinition.getResourceIds())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* get mock processDefinition
|
||||
*
|
||||
* @return ProcessDefinition
|
||||
*/
|
||||
private ProcessDefinition getProcessDefinition() {
|
||||
|
||||
ProcessDefinition processDefinition = new ProcessDefinition();
|
||||
processDefinition.setId(66);
|
||||
processDefinition.setName("test_pdf");
|
||||
processDefinition.setProjectId(2);
|
||||
processDefinition.setTenantId(1);
|
||||
processDefinition.setDescription("");
|
||||
|
||||
return processDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* get mock Project
|
||||
*
|
||||
* @param projectName projectName
|
||||
* @return Project
|
||||
*/
|
||||
private Project getProject(String projectName) {
|
||||
Project project = new Project();
|
||||
project.setId(1);
|
||||
project.setName(projectName);
|
||||
project.setUserId(1);
|
||||
return project;
|
||||
}
|
||||
|
||||
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
|
||||
result.put(Constants.STATUS, status);
|
||||
if (statusParams != null && statusParams.length > 0) {
|
||||
result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams));
|
||||
} else {
|
||||
result.put(Constants.MSG, status.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -92,9 +92,6 @@ public class ProcessInstanceServiceTest {
|
|||
@Mock
|
||||
ProcessDefinitionService processDefinitionService;
|
||||
|
||||
@Mock
|
||||
ProcessDefinitionVersionService processDefinitionVersionService;
|
||||
|
||||
@Mock
|
||||
TaskInstanceMapper taskInstanceMapper;
|
||||
|
||||
|
|
@ -387,7 +384,6 @@ public class ProcessInstanceServiceTest {
|
|||
when(processService.getTenantForProcess(Mockito.anyInt(), Mockito.anyInt())).thenReturn(tenant);
|
||||
when(processService.updateProcessInstance(processInstance)).thenReturn(1);
|
||||
when(processDefinitionService.checkProcessNodeList(Mockito.any(), eq(shellJson))).thenReturn(result);
|
||||
when(processDefinitionVersionService.addProcessDefinitionVersion(processDefinition)).thenReturn(1);
|
||||
Map<String, Object> processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectName, 1,
|
||||
shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", "");
|
||||
Assert.assertEquals(Status.UPDATE_PROCESS_INSTANCE_ERROR, processInstanceFinishRes.get(Constants.STATUS));
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
/**
|
||||
* process definition log mapper interface
|
||||
|
|
@ -62,4 +64,23 @@ public interface ProcessDefinitionLogMapper extends BaseMapper<ProcessDefinition
|
|||
*/
|
||||
ProcessDefinitionLog queryByDefinitionCodeAndVersion(@Param("processDefinitionCode") Long processDefinitionCode,
|
||||
@Param("version") long version);
|
||||
|
||||
/**
|
||||
* query the paging process definition version list by pagination info
|
||||
*
|
||||
* @param page pagination info
|
||||
* @param processDefinitionCode process definition code
|
||||
* @return the paging process definition version list
|
||||
*/
|
||||
IPage<ProcessDefinitionLog> queryProcessDefinitionVersionsPaging(Page<ProcessDefinitionLog> page,
|
||||
@Param("processDefinitionCode") Long processDefinitionCode);
|
||||
|
||||
/**
|
||||
* delete the certain process definition version by process definition id and version number
|
||||
*
|
||||
* @param processDefinitionCode process definition code
|
||||
* @param version version number
|
||||
* @return delete result
|
||||
*/
|
||||
int deleteByProcessDefinitionCodeAndVersion(@Param("processDefinitionCode") Long processDefinitionCode, @Param("version") long version);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao.mapper;
|
|||
|
||||
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog;
|
||||
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -29,6 +30,7 @@ import java.util.Map;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
/**
|
||||
* process definition mapper interface
|
||||
|
|
@ -169,4 +171,15 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
|
|||
* @return project ids list
|
||||
*/
|
||||
List<Integer> listProjectIds();
|
||||
|
||||
|
||||
/**
|
||||
* query the paging process definition version list by pagination info
|
||||
*
|
||||
* @param page pagination info
|
||||
* @param processDefinitionCode process definition code
|
||||
* @return the paging process definition version list
|
||||
*/
|
||||
IPage<ProcessDefinitionLog> queryProcessDefinitionVersionsPaging(Page<ProcessDefinitionLog> page,
|
||||
@Param("processDefinitionCode") Long processDefinitionCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.mapper;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
/**
|
||||
* process definition mapper interface
|
||||
*/
|
||||
public interface ProcessDefinitionVersionMapper extends BaseMapper<ProcessDefinitionVersion> {
|
||||
|
||||
/**
|
||||
* query max version by process definition id
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the max version of this process definition id
|
||||
*/
|
||||
Long queryMaxVersionByProcessDefinitionId(@Param("processDefinitionId") int processDefinitionId);
|
||||
|
||||
/**
|
||||
* query the paging process definition version list by pagination info
|
||||
*
|
||||
* @param page pagination info
|
||||
* @param processDefinitionId process definition id
|
||||
* @return the paging process definition version list
|
||||
*/
|
||||
IPage<ProcessDefinitionVersion> queryProcessDefinitionVersionsPaging(Page<ProcessDefinitionVersion> page,
|
||||
@Param("processDefinitionId") int processDefinitionId);
|
||||
|
||||
/**
|
||||
* query the certain process definition version info by process definition id and version number
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return the process definition version info
|
||||
*/
|
||||
ProcessDefinitionVersion queryByProcessDefinitionIdAndVersion(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version);
|
||||
|
||||
/**
|
||||
* delete the certain process definition version by process definition id and version number
|
||||
*
|
||||
* @param processDefinitionId process definition id
|
||||
* @param version version number
|
||||
* @return delete result
|
||||
*/
|
||||
int deleteByProcessDefinitionIdAndVersion(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version);
|
||||
|
||||
}
|
||||
|
|
@ -56,4 +56,20 @@
|
|||
where code = #{processDefinitionCode}
|
||||
|
||||
</select>
|
||||
|
||||
<select id="queryProcessDefinitionVersionsPaging"
|
||||
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog">
|
||||
select
|
||||
<include refid="baseSql"/>
|
||||
from t_ds_process_definition_log
|
||||
where code = #{processDefinitionCode}
|
||||
order by version desc
|
||||
</select>
|
||||
|
||||
<delete id="deleteByProcessDefinitionCodeAndVersion">
|
||||
delete
|
||||
from t_ds_process_definition_log
|
||||
where code = #{processDefinitionCode}
|
||||
and version = #{version}
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionVersionMapper">
|
||||
<sql id="baseSql">
|
||||
id
|
||||
, process_definition_id, version, process_definition_json, description, global_params,locations,connects,
|
||||
warning_group_id, create_time, timeout, resource_ids
|
||||
</sql>
|
||||
<select id="queryMaxVersionByProcessDefinitionId" resultType="java.lang.Long">
|
||||
select max(version)
|
||||
from t_ds_process_definition_version
|
||||
where process_definition_id = #{processDefinitionId}
|
||||
</select>
|
||||
|
||||
<select id="queryProcessDefinitionVersionsPaging"
|
||||
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
|
||||
select
|
||||
<include refid="baseSql"/>
|
||||
from t_ds_process_definition_version
|
||||
where process_definition_id = #{processDefinitionId}
|
||||
order by version desc
|
||||
</select>
|
||||
|
||||
<select id="queryByProcessDefinitionIdAndVersion"
|
||||
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
|
||||
select
|
||||
<include refid="baseSql"/>
|
||||
from t_ds_process_definition_version
|
||||
where process_definition_id = #{processDefinitionId}
|
||||
and version = #{version}
|
||||
</select>
|
||||
|
||||
<delete id="deleteByProcessDefinitionIdAndVersion">
|
||||
delete
|
||||
from t_ds_process_definition_version
|
||||
where process_definition_id = #{processDefinitionId}
|
||||
and version = #{version}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.mapper;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.StringUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Transactional
|
||||
@Rollback(true)
|
||||
public class ProcessDefinitionVersionMapperTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
ProcessDefinitionMapper processDefinitionMapper;
|
||||
|
||||
@Autowired
|
||||
ProcessDefinitionVersionMapper processDefinitionVersionMapper;
|
||||
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
QueueMapper queueMapper;
|
||||
|
||||
@Autowired
|
||||
TenantMapper tenantMapper;
|
||||
|
||||
@Autowired
|
||||
ProjectMapper projectMapper;
|
||||
|
||||
/**
|
||||
* insert
|
||||
*
|
||||
* @return ProcessDefinition
|
||||
*/
|
||||
private ProcessDefinitionVersion insertOne() {
|
||||
// insertOne
|
||||
ProcessDefinitionVersion processDefinitionVersion
|
||||
= new ProcessDefinitionVersion();
|
||||
processDefinitionVersion.setProcessDefinitionId(66);
|
||||
processDefinitionVersion.setVersion(10);
|
||||
processDefinitionVersion.setProcessDefinitionJson(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setDescription(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setGlobalParams(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setCreateTime(new Date());
|
||||
processDefinitionVersion.setLocations(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setConnects(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setTimeout(10);
|
||||
processDefinitionVersion.setResourceIds("1,2");
|
||||
processDefinitionVersionMapper.insert(processDefinitionVersion);
|
||||
return processDefinitionVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* insert
|
||||
*
|
||||
* @return ProcessDefinitionVersion
|
||||
*/
|
||||
private ProcessDefinitionVersion insertTwo() {
|
||||
// insertTwo
|
||||
ProcessDefinitionVersion processDefinitionVersion
|
||||
= new ProcessDefinitionVersion();
|
||||
processDefinitionVersion.setProcessDefinitionId(67);
|
||||
processDefinitionVersion.setVersion(11);
|
||||
processDefinitionVersion.setProcessDefinitionJson(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setDescription(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setGlobalParams(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setCreateTime(new Date());
|
||||
processDefinitionVersion.setLocations(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setConnects(StringUtils.EMPTY);
|
||||
processDefinitionVersion.setTimeout(10);
|
||||
processDefinitionVersion.setResourceIds("1,2");
|
||||
processDefinitionVersionMapper.insert(processDefinitionVersion);
|
||||
return processDefinitionVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* test insert
|
||||
*/
|
||||
@Test
|
||||
public void testInsert() {
|
||||
ProcessDefinitionVersion processDefinitionVersion = insertOne();
|
||||
Assert.assertTrue(processDefinitionVersion.getId() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test query
|
||||
*/
|
||||
@Test
|
||||
public void testQueryMaxVersionByProcessDefinitionId() {
|
||||
ProcessDefinitionVersion processDefinitionVersion = insertOne();
|
||||
|
||||
Long version = processDefinitionVersionMapper.queryMaxVersionByProcessDefinitionId(
|
||||
processDefinitionVersion.getProcessDefinitionId());
|
||||
// query
|
||||
Assert.assertEquals(10, (long) version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryProcessDefinitionVersionsPaging() {
|
||||
insertOne();
|
||||
insertTwo();
|
||||
|
||||
Page<ProcessDefinitionVersion> page = new Page<>(1, 3);
|
||||
|
||||
IPage<ProcessDefinitionVersion> processDefinitionVersionIPage =
|
||||
processDefinitionVersionMapper.queryProcessDefinitionVersionsPaging(page, 10);
|
||||
|
||||
Assert.assertTrue(processDefinitionVersionIPage.getSize() >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteByProcessDefinitionIdAndVersion() {
|
||||
ProcessDefinitionVersion processDefinitionVersion = insertOne();
|
||||
int i = processDefinitionVersionMapper.deleteByProcessDefinitionIdAndVersion(
|
||||
processDefinitionVersion.getProcessDefinitionId(), processDefinitionVersion.getVersion());
|
||||
Assert.assertEquals(1, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByProcessDefinitionIdAndVersion() {
|
||||
ProcessDefinitionVersion processDefinitionVersion1 = insertOne();
|
||||
ProcessDefinitionVersion processDefinitionVersion3 = processDefinitionVersionMapper.queryByProcessDefinitionIdAndVersion(
|
||||
processDefinitionVersion1.getProcessDefinitionId(), 10);
|
||||
|
||||
ProcessDefinitionVersion processDefinitionVersion2 = insertTwo();
|
||||
ProcessDefinitionVersion processDefinitionVersion4 = processDefinitionVersionMapper.queryByProcessDefinitionIdAndVersion(
|
||||
processDefinitionVersion2.getProcessDefinitionId(), 11);
|
||||
|
||||
Assert.assertEquals(processDefinitionVersion1.getProcessDefinitionId(),
|
||||
processDefinitionVersion3.getProcessDefinitionId());
|
||||
Assert.assertEquals(processDefinitionVersion2.getProcessDefinitionId(),
|
||||
processDefinitionVersion4.getProcessDefinitionId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue