Search in sources :

Example 21 with TaskState

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());
}
Also used : TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState)

Example 22 with TaskState

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;
}
Also used : JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) BiFunction(java.util.function.BiFunction) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RECONCILER_ACTIVE_TIMEOUT_MS(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder.RECONCILER_ACTIVE_TIMEOUT_MS) Map(java.util.Map) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) StoreEvent(com.netflix.titus.master.jobmanager.service.integration.scenario.StubbedJobStore.StoreEvent) JobManagerUtil(com.netflix.titus.master.jobmanager.service.JobManagerUtil) Caller(com.netflix.titus.api.model.callmetadata.Caller) Job(com.netflix.titus.api.jobmanager.model.job.Job) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) List(java.util.List) VersionSupplier(com.netflix.titus.master.jobmanager.service.VersionSupplier) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) VersionSuppliers(com.netflix.titus.master.jobmanager.service.VersionSuppliers) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) Optional(java.util.Optional) Trigger(com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) ServiceJobProcesses(com.netflix.titus.api.jobmanager.model.job.ServiceJobProcesses) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) TestScheduler(rx.schedulers.TestScheduler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Pair(com.netflix.titus.common.util.tuple.Pair) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) Iterator(java.util.Iterator) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Subscriber(rx.Subscriber) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) CallerType(com.netflix.titus.api.model.callmetadata.CallerType) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) CapacityAttributes(com.netflix.titus.api.jobmanager.model.job.CapacityAttributes) Preconditions(com.google.common.base.Preconditions) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Optional(java.util.Optional) HashMap(java.util.HashMap) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus)

Aggregations

TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)22 Task (com.netflix.titus.api.jobmanager.model.job.Task)12 ArrayList (java.util.ArrayList)9 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)7 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)7 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)7 Job (com.netflix.titus.api.jobmanager.model.job.Job)6 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)6 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)6 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Optional (java.util.Optional)6 Stopwatch (com.google.common.base.Stopwatch)5 JobManagerConstants (com.netflix.titus.api.jobmanager.service.JobManagerConstants)5 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)4 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)4 ChangeAction (com.netflix.titus.common.framework.reconciler.ChangeAction)4 Pair (com.netflix.titus.common.util.tuple.Pair)4 VersionSupplier (com.netflix.titus.master.jobmanager.service.VersionSupplier)4