Search in sources :

Example 51 with BatchJobExt

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

the class JobSubmitAndControlBasicTest method testSubmitBatchJobWithEfsMount.

/**
 * Verify batch job submit with the expected state transitions. Verify agent receives proper EFS mount data.
 */
@Test(timeout = 30_000)
public void testSubmitBatchJobWithEfsMount() {
    EfsMount efsMount1 = ContainersGenerator.efsMounts().getValue().toBuilder().withMountPoint("/data/logs").build();
    EfsMount efsMount2 = ContainersGenerator.efsMounts().skip(1).getValue().toBuilder().withMountPoint("/data").build();
    List<EfsMount> efsMounts = asList(efsMount1, efsMount2);
    List<EfsMount> expectedOrder = asList(efsMount2, efsMount1);
    JobDescriptor<BatchJobExt> jobWithEfs = ONE_TASK_BATCH_JOB.but(jd -> jd.getContainer().but(c -> c.getContainerResources().toBuilder().withEfsMounts(efsMounts)));
    jobsScenarioBuilder.schedule(jobWithEfs, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.startTasksInNewJob()).assertEachPod(podWithEfsMounts(expectedOrder), "Container not assigned the expected EFS mount").allTasks(ScenarioTemplates.completeTask()).template(ScenarioTemplates.jobFinished()).expectJobEventStreamCompletes());
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) AwsInstanceType(com.netflix.titus.common.aws.AwsInstanceType) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) JobManagerConfiguration(com.netflix.titus.runtime.jobmanager.JobManagerConfiguration) V3_ENGINE_APP_PREFIX(com.netflix.titus.testkit.junit.master.TitusStackResource.V3_ENGINE_APP_PREFIX) EfsMount(com.netflix.titus.api.model.EfsMount) JobAsserts.podWithResources(com.netflix.titus.master.integration.v3.scenario.JobAsserts.podWithResources) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ContainersGenerator(com.netflix.titus.testkit.model.job.ContainersGenerator) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TaskState(com.netflix.titus.grpc.protogen.TaskStatus.TaskState) JobAsserts.podWithEfsMounts(com.netflix.titus.master.integration.v3.scenario.JobAsserts.podWithEfsMounts) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) List(java.util.List) Rule(org.junit.Rule) EmbeddedTitusCells.basicKubeCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells.basicKubeCell) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobAttributes(com.netflix.titus.api.jobmanager.JobAttributes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) EfsMount(com.netflix.titus.api.model.EfsMount) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 52 with BatchJobExt

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

the class RateLimiterInterceptorTest method testRateLimiting.

@Test
public void testRateLimiting() throws Exception {
    Job<BatchJobExt> job = batchJobs(JobDescriptorGenerator.oneTaskBatchJobDescriptor()).getValue();
    // Use all tokens
    EntityHolder nextRoot = EntityHolder.newRoot("root", job);
    for (int i = 0; i < BUCKET_SIZE; i++) {
        assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(BUCKET_SIZE - i);
        ModelAction updateAction = executeRateLimitedAction(SampleTitusChangeActions.successfulJob());
        nextRoot = updateAction.apply(nextRoot).get().getRight();
    }
    assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(0);
    // Refill
    testClock.advanceTime(REFILL_INTERVAL_MS, TimeUnit.MILLISECONDS);
    assertThat(rateLimiterInterceptor.executionLimits(nextRoot)).isEqualTo(1);
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ModelAction(com.netflix.titus.common.framework.reconciler.ModelAction) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Test(org.junit.Test)

Example 53 with BatchJobExt

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

the class MustBeRelocatedSelfManagedTaskCollectorStepTest method testOriginalPlanIsReturnedOnEachInvocation.

@Test
public void testOriginalPlanIsReturnedOnEachInvocation() {
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    Task task = jobOperations.getTasks().get(0);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, task);
    Map<String, TaskRelocationPlan> firstResult = step.collectTasksThatMustBeRelocated();
    assertThat(firstResult).hasSize(1);
    TaskRelocationPlan first = firstResult.get(task.getId());
    ((TestClock) titusRuntime.getClock()).advanceTime(1, TimeUnit.SECONDS);
    Map<String, TaskRelocationPlan> secondResult = step.collectTasksThatMustBeRelocated();
    assertThat(secondResult).hasSize(1);
    TaskRelocationPlan second = secondResult.get(task.getId());
    assertThat(first).isEqualTo(second);
}
Also used : TestClock(com.netflix.titus.common.util.time.TestClock) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 54 with BatchJobExt

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

the class MustBeRelocatedTaskStoreUpdateStepTest method testCreateOrUpdate.

@Test
public void testCreateOrUpdate() {
    when(store.getAllTaskRelocationPlans()).thenReturn(Mono.just(Collections.emptyMap()));
    MustBeRelocatedTaskStoreUpdateStep step = new MustBeRelocatedTaskStoreUpdateStep(configuration, store, transactionLog, titusRuntime);
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, jobOperations.getTasks().get(0));
    when(store.createOrUpdateTaskRelocationPlans(anyList())).thenReturn(Mono.just(Collections.singletonMap("task1", Optional.empty())));
    TaskRelocationPlan taskRelocationPlan = oneMigrationPlan();
    Map<String, TaskRelocationPlan> storeResult = step.persistChangesInStore(Collections.singletonMap(taskRelocationPlan.getTaskId(), taskRelocationPlan));
    assertThat(storeResult).hasSize(1);
    verify(store, times(1)).createOrUpdateTaskRelocationPlans(Collections.singletonList(taskRelocationPlan));
    // No try again with the same data, and make sure no store update is executed
    Map<String, TaskRelocationPlan> storeResultRepeated = step.persistChangesInStore(Collections.singletonMap(taskRelocationPlan.getTaskId(), taskRelocationPlan));
    assertThat(storeResultRepeated).hasSize(1);
    verify(store, times(1)).createOrUpdateTaskRelocationPlans(Collections.singletonList(taskRelocationPlan));
}
Also used : BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 55 with BatchJobExt

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

the class TaskEvictionStepTest method testSuccessfulEviction.

@Test
public void testSuccessfulEviction() {
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    relocationConnectorStubs.setQuota("job1", 1);
    Task task = jobOperations.getTasks().get(0);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, task);
    TaskRelocationPlan taskRelocationPlan = oneMigrationPlan().toBuilder().withTaskId(task.getId()).build();
    Map<String, TaskRelocationStatus> result = step.evict(Collections.singletonMap(task.getId(), taskRelocationPlan));
    assertThat(result).hasSize(1);
    TaskRelocationStatus relocationStatus = result.get(task.getId());
    assertThat(relocationStatus.getTaskId()).isEqualTo(task.getId());
    assertThat(relocationStatus.getStatusCode()).isEqualTo(TaskRelocationStatus.STATUS_CODE_TERMINATED);
    assertThat(relocationStatus.getTaskRelocationPlan()).isEqualTo(taskRelocationPlan);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) 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