Search in sources :

Example 21 with ExponentialBackoffRetry

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

the class RemoteConfigurationRegistryClientServiceTest method initializeTestClientAndZNodes.

/**
 * Create a ZooKeeper client with SASL digest auth configured, and initialize the test znodes.
 */
private CuratorFramework initializeTestClientAndZNodes(TestingCluster zkCluster, String principal) throws Exception {
    // Create the client for the test cluster
    CuratorFramework setupClient = CuratorFrameworkFactory.builder().connectString(zkCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    assertNotNull(setupClient);
    setupClient.start();
    List<ACL> acls = new ArrayList<>();
    if (principal != null) {
        acls.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", principal)));
    } else {
        acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/descriptors");
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/shared-providers");
    List<ACL> negativeACLs = new ArrayList<>();
    if (principal != null) {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", "notyou")));
    } else {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(negativeACLs).forPath("/someotherconfig");
    return setupClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 22 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project twister2 by DSC-SPIDAL.

the class ZKUtil method connectToServer.

/**
 * connect to ZooKeeper server
 * @param config
 * @return
 */
public static CuratorFramework connectToServer(Config config) {
    String zkServerAddress = ZKContext.zooKeeperServerIP(config);
    String zkServerPort = ZKContext.zooKeeperServerPort(config);
    String zkServer = zkServerAddress + ":" + zkServerPort;
    try {
        CuratorFramework client = CuratorFrameworkFactory.newClient(zkServer, new ExponentialBackoffRetry(1000, 3));
        client.start();
        LOG.log(Level.INFO, "Connected to ZooKeeper server: " + zkServer);
        return client;
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Could not connect to ZooKeeper server" + zkServer, e);
        throw new RuntimeException(e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 23 with ExponentialBackoffRetry

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

the class LoadBalancer method start.

private void start() throws Exception {
    curaFramework = CuratorFrameworkFactory.newClient(getZkConnectString(), new ExponentialBackoffRetry(1000, 3));
    curaFramework.start();
    curaFramework.setACL().withACL(CONFIG.getAcls());
    connectionStateListener = getConnectionStateListener();
    curaFramework.getConnectionStateListenable().addListener(connectionStateListener);
    unhandledErrorListener = getUnhandledErrorListener();
    curaFramework.getUnhandledErrorListenable().addListener(unhandledErrorListener);
    cache = new PathChildrenCache(curaFramework, CONFIG.getParentPath(), true);
    cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
    closeAbles.add(cache);
    closeAbles.add(curaFramework);
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache)

Example 24 with ExponentialBackoffRetry

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

the class ZookeeperRegistry method registerServer.

@Override
public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString, String pqsHost) throws Exception {
    this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString, new ExponentialBackoffRetry(1000, 10));
    this.client.start();
    HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort);
    String path = configuration.getFullPathToNode(hostAndPort);
    String node = hostAndPort.toString();
    this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, node.getBytes(StandardCharsets.UTF_8));
    Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path);
    if (stat != null) {
        LOG.info(" node created with right ACL");
    } else {
        LOG.error("could not create node with right ACL. So, system would exit now.");
        throw new RuntimeException(" Unable to connect to Zookeeper");
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Stat(org.apache.zookeeper.data.Stat) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 25 with ExponentialBackoffRetry

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

the class MaasIntegrationTest method setupBeforeClass.

@BeforeAll
public static void setupBeforeClass() throws Exception {
    UnitTestHelper.setJavaLoggingLevel(Level.SEVERE);
    LOG.info("Starting up YARN cluster");
    zkServerComponent = new ZKServerComponent();
    yarnComponent = new YarnComponent().withApplicationMasterClass(ApplicationMaster.class).withTestName(MaasIntegrationTest.class.getSimpleName());
    runner = new ComponentRunner.Builder().withComponent("yarn", yarnComponent).withComponent("zk", zkServerComponent).withMillisecondsBetweenAttempts(15000).withNumRetries(10).build();
    runner.start();
    String zookeeperUrl = zkServerComponent.getConnectionString();
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
    client.start();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKServerComponent(org.apache.metron.integration.components.ZKServerComponent) YarnComponent(org.apache.metron.integration.components.YarnComponent) 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