discovery service cleanup part 1 (#1041)

* minor clean-up

* retrigger build

* retrigger build

* more clean-up

* trigger
This commit is contained in:
erabii
2022-08-18 00:01:46 +03:00
committed by GitHub
parent 8f0d4f2b60
commit 5aff4d3f8d
8 changed files with 30 additions and 61 deletions

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2019-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.kubernetes.client.discovery;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ConditionalOnProperty(value = "spring.cloud.kubernetes.discovery.enabled", matchIfMissing = true)
public @interface ConditionalOnKubernetesDiscoveryEnabled {
}

View File

@@ -45,6 +45,7 @@ import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAu
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.PodUtils;
import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.context.ApplicationEventPublisher;

View File

@@ -43,9 +43,9 @@ import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIn
import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator;
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration;
import org.springframework.cloud.kubernetes.client.KubernetesClientPodUtils;
import org.springframework.cloud.kubernetes.client.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2019 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.kubernetes.fabric8.discovery;
package org.springframework.cloud.kubernetes.commons.discovery;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -29,8 +29,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
* Provides a more succinct conditional
* <code>spring.cloud.kubernetes.discovery.enabled</code>.
*
* @author Tim Ysewyn
* @since 2.2.0
* @author wind57
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@@ -24,25 +24,22 @@ import org.springframework.context.ApplicationEventPublisher;
/**
* @author Ryan Baxter
*/
public class KubernetesDiscoveryClientHealthIndicatorInitializer implements InitializingBean {
public final class KubernetesDiscoveryClientHealthIndicatorInitializer implements InitializingBean {
private PodUtils podUtils;
private final PodUtils<?> podUtils;
private ApplicationEventPublisher applicationEventPublisher;
private final ApplicationEventPublisher applicationEventPublisher;
public KubernetesDiscoveryClientHealthIndicatorInitializer(PodUtils podUtils,
public KubernetesDiscoveryClientHealthIndicatorInitializer(PodUtils<?> podUtils,
ApplicationEventPublisher applicationEventPublisher) {
this.podUtils = podUtils;
this.applicationEventPublisher = applicationEventPublisher;
}
public void initialize() {
this.applicationEventPublisher.publishEvent(new InstanceRegisteredEvent<>(podUtils.currentPod(), null));
}
@Override
public void afterPropertiesSet() {
this.initialize();
this.applicationEventPublisher.publishEvent(new InstanceRegisteredEvent<>(podUtils.currentPod(), null));
}
}

View File

@@ -21,8 +21,9 @@ import java.util.Map;
import java.util.Objects;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.style.ToStringCreator;
public class KubernetesServiceInstance implements ServiceInstance {
public final class KubernetesServiceInstance implements ServiceInstance {
/**
* Key of the namespace metadata.
@@ -33,10 +34,6 @@ public class KubernetesServiceInstance implements ServiceInstance {
private static final String HTTPS_PREFIX = "https";
private static final String DSL = "//";
private static final String COLON = ":";
private String instanceId;
private String serviceId;
@@ -61,7 +58,7 @@ public class KubernetesServiceInstance implements ServiceInstance {
* @param host the address where the service instance can be found.
* @param port the port on which the service is running.
* @param metadata a map containing metadata.
* @param secure indicates whether or not the connection needs to be secure.
* @param secure indicates whether the connection needs to be secure.
*/
public KubernetesServiceInstance(String instanceId, String serviceId, String host, int port,
Map<String, String> metadata, Boolean secure) {
@@ -82,9 +79,9 @@ public class KubernetesServiceInstance implements ServiceInstance {
* @param host the address where the service instance can be found.
* @param port the port on which the service is running.
* @param metadata a map containing metadata.
* @param secure indicates whether or not the connection needs to be secure.
* @param secure indicates whether the connection needs to be secure.
* @param namespace the namespace of the service.
* @param cluster the clust the service resides in.
* @param cluster the cluster the service resides in.
*/
public KubernetesServiceInstance(String instanceId, String serviceId, String host, int port,
Map<String, String> metadata, Boolean secure, String namespace, String cluster) {
@@ -143,7 +140,7 @@ public class KubernetesServiceInstance implements ServiceInstance {
}
private URI createUri(String scheme, String host, int port) {
return URI.create(scheme + COLON + DSL + host + COLON + port);
return URI.create(scheme + "://" + host + ":" + port);
}
public String getNamespace() {
@@ -212,9 +209,18 @@ public class KubernetesServiceInstance implements ServiceInstance {
@Override
public String toString() {
return "KubernetesServiceInstance{" + "instanceId='" + instanceId + '\'' + ", serviceId='" + serviceId + '\''
+ ", host='" + host + '\'' + ", port=" + port + ", uri=" + uri + ", secure=" + secure + ", namespace="
+ getNamespace() + ", cluster=" + cluster + ", metadata=" + metadata + '}';
ToStringCreator creator = new ToStringCreator(this);
creator.append("instanceId", instanceId);
creator.append("serviceId", serviceId);
creator.append("host", host);
creator.append("port", port);
creator.append("uri", uri);
creator.append("secure", secure);
creator.append("namespace", getNamespace());
creator.append("cluster", cluster);
creator.append("metadata", metadata);
return creator.toString();
}
@Override

View File

@@ -31,6 +31,7 @@ import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.PodUtils;
import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;

View File

@@ -32,8 +32,8 @@ import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCom
import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties;
import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator;
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.cloud.kubernetes.fabric8.discovery.ConditionalOnKubernetesDiscoveryEnabled;
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction;
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;