use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class TaskScenarioBuilder method transitionUntil.
public TaskScenarioBuilder transitionUntil(TaskStatus.TaskState taskState) {
logger.info("[{}] Transition task on agent to state {}", discoverActiveTest(), taskState);
String taskId = getTask().getId();
TaskState coreTaskState = EmbeddedKubeUtil.getPodState(kubeCluster.getPods().get(taskId));
TaskStatus.TaskState currentState = toGrpcTaskState(coreTaskState);
int startingPoint = currentState.ordinal();
int targetPoint = taskState.ordinal();
for (int next = startingPoint + 1; next <= targetPoint; next++) {
TaskStatus.TaskState nextState = TaskStatus.TaskState.forNumber(next);
if (nextState != TaskStatus.TaskState.KillInitiated) {
if (nextState == TaskStatus.TaskState.StartInitiated) {
kubeCluster.moveToStartInitiatedState(taskId);
} else if (nextState == TaskStatus.TaskState.Started) {
kubeCluster.moveToStartedState(taskId);
} else if (nextState == TaskStatus.TaskState.Finished) {
kubeCluster.moveToFinishedSuccess(taskId);
}
}
}
return this;
}
use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class TaskScenarioBuilder method expectStateUpdates.
public TaskScenarioBuilder expectStateUpdates(TaskStatus.TaskState... expectedStates) {
logger.info("[{}] Expecting sequence of events with task states {}...", discoverActiveTest(), asList(expectedStates));
Stopwatch stopWatch = Stopwatch.createStarted();
for (TaskStatus.TaskState expectedState : expectedStates) {
TaskState expectedCoreState = toCoreTaskState(expectedState);
expectTaskUpdate(task -> task.getStatus().getState() == expectedCoreState, "Expected state " + expectedCoreState);
}
logger.info("[{}] Expected sequence of events with task states {} received in {}[ms]", discoverActiveTest(), asList(expectedStates), stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class KubeNotificationProcessorTest method testUpdateTaskStatusVK.
@Test
public void testUpdateTaskStatusVK() {
V1Pod pod = newPod(TASK.getId(), andRunning());
V1Node node = newNode(andIpAddress("2.2.2.2"), andNodeAnnotations(TITUS_NODE_DOMAIN + "ami", "ami123", TITUS_NODE_DOMAIN + "stack", "myStack"));
Map<String, String> UpdatedAnnotations = new HashMap<>();
UpdatedAnnotations.put(LEGACY_ANNOTATION_IP_ADDRESS, "1.2.3.4");
pod.getMetadata().setAnnotations(UpdatedAnnotations);
Task updatedTask = processor.updateTaskStatus(new PodWrapper(pod), TaskStatus.newBuilder().withState(TaskState.Started).build(), Optional.of(node), TASK, false).orElse(null);
Set<TaskState> pastStates = updatedTask.getStatusHistory().stream().map(ExecutableStatus::getState).collect(Collectors.toSet());
assertThat(pastStates).contains(TaskState.Accepted, TaskState.Launched, TaskState.StartInitiated);
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_HOST, "2.2.2.2");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_AMI, "ami123");
assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_STACK, "myStack");
}
use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class KillInitiatedActions method reconcilerInitiatedAllTasksKillInitiated.
/**
* For all active tasks, send terminate command to the compute provider, and change their state to {@link TaskState#KillInitiated}.
* This method is used for internal state reconciliation.
*/
public static List<ChangeAction> reconcilerInitiatedAllTasksKillInitiated(ReconciliationEngine<JobManagerReconcilerEvent> engine, JobServiceRuntime runtime, JobStore jobStore, String reasonCode, String reason, int concurrencyLimit, VersionSupplier versionSupplier, TitusRuntime titusRuntime) {
List<ChangeAction> result = new ArrayList<>();
EntityHolder runningView = engine.getRunningView();
Set<String> runningTaskIds = new HashSet<>();
runningView.getChildren().forEach(taskHolder -> runningTaskIds.add(taskHolder.<Task>getEntity().getId()));
// Immediately finish Accepted tasks, which are not yet in the running model.
for (EntityHolder entityHolder : engine.getReferenceView().getChildren()) {
if (result.size() >= concurrencyLimit) {
return result;
}
Task task = entityHolder.getEntity();
TaskState state = task.getStatus().getState();
if (state == TaskState.Accepted && !runningTaskIds.contains(task.getId())) {
result.add(BasicTaskActions.updateTaskAndWriteItToStore(task.getId(), engine, taskRef -> JobFunctions.changeTaskStatus(taskRef, TaskState.Finished, reasonCode, reason, titusRuntime.getClock()), jobStore, V3JobOperations.Trigger.Reconciler, reason, versionSupplier, titusRuntime, JobManagerConstants.RECONCILER_CALLMETADATA.toBuilder().withCallReason(reason).build()));
}
}
// Move running tasks to KillInitiated state
for (EntityHolder taskHolder : runningView.getChildren()) {
if (result.size() >= concurrencyLimit) {
return result;
}
Task task = taskHolder.getEntity();
TaskState state = task.getStatus().getState();
if (state != TaskState.KillInitiated && state != TaskState.Finished) {
result.add(reconcilerInitiatedTaskKillInitiated(engine, task, runtime, jobStore, versionSupplier, reasonCode, reason, titusRuntime));
}
}
return result;
}
use of com.netflix.titus.api.jobmanager.model.job.TaskState in project titus-control-plane by Netflix.
the class KillInitiatedActions method userInitiateTaskKillAction.
/**
* Change a task to {@link TaskState#KillInitiated} state, store it, and send the kill command to the compute provider.
* All models are updated when both operations complete.
* This method is used for user initiated kill operations, so the store operation happens before response is sent back to the user.
*/
public static ChangeAction userInitiateTaskKillAction(ReconciliationEngine<JobManagerReconcilerEvent> engine, JobServiceRuntime executionContext, JobStore jobStore, VersionSupplier versionSupplier, String taskId, boolean shrink, boolean preventMinSizeUpdate, String reasonCode, String reason, TitusRuntime titusRuntime, CallMetadata callMetadata) {
return TitusChangeAction.newAction("userInitiateTaskKill").id(taskId).trigger(V3JobOperations.Trigger.API).summary(reason).callMetadata(callMetadata).changeWithModelUpdates(self -> JobEntityHolders.toTaskObservable(engine, taskId, titusRuntime).flatMap(task -> {
TaskState taskState = task.getStatus().getState();
if (taskState == TaskState.KillInitiated || taskState == TaskState.Finished) {
return Observable.just(Collections.<ModelActionHolder>emptyList());
}
if (shrink) {
Job<ServiceJobExt> job = engine.getReferenceView().getEntity();
Capacity capacity = job.getJobDescriptor().getExtensions().getCapacity();
if (preventMinSizeUpdate && capacity.getDesired() <= capacity.getMin()) {
return Observable.<List<ModelActionHolder>>error(JobManagerException.terminateAndShrinkNotAllowed(job, task));
}
}
Task taskWithKillInitiated = VersionSuppliers.nextVersion(JobFunctions.changeTaskStatus(task, TaskState.KillInitiated, reasonCode, reason, titusRuntime.getClock()), versionSupplier);
Callable<List<ModelActionHolder>> modelUpdateActions = () -> JobEntityHolders.expectTask(engine, task.getId(), titusRuntime).map(current -> {
List<ModelActionHolder> updateActions = new ArrayList<>();
TitusModelAction stateUpdateAction = TitusModelAction.newModelUpdate(self).taskUpdate(taskWithKillInitiated);
updateActions.addAll(ModelActionHolder.allModels(stateUpdateAction));
if (shrink) {
TitusModelAction shrinkAction = createShrinkAction(self, versionSupplier);
updateActions.add(ModelActionHolder.reference(shrinkAction));
}
return updateActions;
}).orElse(Collections.emptyList());
return jobStore.updateTask(taskWithKillInitiated).andThen(createKillAction(executionContext, task)).andThen(Observable.fromCallable(modelUpdateActions));
}));
}
Aggregations