コード例 #1
0
  /**
   * Add git container to application associated to server
   *
   * @param application
   * @return
   * @throws ServiceException
   * @throws CheckException
   */
  private Module addGitContainer(Application application, String tagName)
      throws ServiceException, CheckException {

    Module moduleGit = ModuleFactory.getModule("git");
    // todo : externaliser la variable
    String containerGitAddress = "/cloudunit/git/.git";

    try {
      // Assign fixed host ports for forwarding git ports (22)
      Map<String, String> mapProxyPorts = portUtils.assignProxyPorts(application);
      String freeProxySshPortNumber = mapProxyPorts.get("freeProxySshPortNumber");

      // Creation of git container fo application
      moduleGit.setName("git");
      moduleGit.setImage(imageService.findByName("git"));
      moduleGit.setApplication(application);

      moduleGit.setSshPort(freeProxySshPortNumber);
      moduleGit = moduleService.initModule(application, moduleGit, tagName);

      application.getModules().add(moduleGit);
      application.setGitContainerIP(moduleGit.getContainerIP());

      application.setGitSshProxyPort(freeProxySshPortNumber);

      // Update GIT respository informations in the current application
      application.setGitAddress(
          "ssh://"
              + AlphaNumericsCharactersCheckUtils.convertToAlphaNumerics(
                  application.getUser().getLogin())
              + "@"
              + application.getName()
              + "."
              + application.getSuffixCloudUnitIO().substring(1)
              + ":"
              + application.getGitSshProxyPort()
              + containerGitAddress);

      moduleGit.setStatus(Status.START);
      moduleGit = moduleService.update(moduleGit);

    } catch (UnsupportedEncodingException e) {
      moduleGit.setStatus(Status.FAIL);
      logger.error("Error :  Error during persist git module " + e);
      throw new ServiceException(e.getLocalizedMessage(), e);
    }
    return moduleGit;
  }