Search in sources :

Example 1 with TitusModelAction

use of com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction in project titus-control-plane by Netflix.

the class JobTransactionLogger method logJobModelUpdateErrorReconcilerEvent.

private static String logJobModelUpdateErrorReconcilerEvent(JobModelReconcilerEvent.JobModelUpdateErrorReconcilerEvent event) {
    String jobId = event.getJob().getId();
    String entityId = event.getPreviousEntityHolder().getId();
    ModelActionHolder actionHolder = event.getModelActionHolder();
    TitusModelAction action = (TitusModelAction) actionHolder.getAction();
    return doFormat(jobId, event.getTransactionId(), "error", "modelUpdate/" + event.getModelActionHolder().getModel().name(), ((TitusModelAction) actionHolder.getAction()).getName(), event.getChangeAction().getTrigger(), toTargetName(jobId, entityId), entityId, 0, 0, event.getCallMetadata().getCallerId(), event.getCallMetadata().getCallReason(), action.getSummary());
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder)

Example 2 with TitusModelAction

use of com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction in project titus-control-plane by Netflix.

the class BasicServiceJobActions method updateJobEnableStatus.

/**
 * Change job 'enable' status.
 */
public static TitusChangeAction updateJobEnableStatus(ReconciliationEngine<JobManagerReconcilerEvent> engine, boolean enabled, JobStore jobStore, VersionSupplier versionSupplier, CallMetadata callMetadata) {
    return TitusChangeAction.newAction("updateJobCapacityAction").id(engine.getReferenceView().getId()).trigger(V3JobOperations.Trigger.API).summary("Changing job enable status to: %s", enabled).callMetadata(callMetadata).changeWithModelUpdates(self -> {
        Job<ServiceJobExt> serviceJob = engine.getReferenceView().getEntity();
        if (serviceJob.getStatus().getState() != JobState.Accepted) {
            return Observable.error(JobManagerException.jobTerminating(serviceJob));
        }
        Job<ServiceJobExt> updatedJob = VersionSuppliers.nextVersion(JobFunctions.changeJobEnabledStatus(serviceJob, enabled), versionSupplier);
        TitusModelAction modelAction = TitusModelAction.newModelUpdate(self).jobUpdate(jobHolder -> jobHolder.setEntity(updatedJob));
        return jobStore.updateJob(updatedJob).andThen(Observable.just(ModelActionHolder.referenceAndStore(modelAction)));
    });
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)

Example 3 with TitusModelAction

use of com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction in project titus-control-plane by Netflix.

the class BasicServiceJobActions method updateJobCapacityAction.

/**
 * Update job capacity.
 */
public static TitusChangeAction updateJobCapacityAction(ReconciliationEngine<JobManagerReconcilerEvent> engine, CapacityAttributes capacityAttributes, JobStore jobStore, VersionSupplier versionSupplier, CallMetadata callMetadata, EntitySanitizer entitySanitizer) {
    return TitusChangeAction.newAction("updateJobCapacityAction").id(engine.getReferenceView().getId()).trigger(V3JobOperations.Trigger.API).summary("Changing job capacity to: %s", capacityAttributes).callMetadata(callMetadata).changeWithModelUpdates(self -> {
        Job<ServiceJobExt> serviceJob = engine.getReferenceView().getEntity();
        if (serviceJob.getStatus().getState() != JobState.Accepted) {
            return Observable.error(JobManagerException.jobTerminating(serviceJob));
        }
        Capacity currentCapacity = serviceJob.getJobDescriptor().getExtensions().getCapacity();
        Capacity.Builder newCapacityBuilder = currentCapacity.toBuilder();
        capacityAttributes.getDesired().ifPresent(newCapacityBuilder::withDesired);
        capacityAttributes.getMax().ifPresent(newCapacityBuilder::withMax);
        capacityAttributes.getMin().ifPresent(newCapacityBuilder::withMin);
        if (capacityAttributes.getDesired().isPresent()) {
            newCapacityBuilder.withDesired(capacityAttributes.getDesired().get());
        } else {
            setDesiredBasedOnMinMax(newCapacityBuilder, currentCapacity, capacityAttributes);
        }
        Capacity newCapacity = newCapacityBuilder.build();
        if (currentCapacity.equals(newCapacity)) {
            return Observable.empty();
        }
        // model validation for capacity
        Set<ValidationError> violations = entitySanitizer.validate(newCapacity);
        if (!violations.isEmpty()) {
            return Observable.error(TitusServiceException.invalidArgument(String.format("Current %s", currentCapacity), violations));
        }
        // checking if service job processes allow changes to desired capacity
        if (isDesiredCapacityInvalid(newCapacity, serviceJob)) {
            return Observable.error(JobManagerException.invalidDesiredCapacity(serviceJob.getId(), newCapacity.getDesired(), serviceJob.getJobDescriptor().getExtensions().getServiceJobProcesses()));
        }
        // append callmetadata job attributes
        Job<ServiceJobExt> serviceJobExtCallMetadata = JobFunctions.appendCallMetadataJobAttributes(serviceJob, callMetadata);
        // ready to update job capacity
        Job<ServiceJobExt> updatedJob = VersionSuppliers.nextVersion(JobFunctions.changeServiceJobCapacity(serviceJobExtCallMetadata, newCapacity), versionSupplier);
        TitusModelAction modelAction = TitusModelAction.newModelUpdate(self).jobUpdate(jobHolder -> jobHolder.setEntity(updatedJob));
        return jobStore.updateJob(updatedJob).andThen(Observable.just(ModelActionHolder.referenceAndStore(modelAction)));
    });
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

Example 4 with TitusModelAction

use of com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction in project titus-control-plane by Netflix.

the class MoveTaskBetweenJobsAction method createModelUpdateActionsFrom.

private List<ModelActionHolder> createModelUpdateActionsFrom(Job<ServiceJobExt> updatedJobFrom, Job<ServiceJobExt> updatedJobTo, Task taskFrom, CallMetadata callMetadata) {
    List<ModelActionHolder> actions = new ArrayList<>();
    // Remove task from all models.
    TitusModelAction removeTaskAction = TitusModelAction.newModelUpdate("moveTask").job(updatedJobFrom).trigger(Trigger.API).summary("Task moved to another job: jobTo=" + updatedJobTo.getId()).callMetadata(callMetadata).removeTask(taskFrom);
    actions.addAll(ModelActionHolder.allModels(removeTaskAction));
    String summary = "Decremented the desired job size by one, as its task was moved to another job: jobTo=" + updatedJobTo.getId();
    // Change job size
    TitusModelAction modelAction = TitusModelAction.newModelUpdate("decrementJobSize").job(updatedJobFrom).trigger(Trigger.API).summary(summary).jobUpdate(jobHolder -> jobHolder.setEntity(updatedJobFrom));
    actions.addAll(ModelActionHolder.referenceAndStore(modelAction));
    return actions;
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ArrayList(java.util.ArrayList) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder)

Example 5 with TitusModelAction

use of com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction in project titus-control-plane by Netflix.

the class MoveTaskBetweenJobsAction method createModelUpdateActionsTo.

private List<ModelActionHolder> createModelUpdateActionsTo(Job<ServiceJobExt> updatedJobFrom, Job<?> updatedJobTo, Task taskToUpdated, Optional<EntityHolder> taskFromRunningHolder, CallMetadata callMetadata) {
    List<ModelActionHolder> actions = new ArrayList<>();
    String summary = "Received task from another job: jobFrom=" + updatedJobFrom.getId();
    // Add task
    TitusModelAction addTaskAction = TitusModelAction.newModelUpdate("moveTask").job(updatedJobTo).trigger(Trigger.API).summary(summary).callMetadata(callMetadata).taskUpdate(taskToUpdated);
    if (taskFromRunningHolder.isPresent()) {
        actions.addAll(ModelActionHolder.allModels(addTaskAction));
    } else {
        actions.addAll(ModelActionHolder.referenceAndStore(addTaskAction));
    }
    // Change job size
    TitusModelAction modelAction = TitusModelAction.newModelUpdate("incrementJobSize").job(updatedJobTo).trigger(Trigger.API).summary("Incremented the desired job size by one, as it got a task from another job: jobFrom=" + updatedJobFrom.getId()).jobUpdate(jobHolder -> jobHolder.setEntity(updatedJobTo));
    actions.addAll(ModelActionHolder.referenceAndStore(modelAction));
    return actions;
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ArrayList(java.util.ArrayList) ModelActionHolder(com.netflix.titus.common.framework.reconciler.ModelActionHolder)

Aggregations

TitusModelAction (com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction)20 ModelActionHolder (com.netflix.titus.common.framework.reconciler.ModelActionHolder)10 ArrayList (java.util.ArrayList)7 Task (com.netflix.titus.api.jobmanager.model.job.Task)6 Job (com.netflix.titus.api.jobmanager.model.job.Job)4 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)4 EntityHolder (com.netflix.titus.common.framework.reconciler.EntityHolder)4 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)3 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)3 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)3 TitusChangeAction (com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)3 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)2 JobStatus (com.netflix.titus.api.jobmanager.model.job.JobStatus)2 JobManagerConstants (com.netflix.titus.api.jobmanager.service.JobManagerConstants)2 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)2 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)2 Trigger (com.netflix.titus.api.jobmanager.service.V3JobOperations.Trigger)2 JobStore (com.netflix.titus.api.jobmanager.store.JobStore)2 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)2 ReconciliationEngine (com.netflix.titus.common.framework.reconciler.ReconciliationEngine)2