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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations