private void waitForManagementWebServices(
      final boolean isSecureConnection,
      final String username,
      final String password,
      final Integer restPort,
      final Integer webuiPort,
      final long end,
      final MachineDetails[] servers)
      throws MalformedURLException, URISyntaxException, InterruptedException, TimeoutException,
          CLIException {
    // Wait for rest to become available
    // When the rest gateway is up and running, the cloud is ready to go
    for (final MachineDetails server : servers) {
      String ipAddress = null;
      if (cloud.getConfiguration().isBootstrapManagementOnPublicIp()) {
        ipAddress = server.getPublicAddress();
      } else {
        ipAddress = server.getPrivateAddress();
      }

      final URL restAdminUrl =
          new URI(
                  ShellUtils.getRestProtocol(isSecureConnection),
                  null,
                  ipAddress,
                  restPort,
                  null,
                  null,
                  null)
              .toURL();
      final URL webUIUrl =
          new URI(
                  ShellUtils.getRestProtocol(isSecureConnection),
                  null,
                  ipAddress,
                  webuiPort,
                  null,
                  null,
                  null)
              .toURL();

      // We are relying on start-management command to be run on the
      // new machine, so everything should be up if the rest admin is up
      waitForConnection(
          username,
          password,
          restAdminUrl,
          isSecureConnection,
          CalcUtils.millisUntil(end),
          TimeUnit.MILLISECONDS);

      logger.info("Rest service is available at: " + restAdminUrl + '.');
      logger.info("Webui service is available at: " + webUIUrl + '.');
    }
  }
Esempio n. 2
0
  /**
   * ****** .
   *
   * @param url .
   * @param isSecureConnection .
   * @return .
   * @throws MalformedURLException .
   */
  public static String getFormattedRestUrl(final String url, final boolean isSecureConnection)
      throws MalformedURLException {
    String formattedURL = url;
    if (!formattedURL.endsWith("/")) {
      formattedURL = formattedURL + '/';
    }

    final String protocolPrefix = ShellUtils.getRestProtocol(isSecureConnection) + "://";
    if (!formattedURL.startsWith("http://") && !formattedURL.startsWith("https://")) {
      formattedURL = protocolPrefix + formattedURL;
    }

    URL urlObj;
    urlObj = new URL(formattedURL);
    if (urlObj.getPort() == -1) {
      final StringBuilder urlSB = new StringBuilder(formattedURL);
      final int portIndex = formattedURL.indexOf("/", protocolPrefix.length() + 1);
      urlSB.insert(portIndex, ':' + ShellUtils.getDefaultRestPortAsString(isSecureConnection));
      formattedURL = urlSB.toString();
      urlObj = new URL(formattedURL);
    }

    return formattedURL;
  }