Search in sources :

Example 1 with ZKHostStore

use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.

the class SegmentContainerMonitorTest method testMonitorWithZKStore.

@Test(timeout = 30000)
public void testMonitorWithZKStore() throws Exception {
    HostMonitorConfig config = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).containerCount(Config.HOST_STORE_CONTAINER_COUNT).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).build();
    HostControllerStore hostStore = HostStoreFactory.createStore(config, StoreClientFactory.createZKStoreClient(PRAVEGA_ZK_CURATOR_RESOURCE.client));
    // 6 latches to match 6 operations of register/deregiter done in the test
    List<CompletableFuture<Void>> latches = Arrays.asList(new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>());
    AtomicInteger next = new AtomicInteger(0);
    ((ZKHostStore) hostStore).addListener(() -> {
        latches.get(next.getAndIncrement()).complete(null);
    });
    testMonitor(hostStore, latches);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) ZKHostStore(io.pravega.controller.store.host.ZKHostStore) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) Test(org.junit.Test)

Example 2 with ZKHostStore

use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.

the class HostStoreTest method zkHostStoreTests.

@Test(timeout = 10000L)
public void zkHostStoreTests() throws Exception {
    @Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
    ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(zkTestServer.getConnectString()).initialSleepInterval(2000).maxRetries(1).sessionTimeoutMs(10 * 1000).namespace("hostStoreTest/" + UUID.randomUUID()).build();
    StoreClientConfig storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
    @Cleanup StoreClient storeClient = StoreClientFactory.createStoreClient(storeClientConfig);
    HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).hostMonitorMinRebalanceInterval(10).containerCount(containerCount).build();
    // Update host store map.
    Map<Host, Set<Integer>> hostContainerMap = HostMonitorConfigImpl.getHostContainerMap(host, controllerPort, containerCount);
    // Create ZK based host store.
    HostControllerStore hostStore = HostStoreFactory.createStore(hostMonitorConfig, storeClient);
    CompletableFuture<Void> latch1 = new CompletableFuture<>();
    CompletableFuture<Void> latch2 = new CompletableFuture<>();
    ((ZKHostStore) hostStore).addListener(() -> {
        // wait for the second operation to complete (related to updateHostContainersMap()).
        if (latch1.isDone()) {
            latch2.complete(null);
        }
        latch1.complete(null);
    });
    hostStore.updateHostContainersMap(hostContainerMap);
    latch1.join();
    latch2.join();
    validateStore(hostStore);
    // verify that a new hostStore is initialized with map set by previous host store.
    HostControllerStore hostStore2 = HostStoreFactory.createStore(hostMonitorConfig, storeClient);
    Map<Host, Set<Integer>> map = hostStore2.getHostContainersMap();
    assertEquals(hostContainerMap, map);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) StoreClient(io.pravega.controller.store.client.StoreClient) Set(java.util.Set) TestingServerStarter(io.pravega.test.common.TestingServerStarter) Host(io.pravega.common.cluster.Host) Cleanup(lombok.Cleanup) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) CompletableFuture(java.util.concurrent.CompletableFuture) ZKClientConfig(io.pravega.controller.store.client.ZKClientConfig) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StoreClientConfig(io.pravega.controller.store.client.StoreClientConfig) ZKHostStore(io.pravega.controller.store.host.ZKHostStore) Test(org.junit.Test)

Example 3 with ZKHostStore

use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.

the class TestUtils method createDummyHostContainerAssignment.

/**
 * This method creates a dummy Host-Container mapping, given that it is not created in Pravega standalone.
 *
 * @param zkConnectString   Connection endpoint for Zookeeper.
 * @param hostIp            Name of the host to connect to.
 * @param hostPort          Port of the host to connect to.
 */
public static void createDummyHostContainerAssignment(String zkConnectString, String hostIp, int hostPort) {
    @Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().namespace("pravega/pravega-cluster").connectString(zkConnectString).retryPolicy(new RetryOneTime(5000)).build();
    curatorFramework.start();
    ZKHostStore zkHostStore = new ZKHostStore(curatorFramework, 4);
    Map<Host, Set<Integer>> dummyHostContainerAssignment = new HashMap<>();
    dummyHostContainerAssignment.put(new Host(hostIp, hostPort, ""), new HashSet<>(Arrays.asList(0, 1, 2, 3)));
    zkHostStore.updateHostContainersMap(dummyHostContainerAssignment);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Host(io.pravega.common.cluster.Host) ZKHostStore(io.pravega.controller.store.host.ZKHostStore) Cleanup(lombok.Cleanup)

Aggregations

ZKHostStore (io.pravega.controller.store.host.ZKHostStore)3 Host (io.pravega.common.cluster.Host)2 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)2 HostMonitorConfig (io.pravega.controller.store.host.HostMonitorConfig)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Cleanup (lombok.Cleanup)2 Test (org.junit.Test)2 StoreClient (io.pravega.controller.store.client.StoreClient)1 StoreClientConfig (io.pravega.controller.store.client.StoreClientConfig)1 ZKClientConfig (io.pravega.controller.store.client.ZKClientConfig)1 TestingServerStarter (io.pravega.test.common.TestingServerStarter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 RetryOneTime (org.apache.curator.retry.RetryOneTime)1 TestingServer (org.apache.curator.test.TestingServer)1