Remove deprecations.

This commit is contained in:
Olga Maciaszek-Sharma
2020-12-10 12:31:45 +01:00
parent 8739f8c233
commit 8969d5d1e1
13 changed files with 15 additions and 575 deletions

View File

@@ -73,32 +73,6 @@ public class DefaultServiceInstance implements ServiceInstance {
this(instanceId, serviceId, host, port, secure, new LinkedHashMap<>());
}
/**
* @param serviceId the id of the service.
* @param host the host where the service instance can be found.
* @param port the port on which the service is running.
* @param secure indicates whether or not the connection needs to be secure.
* @param metadata a map containing metadata.
* @deprecated - use other constructors
*/
@Deprecated
public DefaultServiceInstance(String serviceId, String host, int port, boolean secure,
Map<String, String> metadata) {
this(null, serviceId, host, port, secure, metadata);
}
/**
* @param serviceId the id of the service.
* @param host the host where the service instance can be found.
* @param port the port on which the service is running.
* @param secure indicates whether or not the connection needs to be secure.
* @deprecated - use other constructors
*/
@Deprecated
public DefaultServiceInstance(String serviceId, String host, int port, boolean secure) {
this(serviceId, host, port, secure, new LinkedHashMap<>());
}
public DefaultServiceInstance() {
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2012-2020 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.client.discovery.noop;
import java.util.Collections;
import java.util.List;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
/**
* DiscoveryClient used when no implementations are found on the classpath.
*
* @deprecated Use
* {@link org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient
* instead}.
* @author Dave Syer
*/
@Deprecated
public class NoopDiscoveryClient implements DiscoveryClient {
public NoopDiscoveryClient(ServiceInstance instance) {
}
@Override
public String description() {
return "Spring Cloud No-op DiscoveryClient";
}
@Override
public List<ServiceInstance> getInstances(String serviceId) {
return Collections.emptyList();
}
@Override
public List<String> getServices() {
return Collections.emptyList();
}
}

View File

@@ -1,145 +0,0 @@
/*
* Copyright 2012-2020 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.client.discovery.noop;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;
/**
* @deprecated Use
* {@link org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration
* instead}.
* @author Dave Syer
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnMissingBean(DiscoveryClient.class)
@Deprecated
public class NoopDiscoveryClientAutoConfiguration implements ApplicationListener<ContextRefreshedEvent> {
private final Log log = LogFactory.getLog(NoopDiscoveryClientAutoConfiguration.class);
@Autowired(required = false)
private ServerProperties server;
@Autowired
private ApplicationContext context;
@Autowired
private Environment environment;
@Autowired(required = false)
private PortFinder portFinder;
private DefaultServiceInstance serviceInstance;
@PostConstruct
public void init() {
String host = "localhost";
try {
host = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e) {
this.log.warn("Cannot get host info: (" + e.getMessage() + ")");
}
int port = findPort();
this.serviceInstance = new DefaultServiceInstance(
this.environment.getProperty("spring.application.name", "application"), host, port, false);
}
private int findPort() {
int port = 0;
if (this.server != null && this.server.getPort() != null) {
port = this.server.getPort();
}
if (port != 0 && this.portFinder != null) {
Integer found = this.portFinder.findPort();
if (found != null) {
port = found;
}
}
else {
// Apparently spring-web is not on the classpath
if (this.log.isDebugEnabled()) {
this.log.debug("Could not locate port in embedded container (spring-web not available)");
}
}
return port;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
this.context.publishEvent(new InstanceRegisteredEvent<>(this, this.environment));
}
@Bean
public DiscoveryClient discoveryClient() {
return new NoopDiscoveryClient(this.serviceInstance);
}
private interface PortFinder {
Integer findPort();
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = { "org.springframework.web.context.support.GenericWebApplicationContext",
"org.springframework.boot.context.embedded.EmbeddedWebApplicationContext" })
protected static class Boot15PortFinderConfiguration {
@Bean
public PortFinder portFinder(final ApplicationContext context) {
return new PortFinder() {
@Override
public Integer findPort() {
// TODO: support reactive
/*
* if (context instanceof EmbeddedWebApplicationContext) {
* EmbeddedServletContainer container =
* ((EmbeddedWebApplicationContext) context)
* .getEmbeddedServletContainer(); if (container != null) { return
* container.getPort(); } }
*/
return null;
}
};
}
}
}

View File

@@ -24,7 +24,6 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
@@ -38,7 +37,7 @@ import org.springframework.core.annotation.Order;
* @author Charu Covindane
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class })
@AutoConfigureBefore({ CommonsClientAutoConfiguration.class })
public class SimpleDiscoveryClientAutoConfiguration implements ApplicationListener<WebServerInitializedEvent> {
private ServerProperties server;

View File

@@ -16,9 +16,7 @@
package org.springframework.cloud.client.discovery.simple;
import java.net.URI;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -26,7 +24,6 @@ import javax.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
/**
@@ -89,103 +86,4 @@ public class SimpleDiscoveryProperties {
local = new DefaultServiceInstance(null, serviceId, host, port, false);
}
/**
* Basic implementation of {@link ServiceInstance}.
*
* @deprecated in favor of {@link DefaultServiceInstance}
*/
@Deprecated
public static class SimpleServiceInstance implements ServiceInstance {
/**
* The URI of the service instance. Will be parsed to extract the scheme, host,
* and port.
*/
private URI uri;
private String host;
private int port;
private boolean secure;
/**
* Metadata for the service instance. Can be used by discovery clients to modify
* their behaviour per instance, e.g. when load balancing.
*/
private Map<String, String> metadata = new LinkedHashMap<>();
/**
* The unique identifier or name for the service instance.
*/
private String instanceId;
/**
* The identifier or name for the service. Multiple instances might share the same
* service ID.
*/
private String serviceId;
public SimpleServiceInstance() {
}
public SimpleServiceInstance(URI uri) {
setUri(uri);
}
@Override
public String getInstanceId() {
return this.instanceId;
}
public void setInstanceId(String id) {
this.instanceId = id;
}
@Override
public String getServiceId() {
return this.serviceId;
}
public void setServiceId(String id) {
this.serviceId = id;
}
@Override
public String getHost() {
return this.host;
}
@Override
public int getPort() {
return this.port;
}
@Override
public boolean isSecure() {
return this.secure;
}
@Override
public URI getUri() {
return this.uri;
}
public void setUri(URI uri) {
this.uri = uri;
this.host = this.uri.getHost();
this.port = this.uri.getPort();
String scheme = this.uri.getScheme();
if ("https".equals(scheme)) {
this.secure = true;
}
}
@Override
public Map<String, String> getMetadata() {
return this.metadata;
}
}
}

View File

@@ -16,9 +16,7 @@
package org.springframework.cloud.client.discovery.simple.reactive;
import java.net.URI;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -91,101 +89,4 @@ public class SimpleReactiveDiscoveryProperties {
}
}
/**
* Basic implementation of {@link ServiceInstance}.
*/
@Deprecated
public static class SimpleServiceInstance implements ServiceInstance {
/**
* The URI of the service instance. Will be parsed to extract the scheme, host,
* and port.
*/
private URI uri;
private String host;
private int port;
private boolean secure;
/**
* Metadata for the service instance. Can be used by discovery clients to modify
* their behaviour per instance, e.g. when load balancing.
*/
private Map<String, String> metadata = new LinkedHashMap<>();
/**
* The unique identifier or name for the service instance.
*/
private String instanceId;
/**
* The identifier or name for the service. Multiple instances might share the same
* service ID.
*/
private String serviceId;
public SimpleServiceInstance() {
}
public SimpleServiceInstance(URI uri) {
setUri(uri);
}
@Override
public String getInstanceId() {
return this.instanceId;
}
public void setInstanceId(String id) {
this.instanceId = id;
}
@Override
public String getServiceId() {
return this.serviceId;
}
public void setServiceId(String id) {
this.serviceId = id;
}
@Override
public String getHost() {
return this.host;
}
@Override
public int getPort() {
return this.port;
}
@Override
public boolean isSecure() {
return this.secure;
}
@Override
public URI getUri() {
return this.uri;
}
public void setUri(URI uri) {
this.uri = uri;
this.host = this.uri.getHost();
this.port = this.uri.getPort();
String scheme = this.uri.getScheme();
if ("https".equals(scheme)) {
this.secure = true;
}
}
@Override
public Map<String, String> getMetadata() {
return this.metadata;
}
}
}

View File

@@ -43,11 +43,6 @@ public class DefaultResponse implements Response<ServiceInstance> {
return this.serviceInstance;
}
@Override
public void onComplete(CompletionContext completionContext) {
// do nothing: deprecated interface method
}
@Override
public String toString() {
ToStringCreator to = new ToStringCreator(this);

View File

@@ -33,9 +33,4 @@ public class EmptyResponse implements Response<ServiceInstance> {
return null;
}
@Override
public void onComplete(CompletionContext completionContext) {
// do nothing: deprecated interface method
}
}

View File

@@ -28,13 +28,4 @@ public interface Response<T> {
T getServer();
/**
* Notification that the request completed.
* @deprecated in favour of
* {@link LoadBalancerLifecycle#onComplete(CompletionContext)}
* @param completionContext - completion context
*/
@Deprecated
void onComplete(CompletionContext completionContext);
}

View File

@@ -4,7 +4,6 @@ org.springframework.cloud.client.CommonsClientAutoConfiguration,\
org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration,\
org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration,\
org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration,\
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration,\
org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration,\
org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration,\
org.springframework.cloud.client.hypermedia.CloudHypermediaAutoConfiguration,\

View File

@@ -16,18 +16,13 @@
package org.springframework.cloud.loadbalancer.core;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import reactor.core.publisher.Flux;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.core.env.Environment;
import static org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory.PROPERTY_NAME;
/**
* A {@link Supplier} of lists of {@link ServiceInstance} objects.
@@ -47,112 +42,4 @@ public interface ServiceInstanceListSupplier extends Supplier<Flux<List<ServiceI
return new ServiceInstanceListSupplierBuilder();
}
static FixedServiceInstanceListSupplier.Builder fixed(Environment environment) {
return new FixedServiceInstanceListSupplier.Builder(environment);
}
static FixedServiceInstanceListSupplier.SimpleBuilder fixed(String serviceId) {
return new FixedServiceInstanceListSupplier.SimpleBuilder(serviceId);
}
class FixedServiceInstanceListSupplier implements ServiceInstanceListSupplier {
private final String serviceId;
private List<ServiceInstance> instances;
@Deprecated
public static Builder with(Environment env) {
return new Builder(env);
}
private FixedServiceInstanceListSupplier(String serviceId, List<ServiceInstance> instances) {
this.serviceId = serviceId;
this.instances = instances;
}
@Override
public String getServiceId() {
return serviceId;
}
@Override
public Flux<List<ServiceInstance>> get() {
return Flux.just(instances);
}
@Deprecated
public static final class SimpleBuilder {
private final ArrayList<ServiceInstance> instances = new ArrayList<>();
private final String serviceId;
private SimpleBuilder(String serviceId) {
this.serviceId = serviceId;
}
public SimpleBuilder instance(ServiceInstance instance) {
instances.add(instance);
return this;
}
public SimpleBuilder instance(int port) {
return instance("localhost", port);
}
public SimpleBuilder instance(String host, int port) {
DefaultServiceInstance instance = new DefaultServiceInstance(instanceId(serviceId, host, port),
serviceId, host, port, false);
return instance(instance);
}
private String instanceId(String serviceId, String host, int port) {
return serviceId + ":" + host + ":" + port;
}
public FixedServiceInstanceListSupplier build() {
return new FixedServiceInstanceListSupplier(serviceId, instances);
}
}
@Deprecated
public static final class Builder {
private final Environment env;
private final ArrayList<ServiceInstance> instances = new ArrayList<>();
private Builder(Environment env) {
this.env = env;
}
public Builder instance(ServiceInstance instance) {
instances.add(instance);
return this;
}
public Builder instance(int port, String serviceId) {
return instance("localhost", port, serviceId);
}
public Builder instance(String host, int port, String serviceId) {
DefaultServiceInstance instance = new DefaultServiceInstance(instanceId(serviceId, host, port),
serviceId, host, port, false);
return instance(instance);
}
private String instanceId(String serviceId, String host, int port) {
return serviceId + ":" + host + ":" + port;
}
public FixedServiceInstanceListSupplier build() {
return new FixedServiceInstanceListSupplier(env.getProperty(PROPERTY_NAME), instances);
}
}
}
}

View File

@@ -41,6 +41,7 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerProperties;
import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.bind.annotation.GetMapping;
@@ -91,11 +92,12 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldCheckInstanceWithProvidedHealthCheckPath() {
String serviceId = "ignored-service";
healthCheck.getPath().put("ignored-service", "/health");
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();
@@ -105,10 +107,11 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldCheckInstanceWithDefaultHealthCheckPath() {
String serviceId = "ignored-service";
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();
@@ -118,11 +121,12 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldReturnFalseIfEndpointNotFound() {
healthCheck.getPath().put("ignored-service", "/test");
String serviceId = "ignored-service";
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
healthCheck.getPath().put(serviceId, "/test");
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();

View File

@@ -34,7 +34,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.CompletionContext;
import org.springframework.cloud.client.loadbalancer.DefaultRequest;
import org.springframework.cloud.client.loadbalancer.DefaultRequestContext;
import org.springframework.cloud.client.loadbalancer.DefaultResponse;
@@ -99,8 +98,6 @@ public class LoadBalancerTests {
else {
then(instance.isSecure()).isFalse();
}
response.onComplete(new CompletionContext(CompletionContext.Status.SUCCESS));
}).verifyComplete();
}
}