Browse Source

[Bug][PGSQL] Delete the stopped workflow without deleting the correspon… (#5066)

* [Bug][Api] Delete the stopped workflow without deleting the corresponding sub process, the workflow instance name is not displayed in the sub process

* fix ut

* fix ut err

* sql style

* fix error
pull/3/MERGE
Kirs 4 years ago committed by GitHub
parent
commit
f109a758f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
  2. 3
      sql/dolphinscheduler_postgre.sql
  3. 18
      sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql
  4. 16
      sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_dml.sql

37
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.enums.Flag;
@ -32,6 +33,7 @@ import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -43,7 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
@Rollback
public class TaskInstanceMapperTest {
@ -59,6 +61,17 @@ public class TaskInstanceMapperTest {
@Autowired
ProcessInstanceMapMapper processInstanceMapMapper;
private int processInstanceId;
@Before
public void before() {
ProcessInstance processInstance = new ProcessInstance();
processInstance.setWarningGroupId(0);
processInstance.setCommandParam("");
processInstanceMapper.insert(processInstance);
processInstanceId = processInstance.getId();
}
/**
* insert
*
@ -66,19 +79,13 @@ public class TaskInstanceMapperTest {
*/
private TaskInstance insertOne() {
//insertOne
return insertOne("us task", 1, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString());
return insertOne("us task", processInstanceId, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString(),1);
}
/**
* construct a task instance and then insert
*
* @param taskName
* @param processInstanceId
* @param state
* @param taskType
* @return
*/
private TaskInstance insertOne(String taskName, int processInstanceId, ExecutionStatus state, String taskType) {
private TaskInstance insertOne(String taskName, int processInstanceId, ExecutionStatus state, String taskType,int processDefinitionId) {
TaskInstance taskInstance = new TaskInstance();
taskInstance.setFlag(Flag.YES);
taskInstance.setName(taskName);
@ -88,6 +95,7 @@ public class TaskInstanceMapperTest {
taskInstance.setTaskJson("{}");
taskInstance.setProcessInstanceId(processInstanceId);
taskInstance.setTaskType(taskType);
taskInstance.setProcessDefinitionId(processDefinitionId);
taskInstanceMapper.insert(taskInstance);
return taskInstance;
}
@ -133,7 +141,7 @@ public class TaskInstanceMapperTest {
@Test
public void testQueryTaskByProcessIdAndState() {
TaskInstance task = insertOne();
task.setProcessInstanceId(110);
task.setProcessInstanceId(processInstanceId);
taskInstanceMapper.updateById(task);
List<Integer> taskInstances = taskInstanceMapper.queryTaskByProcessIdAndState(
task.getProcessInstanceId(),
@ -150,8 +158,8 @@ public class TaskInstanceMapperTest {
public void testFindValidTaskListByProcessId() {
TaskInstance task = insertOne();
TaskInstance task2 = insertOne();
task.setProcessInstanceId(110);
task2.setProcessInstanceId(110);
task.setProcessInstanceId(processInstanceId);
task2.setProcessInstanceId(processInstanceId);
taskInstanceMapper.updateById(task);
taskInstanceMapper.updateById(task2);
@ -279,7 +287,6 @@ public class TaskInstanceMapperTest {
*/
@Test
public void testQueryTaskInstanceListPaging() {
TaskInstance task = insertOne();
ProcessDefinition definition = new ProcessDefinition();
definition.setProjectId(1111);
@ -294,9 +301,7 @@ public class TaskInstanceMapperTest {
processInstance.setCommandType(CommandType.START_PROCESS);
processInstanceMapper.insert(processInstance);
task.setProcessDefinitionId(definition.getId());
task.setProcessInstanceId(processInstance.getId());
taskInstanceMapper.updateById(task);
TaskInstance task = insertOne("us task", processInstance.getId(), ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString(),definition.getId());
Page<TaskInstance> page = new Page(1, 3);
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(

3
sql/dolphinscheduler_postgre.sql

@ -578,7 +578,8 @@ CREATE TABLE t_ds_task_instance (
first_submit_time timestamp DEFAULT NULL ,
delay_time int DEFAULT '0' ,
var_pool text ,
PRIMARY KEY (id)
PRIMARY KEY (id),
CONSTRAINT foreign_key_instance_id FOREIGN KEY(process_instance_id) REFERENCES t_ds_process_instance(id) ON DELETE CASCADE
) ;
--

18
sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql

@ -0,0 +1,18 @@
/*
* 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.
*/
-- Add foreign key constraints for t_ds_task_instance --
ALTER TABLE t_ds_task_instance ADD CONSTRAINT foreign_key_instance_id FOREIGN KEY(process_instance_id) REFERENCES t_ds_process_instance(id) ON DELETE CASCADE;

16
sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_dml.sql

@ -0,0 +1,16 @@
/*
* 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.
*/
Loading…
Cancel
Save