Esempio n. 1
0
 public List<CIBuild> getBuilds(CIJob job) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug("Entering Method CIManagerImpl.getCIBuilds(CIJob job)");
   }
   List<CIBuild> ciBuilds = null;
   try {
     if (debugEnabled) {
       S_LOGGER.debug("getCIBuilds()  JobName = " + job.getName());
     }
     JsonArray jsonArray = getBuildsArray(job);
     ciBuilds = new ArrayList<CIBuild>(jsonArray.size());
     Gson gson = new Gson();
     CIBuild ciBuild = null;
     for (int i = 0; i < jsonArray.size(); i++) {
       ciBuild = gson.fromJson(jsonArray.get(i), CIBuild.class);
       setBuildStatus(ciBuild, job);
       String buildUrl = ciBuild.getUrl();
       String jenkinUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort();
       buildUrl =
           buildUrl.replaceAll(
               "localhost:" + job.getJenkinsPort(),
               jenkinUrl); // when displaying url it should display setup machine ip
       ciBuild.setUrl(buildUrl);
       ciBuilds.add(ciBuild);
     }
   } catch (Exception e) {
     if (debugEnabled) {
       S_LOGGER.debug(
           "Entering Method CIManagerImpl.getCIBuilds(CIJob job) " + e.getLocalizedMessage());
     }
   }
   return ciBuilds;
 }
Esempio n. 2
0
 private int getTotalBuilds(CIJob job) throws PhrescoException {
   try {
     S_LOGGER.debug("Entering Method CIManagerImpl.getTotalBuilds(CIJob job)");
     S_LOGGER.debug("getCIBuilds()  JobName = " + job.getName());
     JsonArray jsonArray = getBuildsArray(job);
     Gson gson = new Gson();
     CIBuild ciBuild = null;
     if (jsonArray.size() > 0) {
       ciBuild = gson.fromJson(jsonArray.get(0), CIBuild.class);
       String buildUrl = ciBuild.getUrl();
       String jenkinsUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort();
       // display the jenkins running url in ci
       buildUrl = buildUrl.replaceAll("localhost:" + job.getJenkinsPort(), jenkinsUrl);
       // list
       String response = getJsonResponse(buildUrl + API_JSON);
       JsonParser parser = new JsonParser();
       JsonElement jsonElement = parser.parse(response);
       JsonObject jsonObject = jsonElement.getAsJsonObject();
       JsonElement resultJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT);
       JsonArray asJsonArray =
           jsonObject.getAsJsonArray(FrameworkConstants.CI_JOB_BUILD_ARTIFACTS);
       // when build result is not known
       if (jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT).toString().equals(STRING_NULL)) {
         // it indicates the job is in progress and not yet completed
         return -1;
         // when build is success and build zip relative path is unknown
       } else if (resultJson.getAsString().equals(CI_SUCCESS_FLAG) && asJsonArray.size() < 1) {
         return -1;
       } else {
         return jsonArray.size();
       }
     } else {
       return -1; // When the project is build first time,
     }
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
Esempio n. 3
0
  private void setBuildStatus(CIBuild ciBuild, CIJob job) throws PhrescoException {
    S_LOGGER.debug("Entering Method CIManagerImpl.setBuildStatus(CIBuild ciBuild)");
    S_LOGGER.debug("setBuildStatus()  url = " + ciBuild.getUrl());
    String buildUrl = ciBuild.getUrl();
    String jenkinsUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort();
    buildUrl =
        buildUrl.replaceAll(
            "localhost:" + job.getJenkinsPort(),
            jenkinsUrl); // display the jenkins running url in ci list
    String response = getJsonResponse(buildUrl + API_JSON);
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(response);
    JsonObject jsonObject = jsonElement.getAsJsonObject();

    JsonElement resultJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT);
    JsonElement idJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_ID);
    JsonElement timeJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_TIME_STAMP);
    JsonArray asJsonArray = jsonObject.getAsJsonArray(FrameworkConstants.CI_JOB_BUILD_ARTIFACTS);

    if (jsonObject
        .get(FrameworkConstants.CI_JOB_BUILD_RESULT)
        .toString()
        .equals(STRING_NULL)) { // when build is result is not known
      ciBuild.setStatus(INPROGRESS);
    } else if (resultJson.getAsString().equals(CI_SUCCESS_FLAG)
        && asJsonArray.size()
            < 1) { // when build is success and zip relative path is not added in json
      ciBuild.setStatus(INPROGRESS);
    } else {
      ciBuild.setStatus(resultJson.getAsString());
      // download path
      for (JsonElement jsonArtElement : asJsonArray) {
        String buildDownloadZip =
            jsonArtElement
                .getAsJsonObject()
                .get(FrameworkConstants.CI_JOB_BUILD_DOWNLOAD_PATH)
                .toString();
        if (buildDownloadZip.endsWith(CI_ZIP)) {
          if (debugEnabled) {
            S_LOGGER.debug("download artifact " + buildDownloadZip);
          }
          ciBuild.setDownload(buildDownloadZip);
        }
      }
    }

    ciBuild.setId(idJson.getAsString());
    String dispFormat = DD_MM_YYYY_HH_MM_SS;
    ciBuild.setTimeStamp(getDate(timeJson.getAsString(), dispFormat));
  }