コード例 #1
0
  @Override
  @Transactional
  public Application deploy(File file, Application application)
      throws ServiceException, CheckException {

    int code = -1;
    Map<String, String> configShell = new HashMap<>();

    try {
      // get app with all its components

      for (Server server : application.getServers()) {

        // loading server ssh informations

        String rootPassword = server.getApplication().getUser().getPassword();
        configShell.put("port", server.getSshPort());
        configShell.put("dockerManagerAddress", application.getManagerIp());
        configShell.put("password", rootPassword);
        String destFile = "/cloudunit/tmp/";

        // send the file on container

        shellUtils.sendFile(
            file, rootPassword, server.getSshPort(), application.getManagerIp(), destFile);

        // call deployment script

        code =
            shellUtils.executeShell(
                "bash /cloudunit/scripts/deploy.sh "
                    + file.getName()
                    + " "
                    + application.getUser().getLogin(),
                configShell);
      }

      // if all is ok, create a new deployment tag and set app to starting

      if (code == 0) {
        deploymentService.create(application, Type.WAR);
      } else {
        throw new CheckException("No way to deploy application " + file + ", " + application);
      }

    } catch (Exception e) {
      throw new ServiceException(e.getLocalizedMessage(), e);
    }

    return application;
  }
コード例 #2
0
  @Transactional
  public void deployToContainerId(
      String applicationName, String containerId, File file, String destFile)
      throws ServiceException {

    try {
      Application application =
          this.findByNameAndUser(authentificationUtils.getAuthentificatedUser(), applicationName);

      Map<String, String> configShell = new HashMap<>();

      String sshPort = application.getSShPortByContainerId(containerId);
      String rootPassword = application.getUser().getPassword();
      configShell.put("port", sshPort);
      configShell.put("dockerManagerAddress", application.getManagerIp());
      configShell.put("password", rootPassword);

      // send the file on container
      shellUtils.sendFile(file, rootPassword, sshPort, application.getManagerIp(), destFile);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }