org.apache.twill.zookeeper.ZKClientServices Java Examples
The following examples show how to use
org.apache.twill.zookeeper.ZKClientServices.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZKModule.java From phoenix-tephra with Apache License 2.0 | 6 votes |
@Provides @Singleton private ZKClientService provideZKClientService(Configuration conf) { String zkStr = conf.get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM); if (zkStr == null) { // Default to HBase one. zkStr = conf.get(TxConstants.HBase.ZOOKEEPER_QUORUM); } int timeOut = conf.getInt(TxConstants.HBase.ZK_SESSION_TIMEOUT, TxConstants.HBase.DEFAULT_ZK_SESSION_TIMEOUT); ZKClientService zkClientService = new TephraZKClientService(zkStr, timeOut, null, ArrayListMultimap.<String, byte[]>create()); return ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(zkClientService, RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS) ) ) ); }
Example #2
Source File: TephraTransactionProvider.java From phoenix with Apache License 2.0 | 6 votes |
@Override public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connInfo, int port) { config.setInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, port); int retryTimeOut = config.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC); ZKClientService zkClient = ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( ZKClientService.Builder.of(connInfo.getZookeeperConnectionString()) .setSessionTimeout(config.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT)) .build(), RetryStrategies.exponentialDelay(500, retryTimeOut, TimeUnit.MILLISECONDS) ) ) ); DiscoveryService discovery = new ZKDiscoveryService(zkClient); TransactionManager txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector()); TransactionService txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager)); TephraTransactionService service = new TephraTransactionService(zkClient, txService); service.start(); return service; }
Example #3
Source File: ZKDiscoveryServiceTest.java From twill with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { zkServer = InMemoryZKServer.builder().setTickTime(100000).build(); zkServer.startAndWait(); zkClient = ZKClientServices.delegate( ZKClients.retryOnFailure( ZKClients.reWatchOnExpire( ZKClientService.Builder.of(zkServer.getConnectionStr()).build()), RetryStrategies.fixDelay(1, TimeUnit.SECONDS))); zkClient.startAndWait(); }
Example #4
Source File: ServiceMain.java From twill with Apache License 2.0 | 5 votes |
/** * Creates a {@link ZKClientService}. */ protected final ZKClientService createZKClient() { TwillRuntimeSpecification twillRuntimeSpec = getTwillRuntimeSpecification(); return ZKClientServices.delegate( ZKClients.namespace( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure( ZKClientService.Builder.of(twillRuntimeSpec.getZkConnectStr()).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS) ) ), "/" + twillRuntimeSpec.getTwillAppName() ) ); }
Example #5
Source File: YarnTwillRunnerService.java From twill with Apache License 2.0 | 5 votes |
private ZKClientService getZKClientService(String zkConnect) { return ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnect) .setSessionTimeout(ZK_TIMEOUT) .build(), RetryStrategies.exponentialDelay(100, 2000, TimeUnit.MILLISECONDS)))); }
Example #6
Source File: KafkaAppender.java From twill with Apache License 2.0 | 5 votes |
@Override public void start() { Preconditions.checkNotNull(zkConnectStr); eventConverter = new LogEventConverter(hostname, runnableName); scheduler = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory(PUBLISH_THREAD_NAME)); zkClientService = ZKClientServices.delegate( ZKClients.reWatchOnExpire( ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnectStr).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS)))); kafkaClient = new ZKKafkaClientService(zkClientService); Futures.addCallback(Services.chainStart(zkClientService, kafkaClient), new FutureCallback<List<ListenableFuture<Service.State>>>() { @Override public void onSuccess(List<ListenableFuture<Service.State>> result) { for (ListenableFuture<Service.State> future : result) { Preconditions.checkState(Futures.getUnchecked(future) == Service.State.RUNNING, "Service is not running."); } addInfo("Kafka client started: " + zkConnectStr); scheduler.scheduleWithFixedDelay(flushTask, 0, flushPeriod, TimeUnit.MILLISECONDS); } @Override public void onFailure(Throwable t) { // Fail to talk to kafka. Other than logging, what can be done? addError("Failed to start kafka appender.", t); } }, Threads.SAME_THREAD_EXECUTOR); super.start(); }
Example #7
Source File: ZKDiscoveryServiceTest.java From twill with Apache License 2.0 | 4 votes |
@Test (timeout = 30000) public void testDoubleRegister() throws Exception { Map.Entry<DiscoveryService, DiscoveryServiceClient> entry = create(); try { DiscoveryService discoveryService = entry.getKey(); DiscoveryServiceClient discoveryServiceClient = entry.getValue(); // Register on the same host port, it shouldn't fail. Cancellable cancellable = register(discoveryService, "test_double_reg", "localhost", 54321); Cancellable cancellable2 = register(discoveryService, "test_double_reg", "localhost", 54321); ServiceDiscovered discoverables = discoveryServiceClient.discover("test_double_reg"); Assert.assertTrue(waitTillExpected(1, discoverables)); cancellable.cancel(); cancellable2.cancel(); // Register again with two different clients, but killing session of the first one. final ZKClientService zkClient2 = ZKClientServices.delegate( ZKClients.retryOnFailure( ZKClients.reWatchOnExpire( ZKClientService.Builder.of(zkServer.getConnectionStr()).build()), RetryStrategies.fixDelay(1, TimeUnit.SECONDS))); zkClient2.startAndWait(); try (ZKDiscoveryService discoveryService2 = new ZKDiscoveryService(zkClient2)) { cancellable2 = register(discoveryService2, "test_multi_client", "localhost", 54321); // Schedule a thread to shutdown zkClient2. new Thread() { @Override public void run() { try { TimeUnit.SECONDS.sleep(2); zkClient2.stopAndWait(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } } }.start(); // This call would block until zkClient2 is shutdown. cancellable = register(discoveryService, "test_multi_client", "localhost", 54321); cancellable.cancel(); } finally { zkClient2.stopAndWait(); } } finally { closeServices(entry); } }