Browse Source

[1.3.6-prepare][PGSQL] Delete the stopped workflow without deleting the correspon… (#5153)

pr    #5066
issue #5048
Kirs 4 years ago committed by GitHub
parent
commit
64701e0533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 102
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
  2. 3
      sql/dolphinscheduler_postgre.sql
  3. 5
      sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql

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

@ -14,12 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.dao.mapper;
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;
import org.apache.dolphinscheduler.common.enums.TaskType;
@ -27,7 +24,12 @@ import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
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;
@ -36,13 +38,10 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
@Rollback
public class TaskInstanceMapperTest {
@ -55,20 +54,44 @@ public class TaskInstanceMapperTest {
@Autowired
ProcessInstanceMapper processInstanceMapper;
@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
*
* @return TaskInstance
*/
private TaskInstance insertOne(){
private TaskInstance insertOne() {
//insertOne
return insertOne("us task", processInstanceId, ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString(),1);
}
/**
* construct a task instance and then insert
*/
private TaskInstance insertOne(String taskName, int processInstanceId, ExecutionStatus state, String taskType,int processDefinitionId) {
TaskInstance taskInstance = new TaskInstance();
taskInstance.setFlag(Flag.YES);
taskInstance.setName("ut task");
taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
taskInstance.setName(taskName);
taskInstance.setState(state);
taskInstance.setStartTime(new Date());
taskInstance.setEndTime(new Date());
taskInstance.setTaskJson("{}");
taskInstance.setTaskType(TaskType.SHELL.toString());
taskInstance.setProcessInstanceId(processInstanceId);
taskInstance.setTaskType(taskType);
taskInstance.setProcessDefinitionId(processDefinitionId);
taskInstanceMapper.insert(taskInstance);
return taskInstance;
}
@ -77,7 +100,7 @@ public class TaskInstanceMapperTest {
* test update
*/
@Test
public void testUpdate(){
public void testUpdate() {
//insertOne
TaskInstance taskInstance = insertOne();
//update
@ -90,7 +113,7 @@ public class TaskInstanceMapperTest {
* test delete
*/
@Test
public void testDelete(){
public void testDelete() {
TaskInstance taskInstance = insertOne();
int delete = taskInstanceMapper.deleteById(taskInstance.getId());
Assert.assertEquals(1, delete);
@ -114,7 +137,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(),
@ -131,8 +154,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);
@ -149,7 +172,7 @@ public class TaskInstanceMapperTest {
taskInstanceMapper.deleteById(task2.getId());
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(taskInstances.size(), 0);
Assert.assertNotEquals(taskInstances1.size(), 0 );
Assert.assertNotEquals(taskInstances1.size(), 0);
}
/**
@ -254,47 +277,4 @@ public class TaskInstanceMapperTest {
processDefinitionMapper.deleteById(definition.getId());
taskInstanceMapper.deleteById(task.getId());
}
/**
* test page
*/
@Test
public void testQueryTaskInstanceListPaging() {
TaskInstance task = insertOne();
ProcessDefinition definition = new ProcessDefinition();
definition.setProjectId(1111);
processDefinitionMapper.insert(definition);
ProcessInstance processInstance = new ProcessInstance();
processInstance.setProcessDefinitionId(definition.getId());
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
processInstance.setName("ut process");
processInstance.setStartTime(new Date());
processInstance.setEndTime(new Date());
processInstance.setCommandType(CommandType.START_PROCESS);
processInstanceMapper.insert(processInstance);
task.setProcessDefinitionId(definition.getId());
task.setProcessInstanceId(processInstance.getId());
taskInstanceMapper.updateById(task);
Page<TaskInstance> page = new Page(1,3);
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page,
definition.getProjectId(),
task.getProcessInstanceId(),
"",
"",
0,
new int[0],
"",
null,null
);
processInstanceMapper.deleteById(processInstance.getId());
taskInstanceMapper.deleteById(task.getId());
processDefinitionMapper.deleteById(definition.getId());
Assert.assertNotEquals(taskInstanceIPage.getTotal(), 0);
}
}

3
sql/dolphinscheduler_postgre.sql

@ -569,7 +569,8 @@ CREATE TABLE t_ds_task_instance (
task_instance_priority int DEFAULT NULL ,
worker_group varchar(64),
executor_id int DEFAULT NULL ,
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
) ;
--

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

@ -35,3 +35,8 @@ d//
delimiter ;
SELECT uc_dolphin_T_t_ds_worker_group_A_ip_list();
DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_worker_group_A_ip_list();
delimiter ;
-- 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;

Loading…
Cancel
Save