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; } }
@Before public void setup() { conf = new HiveConf(); lockObjData = new HiveLockObjectData("1", "10", "SHARED", "show tables", conf); hiveLock = new HiveLockObject(TABLE, lockObjData); zLock = new ZooKeeperHiveLock(TABLE_LOCK_PATH, hiveLock, HiveLockMode.SHARED); while (server == null) { try { server = new TestingServer(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build(); client.start(); } catch (Exception e) { System.err.println("Getting bind exception - retrying to allocate server"); server = null; } } }
@Test(expectedExceptions = {RuntimeException.class}, expectedExceptionsMessageRegExp = ".*init.*") public void testLoad_withZkClientException() throws Exception { CuratorFramework client = Mockito.mock(CuratorFramework.class); doThrow(new RuntimeException()).when(client).start(); RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser()); source.load(); }
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(); }
@Test(timeout = 60_000L) public void testSessionKilled() throws Exception curator.start(); curator.blockUntilConnected(); Announcer announcer = new Announcer(curator, exec); KillSession.kill(curator.getZookeeperClient().getZooKeeper(), server.getConnectString());
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); client.create().creatingParentsIfNeeded().forPath(PATH, "test".getBytes()); CloseableUtils.closeQuietly(client); client = createWithOptions(server.getConnectString(), new ExponentialBackoffRetry(1000, 3), 1000, 1000); client.start(); System.out.println(new String(client.getData().forPath(PATH))); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
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; }
@Test(expectedExceptions = {RuntimeException.class}, expectedExceptionsMessageRegExp = ".*init.*") public void testLoad_withZkNodeCacheException() throws Exception { CuratorFramework client = Mockito.mock(CuratorFramework.class); doNothing().when(client).start(); RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser()); source.load(); }
@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); }
@Before public void setup() throws Exception { testZkServer = new TestingServer(true); zookeeperUrl = testZkServer.getConnectString(); client = ConfigurationsUtils.getClient(zookeeperUrl); client.start(); File sensorDir = new File(new File(TestConstants.SAMPLE_CONFIG_PATH), ENRICHMENT.getDirectory()); sensors.addAll(Collections2.transform( Arrays.asList(sensorDir.list()) , s -> Iterables.getFirst(Splitter.on('.').split(s), "null"))); tmpDir = TestUtils.createTempDir(this.getClass().getName()); configDir = TestUtils.createDir(tmpDir, "config"); parsersDir = TestUtils.createDir(configDir, "parsers"); enrichmentsDir = TestUtils.createDir(configDir, "enrichments"); indexingDir = TestUtils.createDir(configDir, "indexing"); pushAllConfigs(); }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/a"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/another/path"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/yet/another/path"); transaction(client); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
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(); } /**
@Test(expectedExceptions = {ConfigurationResolveException.class}) public void testLoad_withValidData() throws Exception { CuratorFramework client = Mockito.mock(CuratorFramework.class); doNothing().when(client).start(); when(client.blockUntilConnected(anyInt(), any())).thenReturn(true); String ruleStr = "invalid string"; GetDataBuilder dataBuilder = new GetDataBuilderImpl(null, null, null, null, false) { @Override public byte[] forPath(String path) throws Exception { return ruleStr.getBytes("UTF-8"); } }; when(client.getData()).thenReturn(dataBuilder); RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser()); source.load(); }
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); } }