public URL getRootUrl() {
   try {
     return new URL(
         URLUtils.join(config.getMasterUrl().toString(), "api", config.getApiVersion()));
   } catch (MalformedURLException e) {
     throw KubernetesClientException.launderThrowable(e);
   }
 }
Exemple #2
0
  public static Configuration fromMap(Map<String, String> map) {
    Configuration configuration = new Configuration();
    try {
      configuration.masterUrl =
          getStringProperty(KUBERNETES_MASTER, map, FALLBACK_CONFIG.getMasterUrl());
      configuration.environment = getStringProperty(FABRIC8_ENVIRONMENT, map, null);
      configuration.environmentInitEnabled =
          getBooleanProperty(ENVIRONMENT_INIT_ENABLED, map, true);
      configuration.environmentConfigUrl = getKubernetesConfigurationUrl(map);
      configuration.environmentDependencies =
          Strings.splitAndTrimAsList(getStringProperty(ENVIRONMENT_DEPENDENCIES, map, ""), " ");

      configuration.namespaceLazyCreateEnabled =
          getBooleanProperty(
              NAMESPACE_LAZY_CREATE_ENABLED, map, DEFAULT_NAMESPACE_LAZY_CREATE_ENABLED);

      String existingNamespace = getStringProperty(NAMESPACE_TO_USE, map, null);
      String environmentNamespace = findNamespaceForEnvironment(configuration.environment, map);
      configuration.namespaceToUse = selectNamespace(environmentNamespace, existingNamespace);

      // We default to "cleanup=true" when generating namespace and "cleanup=false" when using
      // existing namespace.
      configuration.namespaceCleanupEnabled =
          getBooleanProperty(
              NAMESPACE_CLEANUP_ENABLED, map, Strings.isNullOrBlank(configuration.namespaceToUse));
      configuration.namespaceCleanupConfirmationEnabled =
          getBooleanProperty(NAMESPACE_CLEANUP_CONFIRM_ENABLED, map, false);
      configuration.namespaceCleanupTimeout =
          getLongProperty(NAMESPACE_CLEANUP_TIMEOUT, map, DEFAULT_NAMESPACE_CLEANUP_TIMEOUT);

      configuration.waitTimeout = getLongProperty(WAIT_TIMEOUT, map, DEFAULT_WAIT_TIMEOUT);
      configuration.waitPollInterval =
          getLongProperty(WAIT_POLL_INTERVAL, map, DEFAULT_WAIT_POLL_INTERVAL);
      configuration.waitForServiceList =
          Strings.splitAndTrimAsList(getStringProperty(WAIT_FOR_SERVICE_LIST, map, ""), " ");
      configuration.waitForServiceConnectionEnabled =
          getBooleanProperty(
              WAIT_FOR_SERVICE_CONNECTION_ENABLED,
              map,
              DEFAULT_WAIT_FOR_SERVICE_CONNECTION_ENABLED);
      configuration.waitForServiceConnectionTimeout =
          getLongProperty(
              WAIT_FOR_SERVICE_CONNECTION_TIMEOUT, map, DEFAULT_NAMESPACE_CLEANUP_TIMEOUT);

      configuration.ansiLoggerEnabled = getBooleanProperty(ANSI_LOGGER_ENABLED, map, true);
      configuration.kubernetesDomain = getStringProperty(KUBERNETES_DOMAIN, map, "vagrant.f8");
      configuration.gofabric8Enabled = getBooleanProperty(GOFABRIC8_ENABLED, map, false);

      configuration.properties = map;
    } catch (Throwable t) {
      if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
      } else {
        throw new RuntimeException(t);
      }
    }
    return configuration;
  }
 public ReplicationControllerOperationsImpl(OkHttpClient client, Config config, String namespace) {
   this(
       client,
       config,
       null,
       namespace,
       null,
       true,
       null,
       null,
       false,
       false,
       config.getRollingTimeout(),
       TimeUnit.MINUTES);
 }
  /**
   * Checks if the response status code is the expected and throws the appropriate
   * KubernetesClientException if not.
   *
   * @param request The {#link Request} object.
   * @param response The {@link Response} object.
   * @param expectedStatusCode The expected status code.
   * @throws KubernetesClientException When the response code is not the expected.
   */
  protected void assertResponseCode(Request request, Response response, int expectedStatusCode) {
    int statusCode = response.code();
    String customMessage = config.getErrorMessages().get(statusCode);

    if (statusCode == expectedStatusCode) {
      return;
    } else if (customMessage != null) {
      throw requestFailure(request, createStatus(statusCode, customMessage));
    } else {
      try {
        Status status = JSON_MAPPER.readValue(response.body().byteStream(), Status.class);
        throw requestFailure(request, status);
      } catch (IOException e) {
        throw requestFailure(request, createStatus(statusCode, ""));
      }
    }
  }