Search in sources :

Example 31 with BatchJobExt

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

the class DefaultPodAffinityFactoryTest method testIpAllocationAzAffinity.

@Test
public void testIpAllocationAzAffinity() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(1).toList();
    job = job.toBuilder().withJobDescriptor(JobFunctions.jobWithIpAllocations(job.getJobDescriptor(), ipAddressAllocations)).build();
    Pair<V1Affinity, Map<String, String>> affinityWithAnnotations = factory.buildV1Affinity(job, JobIpAllocationGenerator.appendIpAllocationAttribute(JobGenerator.oneBatchTask(), ipAddressAllocations.get(0).getIpAddressAllocation().getAllocationId()));
    V1NodeSelector nodeSelector = affinityWithAnnotations.getLeft().getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution();
    assertThat(nodeSelector.getNodeSelectorTerms()).hasSize(1);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getKey()).isEqualTo(KubeConstants.NODE_LABEL_ZONE);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getValues().get(0)).isEqualTo(ipAddressAllocations.get(0).getIpAddressAllocation().getIpAddressLocation().getAvailabilityZone());
}
Also used : SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector) Map(java.util.Map) Test(org.junit.Test)

Example 32 with BatchJobExt

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

the class DefaultPodAffinityFactoryTest method testResourcePoolAffinity.

@Test
public void testResourcePoolAffinity() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    job = job.toBuilder().withJobDescriptor(JobFunctions.appendJobDescriptorAttributes(job.getJobDescriptor(), Collections.singletonMap(JobAttributes.JOB_PARAMETER_RESOURCE_POOLS, "elastic"))).build();
    Pair<V1Affinity, Map<String, String>> affinityWithAnnotations = factory.buildV1Affinity(job, JobGenerator.oneBatchTask());
    V1NodeSelector nodeSelector = affinityWithAnnotations.getLeft().getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution();
    assertThat(nodeSelector.getNodeSelectorTerms()).hasSize(1);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getKey()).isEqualTo(KubeConstants.NODE_LABEL_RESOURCE_POOL);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getValues().get(0)).isEqualTo("elastic");
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector) Map(java.util.Map) Test(org.junit.Test)

Example 33 with BatchJobExt

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

the class ResourceConsumptionEvaluatorTest method batchJobWithMultipleTasks.

@SuppressWarnings("unchecked")
@Test
public void batchJobWithMultipleTasks() {
    when(applicationSlaManagementService.getApplicationSLAs()).thenReturn(asList(ConsumptionModelGenerator.DEFAULT_SLA, ConsumptionModelGenerator.CRITICAL_SLA_1, ConsumptionModelGenerator.NOT_USED_SLA));
    // Job with defined capacity group SLA
    Job<BatchJobExt> goodCapacityJob = newBatchJob("goodCapacityJob", jd -> jd.toBuilder().withExtensions(jd.getExtensions().toBuilder().withSize(2).build()).withCapacityGroup(ConsumptionModelGenerator.CRITICAL_SLA_1.getAppName()).build()).getLeft();
    List<Task> goodCapacityTasks = jobComponentStub.getJobOperations().getTasks(goodCapacityJob.getId());
    // Job without appName defined
    Job<BatchJobExt> noAppNameJob = newBatchJob("badCapacityJob", jd -> jd.toBuilder().withApplicationName("").withExtensions(jd.getExtensions().toBuilder().withSize(2).build()).withCapacityGroup(ConsumptionModelGenerator.DEFAULT_SLA.getAppName()).build()).getLeft();
    List<Task> noAppNameTasks = jobComponentStub.getJobOperations().getTasks(noAppNameJob.getId());
    // Job with capacity group for which SLA is not defined
    Job<BatchJobExt> badCapacityJob = newBatchJob("badCapacityJob", jd -> jd.toBuilder().withExtensions(jd.getExtensions().toBuilder().withSize(2).build()).withCapacityGroup("missingCapacityGroup").build()).getLeft();
    List<Task> badCapacityTasks = jobComponentStub.getJobOperations().getTasks(badCapacityJob.getId());
    // Evaluate
    ResourceConsumptionEvaluator evaluator = new ResourceConsumptionEvaluator(applicationSlaManagementService, v3JobOperations);
    Set<String> undefined = evaluator.getUndefinedCapacityGroups();
    assertThat(undefined).contains("missingCapacityGroup");
    CompositeResourceConsumption systemConsumption = evaluator.getSystemConsumption();
    Map<String, ResourceConsumption> tierConsumptions = systemConsumption.getContributors();
    assertThat(tierConsumptions).containsKeys(Tier.Critical.name(), Tier.Flex.name());
    // Critical capacity group
    CompositeResourceConsumption criticalConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Critical.name(), ConsumptionModelGenerator.CRITICAL_SLA_1.getAppName()).get();
    assertThat(criticalConsumption.getCurrentConsumption()).isEqualTo(expectedCurrentConsumptionForBatchJob(goodCapacityJob, goodCapacityTasks));
    assertThat(criticalConsumption.getMaxConsumption()).isEqualTo(expectedMaxConsumptionForBatchJob(goodCapacityJob));
    assertThat(criticalConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.CRITICAL_SLA_1));
    assertThat(criticalConsumption.isAboveLimit()).isTrue();
    // Default capacity group
    CompositeResourceConsumption defaultConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Flex.name(), ConsumptionModelGenerator.DEFAULT_SLA.getAppName()).get();
    assertThat(defaultConsumption.getCurrentConsumption()).isEqualTo(ResourceDimensions.add(expectedCurrentConsumptionForBatchJob(noAppNameJob, noAppNameTasks), expectedCurrentConsumptionForBatchJob(badCapacityJob, badCapacityTasks)));
    assertThat(defaultConsumption.getMaxConsumption()).isEqualTo(ResourceDimensions.add(expectedMaxConsumptionForBatchJob(noAppNameJob), expectedMaxConsumptionForBatchJob(badCapacityJob)));
    assertThat(defaultConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.DEFAULT_SLA));
    assertThat(defaultConsumption.isAboveLimit()).isFalse();
    // Not used capacity group
    CompositeResourceConsumption notUsedConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Critical.name(), ConsumptionModelGenerator.NOT_USED_SLA.getAppName()).get();
    assertThat(notUsedConsumption.getCurrentConsumption()).isEqualTo(ResourceDimension.empty());
    assertThat(notUsedConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.NOT_USED_SLA));
    assertThat(notUsedConsumption.isAboveLimit()).isFalse();
}
Also used : JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) ApplicationSlaManagementService(com.netflix.titus.master.service.management.ApplicationSlaManagementService) Task(com.netflix.titus.api.jobmanager.model.job.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResourceDimensions(com.netflix.titus.master.model.ResourceDimensions) Function(java.util.function.Function) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) Pair(com.netflix.titus.common.util.tuple.Pair) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ResourceDimension(com.netflix.titus.api.model.ResourceDimension) ResourceConsumptionEvaluator.perTaskResourceDimension(com.netflix.titus.master.service.management.internal.ResourceConsumptionEvaluator.perTaskResourceDimension) Before(org.junit.Before) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Tier(com.netflix.titus.api.model.Tier) ResourceConsumptions.findConsumption(com.netflix.titus.master.service.management.ResourceConsumptions.findConsumption) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources) JobComponentStub(com.netflix.titus.testkit.model.job.JobComponentStub) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) Mockito.mock(org.mockito.Mockito.mock) Task(com.netflix.titus.api.jobmanager.model.job.Task) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 34 with BatchJobExt

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

the class RelocationUtilTest method buildTasksFromNodesAndJobsFilter.

@Test
public void buildTasksFromNodesAndJobsFilter() {
    String node1 = "node1";
    String node2 = "node2";
    String node3 = "node3";
    Job<BatchJobExt> job1 = JobGenerator.oneBatchJob();
    Job<BatchJobExt> job2 = JobGenerator.oneBatchJob();
    Job<BatchJobExt> job3 = JobGenerator.oneBatchJob();
    BatchJobTask task1 = JobGenerator.batchTasks(job1).getValue().toBuilder().addToTaskContext(TaskAttributes.TASK_ATTRIBUTES_AGENT_INSTANCE_ID, node1).build();
    BatchJobTask task2 = JobGenerator.batchTasks(job2).getValue().toBuilder().addToTaskContext(TaskAttributes.TASK_ATTRIBUTES_AGENT_INSTANCE_ID, node2).build();
    BatchJobTask task3 = JobGenerator.batchTasks(job3).getValue().toBuilder().addToTaskContext(TaskAttributes.TASK_ATTRIBUTES_AGENT_INSTANCE_ID, node3).build();
    ReadOnlyJobOperations jobOperations = mock(ReadOnlyJobOperations.class);
    when(jobOperations.getJobs()).thenReturn(Arrays.asList(job1, job2, job3));
    when(jobOperations.getTasks(job1.getId())).thenReturn(Collections.singletonList(task1));
    when(jobOperations.getTasks(job2.getId())).thenReturn(Collections.singletonList(task2));
    when(jobOperations.getTasks(job3.getId())).thenReturn(Collections.singletonList(task3));
    Map<String, TitusNode> nodes = new HashMap<>(3);
    nodes.put(node1, buildNode(node1));
    nodes.put(node2, buildNode(node2));
    nodes.put(node3, buildNode(node3));
    Set<String> jobIds = new HashSet<>(2);
    jobIds.addAll(Arrays.asList(job1.getId(), job3.getId()));
    List<String> taskIdsOnBadNodes = RelocationUtil.buildTasksFromNodesAndJobsFilter(nodes, jobIds, jobOperations);
    assertThat(taskIdsOnBadNodes.size()).isEqualTo(2);
}
Also used : ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with BatchJobExt

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

the class TaskRelocationIntegrationTest method createAndPlaceOneTaskJob.

private Task createAndPlaceOneTaskJob(String instanceGroup) {
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(RELOCATION_TIME_MS));
    relocationConnectorStubs.addJob(job);
    Task task = jobOperations.getTasks().get(0);
    relocationConnectorStubs.place(instanceGroup, task);
    return task;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)

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