Search in sources :

Example 41 with BatchJobExt

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

the class DefaultLoadBalancerJobValidatorTest method testValidateJobIsService.

@Test
public void testValidateJobIsService() throws Exception {
    when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.of(Job.<BatchJobExt>newBuilder().withId(JOB_ID).withStatus(JobStatus.newBuilder().withState(JobState.Accepted).build()).withJobDescriptor(JobDescriptor.<BatchJobExt>newBuilder().build()).build()));
    Throwable thrown = catchThrowable(() -> loadBalancerValidator.validateJobId(JOB_ID));
    assertThat(thrown).isInstanceOf(JobManagerException.class);
    assertThat(((JobManagerException) thrown).getErrorCode()).isEqualTo(JobManagerException.ErrorCode.NotServiceJob);
}
Also used : BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) Test(org.junit.Test)

Example 42 with BatchJobExt

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

the class JobQuotaControllerTest method testMergeRatePerIntervalDisruptionBudgetRateQuotaController.

@Test
public void testMergeRatePerIntervalDisruptionBudgetRateQuotaController() {
    // First version
    Job<BatchJobExt> job = newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), ratePerInterval(60_000, 5), Collections.emptyList()));
    com.netflix.titus.api.model.reference.Reference jobReference = com.netflix.titus.api.model.reference.Reference.job(job.getId());
    scheduleJob(job, 10);
    List<QuotaController<Job<?>>> controllers = buildQuotaControllers(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    RatePerIntervalRateController controller = (RatePerIntervalRateController) controllers.get(0);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(controller.consume(task.getId()).isApproved()).isTrue();
    assertThat(controller.getQuota(jobReference).getQuota()).isEqualTo(4);
    // Change job descriptor and consume some quota
    Job<BatchJobExt> updatedJob = jobComponentStub.changeJob(exceptRate(job, ratePerInterval(30_000, 5)));
    List<QuotaController<Job<?>>> merged = mergeQuotaControllers(controllers, updatedJob, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    RatePerIntervalRateController updatedController = (RatePerIntervalRateController) merged.get(0);
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(4);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 43 with BatchJobExt

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

the class TaskRelocationLimitControllerTest method testQuota.

@Test
public void testQuota() {
    Job<BatchJobExt> job = createBatchJob(2);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    Reference jobReference = Reference.job(job.getId());
    Reference taskReference = Reference.task(task.getId());
    TaskRelocationLimitController quotaController = new TaskRelocationLimitController(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance());
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(10);
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(1);
    // Now consume quotas for the first task
    assertThat(quotaController.consume(task.getId()).isApproved()).isTrue();
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(1);
    jobComponentStub.moveTaskToState(task, TaskState.Started);
    jobComponentStub.killTask(task, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement1 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    assertThat(quotaController.consume(replacement1.getId()).isApproved()).isTrue();
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(10);
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(0);
    jobComponentStub.moveTaskToState(replacement1, TaskState.Started);
    jobComponentStub.killTask(replacement1, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement2 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    assertThat(quotaController.consume(replacement2.getId()).isApproved()).isFalse();
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(9);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 44 with BatchJobExt

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

the class UnhealthyTasksLimitTrackerTest method testPercentageBasedQuotaWithOneTaskJob.

@Test
public void testPercentageBasedQuotaWithOneTaskJob() {
    Job<BatchJobExt> job = newBatchJobWithPercentageLimit(1, 95);
    UnhealthyTasksLimitTracker tracker = UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) job.getJobDescriptor().getDisruptionBudget().getDisruptionBudgetPolicy(), jobOperations, jobComponentStub.getContainerHealthService());
    Reference jobReference = Reference.job(job.getId());
    // No tasks are started yet
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
    // Start task
    jobOperations.getTasks().forEach(task -> jobComponentStub.moveTaskToState(task, TaskState.Started));
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
    // Now make one unhealthy. As this is the only task in the job, it should be possible to move it
    jobComponentStub.changeContainerHealth(jobOperations.getTasks().get(0).getId(), ContainerHealthState.Unhealthy);
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
}
Also used : Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 45 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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)

Aggregations

BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)73 Test (org.junit.Test)55 Task (com.netflix.titus.api.jobmanager.model.job.Task)30 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)25 List (java.util.List)20 ArrayList (java.util.ArrayList)19 JobStore (com.netflix.titus.api.jobmanager.store.JobStore)17 HashMap (java.util.HashMap)16 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)14 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)13 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)11 V1Pod (io.kubernetes.client.openapi.models.V1Pod)11 Job (com.netflix.titus.api.jobmanager.model.job.Job)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 Container (com.netflix.titus.api.jobmanager.model.job.Container)6 Map (java.util.Map)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 V1Container (io.kubernetes.client.openapi.models.V1Container)5 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)4 Image (com.netflix.titus.api.jobmanager.model.job.Image)4