/** * Returns true if in offline mode, "false" if not speciied. * Can be overriden by */ protected boolean isOnline() { String isOnline = getConfig(Config.online); if (isOnline != null) { return Configs.asBoolean(isOnline); } Boolean ret = asBooleanFromGlobalProp("fabric8.online"); return ret != null ? ret : getDefaultOnline(); }
protected Boolean asBooleanFromGlobalProp(String prop) { String value = getProject().getProperties().getProperty(prop); if (value == null) { value = System.getProperty(prop); } return value != null ? Boolean.valueOf(value) : null; }
if (!isOnline()) { getLog().info("Not looking for service " + serviceName + " as we are in offline mode"); return null; } else { try { KubernetesClient kubernetes = getKubernetes(); String ns = kubernetes.getNamespace(); if (Strings.isNullOrBlank(ns)) { ns = getNamespace(); Stack<Throwable> stack = unfoldExceptions(e); while (!stack.isEmpty()) { Throwable t = stack.pop(); if (t instanceof ConnectException || "No route to host".equals(t.getMessage())) { getLog().warn("Cannot connect to Kubernetes to find URL for service %s : %s", serviceName, cause.getMessage()); return null; } else if (t instanceof IllegalArgumentException || t.getMessage() != null && t.getMessage().matches("^No.*found.*$")) { getLog().warn("%s", cause.getMessage()); return null; }; getLog().warn("Cannot find URL for service %s : %s", serviceName, cause.getMessage()); return null;
private KubernetesClient getKubernetes() { if (kubernetesClient == null) { String namespace = getNamespace(); kubernetesClient = new ClusterAccess(namespace).createDefaultClient(log); } return kubernetesClient; }
private String getNamespace() { String namespace = getContext().getNamespace(); if (Strings.isNullOrBlank(namespace)) { namespace = KubernetesHelper.defaultNamespace(); } return Strings.isNullOrBlank(namespace) ? DEFAULT_NAMESPACE : namespace; }