use of org.apache.oozie.util.HCatURI 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.util.HCatURI in project oozie by apache.
the class EhcacheHCatDependencyCache method getWaitingActions.
@Override
public Collection<String> getWaitingActions(HCatURI hcatURI) {
Collection<String> actionIDs = null;
Cache missingCache = missingDepsByServer.get(canonicalizeHostname(hcatURI.getServer()));
if (missingCache != null) {
SortedPKV sortedPKV = new SortedPKV(hcatURI.getPartitionMap());
String missingKey = hcatURI.getDb() + TABLE_DELIMITER + hcatURI.getTable() + TABLE_DELIMITER + sortedPKV.getPartKeys() + TABLE_DELIMITER + sortedPKV.getPartVals();
Element element = missingCache.get(missingKey);
if (element != null) {
WaitingActions waitingActions = (WaitingActions) element.getObjectValue();
actionIDs = new ArrayList<String>();
URI uri = hcatURI.getURI();
String uriString = null;
try {
uriString = new URI(uri.getScheme(), canonicalizeHostname(uri.getAuthority()), uri.getPath(), uri.getQuery(), uri.getFragment()).toString();
} catch (URISyntaxException e) {
uriString = hcatURI.toURIString();
}
for (WaitingAction action : waitingActions.getWaitingActions()) {
if (action.getDependencyURI().equals(uriString)) {
actionIDs.add(action.getActionID());
}
}
}
}
return actionIDs;
}
use of org.apache.oozie.util.HCatURI in project oozie by apache.
the class EhcacheHCatDependencyCache method removeNonWaitingCoordActions.
@Override
public void removeNonWaitingCoordActions(Set<String> staleActions) {
for (Entry<String, Cache> entry : missingDepsByServer.entrySet()) {
Cache missingCache = entry.getValue();
if (missingCache == null) {
continue;
}
synchronized (missingCache) {
for (Object key : missingCache.getKeys()) {
Element element = missingCache.get(key);
if (element == null) {
continue;
}
Collection<WaitingAction> waitingActions = ((WaitingActions) element.getObjectValue()).getWaitingActions();
Iterator<WaitingAction> wactionItr = waitingActions.iterator();
HCatURI hcatURI = null;
while (wactionItr.hasNext()) {
WaitingAction waction = wactionItr.next();
if (staleActions.contains(waction.getActionID())) {
try {
hcatURI = new HCatURI(waction.getDependencyURI());
wactionItr.remove();
} catch (URISyntaxException e) {
continue;
}
}
}
if (waitingActions.isEmpty() && hcatURI != null) {
missingCache.remove(key);
// Decrement partition key pattern count if the cache entry is removed
SortedPKV sortedPKV = new SortedPKV(hcatURI.getPartitionMap());
String partKeys = sortedPKV.getPartKeys();
String tableKey = canonicalizeHostname(hcatURI.getServer()) + TABLE_DELIMITER + hcatURI.getDb() + TABLE_DELIMITER + hcatURI.getTable();
String hcatURIStr = hcatURI.toURIString();
decrementPartKeyPatternCount(tableKey, partKeys, hcatURIStr);
}
}
}
}
}
use of org.apache.oozie.util.HCatURI in project oozie by apache.
the class SimpleHCatDependencyCache method removeNonWaitingCoordActions.
@Override
public void removeNonWaitingCoordActions(Set<String> coordActions) {
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
for (String coordActionId : coordActions) {
LOG.info("Removing non waiting coord action {0} from partition dependency map", coordActionId);
synchronized (actionPartitionMap) {
Map<String, Collection<String>> partitionMap = actionPartitionMap.get(coordActionId);
if (partitionMap != null) {
Iterator<String> tableItr = partitionMap.keySet().iterator();
while (tableItr.hasNext()) {
String tableKey = tableItr.next();
HCatURI hcatUri = null;
Map<String, Map<String, Collection<WaitingAction>>> partKeyPatterns = missingDeps.get(tableKey);
if (partKeyPatterns != null) {
synchronized (partKeyPatterns) {
Collection<String> partKeys = partitionMap.get(tableKey);
if (partKeys != null) {
hcatUri = removePartitions(coordActionId, partKeys, partKeyPatterns);
}
}
if (partKeyPatterns.size() == 0) {
tableItr.remove();
if (hcatUri != null) {
// Close JMS session. Stop listening on topic
hcatService.unregisterFromNotification(hcatUri);
}
}
}
}
}
actionPartitionMap.remove(coordActionId);
}
}
}
use of org.apache.oozie.util.HCatURI in project oozie by apache.
the class HCatELFunctions method hcat_exists.
/* Workflow Parameterization EL functions */
/**
* Return true if partitions exists or false if not.
*
* @param uri hcatalog partition uri.
* @return <code>true</code> if the uri exists, <code>false</code> if it does not.
* @throws Exception
*/
public static boolean hcat_exists(String uri) throws Exception {
URI hcatURI = new URI(uri);
URIHandlerService uriService = Services.get().get(URIHandlerService.class);
URIHandler handler = uriService.getURIHandler(hcatURI);
WorkflowJob workflow = DagELFunctions.getWorkflow();
String user = workflow.getUser();
return handler.exists(hcatURI, EMPTY_CONF, user);
}
Aggregations