Search in sources :

Example 1 with GetStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse in project bookkeeper by apache.

the class TestProtocolInternalUtils method testCreateStorageContainerEndpointResponse.

@Test
public void testCreateStorageContainerEndpointResponse() {
    List<StorageContainerEndpoint> endpoints = Lists.newArrayList(StorageContainerEndpoint.newBuilder().setStorageContainerId(1L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(2L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(3L).build());
    GetStorageContainerEndpointResponse response = createGetStorageContainerEndpointResponse(endpoints);
    assertEquals(3, response.getResponsesCount());
    int i = 0;
    for (OneStorageContainerEndpointResponse oneResp : response.getResponsesList()) {
        assertEquals(StatusCode.SUCCESS, oneResp.getStatusCode());
        assertTrue(endpoints.get(i) == oneResp.getEndpoint());
        ++i;
    }
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) ProtoUtils.createGetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointResponse) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Test(org.junit.Test)

Example 2 with GetStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse in project bookkeeper by apache.

the class ProtoUtils method createGetStorageContainerEndpointResponse.

/**
 * Create a {@link GetStorageContainerEndpointResponse}.
 *
 * @param endpoints list of storage container endpoints
 * @return a get storage container endpoint response.
 */
public static GetStorageContainerEndpointResponse createGetStorageContainerEndpointResponse(List<StorageContainerEndpoint> endpoints) {
    GetStorageContainerEndpointResponse.Builder builder = GetStorageContainerEndpointResponse.newBuilder();
    builder.setStatusCode(StatusCode.SUCCESS);
    for (StorageContainerEndpoint endpoint : endpoints) {
        builder.addResponses(OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(endpoint));
    }
    return builder.build();
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)

Example 3 with GetStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse in project bookkeeper by apache.

the class GrpcStorageContainerService method getStorageContainerEndpoint.

@Override
public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
    GetStorageContainerEndpointResponse.Builder responseBuilder = GetStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS);
    for (int i = 0; i < request.getRequestsCount(); i++) {
        Endpoint endpoint = rangeStore.getRoutingService().getStorageContainer(request.getRequests(i).getStorageContainer());
        OneStorageContainerEndpointResponse.Builder oneRespBuilder;
        if (null != endpoint) {
            oneRespBuilder = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setRwEndpoint(endpoint).addRoEndpoint(endpoint).setRevision(0L));
        } else {
            oneRespBuilder = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.INTERNAL_SERVER_ERROR);
        }
        responseBuilder = responseBuilder.addResponses(oneRespBuilder);
    }
    responseObserver.onNext(responseBuilder.build());
    responseObserver.onCompleted();
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)

Example 4 with GetStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse in project bookkeeper by apache.

the class GrpcClientTestBase method setUp.

@Before
public void setUp() throws Exception {
    fakeServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    scheduler = OrderedScheduler.newSchedulerBuilder().name("scheduler-" + getClass()).numThreads(Runtime.getRuntime().availableProcessors()).build();
    settings = StorageClientSettings.newBuilder().managedChannelBuilder(InProcessChannelBuilder.forName(serverName).directExecutor()).usePlaintext(true).build();
    serverManager = new StorageServerClientManagerImpl(settings, resources.scheduler(), endpoint -> new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty()));
    StorageContainerServiceImplBase scService = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            GetStorageContainerEndpointResponse.Builder respBuilder = GetStorageContainerEndpointResponse.newBuilder();
            respBuilder.setStatusCode(StatusCode.SUCCESS);
            for (OneStorageContainerEndpointRequest oneReq : request.getRequestsList()) {
                OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(oneReq.getStorageContainer()).setRevision(oneReq.getRevision() + 1).setRwEndpoint(ENDPOINT)).build();
                respBuilder.addResponses(oneResp);
            }
            responseObserver.onNext(respBuilder.build());
            responseObserver.onCompleted();
        }
    };
    serviceRegistry.addService(scService.bindService());
    doSetup();
}
Also used : GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ClientResources(org.apache.bookkeeper.clients.utils.ClientResources) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) StreamObserver(io.grpc.stub.StreamObserver) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) After(org.junit.After) Optional(java.util.Optional) Server(io.grpc.Server) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) Before(org.junit.Before) StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) Before(org.junit.Before)

Aggregations

GetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)4 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)4 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)3 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 Server (io.grpc.Server)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 StreamObserver (io.grpc.stub.StreamObserver)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1 Optional (java.util.Optional)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)1 StorageServerClientManagerImpl (org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl)1 ClientResources (org.apache.bookkeeper.clients.utils.ClientResources)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1 GetStorageContainerEndpointRequest (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest)1 OneStorageContainerEndpointRequest (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest)1 StatusCode (org.apache.bookkeeper.stream.proto.storage.StatusCode)1 StorageContainerServiceImplBase (org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase)1 ProtoUtils.createGetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointResponse)1