use of com.netflix.titus.common.framework.reconciler.EntityHolder in project titus-control-plane by Netflix.
the class CreateOrReplaceBatchTaskActions method createNewTaskModelAction.
private static List<ModelActionHolder> createNewTaskModelAction(TitusChangeAction.Builder changeActionBuilder, BatchJobTask newTask, Optional<BatchJobTask> replacementOf, Retryer nextTaskRetryer) {
List<ModelActionHolder> actions = new ArrayList<>();
TitusModelAction.Builder modelBuilder = TitusModelAction.newModelUpdate(changeActionBuilder).summary("Creating new task entity holder");
EntityHolder taskHolder = EntityHolder.newRoot(newTask.getId(), newTask).addTag(TaskRetryers.ATTR_TASK_RETRY, nextTaskRetryer);
if (replacementOf.isPresent()) {
taskHolder = taskHolder.addTag(JobEntityHolders.ATTR_REPLACEMENT_OF, replacementOf.get());
}
actions.add(ModelActionHolder.reference(modelBuilder.addTaskHolder(taskHolder)));
actions.add(ModelActionHolder.store(modelBuilder.taskUpdate(newTask)));
return actions;
}
use of com.netflix.titus.common.framework.reconciler.EntityHolder in project titus-control-plane by Netflix.
the class DifferenceResolverUtils method countActiveNotStartedTasks.
public static int countActiveNotStartedTasks(EntityHolder refJobHolder, EntityHolder runningJobHolder) {
Set<String> pendingTaskIds = new HashSet<>();
Consumer<EntityHolder> countingFun = jobHolder -> jobHolder.getChildren().forEach(taskHolder -> {
TaskState state = ((Task) taskHolder.getEntity()).getStatus().getState();
if (state != TaskState.Started && state != TaskState.Finished) {
pendingTaskIds.add(taskHolder.getId());
}
});
countingFun.accept(refJobHolder);
countingFun.accept(runningJobHolder);
return pendingTaskIds.size();
}
use of com.netflix.titus.common.framework.reconciler.EntityHolder in project titus-control-plane by Netflix.
the class ServiceDifferenceResolver method applyRuntime.
private List<ChangeAction> applyRuntime(ReconciliationEngine<JobManagerReconcilerEvent> engine, ServiceJobView refJobView, EntityHolder runningModel, EntityHolder storeModel, AtomicInteger allowedNewTasks, AtomicInteger allowedTaskKills) {
EntityHolder referenceModel = refJobView.getJobHolder();
ServiceJobView runningJobView = new ServiceJobView(runningModel);
if (hasJobState(referenceModel, JobState.KillInitiated)) {
List<ChangeAction> killInitiatedActions = KillInitiatedActions.reconcilerInitiatedAllTasksKillInitiated(engine, runtime, jobStore, TaskStatus.REASON_TASK_KILLED, "Killing task as its job is in KillInitiated state", allowedTaskKills.get(), versionSupplier, titusRuntime);
if (killInitiatedActions.isEmpty()) {
return findTaskStateTimeouts(engine, runningJobView, configuration, runtime, jobStore, versionSupplier, stuckInStateRateLimiter, titusRuntime);
}
allowedTaskKills.set(allowedTaskKills.get() - killInitiatedActions.size());
return killInitiatedActions;
} else if (hasJobState(referenceModel, JobState.Finished)) {
return Collections.emptyList();
}
List<ChangeAction> actions = new ArrayList<>();
List<ChangeAction> numberOfTaskAdjustingActions = findJobSizeInconsistencies(engine, refJobView, storeModel, allowedNewTasks, allowedTaskKills);
actions.addAll(numberOfTaskAdjustingActions);
if (numberOfTaskAdjustingActions.isEmpty()) {
actions.addAll(findMissingRunningTasks(engine, refJobView, runningJobView));
}
actions.addAll(findTaskStateTimeouts(engine, runningJobView, configuration, runtime, jobStore, versionSupplier, stuckInStateRateLimiter, titusRuntime));
return actions;
}
use of com.netflix.titus.common.framework.reconciler.EntityHolder in project titus-control-plane by Netflix.
the class TaskTimeoutChangeActions method setTimeout.
public static TitusChangeAction setTimeout(String taskId, TaskState taskState, long timeoutMs, Clock clock) {
String tagName = STATE_TAGS.get(taskState);
Preconditions.checkArgument(tagName != null, "Timeout not tracked for state %s", taskState);
return TitusChangeAction.newAction("setTimeout").id(taskId).trigger(Trigger.Reconciler).summary("Setting timeout for task in state %s: %s", taskState, DateTimeExt.toTimeUnitString(timeoutMs)).callMetadata(JobManagerConstants.RECONCILER_CALLMETADATA.toBuilder().withCallReason("configure timeout").build()).applyModelUpdate(self -> {
TitusModelAction modelAction = TitusModelAction.newModelUpdate(self).taskMaybeUpdate(jobHolder -> jobHolder.findById(taskId).map(taskHolder -> {
EntityHolder newTaskHolder = taskHolder.addTag(tagName, clock.wallTime() + timeoutMs);
if (taskState == TaskState.KillInitiated) {
newTaskHolder = newTaskHolder.addTag(KILL_INITIATED_ATTEMPT_TAG, 0);
}
return Pair.of(jobHolder.addChild(newTaskHolder), newTaskHolder);
}));
return ModelActionHolder.running(modelAction);
});
}
use of com.netflix.titus.common.framework.reconciler.EntityHolder in project titus-control-plane by Netflix.
the class RetryActionInterceptorTest method expectAboveExecutionLimits.
private EntityHolder expectAboveExecutionLimits(ModelAction updateAction, EntityHolder model) {
Optional<Pair<EntityHolder, EntityHolder>> pair = updateAction.apply(model);
assertThat(pair).isPresent();
EntityHolder modelWithTag = pair.get().getRight();
assertThat(retryInterceptor.executionLimits(modelWithTag)).isFalse();
return modelWithTag;
}
Aggregations