예제 #1
0
파일: Metrics.java 프로젝트: kyo19/pegasus
  /**
   * Writes out the workflow metrics file in the submit directory
   *
   * @param metrics the metrics to be written out.
   * @return the path to metrics file in the submit directory
   * @throws IOException in case of error while writing out file.
   */
  private File writeOutMetricsFile(PlannerMetrics metrics) throws IOException {

    if (metrics == null) {
      throw new IOException("NULL Metrics passed");
    }

    // create a writer to the braindump.txt in the directory.
    File f = metrics.getMetricsFileLocationInSubmitDirectory();

    if (f == null) {
      throw new IOException("The metrics file location is not yet initialized");
    }

    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(f)));

    writer.println(metrics.toPrettyJson());
    writer.write("\n");

    writer.close();

    return f;
  }
예제 #2
0
파일: Metrics.java 프로젝트: kyo19/pegasus
  /**
   * Sends the planner metrics to the metrics server
   *
   * @param metrics the metrics to log
   * @param url the url to send the metrics to
   */
  private SendMetricsResult send(PlannerMetrics metrics, String url) throws IOException {
    SendMetricsResult result = new SendMetricsResult();

    URL u = new URL(url);
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setDoOutput(true);
    // connection.setDoInput( true );
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Content-Type", "application/json");

    try {
      OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());

      try {
        // String payload = URLEncoder.encode( metrics.toJson(), "UTF-8") ;
        String payload = metrics.toJson();
        out.write(payload);
      } finally {
        out.close();
      }

      result.setCode(connection.getResponseCode());
      result.setResponseMessage(connection.getResponseMessage());

      /*
      BufferedReader in = new BufferedReader(
                              new InputStreamReader(
                               connection.getInputStream()));
      String result;
      while (( result = in.readLine()) != null) {
          System.out.println( result );
      }*/
    } finally {
      connection.disconnect();
    }

    return result;
  }