use of org.apache.twill.discovery.ZKDiscoveryService in project phoenix by apache.
the class ConnectionQueryServicesImpl method initTxServiceClient.
private void initTxServiceClient() {
String zkQuorumServersString = this.getProps().get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM);
if (zkQuorumServersString == null) {
zkQuorumServersString = connectionInfo.getZookeeperQuorum() + ":" + connectionInfo.getPort();
}
int timeOut = props.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
// Create instance of the tephra zookeeper client
txZKClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
txZKClientService.startAndWait();
ZKDiscoveryService zkDiscoveryService = new ZKDiscoveryService(txZKClientService);
PooledClientProvider pooledClientProvider = new PooledClientProvider(config, zkDiscoveryService);
this.txServiceClient = new TransactionServiceClient(config, pooledClientProvider);
}
use of org.apache.twill.discovery.ZKDiscoveryService in project phoenix by apache.
the class BaseTest method setupTxManager.
protected static void setupTxManager() throws SQLException, IOException {
ConnectionInfo connInfo = ConnectionInfo.create(getUrl());
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, 2000, TimeUnit.MILLISECONDS))));
zkClient.startAndWait();
DiscoveryService discovery = new ZKDiscoveryService(zkClient);
txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
txService.startAndWait();
}
use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.
the class ResourceBalancerServiceTest method testResourceBalancerService.
@Test
public void testResourceBalancerService() throws Exception {
// Simple test for resource balancer does react to discovery changes correct
// More detailed tests are in ResourceCoordinatorTest, which the ResourceBalancerService depends on
ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
zkClient.startAndWait();
try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
// Test the failure on stop case
final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, false);
stopFailureService.startAndWait();
// Should get all four partitions
Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable<Set<Integer>>() {
@Override
public Set<Integer> call() throws Exception {
return stopFailureService.getPartitions();
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Register a new discoverable, this should trigger a partition change in the resource balancer service
Cancellable cancellable = discoveryService.register(new Discoverable("test", new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234)));
try {
// Should get reduced to two partitions
Tasks.waitFor(2, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return stopFailureService.getPartitions().size();
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
} finally {
cancellable.cancel();
}
} finally {
zkClient.stopAndWait();
}
}
use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.
the class ResourceBalancerServiceTest method testServiceStopFailure.
@Test
public void testServiceStopFailure() throws Exception {
ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
zkClient.startAndWait();
try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
// Test the failure on stop case
final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, true);
stopFailureService.startAndWait();
// Should get four partitions
Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable<Set<Integer>>() {
@Override
public Set<Integer> call() throws Exception {
return stopFailureService.getPartitions();
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Register a new discoverable, this should trigger a partition change in the resource balancer service
Cancellable cancellable = discoveryService.register(new Discoverable("test", new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234)));
try {
// When there is exception thrown by the underlying service during partition change,
// the resource balancer service should fail.
Tasks.waitFor(Service.State.FAILED, new Callable<Service.State>() {
@Override
public Service.State call() throws Exception {
return stopFailureService.state();
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
} finally {
cancellable.cancel();
}
} finally {
zkClient.stopAndWait();
}
}
use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.
the class ResourceBalancerServiceTest method testServiceStartFailure.
@Test
public void testServiceStartFailure() throws Exception {
ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
zkClient.startAndWait();
try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
// Test the failure on start case
final TestBalancerService startFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, true, false);
startFailureService.startAndWait();
// The resource balance service should fail
Tasks.waitFor(Service.State.FAILED, new Callable<Service.State>() {
@Override
public Service.State call() throws Exception {
return startFailureService.state();
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
} finally {
zkClient.stopAndWait();
}
}
Aggregations