Search in sources :

Example 86 with CuratorFramework

use of org.apache.curator.framework.CuratorFramework in project pravega by pravega.

the class BookKeeperAdapter method shutDown.

@Override
protected void shutDown() {
    this.logs.values().forEach(DurableDataLog::close);
    this.logs.clear();
    BookKeeperLogFactory lf = this.logFactory;
    if (lf != null) {
        lf.close();
        this.logFactory = null;
    }
    stopBookKeeper();
    CuratorFramework zkClient = this.zkClient;
    if (zkClient != null) {
        zkClient.close();
        this.zkClient = null;
    }
    Runtime.getRuntime().removeShutdownHook(this.stopBookKeeperProcess);
}
Also used : DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) CuratorFramework(org.apache.curator.framework.CuratorFramework) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)

Example 87 with CuratorFramework

use of org.apache.curator.framework.CuratorFramework in project pravega by pravega.

the class ClusterZKTest method deregisterNode.

@Test(timeout = TEST_TIMEOUT)
public void deregisterNode() throws Exception {
    LinkedBlockingQueue<String> nodeAddedQueue = new LinkedBlockingQueue<>();
    LinkedBlockingQueue<String> nodeRemovedQueue = new LinkedBlockingQueue<>();
    LinkedBlockingQueue<Exception> exceptionsQueue = new LinkedBlockingQueue<>();
    CuratorFramework client2 = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
    @Cleanup Cluster clusterListener = new ClusterZKImpl(client2, ClusterType.HOST);
    clusterListener.addListener((eventType, host) -> {
        switch(eventType) {
            case HOST_ADDED:
                nodeAddedQueue.offer(host.getIpAddr());
                break;
            case HOST_REMOVED:
                nodeRemovedQueue.offer(host.getIpAddr());
                break;
            case ERROR:
                exceptionsQueue.offer(new RuntimeException("Encountered error"));
                break;
            default:
                exceptionsQueue.offer(new RuntimeException("Unhandled case"));
                break;
        }
    });
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
    // Create Add a node to the cluster.
    @Cleanup Cluster clusterZKInstance1 = new ClusterZKImpl(client, ClusterType.HOST);
    clusterZKInstance1.registerHost(new Host(HOST_1, PORT, null));
    assertEquals(HOST_1, nodeAddedQueue.poll(5, TimeUnit.SECONDS));
    clusterZKInstance1.deregisterHost(new Host(HOST_1, PORT, null));
    assertEquals(HOST_1, nodeRemovedQueue.poll(5, TimeUnit.SECONDS));
    Exception exception = exceptionsQueue.poll();
    if (exception != null) {
        throw exception;
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Cluster(io.pravega.common.cluster.Cluster) Host(io.pravega.common.cluster.Host) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Cleanup(lombok.Cleanup) IOException(java.io.IOException) Test(org.junit.Test)

Example 88 with CuratorFramework

use of org.apache.curator.framework.CuratorFramework in project pravega by pravega.

the class ZookeeperTest method zkTest.

/**
 * Invoke the zookeeper test, ensure zookeeper can be accessed.
 * The test fails incase zookeeper cannot be accessed
 */
@Test(timeout = 5 * 60 * 1000)
public void zkTest() {
    log.info("Start execution of ZkTest");
    Service zk = Utils.createZookeeperService();
    URI zkUri = zk.getServiceDetails().get(0);
    CuratorFramework curatorFrameworkClient = CuratorFrameworkFactory.newClient(zkUri.getHost() + ":2181", new RetryOneTime(5000));
    curatorFrameworkClient.start();
    log.info("CuratorFramework status {} ", curatorFrameworkClient.getState());
    assertEquals("Connection to zk client ", STARTED, curatorFrameworkClient.getState());
    log.info("Zookeeper Service URI : {} ", zkUri);
    log.info("ZkTest  execution completed");
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Service(io.pravega.test.system.framework.services.Service) URI(java.net.URI) Test(org.junit.Test)

Example 89 with CuratorFramework

use of org.apache.curator.framework.CuratorFramework in project eventuate-local by eventuate-local.

the class EventTableChangesToAggregateTopicRelayConfiguration method makeStartedCuratorClient.

static CuratorFramework makeStartedCuratorClient(String connectionString) {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.builder().retryPolicy(retryPolicy).connectString(connectionString).build();
    client.start();
    return client;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 90 with CuratorFramework

use of org.apache.curator.framework.CuratorFramework in project eventuate-local by eventuate-local.

the class EventTableChangesToAggregateTopicTranslatorConfiguration method makeStartedCuratorClient.

static CuratorFramework makeStartedCuratorClient(String connectionString) {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.builder().retryPolicy(retryPolicy).connectString(connectionString).build();
    client.start();
    return client;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)824 Test (org.testng.annotations.Test)290 RetryOneTime (org.apache.curator.retry.RetryOneTime)267 Test (org.junit.Test)168 Timing (org.apache.curator.test.Timing)147 CountDownLatch (java.util.concurrent.CountDownLatch)120 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)98 KeeperException (org.apache.zookeeper.KeeperException)84 IOException (java.io.IOException)75 ConnectionState (org.apache.curator.framework.state.ConnectionState)70 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)52 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)50 RetryNTimes (org.apache.curator.retry.RetryNTimes)48 ExecutorService (java.util.concurrent.ExecutorService)47 ArrayList (java.util.ArrayList)44 RetryPolicy (org.apache.curator.RetryPolicy)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 Stat (org.apache.zookeeper.data.Stat)35 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)33 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)32