diff --git a/src/main/java/cws/k8s/scheduler/model/State.java b/src/main/java/cws/k8s/scheduler/model/State.java index 4c7430e..f22f395 100644 --- a/src/main/java/cws/k8s/scheduler/model/State.java +++ b/src/main/java/cws/k8s/scheduler/model/State.java @@ -2,6 +2,13 @@ public enum State { - RECEIVED_CONFIG, UNSCHEDULED, SCHEDULED, PREPARED, ERROR, PROCESSING_FINISHED, FINISHED, FINISHED_WITH_ERROR, INIT_WITH_ERRORS, DELETED + RECEIVED_CONFIG(0), UNSCHEDULED(1), SCHEDULED(2), PREPARED(3), INIT_WITH_ERRORS(3), PROCESSING_FINISHED(4), + FINISHED(5), FINISHED_WITH_ERROR(5), ERROR(1000), DELETED(Integer.MAX_VALUE); + + public final int level; + + State(int level) { + this.level = level; + } } diff --git a/src/main/java/cws/k8s/scheduler/scheduler/Scheduler.java b/src/main/java/cws/k8s/scheduler/scheduler/Scheduler.java index 707d359..f792d92 100644 --- a/src/main/java/cws/k8s/scheduler/scheduler/Scheduler.java +++ b/src/main/java/cws/k8s/scheduler/scheduler/Scheduler.java @@ -398,14 +398,16 @@ public void endBatch( int tasksInBatch ){ /** * @return returns the task, if the state was changed */ - Task changeStateOfTask(Pod pod, State state){ - Task t = getTaskByPod( pod ); - if( t != null ){ - synchronized ( t.getState() ){ - if( t.getState().getState() != state ){ - t.getState().setState( state ); + Task changeStateOfTask(Pod pod, State state) { + Task t = getTaskByPod(pod); + if (t != null) { + synchronized (t.getState()) { + if (t.getState().getState().level < state.level) { + t.getState().setState(state); return t; } else { + log.debug("Task {} was already in state {} and cannot be changed to {}", t.getConfig().getRunName(), + t.getState().getState(), state); return null; } }