Search in sources :

Example 1 with ServiceJobExt

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

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

the class CachedServiceJobTest method testAddTask.

@Test
public void testAddTask() {
    PCollectionJobSnapshot initialSnapshot = initialSnapshot(2, false);
    // Empty
    CachedJob cached1 = CollectionsExt.first(initialSnapshot.cachedJobsById.values());
    assertThat(cached1.getTasks()).hasSize(2);
    // One task
    Task extraTask = newServiceTask((Job<ServiceJobExt>) cached1.getJob(), 3);
    PCollectionJobSnapshot withThreeTasks = (PCollectionJobSnapshot) cached1.updateTask(initialSnapshot, extraTask).orElse(null);
    CachedJob cached2 = CollectionsExt.first(withThreeTasks.cachedJobsById.values());
    assertThat(cached2.getTasks()).hasSize(3);
    assertThat(cached2.getTasks()).containsValue(extraTask);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobSnapshotTestUtil.newServiceTask(com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshotTestUtil.newServiceTask) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Test(org.junit.Test)

Example 3 with ServiceJobExt

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

the class CassandraJobStoreTest method testMoveTask.

@Test
public void testMoveTask() {
    JobStore store = getJobStore();
    store.init().await();
    Job<ServiceJobExt> jobFrom = createServiceJobObject();
    store.storeJob(jobFrom).await();
    Job<ServiceJobExt> jobTo = createServiceJobObject();
    store.storeJob(jobTo).await();
    Task task = createServiceTaskObject(jobFrom);
    store.storeTask(task).await();
    Job<ServiceJobExt> updatedFromJob = JobFunctions.incrementJobSize(jobFrom, -1);
    Job<ServiceJobExt> updatedToJob = JobFunctions.incrementJobSize(jobTo, 1);
    Task updatedTask = task.toBuilder().withJobId(updatedToJob.getId()).build();
    store.moveTask(updatedFromJob, updatedToJob, updatedTask).await();
    // Load jobFrom from store
    Job<?> jobFromLoaded = store.retrieveJob(jobFrom.getId()).toBlocking().first();
    assertThat(JobFunctions.getJobDesiredSize(jobFromLoaded)).isEqualTo(0);
    Pair<List<Task>, Integer> jobFromTasksLoaded = store.retrieveTasksForJob(jobFrom.getId()).toBlocking().first();
    assertThat(jobFromTasksLoaded.getLeft()).hasSize(0);
    // Load jobTo from store
    Job<?> jobToLoaded = store.retrieveJob(jobTo.getId()).toBlocking().first();
    assertThat(JobFunctions.getJobDesiredSize(jobToLoaded)).isEqualTo(2);
    Pair<List<Task>, Integer> jobToTasksLoaded = store.retrieveTasksForJob(jobTo.getId()).toBlocking().first();
    assertThat(jobToTasksLoaded.getLeft()).hasSize(1);
    jobToTasksLoaded.getLeft().forEach(t -> assertThat(t.getJobId()).isEqualTo(jobTo.getId()));
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 4 with ServiceJobExt

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

the class CassandraJobStoreTest method createServiceJobObject.

private Job<ServiceJobExt> createServiceJobObject() {
    ExponentialBackoffRetryPolicy exponential = JobModel.newExponentialBackoffRetryPolicy().withInitialDelayMs(10).withMaxDelayMs(100).withRetries(5).build();
    JobDescriptor<ServiceJobExt> jobDescriptor = JobDescriptorGenerator.oneTaskServiceJobDescriptor().but(jd -> jd.getExtensions().toBuilder().withRetryPolicy(exponential).build());
    return JobGenerator.serviceJobs(jobDescriptor).getValue();
}
Also used : ExponentialBackoffRetryPolicy(com.netflix.titus.api.jobmanager.model.job.retry.ExponentialBackoffRetryPolicy) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)

Example 5 with ServiceJobExt

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

the class CassandraJobStoreTest method createServiceJobWithPlatformSidecarsObject.

/**
 * createServiceJobWithPlatformSidecarsObject is an extra strenuous test for the CassandraJobStore
 * suite, as it exercises all the things needed to ensure that the complex arguments field
 * is properly serialized correctly.
 */
private Job<ServiceJobExt> createServiceJobWithPlatformSidecarsObject() {
    Struct.Builder args = Struct.newBuilder();
    args.putFields("foo", Value.newBuilder().setStringValue("bar").build());
    args.putFields("baz", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
    args.putFields("num", Value.newBuilder().setNumberValue(42.0).build());
    PlatformSidecar ps1 = PlatformSidecar.newBuilder().withName("testSidecar").withChannel("testChannel").withArguments("{\"foo\":true,\"bar\":3.0}").build();
    List<PlatformSidecar> platformSidecars = Collections.singletonList(ps1);
    JobDescriptor<ServiceJobExt> jobDescriptor = JobDescriptorGenerator.oneTaskServiceJobDescriptor().but(jd -> jd.toBuilder().withPlatformSidecars(platformSidecars).build());
    return JobGenerator.serviceJobs(jobDescriptor).getValue();
}
Also used : PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Struct(com.google.protobuf.Struct)

Aggregations

ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)42 Test (org.junit.Test)17 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)13 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)13 Job (com.netflix.titus.api.jobmanager.model.job.Job)11 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)8 Task (com.netflix.titus.api.jobmanager.model.job.Task)8 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)8 List (java.util.List)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Stopwatch (com.google.common.base.Stopwatch)6 Empty (com.google.protobuf.Empty)6 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)6 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)6 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)6 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)5 JobScenarioBuilder (com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder)5 JobDescriptorGenerator.oneTaskServiceJobDescriptor (com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor)5 ArrayList (java.util.ArrayList)5 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)4