use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class PodToTaskMapper method handlePodFinished.
/**
* Handle pod 'Succeeded' or 'Failed'. Possible scenarios:
* <ul>
* <li>pod terminated while sitting in a queue</li>
* <li>pod failure during container setup process (bad image, stuck in state, etc)</li>
* <li>pod terminated during container setup</li>
* <li>container ran to completion</li>
* <li>container terminated by a user</li>
* </ul>
*/
private Either<TaskStatus, String> handlePodFinished() {
TaskState taskState = task.getStatus().getState();
String reasonCode;
if (podWrapper.getPodPhase() == PodPhase.SUCCEEDED) {
reasonCode = resolveFinalTaskState(REASON_NORMAL);
} else {
// PodPhase.FAILED
reasonCode = resolveFinalTaskState(REASON_FAILED);
}
return Either.ofValue(TaskStatus.newBuilder().withState(Finished).withReasonCode(effectiveFinalReasonCode(reasonCode)).withReasonMessage(podWrapper.getMessage()).withTimestamp(titusRuntime.getClock().wallTime()).build());
}
use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class JobScenarioBuilder method triggerComputePlatformEvent.
private JobScenarioBuilder triggerComputePlatformEvent(Task task, TaskState taskState, String reason, int errorCode) {
String reasonMessage;
if (taskState == TaskState.Finished) {
reasonMessage = errorCode == 0 ? "Completed successfully" : "Container terminated with an error " + errorCode;
} else {
reasonMessage = "Task changed state to " + taskState;
}
AtomicBoolean done = new AtomicBoolean();
final Map<String, String> newTaskContext = new HashMap<>();
if (taskState == TaskState.Launched) {
newTaskContext.putAll(computeProvider.getScheduledTaskContext(task.getId()));
}
TaskStatus taskStatus = JobModel.newTaskStatus().withState(taskState).withReasonCode(reason).withReasonMessage(reasonMessage).withTimestamp(testScheduler.now()).build();
Function<Task, Optional<Task>> changeFunction = currentTask -> JobManagerUtil.newMesosTaskStateUpdater(taskStatus, titusRuntime).apply(currentTask).map(updated -> updated.toBuilder().withTaskContext(CollectionsExt.merge(updated.getTaskContext(), newTaskContext)).build());
jobOperations.updateTask(task.getId(), changeFunction, Trigger.ComputeProvider, String.format("ComputeProvider callback taskStatus=%s, reason=%s (%s)", taskState, reason, reasonMessage), callMetadata).subscribe(() -> done.set(true));
autoAdvanceUntil(done::get);
assertThat(done.get()).isTrue();
return this;
}
Aggregations