Example #1
1
 private CIJobStatus deleteCI(CIJob job, List<String> builds) throws PhrescoException {
   S_LOGGER.debug("Entering Method CIManagerImpl.deleteCI(CIJob job)");
   S_LOGGER.debug("Job name " + job.getName());
   cli = getCLI(job);
   String deleteType = null;
   List<String> argList = new ArrayList<String>();
   S_LOGGER.debug("job name " + job.getName());
   S_LOGGER.debug("Builds " + builds);
   if (CollectionUtils.isEmpty(builds)) { // delete job
     S_LOGGER.debug("Job deletion started");
     S_LOGGER.debug("Command " + FrameworkConstants.CI_JOB_DELETE_COMMAND);
     deleteType = DELETE_TYPE_JOB;
     argList.add(FrameworkConstants.CI_JOB_DELETE_COMMAND);
     argList.add(job.getName());
   } else { // delete Build
     S_LOGGER.debug("Build deletion started");
     deleteType = DELETE_TYPE_BUILD;
     argList.add(FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     argList.add(job.getName());
     StringBuilder result = new StringBuilder();
     for (String string : builds) {
       result.append(string);
       result.append(",");
     }
     String buildNos = result.substring(0, result.length() - 1);
     argList.add(buildNos);
     S_LOGGER.debug("Command " + FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     S_LOGGER.debug("Build numbers " + buildNos);
   }
   try {
     int status = cli.execute(argList);
     String message = deleteType + " deletion started in jenkins";
     if (status == FrameworkConstants.JOB_STATUS_NOTOK) {
       deleteType = deleteType.substring(0, 1).toLowerCase() + deleteType.substring(1);
       message = "Error while deleting " + deleteType + " in jenkins";
     }
     S_LOGGER.debug("Delete CI Status " + status);
     S_LOGGER.debug("Delete CI Message " + message);
     return new CIJobStatus(status, message);
   } finally {
     if (cli != null) {
       try {
         cli.close();
       } catch (IOException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       } catch (InterruptedException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       }
     }
   }
 }
Example #2
0
 private void deleteJsonJobs(ApplicationInfo appInfo, List<CIJob> selectedJobs)
     throws PhrescoException {
   try {
     if (CollectionUtils.isEmpty(selectedJobs)) {
       return;
     }
     Gson gson = new Gson();
     List<CIJob> jobs = getJobs(appInfo);
     if (CollectionUtils.isEmpty(jobs)) {
       return;
     }
     // all values
     Iterator<CIJob> iterator = jobs.iterator();
     // deletable values
     for (CIJob selectedInfo : selectedJobs) {
       while (iterator.hasNext()) {
         CIJob itrCiJob = iterator.next();
         if (itrCiJob.getName().equals(selectedInfo.getName())) {
           iterator.remove();
           break;
         }
       }
     }
     writeJsonJobs(appInfo, jobs, CI_CREATE_NEW_JOBS);
   } catch (Exception e) {
     throw new PhrescoException(e);
   }
 }
Example #3
0
  private void setSvnCredential(CIJob job) throws JDOMException, IOException {
    S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential");
    try {
      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML;
      if (debugEnabled) {
        S_LOGGER.debug("credentialFilePath ... " + credentialFilePath);
      }
      File credentialFile = new File(credentialFilePath);

      SvnProcessor processor = new SvnProcessor(credentialFile);

      //			DataInputStream in = new DataInputStream(new FileInputStream(credentialFile));
      //			while (in.available() != 0) {
      //				System.out.println(in.readLine());
      //			}
      //			in.close();

      processor.changeNodeValue("credentials/entry//userName", job.getUserName());
      processor.changeNodeValue("credentials/entry//password", job.getPassword());
      processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName()));

      // jenkins home location
      String jenkinsJobHome = System.getenv(JENKINS_HOME);
      StringBuilder builder = new StringBuilder(jenkinsJobHome);
      builder.append(File.separator);

      processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML));
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into the catch block of CIManagerImpl.setSvnCredential "
              + e.getLocalizedMessage());
    }
  }
Example #4
0
 private CLI getCLI(CIJob job) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug("Entering Method CIManagerImpl.getCLI()");
   }
   String jenkinsUrl =
       HTTP_PROTOCOL
           + PROTOCOL_POSTFIX
           + job.getJenkinsUrl()
           + COLON
           + job.getJenkinsPort()
           + FORWARD_SLASH
           + CI
           + FORWARD_SLASH;
   if (debugEnabled) {
     S_LOGGER.debug("jenkinsUrl to get cli object " + jenkinsUrl);
   }
   try {
     return new CLI(new URL(jenkinsUrl));
   } catch (MalformedURLException e) {
     throw new PhrescoException(e);
   } catch (IOException e) {
     throw new PhrescoException(e);
   } catch (InterruptedException e) {
     throw new PhrescoException(e);
   }
 }
Example #5
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;
 }
Example #6
0
File: CI.java Project: ab-k/phresco
 public String buildProgress() {
   S_LOGGER.debug("Entering Method CI.buildProgress()");
   try {
     buildInProgress = false;
     String[] selectedJobs = getHttpRequest().getParameterValues(REQ_SELECTED_JOBS_LIST);
     S_LOGGER.debug("build progress jobs monitoring");
     ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
     Project project = administrator.getProject(projectCode);
     CIJob existJob = administrator.getJob(project);
     if (existJob != null) {
       boolean buildJenkinsAlive = false;
       buildJenkinsAlive =
           DiagnoseUtil.isConnectionAlive(
               "http", existJob.getJenkinsUrl(), Integer.parseInt(existJob.getJenkinsPort()));
       S_LOGGER.debug("Build jenkins alive " + buildJenkinsAlive);
       if (buildJenkinsAlive == true && administrator.getProgressInBuild(project) > 0) {
         buildInProgress = true;
       }
     }
   } catch (Exception e) {
     S_LOGGER.error(
         "Entered into catch block of CI.buildProgress()"
             + FrameworkUtil.getStackTraceAsString(e));
   }
   return SUCCESS;
 }
Example #7
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));
  }
Example #8
0
  private void setMailCredential(CIJob job) {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.setMailCredential");
    }
    try {
      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String mailFilePath = jenkinsTemplateDir + MAIL + HYPHEN + CREDENTIAL_XML;
      if (debugEnabled) {
        S_LOGGER.debug("configFilePath ... " + mailFilePath);
      }
      File mailFile = new File(mailFilePath);

      SvnProcessor processor = new SvnProcessor(mailFile);

      //			DataInputStream in = new DataInputStream(new FileInputStream(mailFile));
      //			while (in.available() != 0) {
      //				System.out.println(in.readLine());
      //			}
      //			in.close();

      // Mail have to go with jenkins running email address
      InetAddress ownIP = InetAddress.getLocalHost();
      processor.changeNodeValue(
          CI_HUDSONURL,
          HTTP_PROTOCOL
              + PROTOCOL_POSTFIX
              + ownIP.getHostAddress()
              + COLON
              + job.getJenkinsPort()
              + FORWARD_SLASH
              + CI
              + FORWARD_SLASH);
      processor.changeNodeValue("smtpAuthUsername", job.getSenderEmailId());
      processor.changeNodeValue("smtpAuthPassword", job.getSenderEmailPassword());
      processor.changeNodeValue("adminAddress", job.getSenderEmailId());

      // jenkins home location
      String jenkinsJobHome = System.getenv(JENKINS_HOME);
      StringBuilder builder = new StringBuilder(jenkinsJobHome);
      builder.append(File.separator);

      processor.writeStream(new File(builder.toString() + CI_MAILER_XML));
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into the catch block of CIManagerImpl.setMailCredential "
              + e.getLocalizedMessage());
    }
  }
Example #9
0
  private CIJobStatus buildJob(CIJob job) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.buildJob(CIJob job)");
    }
    cli = getCLI(job);

    List<String> argList = new ArrayList<String>();
    argList.add(FrameworkConstants.CI_BUILD_JOB_COMMAND);
    argList.add(job.getName());
    try {
      int status = cli.execute(argList);
      String message = FrameworkConstants.CI_BUILD_STARTED;
      if (status == FrameworkConstants.JOB_STATUS_NOTOK) {
        message = FrameworkConstants.CI_BUILD_STARTING_ERROR;
      }
      return new CIJobStatus(status, message);
    } finally {
      if (cli != null) {
        try {
          cli.close();
        } catch (IOException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        } catch (InterruptedException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        }
      }
    }
  }
Example #10
0
 private int getProgressInBuild(CIJob job) throws PhrescoException {
   S_LOGGER.debug("Entering Method CIManagerImpl.isBuilding(CIJob job)");
   String jenkinsUrl =
       HTTP_PROTOCOL
           + PROTOCOL_POSTFIX
           + job.getJenkinsUrl()
           + COLON
           + job.getJenkinsPort()
           + FORWARD_SLASH
           + CI
           + FORWARD_SLASH;
   String isBuildingUrlUrl = BUSY_EXECUTORS;
   String jsonResponse = getJsonResponse(jenkinsUrl + isBuildingUrlUrl);
   int buidInProgress = Integer.parseInt(jsonResponse);
   S_LOGGER.debug("buidInProgress " + buidInProgress);
   return buidInProgress;
 }
Example #11
0
File: CI.java Project: ab-k/phresco
 public String CIBuildDownload() {
   S_LOGGER.debug("Entering Method CI.CIBuildDownload()");
   try {
     ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
     Project project = administrator.getProject(projectCode);
     CIJob existJob = administrator.getJob(project, downloadJobName);
     // Get it from web path
     URL url = new URL(buildDownloadUrl);
     S_LOGGER.debug("Entering Method CI.CIBuildDownload() buildDownloadUrl " + buildDownloadUrl);
     fileInputStream = url.openStream();
     fileName = existJob.getName();
     return SUCCESS;
   } catch (Exception e) {
     S_LOGGER.error(
         "Entered into catch block of CI.CIBuildDownload()"
             + FrameworkUtil.getStackTraceAsString(e));
   }
   return SUCCESS;
 }
Example #12
0
  private JsonArray getBuildsArray(CIJob job) throws PhrescoException {
    try {
      String jenkinsUrl = "http://" + job.getJenkinsUrl() + ":" + job.getJenkinsPort() + "/ci/";
      String jobNameUtf8 = job.getName().replace(" ", "%20");
      String buildsJsonUrl = jenkinsUrl + "job/" + jobNameUtf8 + "/api/json";
      String jsonResponse = getJsonResponse(buildsJsonUrl);

      JsonParser parser = new JsonParser();
      JsonElement jsonElement = parser.parse(jsonResponse);
      JsonObject jsonObject = jsonElement.getAsJsonObject();
      JsonElement element = jsonObject.get(FrameworkConstants.CI_JOB_JSON_BUILDS);

      JsonArray jsonArray = element.getAsJsonArray();

      return jsonArray;
    } catch (Exception e) {
      throw new PhrescoException(e);
    }
  }
Example #13
0
File: CI.java Project: ab-k/phresco
  public String ci() {
    S_LOGGER.debug("Entering Method CI.ci()");
    try {
      boolean jenkinsAlive = false;
      // UI didnt trigger anybuild from here
      getHttpRequest().setAttribute(CI_BUILD_TRIGGERED_FROM_UI, FALSE);
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = (Project) administrator.getProject(projectCode);
      getHttpRequest().setAttribute(REQ_PROJECT, project);
      getHttpRequest().setAttribute(REQ_SELECTED_MENU, APPLICATIONS);
      getHttpRequest().setAttribute(CI_JENKINS_ALIVE, jenkinsAlive);

      jenkinsAlive =
          DiagnoseUtil.isConnectionAlive(
              HTTP_PROTOCOL, LOCALHOST, Integer.parseInt(getPortNo(Utility.getJenkinsHome())));
      S_LOGGER.debug("jenkins Alive " + jenkinsAlive);
      getHttpRequest().setAttribute(CI_JENKINS_ALIVE, jenkinsAlive);

      List<CIJob> existingJobs = administrator.getJobs(project);
      Map<String, List<CIBuild>> ciJobsAndBuilds = new HashMap<String, List<CIBuild>>();
      if (existingJobs != null) {
        for (CIJob ciJob : existingJobs) {
          boolean buildJenkinsAlive = false;
          boolean isJobCreatingBuild = false;
          int noOfJobsIsInProgress = 0;
          List<CIBuild> builds = null;
          buildInProgress = false;
          buildJenkinsAlive =
              DiagnoseUtil.isConnectionAlive(
                  HTTP_PROTOCOL, ciJob.getJenkinsUrl(), Integer.parseInt(ciJob.getJenkinsPort()));
          isJobCreatingBuild = administrator.isJobCreatingBuild(ciJob);
          S_LOGGER.debug("ciJob.getName() ====> " + ciJob.getName());
          S_LOGGER.debug("ciJob.getName() alive  ====> " + buildJenkinsAlive);
          S_LOGGER.debug("ciJob.getName() isJobCreatingBuild  ====> " + isJobCreatingBuild);
          getHttpRequest()
              .setAttribute(CI_BUILD_JENKINS_ALIVE + ciJob.getName(), buildJenkinsAlive);
          getHttpRequest()
              .setAttribute(CI_BUILD_IS_IN_PROGRESS + ciJob.getName(), isJobCreatingBuild);
          if (buildJenkinsAlive == true) {
            builds = administrator.getBuilds(ciJob);
          }
          S_LOGGER.debug("ciJob.getName() builds ====> " + builds);
          ciJobsAndBuilds.put(ciJob.getName(), builds);
        }
      }
      getHttpRequest().setAttribute(REQ_EXISTING_JOBS, ciJobsAndBuilds);
      numberOfJobsIsInProgress();
      S_LOGGER.debug("numberOfJobsInProgress " + numberOfJobsInProgress);
      getHttpRequest().setAttribute(CI_NO_OF_JOBS_IN_PROGRESS, numberOfJobsInProgress);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.ci()" + FrameworkUtil.getStackTraceAsString(e));
    }
    return APP_CI;
  }
Example #14
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);
   }
 }
Example #15
0
File: CI.java Project: ab-k/phresco
  public String configure() {
    S_LOGGER.debug("Entering Method  CI.configure()");
    try {
      String[] selectedJobsName = getHttpRequest().getParameterValues(REQ_SELECTED_JOBS_LIST);
      String jobName = "";
      if (!ArrayUtils.isEmpty(selectedJobsName)) {
        jobName = selectedJobsName[0];
      }
      S_LOGGER.debug("selectedJobs for configuration " + jobName);

      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      // Get environment info
      List<Environment> environments = administrator.getEnvironments(project);
      getHttpRequest().setAttribute(REQ_ENVIRONMENTS, environments);
      getHttpRequest().setAttribute(REQ_PROJECT, project);
      // Get xcode targets
      String technology = project.getProjectInfo().getTechnology().getId();
      if (TechnologyTypes.IPHONES.contains(technology)) {
        List<PBXNativeTarget> xcodeConfigs = ApplicationsUtil.getXcodeConfiguration(projectCode);
        getHttpRequest().setAttribute(REQ_XCODE_CONFIGS, xcodeConfigs);
        // get list of sdks
        List<String> iphoneSdks = IosSdkUtil.getMacSdks(MacSdkType.iphoneos);
        iphoneSdks.addAll(IosSdkUtil.getMacSdks(MacSdkType.iphonesimulator));
        iphoneSdks.addAll(IosSdkUtil.getMacSdks(MacSdkType.macosx));
        getHttpRequest().setAttribute(REQ_IPHONE_SDKS, iphoneSdks);
      }
      CIJob existJob = administrator.getJob(project, jobName);
      existJob.setCollabNetpassword(CIPasswordScrambler.unmask(existJob.getCollabNetpassword()));
      getHttpRequest().setAttribute(REQ_EXISTING_JOB, existJob);
      getHttpRequest().setAttribute(REQ_SELECTED_MENU, APPLICATIONS);
      getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.configure()" + FrameworkUtil.getStackTraceAsString(e));
      new LogErrorReport(e, "CI configuration clicked");
    }
    return APP_CI_CONFIGURE;
  }
Example #16
0
 public CIJob getJob(ApplicationInfo appInfo, String jobName) throws PhrescoException {
   try {
     S_LOGGER.debug("Search for jobName => " + jobName);
     if (StringUtils.isEmpty(jobName)) {
       return null;
     }
     List<CIJob> jobs = getJobs(appInfo);
     if (CollectionUtils.isEmpty(jobs)) {
       S_LOGGER.debug("job list is empty!!!!!!!!");
       return null;
     }
     S_LOGGER.debug("Job list found!!!!!");
     for (CIJob job : jobs) {
       S_LOGGER.debug("job list job Names => " + job.getName());
       if (job.getName().equals(jobName)) {
         return job;
       }
     }
   } catch (Exception e) {
     throw new PhrescoException(e);
   }
   return null;
 }
Example #17
0
 private boolean adaptExistingJobs(ApplicationInfo appInfo) {
   try {
     CIJob existJob = getJob(appInfo);
     S_LOGGER.debug("Going to get existing jobs to relocate!!!!!");
     if (existJob != null) {
       S_LOGGER.debug("Existing job found " + existJob.getName());
       boolean deleteExistJob = deleteCIJobFile(appInfo);
       Gson gson = new Gson();
       List<CIJob> existingJobs = new ArrayList<CIJob>();
       existingJobs.addAll(Arrays.asList(existJob));
       FileWriter writer = null;
       File ciJobFile = new File(getCIJobPath(appInfo));
       String jobJson = gson.toJson(existingJobs);
       writer = new FileWriter(ciJobFile);
       writer.write(jobJson);
       writer.flush();
       S_LOGGER.debug("Existing job moved to new type of project!!");
     }
     return true;
   } catch (Exception e) {
     S_LOGGER.debug("It is already adapted !!!!! ");
   }
   return false;
 }
Example #18
0
  private void customizeNodes(ConfigProcessor processor, CIJob job)
      throws JDOMException, PhrescoException {

    // SVN url customization
    if (SVN.equals(job.getRepoType())) {
      S_LOGGER.debug("This is svn type project!!!!!");
      processor.changeNodeValue(SCM_LOCATIONS_REMOTE, job.getSvnUrl());
    } else if (GIT.equals(job.getRepoType())) {
      S_LOGGER.debug("This is git type project!!!!!");
      processor.changeNodeValue(SCM_USER_REMOTE_CONFIGS_URL, job.getSvnUrl());
      processor.changeNodeValue(SCM_BRANCHES_NAME, job.getBranch());
      // cloned workspace
    } else if (CLONED_WORKSPACE.equals(job.getRepoType())) {
      S_LOGGER.debug("Clonned workspace selected!!!!!!!!!!");
      processor.useClonedScm(job.getUsedClonnedWorkspace(), SUCCESSFUL);
    }

    // Schedule expression customization
    processor.changeNodeValue(TRIGGERS_SPEC, job.getScheduleExpression());

    // Triggers Implementation
    List<String> triggers = job.getTriggers();

    processor.createTriggers(TRIGGERS, triggers, job.getScheduleExpression());

    // if the technology is java stanalone and functional test , goal have to specified in post
    // build step only
    if (job.isEnablePostBuildStep() && FUNCTIONAL_TEST.equals(job.getOperation())) {
      // Maven command customization
      processor.changeNodeValue(GOALS, CI_FUNCTIONAL_ADAPT.trim());
    } else {
      // Maven command customization
      processor.changeNodeValue(GOALS, job.getMvnCommand());
    }

    // Recipients customization
    Map<String, String> email = job.getEmail();

    // Failure Reception list
    processor.changeNodeValue(
        TRIGGER_FAILURE_EMAIL_RECIPIENT_LIST, (String) email.get(FAILURE_EMAILS));

    // Success Reception list
    processor.changeNodeValue(
        TRIGGER_SUCCESS__EMAIL_RECIPIENT_LIST, (String) email.get(SUCCESS_EMAILS));

    // enable collabnet file release plugin integration
    if (job.isEnableBuildRelease()) {
      S_LOGGER.debug("Enablebling collabnet file release plugin ");
      processor.enableCollabNetBuildReleasePlugin(job);
    }

    // use clonned scm
    if (CLONED_WORKSPACE.equals(job.getRepoType())) {
      S_LOGGER.debug("using cloned workspace ");
      processor.useClonedScm(job.getUsedClonnedWorkspace(), SUCCESSFUL);
    }

    // clone workspace for future use
    if (job.isCloneWorkspace()) {
      S_LOGGER.debug("Clonning the workspace ");
      processor.cloneWorkspace(ALL_FILES, SUCCESSFUL, TAR);
    }

    // Build Other projects
    if (StringUtils.isNotEmpty(job.getDownStreamProject())) {
      S_LOGGER.debug("Enabling downstream project!!!!!!");
      processor.buildOtherProjects(job.getDownStreamProject());
    }

    // pom location specifier
    if (StringUtils.isNotEmpty(job.getPomLocation())) {
      S_LOGGER.debug("POM location changing " + job.getPomLocation());
      processor.updatePOMLocation(job.getPomLocation());
    }

    if (job.isEnablePostBuildStep()) {
      System.out.println("java stanalone technology with functional test enabled!!!!!!!");
      String mvnCommand = job.getMvnCommand();
      String[] ciAdapted =
          mvnCommand.split(CI_FUNCTIONAL_ADAPT); // java stanalone functional test alone
      for (String ciCommand : ciAdapted) {
        S_LOGGER.debug("ciCommand...." + ciCommand);
      }
      // iterate over loop
      processor.enablePostBuildStep(job.getPomLocation(), ciAdapted[1]);
    }

    if (job.isEnablePreBuildStep()) {
      System.out.println("java stanalone technology with functional test enabled!!!!!!!");
      // iterate over loop
      List<String> prebuildStepCommands = job.getPrebuildStepCommands();
      for (String prebuildStepCommand : prebuildStepCommands) {
        processor.enablePreBuildStep(job.getPomLocation(), prebuildStepCommand);
      }
    }
  }
Example #19
0
  private CIJobStatus configureJob(CIJob job, String jobType) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.createJob(CIJob job)");
    }
    try {
      cli = getCLI(job);
      List<String> argList = new ArrayList<String>();
      argList.add(jobType);
      argList.add(job.getName());

      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String configFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CONFIG_XML;
      if (debugEnabled) {
        S_LOGGER.debug("configFilePath ...  " + configFilePath);
      }

      File configFile = new File(configFilePath);
      ConfigProcessor processor = new ConfigProcessor(configFile);
      customizeNodes(processor, job);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (debugEnabled) {
        S_LOGGER.debug("argList " + argList.toString());
      }
      int result = cli.execute(argList, processor.getConfigAsStream(), System.out, baos);

      String message = "Job created successfully";
      if (result == -1) {
        byte[] byteArray = baos.toByteArray();
        message = new String(byteArray);
      }
      if (debugEnabled) {
        S_LOGGER.debug("message " + message);
      }
      // when svn is selected credential value has to set
      if (SVN.equals(job.getRepoType())) {
        setSvnCredential(job);
      }

      setMailCredential(job);
      return new CIJobStatus(result, message);
    } catch (IOException e) {
      throw new PhrescoException(e);
    } catch (JDOMException e) {
      throw new PhrescoException(e);
    } finally {
      if (cli != null) {
        try {
          cli.close();
        } catch (IOException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        } catch (InterruptedException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        }
      }
    }
  }
Example #20
0
File: CI.java Project: ab-k/phresco
  public String doUpdateSave(String jobType) {
    S_LOGGER.debug("Entering Method  CI.doUpdateSave()");
    try {
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      String technology = project.getProjectInfo().getTechnology().getId();
      CIJob existJob = null;
      if (StringUtils.isNotEmpty(oldJobName)) {
        existJob = administrator.getJob(project, oldJobName);
      }
      if (existJob == null) {
        existJob = new CIJob();
      }
      InetAddress thisIp = InetAddress.getLocalHost();
      existJob.setName(name);
      existJob.setSvnUrl(svnurl);
      existJob.setUserName(username);
      existJob.setPassword(CIPasswordScrambler.mask(password));
      existJob.setJenkinsUrl(thisIp.getHostAddress());
      existJob.setJenkinsPort(getPortNo(Utility.getJenkinsHome()));
      existJob.setTriggers(triggers);
      Map<String, String> emails = new HashMap<String, String>(2);
      emails.put(REQ_KEY_SUCCESS_EMAILS, successEmailIds);
      emails.put(REQ_KEY_FAILURE_EMAILS, failureEmailIds);

      Map<String, String> settingsInfoMap = new HashMap<String, String>(2);
      ActionType actionType = null;

      // For web technologies
      if (StringUtils.isNotEmpty(environment)) {
        settingsInfoMap.put(ENVIRONMENT_NAME, environment);
      }

      // For android technologies
      if (StringUtils.isNotEmpty(androidVersion)) {
        settingsInfoMap.put(AndroidConstants.ANDROID_VERSION_MVN_PARAM, androidVersion);
      }

      // For iphone technoloies
      if (TechnologyTypes.IPHONES.contains(technology)) {
        settingsInfoMap.put(IPHONE_SDK, sdk);
        settingsInfoMap.put(IPHONE_CONFIGURATION, mode);
        settingsInfoMap.put(IPHONE_TARGET_NAME, target);
        if (TechnologyTypes.IPHONE_HYBRID.equals(technology)) {
          settingsInfoMap.put(IPHONE_PLISTFILE, XCodeConstants.HYBRID_PLIST);
          settingsInfoMap.put(ENCRYPT, FALSE);
        } else if (TechnologyTypes.IPHONE_NATIVE.equals(technology)) {
          settingsInfoMap.put(IPHONE_PLISTFILE, XCodeConstants.NATIVE_PLIST);
          settingsInfoMap.put(ENCRYPT, TRUE);
        }
      }

      // For mobile technologies
      if (TechnologyTypes.ANDROIDS.contains(technology)) {
        if (StringUtils.isEmpty(proguard)) {
          // if the checkbox is selected value should be set to false otherwise true
          proguard = TRUE;
        }
        settingsInfoMap.put(ANDROID_PROGUARD_SKIP, proguard);
        actionType = ActionType.MOBILE_COMMON_COMMAND;
        if (StringUtils.isNotEmpty(signing)) {
          actionType.setProfileId(PROFILE_ID);
        }
      } else if (TechnologyTypes.IPHONES.contains(technology)) {
        actionType = ActionType.IPHONE_BUILD_UNIT_TEST;
      } else {
        actionType = ActionType.BUILD;
      }
      ProjectRuntimeManager runtimeManager = PhrescoFrameworkFactory.getProjectRuntimeManager();
      String mvncmd = "";
      StringBuilder command = actionType.getCommand();
      StringBuilder buildMavenCommand = new StringBuilder();
      if (command == null) {
        buildMavenCommand = runtimeManager.buildMavenCommand(project, actionType, settingsInfoMap);
      } else {
        buildMavenCommand.append(command);
        buildMavenCommand.append(SPACE);
        buildMavenCommand.append(runtimeManager.buildMavenArgCommand(actionType, settingsInfoMap));
      }
      mvncmd = buildMavenCommand.toString().substring(4).trim();
      mvncmd = CI_PROFILE + mvncmd;
      S_LOGGER.debug("mvn command " + mvncmd);
      existJob.setMvnCommand(mvncmd);
      existJob.setEmail(emails);
      existJob.setScheduleType(schedule);
      existJob.setScheduleExpression(cronExpression);
      existJob.setSenderEmailId(senderEmailId);
      existJob.setSenderEmailPassword(senderEmailPassword);
      existJob.setBranch(branch);
      existJob.setRepoType(svnType);
      // collabNet file release plugin imple
      existJob.setEnableBuildRelease(enableBuildRelease);
      existJob.setCollabNetURL(collabNetURL);
      existJob.setCollabNetusername(collabNetusername);
      existJob.setCollabNetpassword(CIPasswordScrambler.mask(collabNetpassword));
      existJob.setCollabNetProject(collabNetProject);
      existJob.setCollabNetPackage(collabNetPackage);
      existJob.setCollabNetRelease(collabNetRelease);
      existJob.setCollabNetoverWriteFiles(collabNetoverWriteFiles);

      if (CI_CREATE_JOB_COMMAND.equals(jobType)) {
        administrator.createJob(project, existJob);
        addActionMessage(getText(SUCCESS_JOB));
      } else if (CI_UPDATE_JOB_COMMAND.equals(jobType)) {
        administrator.updateJob(project, existJob);
        addActionMessage(getText(SUCCESS_UPDATE));
      }

      restartJenkins(); // TODO: reload config

      getHttpRequest().setAttribute(REQ_SELECTED_MENU, APPLICATIONS);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.doUpdateSave()" + FrameworkUtil.getStackTraceAsString(e));
      addActionMessage(getText(CI_SAVE_UPDATE_FAILED, e.getLocalizedMessage()));
    }

    return ci();
  }