Search in sources :

Example 1 with Cell

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

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

the class AggregatingLoadBalancerServiceTest 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 AnonymousCallMetadataResolver anonymousCallMetadataResolver = new AnonymousCallMetadataResolver();
    final AggregatingCellClient aggregatingCellClient = new AggregatingCellClient(connector);
    service = new AggregatingLoadbalancerService(connector, anonymousCallMetadataResolver, grpcConfiguration, aggregatingCellClient, new AggregatingJobManagementServiceHelper(aggregatingCellClient, 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)

Example 3 with Cell

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

the class DefaultCellConnectorTest method buildChannelsTest.

@Test
public void buildChannelsTest() {
    TitusFederationConfiguration titusFederationConfiguration = mock(TitusFederationConfiguration.class);
    when(titusFederationConfiguration.getCells()).thenReturn("cell1=hostName1:7001;cell2=hostName2:7002");
    DefaultCellInfoResolver cellInfoResolver = new DefaultCellInfoResolver(titusFederationConfiguration);
    DefaultCellConnector defaultCellConnector = new DefaultCellConnector(cellInfoResolver);
    Map<Cell, ManagedChannel> channels = defaultCellConnector.getChannels();
    assertThat(channels).isNotEmpty();
    assertThat(channels.size()).isEqualTo(2);
    Optional<ManagedChannel> hostOneChannel = defaultCellConnector.getChannelForCell(new Cell("cell1", "hostName1:7001"));
    Optional<ManagedChannel> hostTwoChannel = defaultCellConnector.getChannelForCell(new Cell("cell2", "hostName2:7002"));
    assertThat(hostOneChannel.isPresent()).isTrue();
    assertThat(hostTwoChannel.isPresent()).isTrue();
    Optional<ManagedChannel> hostThreeChannel = defaultCellConnector.getChannelForCell(new Cell("cell3", "hostName3:7002"));
    assertThat(hostThreeChannel.isPresent()).isFalse();
}
Also used : TitusFederationConfiguration(com.netflix.titus.federation.startup.TitusFederationConfiguration) ManagedChannel(io.grpc.ManagedChannel) Cell(com.netflix.titus.api.federation.model.Cell) Test(org.junit.Test)

Example 4 with Cell

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

the class FallbackJobServiceGatewayTest method setUp.

@Before
public void setUp() {
    stackName = UUID.randomUUID().toString();
    GrpcConfiguration grpcConfiguration = mock(GrpcConfiguration.class);
    when(grpcConfiguration.getRequestTimeoutMs()).thenReturn(GRPC_REQUEST_TIMEOUT_MS);
    when(grpcConfiguration.getPrimaryFallbackTimeoutMs()).thenReturn(GRPC_PRIMARY_FALLBACK_TIMEOUT_MS);
    when(fedConfig.getStack()).thenReturn(stackName);
    when(fedConfig.getCells()).thenReturn("one=1;two=2");
    when(fedConfig.getRoutingRules()).thenReturn("one=(app1.*|app2.*);two=(app3.*)");
    CellInfoResolver cellInfoResolver = new DefaultCellInfoResolver(fedConfig);
    ApplicationCellRouter cellRouter = new ApplicationCellRouter(cellInfoResolver, fedConfig);
    cells = cellInfoResolver.resolve();
    cellToServiceMap = ImmutableMap.of(cells.get(0), cellOne, cells.get(1), cellTwo);
    RemoteFederationConnector fedConnector = mock(RemoteFederationConnector.class);
    when(fedConnector.getChannel()).thenReturn(remoteFederationRule.getChannel());
    CellConnector cellConnector = mock(CellConnector.class);
    when(cellConnector.getChannels()).thenReturn(cellToServiceMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, cellPairEntry -> cellPairEntry.getValue().getChannel())));
    when(cellConnector.getChannelForCell(any(Cell.class))).thenAnswer(invocation -> Optional.ofNullable(cellToServiceMap.get(invocation.<Cell>getArgument(0))).map(GrpcServerRule::getChannel));
    final AggregatingCellClient aggregatingCellClient = new AggregatingCellClient(cellConnector);
    aggregatingJobServiceGateway = new AggregatingJobServiceGateway(grpcConfiguration, fedConfig, cellConnector, cellRouter, aggregatingCellClient, new AggregatingJobManagementServiceHelper(aggregatingCellClient, grpcConfiguration), titusRuntime);
    remoteJobServiceGateway = new RemoteJobServiceGateway(fedConfig, fedConnector, cellRouter, grpcConfiguration);
    fallbackJobServiceGateway = new FallbackJobServiceGateway(titusRuntime, fedConfig, remoteJobServiceGateway, aggregatingJobServiceGateway);
    clock = Clocks.test();
    dataGenerator = new ServiceDataGenerator(clock, TASKS_IN_GENERATED_JOBS);
}
Also used : ApplicationCellRouter(com.netflix.titus.federation.service.router.ApplicationCellRouter) Cell(com.netflix.titus.api.federation.model.Cell) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) Before(org.junit.Before)

Example 5 with Cell

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

the class CellInfoUtilTest method duplicatedRoutingRulesAreIgnored.

@Test
public void duplicatedRoutingRulesAreIgnored() {
    Cell cell = new Cell("cell1", "1");
    String cellsSpec = "cell1=(app1.*);cell1=(app2.*)";
    Map<Cell, String> routingRules = CellInfoUtil.extractCellRoutingFromCellSpecification(Collections.singletonList(cell), cellsSpec);
    assertThat(routingRules).isNotNull();
    assertThat(routingRules).hasSize(1);
    // second value got ignored
    assertThat(routingRules.get(cell)).isEqualTo("(app1.*)");
}
Also used : Cell(com.netflix.titus.api.federation.model.Cell) Test(org.junit.Test)

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