Search in sources :

Example 1 with Job

use of com.netflix.titus.api.jobmanager.model.job.Job 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);
    }
}
Also used : JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 2 with Job

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

the class GrpcJobReplicatorEventStreamTest method testCacheTaskRemove.

@Test
public void testCacheTaskRemove() {
    Pair<Job, List<Task>> pair = jobServiceStub.createJobAndTasks(SERVICE_JOB);
    List<Task> tasks = pair.getRight();
    Task task = tasks.get(0);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Accepted)).then(() -> jobServiceStub.moveTaskToState(task, TaskState.Finished)).assertNext(next -> assertThat(next.getSnapshot().getTaskMap()).hasSize(tasks.size() - 1)).thenCancel().verify();
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 3 with Job

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

the class GrpcJobReplicatorEventStreamTest method testCacheTaskUpdate.

@Test
public void testCacheTaskUpdate() {
    Pair<Job, List<Task>> pair = jobServiceStub.createJobAndTasks(BATCH_JOB);
    Task task = pair.getRight().get(0);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Accepted)).then(() -> jobServiceStub.moveTaskToState(task, TaskState.Launched)).assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Launched)).thenCancel().verify();
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 4 with Job

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

the class GrpcJobReplicatorEventStreamTest method testCacheJobUpdate.

@Test
public void testCacheJobUpdate() {
    Job job = jobServiceStub.createJob(SERVICE_JOB);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getJobs().get(0).getStatus().getState()).isEqualTo(JobState.Accepted)).then(() -> jobServiceStub.moveJobToKillInitiatedState(job)).assertNext(next -> assertThat(next.getSnapshot().getJobs().get(0).getStatus().getState()).isEqualTo(JobState.KillInitiated)).thenCancel().verify();
}
Also used : Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 5 with Job

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

the class GrpcJobReplicatorEventStreamTest method testCacheJobRemove.

@Test
public void testCacheJobRemove() {
    Job job = jobServiceStub.createJob(SERVICE_JOB);
    jobServiceStub.moveJobToKillInitiatedState(job);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getJobs().get(0).getStatus().getState()).isEqualTo(JobState.KillInitiated)).then(() -> jobServiceStub.finishJob(job)).assertNext(next -> assertThat(next.getSnapshot().getJobs()).isEmpty()).thenCancel().verify();
}
Also used : Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Aggregations

Job (com.netflix.titus.api.jobmanager.model.job.Job)90 Task (com.netflix.titus.api.jobmanager.model.job.Task)53 List (java.util.List)38 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)26 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)23 Pair (com.netflix.titus.common.util.tuple.Pair)21 Optional (java.util.Optional)21 Map (java.util.Map)18 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)17 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)14 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)14 Collections (java.util.Collections)14 HashMap (java.util.HashMap)14 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)13 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)13 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)11 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)11