Search in sources :

Example 1 with InMemoryDiscoveryService

use of org.apache.twill.discovery.InMemoryDiscoveryService in project hive by apache.

the class TephraHBaseConnection method connect.

@Override
public void connect() throws IOException {
    super.connect();
    if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
        LOG.debug("Using an in memory client transaction system for testing");
        TransactionManager txnMgr = new TransactionManager(conf);
        txnMgr.startAndWait();
        txnClient = new InMemoryTxSystemClient(txnMgr);
    } else {
        // TODO should enable use of ZKDiscoveryService if users want it
        LOG.debug("Using real client transaction system for production");
        txnClient = new TransactionServiceClient(conf, new ThreadLocalClientProvider(conf, new InMemoryDiscoveryService()));
    }
    for (String tableName : HBaseReadWrite.tableNames) {
        txnTables.put(tableName, new TransactionAwareHTable(super.getHBaseTable(tableName, true)));
    }
    txn = new TransactionContext(txnClient, txnTables.values());
}
Also used : TransactionAwareHTable(co.cask.tephra.hbase10.TransactionAwareHTable) TransactionManager(co.cask.tephra.TransactionManager) TransactionContext(co.cask.tephra.TransactionContext) ThreadLocalClientProvider(co.cask.tephra.distributed.ThreadLocalClientProvider) InMemoryTxSystemClient(co.cask.tephra.inmemory.InMemoryTxSystemClient) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) TransactionServiceClient(co.cask.tephra.distributed.TransactionServiceClient)

Example 2 with InMemoryDiscoveryService

use of org.apache.twill.discovery.InMemoryDiscoveryService in project cdap by caskdata.

the class UGIProviderTest method testRemoteUGIProvider.

@Test
public void testRemoteUGIProvider() throws Exception {
    // Starts a mock server to handle remote UGI requests
    final NettyHttpService httpService = NettyHttpService.builder("remoteUGITest").addHttpHandlers(Collections.singleton(new UGIProviderTestHandler())).build();
    httpService.startAndWait();
    setKeytabDir(localKeytabDirPath.getAbsolutePath());
    OwnerAdmin ownerAdmin = getOwnerAdmin();
    // add an owner for stream
    ownerAdmin.add(aliceEntity, aliceKerberosPrincipalId);
    try {
        InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
        discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
        RemoteUGIProvider ugiProvider = new RemoteUGIProvider(cConf, discoveryService, locationFactory);
        ImpersonationRequest aliceImpRequest = new ImpersonationRequest(aliceEntity, ImpersonatedOpType.OTHER);
        UGIWithPrincipal aliceUGIWithPrincipal = ugiProvider.getConfiguredUGI(aliceImpRequest);
        // Shouldn't be a kerberos UGI
        Assert.assertFalse(aliceUGIWithPrincipal.getUGI().hasKerberosCredentials());
        // Validate the credentials
        Token<? extends TokenIdentifier> token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("entity"));
        Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
        Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
        Assert.assertEquals(new Text("entity"), token.getKind());
        Assert.assertEquals(new Text("service"), token.getService());
        token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("opType"));
        Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
        Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
        Assert.assertEquals(new Text("opType"), token.getKind());
        Assert.assertEquals(new Text("service"), token.getService());
        // Fetch it again, it should return the same UGI due to caching
        Assert.assertSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
        // Invalid the cache and fetch it again. A different UGI should be returned
        ugiProvider.invalidCache();
        Assert.assertNotSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
    } finally {
        httpService.stopAndWait();
    }
    // cleanup
    ownerAdmin.delete(aliceEntity);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) NettyHttpService(co.cask.http.NettyHttpService) Text(org.apache.hadoop.io.Text) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) Test(org.junit.Test)

Aggregations

InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)2 NettyHttpService (co.cask.http.NettyHttpService)1 TransactionContext (co.cask.tephra.TransactionContext)1 TransactionManager (co.cask.tephra.TransactionManager)1 ThreadLocalClientProvider (co.cask.tephra.distributed.ThreadLocalClientProvider)1 TransactionServiceClient (co.cask.tephra.distributed.TransactionServiceClient)1 TransactionAwareHTable (co.cask.tephra.hbase10.TransactionAwareHTable)1 InMemoryTxSystemClient (co.cask.tephra.inmemory.InMemoryTxSystemClient)1 Text (org.apache.hadoop.io.Text)1 Discoverable (org.apache.twill.discovery.Discoverable)1 Test (org.junit.Test)1