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