Search in sources :

Example 1 with Endpoint

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

the class TestStorageContainerInfo method testBasic.

@Test
public void testBasic() {
    long groupId = 1234L;
    long revision = 4468L;
    Endpoint endpoint = Endpoint.newBuilder().setHostname("123.46.78.96").setPort(3181).build();
    StorageContainerInfo sc = StorageContainerInfo.of(groupId, revision, endpoint, Lists.newArrayList(endpoint));
    assertEquals(groupId, sc.getGroupId());
    assertEquals(revision, sc.getRevision());
    assertEquals(endpoint, sc.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint), sc.getReadEndpoints());
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Test(org.junit.Test)

Example 2 with Endpoint

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

the class NetUtils method parseEndpoint.

/**
 * Parse an endpoint from an endpoint string.
 *
 * @param endpointStr an endpoint string.
 * @return endpoint.
 */
public static Endpoint parseEndpoint(String endpointStr) {
    String[] endpointParts = StringUtils.split(endpointStr, ':');
    checkArgument(2 == endpointParts.length, "Invalid endpoint string %s - It should be 'host:port'.", endpointStr);
    String host = endpointParts[0];
    int port;
    try {
        port = Integer.parseInt(endpointParts[1]);
    } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException("Invalid port found in the endpoint string " + endpointStr, nfe);
    }
    return createEndpoint(host, port);
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Example 3 with Endpoint

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

the class TestRangeStoreImpl method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    storageResources = StorageResources.create();
    Endpoint endpoint = createEndpoint("127.0.0.1", 0);
    // create the client manager
    MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
    MVCCAsyncStore<byte[], byte[]> store = mock(MVCCAsyncStore.class);
    when(storeFactory.openStore(anyLong(), anyLong(), anyLong())).thenReturn(FutureUtils.value(store));
    when(storeFactory.closeStores(anyLong())).thenReturn(FutureUtils.Void());
    rangeStore = (RangeStoreImpl) RangeStoreBuilder.newBuilder().withStorageConfiguration(storageConf).withStorageResources(storageResources).withStorageContainerManagerFactory((numScs, storeConf, rgRegistry) -> new LocalStorageContainerManager(endpoint, storeConf, rgRegistry, 2)).withRangeStoreFactory(storeFactory).withDefaultBackendUri(URI.create("distributedlog://127.0.0.1/stream/storage")).build();
    rangeStore.start();
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LocalStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.LocalStorageContainerManager) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PutRequest(org.apache.bookkeeper.stream.proto.kv.rpc.PutRequest) StreamName(org.apache.bookkeeper.stream.proto.StreamName) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) ProtoUtils.createGetNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetNamespaceRequest) ProtoUtils.createCreateNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateNamespaceRequest) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse) After(org.junit.After) Status(io.grpc.Status) URI(java.net.URI) DEFAULT_STREAM_CONF(org.apache.bookkeeper.stream.protocol.ProtocolConstants.DEFAULT_STREAM_CONF) ProtoUtils.createGetActiveRangesRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetActiveRangesRequest) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) RangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.RangeRequest) ResponseHeader(org.apache.bookkeeper.stream.proto.kv.rpc.ResponseHeader) ByteString(com.google.protobuf.ByteString) Slf4j(lombok.extern.slf4j.Slf4j) ProtoUtils.createGetStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) CompletableFuture(java.util.concurrent.CompletableFuture) DeleteRangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse) CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) ProtoUtils.createCreateStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateStreamRequest) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ROOT_STORAGE_CONTAINER_ID(org.apache.bookkeeper.stream.protocol.ProtocolConstants.ROOT_STORAGE_CONTAINER_ID) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) DeleteRangeRequest(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeRequest) RangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse) Assert.assertEquals(org.junit.Assert.assertEquals) RoutingHeader(org.apache.bookkeeper.stream.proto.kv.rpc.RoutingHeader) GetNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest) GetNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse) MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) LocalStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.LocalStorageContainerManager) Before(org.junit.Before)

Example 4 with Endpoint

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

the class TestHelixStorageContainerManager method testStorageContainerManager.

@Ignore
@Test
public void testStorageContainerManager() throws Exception {
    String clusterName = runtime.getMethodName();
    int numStorageContainers = 12;
    int numHosts = 3;
    controller.createCluster(clusterName, numStorageContainers, 3);
    StorageConfiguration conf = new StorageConfiguration(new CompositeConfiguration());
    Endpoint[] endpoints = new Endpoint[numHosts];
    StorageContainerRegistryImpl[] registries = new StorageContainerRegistryImpl[numHosts];
    HelixStorageContainerManager[] managers = new HelixStorageContainerManager[numHosts];
    int basePort = 80;
    for (int i = 0; i < numHosts; i++) {
        endpoints[i] = createEndpoint("127.0.0.1", basePort + i);
        registries[i] = createRegistry();
        managers[i] = createManager(clusterName, conf, registries[i], endpoints[i]);
    }
    managers[0].start();
    while (registries[0].getNumStorageContainers() < numStorageContainers) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers, registries[0].getNumStorageContainers());
    assertEquals(0, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the second node
    managers[1].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() < numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers / 2, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 2, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the third node
    managers[2].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[2].getNumStorageContainers() < numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    int totalStorageContainers = registries[0].getNumStorageContainers() + registries[1].getNumStorageContainers() + registries[2].getNumStorageContainers();
    assertEquals("Expected " + numStorageContainers + "But " + totalStorageContainers + " found", numStorageContainers, totalStorageContainers);
    assertEquals(numStorageContainers / 3, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[1].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[2].getNumStorageContainers());
    for (int i = 0; i < 10; i++) {
        int nid = ThreadLocalRandom.current().nextInt(numHosts);
        long scId = ThreadLocalRandom.current().nextLong(numStorageContainers);
        Endpoint endpoint = managers[nid].getStorageContainer(scId);
        if (null != endpoint) {
            assertTrue(endpoint.equals(endpoints[0]) || endpoint.equals(endpoints[1]) || endpoint.equals(endpoints[2]));
        }
    }
    for (HelixStorageContainerManager manager : managers) {
        manager.close();
    }
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Endpoint

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

the class TestNetUtils method testToInetSocketAddress.

@Test
public void testToInetSocketAddress() {
    String hostname = "127.0.0.1";
    int port = 8080;
    Endpoint endpoint = createEndpoint(hostname, port);
    InetSocketAddress socketAddress = new InetSocketAddress(hostname, port);
    assertEquals(socketAddress, NetUtils.of(endpoint));
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) NetUtils.parseEndpoint(org.apache.bookkeeper.clients.utils.NetUtils.parseEndpoint) NetUtils.createEndpoint(org.apache.bookkeeper.clients.utils.NetUtils.createEndpoint) InetSocketAddress(java.net.InetSocketAddress) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) NetUtils.parseEndpoint(org.apache.bookkeeper.clients.utils.NetUtils.parseEndpoint) NetUtils.createEndpoint(org.apache.bookkeeper.clients.utils.NetUtils.createEndpoint) 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