Пример #1
0
 /**
  * Cleanup output-events directories
  *
  * @param eAction coordinator action xml
  */
 @SuppressWarnings("unchecked")
 private void cleanupOutputEvents(Element eAction) 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);
           Configuration actionConf = null;
           try {
             actionConf = new XConfiguration(new StringReader(coordJob.getConf()));
           } catch (IOException e) {
             throw new CommandException(
                 ErrorCode.E0907, "failed to read coord job conf to clean up output data");
           }
           HashMap<String, Context> contextMap = new HashMap<String, Context>();
           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 (!contextMap.containsKey(schemeWithAuthority)) {
                 Context context = handler.getContext(uri, actionConf, coordJob.getUser(), false);
                 contextMap.put(schemeWithAuthority, context);
               }
               handler.delete(uri, contextMap.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());
           } finally {
             Iterator<Entry<String, Context>> itr = contextMap.entrySet().iterator();
             while (itr.hasNext()) {
               Entry<String, Context> entry = itr.next();
               entry.getValue().destroy();
               itr.remove();
             }
           }
         }
       }
     }
   } else {
     LOG.info("No output-events defined in coordinator xml. Therefore nothing to cleanup");
   }
 }