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());
}
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)));
});
}
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)));
});
}
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;
}
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;
}
Aggregations