Search in sources :

Example 6 with TitusChangeAction

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);
    });
}
Also used : Trigger(com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger) DateTimeExt(com.netflix.titus.common.util.DateTimeExt) JobManagerConstants(com.netflix.titus.api.jobmanager.service.JobManagerConstants) ImmutableMap(com.google.common.collect.ImmutableMap) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Task(com.netflix.titus.api.jobmanager.model.job.Task) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) Pair(com.netflix.titus.common.util.tuple.Pair) Map(java.util.Map) JobManagerConfiguration(com.netflix.titus.master.jobmanager.service.JobManagerConfiguration) Preconditions(com.google.common.base.Preconditions) Clock(com.netflix.titus.common.util.time.Clock) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder)

Example 7 with TitusChangeAction

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);
}
Also used : Trigger(com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) Test(org.junit.Test) UUID(java.util.UUID) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) JobStatus(com.netflix.titus.api.jobmanager.model.job.JobStatus) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) JobModelUpdateReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) Optional(java.util.Optional) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobModelUpdateReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Job(com.netflix.titus.api.jobmanager.model.job.Job) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder) Test(org.junit.Test)

Example 8 with TitusChangeAction

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);
}
Also used : ModelAction(com.netflix.titus.common.framework.reconciler.ModelAction) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Test(org.junit.Test)

Example 9 with TitusChangeAction

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();
}
Also used : ReconciliationEngine(com.netflix.titus.common.framework.reconciler.ReconciliationEngine) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) Pair(com.netflix.titus.common.util.tuple.Pair)

Example 10 with TitusChangeAction

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() + ')');
}
Also used : TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)

Aggregations

TitusChangeAction (com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)11 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)6 JobManagerReconcilerEvent (com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent)5 ReconciliationEngine (com.netflix.titus.common.framework.reconciler.ReconciliationEngine)4 Job (com.netflix.titus.api.jobmanager.model.job.Job)3 Task (com.netflix.titus.api.jobmanager.model.job.Task)3 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)3 Trigger (com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger)3 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)3 ModelActionHolder (com.netflix.titus.common.framework.reconciler.ModelActionHolder)3 JobManagerConfiguration (com.netflix.titus.master.jobmanager.service.JobManagerConfiguration)3 TitusModelAction (com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)2 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)2 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)2 JobModel (com.netflix.titus.api.jobmanager.model.job.JobModel)2