Search in sources :

Example 1 with URIHandlerException

use of org.apache.oozie.dependency.URIHandlerException in project oozie by apache.

the class CoordRerunXCommand method cleanupOutputEvents.

/**
 * Cleanup output-events directories
 *
 * @param eAction coordinator action xml
 */
@SuppressWarnings("unchecked")
private void cleanupOutputEvents(Element eAction, Configuration coordJobConf, Map<String, Context> uriHandlerContextMap) throws CommandException {
    Element outputList = eAction.getChild("output-events", eAction.getNamespace());
    if (outputList != null) {
        for (Element data : (List<Element>) outputList.getChildren("data-out", eAction.getNamespace())) {
            String nocleanup = data.getAttributeValue("nocleanup");
            if (data.getChild("uris", data.getNamespace()) != null && (nocleanup == null || !nocleanup.equals("true"))) {
                String uris = data.getChild("uris", data.getNamespace()).getTextTrim();
                if (uris != null) {
                    String[] uriArr = uris.split(CoordELFunctions.INSTANCE_SEPARATOR);
                    try {
                        for (String uriStr : uriArr) {
                            URI uri = new URI(uriStr);
                            URIHandler handler = Services.get().get(URIHandlerService.class).getURIHandler(uri);
                            String schemeWithAuthority = uri.getScheme() + "://" + uri.getAuthority();
                            if (!uriHandlerContextMap.containsKey(schemeWithAuthority)) {
                                Context context = handler.getContext(uri, coordJobConf, coordJob.getUser(), false);
                                uriHandlerContextMap.put(schemeWithAuthority, context);
                            }
                            handler.delete(uri, uriHandlerContextMap.get(schemeWithAuthority));
                            LOG.info("Cleanup the output data " + uri.toString());
                        }
                    } catch (URISyntaxException e) {
                        throw new CommandException(ErrorCode.E0907, e.getMessage());
                    } catch (URIHandlerException e) {
                        throw new CommandException(ErrorCode.E0907, e.getMessage());
                    }
                }
            }
        }
    } else {
        LOG.info("No output-events defined in coordinator xml. Therefore nothing to cleanup");
    }
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) Element(org.jdom.Element) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) List(java.util.List) URISyntaxException(java.net.URISyntaxException) CommandException(org.apache.oozie.command.CommandException) URI(java.net.URI)

Example 2 with URIHandlerException

use of org.apache.oozie.dependency.URIHandlerException in project oozie by apache.

the class CoordOldInputDependency method getMissingDependencies.

public Map<String, ActionDependency> getMissingDependencies(CoordinatorActionBean coordAction) throws CommandException, IOException, JDOMException {
    Map<String, ActionDependency> dependenciesMap = null;
    try {
        dependenciesMap = getDependency(coordAction);
    } catch (URIHandlerException e) {
        throw new IOException(e);
    }
    StringBuilder nonExistList = new StringBuilder();
    StringBuilder nonResolvedList = new StringBuilder();
    CoordCommandUtils.getResolvedList(getMissingDependencies(), nonExistList, nonResolvedList);
    Set<String> missingSets = new HashSet<String>(Arrays.asList(nonExistList.toString().split(CoordELFunctions.INSTANCE_SEPARATOR)));
    missingSets.addAll(Arrays.asList(nonResolvedList.toString().split(CoordCommandUtils.RESOLVED_UNRESOLVED_SEPARATOR)));
    for (Iterator<Map.Entry<String, ActionDependency>> it = dependenciesMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<String, ActionDependency> entry = it.next();
        ActionDependency dependency = entry.getValue();
        dependency.getMissingDependencies().retainAll(missingSets);
        if (dependency.getUriTemplate() != null) {
            for (int i = 0; i < dependency.getMissingDependencies().size(); i++) {
                if (dependency.getMissingDependencies().get(i).trim().startsWith("${coord:")) {
                    dependency.getMissingDependencies().set(i, dependency.getMissingDependencies().get(i) + " -> " + dependency.getUriTemplate());
                }
            }
        }
        if (dependenciesMap.get(entry.getKey()).getMissingDependencies().isEmpty()) {
            it.remove();
        }
    }
    return dependenciesMap;
}
Also used : IOException(java.io.IOException) ActionDependency(org.apache.oozie.dependency.ActionDependency) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

URIHandlerException (org.apache.oozie.dependency.URIHandlerException)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 CommandException (org.apache.oozie.command.CommandException)1 ActionDependency (org.apache.oozie.dependency.ActionDependency)1 URIHandler (org.apache.oozie.dependency.URIHandler)1 Context (org.apache.oozie.dependency.URIHandler.Context)1 URIHandlerService (org.apache.oozie.service.URIHandlerService)1 Element (org.jdom.Element)1