protected void downloadSampleAxisURLs(File sampleDir, File jobJSONFile) throws Exception {

    JSONObject jobJSONObject =
        JenkinsResultsParserUtil.toJSONObject(
            JenkinsResultsParserUtil.getLocalURL(toURLString(jobJSONFile)));

    int number = jobJSONObject.getInt("number");

    JSONArray runsJSONArray = jobJSONObject.getJSONArray("runs");

    for (int i = 0; i < runsJSONArray.length(); i++) {
      JSONObject runJSONObject = runsJSONArray.getJSONObject(i);

      if (number != runJSONObject.getInt("number")) {
        continue;
      }

      URL runURL = createURL(URLDecoder.decode(runJSONObject.getString("url"), "UTF-8"));

      File runDir = new File(sampleDir, "run-" + i + "/" + number + "/");

      downloadSampleURL(runDir, runURL, "/api/json");
      downloadSampleURL(runDir, runURL, "/logText/progressiveText");
      downloadSampleURL(runDir, runURL, "/testReport/api/json");

      runJSONObject.put("url", toURLString(runDir));
    }

    write(jobJSONFile, jobJSONObject.toString(4));
  }
Ejemplo n.º 2
0
  private int _executeBashCommands(List<String> commands, String targetSlave)
      throws InterruptedException, IOException {

    StringBuffer sb = new StringBuffer("ssh ");

    sb.append(targetSlave);
    sb.append(" '");

    if ((_cleanUpCommand != null) && !_cleanUpCommand.isEmpty()) {
      sb.append(_cleanUpCommand);
      sb.append("; ");
    }

    for (int i = 0; i < commands.size(); i++) {
      sb.append(commands.get(i));

      if (i < (commands.size() - 1)) {
        sb.append(" && ");
      }
    }

    sb.append("'");

    Process process = JenkinsResultsParserUtil.executeBashCommands(sb.toString());

    return process.exitValue();
  }
Ejemplo n.º 3
0
  @Override
  public String getResult() {
    if (!_status.equals("completed")) {
      throw new IllegalStateException("Build not completed");
    }

    String buildURL = getBuildURL();

    if ((result == null) && (buildURL != null)) {
      try {
        JSONObject resultJSONObject =
            JenkinsResultsParserUtil.toJSONObject(buildURL + "api/json?tree=result");

        result = resultJSONObject.optString("result");

        if (result.equals("")) {
          result = null;
        }
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    return result;
  }
Ejemplo n.º 4
0
  public void start(int threadCount) {
    _copyFromSource();

    ExecutorService executorService = Executors.newFixedThreadPool(threadCount);

    System.out.println("File propagation starting with " + threadCount + " threads.");

    try {
      long start = System.currentTimeMillis();

      while (!_targetSlaves.isEmpty() || !_busySlaves.isEmpty()) {
        synchronized (this) {
          for (String mirrorSlave : _mirrorSlaves) {
            if (_targetSlaves.isEmpty()) {
              break;
            }

            String targetSlave = _targetSlaves.remove(0);

            executorService.execute(new FilePropagatorThread(this, mirrorSlave, targetSlave));

            _busySlaves.add(mirrorSlave);
            _busySlaves.add(targetSlave);
          }

          _mirrorSlaves.removeAll(_busySlaves);
        }

        StringBuffer sb = new StringBuffer();

        sb.append("Average thread duration: ");
        sb.append(getAverageThreadDuration());
        sb.append("ms\nBusy slaves:");
        sb.append(_busySlaves.size());
        sb.append("\nMirror slaves:");
        sb.append(_mirrorSlaves.size());
        sb.append("\nTarget slaves:");
        sb.append(_targetSlaves.size());
        sb.append("\nTotal duration: ");
        sb.append(System.currentTimeMillis() - start);
        sb.append("\n");

        System.out.println(sb.toString());

        JenkinsResultsParserUtil.sleep(5000);
      }

      System.out.println(
          "File propagation completed in " + (System.currentTimeMillis() - start) + "ms.");

      if (!_errorSlaves.isEmpty()) {
        System.out.println(_errorSlaves.size() + " slaves failed to respond:\n" + _errorSlaves);
      }
    } finally {
      executorService.shutdown();
    }
  }
  protected void downloadSample(
      String sampleKey, String axisVariable, String buildNumber, String jobName, String hostName)
      throws Exception {

    String urlString = "https://${hostName}.liferay.com/job/${jobName}//${buildNumber}/";

    if (axisVariable != null) {
      urlString =
          "https://${hostName}.liferay.com/job/${jobName}"
              + "/AXIS_VARIABLE=${axis}/${buildNumber}/";

      urlString = replaceToken(urlString, "axis", axisVariable);
    }

    urlString = replaceToken(urlString, "buildNumber", buildNumber);
    urlString = replaceToken(urlString, "hostName", hostName);
    urlString = replaceToken(urlString, "jobName", jobName);

    URL url = JenkinsResultsParserUtil.createURL(urlString);

    downloadSample(sampleKey + "-" + jobName, url);
  }
  private static void _downloadSampleURL(File dir, URL url, String urlSuffix) throws Exception {

    _write(new File(dir, urlSuffix), JenkinsResultsParserUtil.toString(url + urlSuffix));
  }