Search in sources :

Example 11 with HCatURI

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);
    }
}
Also used : ConnectionFailureException(org.apache.hive.hcatalog.api.ConnectionFailureException) HCatException(org.apache.hive.hcatalog.common.HCatException) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) HCatAccessorException(org.apache.oozie.service.HCatAccessorException) HCatPartition(org.apache.hive.hcatalog.api.HCatPartition)

Example 12 with HCatURI

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;
}
Also used : Element(net.sf.ehcache.Element) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HCatURI(org.apache.oozie.util.HCatURI) Cache(net.sf.ehcache.Cache)

Example 13 with HCatURI

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);
                }
            }
        }
    }
}
Also used : Element(net.sf.ehcache.Element) URISyntaxException(java.net.URISyntaxException) HCatURI(org.apache.oozie.util.HCatURI) Cache(net.sf.ehcache.Cache)

Example 14 with HCatURI

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);
        }
    }
}
Also used : HCatAccessorService(org.apache.oozie.service.HCatAccessorService) Collection(java.util.Collection) HCatURI(org.apache.oozie.util.HCatURI) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 15 with HCatURI

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);
}
Also used : URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) WorkflowJob(org.apache.oozie.client.WorkflowJob) URI(java.net.URI) HCatURI(org.apache.oozie.util.HCatURI)

Aggregations

HCatURI (org.apache.oozie.util.HCatURI)38 URISyntaxException (java.net.URISyntaxException)16 Test (org.junit.Test)13 PartitionDependencyManagerService (org.apache.oozie.service.PartitionDependencyManagerService)11 HCatAccessorService (org.apache.oozie.service.HCatAccessorService)8 ELEvaluator (org.apache.oozie.util.ELEvaluator)6 URI (java.net.URI)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 HCatException (org.apache.hive.hcatalog.common.HCatException)4 HCatAccessorException (org.apache.oozie.service.HCatAccessorException)4 Map (java.util.Map)3 HCatClient (org.apache.hive.hcatalog.api.HCatClient)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Cache (net.sf.ehcache.Cache)2 Element (net.sf.ehcache.Element)2 ConnectionFailureException (org.apache.hive.hcatalog.api.ConnectionFailureException)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2