public ZookeeperOffsetHandler(Properties props) { this.groupId = props.getProperty(ConsumerConfig.GROUP_ID_CONFIG); if (this.groupId == null) { throw new IllegalArgumentException("Required property '" + ConsumerConfig.GROUP_ID_CONFIG + "' has not been set"); } String zkConnect = props.getProperty("zookeeper.connect"); if (zkConnect == null) { throw new IllegalArgumentException("Required property 'zookeeper.connect' has not been set"); } // we use Curator's default timeouts int sessionTimeoutMs = Integer.valueOf(props.getProperty("zookeeper.session.timeout.ms", "60000")); int connectionTimeoutMs = Integer.valueOf(props.getProperty("zookeeper.connection.timeout.ms", "15000")); // undocumented config options allowing users to configure the retry policy. (they are "flink." prefixed as they are no official kafka configs) int backoffBaseSleepTime = Integer.valueOf(props.getProperty("flink.zookeeper.base-sleep-time.ms", "100")); int backoffMaxRetries = Integer.valueOf(props.getProperty("flink.zookeeper.max-retries", "10")); RetryPolicy retryPolicy = new ExponentialBackoffRetry(backoffBaseSleepTime, backoffMaxRetries); curatorClient = CuratorFrameworkFactory.newClient(zkConnect, sessionTimeoutMs, connectionTimeoutMs, retryPolicy); curatorClient.start(); }
public static CuratorFramework createZkClient(TestingServer testingZKServer, Closer closer) throws InterruptedException { CuratorFramework curatorFramework = closer.register(CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); curatorFramework.start(); if (! curatorFramework.blockUntilConnected(60, TimeUnit.SECONDS)) { throw new RuntimeException("Time out waiting to connect to ZK!"); } return curatorFramework; } }
protected static CuratorFramework createNewClient() throws InterruptedException { CuratorFramework client = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 3)); client.start(); return client; }
public ZookeeperClient(String zkUrl) { zookeeperConnection = zkUrl; LOG.info("Initialize curator with zkurl:" + zkUrl); curator = CuratorFrameworkFactory.newClient(zookeeperConnection, new RetryOneTime(3000)); curator.start(); }
client = CuratorFrameworkFactory.newClient(zkQuorum, retryPolicy); client.start(); MaaSConfig config = ConfigUtil.INSTANCE.read(client, zkRoot, new MaaSConfig(), MaaSConfig.class); JsonInstanceSerializer<ModelEndpoint> serializer = new JsonInstanceSerializer<>(ModelEndpoint.class); CloseableUtils.closeQuietly(serviceDiscovery); CloseableUtils.closeQuietly(client);
public SubPubTest() throws Exception { this.testingServer = new TestingServer(); client = AsyncCuratorFramework.wrap(CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new RetryOneTime(1))); executorService = Executors.newSingleThreadScheduledExecutor(); }
LOG.info("Testing ZK Server listening on: " + testingZKServer.getConnectString()); CuratorFrameworkFactory.newClient(testingZKServer.getConnectString(), new RetryOneTime(2000))); this.curatorFramework.start(); ConfigValueFactory.fromAnyRef(testingZKServer.getConnectString())) .resolve();
/** * Open a ZooKeeper connection for the JobState. */ public static CuratorFramework zkOpen(String zkHosts, int zkSessionTimeoutMs) throws IOException { //do we need to add a connection status listener? What will that do? ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework zk = CuratorFrameworkFactory.newClient(zkHosts, zkSessionTimeoutMs, CuratorFrameworkFactory.builder().getConnectionTimeoutMs(), retryPolicy); zk.start(); return zk; }
@Before public void setup() throws Exception { testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); client.start(); discoverer = new ServiceDiscoverer(client, "/maas/discover"); discoverer.start(); }
/** * Instantiates a new Zookeeper config provider. */ public ZookeeperConfigProvider(URI uri) throws Exception { String connectString = uri.getHost() + ":" + (uri.getPort() == -1 ? 2181 : uri.getPort()); String serviceName = uri.getPath().split("/", 2)[1]; client = CuratorFrameworkFactory.newClient(connectString, new RetryOneTime(1000)); client.start(); shutdownFunctions.add(client::close); initProvider(client, serviceName); }
public static CuratorFramework createClient(final TestingServer server) { return CuratorFrameworkFactory.newClient( server.getConnectString(), new RetryOneTime(1)); }
void start() { try { server = new TestingServer(curatorPort, true); this.curator = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1000)); this.curator.start(); this.curator.blockUntilConnected(10, TimeUnit.SECONDS); initializer.accept(this); } catch (Exception ex) { throw new IllegalStateException("Failed to start Zookeeper", ex); } }
@Autowired public CuratorDistributedLockServiceProvider( @Value("${zookeeper.connectionString:localhost:12181}") String zookeeperConnectionString, @Value("${zookeeper.sleepTime:1000}") String sleepTime, @Value("${zookeeper.maxRetries:3}") String maxRetries, @Value("${curator.lockBasePath:/tmp/zookeeper}") String lockBasePath) { RetryPolicy retryPolicy = new ExponentialBackoffRetry(Integer.valueOf(sleepTime), Integer.valueOf(maxRetries)); this.curatorFramework = CuratorFrameworkFactory.newClient(zookeeperConnectionString, retryPolicy); this.lockBasePath = lockBasePath; curatorFramework.start(); } /**
MockDGAModel.start(8282); testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); client.start(); context = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client)
private void withZooKeeper(ZooKeeperTask task) throws HekateException { try (CuratorFramework client = CuratorFrameworkFactory.newClient( connectionString, sessionTimeout, connectTimeout, new RetryOneTime(0) )) { client.start(); try { if (!client.blockUntilConnected(connectTimeout, TimeUnit.MILLISECONDS)) { throw new HekateException("Timeout connecting to ZooKeeper [connections-string=" + connectionString + ']'); } } catch (InterruptedException e) { throw new HekateException("Thread got interrupted while connecting to ZooKeeper.", e); } task.execute(client); } }
void start() { try { server = new TestingServer(curatorPort, true); this.curator = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1000)); this.curator.start(); this.curator.blockUntilConnected(10, TimeUnit.SECONDS); initializer.accept(this); } catch (Exception ex) { throw new IllegalStateException("Failed to start Zookeeper", ex); } }
public ZkBasedSnowFlakeIdGenerator(String zooKeeperUrl, String applicationName) { CuratorFramework client = CuratorFrameworkFactory.newClient(zooKeeperUrl, new RetryForever(1000)); client.start(); try { String path = "/EasyTransIdGen/" + applicationName + "/P"; String nodeName = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path); String sequenceStr = nodeName.replaceAll(path, ""); hostSeq = Long.parseLong(sequenceStr) % (2^SnowFlake.MACHINE_BIT); client.close();//do not need to keep connection, hostSeq will not change } catch (Exception e) { throw new RuntimeException("create Id generator failed",e); } }
@Override public void start() throws Exception { zkServer = new TestingServer(zookeeperPort, logDir); ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); curatorClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), retryPolicy); curatorClient.start(); Properties props = new Properties(); props.setProperty("zookeeper.connect", zkServer.getConnectString()); props.setProperty("broker.id", "0"); props.setProperty("port", "" + kafkaPort); props.setProperty("log.dirs", logDir.getAbsolutePath()); props.setProperty("auto.create.topics.enable", "true"); kafkaServer = new KafkaServerStartable(new KafkaConfig(props)); kafkaServer.startup(); }
/** * Invoke the zookeeper test, ensure zookeeper can be accessed. * The test fails in case zookeeper cannot be accessed. * */ @Test 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"); } }
@Override public Void call() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); try { client.start(); final ExampleClientReentrantLocks example = new ExampleClientReentrantLocks(client, PATH, resource, "Client " + index); for (int j = 0; j < REPETITIONS; ++j) { example.doWork(10, TimeUnit.SECONDS); } }catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } catch (Throwable e) { e.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); } return null; } };