Exemple #1
0
 public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String hdfsFolder = request.getParameter("hdfsFolder");
   HttpSession session = request.getSession(true);
   ConfigurationManager configurationManager =
       ((LoginPass) session.getAttribute(ShsContext.LOGIN_PASS)).getConfigurationManager();
   PrintWriter out = response.getWriter();
   Map<String, String> jsonKeyValMap = new LinkedHashMap<String, String>();
   try {
     IFileSystem filesystem = configurationManager.getFileSystem();
     IFile[] files = filesystem.listFiles(hdfsFolder);
     response.setContentType("application/json");
     int count = 0;
     for (IFile file : files) {
       jsonKeyValMap.put("fileName" + count, file.getFilename());
       jsonKeyValMap.put("fileOwner" + count, file.getOwner());
       jsonKeyValMap.put("fileLen" + count, FileUtils.byteCountToDisplaySize(file.getLen()));
       jsonKeyValMap.put(
           "fileModificationTime" + count,
           ShsContext.DATE_FORMAT.format(new Date(file.getModificationTime())));
       jsonKeyValMap.put("isDir" + count, file.isDir() ? "0" : "1");
       count++;
     }
   } catch (Exception ee) {
     IOException iee = new IOException(ee);
     iee.setStackTrace(ee.getStackTrace());
     throw iee;
   }
   out.write(ShsContext.getJsonString(jsonKeyValMap));
   out.close();
 }
Exemple #2
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession(true);
    String employeeId = ((LoginPass) session.getAttribute(ShsContext.LOGIN_PASS)).getUsername();

    Map<String, String> jsonKeyValMap = new HashMap<String, String>();
    String resourceFile =
        ShsContext.getStorageDir(employeeId) + request.getParameter(ShsContext.JAR_FILENAME);

    String className = request.getParameter(ShsContext.CLASS_NAME);

    String additionalParameters = request.getParameter(ShsContext.ADDITIONAL_PARAMETERS);
    if (StringUtils.isEmpty(additionalParameters)) {
      additionalParameters = "";
    }
    String command =
        ShsContext.getCommand(
            ShsContext.SCRIPT_FILENAME, resourceFile, className, additionalParameters);

    System.out.println("command=\n" + command);
    Process process = ShsContext.execute(command);
    InputStream in = process.getInputStream();
    InputStream error = process.getErrorStream();
    String jobId = null;
    if (in.available() > 0) {
      System.out.println("Trying to get jobId from InputStream...");
      jobId = ShsContext.getJobId(in);
    } else {
      System.out.println("Trying to get jobId from ErrorInputStream...");
      jobId = ShsContext.getJobId(error);
    }

    if (jobId != null) {
      jsonKeyValMap.put("jobid", jobId);
    } else {
      jsonKeyValMap.put(
          "error_msg",
          "Failed to submit the MapReduce task, please contact administrator for more details.");
    }
    in.close();
    error.close();
    PrintWriter out = response.getWriter();
    response.setContentType("application/json");
    out.write(ShsContext.getJsonString(jsonKeyValMap));
    out.close();
  }