1. 删除Command类,Doris数据库改用TaskCommandInfo类作为实体类
2. 取消FailedState和GeneratingState的使用 3. 修改部分bug
This commit is contained in:
@@ -23,12 +23,7 @@ public class StateChangeService {
|
||||
}
|
||||
|
||||
@DSTransactional
|
||||
public Boolean changeState(Integer stateNum, Long taskId) throws DorisStartException {
|
||||
if (Objects.equals(stateNum, StateEnum.GENERATING.getStateNum()) ||
|
||||
Objects.equals(stateNum, StateEnum.FAILED.getStateNum())) {
|
||||
throw new IllegalArgumentException("非法任务状态:" + StateEnum.getStateByNum(stateNum));
|
||||
}
|
||||
|
||||
public Boolean changeState(Integer stateNum, Long taskId, Boolean inner) throws DorisStartException {
|
||||
Integer originalStateNum = taskService.queryTaskStatus(taskId);
|
||||
if (originalStateNum == null) {
|
||||
throw new IllegalArgumentException("无法找到" + taskId + "的任务状态,也许任务ID不存在?");
|
||||
@@ -38,8 +33,15 @@ public class StateChangeService {
|
||||
|
||||
State newState = StateEnum.getStateByNum(stateNum);
|
||||
|
||||
if (newState == null) {
|
||||
return false;
|
||||
if (!inner && !checkState(originalState, newState)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("任务状态转换失败,原状态:%s,欲切换状态:%s",
|
||||
originalState.getClass().getSimpleName(),
|
||||
newState.getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
if (Objects.equals(originalState, newState)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!originalState.handle(newState, commandService, taskService, taskId)) {
|
||||
@@ -54,4 +56,21 @@ public class StateChangeService {
|
||||
// 这里一定是handle成功的状态,我们再进行task status的修改,如果handle失败,要么返回false,要么抛出异常,不会进入此处
|
||||
return taskService.changeTaskStatus(taskId, stateNum);
|
||||
}
|
||||
|
||||
private Boolean checkState(State originalState, State newState) {
|
||||
if (originalState == null || newState == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// FAILED、FINISHED状态以及GENERATING都只能在程序内部修改,外部接口不能修改
|
||||
if (Objects.equals(newState, StateEnum.FAILED.getState())
|
||||
|| Objects.equals(newState, StateEnum.FINISHED.getState())
|
||||
|| Objects.equals(newState, StateEnum.GENERATING.getState())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 在任务状态转换为GENERATING之后,我们需要在外部接口屏蔽掉所有状态
|
||||
// 我们需要保证只有任务创建函数才能将GENERATING状态转换为RUNNING状态
|
||||
return !Objects.equals(originalState, StateEnum.GENERATING.getState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ public class FailedState extends StateHandler implements State {
|
||||
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||
case RUNNING -> handleStart(taskService, commandService, taskId);
|
||||
case STOP -> handleStop(commandService, taskId);
|
||||
case FAILED -> true;
|
||||
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.realtime.protection.server.task.status.states;
|
||||
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import com.realtime.protection.configuration.utils.status.State;
|
||||
import com.realtime.protection.server.command.CommandService;
|
||||
@@ -9,9 +8,9 @@ import com.realtime.protection.server.task.status.StateHandler;
|
||||
|
||||
public class GeneratingState extends StateHandler implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||
case RUNNING, GENERATING -> true;
|
||||
case RUNNING -> true;
|
||||
case FAILED -> handleFailed(commandService, taskId);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||
};
|
||||
|
||||
@@ -11,8 +11,8 @@ public class PendingState extends StateHandler implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||
case GENERATING -> handleStart(taskService, commandService, taskId);
|
||||
case FAILED -> handleFailed(commandService, taskId);
|
||||
case RUNNING -> handleStart(taskService, commandService, taskId);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ public class RunningState extends StateHandler implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||
case RUNNING, GENERATING -> true;
|
||||
case PAUSED -> handlePause(commandService, taskId);
|
||||
case STOP -> handleStop(commandService, taskId);
|
||||
case FINISHED -> handleFinish(commandService, taskId);
|
||||
|
||||
Reference in New Issue
Block a user