use of com.netflix.titus.api.jobmanager.model.job.JobFunctions.appendJobDescriptorAttributes in project titus-control-plane by Netflix.
the class JobRuntimePredictionSanitizer method capPredictionToRuntimeLimit.
/**
* Use the prediction when available and shorter than the runtime limit, otherwise the runtime limit becomes
* the prediction if within {@link JobRuntimePredictionConfiguration#getMaxOpportunisticRuntimeLimitMs()}
*/
@SuppressWarnings("unchecked")
private JobDescriptor capPredictionToRuntimeLimit(JobDescriptor jobDescriptor) {
// non-batch jobs have been filtered before this point, it is safe to cast
BatchJobExt extensions = ((JobDescriptor<BatchJobExt>) jobDescriptor).getExtensions();
long runtimeLimitMs = extensions.getRuntimeLimitMs();
if (runtimeLimitMs <= 0 || runtimeLimitMs > configuration.getMaxOpportunisticRuntimeLimitMs()) {
// no runtime limit or too high to be used, noop
return jobDescriptor;
}
return JobFunctions.getJobRuntimePrediction(jobDescriptor).filter(prediction -> runtimeLimitMs > prediction.toMillis()).map(ignored -> jobDescriptor).orElseGet(() -> JobFunctions.appendJobDescriptorAttributes(jobDescriptor, ImmutableMap.<String, String>builder().put(JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, Double.toString(runtimeLimitMs / 1000.0)).put(JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, Double.toString(1.0)).build()));
}
Aggregations