Search in sources :

Example 11 with ServiceJobExt

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

the class JobIpAllocationsTest method testWaitingTaskContext.

/**
 * Tests a job waiting for an in use IP allocation has updated task context fields.
 */
@Test(timeout = 30_000)
// TODO Read static IP allocation status from pod message field, and add it to the task context.
@Ignore
public void testWaitingTaskContext() throws Exception {
    JobDescriptor<ServiceJobExt> firstIpJobDescriptor = ONE_TASK_SERVICE_JOB;
    JobDescriptor<ServiceJobExt> secondIpJobDescriptor = firstIpJobDescriptor.but(j -> j.getJobGroupInfo().toBuilder().withSequence("v001"));
    // Schedule the first task and ensure it's in the correct zone with the correct task context
    jobsScenarioBuilder.schedule(firstIpJobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.startTasksInNewJob()).allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectTaskContext(TaskAttributes.TASK_ATTRIBUTES_IP_ALLOCATION_ID, getIpAllocationIdFromJob(0, firstIpJobDescriptor))).allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectZoneId(getZoneFromJobIpAllocation(0, firstIpJobDescriptor))));
    String firstJobId = jobsScenarioBuilder.takeJob(0).getJobId();
    // Schedule the second task and ensure it's blocked on the first task
    jobsScenarioBuilder.schedule(secondIpJobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.jobAccepted()).expectAllTasksCreated().allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectStateUpdates(TaskStatus.TaskState.Accepted)));
    String secondJobId = jobsScenarioBuilder.takeJob(1).getJobId();
    // Query the gRPC endpoint and ensure the first task does not have a waiting task context field.
    TaskQueryResult firstTaskQueryResult = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(100).build()).putFilteringCriteria("jobIds", firstJobId).build());
    assertThat(firstTaskQueryResult.getItemsCount()).isEqualTo(1);
    firstTaskQueryResult.getItemsList().forEach(task -> {
        assertThat(task.getTaskContextMap()).doesNotContainKeys(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION);
    });
    String firstTaskId = firstTaskQueryResult.getItems(0).getId();
    // Query the gRPC endpoint and ensure the second task has a waiting task context field.
    TaskQueryResult secondTaskQueryResult = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(100).build()).putFilteringCriteria("jobIds", secondJobId).build());
    assertThat(secondTaskQueryResult.getItemsCount()).isEqualTo(1);
    secondTaskQueryResult.getItemsList().forEach(task -> {
        assertThat(task.getTaskContextMap()).contains(new AbstractMap.SimpleImmutableEntry<>(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION, firstTaskId));
    });
    // Observe the second job and ensure the streamed task has a waiting task context field.
    boolean verified = false;
    Iterator<JobChangeNotification> it = client.observeJob(JobId.newBuilder().setId(secondJobId).build());
    while (it.hasNext()) {
        JobChangeNotification jobChangeNotification = it.next();
        if (jobChangeNotification.hasTaskUpdate()) {
            Map<String, String> taskContext = jobChangeNotification.getTaskUpdate().getTask().getTaskContextMap();
            assertThat(taskContext).contains(new AbstractMap.SimpleImmutableEntry<>(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION, firstTaskId));
            verified = true;
        } else if (jobChangeNotification.hasSnapshotEnd()) {
            break;
        }
    }
    assertThat(verified).isTrue();
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) JobDescriptorGenerator.serviceJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.serviceJobDescriptors) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) Function(java.util.function.Function) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) GrpcJobManagementModelConverters.toGrpcJobDescriptor(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcJobDescriptor) JobTestUtils.submitBadJob(com.netflix.titus.master.integration.v3.job.JobTestUtils.submitBadJob) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Iterator(java.util.Iterator) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Page(com.netflix.titus.grpc.protogen.Page) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) AbstractMap(java.util.AbstractMap) List(java.util.List) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) Ignore(org.junit.Ignore) JobIpAllocationGenerator(com.netflix.titus.testkit.model.job.JobIpAllocationGenerator) EmbeddedTitusCells.basicKubeCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells.basicKubeCell) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) AbstractMap(java.util.AbstractMap) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Ignore(org.junit.Ignore) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 12 with ServiceJobExt

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

the class DefaultAppScaleManagerTest method mockV3Operations.

private V3JobOperations mockV3Operations(String jobIdOne, String jobIdTwo) {
    V3JobOperations v3JobOperations = mock(V3JobOperations.class);
    // FIXME Use JobGenerator instead of mocking.
    Job jobOne = mock(Job.class);
    when(jobOne.getId()).thenReturn(jobIdOne);
    JobDescriptor jobDescriptorOne = mock(JobDescriptor.class);
    ServiceJobExt serviceJobExtOne = mock(ServiceJobExt.class);
    JobGroupInfo jobGroupInfoOne = buildMockJobGroupInfo(jobIdOne);
    Capacity capacityOne = mock(Capacity.class);
    when(capacityOne.getMax()).thenReturn(10);
    when(capacityOne.getMin()).thenReturn(1);
    when(serviceJobExtOne.getCapacity()).thenReturn(capacityOne);
    when(jobDescriptorOne.getExtensions()).thenReturn(serviceJobExtOne);
    when(jobOne.getJobDescriptor()).thenReturn(jobDescriptorOne);
    when(jobDescriptorOne.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
    when(jobDescriptorOne.getApplicationName()).thenReturn("testApp1");
    Job jobTwo = mock(Job.class);
    when(jobTwo.getId()).thenReturn(jobIdTwo);
    JobDescriptor jobDescriptorTwo = mock(JobDescriptor.class);
    ServiceJobExt serviceJobExtTwo = mock(ServiceJobExt.class);
    Capacity capacityJobTwo = mock(Capacity.class);
    when(capacityJobTwo.getMin()).thenAnswer(new Answer<Integer>() {

        private int count = 0;

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            if (count++ < 2) {
                return 1;
            } else {
                return 5;
            }
        }
    });
    when(capacityJobTwo.getMax()).thenAnswer(new Answer<Integer>() {

        private int count = 0;

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            if (count++ < 2) {
                return 10;
            } else {
                return 15;
            }
        }
    });
    when(serviceJobExtTwo.getCapacity()).thenReturn(capacityJobTwo);
    when(jobDescriptorTwo.getExtensions()).thenReturn(serviceJobExtTwo);
    when(jobDescriptorTwo.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
    when(jobDescriptorTwo.getApplicationName()).thenReturn("testApp2");
    when(jobTwo.getJobDescriptor()).thenReturn(jobDescriptorTwo);
    when(jobTwo.getStatus()).thenReturn(JobModel.newJobStatus().withState(JobState.Accepted).build());
    when(v3JobOperations.getJob(jobIdOne)).thenReturn(Optional.of(jobOne));
    when(v3JobOperations.getJob(jobIdTwo)).thenReturn(Optional.of(jobTwo));
    JobManagerEvent<?> jobUpdateEvent = JobUpdateEvent.newJob(jobTwo, callMetadata);
    when(v3JobOperations.observeJobs()).thenAnswer(invocation -> Observable.from(asList(jobUpdateEvent)));
    return v3JobOperations;
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 13 with ServiceJobExt

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

the class DefaultAppScaleManagerTest method mockV3OperationsForJobs.

private V3JobOperations mockV3OperationsForJobs(List<String> jobIds) {
    V3JobOperations v3JobOperations = mock(V3JobOperations.class);
    for (String jobId : jobIds) {
        // FIXME Use JobGenerator instead of mocking.
        Job job = mock(Job.class);
        when(job.getId()).thenReturn(jobId);
        JobDescriptor jobDescriptorOne = mock(JobDescriptor.class);
        ServiceJobExt serviceJobExtOne = mock(ServiceJobExt.class);
        JobGroupInfo jobGroupInfoOne = buildMockJobGroupInfo(jobId);
        Capacity capacityOne = mock(Capacity.class);
        when(capacityOne.getMax()).thenReturn(10);
        when(capacityOne.getMin()).thenReturn(1);
        when(serviceJobExtOne.getCapacity()).thenReturn(capacityOne);
        when(jobDescriptorOne.getExtensions()).thenReturn(serviceJobExtOne);
        when(job.getJobDescriptor()).thenReturn(jobDescriptorOne);
        when(jobDescriptorOne.getJobGroupInfo()).thenReturn(jobGroupInfoOne);
        when(jobDescriptorOne.getApplicationName()).thenReturn("testApp");
        when(v3JobOperations.getJob(jobId)).thenReturn(Optional.of(job));
        JobManagerEvent<?> jobUpdateEvent = JobUpdateEvent.newJob(job, callMetadata);
        when(v3JobOperations.observeJobs()).thenAnswer(invocation -> Observable.from(asList(jobUpdateEvent)));
    }
    return v3JobOperations;
}
Also used : V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 14 with ServiceJobExt

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

the class JobScenarioBuilder method updateJobCapacity.

public JobScenarioBuilder updateJobCapacity(Capacity capacity) {
    logger.info("[{}] Changing job {} capacity to {}...", discoverActiveTest(), jobId, capacity);
    Stopwatch stopWatch = Stopwatch.createStarted();
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacity(JobCapacityUpdate.newBuilder().setJobId(jobId).setCapacity(toGrpcCapacity(capacity)).build(), responseObserver);
    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        return ext.getCapacity().equals(capacity);
    }, "Job capacity update did not complete in time");
    logger.info("[{}] Job {} scaled to new size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Stopwatch(com.google.common.base.Stopwatch)

Example 15 with ServiceJobExt

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

the class JobScenarioBuilder method updateJobCapacityMin.

public JobScenarioBuilder updateJobCapacityMin(int min, int expectedMax, int expectedDesired) {
    logger.info("[{}] Changing job {} capacity min to {}...", discoverActiveTest(), jobId, min);
    Stopwatch stopWatch = Stopwatch.createStarted();
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMin(UInt32Value.newBuilder().setValue(min).build()).build()).build(), responseObserver);
    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        Capacity capacity = ext.getCapacity();
        return capacity.getMin() == min && capacity.getMax() == expectedMax && capacity.getDesired() == expectedDesired;
    }, "Job capacity update did not complete in time");
    logger.info("[{}] Job {} scaled to new min size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GrpcJobManagementModelConverters.toGrpcCapacity(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcCapacity) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Stopwatch(com.google.common.base.Stopwatch)

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