Search in sources :

Example 1 with TitusChangeAction

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

the class JobTransactionLogger method logJobAfterChangeReconcilerEvent.

private static String logJobAfterChangeReconcilerEvent(JobChangeReconcilerEvent.JobAfterChangeReconcilerEvent event) {
    TitusChangeAction changeAction = event.getChangeAction();
    String jobId = event.getJob().getId();
    String entityId = changeAction.getId();
    return doFormat(jobId, event.getTransactionId(), "ok", "afterChange", event.getChangeAction().getName(), changeAction.getTrigger(), toTargetName(jobId, entityId), entityId, event.getWaitTimeMs(), event.getExecutionTimeMs(), event.getCallMetadata().getCallerId(), event.getCallMetadata().getCallReason(), changeAction.getSummary());
}
Also used : TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)

Example 2 with TitusChangeAction

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

the class JobTransactionLogger method logJobBeforeChangeReconcilerEvent.

private static String logJobBeforeChangeReconcilerEvent(JobChangeReconcilerEvent.JobBeforeChangeReconcilerEvent event) {
    TitusChangeAction changeAction = event.getChangeAction();
    String jobId = event.getJob().getId();
    String entityId = changeAction.getId();
    return doFormat(jobId, event.getTransactionId(), "ok", "beforeChange", event.getChangeAction().getName(), changeAction.getTrigger(), toTargetName(jobId, entityId), entityId, 0, 0, event.getCallMetadata().getCallerId(), event.getCallMetadata().getCallReason(), changeAction.getSummary());
}
Also used : TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)

Example 3 with TitusChangeAction

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

the class DefaultV3JobOperations method moveServiceTask.

@Override
public Observable<Void> moveServiceTask(String sourceJobId, String targetJobId, String taskId, CallMetadata callMetadata) {
    return Observable.defer(() -> {
        Pair<ReconciliationEngine<JobManagerReconcilerEvent>, EntityHolder> fromEngineTaskPair = reconciliationFramework.findEngineByChildId(taskId).orElseThrow(() -> JobManagerException.taskNotFound(taskId));
        ReconciliationEngine<JobManagerReconcilerEvent> engineFrom = fromEngineTaskPair.getLeft();
        Job<ServiceJobExt> jobFrom = engineFrom.getReferenceView().getEntity();
        if (!JobFunctions.isServiceJob(jobFrom)) {
            throw JobManagerException.notServiceJob(jobFrom.getId());
        }
        if (!jobFrom.getId().equals(sourceJobId)) {
            throw JobManagerException.taskJobMismatch(taskId, sourceJobId);
        }
        if (jobFrom.getId().equals(targetJobId)) {
            throw JobManagerException.sameJobs(jobFrom.getId());
        }
        ReconciliationEngine<JobManagerReconcilerEvent> engineTo = reconciliationFramework.findEngineByRootId(targetJobId).orElseThrow(() -> JobManagerException.jobNotFound(targetJobId));
        Job<ServiceJobExt> jobTo = engineTo.getReferenceView().getEntity();
        if (!JobFunctions.isServiceJob(jobTo)) {
            throw JobManagerException.notServiceJob(jobTo.getId());
        }
        JobCompatibility compatibility = JobCompatibility.of(jobFrom, jobTo);
        if (featureActivationConfiguration.isMoveTaskValidationEnabled() && !compatibility.isCompatible()) {
            Optional<String> diffReport = ProtobufExt.diffReport(GrpcJobManagementModelConverters.toGrpcJobDescriptor(compatibility.getNormalizedDescriptorFrom()), GrpcJobManagementModelConverters.toGrpcJobDescriptor(compatibility.getNormalizedDescriptorTo()));
            throw JobManagerException.notCompatible(jobFrom, jobTo, diffReport.orElse(""));
        }
        return reconciliationFramework.changeReferenceModel(new MoveTaskBetweenJobsAction(engineFrom, engineTo, taskId, store, callMetadata, versionSupplier), (rootId, modelUpdatesObservable) -> {
            String name;
            String summary;
            if (targetJobId.equals(rootId)) {
                name = "moveTask(to)";
                summary = "Moving a task to this job from job " + jobFrom.getId();
            } else {
                name = "moveTask(from)";
                summary = "Moving a task out of this job to job " + jobTo.getId();
            }
            return new TitusChangeAction(Trigger.API, rootId, null, name, summary, callMetadata) {

                @Override
                public Observable<List<ModelActionHolder>> apply() {
                    return modelUpdatesObservable;
                }
            };
        }, jobFrom.getId(), jobTo.getId());
    });
}
Also used : MoveTaskBetweenJobsAction(com.netflix.titus.master.jobmanager.service.service.action.MoveTaskBetweenJobsAction) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) JobCompatibility(com.netflix.titus.api.jobmanager.model.job.JobCompatibility) ReconciliationEngine(com.netflix.titus.common.framework.reconciler.ReconciliationEngine) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with TitusChangeAction

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

the class BatchDifferenceResolver method createNewTaskAction.

private Optional<TitusChangeAction> createNewTaskAction(BatchJobView refJobView, int taskIndex, Optional<EntityHolder> previousTask, List<String> unassignedIpAllocations, List<String> ebsVolumeIds) {
    // Safety check
    long numberOfNotFinishedTasks = refJobView.getJobHolder().getChildren().stream().filter(holder -> TaskState.isRunning(((Task) holder.getEntity()).getStatus().getState())).count();
    if (numberOfNotFinishedTasks >= refJobView.getRequiredSize()) {
        titusRuntime.getCodeInvariants().inconsistent("Batch job reconciler attempts to create too many tasks: jobId=%s, requiredSize=%s, current=%s", refJobView.getJob().getId(), refJobView.getRequiredSize(), numberOfNotFinishedTasks);
        return Optional.empty();
    }
    Map<String, String> taskContext = getTaskContext(previousTask, unassignedIpAllocations, ebsVolumeIds);
    JobDescriptor jobDescriptor = refJobView.getJob().getJobDescriptor();
    ApplicationSLA capacityGroupDescriptor = JobManagerUtil.getCapacityGroupDescriptor(jobDescriptor, capacityGroupService);
    String resourcePool = capacityGroupDescriptor.getResourcePool();
    taskContext = CollectionsExt.copyAndAdd(taskContext, ImmutableMap.of(TaskAttributes.TASK_ATTRIBUTES_RESOURCE_POOL, resourcePool, TaskAttributes.TASK_ATTRIBUTES_TIER, capacityGroupDescriptor.getTier().name()));
    TitusChangeAction storeAction = storeWriteRetryInterceptor.apply(createOrReplaceTaskAction(runtime, jobStore, refJobView.getJobHolder(), taskIndex, versionSupplier, clock, taskContext));
    return Optional.of(storeAction);
}
Also used : 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) LoggerFactory(org.slf4j.LoggerFactory) RetryActionInterceptor(com.netflix.titus.master.jobmanager.service.common.interceptor.RetryActionInterceptor) RECONCILER_CALLMETADATA(com.netflix.titus.api.jobmanager.service.JobManagerConstants.RECONCILER_CALLMETADATA) FeatureActivationConfiguration(com.netflix.titus.api.FeatureActivationConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) BasicJobActions(com.netflix.titus.master.jobmanager.service.common.action.task.BasicJobActions) JobManagerConfiguration(com.netflix.titus.master.jobmanager.service.JobManagerConfiguration) Schedulers(rx.schedulers.Schedulers) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobManagerUtil(com.netflix.titus.master.jobmanager.service.JobManagerUtil) TaskRetryers(com.netflix.titus.master.jobmanager.service.common.action.TaskRetryers) Job(com.netflix.titus.api.jobmanager.model.job.Job) ImmutableMap(com.google.common.collect.ImmutableMap) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) Set(java.util.Set) Scheduler(rx.Scheduler) DifferenceResolverUtils.getUnassignedIpAllocations(com.netflix.titus.master.jobmanager.service.common.DifferenceResolverUtils.getUnassignedIpAllocations) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) VersionSupplier(com.netflix.titus.master.jobmanager.service.VersionSupplier) ReconciliationEngine(com.netflix.titus.common.framework.reconciler.ReconciliationEngine) Optional(java.util.Optional) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) Clock(com.netflix.titus.common.util.time.Clock) KillInitiatedActions(com.netflix.titus.master.jobmanager.service.common.action.task.KillInitiatedActions) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) ApplicationSlaManagementService(com.netflix.titus.master.service.management.ApplicationSlaManagementService) CreateOrReplaceBatchTaskActions.createOrReplaceTaskAction(com.netflix.titus.master.jobmanager.service.batch.action.CreateOrReplaceBatchTaskActions.createOrReplaceTaskAction) DifferenceResolverUtils(com.netflix.titus.master.jobmanager.service.common.DifferenceResolverUtils) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ChangeAction(com.netflix.titus.common.framework.reconciler.ChangeAction) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) DifferenceResolverUtils.getUnassignedEbsVolumes(com.netflix.titus.master.jobmanager.service.common.DifferenceResolverUtils.getUnassignedEbsVolumes) Named(javax.inject.Named) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Logger(org.slf4j.Logger) DifferenceResolverUtils.getTaskContext(com.netflix.titus.master.jobmanager.service.common.DifferenceResolverUtils.getTaskContext) Retryers(com.netflix.titus.common.util.retry.Retryers) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) TimeUnit(java.util.concurrent.TimeUnit) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) BasicTaskActions(com.netflix.titus.master.jobmanager.service.common.action.task.BasicTaskActions) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) TokenBucket(com.netflix.titus.common.util.limiter.tokenbucket.TokenBucket) Collections(java.util.Collections) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)

Example 5 with TitusChangeAction

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

the class ServiceDifferenceResolver method createNewTaskAction.

private Optional<TitusChangeAction> createNewTaskAction(ServiceJobView refJobView, Optional<EntityHolder> previousTask, List<String> unassignedIpAllocations, List<String> unassignedEbsVolumeIds) {
    // Safety check
    long numberOfNotFinishedTasks = getNumberOfNotFinishedTasks(refJobView);
    if (numberOfNotFinishedTasks >= refJobView.getRequiredSize()) {
        titusRuntime.getCodeInvariants().inconsistent("Service job reconciler attempts to create too many tasks: jobId=%s, requiredSize=%s, current=%s", refJobView.getJob().getId(), refJobView.getRequiredSize(), numberOfNotFinishedTasks);
        return Optional.empty();
    }
    Map<String, String> taskContext = getTaskContext(previousTask, unassignedIpAllocations, unassignedEbsVolumeIds);
    JobDescriptor jobDescriptor = refJobView.getJob().getJobDescriptor();
    ApplicationSLA capacityGroupDescriptor = JobManagerUtil.getCapacityGroupDescriptor(jobDescriptor, capacityGroupService);
    String resourcePool = capacityGroupDescriptor.getResourcePool();
    taskContext = CollectionsExt.copyAndAdd(taskContext, ImmutableMap.of(TaskAttributes.TASK_ATTRIBUTES_RESOURCE_POOL, resourcePool, TaskAttributes.TASK_ATTRIBUTES_TIER, capacityGroupDescriptor.getTier().name()));
    TitusChangeAction storeAction = storeWriteRetryInterceptor.apply(createOrReplaceTaskAction(runtime, jobStore, versionSupplier, refJobView.getJobHolder(), previousTask, clock, taskContext));
    return Optional.of(storeAction);
}
Also used : JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) 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