use of com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction 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.master.jobmanager.service.common.action.TitusChangeAction in project titus-control-plane by Netflix.
the class JobTransactionLoggerTest method testLogFormatting.
/**
* Sole purpose of this test is visual inspection of the generated log line.
*/
@Test
public void testLogFormatting() throws Exception {
Job previousJob = createJob();
Job currentJob = previousJob.toBuilder().withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build();
ModelActionHolder modelActionHolder = ModelActionHolder.reference(TitusModelAction.newModelUpdate("testModelAction").job(previousJob).trigger(Trigger.API).summary("Job model update").jobUpdate(jobHolder -> jobHolder.setEntity(currentJob)));
TitusChangeAction changeAction = TitusChangeAction.newAction("testChangeAction").job(previousJob).trigger(Trigger.API).summary("Job update").callMetadata(CallMetadata.newBuilder().withCallerId("LoggerTest").withCallReason("Testing logger transaction").build()).applyModelUpdate(self -> modelActionHolder);
JobManagerReconcilerEvent jobReconcilerEvent = new JobModelUpdateReconcilerEvent(previousJob, changeAction, modelActionHolder, EntityHolder.newRoot(currentJob.getId(), currentJob), Optional.of(EntityHolder.newRoot(previousJob.getId(), previousJob)), "1");
String logLine = JobTransactionLogger.doFormat(jobReconcilerEvent);
assertThat(logLine).isNotEmpty();
logger.info("Job event: {}", logLine);
}
use of com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction in project titus-control-plane by Netflix.
the class RetryActionInterceptorTest method testRetry.
@Test
public void testRetry() throws Exception {
TitusChangeAction changeAction = SampleTitusChangeActions.failingJob(2);
// First two calls should fail
ModelAction updateAction1 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RetryModelUpdateAction.class);
EntityHolder modelWithTag1 = expectAboveExecutionLimits(updateAction1, EntityHolder.newRoot("rootId", "data"));
expectBelowExecutionLimitsWhenTimeAdvanced(modelWithTag1, INITIAL_DELAY_MS);
ModelAction updateAction2 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RetryModelUpdateAction.class);
EntityHolder modelWithTag2 = expectAboveExecutionLimits(updateAction2, modelWithTag1);
expectBelowExecutionLimitsWhenTimeAdvanced(modelWithTag2, INITIAL_DELAY_MS * 2);
// Third call should succeed
ModelAction updateAction3 = expectUpdateActionOfType(changeAction, RetryActionInterceptor.RemoveRetryRecord.class);
expectNoRetryTag(updateAction3, modelWithTag2);
}
use of com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction in project titus-control-plane by Netflix.
the class DefaultV3JobOperations method updateTask.
@Override
public Completable updateTask(String taskId, Function<Task, Optional<Task>> changeFunction, Trigger trigger, String reason, CallMetadata callMetadata) {
Optional<ReconciliationEngine<JobManagerReconcilerEvent>> engineOpt = reconciliationFramework.findEngineByChildId(taskId).map(Pair::getLeft);
if (!engineOpt.isPresent()) {
return Completable.error(JobManagerException.taskNotFound(taskId));
}
ReconciliationEngine<JobManagerReconcilerEvent> engine = engineOpt.get();
TitusChangeAction changeAction = BasicTaskActions.updateTaskInRunningModel(taskId, trigger, jobManagerConfiguration, engine, changeFunction, reason, versionSupplier, titusRuntime, callMetadata);
return engine.changeReferenceModel(changeAction, taskId).toCompletable();
}
use of com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction in project titus-control-plane by Netflix.
the class JobTransactionLogger method logJobChangeErrorReconcilerEvent.
private static String logJobChangeErrorReconcilerEvent(JobChangeReconcilerEvent.JobChangeErrorReconcilerEvent event) {
TitusChangeAction changeAction = event.getChangeAction();
String jobId = event.getJob().getId();
String entityId = changeAction.getId();
return doFormat(jobId, event.getTransactionId(), "error", "afterChange", event.getChangeAction().getName(), changeAction.getTrigger(), toTargetName(jobId, entityId), entityId, event.getWaitTimeMs(), event.getExecutionTimeMs(), event.getCallMetadata().getCallerId(), event.getCallMetadata().getCallReason(), event.getError().getMessage() + '(' + changeAction.getSummary() + ')');
}
Aggregations