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
Kirs 4 years ago
parent
commit
f109a758f8

+ 24 - 19
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.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
 import org.apache.dolphinscheduler.common.enums.CommandType;
 import org.apache.dolphinscheduler.common.enums.CommandType;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.enums.Flag;
 import org.apache.dolphinscheduler.common.enums.Flag;
@@ -32,6 +33,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
 import org.junit.Assert;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
 @RunWith(SpringRunner.class)
 @RunWith(SpringRunner.class)
 @SpringBootTest
 @SpringBootTest
 @Transactional
 @Transactional
-@Rollback(true)
+@Rollback
 public class TaskInstanceMapperTest {
 public class TaskInstanceMapperTest {
 
 
 
 
@@ -59,6 +61,17 @@ public class TaskInstanceMapperTest {
     @Autowired
     @Autowired
     ProcessInstanceMapMapper processInstanceMapMapper;
     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
      * insert
      *
      *
@@ -66,19 +79,13 @@ public class TaskInstanceMapperTest {
      */
      */
     private TaskInstance insertOne() {
     private TaskInstance insertOne() {
         //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
      * 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 taskInstance = new TaskInstance();
         taskInstance.setFlag(Flag.YES);
         taskInstance.setFlag(Flag.YES);
         taskInstance.setName(taskName);
         taskInstance.setName(taskName);
@@ -88,6 +95,7 @@ public class TaskInstanceMapperTest {
         taskInstance.setTaskJson("{}");
         taskInstance.setTaskJson("{}");
         taskInstance.setProcessInstanceId(processInstanceId);
         taskInstance.setProcessInstanceId(processInstanceId);
         taskInstance.setTaskType(taskType);
         taskInstance.setTaskType(taskType);
+        taskInstance.setProcessDefinitionId(processDefinitionId);
         taskInstanceMapper.insert(taskInstance);
         taskInstanceMapper.insert(taskInstance);
         return taskInstance;
         return taskInstance;
     }
     }
@@ -96,7 +104,7 @@ public class TaskInstanceMapperTest {
      * test update
      * test update
      */
      */
     @Test
     @Test
-    public void testUpdate(){
+    public void testUpdate() {
         //insertOne
         //insertOne
         TaskInstance taskInstance = insertOne();
         TaskInstance taskInstance = insertOne();
         //update
         //update
@@ -133,7 +141,7 @@ public class TaskInstanceMapperTest {
     @Test
     @Test
     public void testQueryTaskByProcessIdAndState() {
     public void testQueryTaskByProcessIdAndState() {
         TaskInstance task = insertOne();
         TaskInstance task = insertOne();
-        task.setProcessInstanceId(110);
+        task.setProcessInstanceId(processInstanceId);
         taskInstanceMapper.updateById(task);
         taskInstanceMapper.updateById(task);
         List<Integer> taskInstances = taskInstanceMapper.queryTaskByProcessIdAndState(
         List<Integer> taskInstances = taskInstanceMapper.queryTaskByProcessIdAndState(
                 task.getProcessInstanceId(),
                 task.getProcessInstanceId(),
@@ -150,8 +158,8 @@ public class TaskInstanceMapperTest {
     public void testFindValidTaskListByProcessId() {
     public void testFindValidTaskListByProcessId() {
         TaskInstance task = insertOne();
         TaskInstance task = insertOne();
         TaskInstance task2 = insertOne();
         TaskInstance task2 = insertOne();
-        task.setProcessInstanceId(110);
-        task2.setProcessInstanceId(110);
+        task.setProcessInstanceId(processInstanceId);
+        task2.setProcessInstanceId(processInstanceId);
         taskInstanceMapper.updateById(task);
         taskInstanceMapper.updateById(task);
         taskInstanceMapper.updateById(task2);
         taskInstanceMapper.updateById(task2);
 
 
@@ -279,7 +287,6 @@ public class TaskInstanceMapperTest {
      */
      */
     @Test
     @Test
     public void testQueryTaskInstanceListPaging() {
     public void testQueryTaskInstanceListPaging() {
-        TaskInstance task = insertOne();
 
 
         ProcessDefinition definition = new ProcessDefinition();
         ProcessDefinition definition = new ProcessDefinition();
         definition.setProjectId(1111);
         definition.setProjectId(1111);
@@ -294,11 +301,9 @@ public class TaskInstanceMapperTest {
         processInstance.setCommandType(CommandType.START_PROCESS);
         processInstance.setCommandType(CommandType.START_PROCESS);
         processInstanceMapper.insert(processInstance);
         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);
+        Page<TaskInstance> page = new Page(1, 3);
         IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
         IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
                 page,
                 page,
                 definition.getProjectId(),
                 definition.getProjectId(),
@@ -309,7 +314,7 @@ public class TaskInstanceMapperTest {
                 0,
                 0,
                 new int[0],
                 new int[0],
                 "",
                 "",
-                null,null
+                null, null
         );
         );
         processInstanceMapper.deleteById(processInstance.getId());
         processInstanceMapper.deleteById(processInstance.getId());
         taskInstanceMapper.deleteById(task.getId());
         taskInstanceMapper.deleteById(task.getId());

+ 2 - 1
sql/dolphinscheduler_postgre.sql

@@ -578,7 +578,8 @@ CREATE TABLE t_ds_task_instance (
   first_submit_time timestamp DEFAULT NULL ,
   first_submit_time timestamp DEFAULT NULL ,
   delay_time int DEFAULT '0' ,
   delay_time int DEFAULT '0' ,
   var_pool text ,
   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 - 0
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 - 0
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.
+*/