use of org.apache.oozie.service.HCatAccessorException 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.oozie.service.HCatAccessorException 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.oozie.service.HCatAccessorException in project oozie by apache.
the class HCatURIHandler method exists.
private boolean exists(URI uri, HCatClient client, boolean closeClient) throws HCatAccessorException {
try {
boolean flag;
HCatURI hcatURI = new HCatURI(uri.toString());
if (!hcatURI.getPartitionMap().isEmpty()) {
List<HCatPartition> partitions = client.getPartitions(hcatURI.getDb(), hcatURI.getTable(), hcatURI.getPartitionMap());
flag = partitions != null && !partitions.isEmpty();
} else {
List<String> tables = client.listTableNamesByPattern(hcatURI.getDb(), hcatURI.getTable());
flag = tables != null && !tables.isEmpty();
}
return (flag);
} catch (ConnectionFailureException e) {
throw new HCatAccessorException(ErrorCode.E1501, e);
} catch (HCatException e) {
throw new HCatAccessorException(ErrorCode.E0902, e);
} catch (URISyntaxException e) {
throw new HCatAccessorException(ErrorCode.E0902, e);
} finally {
closeQuietly(client, null, closeClient);
}
}
use of org.apache.oozie.service.HCatAccessorException 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.oozie.service.HCatAccessorException in project oozie by apache.
the class HCatURIHandler method getMetastoreConnectURI.
private String getMetastoreConnectURI(URI uri) throws HCatAccessorException {
String metastoreURI;
// For unit tests
if (uri.getAuthority().equals("unittest-local")) {
metastoreURI = "";
} else {
// Hardcoding hcat to thrift mapping till support for webhcat(templeton)
// is added
HCatURI hCatURI;
try {
hCatURI = new HCatURI(uri.toString());
metastoreURI = hCatURI.getServerEndPointWithScheme("thrift");
} catch (URISyntaxException e) {
throw new HCatAccessorException(ErrorCode.E0902, e);
}
}
return metastoreURI;
}
Aggregations