Search in sources :

Example 1 with JobDescriptor

use of com.netflix.titus.grpc.protogen.JobDescriptor in project titus-control-plane by Netflix.

the class AggregatingJobServiceGatewayTest method createJobRouteToCorrectStack.

@Test
public void createJobRouteToCorrectStack() {
    // Build service handlers for each cell
    cellToServiceMap.forEach((cell, grpcServerRule) -> grpcServerRule.getServiceRegistry().addService(new CellWithCachedJobsService(cell.getName())));
    // Expected assignments based on routing rules in setUp()
    Map<String, String> expectedAssignmentMap = ImmutableMap.of("app1", "one", "app2", "one", "app3", "two", "app4", "one");
    expectedAssignmentMap.forEach((appName, expectedCellName) -> {
        // Create the job and let it get routed
        JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName(appName).setCapacityGroup(appName + "CapGroup").build();
        String jobId = service.createJob(jobDescriptor, JobManagerConstants.UNDEFINED_CALL_METADATA).toBlocking().first();
        // Get a client to the test gRPC service for the cell that we expect got it
        // TODO(Andrew L): This can use findJob() instead once AggregatingService implements it
        Cell expectedCell = getCellWithName(expectedCellName).orElseThrow(() -> TitusServiceException.cellNotFound(expectedCellName));
        JobManagementServiceStub expectedCellClient = JobManagementServiceGrpc.newStub(cellToServiceMap.get(expectedCell).getChannel());
        // Check that the cell has it with the correct attribute
        TestStreamObserver<Job> findJobResponse = new TestStreamObserver<>();
        expectedCellClient.findJob(JobId.newBuilder().setId(jobId).build(), findJobResponse);
        assertThatCode(() -> {
            Job job = findJobResponse.takeNext(1, TimeUnit.SECONDS);
            assertThat(job.getJobDescriptor().getAttributesOrThrow(JOB_ATTRIBUTES_CELL).equals(expectedCellName));
        }).doesNotThrowAnyException();
    });
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Job(com.netflix.titus.grpc.protogen.Job) Cell(com.netflix.titus.api.federation.model.Cell) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) Test(org.junit.Test)

Example 2 with JobDescriptor

use of com.netflix.titus.grpc.protogen.JobDescriptor in project titus-control-plane by Netflix.

the class FallbackJobServiceGatewayTest method createJobWithoutFallbackOnTimeout.

@Test
public void createJobWithoutFallbackOnTimeout() {
    RemoteJobManagementService remoteJobManagementService = new RemoteJobManagementServiceWithTimeoutMethods();
    CellWithCachedJobsService cachedJobsService = new CellWithCachedJobsService(cells.get(0).getName());
    cellOne.getServiceRegistry().addService(cachedJobsService);
    remoteFederationRule.getServiceRegistry().addService(remoteJobManagementService);
    JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName("app1").build();
    // Prove fallback is NOT happening
    assertNoFallback(jobDescriptor, remoteJobManagementService, cachedJobsService);
    // Prove fallback is NOT happening and the Timeout error is returned
    when(fedConfig.isRemoteFederationEnabled()).thenReturn(true);
    Observable<String> createObservable = fallbackJobServiceGateway.createJob(jobDescriptor, JobManagerConstants.UNDEFINED_CALL_METADATA);
    try {
        createObservable.toBlocking().first();
        // We shouldn't reach here as we expect to raise a DEADLINE_EXCEEDED exception
        assertThat(false).isEqualTo(true);
    } catch (StatusRuntimeException e) {
        assertThat(remoteJobManagementService.createCount.get()).isEqualTo(1);
        assertThat(Status.fromThrowable(e).getCode()).isEqualTo(Status.Code.DEADLINE_EXCEEDED);
    }
}
Also used : JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 3 with JobDescriptor

use of com.netflix.titus.grpc.protogen.JobDescriptor in project titus-control-plane by Netflix.

the class FallbackJobServiceGatewayTest method createJobWithFallbackFromRemoteJobManagementService.

private void createJobWithFallbackFromRemoteJobManagementService(RemoteJobManagementService remoteJobManagementService) {
    CellWithCachedJobsService cachedJobsService = new CellWithCachedJobsService(cells.get(0).getName());
    cellOne.getServiceRegistry().addService(cachedJobsService);
    remoteFederationRule.getServiceRegistry().addService(remoteJobManagementService);
    JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName("app1").build();
    // Prove fallback is NOT happening
    assertNoFallback(jobDescriptor, remoteJobManagementService, cachedJobsService);
    // Prove fallback IS happening
    when(fedConfig.isRemoteFederationEnabled()).thenReturn(true);
    assertFallback(jobDescriptor, remoteJobManagementService, cachedJobsService);
}
Also used : JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor)

Example 4 with JobDescriptor

use of com.netflix.titus.grpc.protogen.JobDescriptor in project titus-control-plane by Netflix.

the class RemoteJobServiceGateway method createJob.

@Override
public Observable<String> createJob(JobDescriptor jobDescriptor, CallMetadata callMetadata) {
    // We want to know where the job would have been routed so remote federation can compare it to its own routing
    // decision.
    Cell cell = cellRouter.routeKey(jobDescriptor).orElse(unknownCell);
    String federatedJobId = UUID.randomUUID().toString();
    JobDescriptor jd = addAttributes(jobDescriptor.toBuilder(), federatedJobId, cell.getName()).build();
    return createRequestObservable(emitter -> {
        StreamObserver<JobId> streamObserver = GrpcUtil.createClientResponseObserver(emitter, jobId -> emitter.onNext(jobId.getId()), emitter::onError, emitter::onCompleted);
        wrap(remoteClient, callMetadata, grpcConfiguration.getRequestTimeoutMs()).createJob(jd, streamObserver);
    }, grpcConfiguration.getRequestTimeoutMs());
}
Also used : JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Cell(com.netflix.titus.api.federation.model.Cell) JobId(com.netflix.titus.grpc.protogen.JobId)

Example 5 with JobDescriptor

use of com.netflix.titus.grpc.protogen.JobDescriptor in project titus-control-plane by Netflix.

the class ApplicationCellRouterTest method jobCellAntiAffinity.

@Test
public void jobCellAntiAffinity() {
    JobDescriptor withCellAntiAffinity = APP_2.toBuilder().putAttributes(JobAttributes.JOB_PARAMETER_ATTRIBUTES_CELL_AVOID, "cell4, cell1").build();
    JobDescriptor allRejectedGoesToDefault = APP_2.toBuilder().putAttributes(JobAttributes.JOB_PARAMETER_ATTRIBUTES_CELL_AVOID, "cell1,cell2").build();
    TitusFederationConfiguration titusFederationConfiguration = mock(TitusFederationConfiguration.class);
    when(titusFederationConfiguration.getCells()).thenReturn("cell1=hostName1:7001;cell2=hostName2:7002");
    when(titusFederationConfiguration.getRoutingRules()).thenReturn("cell1=(app1.*|app2.*);cell2=(app3.*)");
    CellInfoResolver cellInfoResolver = new DefaultCellInfoResolver(titusFederationConfiguration);
    ApplicationCellRouter cellRouter = new ApplicationCellRouter(cellInfoResolver, titusFederationConfiguration);
    assertThat(cellRouter.routeKey(withCellAntiAffinity).get().getName()).isEqualTo("cell2");
    assertThat(cellRouter.routeKey(allRejectedGoesToDefault)).isEmpty();
}
Also used : TitusFederationConfiguration(com.netflix.titus.federation.startup.TitusFederationConfiguration) CellInfoResolver(com.netflix.titus.federation.service.CellInfoResolver) DefaultCellInfoResolver(com.netflix.titus.federation.service.DefaultCellInfoResolver) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) DefaultCellInfoResolver(com.netflix.titus.federation.service.DefaultCellInfoResolver) Test(org.junit.Test)

Aggregations

JobDescriptor (com.netflix.titus.grpc.protogen.JobDescriptor)13 Test (org.junit.Test)7 Cell (com.netflix.titus.api.federation.model.Cell)4 JobId (com.netflix.titus.grpc.protogen.JobId)4 CellInfoResolver (com.netflix.titus.federation.service.CellInfoResolver)2 DefaultCellInfoResolver (com.netflix.titus.federation.service.DefaultCellInfoResolver)2 TitusFederationConfiguration (com.netflix.titus.federation.startup.TitusFederationConfiguration)2 JobManagementServiceStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 File (java.io.File)2 JobConfiguration (com.netflix.titus.api.jobmanager.model.job.sanitizer.JobConfiguration)1 ResourceDimension (com.netflix.titus.api.model.ResourceDimension)1 Evaluators (com.netflix.titus.common.util.Evaluators)1 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)1 BatchJobSpec (com.netflix.titus.grpc.protogen.BatchJobSpec)1 Capacity (com.netflix.titus.grpc.protogen.Capacity)1 Constraints (com.netflix.titus.grpc.protogen.Constraints)1 ContainerResources (com.netflix.titus.grpc.protogen.ContainerResources)1 Image (com.netflix.titus.grpc.protogen.Image)1 Job (com.netflix.titus.grpc.protogen.Job)1