Search in sources :

Example 26 with ZKClientService

use of org.apache.twill.zookeeper.ZKClientService in project cdap by caskdata.

the class ZKExtOperationsTest method testSetOrCreate.

@Test
public void testSetOrCreate() throws Exception {
    String path = "/parent/testSetOrCreate";
    ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClient.startAndWait();
    // Create with "1"
    Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
    // Should get "1" back
    Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
    // Set with "2"
    Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
    // Should get "2" back
    Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
    zkClient.stopAndWait();
}
Also used : ZKClientService(org.apache.twill.zookeeper.ZKClientService) Test(org.junit.Test)

Example 27 with ZKClientService

use of org.apache.twill.zookeeper.ZKClientService in project phoenix by apache.

the class TephraTransactionContext method setTransactionClient.

@Override
public ZKClientService setTransactionClient(Configuration config, ReadOnlyProps props, ConnectionInfo connectionInfo) {
    String zkQuorumServersString = props.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
    ZKClientService 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);
    txClient = this.txServiceClient = new TransactionServiceClient(config, pooledClientProvider);
    return txZKClientService;
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) ZKClientService(org.apache.twill.zookeeper.ZKClientService) TephraZKClientService(org.apache.tephra.zookeeper.TephraZKClientService) TephraZKClientService(org.apache.tephra.zookeeper.TephraZKClientService) PooledClientProvider(org.apache.tephra.distributed.PooledClientProvider) TransactionServiceClient(org.apache.tephra.distributed.TransactionServiceClient)

Aggregations

ZKClientService (org.apache.twill.zookeeper.ZKClientService)27 Injector (com.google.inject.Injector)14 Test (org.junit.Test)14 CConfiguration (co.cask.cdap.common.conf.CConfiguration)11 IOException (java.io.IOException)9 ConfigModule (co.cask.cdap.common.guice.ConfigModule)8 ZKClientModule (co.cask.cdap.common.guice.ZKClientModule)8 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)7 AbstractModule (com.google.inject.AbstractModule)6 Configuration (org.apache.hadoop.conf.Configuration)6 DataFabricModules (co.cask.cdap.data.runtime.DataFabricModules)5 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)5 TransactionMetricsModule (co.cask.cdap.data.runtime.TransactionMetricsModule)5 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)5 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)5 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)5 DefaultOwnerAdmin (co.cask.cdap.security.impersonation.DefaultOwnerAdmin)5 UnsupportedUGIProvider (co.cask.cdap.security.impersonation.UnsupportedUGIProvider)5 ZKDiscoveryService (org.apache.twill.discovery.ZKDiscoveryService)5 SystemDatasetRuntimeModule (co.cask.cdap.data.runtime.SystemDatasetRuntimeModule)4