예제 #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");
   }
 }
  @RequestMapping(value = "/start/DirectoryService", method = RequestMethod.POST)
  public void handleRequest(final HttpServletRequest req, final HttpServletResponse resp)
      throws ServletException, IOException {

    resp.setContentType("text/xml");
    resp.setHeader("Cache-Control", "no-cache");
    final PrintWriter out = resp.getWriter();
    String directory_path;
    String expanded_paths;
    String order;
    FileSearchBean.SortBy sortBy;
    try {
      order = req.getParameter(SORT_ORDER_ATTRIBUTE_NAME);
      if ("date".equals(order)) {
        sortBy = FileSearchBean.SortBy.DATE;
      } else {
        sortBy = FileSearchBean.SortBy.NAME;
      }
      directory_path = req.getParameter(DIRECTORY_PATH_ATTRIBUTE_NAME);
      if (directory_path == null) {
        directory_path = "";
      }
      directory_path = removePathParentUsage(directory_path);
      expanded_paths = req.getParameter(EXPANDED_PATHS_ATTRIBUTE_NAME);
      if (expanded_paths == null) {
        expanded_paths = "";
      }

      final FileSearchBean fileBean = new FileSearchBean(getBaseFolder().getAbsolutePath(), sortBy);
      fileBean.setPath(fixFileSeparators(directory_path));
      fileBean.setExpandedPaths(expanded_paths);
      fileBean.writeFolderContent(out);
    } catch (MprcException e) {
      throw new ServletException("Problem in FileDirectoryServiceServlet, " + e.getMessage(), e);
    } catch (Exception e) {
      throw new ServletException("Problem in login session:" + e.getMessage(), e);
    } finally {
      out.close();
    }
  } // end doGet
예제 #3
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;
  }
예제 #4
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;
 }