Пример #1
0
  public static void finish() {
    if (!makeThunk) {
      Record.finish();

      if (monitor) monitorThread.finish();
      setExecStatus("done", false);
      outputMap.printEasy(getFile("output.map"));
      StopWatch.getStats().printEasy(getFile("time.map"));
      if (create) stderr.println(virtualExecDir);
      if (LogInfo.getNumErrors() > 0 || LogInfo.getNumWarnings() > 0)
        stderr.printf("%d errors, %d warnings\n", LogInfo.getNumErrors(), LogInfo.getNumWarnings());
      if (startMainTrack) end_track();
    }

    System.exit(exitCode);
  }
Пример #2
0
 // This should be all we need to put in a main function.
 // args are the commandline arguments
 // First object is the Runnable object to call run on.
 // All of them are objects whose options args is to supposed to populate.
 public static void run(String[] args, Object... objects) {
   init(args, objects);
   if (makeThunk) {
     setExecStatus("thunk", true);
     printOutputMap(Execution.getFile("output.map"));
     List<String> cmd = new ArrayList();
     cmd.add("java");
     if (thunkJavaOpts != null) cmd.add(thunkJavaOpts);
     cmd.add("-cp " + StrUtils.join(jarFiles, ":") + ":" + System.getProperty("java.class.path"));
     cmd.addAll(
         ListUtils.newList(
             objects[0].getClass().getName(),
             "++" + virtualExecDir, // Load these options
             // Next time when we run, just run in the same path that we used to create the thunk
             "-execDir",
             virtualExecDir,
             "-overwriteExecDir"));
     IOUtils.printLinesHard(
         Execution.getFile("job.map"),
         ListUtils.newList(
             "workingDir\t" + SysInfoUtils.getcwd(), // Run from current directory
             "command\t" + StrUtils.join(cmd, "\t"),
             "priority\t" + thunkPriority));
   } else {
     if (dontCatchExceptions) {
       ((Runnable) objects[0]).run();
     } else {
       try {
         ((Runnable) objects[0]).run();
       } catch (Throwable t) {
         raiseException(t);
       }
     }
   }
   finish();
 }
Пример #3
0
 private static void mkdirHard(File f) {
   if (!f.mkdir()) {
     stderr.println("Cannot create directory: " + f);
     System.exit(1);
   }
 }
Пример #4
0
  public static void init(String[] args, Object... objects) {
    // Parse options
    parser = new OptionsParser();
    parser.doRegister("log", LogInfo.class);
    parser.doRegister("exec", Execution.class);
    parser.doRegisterAll(objects);
    // These options are specific to the execution, so we don't want to overwrite them
    // with a previous execution's.
    parser.setDefaultDirFileName("options.map");
    parser.setIgnoreOptsFromFileName(
        "options.map",
        ListUtils.newList(
            "log.file",
            "exec.execDir",
            "exec.execPoolDir",
            "exec.actualPoolDir",
            "exec.makeThunk"));
    if (!parser.doParse(args)) System.exit(1);

    // Load classes
    if (jarFiles.size() > 0) {
      List<String> names = new ArrayList();
      for (String jarFile : jarFiles) names.add(new File(jarFile).getName());
      stderr.println("Loading JAR files: " + StrUtils.join(names));
      for (String jarFile : jarFiles) // Load classes
      ClassInitializer.initializeJar(jarFile);
    }
    // Set character encoding
    if (charEncoding != null) CharEncUtils.setCharEncoding(charEncoding);

    if (printOptionsAndExit) { // Just print options and exit
      parser.doGetOptionPairs().print(stdout);
      System.exit(0);
    }

    // Create a new directory
    if (create) {
      createVirtualExecDir();
      stderr.println(virtualExecDir);
      if (!makeThunk) LogInfo.file = getFile("log");

      // Copy the Jar files for reference
      if (!makeThunk) {
        for (String jarFile : jarFiles)
          Utils.systemHard(String.format("cp %s %s", jarFile, virtualExecDir));
      }
    } else {
      LogInfo.file = "";
    }

    if (!makeThunk) {
      LogInfo.init();
      if (startMainTrack) track("main()", true);
    }

    // Output options
    if (!makeThunk && virtualExecDir != null) logs("Execution directory: " + virtualExecDir);
    if (!makeThunk) getInfo().printEasy(getFile("info.map"));
    printOptions();
    if (create && addToView.size() > 0)
      IOUtils.printLinesHard(Execution.getFile("addToView"), addToView);

    // Start monitoring
    if (!makeThunk && monitor) {
      monitorThread = new MonitorThread();
      monitorThread.start();
    }

    if (!makeThunk) Record.init(Execution.getFile("record"));
  }