Search in sources :

Example 6 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor in project titus-control-plane by Netflix.

the class DefaultAppScaleManagerTest method mockV3OperationsForJobs.

private V3JobOperations mockV3OperationsForJobs(List<String> jobIds) {
    V3JobOperations v3JobOperations = mock(V3JobOperations.class);
    for (String jobId : jobIds) {
        // FIXME Use JobGenerator instead of mocking.
        Job job = mock(Job.class);
        when(job.getId()).thenReturn(jobId);
        JobDescriptor jobDescriptorOne = mock(JobDescriptor.class);
        ServiceJobExt serviceJobExtOne = mock(ServiceJobExt.class);
        JobGroupInfo jobGroupInfoOne = buildMockJobGroupInfo(jobId);
        Capacity capacityOne = mock(Capacity.class);
        when(capacityOne.getMax()).thenReturn(10);
        when(capacityOne.getMin()).thenReturn(1);
        when(serviceJobExtOne.getCapacity()).thenReturn(capacityOne);
        when(jobDescriptorOne.getExtensions()).thenReturn(serviceJobExtOne);
        when(job.getJobDescriptor()).thenReturn(jobDescriptorOne);
        when(jobDescriptorOne.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
        when(jobDescriptorOne.getApplicationName()).thenReturn("testApp");
        when(v3JobOperations.getJob(jobId)).thenReturn(Optional.of(job));
        JobManagerEvent<?> jobUpdateEvent = JobUpdateEvent.newJob(job, callMetadata);
        when(v3JobOperations.observeJobs()).thenAnswer(invocation -> Observable.from(asList(jobUpdateEvent)));
    }
    return v3JobOperations;
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 7 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor in project titus-control-plane by Netflix.

the class MoveTaskTest method testMoveWithIncompatibleTargetJob.

@Test
public void testMoveWithIncompatibleTargetJob() {
    JobDescriptor<ServiceJobExt> jobDescriptor = oneTaskServiceJobDescriptor();
    JobScenarioBuilder sourceJobBuilder = startNewJob(jobDescriptor);
    String sourceJobId = sourceJobBuilder.getJobId();
    JobDescriptor<ServiceJobExt> incompatible = jobDescriptor.but(descriptor -> descriptor.getContainer().but(container -> container.getImage().toBuilder().withName("other/image").build()));
    String targetJobId = startNewJob(incompatible).getJobId();
    try {
        sourceJobBuilder.moveTask(0, 0, sourceJobId, targetJobId);
    } catch (JobManagerException e) {
        assertThat(e.getErrorCode()).isEqualTo(JobManagerException.ErrorCode.JobsNotCompatible);
        assertThat(e.getMessage()).contains("container.image.name");
    }
}
Also used : ScenarioTemplates(com.netflix.titus.master.jobmanager.service.integration.scenario.ScenarioTemplates) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) TimeoutException(java.util.concurrent.TimeoutException) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test) JobsScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder) TestScheduler(rx.schedulers.TestScheduler) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) TimeUnit(java.util.concurrent.TimeUnit) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test)

Example 8 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateHardSoftTimeout.

// Hard/Soft validation tests
@Test
public void validateHardSoftTimeout() {
    AdmissionValidator<JobDescriptor> never0 = new NeverJobValidator(ValidationError.Type.HARD);
    AdmissionValidator never1 = new NeverJobValidator(ValidationError.Type.SOFT);
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(never0, never1));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 2).verifyComplete();
    Collection<ValidationError> errors = mono.block();
    validateTimeoutErrors(errors);
    Collection<ValidationError> hardErrors = errors.stream().filter(error -> error.getType().equals(ValidationError.Type.HARD)).collect(Collectors.toList());
    assertThat(hardErrors).hasSize(1);
    Collection<ValidationError> softErrors = errors.stream().filter(error -> error.getType().equals(ValidationError.Type.SOFT)).collect(Collectors.toList());
    assertThat(softErrors).hasSize(1);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 9 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor in project titus-control-plane by Netflix.

the class JobRuntimePredictionSanitizerTest method runtimeLimitIsOnlyUsedWhenWithinAllowedConfig.

@Test
public void runtimeLimitIsOnlyUsedWhenWithinAllowedConfig() {
    JobRuntimePredictionClient client = mock(JobRuntimePredictionClient.class);
    JobRuntimePredictions predictions = new JobRuntimePredictions("v1", modelId, new TreeSet<>());
    when(client.getRuntimePredictions(any())).thenReturn(Mono.just(predictions));
    JobRuntimePredictionConfiguration lowConfig = mock(JobRuntimePredictionConfiguration.class);
    // lower than the 60s runtime limit on the job
    when(lowConfig.getMaxOpportunisticRuntimeLimitMs()).thenReturn(30_000L);
    AdmissionSanitizer<JobDescriptor> sanitizer = new JobRuntimePredictionSanitizer(client, JobRuntimePredictionSelectors.best(), lowConfig, TitusRuntimes.test());
    StepVerifier.create(sanitizer.sanitizeAndApply(jobDescriptor)).assertNext(result -> assertThat(((JobDescriptor<?>) result).getAttributes()).doesNotContainKeys(JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE, JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC, JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE).containsEntry(JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION, "true").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, modelId).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION, "v1")).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) JobRuntimePredictions(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictions) JobRuntimePredictionClient(com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient) Test(org.junit.Test)

Example 10 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor in project titus-control-plane by Netflix.

the class JobRuntimePredictionSanitizerTest method higherQualityPredictionsMustBeLonger.

@Test
public void higherQualityPredictionsMustBeLonger() {
    JobRuntimePredictionClient client = mock(JobRuntimePredictionClient.class);
    JobRuntimePredictions predictions = new JobRuntimePredictions("v1", modelId, new TreeSet<>(Arrays.asList(new JobRuntimePrediction(0.05, 5.1), new JobRuntimePrediction(0.25, 4.0), new JobRuntimePrediction(0.35, 4.1), new JobRuntimePrediction(0.90, 4.0))));
    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_SANITIZATION_SKIPPED_RUNTIME_PREDICTION, "true").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID, modelId).containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION, "v1").containsEntry(JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE, "0.05=5.1;0.25=4.0;0.35=4.1;0.9=4.0")).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)

Aggregations

JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)28 Test (org.junit.Test)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)15 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)13 Before (org.junit.Before)13 Mono (reactor.core.publisher.Mono)12 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)11 AdmissionSanitizer (com.netflix.titus.common.model.admission.AdmissionSanitizer)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)9 JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION)9 JOB_PARAMETER_SKIP_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION)9 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)9 JobRuntimePredictionClient (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient)9