Search in sources :

Example 6 with Cell

use of com.netflix.titus.api.federation.model.Cell 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 7 with Cell

use of com.netflix.titus.api.federation.model.Cell in project titus-control-plane by Netflix.

the class ApplicationCellRouterTest method rulesWithNonConfiguredCellsAreIgnored.

@Test
public void rulesWithNonConfiguredCellsAreIgnored() {
    TitusFederationConfiguration titusFederationConfiguration = mock(TitusFederationConfiguration.class);
    when(titusFederationConfiguration.getCells()).thenReturn("cell1=hostName1:7001;cell2=hostName2:7002");
    when(titusFederationConfiguration.getRoutingRules()).thenReturn("cell1=(app1.*|app2.*);cell2=(app3.*);cell3=(app4.*)");
    CellInfoResolver cellInfoResolver = new DefaultCellInfoResolver(titusFederationConfiguration);
    ApplicationCellRouter cellRouter = new ApplicationCellRouter(cellInfoResolver, titusFederationConfiguration);
    Cell cell = cellRouter.routeKey(APP_4).get();
    // no rules default to first
    assertThat(cell.getName()).isEqualTo("cell1");
}
Also used : TitusFederationConfiguration(com.netflix.titus.federation.startup.TitusFederationConfiguration) CellInfoResolver(com.netflix.titus.federation.service.CellInfoResolver) DefaultCellInfoResolver(com.netflix.titus.federation.service.DefaultCellInfoResolver) DefaultCellInfoResolver(com.netflix.titus.federation.service.DefaultCellInfoResolver) Cell(com.netflix.titus.api.federation.model.Cell) Test(org.junit.Test)

Example 8 with Cell

use of com.netflix.titus.api.federation.model.Cell in project titus-control-plane by Netflix.

the class AggregatingJobServiceGateway method createJob.

@Override
public Observable<String> createJob(JobDescriptor jobDescriptor, CallMetadata callMetadata) {
    Cell cell = router.routeKey(jobDescriptor).orElse(null);
    if (cell == null) {
        // This should never happen in a correctly setup system.
        return Observable.error(new IllegalStateException("Internal system error. Routing rule not found"));
    }
    logger.debug("Routing JobDescriptor {} to Cell {}", jobDescriptor, cell);
    Optional<JobManagementServiceStub> optionalClient = CellConnectorUtil.toStub(cell, cellConnector, JobManagementServiceGrpc::newStub);
    if (!optionalClient.isPresent()) {
        return Observable.error(TitusServiceException.cellNotFound(cell.getName()));
    }
    JobManagementServiceStub client = optionalClient.get();
    JobDescriptor.Builder jobDescriptorBuilder = addStackName(jobDescriptor.toBuilder());
    jobDescriptorBuilder = removeFederationAttributes(jobDescriptorBuilder);
    jobDescriptorBuilder = addRoutingCell(jobDescriptorBuilder, cell);
    JobDescriptor jd = jobDescriptorBuilder.build();
    return createRequestObservable(emitter -> {
        StreamObserver<JobId> streamObserver = GrpcUtil.createClientResponseObserver(emitter, jobId -> emitter.onNext(jobId.getId()), emitter::onError, emitter::onCompleted);
        wrap(client, callMetadata).createJob(jd, streamObserver);
    }, grpcConfiguration.getRequestTimeoutMs());
}
Also used : JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Cell(com.netflix.titus.api.federation.model.Cell) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) JobId(com.netflix.titus.grpc.protogen.JobId) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)

Example 9 with Cell

use of com.netflix.titus.api.federation.model.Cell in project titus-control-plane by Netflix.

the class AggregatingAutoScalingTestBase method setUp.

@Before
public void setUp() {
    CellConnector connector = mock(CellConnector.class);
    Map<Cell, ManagedChannel> cellMap = new HashMap<>();
    cellMap.put(new Cell("one", "1"), cellOne.getChannel());
    cellMap.put(new Cell("two", "2"), cellTwo.getChannel());
    when(connector.getChannels()).thenReturn(cellMap);
    when(connector.getChannelForCell(any())).then(invocation -> Optional.ofNullable(cellMap.get(invocation.getArgument(0))));
    GrpcConfiguration grpcConfiguration = mock(GrpcConfiguration.class);
    when(grpcConfiguration.getRequestTimeoutMs()).thenReturn(1000L);
    final AggregatingCellClient aggregatingCellClient = new AggregatingCellClient(connector);
    service = new AggregatingAutoScalingService(connector, grpcConfiguration, new AggregatingJobManagementServiceHelper(aggregatingCellClient, grpcConfiguration), aggregatingCellClient);
}
Also used : HashMap(java.util.HashMap) ManagedChannel(io.grpc.ManagedChannel) Cell(com.netflix.titus.api.federation.model.Cell) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) Before(org.junit.Before)

Example 10 with Cell

use of com.netflix.titus.api.federation.model.Cell in project titus-control-plane by Netflix.

the class AggregatingHealthServiceTest method setup.

@Before
public void setup() {
    Map<Cell, ManagedChannel> cellMap = new HashMap<>();
    cellMap.put(new Cell("one", "1"), cellOne.getChannel());
    cellMap.put(new Cell("two", "2"), cellTwo.getChannel());
    when(connector.getChannels()).thenReturn(cellMap);
    when(connector.getChannelForCell(any())).then(invocation -> Optional.ofNullable(cellMap.get(invocation.getArgument(0))));
    GrpcConfiguration grpcConfiguration = mock(GrpcConfiguration.class);
    when(grpcConfiguration.getRequestTimeoutMs()).thenReturn(1000L);
    AnonymousCallMetadataResolver anonymousCallMetadataResolver = new AnonymousCallMetadataResolver();
    AggregatingCellClient aggregatingCellClient = new AggregatingCellClient(connector);
    service = new AggregatingHealthService(aggregatingCellClient, anonymousCallMetadataResolver, grpcConfiguration);
}
Also used : HashMap(java.util.HashMap) ManagedChannel(io.grpc.ManagedChannel) Cell(com.netflix.titus.api.federation.model.Cell) AnonymousCallMetadataResolver(com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) Before(org.junit.Before)

Aggregations

Cell (com.netflix.titus.api.federation.model.Cell)16 Test (org.junit.Test)7 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)6 Before (org.junit.Before)6 TitusFederationConfiguration (com.netflix.titus.federation.startup.TitusFederationConfiguration)4 JobDescriptor (com.netflix.titus.grpc.protogen.JobDescriptor)4 ManagedChannel (io.grpc.ManagedChannel)4 ApplicationCellRouter (com.netflix.titus.federation.service.router.ApplicationCellRouter)3 JobManagementServiceStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)3 AnonymousCallMetadataResolver (com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver)3 HashMap (java.util.HashMap)3 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)2 CellInfoResolver (com.netflix.titus.federation.service.CellInfoResolver)2 DefaultCellInfoResolver (com.netflix.titus.federation.service.DefaultCellInfoResolver)2 JobId (com.netflix.titus.grpc.protogen.JobId)2 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)2 CallbackCountDownLatch (com.netflix.titus.common.util.concurrency.CallbackCountDownLatch)1 EmitterWithMultipleSubscriptions (com.netflix.titus.common.util.rx.EmitterWithMultipleSubscriptions)1 HealthCheckResponse (com.netflix.titus.grpc.protogen.HealthCheckResponse)1 Job (com.netflix.titus.grpc.protogen.Job)1