Search in sources :

Example 91 with ExponentialBackoffRetry

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

the class ZKSegmentContainerManagerTest method startClient.

private CuratorFramework startClient() {
    val client = CuratorFrameworkFactory.newClient(zkUrl, new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY));
    client.start();
    return client;
}
Also used : lombok.val(lombok.val) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 92 with ExponentialBackoffRetry

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

the class BookKeeperRunner method initialize.

public void initialize() throws Exception {
    // BookKeeper
    // Pick random ports to reduce chances of collisions during concurrent test executions.
    int zkPort = TestUtils.getAvailableListenPort();
    val bookiePorts = new ArrayList<Integer>();
    for (int i = 0; i < this.bookieCount; i++) {
        bookiePorts.add(TestUtils.getAvailableListenPort());
    }
    this.bkRunner = BookKeeperServiceRunner.builder().startZk(true).zkPort(zkPort).secureZK(false).secureBK(false).ledgersPath("/ledgers/" + zkPort).bookiePorts(bookiePorts).build();
    this.bkRunner.startAll();
    // Create a ZKClient with a base namespace.
    String baseNamespace = "pravega/" + zkPort;
    this.zkClient = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).namespace(baseNamespace).retryPolicy(new ExponentialBackoffRetry(1000, 5)).connectionTimeoutMs(5000).sessionTimeoutMs(5000).build();
    this.zkClient.start();
    // Attach a sub-namespace for the Container Metadata.
    String logMetaNamespace = "segmentstore/containers";
    this.configBuilder.include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, "localhost:" + zkPort).with(BookKeeperConfig.ZK_METADATA_PATH, logMetaNamespace).with(BookKeeperConfig.BK_LEDGER_PATH, "/ledgers/" + zkPort).with(BookKeeperConfig.BK_ACK_QUORUM_SIZE, this.bookieCount).with(BookKeeperConfig.BK_WRITE_QUORUM_SIZE, this.bookieCount).with(BookKeeperConfig.BK_ENSEMBLE_SIZE, this.bookieCount));
}
Also used : lombok.val(lombok.val) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList)

Example 93 with ExponentialBackoffRetry

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

the class InProcPravegaCluster method cleanUpZK.

private void cleanUpZK() {
    String[] pathsTobeCleaned = { "/pravega", "/hostIndex", "/store", "/taskIndex" };
    RetryPolicy rp = new ExponentialBackoffRetry(1000, 3);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zkUrl).connectionTimeoutMs(5000).sessionTimeoutMs(5000).retryPolicy(rp);
    if (secureZK) {
        ZKTLSUtils.setSecureZKClientProperties(jksTrustFile, "1111_aaaa");
    }
    @Cleanup CuratorFramework zclient = builder.build();
    zclient.start();
    for (String path : pathsTobeCleaned) {
        try {
            zclient.delete().guaranteed().deletingChildrenIfNeeded().forPath(path);
        } catch (Exception e) {
            log.warn("Not able to delete path {} . Exception {}", path, e.getMessage());
        }
    }
    zclient.close();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ToString(lombok.ToString) RetryPolicy(org.apache.curator.RetryPolicy) Cleanup(lombok.Cleanup) IOException(java.io.IOException)

Example 94 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project sofa-ark by alipay.

the class ZookeeperConfigActivator method start.

@Override
public void start(final PluginContext context) {
    if (!enableZkServer) {
        LOGGER.warn("config server is disabled.");
        return;
    }
    String config = ArkConfigs.getStringValue(Constants.CONFIG_SERVER_ADDRESS);
    RegistryConfig registryConfig = ZookeeperConfigurator.buildConfig(config);
    String address = registryConfig.getAddress();
    int idx = address.indexOf(Constants.ZOOKEEPER_CONTEXT_SPLIT);
    if (idx != -1) {
        rootPath = address.substring(idx);
        if (!rootPath.endsWith(Constants.ZOOKEEPER_CONTEXT_SPLIT)) {
            rootPath += Constants.ZOOKEEPER_CONTEXT_SPLIT;
        }
        address = address.substring(0, idx);
    }
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFrameworkFactory.Builder zkClientBuilder = CuratorFrameworkFactory.builder().connectString(address).sessionTimeoutMs(3 * registryConfig.getConnectTimeout()).connectionTimeoutMs(registryConfig.getConnectTimeout()).canBeReadOnly(false).retryPolicy(retryPolicy).defaultData(null);
    List<AuthInfo> authInfos = buildAuthInfo(registryConfig);
    if (!authInfos.isEmpty()) {
        zkClientBuilder = zkClientBuilder.aclProvider(getDefaultAclProvider()).authorization(authInfos);
    }
    zkClient = zkClientBuilder.build();
    zkClient.getConnectionStateListenable().addListener(new ConnectionStateListener() {

        @Override
        public void stateChanged(CuratorFramework client, ConnectionState newState) {
            LOGGER.info("Reconnect to zookeeper, re-register config resource.");
            if (newState == ConnectionState.RECONNECTED) {
                unSubscribeIpConfig();
                registryResource(ipResourcePath, CreateMode.EPHEMERAL);
                subscribeIpConfig();
            }
        }
    });
    zkClient.start();
    registryResource(bizResourcePath, CreateMode.PERSISTENT);
    registryResource(ipResourcePath, CreateMode.EPHEMERAL);
    subscribeIpConfig();
    subscribeBizConfig();
    registerEventHandler(context);
}
Also used : RegistryConfig(com.alipay.sofa.ark.config.RegistryConfig) AuthInfo(org.apache.curator.framework.AuthInfo) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorFramework(org.apache.curator.framework.CuratorFramework) ConnectionState(org.apache.curator.framework.state.ConnectionState) RetryPolicy(org.apache.curator.RetryPolicy) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Example 95 with ExponentialBackoffRetry

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

the class TestZooKeeperTokenStore method setUp.

@Override
protected void setUp() throws Exception {
    File zkDataDir = new File(System.getProperty("test.tmp.dir"));
    if (this.zkCluster != null) {
        throw new IOException("Cluster already running");
    }
    this.zkCluster = new MiniZooKeeperCluster();
    this.zkPort = this.zkCluster.startup(zkDataDir);
    this.zkClient = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
    this.zkClient.start();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) IOException(java.io.IOException) MiniZooKeeperCluster(org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster) File(java.io.File)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)181 CuratorFramework (org.apache.curator.framework.CuratorFramework)107 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)26 TestingCluster (org.apache.curator.test.TestingCluster)23 Test (org.testng.annotations.Test)23 IOException (java.io.IOException)18 TestingServer (org.apache.curator.test.TestingServer)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 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 KeeperException (org.apache.zookeeper.KeeperException)8 HashMap (java.util.HashMap)7