Search in sources :

Example 1 with AddLoadBalancerRequest

use of com.netflix.titus.grpc.protogen.AddLoadBalancerRequest in project titus-control-plane by Netflix.

the class AggregatingLoadbalancerService method addLoadBalancer.

@Override
public Completable addLoadBalancer(AddLoadBalancerRequest request, CallMetadata callMetadata) {
    JobId jobId = JobId.newBuilder().setId(request.getJobId()).build();
    final Observable<Empty> responseObservable = jobManagementServiceHelper.findJobInAllCells(jobId.getId(), callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, responseObserver) -> client.addLoadBalancer(request, responseObserver), callMetadata));
    return responseObservable.toCompletable();
}
Also used : Completable(rx.Completable) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) GetAllLoadBalancersRequest(com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest) GrpcJobQueryModelConverters.toPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPagination) AddLoadBalancerRequest(com.netflix.titus.grpc.protogen.AddLoadBalancerRequest) GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) StringExt(com.netflix.titus.common.util.StringExt) PageAggregationUtil.takeCombinedPage(com.netflix.titus.federation.service.PageAggregationUtil.takeCombinedPage) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) Empty(com.google.protobuf.Empty) CallMetadataResolver(com.netflix.titus.runtime.endpoint.metadata.CallMetadataResolver) StreamObserver(io.grpc.stub.StreamObserver) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) Pair(com.netflix.titus.common.util.tuple.Pair) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) PageAggregationUtil.combinePagination(com.netflix.titus.federation.service.PageAggregationUtil.combinePagination) BiConsumer(java.util.function.BiConsumer) GrpcModelConverters(com.netflix.titus.runtime.loadbalancer.GrpcModelConverters) RemoveLoadBalancerRequest(com.netflix.titus.grpc.protogen.RemoveLoadBalancerRequest) LoadBalancerCursors(com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Cell(com.netflix.titus.api.federation.model.Cell) Pagination(com.netflix.titus.grpc.protogen.Pagination) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Collectors(java.util.stream.Collectors) LoadBalancerServiceStub(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc.LoadBalancerServiceStub) List(java.util.List) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) LoadBalancerServiceGrpc(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc) GrpcJobQueryModelConverters.emptyGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.emptyGrpcPagination) AbstractStub(io.grpc.stub.AbstractStub) LoadBalancerService(com.netflix.titus.runtime.service.LoadBalancerService) JobId(com.netflix.titus.grpc.protogen.JobId) Empty(com.google.protobuf.Empty) JobId(com.netflix.titus.grpc.protogen.JobId)

Example 2 with AddLoadBalancerRequest

use of com.netflix.titus.grpc.protogen.AddLoadBalancerRequest in project titus-control-plane by Netflix.

the class LoadBalancerTests method putLoadBalancersPerJob.

/**
 * Common testing helper that adds a specified number of random load balancer ids to
 * a specified number of jobs. The helper ensures the gRPC request was successful and
 * returns the job ids and load balancer ids as a map.
 */
public static Map<String, Set<LoadBalancerId>> putLoadBalancersPerJob(int numJobs, int numLoadBalancersPerJob, BiConsumer<AddLoadBalancerRequest, TestStreamObserver<Empty>> putLoadBalancer) {
    // Create job entries
    Map<String, Set<LoadBalancerId>> jobIdToLoadBalancersMap = new ConcurrentHashMap<>();
    for (int i = 1; i <= numJobs; i++) {
        jobIdToLoadBalancersMap.put("Titus-" + i, new HashSet<>());
    }
    // For each job, insert load balancers
    jobIdToLoadBalancersMap.forEach((jobId, loadBalancerSet) -> {
        for (int i = 0; i < numLoadBalancersPerJob; i++) {
            LoadBalancerId loadBalancerId = LoadBalancerId.newBuilder().setId(RandomStringUtils.randomAlphanumeric(10)).build();
            AddLoadBalancerRequest request = AddLoadBalancerRequest.newBuilder().setJobId(jobId).setLoadBalancerId(loadBalancerId).build();
            TestStreamObserver<Empty> addResponse = new TestStreamObserver<>();
            putLoadBalancer.accept(request, addResponse);
            assertThatCode(addResponse::awaitDone).doesNotThrowAnyException();
            assertThat(addResponse.hasError()).isFalse();
            loadBalancerSet.add(loadBalancerId);
        }
    });
    return jobIdToLoadBalancersMap;
}
Also used : AddLoadBalancerRequest(com.netflix.titus.grpc.protogen.AddLoadBalancerRequest) Empty(com.google.protobuf.Empty) Set(java.util.Set) HashSet(java.util.HashSet) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) LoadBalancerId(com.netflix.titus.grpc.protogen.LoadBalancerId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with AddLoadBalancerRequest

use of com.netflix.titus.grpc.protogen.AddLoadBalancerRequest in project titus-control-plane by Netflix.

the class LoadBalancerSpringResourceTest method testAddLoadBalancer.

@Test
public void testAddLoadBalancer() throws Exception {
    AddLoadBalancerRequest forwardedRequest = AddLoadBalancerRequest.newBuilder().setJobId(JOB_ID).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LOAD_BALANCER_ID).build()).build();
    when(serviceMock.addLoadBalancer(forwardedRequest, JUNIT_REST_CALL_METADATA)).thenReturn(Completable.complete());
    SpringMockMvcUtil.doPost(mockMvc, "/api/v3/loadBalancers", Optional.empty(), Optional.empty(), Optional.of(new String[] { "jobId", JOB_ID, "loadBalancerId", LOAD_BALANCER_ID }));
    verify(serviceMock, times(1)).addLoadBalancer(forwardedRequest, JUNIT_REST_CALL_METADATA);
}
Also used : AddLoadBalancerRequest(com.netflix.titus.grpc.protogen.AddLoadBalancerRequest) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

AddLoadBalancerRequest (com.netflix.titus.grpc.protogen.AddLoadBalancerRequest)3 Empty (com.google.protobuf.Empty)2 Cell (com.netflix.titus.api.federation.model.Cell)1 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)1 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)1 TitusServiceException (com.netflix.titus.api.service.TitusServiceException)1 StringExt (com.netflix.titus.common.util.StringExt)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)1 PageAggregationUtil.combinePagination (com.netflix.titus.federation.service.PageAggregationUtil.combinePagination)1 PageAggregationUtil.takeCombinedPage (com.netflix.titus.federation.service.PageAggregationUtil.takeCombinedPage)1 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)1 GetAllLoadBalancersRequest (com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest)1 GetAllLoadBalancersResult (com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult)1 GetJobLoadBalancersResult (com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult)1 JobId (com.netflix.titus.grpc.protogen.JobId)1 LoadBalancerId (com.netflix.titus.grpc.protogen.LoadBalancerId)1 LoadBalancerServiceGrpc (com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc)1 LoadBalancerServiceStub (com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc.LoadBalancerServiceStub)1 Pagination (com.netflix.titus.grpc.protogen.Pagination)1