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);
}
}
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;
}
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();
}
}
}
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");
}
}
Aggregations