Search in sources :

Example 1 with JobFunctions.appendJobDescriptorAttributes

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()));
}
Also used : JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) LoggerFactory(org.slf4j.LoggerFactory) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) HashMap(java.util.HashMap) UnaryOperator(java.util.function.UnaryOperator) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION) JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) JobFunctions.appendJobDescriptorAttributes(com.netflix.titus.api.jobmanager.model.job.JobFunctions.appendJobDescriptorAttributes) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Logger(org.slf4j.Logger) JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC) ImmutableMap(com.google.common.collect.ImmutableMap) JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Mono(reactor.core.publisher.Mono) JOB_PARAMETER_SKIP_RUNTIME_PREDICTION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION) JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID) FunctionExt(com.netflix.titus.common.util.FunctionExt) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)1 JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION)1 JOB_PARAMETER_SKIP_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION)1 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)1 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)1 JobFunctions.appendJobDescriptorAttributes (com.netflix.titus.api.jobmanager.model.job.JobFunctions.appendJobDescriptorAttributes)1 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 AdmissionSanitizer (com.netflix.titus.common.model.admission.AdmissionSanitizer)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 FunctionExt (com.netflix.titus.common.util.FunctionExt)1 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)1 JobRuntimePredictionClient (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient)1 JobRuntimePredictions (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions)1 HashMap (java.util.HashMap)1