Beispiel #1
0
 public void updateJob(ApplicationInfo appInfo, CIJob job) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug(
         "Entering Method ProjectAdministratorImpl.updateJob(Project project, CIJob job)");
   }
   FileWriter writer = null;
   try {
     CIJobStatus jobStatus = configureJob(job, FrameworkConstants.CI_UPDATE_JOB_COMMAND);
     if (jobStatus.getCode() == -1) {
       throw new PhrescoException(jobStatus.getMessage());
     }
     if (debugEnabled) {
       S_LOGGER.debug("getCustomModules() ProjectInfo = " + appInfo);
     }
     updateJsonJob(appInfo, job);
   } catch (ClientHandlerException ex) {
     if (debugEnabled) {
       S_LOGGER.error(ex.getLocalizedMessage());
     }
     throw new PhrescoException(ex);
   } finally {
     if (writer != null) {
       try {
         writer.close();
       } catch (IOException e) {
         if (debugEnabled) {
           S_LOGGER.error(e.getLocalizedMessage());
         }
       }
     }
   }
 }
Beispiel #2
0
 public int getTotalBuilds(ApplicationInfo appInfo) throws PhrescoException {
   try {
     CIJob ciJob = getJob(appInfo);
     return getTotalBuilds(ciJob);
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
Beispiel #3
0
 // When already existing adapted project is created , need to move to new adapted project
 private boolean deleteCIJobFile(ApplicationInfo appInfo) throws PhrescoException {
   S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()");
   try {
     File ciJobInfo = new File(getCIJobPath(appInfo));
     return ciJobInfo.delete();
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(
         "Entered into catch block of ProjectAdministratorImpl.deleteCI()"
             + ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
Beispiel #4
0
 public CIJobStatus buildJobs(ApplicationInfo appInfo, List<String> jobsName)
     throws PhrescoException {
   try {
     CIJobStatus jobStatus = null;
     for (String jobName : jobsName) {
       CIJob ciJob = getJob(appInfo, jobName);
       jobStatus = buildJob(ciJob);
     }
     return jobStatus;
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
Beispiel #5
0
 public CIJobStatus deleteJobs(ApplicationInfo appInfo, List<String> jobNames)
     throws PhrescoException {
   S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()");
   try {
     CIJobStatus deleteCI = null;
     for (String jobName : jobNames) {
       S_LOGGER.debug(" Deleteable job name " + jobName);
       CIJob ciJob = getJob(appInfo, jobName);
       // job and build numbers
       deleteCI = deleteCI(ciJob, null);
       S_LOGGER.debug("write back json data after job deletion successfull");
       deleteJsonJobs(appInfo, Arrays.asList(ciJob));
     }
     return deleteCI;
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(
         "Entered into catch block of ProjectAdministratorImpl.deleteCI()"
             + ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
Beispiel #6
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);
   }
 }
Beispiel #7
0
 public CIJobStatus deleteBuilds(ApplicationInfo appInfo, Map<String, List<String>> builds)
     throws PhrescoException {
   S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()");
   try {
     CIJobStatus deleteCI = null;
     Iterator iterator = builds.keySet().iterator();
     while (iterator.hasNext()) {
       String jobName = iterator.next().toString();
       List<String> deleteBuilds = builds.get(jobName);
       S_LOGGER.debug("jobName " + jobName + " builds " + deleteBuilds);
       CIJob ciJob = getJob(appInfo, jobName);
       // job and build numbers
       deleteCI = deleteCI(ciJob, deleteBuilds);
     }
     return deleteCI;
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(
         "Entered into catch block of ProjectAdministratorImpl.deleteCI()"
             + ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }