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();
});
}
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));
}
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();
}
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);
}
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.*)");
}
Aggregations