コード例 #1
0
 /**
  * Executes launcher.
  *
  * @param configuration the Hadoop configuration for the application
  * @param args the launcher arguments
  * @return the exit status
  */
 public static int exec(Configuration configuration, String... args) {
   if (LOG.isDebugEnabled()) {
     LOG.debug(
         MessageFormat.format(
             "Preparing application: {0}", //$NON-NLS-1$
             Arrays.toString(args)));
   }
   configuration.setBoolean(KEY_LAUNCHER_USED, true);
   LauncherOptions options;
   try {
     options = LauncherOptionsParser.parse(configuration, args);
   } catch (Exception e) {
     LOG.error(
         MessageFormat.format("Exception occurred in launcher: {0}", Arrays.toString(args)), e);
     return LAUNCH_ERROR;
   }
   try {
     Configuration conf = options.getConfiguration();
     conf.setClassLoader(options.getApplicationClassLoader());
     Tool tool;
     try {
       tool = ReflectionUtils.newInstance(options.getApplicationClass(), conf);
     } catch (Exception e) {
       LOG.error(
           MessageFormat.format(
               "Exception occurred in launcher: {0}{1}",
               options.getApplicationClass().getName(), options.getApplicationArguments()),
           e);
       return LAUNCH_ERROR;
     }
     try {
       return launch(conf, tool, options.getApplicationArgumentArray());
     } catch (Exception e) {
       LOG.error(
           MessageFormat.format(
               "Exception occurred in launcher: {0}{1}",
               options.getApplicationClass().getName(), options.getApplicationArguments()),
           e);
       return CLIENT_ERROR;
     }
   } finally {
     disposeClassLoader(options.getApplicationClassLoader());
     for (File file : options.getApplicationCacheDirectories()) {
       if (delete(file) == false) {
         LOG.warn(
             MessageFormat.format("Failed to delete the application cache directory: {0}", file));
       }
     }
   }
 }