Ejemplo n.º 1
0
 @Override
 public void destroy() {
   Set<URIHandler> handlers = new HashSet<URIHandler>();
   handlers.addAll(cache.values());
   for (URIHandler handler : handlers) {
     handler.destroy();
   }
   cache.clear();
 }
Ejemplo n.º 2
0
 /** Initialize classes that need to be shipped for using LauncherURIHandler in the launcher job */
 private void initLauncherClassesToShip() {
   launcherClassesToShip = new HashSet<Class<?>>();
   launcherClassesToShip.add(LauncherURIHandlerFactory.class);
   launcherClassesToShip.add(LauncherURIHandler.class);
   for (URIHandler handler : cache.values()) {
     launcherClassesToShip.add(handler.getLauncherURIHandlerClass());
     List<Class<?>> classes = handler.getClassesForLauncher();
     if (classes != null) {
       launcherClassesToShip.addAll(classes);
     }
   }
   launcherClassesToShip.add(defaultHandler.getLauncherURIHandlerClass());
 }
Ejemplo n.º 3
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");
   }
 }
Ejemplo n.º 4
0
  /** Initialize configuration required for using LauncherURIHandler in the launcher job */
  private void initLauncherURIHandlerConf() {
    launcherConf = new Configuration(false);

    for (URIHandler handler : cache.values()) {
      for (String scheme : handler.getSupportedSchemes()) {
        String schemeConf =
            LauncherURIHandlerFactory.CONF_LAUNCHER_URIHANDLER_SCHEME_PREFIX + scheme;
        launcherConf.set(schemeConf, handler.getLauncherURIHandlerClass().getName());
      }
    }

    for (String scheme : defaultHandler.getSupportedSchemes()) {
      String schemeConf = LauncherURIHandlerFactory.CONF_LAUNCHER_URIHANDLER_SCHEME_PREFIX + scheme;
      launcherConf.set(schemeConf, defaultHandler.getLauncherURIHandlerClass().getName());
    }
  }
Ejemplo n.º 5
0
  private void init(Configuration conf) throws ClassNotFoundException {
    cache = new HashMap<String, URIHandler>();

    String[] classes = ConfigurationService.getStrings(conf, URI_HANDLERS);
    for (String classname : classes) {
      Class<?> clazz = Class.forName(classname.trim());
      URIHandler uriHandler = (URIHandler) ReflectionUtils.newInstance(clazz, null);
      uriHandler.init(conf);
      for (String scheme : uriHandler.getSupportedSchemes()) {
        cache.put(scheme, uriHandler);
      }
    }

    Class<?> defaultClass = conf.getClass(URI_HANDLER_DEFAULT, null);
    defaultHandler =
        (defaultClass == null)
            ? new FSURIHandler()
            : (URIHandler) ReflectionUtils.newInstance(defaultClass, null);
    defaultHandler.init(conf);
    for (String scheme : defaultHandler.getSupportedSchemes()) {
      cache.put(scheme, defaultHandler);
    }

    initLauncherClassesToShip();
    initLauncherURIHandlerConf();

    LOG.info("Loaded urihandlers {0}", Arrays.toString(classes));
    LOG.info("Loaded default urihandler {0}", defaultHandler.getClass().getName());
  }