Browse Source

[Improvement-5059][API] Verify that the new workflow definition version is the current version before removing it #5059 (#5060)

* this process definition version is used, not allowed to delete.

* update ProcessDefinitionVersionServiceTest test class.

* update check has associated process definition sql.
pull/3/MERGE
zhuangchong 4 years ago committed by GitHub
parent
commit
705715c313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  2. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  3. 13
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  4. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java
  5. 13
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java
  6. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  7. 7
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  8. 4
      dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/versions.vue

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@ -297,7 +297,9 @@ public enum Status {
PLUGIN_INSTANCE_ALREADY_EXIT(110010, "plugin instance already exit", "该告警插件实例已存在"),
LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR(110011, "query plugin instance page error", "分页查询告警实例失败"),
DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED(110012, "failed to delete the alert instance, there is an alarm group associated with this alert instance",
"删除告警实例失败,存在与此告警实例关联的警报组");
"删除告警实例失败,存在与此告警实例关联的警报组"),
PROCESS_DEFINITION_VERSION_IS_USED(110013,"this process definition version is used","此工作流定义版本被使用");
private final int code;
private final String enMsg;

9
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -274,5 +274,14 @@ public interface ProcessDefinitionService {
*/
Map<String, Object> switchProcessDefinitionVersion(User loginUser, String projectName
, int processDefinitionId, long version);
/**
* check has associated process definition
*
* @param processDefinitionId process definition id
* @param version version
* @return The query result has a specific process definition return true
*/
boolean checkHasAssociatedProcessDefinition(int processDefinitionId, long version);
}

13
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -1798,5 +1798,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
/**
* check has associated process definition
*
* @param processDefinitionId process definition id
* @param version version
* @return The query result has a specific process definition return true
*/
@Override
public boolean checkHasAssociatedProcessDefinition(int processDefinitionId, long version) {
Integer hasAssociatedDefinitionId = processDefineMapper.queryHasAssociatedDefinitionByIdAndVersion(processDefinitionId, version);
return Objects.nonNull(hasAssociatedDefinitionId);
}
}

15
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java

@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.api.service.impl;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
@ -56,6 +57,9 @@ public class ProcessDefinitionVersionServiceImpl extends BaseServiceImpl impleme
@Autowired
private ProjectMapper projectMapper;
@Autowired
private ProcessDefinitionService processDefinitionService;
/**
* add the newest version of one process definition
*
@ -178,8 +182,19 @@ public class ProcessDefinitionVersionServiceImpl extends BaseServiceImpl impleme
if (resultStatus != Status.SUCCESS) {
return checkResult;
}
// check has associated process definition
boolean hasAssociatedProcessDefinition = processDefinitionService.checkHasAssociatedProcessDefinition(processDefinitionId, version);
if (hasAssociatedProcessDefinition) {
putMsg(result, Status.PROCESS_DEFINITION_VERSION_IS_USED);
return result;
}
processDefinitionVersionMapper.deleteByProcessDefinitionIdAndVersion(processDefinitionId, version);
putMsg(result, Status.SUCCESS);
return result;
}
}

13
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java

@ -63,6 +63,9 @@ public class ProcessDefinitionVersionServiceTest {
@Mock
private ProjectServiceImpl projectService;
@Mock
private ProcessDefinitionService processDefinitionService;
@Test
public void testAddProcessDefinitionVersion() {
long expectedVersion = 5L;
@ -201,6 +204,8 @@ public class ProcessDefinitionVersionServiceTest {
.thenReturn(1);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName))
.thenReturn(res);
Mockito.when(processDefinitionService.checkHasAssociatedProcessDefinition(processDefinitionId, version))
.thenReturn(false);
Map<String, Object> resultMap2 = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
loginUser
@ -210,6 +215,14 @@ public class ProcessDefinitionVersionServiceTest {
Assert.assertEquals(Status.SUCCESS, resultMap2.get(Constants.STATUS));
Mockito.when(processDefinitionService.checkHasAssociatedProcessDefinition(processDefinitionId, version))
.thenReturn(true);
Map<String, Object> resultMap3 = processDefinitionVersionService.deleteByProcessDefinitionIdAndVersion(
loginUser
, projectName
, processDefinitionId
, version);
Assert.assertEquals(Status.PROCESS_DEFINITION_VERSION_IS_USED, resultMap3.get(Constants.STATUS));
}
/**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java

@ -144,4 +144,12 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @return project ids list
*/
List<Integer> listProjectIds();
/**
* query has associated definition by id and version
* @param processDefinitionId process definition id
* @param version version
* @return definition id
*/
Integer queryHasAssociatedDefinitionByIdAndVersion(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version);
}

7
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -139,4 +139,11 @@
set version = #{version}
where id = #{processDefinitionId}
</update>
<select id="queryHasAssociatedDefinitionByIdAndVersion" resultType="java.lang.Integer">
select id
from t_ds_process_definition
where id = #{processDefinitionId}
and version = #{version} limit 1
</select>
</mapper>

4
dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/versions.vue

@ -50,7 +50,7 @@
:title="$t('Confirm Switch To This Version?')"
@onConfirm="_mVersionSwitchProcessDefinitionVersion(scope.row)"
>
<el-button type="primary" size="mini" icon="el-icon-warning" circle slot="reference"></el-button>
<el-button :disabled="scope.row.version === versionData.processDefinition.version" type="primary" size="mini" icon="el-icon-warning" circle slot="reference"></el-button>
</el-popconfirm>
</el-tooltip>
<el-tooltip :content="$t('Delete')" placement="top">
@ -62,7 +62,7 @@
:title="$t('Delete?')"
@onConfirm="_mVersionDeleteProcessDefinitionVersion(scope.row,scope.row.id)"
>
<el-button type="danger" size="mini" icon="el-icon-delete" circle slot="reference"></el-button>
<el-button :disabled="scope.row.version === versionData.processDefinition.version" type="danger" size="mini" icon="el-icon-delete" circle slot="reference"></el-button>
</el-popconfirm>
</el-tooltip>
</template>

Loading…
Cancel
Save