Browse Source
* 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 processDefinitionLogpull/3/MERGE
Simon
4 years ago
committed by
GitHub
16 changed files with 164 additions and 851 deletions
@ -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); |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
|
||||
} |
@ -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