use of com.netflix.titus.api.jobmanager.model.job.JobCompatibility 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());
});
}
Aggregations