Search in sources :

Example 6 with AdmissionSanitizer

use of com.netflix.titus.common.model.admission.AdmissionSanitizer in project titus-control-plane by Netflix.

the class JobRuntimePredictionSanitizerTest method errorsCauseSanitizationToBeSkipped.

@Test
public void errorsCauseSanitizationToBeSkipped() {
    JobDescriptor<BatchJobExt> noRuntimeLimit = jobDescriptor.but(jd -> jd.getExtensions().toBuilder().withRuntimeLimitMs(0));
    JobRuntimePredictionClient errorClient = mock(JobRuntimePredictionClient.class);
    when(errorClient.getRuntimePredictions(any())).thenReturn(Mono.error(TitusServiceException.internal("bad request")));
    AdmissionSanitizer<JobDescriptor> sanitizer = new JobRuntimePredictionSanitizer(errorClient, JobRuntimePredictionSelectors.best(), config, TitusRuntimes.test());
    StepVerifier.create(sanitizer.sanitizeAndApply(noRuntimeLimit)).assertNext(result -> assertThat(((JobDescriptor<?>) result).getAttributes()).containsEntry(JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION, "true").doesNotContainKeys(JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) Arrays(java.util.Arrays) 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) StepVerifier(reactor.test.StepVerifier) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) TreeSet(java.util.TreeSet) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) Before(org.junit.Before) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC) JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) 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) Mockito.mock(org.mockito.Mockito.mock) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) Test(org.junit.Test)

Example 7 with AdmissionSanitizer

use of com.netflix.titus.common.model.admission.AdmissionSanitizer in project titus-control-plane by Netflix.

the class JobRuntimePredictionSanitizerTest method predictionsAreCappedToRuntimeLimit.

@Test
public void predictionsAreCappedToRuntimeLimit() {
    JobRuntimePredictionClient client = mock(JobRuntimePredictionClient.class);
    JobRuntimePredictions predictions = new JobRuntimePredictions("v1", modelId, new TreeSet<>(Arrays.asList(new JobRuntimePrediction(0.05, 10.1), new JobRuntimePrediction(0.25, 30.2), new JobRuntimePrediction(0.90, 90.5))));
    when(client.getRuntimePredictions(any())).thenReturn(Mono.just(predictions));
    AdmissionSanitizer<JobDescriptor> sanitizer = new JobRuntimePredictionSanitizer(client, JobRuntimePredictionSelectors.best(), config, TitusRuntimes.test());
    StepVerifier.create(sanitizer.sanitizeAndApply(jobDescriptor)).assertNext(result -> assertThat(((JobDescriptor<?>) result).getAttributes()).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, "60.0").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, "1.0").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, modelId).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION, "v1").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE, "0.05=10.1;0.25=30.2;0.9=90.5")).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) Arrays(java.util.Arrays) 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) StepVerifier(reactor.test.StepVerifier) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) TreeSet(java.util.TreeSet) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) Before(org.junit.Before) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC) JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) 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) Mockito.mock(org.mockito.Mockito.mock) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) Test(org.junit.Test)

Example 8 with AdmissionSanitizer

use of com.netflix.titus.common.model.admission.AdmissionSanitizer in project titus-control-plane by Netflix.

the class JobRuntimePredictionSanitizerTest method emptyPredictionsCauseSanitizationToBeSkipped.

@Test
public void emptyPredictionsCauseSanitizationToBeSkipped() {
    JobDescriptor<BatchJobExt> noRuntimeLimit = jobDescriptor.but(jd -> jd.getExtensions().toBuilder().withRuntimeLimitMs(0));
    JobRuntimePredictionClient client = mock(JobRuntimePredictionClient.class);
    JobRuntimePredictions predictions = new JobRuntimePredictions("v1", modelId, new TreeSet<>());
    when(client.getRuntimePredictions(any())).thenReturn(Mono.just(predictions));
    AdmissionSanitizer<JobDescriptor> sanitizer = new JobRuntimePredictionSanitizer(client, JobRuntimePredictionSelectors.best(), config, TitusRuntimes.test());
    StepVerifier.create(sanitizer.sanitizeAndApply(noRuntimeLimit)).assertNext(result -> assertThat(((JobDescriptor<?>) result).getAttributes()).containsEntry(JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION, "true").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, modelId).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION, "v1").doesNotContainKeys(JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) Arrays(java.util.Arrays) 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) StepVerifier(reactor.test.StepVerifier) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRuntimePrediction(com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction) TreeSet(java.util.TreeSet) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) AdmissionSanitizer(com.netflix.titus.common.model.admission.AdmissionSanitizer) Before(org.junit.Before) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC) JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) 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) Mockito.mock(org.mockito.Mockito.mock) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) Test(org.junit.Test)

Aggregations

JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)8 JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE)8 JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID)8 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC)8 JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)8 JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION)8 JOB_PARAMETER_SKIP_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION)8 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)8 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)8 TitusServiceException (com.netflix.titus.api.service.TitusServiceException)8 AdmissionSanitizer (com.netflix.titus.common.model.admission.AdmissionSanitizer)8 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)8 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)8 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)8 JobRuntimePredictionClient (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient)8 JobRuntimePredictions (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions)8 JobDescriptorGenerator (com.netflix.titus.testkit.model.job.JobDescriptorGenerator)8 Arrays (java.util.Arrays)8 TreeSet (java.util.TreeSet)8 UUID (java.util.UUID)8