Ejemplo n.º 1
0
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
      String uri = getDecodedUri(request);

      try {
        String destination_frame = request.getParameter("destination_frame");
        if (destination_frame == null) {
          destination_frame = "upload" + Key.rand();
        }
        if (!validKeyName(destination_frame)) {
          setResponseStatus(response, HttpServletResponse.SC_BAD_REQUEST);
          response.getWriter().write("Invalid key name, contains illegal characters");
          return;
        }

        //
        // Here is an example of how to upload a file from the command line.
        //
        // curl -v -F "file=@allyears2k_headers.zip"
        // "http://localhost:54321/3/PostFile.bin?destination_frame=a.zip"
        //
        // JSON Payload returned is:
        //     { "destination_frame": "key_name", "total_bytes": nnn }
        //
        InputStream is = extractPartInputStream(request, response);
        if (is == null) {
          return;
        }

        UploadFileVec.ReadPutStats stats = new UploadFileVec.ReadPutStats();
        UploadFileVec.readPut(destination_frame, is, stats);
        String responsePayload =
            "{ "
                + "\"destination_frame\": \""
                + destination_frame
                + "\", "
                + "\"total_bytes\": "
                + stats.total_bytes
                + " "
                + "}\n";
        response.setContentType("application/json");
        response.getWriter().write(responsePayload);
      } catch (Exception e) {
        sendErrorResponse(response, e, uri);
      } finally {
        logRequest("POST", request, response);
      }
    }
Ejemplo n.º 2
0
  /**
   * From a path produce a list of files and keys for parsing.
   *
   * <p>Use as follows:
   *
   * <p>ArrayList<String> files = new ArrayList(); ArrayList<String> keys = new ArrayList();
   * ArrayList<String> fails = new ArrayList(); ArrayList<String> dels = new ArrayList();
   * importFiles(importFiles.path, files, keys, fails, dels);
   *
   * @param path (Input) Path to import data from
   * @param files (Output) List of files found
   * @param keys (Output) List of keys corresponding to files
   * @param fails (Output) List of failed files which mismatch among nodes
   * @param dels (Output) I don't know what this is
   */
  public void importFiles(
      String path,
      ArrayList<String> files,
      ArrayList<String> keys,
      ArrayList<String> fails,
      ArrayList<String> dels) {
    String s = path.toLowerCase(); // path must not be null
    if (s.startsWith("http:") || s.startsWith("https:")) {
      try {
        java.net.URL url = new URL(path);
        Key destination_key = Key.make(path);
        java.io.InputStream is = url.openStream();
        UploadFileVec.ReadPutStats stats = new UploadFileVec.ReadPutStats();
        UploadFileVec.readPut(destination_key, is, stats);
        files.add(path);
        keys.add(destination_key.toString());
      } catch (Throwable e) {
        fails.add(
            path); // Fails for e.g. broken sockets silently swallow exceptions and just record the
                   // failed path
      }
      return;
    }

    if (s.startsWith("s3:")) {
      if (I[Value.S3] == null)
        throw new H2OIllegalArgumentException("S3 support is not configured");
      I[Value.S3].importFiles(path, files, keys, fails, dels);
      return;
    }
    if (s.startsWith("hdfs:")
        || s.startsWith("s3n:")
        || s.startsWith("s3a:")
        || s.startsWith("maprfs:")) {
      if (I[Value.HDFS] == null)
        throw new H2OIllegalArgumentException("HDFS, S3N, and S3A support is not configured");
      I[Value.HDFS].importFiles(path, files, keys, fails, dels);
      return;
    }
    // Attempt NFS import instead
    I[Value.NFS].importFiles(path, files, keys, fails, dels);
  }