use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.
the class HCatCredentialHelper method getHCatClient.
/**
* Getting the HCat client.
* @param launcherConfig
* @param principal
* @param server
* @return HCatClient
* @throws HCatException
*/
public HCatClient getHCatClient(Configuration launcherConfig, String principal, String server) throws HCatException {
HiveConf hiveConf = null;
HCatClient hiveclient = null;
hiveConf = new HiveConf();
XLog.getLog(getClass()).debug("getHCatClient: Principal: {0} Server: {1}", principal, server);
// specified a thrift url
hiveConf.set(HIVE_METASTORE_SASL_ENABLED, "true");
hiveConf.set(HIVE_METASTORE_KERBEROS_PRINCIPAL, principal);
hiveConf.set(HIVE_METASTORE_LOCAL, "false");
hiveConf.set(HiveConf.ConfVars.METASTOREURIS.varname, server);
String protection = launcherConfig.get(HADOOP_RPC_PROTECTION, SaslRpcServer.QualityOfProtection.AUTHENTICATION.name().toLowerCase());
XLog.getLog(getClass()).debug("getHCatClient, setting rpc protection to {0}", protection);
hiveConf.set(HADOOP_RPC_PROTECTION, protection);
hiveclient = HCatClient.create(hiveConf);
return hiveclient;
}
use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.
the class HCatURIHandler method registerForNotification.
@Override
public void registerForNotification(URI uri, Configuration conf, String user, String actionID) throws URIHandlerException {
HCatURI hcatURI;
try {
hcatURI = new HCatURI(uri);
} catch (URISyntaxException e) {
throw new URIHandlerException(ErrorCode.E0906, uri, e);
}
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
if (!hcatService.isRegisteredForNotification(hcatURI)) {
HCatClient client = getHCatClient(uri, conf);
try {
String topic = client.getMessageBusTopicName(hcatURI.getDb(), hcatURI.getTable());
if (topic == null) {
return;
}
hcatService.registerForNotification(hcatURI, topic, new HCatMessageHandler(uri.getAuthority()));
} catch (HCatException e) {
throw new HCatAccessorException(ErrorCode.E1501, e);
} finally {
closeQuietly(client, null, true);
}
}
PartitionDependencyManagerService pdmService = Services.get().get(PartitionDependencyManagerService.class);
pdmService.addMissingDependency(hcatURI, actionID);
}
use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.
the class HCatURIHandler method getHCatClient.
private HCatClientWithToken getHCatClient(URI uri, Configuration conf, String user) throws HCatAccessorException {
final HiveConf hiveConf = getHiveConf(uri, conf);
String delegationToken = null;
try {
// Get UGI to doAs() as the specified user
UserGroupInformation ugi = UserGroupInformation.createProxyUser(user, UserGroupInformation.getLoginUser());
// Define the label for the Delegation Token for the HCat instance.
hiveConf.set("hive.metastore.token.signature", "HCatTokenSignature");
if (hiveConf.getBoolean(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname, false)) {
HCatClient tokenClient = null;
try {
// Retrieve Delegation token for HCatalog
tokenClient = HCatClient.create(hiveConf);
delegationToken = tokenClient.getDelegationToken(user, UserGroupInformation.getLoginUser().getUserName());
// Store Delegation token in the UGI
Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
token.decodeFromUrlString(delegationToken);
token.setService(new Text(hiveConf.get("hive.metastore.token.signature")));
ugi.addToken(token);
} finally {
if (tokenClient != null) {
tokenClient.close();
}
}
}
XLog.getLog(HCatURIHandler.class).info("Creating HCatClient for user [{0}] login_user [{1}] and server [{2}] ", user, UserGroupInformation.getLoginUser(), hiveConf.get(HiveConf.ConfVars.METASTOREURIS.varname));
HCatClient hcatClient = ugi.doAs(new PrivilegedExceptionAction<HCatClient>() {
@Override
public HCatClient run() throws Exception {
HCatClient client = HCatClient.create(hiveConf);
return client;
}
});
HCatClientWithToken clientWithToken = new HCatClientWithToken(hcatClient, delegationToken);
return clientWithToken;
} catch (IOException e) {
throw new HCatAccessorException(ErrorCode.E1501, e.getMessage());
} catch (Exception e) {
throw new HCatAccessorException(ErrorCode.E1501, e.getMessage());
}
}
use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.
the class HCatLauncherURIHandler method delete.
@Override
public boolean delete(URI uri, Configuration conf) throws LauncherException {
HCatClient client = getHCatClient(uri, conf);
try {
HCatURI hcatURI = new HCatURI(uri.toString());
if (!hcatURI.getPartitionMap().isEmpty()) {
client.dropPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap(), true);
} else {
client.dropTable(hcatURI.getDb(), hcatURI.getTable(), true);
}
System.out.println("Dropped partitions for " + uri);
return true;
} catch (ConnectionFailureException e) {
throw new LauncherException("Error trying to drop " + uri, e);
} catch (HCatException e) {
throw new LauncherException("Error trying to drop " + uri, e);
} catch (URISyntaxException e) {
throw new LauncherException("Error trying to drop " + uri, e);
} finally {
closeQuietly(client);
}
}
use of org.apache.hive.hcatalog.api.HCatClient in project oozie by apache.
the class HCatCredentialHelper method set.
/**
* This Function will set the HCat token to the credentials
* @param credentials - the credentials
* @param launcherConfig - launcher configuration
* @param principal - principal for HCat server
* @param server - Serevr URI for HCat server
* @throws Exception
*/
public void set(Credentials credentials, Configuration launcherConfig, String principal, String server) throws Exception {
HCatClient client = null;
try {
client = getHCatClient(launcherConfig, principal, server);
XLog.getLog(getClass()).debug("HCatCredentialHelper: set: User name for which token will be asked from HCat: {0}", launcherConfig.get(USER_NAME));
String tokenStrForm = client.getDelegationToken(launcherConfig.get(USER_NAME), UserGroupInformation.getLoginUser().getShortUserName());
Token<DelegationTokenIdentifier> hcatToken = new Token<DelegationTokenIdentifier>();
hcatToken.decodeFromUrlString(tokenStrForm);
credentials.addToken(CredentialsProviderFactory.getUniqueAlias(hcatToken), hcatToken);
XLog.getLog(getClass()).debug("Added the HCat token to launcher's credentials");
} catch (Exception ex) {
XLog.getLog(getClass()).debug("set Exception {0}", ex.getMessage());
throw ex;
} finally {
if (client != null) {
client.close();
}
}
}
Aggregations