Search in sources :

Example 1 with Trigger

use of com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger 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 2 with Trigger

use of com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger 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 3 with Trigger

use of com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger in project titus-control-plane by Netflix.

the class BasicTaskActions method writeReferenceTaskToStore.

/**
 * Write updated task record to a store. If a task is completed, remove it from the scheduling service.
 * This command calls {@link JobStore#updateTask(Task)}, which assumes that the task record was created already.
 */
public static TitusChangeAction writeReferenceTaskToStore(JobStore titusStore, ReconciliationEngine<JobManagerReconcilerEvent> engine, String taskId, CallMetadata callMetadata, TitusRuntime titusRuntime) {
    return TitusChangeAction.newAction("writeReferenceTaskToStore").trigger(V3JobOperations.Trigger.Reconciler).id(taskId).summary("Persisting task to the store").callMetadata(callMetadata).changeWithModelUpdate(self -> {
        Optional<EntityHolder> taskHolder = engine.getReferenceView().findById(taskId);
        if (!taskHolder.isPresent()) {
            // Should never happen
            titusRuntime.getCodeInvariants().inconsistent("Reference task with id %s not found.", taskId);
            return Observable.empty();
        }
        Task referenceTask = taskHolder.get().getEntity();
        return titusStore.updateTask(referenceTask).andThen(Observable.fromCallable(() -> {
            TitusModelAction modelUpdateAction = TitusModelAction.newModelUpdate(self).taskUpdate(storeRoot -> {
                EntityHolder storedHolder = EntityHolder.newRoot(referenceTask.getId(), referenceTask);
                return Pair.of(storeRoot.addChild(storedHolder), storedHolder);
            });
            return ModelActionHolder.store(modelUpdateAction);
        }));
    });
}
Also used : Trigger(com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger) DateTimeExt(com.netflix.titus.common.util.DateTimeExt) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) JobServiceRuntime(com.netflix.titus.master.jobmanager.service.JobServiceRuntime) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Observable(rx.Observable) Pair(com.netflix.titus.common.util.tuple.Pair) JobManagerConfiguration(com.netflix.titus.master.jobmanager.service.JobManagerConfiguration) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) JobEntityHolders(com.netflix.titus.master.jobmanager.service.common.action.JobEntityHolders) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) TaskRetryers(com.netflix.titus.master.jobmanager.service.common.action.TaskRetryers) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) 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) List(java.util.List) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) VersionSupplier(com.netflix.titus.master.jobmanager.service.VersionSupplier) ReconciliationEngine(com.netflix.titus.common.framework.reconciler.ReconciliationEngine) VersionSuppliers(com.netflix.titus.master.jobmanager.service.VersionSuppliers) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) Optional(java.util.Optional) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) Task(com.netflix.titus.api.jobmanager.model.job.Task) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder)

Aggregations

Trigger (com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger)3 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)3 ModelActionHolder (com.netflix.titus.common.framework.reconciler.ModelActionHolder)3 TitusChangeAction (com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)3 TitusModelAction (com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction)3 Job (com.netflix.titus.api.jobmanager.model.job.Job)2 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)2 JobModel (com.netflix.titus.api.jobmanager.model.job.JobModel)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)2 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)2 DateTimeExt (com.netflix.titus.common.util.DateTimeExt)2 Pair (com.netflix.titus.common.util.tuple.Pair)2 JobManagerConfiguration (com.netflix.titus.master.jobmanager.service.JobManagerConfiguration)2 JobManagerReconcilerEvent (com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent)2 Optional (java.util.Optional)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)1 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)1