Пример #1
0
  public String setup() {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method  CI.setup()");
    }
    try {
      ProjectRuntimeManager runtimeManager = PhrescoFrameworkFactory.getProjectRuntimeManager();
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      ActionType actionType = ActionType.JENKINS_SETUP;
      actionType.setWorkingDirectory(Utility.getJenkinsHome());
      if (debugEnabled) {
        S_LOGGER.debug("Jenkins Home " + Utility.getJenkinsHome().toString());
      }

      // Here we have to place two files in jenkins_home environment variable location
      administrator.getJdkHomeXml();
      administrator.getMavenHomeXml();
      // place email ext plugin in plugin folder
      administrator.getEmailExtPlugin();
      BufferedReader reader = runtimeManager.performAction(project, actionType, null, null);
      getHttpSession().setAttribute(projectCode + CI_SETUP, reader);
      getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
      getHttpRequest().setAttribute(REQ_TEST_TYPE, CI_SETUP);
    } catch (Exception e) {
      if (debugEnabled) {
        S_LOGGER.error(
            "Entered into catch block of CI.setup()" + FrameworkUtil.getStackTraceAsString(e));
      }
    }
    return APP_ENVIRONMENT_READER;
  }
Пример #2
0
 public String localJenkinsLocalAlive() {
   S_LOGGER.debug("Entering Method CI.localJenkinsLocalAlive()");
   try {
     URL url =
         new URL(
             HTTP_PROTOCOL
                 + PROTOCOL_POSTFIX
                 + LOCALHOST
                 + COLON
                 + Integer.parseInt(getPortNo(Utility.getJenkinsHome()))
                 + FORWARD_SLASH
                 + CI);
     URLConnection connection = url.openConnection();
     HttpURLConnection httpConnection = (HttpURLConnection) connection;
     int code = httpConnection.getResponseCode();
     localJenkinsAlive = code + "";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   } catch (ConnectException e) {
     localJenkinsAlive = "404";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   } catch (Exception e) {
     localJenkinsAlive = "404";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   }
   return SUCCESS;
 }
Пример #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());
    }
  }
Пример #4
0
  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;
  }
Пример #5
0
  public String stopJenkins() {
    S_LOGGER.debug("Entering Method  CI.stopJenkins()");
    try {
      ProjectRuntimeManager runtimeManager = PhrescoFrameworkFactory.getProjectRuntimeManager();
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      ActionType actionType = ActionType.JENKINS_STOP;
      actionType.setWorkingDirectory(Utility.getJenkinsHome());
      S_LOGGER.debug("Jenkins Home " + Utility.getJenkinsHome().toString());
      BufferedReader reader = runtimeManager.performAction(project, actionType, null, null);

      getHttpSession().setAttribute(projectCode + CI_STOP, reader);
      getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
      getHttpRequest().setAttribute(REQ_TEST_TYPE, CI_STOP);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.stopJenkins()" + FrameworkUtil.getStackTraceAsString(e));
    }
    return APP_ENVIRONMENT_READER;
  }
Пример #6
0
  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();
  }