Search in sources :

Example 6 with HCatClient

use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.

the class HCatURIHandler method delete.

@Override
public void delete(URI uri, Configuration conf, String user) throws URIHandlerException {
    HCatClientWithToken client = null;
    HCatClient hCatClient = null;
    try {
        HCatURI hcatUri = new HCatURI(uri);
        client = getHCatClient(uri, conf, user);
        hCatClient = client.getHCatClient();
        if (!hcatUri.getPartitionMap().isEmpty()) {
            hCatClient.dropPartitions(hcatUri.getDb(), hcatUri.getTable(), hcatUri.getPartitionMap(), true);
        } else {
            hCatClient.dropTable(hcatUri.getDb(), hcatUri.getTable(), true);
        }
    } catch (URISyntaxException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e);
    } catch (HCatException e) {
        throw new HCatAccessorException(ErrorCode.E1501, e);
    } finally {
        closeQuietly(hCatClient, client != null ? client.getDelegationToken() : null, true);
    }
}
Also used : HCatClient(org.apache.hive.hcatalog.api.HCatClient) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException)

Example 7 with HCatClient

use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.

the class HCatURIHandler method getContext.

@Override
public Context getContext(URI uri, Configuration conf, String user, boolean readOnly) throws URIHandlerException {
    HCatContext context = null;
    // For write operations, perform doAs as user
    if (readOnly) {
        HCatClient client = getHCatClient(uri, conf);
        context = new HCatContext(conf, user, client);
    } else {
        HCatClientWithToken client = getHCatClient(uri, conf, user);
        context = new HCatContext(conf, user, client);
    }
    return context;
}
Also used : HCatClient(org.apache.hive.hcatalog.api.HCatClient)

Example 8 with HCatClient

use of org.apache.hive.hcatalog.api.HCatClient in project storm by apache.

the class AutoHiveNimbus method getDelegationToken.

private Token<DelegationTokenIdentifier> getDelegationToken(HiveConf hcatConf, String metaStoreServicePrincipal, String topologySubmitterUser) throws IOException {
    LOG.info("Creating delegation tokens for principal={}", metaStoreServicePrincipal);
    HCatClient hcatClient = null;
    try {
        hcatClient = HCatClient.create(hcatConf);
        String delegationToken = hcatClient.getDelegationToken(topologySubmitterUser, metaStoreServicePrincipal);
        Token<DelegationTokenIdentifier> delegationTokenId = new Token<DelegationTokenIdentifier>();
        delegationTokenId.decodeFromUrlString(delegationToken);
        DelegationTokenIdentifier d = new DelegationTokenIdentifier();
        d.readFields(new DataInputStream(new ByteArrayInputStream(delegationTokenId.getIdentifier())));
        LOG.info("Created Delegation Token for : " + d.getUser());
        return delegationTokenId;
    } finally {
        if (hcatClient != null) {
            hcatClient.close();
        }
    }
}
Also used : HCatClient(org.apache.hive.hcatalog.api.HCatClient) DelegationTokenIdentifier(org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) Token(org.apache.hadoop.security.token.Token) DataInputStream(java.io.DataInputStream)

Example 9 with HCatClient

use of org.apache.hive.hcatalog.api.HCatClient in project storm by apache.

the class AutoHiveNimbus method renewToken.

private long renewToken(Token token, String metaStoreUri, String hiveMetaStorePrincipal) {
    HCatClient hcatClient = null;
    if (UserGroupInformation.isSecurityEnabled()) {
        try {
            String tokenStr = token.encodeToUrlString();
            HiveConf hcatConf = createHiveConf(metaStoreUri, hiveMetaStorePrincipal);
            LOG.debug("renewing delegation tokens for principal={}", hiveMetaStorePrincipal);
            hcatClient = HCatClient.create(hcatConf);
            Long expiryTime = hcatClient.renewDelegationToken(tokenStr);
            LOG.info("Renewed delegation token. new expiryTime={}", expiryTime);
            return expiryTime;
        } catch (Exception ex) {
            throw new RuntimeException("Failed to renew delegation tokens.", ex);
        } finally {
            if (hcatClient != null) {
                try {
                    hcatClient.close();
                } catch (HCatException e) {
                    LOG.error(" Exception", e);
                }
            }
        }
    } else {
        throw new RuntimeException("Security is not enabled for Hadoop");
    }
}
Also used : HCatClient(org.apache.hive.hcatalog.api.HCatClient) HCatException(org.apache.hive.hcatalog.common.HCatException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) HCatException(org.apache.hive.hcatalog.common.HCatException) IOException(java.io.IOException)

Aggregations

HCatClient (org.apache.hive.hcatalog.api.HCatClient)9 HCatException (org.apache.hive.hcatalog.common.HCatException)6 URISyntaxException (java.net.URISyntaxException)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)3 Token (org.apache.hadoop.security.token.Token)3 HCatAccessorException (org.apache.oozie.service.HCatAccessorException)3 HCatURI (org.apache.oozie.util.HCatURI)3 IOException (java.io.IOException)2 DelegationTokenIdentifier (org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier)2 ConnectionFailureException (org.apache.hive.hcatalog.api.ConnectionFailureException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DelegationTokenIdentifier (org.apache.hadoop.hive.thrift.DelegationTokenIdentifier)1 Text (org.apache.hadoop.io.Text)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 HCatMessageHandler (org.apache.oozie.dependency.hcat.HCatMessageHandler)1 HCatAccessorService (org.apache.oozie.service.HCatAccessorService)1 PartitionDependencyManagerService (org.apache.oozie.service.PartitionDependencyManagerService)1