Ejemplo n.º 1
0
 @Test(dataProvider = "dates")
 public void shouldParseDates(final String input, final String output) {
   try {
     final DateTime date = ReportUtils.parseDate(input, "start");
     Assert.assertEquals(date.toString("MM-dd-yyyy HH:mm:ss"), output);
   } catch (Exception e) {
     Assert.assertEquals(
         MprcException.getDetailedMessage(e), output, "Exception message does not match");
   }
 }
Ejemplo n.º 2
0
  @Override
  public ExitCode run(final SwiftEnvironment environment) {
    if (environment.getParameters().size() < 1) {
      throw new MprcException(
          "Missing path to configuration file.\nUsage: reformat-config <config> [<result>]");
    }

    final File file = new File(environment.getParameters().get(0));

    final PrintWriter printWriter;
    if (environment.getParameters().size() >= 2) {
      String pathname = environment.getParameters().get(1);
      try {
        printWriter = new PrintWriter(new File(pathname));
      } catch (FileNotFoundException e) {
        environment.logCommandError(
            "Could not open file for writing: "
                + pathname
                + "\n"
                + MprcException.getDetailedMessage(e));
        return ExitCode.Error;
      }
    } else {
      printWriter = new PrintWriter(System.out);
    }

    final AppConfigReader reader = new AppConfigReader(file, getFactory());
    try {
      reader.load(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(reader);
    }

    AppConfigWriter writer = null;

    try {
      writer = new AppConfigWriter(printWriter, getFactory());
      writer.save(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(writer);
      FileUtilities.closeQuietly(printWriter);
    }
    return ExitCode.Ok;
  }
Ejemplo n.º 3
0
 /** Process failure, return more descriptive exception */
 private DaemonException processFailedJob(
     final GridWorkPacket gridWorkPacket, final File packageFile, final Exception exception) {
   final DaemonException daemonException;
   final File storedFile = failedJobManager.storeFile(packageFile);
   if (storedFile != null) {
     daemonException =
         new DaemonException(
             MessageFormat.format(
                 "Failed passing work packet to grid engine:\n{0}\nUse {1} for the --sge parameter",
                 gridWorkPacket.toString(), storedFile.getAbsolutePath()),
             exception);
   } else {
     daemonException =
         new DaemonException(
             "Failed passing work packet to grid engine:\n" + gridWorkPacket.toString(),
             exception);
   }
   FileUtilities.quietDelete(packageFile);
   LOGGER.error(MprcException.getDetailedMessage(daemonException), daemonException);
   return daemonException;
 }