use of com.netflix.titus.api.jobmanager.model.job.JobState in project titus-control-plane by Netflix.
the class DefaultLoadBalancerJobValidator method validateJobId.
@Override
public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException {
// Job must exist
Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId));
// Job must be active
JobState state = job.getStatus().getState();
if (state != JobState.Accepted) {
throw JobManagerException.unexpectedJobState(job, JobState.Accepted);
}
// Must be a service job
JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions();
if (!(extensions instanceof ServiceJobExt)) {
throw JobManagerException.notServiceJob(jobId);
}
// Job should have less than max current load balancer associations
int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob();
int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId);
if (numLoadBalancers > maxLoadBalancers) {
throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers);
}
}
use of com.netflix.titus.api.jobmanager.model.job.JobState in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByJobState.
@Test(timeout = 30_000)
public void testSearchByJobState() throws Exception {
JobDescriptor<BatchJobExt> jobDescriptor = batchJobDescriptors().getValue().toBuilder().withApplicationName("testSearchByJobState").build();
String acceptedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
String killInitiatedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob()).killJob().expectJobUpdateEvent(job -> job.getStatus().getState() == JobState.KillInitiated, "Expected state: " + JobState.KillInitiated)).getId();
String acceptedTaskId = jobsScenarioBuilder.takeJob(acceptedJobId).getTaskByIndex(0).getTask().getId();
String killInitiatedTaskId = jobsScenarioBuilder.takeJob(killInitiatedJobId).getTaskByIndex(0).getTask().getId();
// Indexes are recomputed after events are sent, so if we run findJobs/findTasks immediately, they may use stale index.
Thread.sleep(10);
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
// Jobs (Accepted)
JobQueryResult acceptedJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "Accepted").build());
assertThat(acceptedJobQueryResult.getItemsList()).hasSize(1);
Job acceptedJobQueryResultItem = acceptedJobQueryResult.getItems(0);
assertThat(acceptedJobQueryResultItem.getId()).isEqualTo(acceptedJobId);
// Jobs (KillInitiated)
JobQueryResult killInitJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitJobQueryResult.getItemsList()).hasSize(1);
Job killInitJobQueryResultItem = killInitJobQueryResult.getItems(0);
assertThat(killInitJobQueryResultItem.getId()).isEqualTo(killInitiatedJobId);
// Tasks (Accepted)
TaskQueryResult acceptedTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "Accepted").setPage(PAGE).build());
assertThat(acceptedTaskQueryResult.getItemsList()).hasSize(1);
assertThat(acceptedTaskQueryResult.getItems(0).getId()).isEqualTo(acceptedTaskId);
// Tasks (KillInitiated)
TaskQueryResult killInitTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitTaskQueryResult.getItemsList()).hasSize(1);
assertThat(killInitTaskQueryResult.getItems(0).getId()).isEqualTo(killInitiatedTaskId);
}
Aggregations