Search in sources :

Example 11 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.

the class TestStorer method main.

public static void main(String[] args) throws Exception {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient("122.11.47.17:2181", 5 * 1000, 30 * 1000, retryPolicy);
    client.start();
    client.blockUntilConnected();
    FileNodeStorer storer = new ZkFileNodeStorer(client.usingNamespace("test"));
    FileNode node = new FileNode();
    node.setName("file_node_1");
    node.setServiceId("ser_1");
    node.setStorageName("sn_1");
    node.setDuplicates(new int[] { 1, 2, 3 });
    storer.save(node);
    FileNode node2 = storer.getFileNode("file_node_1");
    System.out.println("node2--" + node2.getName());
    node2.setServiceId("ser_2");
    storer.update("file_node_1", node2);
    List<FileNode> nodeList = storer.listFileNodes();
    for (FileNode nd : nodeList) {
        System.out.println("list--" + nd.getName() + ", " + nd.getServiceId());
        storer.delete(nd.getName());
    }
    synchronized (client) {
        client.wait();
    }
}
Also used : FileNodeStorer(com.bonree.brfs.duplication.coordinator.FileNodeStorer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy) FileNode(com.bonree.brfs.duplication.coordinator.FileNode)

Example 12 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project hive by apache.

the class HiveServer2 method addServerInstanceToZooKeeper.

/**
 * Adds a server instance to ZooKeeper as a znode.
 *
 * @param hiveConf
 * @throws Exception
 */
private void addServerInstanceToZooKeeper(HiveConf hiveConf, Map<String, String> confsToPublish) throws Exception {
    String zooKeeperEnsemble = ZooKeeperHiveHelper.getQuorumServers(hiveConf);
    String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE);
    String instanceURI = getServerInstanceURI();
    setUpZooKeeperAuth(hiveConf);
    int sessionTimeout = (int) hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT, TimeUnit.MILLISECONDS);
    int baseSleepTime = (int) hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME, TimeUnit.MILLISECONDS);
    int maxRetries = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_CONNECTION_MAX_RETRIES);
    // Create a CuratorFramework instance to be used as the ZooKeeper client
    // Use the zooKeeperAclProvider to create appropriate ACLs
    zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble).sessionTimeoutMs(sessionTimeout).aclProvider(zooKeeperAclProvider).retryPolicy(new ExponentialBackoffRetry(baseSleepTime, maxRetries)).build();
    zooKeeperClient.start();
    // Create the parent znodes recursively; ignore if the parent already exists.
    try {
        zooKeeperClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace);
        LOG.info("Created the root name space: " + rootNamespace + " on ZooKeeper for HiveServer2");
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            LOG.error("Unable to create HiveServer2 namespace: " + rootNamespace + " on ZooKeeper", e);
            throw e;
        }
    }
    // Znode name: serverUri=host:port;version=versionInfo;sequence=sequenceNumber
    try {
        String pathPrefix = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "serverUri=" + instanceURI + ";" + "version=" + HiveVersionInfo.getVersion() + ";" + "sequence=";
        String znodeData = "";
        if (hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_PUBLISH_CONFIGS)) {
            // HiveServer2 configs that this instance will publish to ZooKeeper,
            // so that the clients can read these and configure themselves properly.
            addConfsToPublish(hiveConf, confsToPublish, instanceURI);
            // Publish configs for this instance as the data on the node
            znodeData = Joiner.on(';').withKeyValueSeparator("=").join(confsToPublish);
        } else {
            znodeData = instanceURI;
        }
        byte[] znodeDataUTF8 = znodeData.getBytes(Charset.forName("UTF-8"));
        znode = new PersistentEphemeralNode(zooKeeperClient, PersistentEphemeralNode.Mode.EPHEMERAL_SEQUENTIAL, pathPrefix, znodeDataUTF8);
        znode.start();
        // We'll wait for 120s for node creation
        long znodeCreationTimeout = 120;
        if (!znode.waitForInitialCreate(znodeCreationTimeout, TimeUnit.SECONDS)) {
            throw new Exception("Max znode creation wait time: " + znodeCreationTimeout + "s exhausted");
        }
        setDeregisteredWithZooKeeper(false);
        final String znodePath = znode.getActualPath();
        // Set a watch on the znode
        if (zooKeeperClient.checkExists().usingWatcher(new DeRegisterWatcher()).forPath(znodePath) == null) {
            // No node exists, throw exception
            throw new Exception("Unable to create znode for this HiveServer2 instance on ZooKeeper.");
        }
        LOG.info("Created a znode on ZooKeeper for HiveServer2 uri: " + instanceURI);
    } catch (Exception e) {
        LOG.error("Unable to create a znode for this server instance", e);
        if (znode != null) {
            znode.close();
        }
        throw (e);
    }
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) PersistentEphemeralNode(org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode) KeeperException(org.apache.zookeeper.KeeperException) ServiceException(org.apache.hive.service.ServiceException) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) KeeperException(org.apache.zookeeper.KeeperException)

Example 13 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.

the class SegmentContainerMonitorTest method startZookeeper.

@Before
public void startZookeeper() throws Exception {
    zkTestServer = new TestingServerStarter().start();
    String zkUrl = zkTestServer.getConnectString();
    zkClient = CuratorFrameworkFactory.newClient(zkUrl, new ExponentialBackoffRetry(200, 10, 5000));
    zkClient.start();
    cluster = new ClusterZKImpl(zkClient, ClusterType.HOST);
}
Also used : TestingServerStarter(io.pravega.test.common.TestingServerStarter) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ClusterZKImpl(io.pravega.common.cluster.zkImpl.ClusterZKImpl) Before(org.junit.Before)

Example 14 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry 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 15 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry 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

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)189 CuratorFramework (org.apache.curator.framework.CuratorFramework)113 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)31 TestingCluster (org.apache.curator.test.TestingCluster)28 Test (org.testng.annotations.Test)23 TestingServer (org.apache.curator.test.TestingServer)19 IOException (java.io.IOException)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ArrayList (java.util.ArrayList)14 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 HashMap (java.util.HashMap)8 KeeperException (org.apache.zookeeper.KeeperException)8