Search in sources :

Example 41 with ServiceJobExt

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

the class DefaultPodAffinityFactoryTest method relocationBinPacking.

@Test
public void relocationBinPacking() {
    Job<ServiceJobExt> job = JobGenerator.oneServiceJob();
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().but(jd -> jd.getDisruptionBudget().toBuilder().withDisruptionBudgetPolicy(SelfManagedDisruptionBudgetPolicy.newBuilder().build()))).build();
    ServiceJobTask task = JobGenerator.oneServiceTask();
    V1Affinity affinity = factory.buildV1Affinity(job, task).getLeft();
    List<V1WeightedPodAffinityTerm> podAffinityTerms = affinity.getPodAffinity().getPreferredDuringSchedulingIgnoredDuringExecution();
    assertThat(podAffinityTerms).hasSize(1);
    V1PodAffinityTerm podAffinityTerm = podAffinityTerms.get(0).getPodAffinityTerm();
    assertThat(podAffinityTerm.getTopologyKey()).isEqualTo(KubeConstants.NODE_LABEL_MACHINE_ID);
    assertThat(podAffinityTerm.getLabelSelector().getMatchExpressions()).hasSize(1);
    V1LabelSelectorRequirement affinityRequirement = podAffinityTerm.getLabelSelector().getMatchExpressions().get(0);
    assertThat(affinityRequirement.getKey()).isEqualTo(KubeConstants.POD_LABEL_RELOCATION_BINPACK);
    assertThat(affinityRequirement.getOperator()).isEqualTo(KubeConstants.SELECTOR_OPERATOR_EXISTS);
    List<V1WeightedPodAffinityTerm> antiAffinityTerms = affinity.getPodAntiAffinity().getPreferredDuringSchedulingIgnoredDuringExecution();
    assertThat(antiAffinityTerms).hasSize(1);
    V1PodAffinityTerm antiAffinityTerm = antiAffinityTerms.get(0).getPodAffinityTerm();
    assertThat(antiAffinityTerm.getTopologyKey()).isEqualTo(KubeConstants.NODE_LABEL_MACHINE_ID);
    assertThat(antiAffinityTerm.getLabelSelector().getMatchExpressions()).hasSize(1);
    V1LabelSelectorRequirement antiAffinityRequirement = antiAffinityTerm.getLabelSelector().getMatchExpressions().get(0);
    assertThat(antiAffinityRequirement.getKey()).isEqualTo(KubeConstants.POD_LABEL_RELOCATION_BINPACK);
    assertThat(antiAffinityRequirement.getOperator()).isEqualTo(KubeConstants.SELECTOR_OPERATOR_DOES_NOT_EXIST);
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) V1WeightedPodAffinityTerm(io.kubernetes.client.openapi.models.V1WeightedPodAffinityTerm) V1PodAffinityTerm(io.kubernetes.client.openapi.models.V1PodAffinityTerm) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KubePodConfiguration(com.netflix.titus.master.kubernetes.pod.KubePodConfiguration) DefaultPodAffinityFactory(com.netflix.titus.master.kubernetes.pod.affinity.DefaultPodAffinityFactory) EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) FeatureActivationConfiguration(com.netflix.titus.api.FeatureActivationConfiguration) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Pair(com.netflix.titus.common.util.tuple.Pair) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1LabelSelectorRequirement(io.kubernetes.client.openapi.models.V1LabelSelectorRequirement) V1NodeSelectorRequirement(io.kubernetes.client.openapi.models.V1NodeSelectorRequirement) Before(org.junit.Before) KubeConstants(com.netflix.titus.runtime.kubernetes.KubeConstants) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector) Job(com.netflix.titus.api.jobmanager.model.job.Job) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) SelfManagedDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.SelfManagedDisruptionBudgetPolicy) JobGenerator(com.netflix.titus.testkit.model.job.JobGenerator) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ExplicitJobPodResourcePoolResolver(com.netflix.titus.master.kubernetes.pod.resourcepool.ExplicitJobPodResourcePoolResolver) Mockito(org.mockito.Mockito) List(java.util.List) JobIpAllocationGenerator(com.netflix.titus.testkit.model.job.JobIpAllocationGenerator) Container(com.netflix.titus.api.jobmanager.model.job.Container) JobConstraints(com.netflix.titus.api.jobmanager.JobConstraints) Collections(java.util.Collections) JobAttributes(com.netflix.titus.api.jobmanager.JobAttributes) JobEbsVolumeGenerator(com.netflix.titus.testkit.model.job.JobEbsVolumeGenerator) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) V1LabelSelectorRequirement(io.kubernetes.client.openapi.models.V1LabelSelectorRequirement) V1PodAffinityTerm(io.kubernetes.client.openapi.models.V1PodAffinityTerm) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) V1WeightedPodAffinityTerm(io.kubernetes.client.openapi.models.V1WeightedPodAffinityTerm) Test(org.junit.Test)

Example 42 with ServiceJobExt

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

the class ArchivedTasksGcTest method createServiceJob.

private Job<ServiceJobExt> createServiceJob(int archivedTasksCount) {
    Job<ServiceJobExt> job = JobGenerator.serviceJobs(JobDescriptorGenerator.oneTaskServiceJobDescriptor()).getValue();
    jobStore.storeJob(job).get();
    for (int i = 0; i < archivedTasksCount; i++) {
        Task task = JobGenerator.serviceTasks(job).getValue().toBuilder().withId("task" + i).build();
        task = JobFunctions.changeTaskStatus(task, TaskStatus.newBuilder().withState(TaskState.Finished).build());
        jobStore.addArchivedTaskInternal(task);
    }
    when(jobOperations.getJobs()).thenReturn(new ArrayList<>(jobStore.getJobsInternal().values()));
    return job;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)

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