Search in sources :

Example 1 with TitusFederationConfiguration

use of com.netflix.titus.federation.startup.TitusFederationConfiguration 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 2 with TitusFederationConfiguration

use of com.netflix.titus.federation.startup.TitusFederationConfiguration 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)

Example 3 with TitusFederationConfiguration

use of com.netflix.titus.federation.startup.TitusFederationConfiguration in project titus-control-plane by Netflix.

the class ApplicationCellRouterTest method cellRoutingRulesFromConfig.

@Test
public void cellRoutingRulesFromConfig() {
    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(APP_3).get().getName()).isEqualTo("cell2");
    assertThat(cellRouter.routeKey(APP_2).get().getName()).isEqualTo("cell1");
    // if not rules, by default go to the first configured in titus.federation.cells
    assertThat(cellRouter.routeKey(OTHER).get().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) Test(org.junit.Test)

Example 4 with TitusFederationConfiguration

use of com.netflix.titus.federation.startup.TitusFederationConfiguration in project titus-control-plane by Netflix.

the class ApplicationCellRouterTest method invalidInitialRoutingPatternThrowsException.

@Test
public void invalidInitialRoutingPatternThrowsException() {
    TitusFederationConfiguration titusFederationConfiguration = mock(TitusFederationConfiguration.class);
    when(titusFederationConfiguration.getCells()).thenReturn("cell1=hostName1:7001;cell2=hostName2:7002");
    when(titusFederationConfiguration.getRoutingRules()).thenReturn("cell1=(app1.*|app2.*);cell2=#)(");
    CellInfoResolver cellInfoResolver = new DefaultCellInfoResolver(titusFederationConfiguration);
    assertThatThrownBy(() -> new ApplicationCellRouter(cellInfoResolver, titusFederationConfiguration)).isInstanceOf(PatternSyntaxException.class);
}
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) Test(org.junit.Test)

Example 5 with TitusFederationConfiguration

use of com.netflix.titus.federation.startup.TitusFederationConfiguration in project titus-control-plane by Netflix.

the class ApplicationCellRouterTest method rulesCanBeChangedDynamically.

@Test
public void rulesCanBeChangedDynamically() {
    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(APP_3).get().getName()).isEqualTo("cell2");
    assertThat(cellRouter.routeKey(APP_2).get().getName()).isEqualTo("cell1");
    // if not rules, by default go to the first configured in titus.federation.cells
    assertThat(cellRouter.routeKey(OTHER).get().getName()).isEqualTo("cell1");
    // flip rules
    reset(titusFederationConfiguration);
    when(titusFederationConfiguration.getCells()).thenReturn("cell1=hostName1:7001;cell2=hostName2:7002");
    when(titusFederationConfiguration.getRoutingRules()).thenReturn("cell2=(app1.*|app2.*);cell1=(app3.*)");
    assertThat(cellRouter.routeKey(APP_3).get().getName()).isEqualTo("cell1");
    assertThat(cellRouter.routeKey(APP_2).get().getName()).isEqualTo("cell2");
    // if not rules, by default go to the first configured in titus.federation.cells
    assertThat(cellRouter.routeKey(OTHER).get().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) Test(org.junit.Test)

Aggregations

TitusFederationConfiguration (com.netflix.titus.federation.startup.TitusFederationConfiguration)10 Test (org.junit.Test)9 CellInfoResolver (com.netflix.titus.federation.service.CellInfoResolver)7 DefaultCellInfoResolver (com.netflix.titus.federation.service.DefaultCellInfoResolver)7 Cell (com.netflix.titus.api.federation.model.Cell)4 JobDescriptor (com.netflix.titus.grpc.protogen.JobDescriptor)2 ApplicationCellRouter (com.netflix.titus.federation.service.router.ApplicationCellRouter)1 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)1 AnonymousCallMetadataResolver (com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver)1 ManagedChannel (io.grpc.ManagedChannel)1 Before (org.junit.Before)1