Unverified Commit 77384b2b authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization][admin] optimize task delete logical (#2917)

* optimize task delete logical * Spotless Apply --------- Co-authored-by: 's avatarZzm0809 <Zzm0809@users.noreply.github.com>
parent 4d116ec3
......@@ -25,7 +25,9 @@ import org.dinky.assertion.Asserts;
import org.dinky.config.Dialect;
import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.JobStatus;
import org.dinky.data.enums.Status;
import org.dinky.data.exception.BusException;
import org.dinky.data.model.Catalogue;
import org.dinky.data.model.Metrics;
import org.dinky.data.model.Task;
......@@ -185,8 +187,9 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* check catalogue task name is exist
*
* @param name name
* @param id id
* @param id id
* @return true if exist , otherwise false
*/
@Override
......@@ -199,6 +202,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* init some value
*
* @param catalogueTask {@link CatalogueTaskDTO}
* @return {@link Task}
*/
......@@ -457,6 +461,22 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
// doing: cascade delete jobInstance && jobHistory && history && statement
// 获取 task 表中的作业
Task task = taskService.getById(catalogue.getTaskId());
if (task != null) {
if (task.getStep().equals(JobLifeCycle.PUBLISH.getValue())) {
throw new BusException(Status.TASK_IS_PUBLISH_CANNOT_DELETE);
}
if (task.getJobInstanceId() != null) {
// 获取前 先强制刷新一下, 避免获取任务信息状态不准确
jobInstanceService.refreshJobInfoDetail(task.getJobInstanceId(), true);
// 获取当前 job instance
JobInstance currentJobInstance = jobInstanceService.getById(task.getJobInstanceId());
if (currentJobInstance != null
&& currentJobInstance.getStatus().equals(JobStatus.RUNNING.getValue())) {
throw new BusException(Status.TASK_IS_RUNNING_CANNOT_DELETE);
}
}
}
// 获取 metrics 表中的监控数据
List<Metrics> metricListByTaskId = monitorService.getMetricsLayoutByTaskId(catalogue.getTaskId());
......
......@@ -186,6 +186,8 @@ public enum Status {
TASK_UPDATE_FAILED(12008, "task.update.failed"),
TASK_IS_ONLINE(12009, "task.is.online"),
TASK_IS_EXIST(12010, "task.is.existed"),
TASK_IS_PUBLISH_CANNOT_DELETE(12011, "task.is.publish.cannot.delete"),
TASK_IS_RUNNING_CANNOT_DELETE(12012, "task.is.running.cannot.delete"),
/**
* alert instance
......
......@@ -104,6 +104,8 @@ added.failed=Added Failed
task.not.exist=Task Not Exist
task.is.online= Task is online, modification is prohibited
task.is.existed=Task is existed
task.is.publish.cannot.delete=Task is published, cannot delete
task.is.running.cannot.delete=Task is running, cannot delete, please stop the task first
cluster.instance.deploy=Deploy Success
clear.failed=Clear Failed
rename.success=Rename Successfully
......
......@@ -104,6 +104,8 @@ added.failed=新增失败
task.not.exist=任务不存在
task.is.online=任务已上线,禁止修改
task.is.existed=作业已存在
task.is.publish.cannot.delete=作业已发布,无法删除,请先下线
task.is.running.cannot.delete=作业正在运行,无法删除,请先停止
cluster.instance.deploy=部署完成
clear.failed=清除失败
rename.success=重命名成功
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment