Search in sources :

Example 11 with Endpoint

use of org.apache.bookkeeper.stream.proto.common.Endpoint 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)

Example 12 with Endpoint

use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.

the class StorageContainerChannel method handleFetchStorageContainerInfoSuccess.

private void handleFetchStorageContainerInfoSuccess(List<OneStorageContainerEndpointResponse> storageContainerEndpoints) {
    if (storageContainerEndpoints.size() != 1) {
        handleFetchStorageContainerInfoFailure(new Exception("Expected only one storage container endpoint. But found " + storageContainerEndpoints.size() + " storage container endpoints."));
        return;
    }
    OneStorageContainerEndpointResponse response = storageContainerEndpoints.get(0);
    if (StatusCode.SUCCESS != response.getStatusCode()) {
        handleFetchStorageContainerInfoFailure(new StorageContainerException(response.getStatusCode(), "fail to fetch location for storage container (" + scId + ")"));
        return;
    }
    StorageContainerEndpoint endpoint = response.getEndpoint();
    if (null != scInfo && scInfo.getRevision() >= endpoint.getRevision()) {
        handleFetchStorageContainerInfoFailure(new StorageContainerException(StatusCode.STALE_GROUP_INFO, "Fetched a stale storage container info : current = " + scInfo.getRevision() + ", fetched = " + endpoint.getRevision() + ""));
        return;
    }
    // we got the updated location
    List<Endpoint> readEndpoints = Lists.newArrayListWithExpectedSize(1 + endpoint.getRoEndpointCount());
    readEndpoints.add(endpoint.getRwEndpoint());
    readEndpoints.addAll(endpoint.getRoEndpointList());
    scInfo = StorageContainerInfo.of(scId, endpoint.getRevision(), endpoint.getRwEndpoint(), readEndpoints);
    // get the channel from channel manager (if it doesn't exist create one)
    StorageServerChannel serverChannel = channelManager.getOrCreateChannel(endpoint.getRwEndpoint());
    if (null == serverChannel) {
        log.info("No channel found/created for range server {}. The channel manager must be shutting down." + " Stop the process of fetching storage container ({}).", endpoint.getRwEndpoint(), scId);
        synchronized (this) {
            rsChannelFuture.completeExceptionally(new ObjectClosedException("StorageServerChannelManager is closed"));
        }
        return;
    }
    // update the future
    synchronized (this) {
        rsChannelFuture.complete(serverChannel);
    }
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) StorageContainerException(org.apache.bookkeeper.clients.exceptions.StorageContainerException) StorageContainerException(org.apache.bookkeeper.clients.exceptions.StorageContainerException) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException)

Example 13 with Endpoint

use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.

the class StreamStorageCli method run.

boolean run(String[] args) {
    setupShell();
    if (args.length == 0) {
        commander.usage();
        return false;
    }
    int cmdPos;
    for (cmdPos = 0; cmdPos < args.length; cmdPos++) {
        if (commandMap.containsKey(args[cmdPos])) {
            break;
        }
    }
    try {
        commander.parse(Arrays.copyOfRange(args, 0, Math.min(cmdPos, args.length)));
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println();
        commander.usage();
        return false;
    }
    if (shellArgs.help) {
        commander.usage();
        return false;
    }
    if (null == shellArgs.endpoint) {
        System.err.println("No endpoint is provided");
        commander.usage();
        return false;
    }
    Endpoint endpoint = NetUtils.parseEndpoint(shellArgs.endpoint);
    settingsBuilder.addEndpoints(endpoint);
    log.info("connecting to storage service = {}", endpoint);
    if (cmdPos == args.length) {
        commander.usage();
        return false;
    } else {
        String cmd = args[cmdPos];
        JCommander subCmd = commander.getCommands().get(cmd);
        CmdBase subCmdObj = (CmdBase) subCmd.getObjects().get(0);
        String[] subCmdArgs = Arrays.copyOfRange(args, cmdPos + 1, args.length);
        return subCmdObj.run(shellArgs.namespace, subCmdArgs);
    }
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) JCommander(com.beust.jcommander.JCommander) CmdBase(org.apache.bookkeeper.stream.cli.commands.CmdBase) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Example 14 with Endpoint

use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.

the class StorageAdminClientTest method doSetup.

@Override
protected void doSetup() throws Exception {
    scheduler = OrderedScheduler.newSchedulerBuilder().name("admin-client-test").numThreads(1).build();
    StorageClientSettings settings = StorageClientSettings.newBuilder().addEndpoints(cluster.getRpcEndpoints().toArray(new Endpoint[cluster.getRpcEndpoints().size()])).usePlaintext(true).build();
    adminClient = StorageClientBuilder.newBuilder().withSettings(settings).buildAdmin();
    defaultBackendUri = URI.create("distributedlog://" + cluster.getZkServers() + "/stream/storage");
}
Also used : StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Example 15 with Endpoint

use of org.apache.bookkeeper.stream.proto.common.Endpoint in project bookkeeper by apache.

the class TestHelixStorageContainerManager method testAddNode.

@Test
public void testAddNode() {
    String clusterName = runtime.getMethodName();
    controller.createCluster(clusterName, 1024, 3);
    List<String> instances = controller.getAdmin().getInstancesInCluster(clusterName);
    assertEquals(0, instances.size());
    Endpoint endpoint = createEndpoint("127.0.0.1", 4181);
    controller.addNode(clusterName, endpoint, Optional.empty());
    instances = controller.getAdmin().getInstancesInCluster(clusterName);
    assertEquals(1, instances.size());
    assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
    // add the instance again
    controller.addNode(clusterName, endpoint, Optional.empty());
    instances = controller.getAdmin().getInstancesInCluster(clusterName);
    assertEquals(1, instances.size());
    assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
    // add a different instance
    Endpoint endpoint2 = createEndpoint("127.0.0.1", 4481);
    controller.addNode(clusterName, endpoint2, Optional.empty());
    instances = controller.getAdmin().getInstancesInCluster(clusterName);
    assertEquals(2, instances.size());
    assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint)));
    assertTrue(instances.contains(HelixStorageController.getEndpointName(endpoint2)));
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Test(org.junit.Test)

Aggregations

Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)20 Test (org.junit.Test)8 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)7 NetUtils.createEndpoint (org.apache.bookkeeper.clients.utils.NetUtils.createEndpoint)3 NetUtils.parseEndpoint (org.apache.bookkeeper.clients.utils.NetUtils.parseEndpoint)3 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)3 StorageConfiguration (org.apache.bookkeeper.stream.storage.conf.StorageConfiguration)3 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)3 JCommander (com.beust.jcommander.JCommander)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 Slf4j (lombok.extern.slf4j.Slf4j)2 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)2 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)2 RangeStoreBuilder (org.apache.bookkeeper.stream.storage.RangeStoreBuilder)2 StorageResources (org.apache.bookkeeper.stream.storage.StorageResources)2 Parameter (com.beust.jcommander.Parameter)1 ByteString (com.google.protobuf.ByteString)1 Server (io.grpc.Server)1