Bumping versions
This commit is contained in:
@@ -113,8 +113,7 @@ public class AppRunner implements AutoCloseable {
|
||||
}
|
||||
|
||||
private boolean tlsEnabled() {
|
||||
return app.getEnvironment().getProperty("server.ssl.enabled", Boolean.class,
|
||||
false);
|
||||
return app.getEnvironment().getProperty("server.ssl.enabled", Boolean.class, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,16 +64,14 @@ public abstract class BaseCertTest {
|
||||
}
|
||||
|
||||
private static File saveKeyAndCert(KeyAndCert keyCert) throws Exception {
|
||||
return saveKeyStore(keyCert.subject(),
|
||||
() -> keyCert.storeKeyAndCert(KEY_PASSWORD));
|
||||
return saveKeyStore(keyCert.subject(), () -> keyCert.storeKeyAndCert(KEY_PASSWORD));
|
||||
}
|
||||
|
||||
private static File saveCert(KeyAndCert keyCert) throws Exception {
|
||||
return saveKeyStore(keyCert.subject(), () -> keyCert.storeCert());
|
||||
}
|
||||
|
||||
private static File saveKeyStore(String prefix, KeyStoreSupplier func)
|
||||
throws Exception {
|
||||
private static File saveKeyStore(String prefix, KeyStoreSupplier func) throws Exception {
|
||||
File result = File.createTempFile(prefix, ".p12");
|
||||
result.deleteOnExit();
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ public class EurekaServerRunner extends AppRunner {
|
||||
property("server.ssl.client-auth", "need");
|
||||
}
|
||||
|
||||
public void setKeyStore(File keyStore, String keyStorePassword, String key,
|
||||
String keyPassword) {
|
||||
public void setKeyStore(File keyStore, String keyStorePassword, String key, String keyPassword) {
|
||||
property("server.ssl.key-store", pathOf(keyStore));
|
||||
property("server.ssl.key-store-type", "PKCS12");
|
||||
property("server.ssl.key-store-password", keyStorePassword);
|
||||
|
||||
@@ -70,8 +70,7 @@ public class KeyAndCert {
|
||||
KeyStore result = KeyStore.getInstance("PKCS12");
|
||||
result.load(null);
|
||||
|
||||
result.setKeyEntry(subject(), keyPair.getPrivate(), keyPassword.toCharArray(),
|
||||
certChain());
|
||||
result.setKeyEntry(subject(), keyPair.getPrivate(), keyPassword.toCharArray(), certChain());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,15 +50,12 @@ public class KeyTool {
|
||||
return new KeyAndCert(keyPair, certificate);
|
||||
}
|
||||
|
||||
public KeyAndCert signCertificate(String subject, KeyAndCert signer)
|
||||
throws Exception {
|
||||
public KeyAndCert signCertificate(String subject, KeyAndCert signer) throws Exception {
|
||||
return signCertificate(createKeyPair(), subject, signer);
|
||||
}
|
||||
|
||||
public KeyAndCert signCertificate(KeyPair keyPair, String subject, KeyAndCert signer)
|
||||
throws Exception {
|
||||
X509Certificate certificate = createCert(keyPair.getPublic(), signer.privateKey(),
|
||||
signer.subject(), subject);
|
||||
public KeyAndCert signCertificate(KeyPair keyPair, String subject, KeyAndCert signer) throws Exception {
|
||||
X509Certificate certificate = createCert(keyPair.getPublic(), signer.privateKey(), signer.subject(), subject);
|
||||
KeyAndCert result = new KeyAndCert(keyPair, certificate);
|
||||
|
||||
return result;
|
||||
@@ -76,32 +73,25 @@ public class KeyTool {
|
||||
|
||||
public X509Certificate createCert(KeyPair keyPair, String ca) throws Exception {
|
||||
JcaX509v3CertificateBuilder builder = certBuilder(keyPair.getPublic(), ca, ca);
|
||||
builder.addExtension(Extension.keyUsage, true,
|
||||
new KeyUsage(KeyUsage.keyCertSign));
|
||||
builder.addExtension(Extension.basicConstraints, false,
|
||||
new BasicConstraints(true));
|
||||
builder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyCertSign));
|
||||
builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(true));
|
||||
|
||||
return signCert(builder, keyPair.getPrivate());
|
||||
}
|
||||
|
||||
public X509Certificate createCert(PublicKey publicKey, PrivateKey privateKey,
|
||||
String issuer, String subject) throws Exception {
|
||||
public X509Certificate createCert(PublicKey publicKey, PrivateKey privateKey, String issuer, String subject)
|
||||
throws Exception {
|
||||
JcaX509v3CertificateBuilder builder = certBuilder(publicKey, issuer, subject);
|
||||
builder.addExtension(Extension.keyUsage, true,
|
||||
new KeyUsage(KeyUsage.digitalSignature));
|
||||
builder.addExtension(Extension.basicConstraints, false,
|
||||
new BasicConstraints(false));
|
||||
builder.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature));
|
||||
builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(false));
|
||||
|
||||
GeneralName[] names = new GeneralName[] {
|
||||
new GeneralName(GeneralName.dNSName, "localhost") };
|
||||
builder.addExtension(Extension.subjectAlternativeName, false,
|
||||
GeneralNames.getInstance(new DERSequence(names)));
|
||||
GeneralName[] names = new GeneralName[] { new GeneralName(GeneralName.dNSName, "localhost") };
|
||||
builder.addExtension(Extension.subjectAlternativeName, false, GeneralNames.getInstance(new DERSequence(names)));
|
||||
|
||||
return signCert(builder, privateKey);
|
||||
}
|
||||
|
||||
private JcaX509v3CertificateBuilder certBuilder(PublicKey publicKey, String issuer,
|
||||
String subject) {
|
||||
private JcaX509v3CertificateBuilder certBuilder(PublicKey publicKey, String issuer, String subject) {
|
||||
X500Name issuerName = new X500Name(String.format("dc=%s", issuer));
|
||||
X500Name subjectName = new X500Name(String.format("dc=%s", subject));
|
||||
|
||||
@@ -110,14 +100,11 @@ public class KeyTool {
|
||||
Date notBefore = new Date(now - ONE_DAY);
|
||||
Date notAfter = new Date(now + TEN_YEARS);
|
||||
|
||||
return new JcaX509v3CertificateBuilder(issuerName, serialNum, notBefore, notAfter,
|
||||
subjectName, publicKey);
|
||||
return new JcaX509v3CertificateBuilder(issuerName, serialNum, notBefore, notAfter, subjectName, publicKey);
|
||||
}
|
||||
|
||||
private X509Certificate signCert(JcaX509v3CertificateBuilder builder,
|
||||
PrivateKey privateKey) throws Exception {
|
||||
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA")
|
||||
.build(privateKey);
|
||||
private X509Certificate signCert(JcaX509v3CertificateBuilder builder, PrivateKey privateKey) throws Exception {
|
||||
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA").build(privateKey);
|
||||
X509CertificateHolder holder = builder.build(signer);
|
||||
|
||||
return new JcaX509CertificateConverter().getCertificate(holder);
|
||||
|
||||
@@ -56,19 +56,17 @@ public class CloudEurekaClient extends DiscoveryClient {
|
||||
|
||||
private AtomicReference<EurekaHttpClient> eurekaHttpClient = new AtomicReference<>();
|
||||
|
||||
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
|
||||
EurekaClientConfig config, ApplicationEventPublisher publisher) {
|
||||
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
|
||||
ApplicationEventPublisher publisher) {
|
||||
this(applicationInfoManager, config, null, publisher);
|
||||
}
|
||||
|
||||
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
|
||||
EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs<?> args,
|
||||
ApplicationEventPublisher publisher) {
|
||||
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
|
||||
AbstractDiscoveryClientOptionalArgs<?> args, ApplicationEventPublisher publisher) {
|
||||
super(applicationInfoManager, config, args);
|
||||
this.applicationInfoManager = applicationInfoManager;
|
||||
this.publisher = publisher;
|
||||
this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class,
|
||||
"eurekaTransport");
|
||||
this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class, "eurekaTransport");
|
||||
ReflectionUtils.makeAccessible(this.eurekaTransportField);
|
||||
}
|
||||
|
||||
@@ -81,8 +79,7 @@ public class CloudEurekaClient extends DiscoveryClient {
|
||||
}
|
||||
|
||||
public InstanceInfo getInstanceInfo(String appname, String instanceId) {
|
||||
EurekaHttpResponse<InstanceInfo> response = getEurekaHttpClient()
|
||||
.getInstance(appname, instanceId);
|
||||
EurekaHttpResponse<InstanceInfo> response = getEurekaHttpClient().getInstance(appname, instanceId);
|
||||
HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusCode());
|
||||
if (httpStatus.is2xxSuccessful() && response.getEntity() != null) {
|
||||
return response.getEntity();
|
||||
@@ -94,8 +91,8 @@ public class CloudEurekaClient extends DiscoveryClient {
|
||||
if (this.eurekaHttpClient.get() == null) {
|
||||
try {
|
||||
Object eurekaTransport = this.eurekaTransportField.get(this);
|
||||
Field registrationClientField = ReflectionUtils
|
||||
.findField(eurekaTransport.getClass(), "registrationClient");
|
||||
Field registrationClientField = ReflectionUtils.findField(eurekaTransport.getClass(),
|
||||
"registrationClient");
|
||||
ReflectionUtils.makeAccessible(registrationClientField);
|
||||
this.eurekaHttpClient.compareAndSet(null,
|
||||
(EurekaHttpClient) registrationClientField.get(eurekaTransport));
|
||||
@@ -108,8 +105,7 @@ public class CloudEurekaClient extends DiscoveryClient {
|
||||
}
|
||||
|
||||
public void setStatus(InstanceStatus newStatus, InstanceInfo info) {
|
||||
getEurekaHttpClient().statusUpdate(info.getAppName(), info.getId(), newStatus,
|
||||
info);
|
||||
getEurekaHttpClient().statusUpdate(info.getAppName(), info.getId(), newStatus, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,8 +64,7 @@ public class CloudEurekaTransportConfig implements EurekaTransportConfig {
|
||||
return sessionedClientReconnectIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setSessionedClientReconnectIntervalSeconds(
|
||||
int sessionedClientReconnectIntervalSeconds) {
|
||||
public void setSessionedClientReconnectIntervalSeconds(int sessionedClientReconnectIntervalSeconds) {
|
||||
this.sessionedClientReconnectIntervalSeconds = sessionedClientReconnectIntervalSeconds;
|
||||
}
|
||||
|
||||
@@ -73,8 +72,7 @@ public class CloudEurekaTransportConfig implements EurekaTransportConfig {
|
||||
return retryableClientQuarantineRefreshPercentage;
|
||||
}
|
||||
|
||||
public void setRetryableClientQuarantineRefreshPercentage(
|
||||
double retryableClientQuarantineRefreshPercentage) {
|
||||
public void setRetryableClientQuarantineRefreshPercentage(double retryableClientQuarantineRefreshPercentage) {
|
||||
this.retryableClientQuarantineRefreshPercentage = retryableClientQuarantineRefreshPercentage;
|
||||
}
|
||||
|
||||
@@ -82,8 +80,7 @@ public class CloudEurekaTransportConfig implements EurekaTransportConfig {
|
||||
return bootstrapResolverRefreshIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setBootstrapResolverRefreshIntervalSeconds(
|
||||
int bootstrapResolverRefreshIntervalSeconds) {
|
||||
public void setBootstrapResolverRefreshIntervalSeconds(int bootstrapResolverRefreshIntervalSeconds) {
|
||||
this.bootstrapResolverRefreshIntervalSeconds = bootstrapResolverRefreshIntervalSeconds;
|
||||
}
|
||||
|
||||
@@ -180,47 +177,36 @@ public class CloudEurekaTransportConfig implements EurekaTransportConfig {
|
||||
&& Objects.equals(readClusterVip, that.readClusterVip)
|
||||
&& Objects.equals(writeClusterVip, that.writeClusterVip)
|
||||
&& bootstrapResolverForQuery == that.bootstrapResolverForQuery
|
||||
&& Objects.equals(bootstrapResolverStrategy,
|
||||
that.bootstrapResolverStrategy)
|
||||
&& Objects.equals(bootstrapResolverStrategy, that.bootstrapResolverStrategy)
|
||||
&& applicationsResolverUseIp == that.applicationsResolverUseIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(sessionedClientReconnectIntervalSeconds,
|
||||
retryableClientQuarantineRefreshPercentage,
|
||||
bootstrapResolverRefreshIntervalSeconds,
|
||||
applicationsResolverDataStalenessThresholdSeconds,
|
||||
asyncResolverRefreshIntervalMs, asyncResolverWarmUpTimeoutMs,
|
||||
asyncExecutorThreadPoolSize, readClusterVip, writeClusterVip,
|
||||
bootstrapResolverForQuery, bootstrapResolverStrategy,
|
||||
return Objects.hash(sessionedClientReconnectIntervalSeconds, retryableClientQuarantineRefreshPercentage,
|
||||
bootstrapResolverRefreshIntervalSeconds, applicationsResolverDataStalenessThresholdSeconds,
|
||||
asyncResolverRefreshIntervalMs, asyncResolverWarmUpTimeoutMs, asyncExecutorThreadPoolSize,
|
||||
readClusterVip, writeClusterVip, bootstrapResolverForQuery, bootstrapResolverStrategy,
|
||||
applicationsResolverUseIp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("CloudEurekaTransportConfig{")
|
||||
.append("sessionedClientReconnectIntervalSeconds=")
|
||||
return new StringBuilder("CloudEurekaTransportConfig{").append("sessionedClientReconnectIntervalSeconds=")
|
||||
.append(sessionedClientReconnectIntervalSeconds).append(", ")
|
||||
.append("retryableClientQuarantineRefreshPercentage=")
|
||||
.append(retryableClientQuarantineRefreshPercentage).append(", ")
|
||||
.append("bootstrapResolverRefreshIntervalSeconds=")
|
||||
.append(bootstrapResolverRefreshIntervalSeconds).append(", ")
|
||||
.append("applicationsResolverDataStalenessThresholdSeconds=")
|
||||
.append("bootstrapResolverRefreshIntervalSeconds=").append(bootstrapResolverRefreshIntervalSeconds)
|
||||
.append(", ").append("applicationsResolverDataStalenessThresholdSeconds=")
|
||||
.append(applicationsResolverDataStalenessThresholdSeconds).append(", ")
|
||||
.append("asyncResolverRefreshIntervalMs=")
|
||||
.append(asyncResolverRefreshIntervalMs).append(", ")
|
||||
.append("asyncResolverWarmUpTimeoutMs=")
|
||||
.append(asyncResolverWarmUpTimeoutMs).append(", ")
|
||||
.append("asyncExecutorThreadPoolSize=")
|
||||
.append(asyncExecutorThreadPoolSize).append(", ")
|
||||
.append("readClusterVip='").append(readClusterVip).append("', ")
|
||||
.append("writeClusterVip='").append(writeClusterVip).append("', ")
|
||||
.append("bootstrapResolverForQuery=").append(bootstrapResolverForQuery)
|
||||
.append(", ").append("bootstrapResolverStrategy='")
|
||||
.append(bootstrapResolverStrategy).append("', ")
|
||||
.append("applicationsResolverUseIp=").append(applicationsResolverUseIp)
|
||||
.append(", ").append("}").toString();
|
||||
.append("asyncResolverRefreshIntervalMs=").append(asyncResolverRefreshIntervalMs).append(", ")
|
||||
.append("asyncResolverWarmUpTimeoutMs=").append(asyncResolverWarmUpTimeoutMs).append(", ")
|
||||
.append("asyncExecutorThreadPoolSize=").append(asyncExecutorThreadPoolSize).append(", ")
|
||||
.append("readClusterVip='").append(readClusterVip).append("', ").append("writeClusterVip='")
|
||||
.append(writeClusterVip).append("', ").append("bootstrapResolverForQuery=")
|
||||
.append(bootstrapResolverForQuery).append(", ").append("bootstrapResolverStrategy='")
|
||||
.append(bootstrapResolverStrategy).append("', ").append("applicationsResolverUseIp=")
|
||||
.append(applicationsResolverUseIp).append(", ").append("}").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,10 +87,9 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
|
||||
@ConditionalOnClass(EurekaClientConfig.class)
|
||||
@ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class,
|
||||
CommonsClientAutoConfiguration.class, ServiceRegistryAutoConfiguration.class })
|
||||
@AutoConfigureAfter(name = {
|
||||
"org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration",
|
||||
@AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class,
|
||||
ServiceRegistryAutoConfiguration.class })
|
||||
@AutoConfigureAfter(name = { "org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration",
|
||||
"org.springframework.cloud.autoconfigure.RefreshAutoConfiguration",
|
||||
"org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration",
|
||||
"org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration" })
|
||||
@@ -108,8 +107,7 @@ public class EurekaClientAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = EurekaClientConfig.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnMissingBean(value = EurekaClientConfig.class, search = SearchStrategy.CURRENT)
|
||||
public EurekaClientConfigBean eurekaClientConfigBean(ConfigurableEnvironment env) {
|
||||
return new EurekaClientConfigBean();
|
||||
}
|
||||
@@ -125,26 +123,20 @@ public class EurekaClientAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = EurekaInstanceConfig.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnMissingBean(value = EurekaInstanceConfig.class, search = SearchStrategy.CURRENT)
|
||||
public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils,
|
||||
ManagementMetadataProvider managementMetadataProvider) {
|
||||
String hostname = getProperty("eureka.instance.hostname");
|
||||
boolean preferIpAddress = Boolean
|
||||
.parseBoolean(getProperty("eureka.instance.prefer-ip-address"));
|
||||
boolean preferIpAddress = Boolean.parseBoolean(getProperty("eureka.instance.prefer-ip-address"));
|
||||
String ipAddress = getProperty("eureka.instance.ip-address");
|
||||
boolean isSecurePortEnabled = Boolean
|
||||
.parseBoolean(getProperty("eureka.instance.secure-port-enabled"));
|
||||
boolean isSecurePortEnabled = Boolean.parseBoolean(getProperty("eureka.instance.secure-port-enabled"));
|
||||
|
||||
String serverContextPath = env.getProperty("server.servlet.context-path", "/");
|
||||
int serverPort = Integer.parseInt(
|
||||
env.getProperty("server.port", env.getProperty("port", "8080")));
|
||||
int serverPort = Integer.parseInt(env.getProperty("server.port", env.getProperty("port", "8080")));
|
||||
|
||||
Integer managementPort = env.getProperty("management.server.port", Integer.class);
|
||||
String managementContextPath = env
|
||||
.getProperty("management.server.servlet.context-path");
|
||||
Integer jmxPort = env.getProperty("com.sun.management.jmxremote.port",
|
||||
Integer.class);
|
||||
String managementContextPath = env.getProperty("management.server.servlet.context-path");
|
||||
Integer jmxPort = env.getProperty("com.sun.management.jmxremote.port", Integer.class);
|
||||
EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils);
|
||||
|
||||
instance.setNonSecurePort(serverPort);
|
||||
@@ -172,8 +164,8 @@ public class EurekaClientAutoConfiguration {
|
||||
instance.setHealthCheckUrlPath(healthCheckUrlPath);
|
||||
}
|
||||
|
||||
ManagementMetadata metadata = managementMetadataProvider.get(instance, serverPort,
|
||||
serverContextPath, managementContextPath, managementPort);
|
||||
ManagementMetadata metadata = managementMetadataProvider.get(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
|
||||
if (metadata != null) {
|
||||
instance.setStatusPageUrl(metadata.getStatusPageUrl());
|
||||
@@ -182,18 +174,15 @@ public class EurekaClientAutoConfiguration {
|
||||
instance.setSecureHealthCheckUrl(metadata.getSecureHealthCheckUrl());
|
||||
}
|
||||
Map<String, String> metadataMap = instance.getMetadataMap();
|
||||
metadataMap.computeIfAbsent("management.port",
|
||||
k -> String.valueOf(metadata.getManagementPort()));
|
||||
metadataMap.computeIfAbsent("management.port", k -> String.valueOf(metadata.getManagementPort()));
|
||||
}
|
||||
else {
|
||||
// without the metadata the status and health check URLs will not be set
|
||||
// and the status page and health check url paths will not include the
|
||||
// context path so set them here
|
||||
if (StringUtils.hasText(managementContextPath)) {
|
||||
instance.setHealthCheckUrlPath(
|
||||
managementContextPath + instance.getHealthCheckUrlPath());
|
||||
instance.setStatusPageUrlPath(
|
||||
managementContextPath + instance.getStatusPageUrlPath());
|
||||
instance.setHealthCheckUrlPath(managementContextPath + instance.getHealthCheckUrlPath());
|
||||
instance.setStatusPageUrlPath(managementContextPath + instance.getStatusPageUrlPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,12 +218,9 @@ public class EurekaClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
|
||||
@ConditionalOnProperty(
|
||||
value = "spring.cloud.service-registry.auto-registration.enabled",
|
||||
matchIfMissing = true)
|
||||
public EurekaAutoServiceRegistration eurekaAutoServiceRegistration(
|
||||
ApplicationContext context, EurekaServiceRegistry registry,
|
||||
EurekaRegistration registration) {
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
|
||||
public EurekaAutoServiceRegistration eurekaAutoServiceRegistration(ApplicationContext context,
|
||||
EurekaServiceRegistry registry, EurekaRegistration registration) {
|
||||
return new EurekaAutoServiceRegistration(context, registry, registration);
|
||||
}
|
||||
|
||||
@@ -249,34 +235,26 @@ public class EurekaClientAutoConfiguration {
|
||||
private AbstractDiscoveryClientOptionalArgs<?> optionalArgs;
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager,
|
||||
EurekaClientConfig config) {
|
||||
return new CloudEurekaClient(manager, config, this.optionalArgs,
|
||||
this.context);
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config) {
|
||||
return new CloudEurekaClient(manager, config, this.optionalArgs, this.context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = ApplicationInfoManager.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
public ApplicationInfoManager eurekaApplicationInfoManager(
|
||||
EurekaInstanceConfig config) {
|
||||
@ConditionalOnMissingBean(value = ApplicationInfoManager.class, search = SearchStrategy.CURRENT)
|
||||
public ApplicationInfoManager eurekaApplicationInfoManager(EurekaInstanceConfig config) {
|
||||
InstanceInfo instanceInfo = new InstanceInfoFactory().create(config);
|
||||
return new ApplicationInfoManager(config, instanceInfo);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
|
||||
@ConditionalOnProperty(
|
||||
value = "spring.cloud.service-registry.auto-registration.enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
|
||||
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
|
||||
CloudEurekaInstanceConfig instanceConfig,
|
||||
ApplicationInfoManager applicationInfoManager, @Autowired(
|
||||
required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager)
|
||||
.with(eurekaClient).with(healthCheckHandler).build();
|
||||
CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager,
|
||||
@Autowired(required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager).with(eurekaClient)
|
||||
.with(healthCheckHandler).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -292,13 +270,11 @@ public class EurekaClientAutoConfiguration {
|
||||
private AbstractDiscoveryClientOptionalArgs<?> optionalArgs;
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
|
||||
@org.springframework.cloud.context.config.annotation.RefreshScope
|
||||
@Lazy
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager,
|
||||
EurekaClientConfig config, EurekaInstanceConfig instance,
|
||||
@Autowired(required = false) HealthCheckHandler healthCheckHandler) {
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
|
||||
EurekaInstanceConfig instance, @Autowired(required = false) HealthCheckHandler healthCheckHandler) {
|
||||
// If we use the proxy of the ApplicationInfoManager we could run into a
|
||||
// problem
|
||||
// when shutdown is called on the CloudEurekaClient where the
|
||||
@@ -313,19 +289,17 @@ public class EurekaClientAutoConfiguration {
|
||||
else {
|
||||
appManager = manager;
|
||||
}
|
||||
CloudEurekaClient cloudEurekaClient = new CloudEurekaClient(appManager,
|
||||
config, this.optionalArgs, this.context);
|
||||
CloudEurekaClient cloudEurekaClient = new CloudEurekaClient(appManager, config, this.optionalArgs,
|
||||
this.context);
|
||||
cloudEurekaClient.registerHealthCheck(healthCheckHandler);
|
||||
return cloudEurekaClient;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = ApplicationInfoManager.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnMissingBean(value = ApplicationInfoManager.class, search = SearchStrategy.CURRENT)
|
||||
@org.springframework.cloud.context.config.annotation.RefreshScope
|
||||
@Lazy
|
||||
public ApplicationInfoManager eurekaApplicationInfoManager(
|
||||
EurekaInstanceConfig config) {
|
||||
public ApplicationInfoManager eurekaApplicationInfoManager(EurekaInstanceConfig config) {
|
||||
InstanceInfo instanceInfo = new InstanceInfoFactory().create(config);
|
||||
return new ApplicationInfoManager(config, instanceInfo);
|
||||
}
|
||||
@@ -333,15 +307,12 @@ public class EurekaClientAutoConfiguration {
|
||||
@Bean
|
||||
@org.springframework.cloud.context.config.annotation.RefreshScope
|
||||
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
|
||||
@ConditionalOnProperty(
|
||||
value = "spring.cloud.service-registry.auto-registration.enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
|
||||
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
|
||||
CloudEurekaInstanceConfig instanceConfig,
|
||||
ApplicationInfoManager applicationInfoManager, @Autowired(
|
||||
required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager)
|
||||
.with(eurekaClient).with(healthCheckHandler).build();
|
||||
CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager,
|
||||
@Autowired(required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager).with(eurekaClient)
|
||||
.with(healthCheckHandler).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -359,8 +330,7 @@ public class EurekaClientAutoConfiguration {
|
||||
@Documented
|
||||
@ConditionalOnClass(RefreshScope.class)
|
||||
@ConditionalOnBean(RefreshAutoConfiguration.class)
|
||||
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "true", matchIfMissing = true)
|
||||
@interface ConditionalOnRefreshScope {
|
||||
|
||||
}
|
||||
@@ -381,8 +351,7 @@ public class EurekaClientAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(value = "eureka.client.refresh.enable",
|
||||
havingValue = "false")
|
||||
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "false")
|
||||
static class OnPropertyDisabled {
|
||||
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
/**
|
||||
* Default Eureka URL.
|
||||
*/
|
||||
public static final String DEFAULT_URL = "http://localhost:8761" + DEFAULT_PREFIX
|
||||
+ "/";
|
||||
public static final String DEFAULT_URL = "http://localhost:8761" + DEFAULT_PREFIX + "/";
|
||||
|
||||
/**
|
||||
* Default availability zone if none is resolved based on region.
|
||||
@@ -474,8 +473,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
serviceUrls = this.serviceUrl.get(DEFAULT_ZONE);
|
||||
}
|
||||
if (!StringUtils.isEmpty(serviceUrls)) {
|
||||
final String[] serviceUrlsSplit = StringUtils
|
||||
.commaDelimitedListToStringArray(serviceUrls);
|
||||
final String[] serviceUrlsSplit = StringUtils.commaDelimitedListToStringArray(serviceUrls);
|
||||
List<String> eurekaServiceUrls = new ArrayList<>(serviceUrlsSplit.length);
|
||||
for (String eurekaServiceUrl : serviceUrlsSplit) {
|
||||
if (!endsWithSlash(eurekaServiceUrl)) {
|
||||
@@ -516,8 +514,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
@Override
|
||||
public String getExperimental(String name) {
|
||||
if (this.propertyResolver != null) {
|
||||
return this.propertyResolver.getProperty(PREFIX + ".experimental." + name,
|
||||
String.class, null);
|
||||
return this.propertyResolver.getProperty(PREFIX + ".experimental." + name, String.class, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -565,8 +562,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return instanceInfoReplicationIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setInstanceInfoReplicationIntervalSeconds(
|
||||
int instanceInfoReplicationIntervalSeconds) {
|
||||
public void setInstanceInfoReplicationIntervalSeconds(int instanceInfoReplicationIntervalSeconds) {
|
||||
this.instanceInfoReplicationIntervalSeconds = instanceInfoReplicationIntervalSeconds;
|
||||
}
|
||||
|
||||
@@ -575,8 +571,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return initialInstanceInfoReplicationIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setInitialInstanceInfoReplicationIntervalSeconds(
|
||||
int initialInstanceInfoReplicationIntervalSeconds) {
|
||||
public void setInitialInstanceInfoReplicationIntervalSeconds(int initialInstanceInfoReplicationIntervalSeconds) {
|
||||
this.initialInstanceInfoReplicationIntervalSeconds = initialInstanceInfoReplicationIntervalSeconds;
|
||||
}
|
||||
|
||||
@@ -585,8 +580,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return eurekaServiceUrlPollIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setEurekaServiceUrlPollIntervalSeconds(
|
||||
int eurekaServiceUrlPollIntervalSeconds) {
|
||||
public void setEurekaServiceUrlPollIntervalSeconds(int eurekaServiceUrlPollIntervalSeconds) {
|
||||
this.eurekaServiceUrlPollIntervalSeconds = eurekaServiceUrlPollIntervalSeconds;
|
||||
}
|
||||
|
||||
@@ -640,8 +634,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return eurekaServerConnectTimeoutSeconds;
|
||||
}
|
||||
|
||||
public void setEurekaServerConnectTimeoutSeconds(
|
||||
int eurekaServerConnectTimeoutSeconds) {
|
||||
public void setEurekaServerConnectTimeoutSeconds(int eurekaServerConnectTimeoutSeconds) {
|
||||
this.eurekaServerConnectTimeoutSeconds = eurekaServerConnectTimeoutSeconds;
|
||||
}
|
||||
|
||||
@@ -668,8 +661,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return eurekaServerTotalConnectionsPerHost;
|
||||
}
|
||||
|
||||
public void setEurekaServerTotalConnectionsPerHost(
|
||||
int eurekaServerTotalConnectionsPerHost) {
|
||||
public void setEurekaServerTotalConnectionsPerHost(int eurekaServerTotalConnectionsPerHost) {
|
||||
this.eurekaServerTotalConnectionsPerHost = eurekaServerTotalConnectionsPerHost;
|
||||
}
|
||||
|
||||
@@ -714,8 +706,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return eurekaConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
public void setEurekaConnectionIdleTimeoutSeconds(
|
||||
int eurekaConnectionIdleTimeoutSeconds) {
|
||||
public void setEurekaConnectionIdleTimeoutSeconds(int eurekaConnectionIdleTimeoutSeconds) {
|
||||
this.eurekaConnectionIdleTimeoutSeconds = eurekaConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
@@ -724,8 +715,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return registryRefreshSingleVipAddress;
|
||||
}
|
||||
|
||||
public void setRegistryRefreshSingleVipAddress(
|
||||
String registryRefreshSingleVipAddress) {
|
||||
public void setRegistryRefreshSingleVipAddress(String registryRefreshSingleVipAddress) {
|
||||
this.registryRefreshSingleVipAddress = registryRefreshSingleVipAddress;
|
||||
}
|
||||
|
||||
@@ -743,8 +733,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return heartbeatExecutorExponentialBackOffBound;
|
||||
}
|
||||
|
||||
public void setHeartbeatExecutorExponentialBackOffBound(
|
||||
int heartbeatExecutorExponentialBackOffBound) {
|
||||
public void setHeartbeatExecutorExponentialBackOffBound(int heartbeatExecutorExponentialBackOffBound) {
|
||||
this.heartbeatExecutorExponentialBackOffBound = heartbeatExecutorExponentialBackOffBound;
|
||||
}
|
||||
|
||||
@@ -753,8 +742,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return cacheRefreshExecutorThreadPoolSize;
|
||||
}
|
||||
|
||||
public void setCacheRefreshExecutorThreadPoolSize(
|
||||
int cacheRefreshExecutorThreadPoolSize) {
|
||||
public void setCacheRefreshExecutorThreadPoolSize(int cacheRefreshExecutorThreadPoolSize) {
|
||||
this.cacheRefreshExecutorThreadPoolSize = cacheRefreshExecutorThreadPoolSize;
|
||||
}
|
||||
|
||||
@@ -763,8 +751,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return cacheRefreshExecutorExponentialBackOffBound;
|
||||
}
|
||||
|
||||
public void setCacheRefreshExecutorExponentialBackOffBound(
|
||||
int cacheRefreshExecutorExponentialBackOffBound) {
|
||||
public void setCacheRefreshExecutorExponentialBackOffBound(int cacheRefreshExecutorExponentialBackOffBound) {
|
||||
this.cacheRefreshExecutorExponentialBackOffBound = cacheRefreshExecutorExponentialBackOffBound;
|
||||
}
|
||||
|
||||
@@ -929,8 +916,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return shouldEnforceRegistrationAtInit;
|
||||
}
|
||||
|
||||
public void setShouldEnforceRegistrationAtInit(
|
||||
boolean shouldEnforceRegistrationAtInit) {
|
||||
public void setShouldEnforceRegistrationAtInit(boolean shouldEnforceRegistrationAtInit) {
|
||||
this.shouldEnforceRegistrationAtInit = shouldEnforceRegistrationAtInit;
|
||||
}
|
||||
|
||||
@@ -952,8 +938,8 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
return false;
|
||||
}
|
||||
EurekaClientConfigBean that = (EurekaClientConfigBean) o;
|
||||
return Objects.equals(propertyResolver, that.propertyResolver)
|
||||
&& enabled == that.enabled && Objects.equals(transport, that.transport)
|
||||
return Objects.equals(propertyResolver, that.propertyResolver) && enabled == that.enabled
|
||||
&& Objects.equals(transport, that.transport)
|
||||
&& registryFetchIntervalSeconds == that.registryFetchIntervalSeconds
|
||||
&& instanceInfoReplicationIntervalSeconds == that.instanceInfoReplicationIntervalSeconds
|
||||
&& initialInstanceInfoReplicationIntervalSeconds == that.initialInstanceInfoReplicationIntervalSeconds
|
||||
@@ -967,128 +953,91 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
|
||||
&& heartbeatExecutorExponentialBackOffBound == that.heartbeatExecutorExponentialBackOffBound
|
||||
&& cacheRefreshExecutorThreadPoolSize == that.cacheRefreshExecutorThreadPoolSize
|
||||
&& cacheRefreshExecutorExponentialBackOffBound == that.cacheRefreshExecutorExponentialBackOffBound
|
||||
&& gZipContent == that.gZipContent
|
||||
&& useDnsForFetchingServiceUrls == that.useDnsForFetchingServiceUrls
|
||||
&& registerWithEureka == that.registerWithEureka
|
||||
&& preferSameZoneEureka == that.preferSameZoneEureka
|
||||
&& gZipContent == that.gZipContent && useDnsForFetchingServiceUrls == that.useDnsForFetchingServiceUrls
|
||||
&& registerWithEureka == that.registerWithEureka && preferSameZoneEureka == that.preferSameZoneEureka
|
||||
&& logDeltaDiff == that.logDeltaDiff && disableDelta == that.disableDelta
|
||||
&& filterOnlyUpInstances == that.filterOnlyUpInstances
|
||||
&& fetchRegistry == that.fetchRegistry
|
||||
&& filterOnlyUpInstances == that.filterOnlyUpInstances && fetchRegistry == that.fetchRegistry
|
||||
&& allowRedirects == that.allowRedirects
|
||||
&& onDemandUpdateStatusChange == that.onDemandUpdateStatusChange
|
||||
&& shouldUnregisterOnShutdown == that.shouldUnregisterOnShutdown
|
||||
&& shouldEnforceRegistrationAtInit == that.shouldEnforceRegistrationAtInit
|
||||
&& Objects.equals(proxyPort, that.proxyPort)
|
||||
&& Objects.equals(proxyHost, that.proxyHost)
|
||||
&& Objects.equals(proxyPort, that.proxyPort) && Objects.equals(proxyHost, that.proxyHost)
|
||||
&& Objects.equals(proxyUserName, that.proxyUserName)
|
||||
&& Objects.equals(proxyPassword, that.proxyPassword)
|
||||
&& Objects.equals(backupRegistryImpl, that.backupRegistryImpl)
|
||||
&& Objects.equals(eurekaServerURLContext, that.eurekaServerURLContext)
|
||||
&& Objects.equals(eurekaServerPort, that.eurekaServerPort)
|
||||
&& Objects.equals(eurekaServerDNSName, that.eurekaServerDNSName)
|
||||
&& Objects.equals(region, that.region)
|
||||
&& Objects.equals(registryRefreshSingleVipAddress,
|
||||
that.registryRefreshSingleVipAddress)
|
||||
&& Objects.equals(eurekaServerDNSName, that.eurekaServerDNSName) && Objects.equals(region, that.region)
|
||||
&& Objects.equals(registryRefreshSingleVipAddress, that.registryRefreshSingleVipAddress)
|
||||
&& Objects.equals(serviceUrl, that.serviceUrl)
|
||||
&& Objects.equals(fetchRemoteRegionsRegistry,
|
||||
that.fetchRemoteRegionsRegistry)
|
||||
&& Objects.equals(fetchRemoteRegionsRegistry, that.fetchRemoteRegionsRegistry)
|
||||
&& Objects.equals(availabilityZones, that.availabilityZones)
|
||||
&& Objects.equals(dollarReplacement, that.dollarReplacement)
|
||||
&& Objects.equals(escapeCharReplacement, that.escapeCharReplacement)
|
||||
&& Objects.equals(encoderName, that.encoderName)
|
||||
&& Objects.equals(decoderName, that.decoderName)
|
||||
&& Objects.equals(clientDataAccept, that.clientDataAccept)
|
||||
&& Objects.equals(order, that.order);
|
||||
&& Objects.equals(encoderName, that.encoderName) && Objects.equals(decoderName, that.decoderName)
|
||||
&& Objects.equals(clientDataAccept, that.clientDataAccept) && Objects.equals(order, that.order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(propertyResolver, enabled, transport,
|
||||
registryFetchIntervalSeconds, instanceInfoReplicationIntervalSeconds,
|
||||
initialInstanceInfoReplicationIntervalSeconds,
|
||||
eurekaServiceUrlPollIntervalSeconds, proxyPort, proxyHost, proxyUserName,
|
||||
proxyPassword, eurekaServerReadTimeoutSeconds,
|
||||
eurekaServerConnectTimeoutSeconds, backupRegistryImpl,
|
||||
eurekaServerTotalConnections, eurekaServerTotalConnectionsPerHost,
|
||||
eurekaServerURLContext, eurekaServerPort, eurekaServerDNSName, region,
|
||||
eurekaConnectionIdleTimeoutSeconds, registryRefreshSingleVipAddress,
|
||||
heartbeatExecutorThreadPoolSize, heartbeatExecutorExponentialBackOffBound,
|
||||
cacheRefreshExecutorThreadPoolSize,
|
||||
cacheRefreshExecutorExponentialBackOffBound, serviceUrl, gZipContent,
|
||||
useDnsForFetchingServiceUrls, registerWithEureka, preferSameZoneEureka,
|
||||
logDeltaDiff, disableDelta, fetchRemoteRegionsRegistry, availabilityZones,
|
||||
filterOnlyUpInstances, fetchRegistry, dollarReplacement,
|
||||
escapeCharReplacement, allowRedirects, onDemandUpdateStatusChange,
|
||||
encoderName, decoderName, clientDataAccept, shouldUnregisterOnShutdown,
|
||||
shouldEnforceRegistrationAtInit, order);
|
||||
return Objects.hash(propertyResolver, enabled, transport, registryFetchIntervalSeconds,
|
||||
instanceInfoReplicationIntervalSeconds, initialInstanceInfoReplicationIntervalSeconds,
|
||||
eurekaServiceUrlPollIntervalSeconds, proxyPort, proxyHost, proxyUserName, proxyPassword,
|
||||
eurekaServerReadTimeoutSeconds, eurekaServerConnectTimeoutSeconds, backupRegistryImpl,
|
||||
eurekaServerTotalConnections, eurekaServerTotalConnectionsPerHost, eurekaServerURLContext,
|
||||
eurekaServerPort, eurekaServerDNSName, region, eurekaConnectionIdleTimeoutSeconds,
|
||||
registryRefreshSingleVipAddress, heartbeatExecutorThreadPoolSize,
|
||||
heartbeatExecutorExponentialBackOffBound, cacheRefreshExecutorThreadPoolSize,
|
||||
cacheRefreshExecutorExponentialBackOffBound, serviceUrl, gZipContent, useDnsForFetchingServiceUrls,
|
||||
registerWithEureka, preferSameZoneEureka, logDeltaDiff, disableDelta, fetchRemoteRegionsRegistry,
|
||||
availabilityZones, filterOnlyUpInstances, fetchRegistry, dollarReplacement, escapeCharReplacement,
|
||||
allowRedirects, onDemandUpdateStatusChange, encoderName, decoderName, clientDataAccept,
|
||||
shouldUnregisterOnShutdown, shouldEnforceRegistrationAtInit, order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EurekaClientConfigBean{").append("propertyResolver=")
|
||||
.append(propertyResolver).append(", ").append("enabled=").append(enabled)
|
||||
.append(", ").append("transport=").append(transport).append(", ")
|
||||
.append("registryFetchIntervalSeconds=")
|
||||
.append(registryFetchIntervalSeconds).append(", ")
|
||||
.append("instanceInfoReplicationIntervalSeconds=")
|
||||
.append(instanceInfoReplicationIntervalSeconds).append(", ")
|
||||
.append("initialInstanceInfoReplicationIntervalSeconds=")
|
||||
return new StringBuilder("EurekaClientConfigBean{").append("propertyResolver=").append(propertyResolver)
|
||||
.append(", ").append("enabled=").append(enabled).append(", ").append("transport=").append(transport)
|
||||
.append(", ").append("registryFetchIntervalSeconds=").append(registryFetchIntervalSeconds).append(", ")
|
||||
.append("instanceInfoReplicationIntervalSeconds=").append(instanceInfoReplicationIntervalSeconds)
|
||||
.append(", ").append("initialInstanceInfoReplicationIntervalSeconds=")
|
||||
.append(initialInstanceInfoReplicationIntervalSeconds).append(", ")
|
||||
.append("eurekaServiceUrlPollIntervalSeconds=")
|
||||
.append(eurekaServiceUrlPollIntervalSeconds).append(", ")
|
||||
.append("proxyPort='").append(proxyPort).append("', ")
|
||||
.append("proxyHost='").append(proxyHost).append("', ")
|
||||
.append("proxyUserName='").append(proxyUserName).append("', ")
|
||||
.append("proxyPassword='").append(proxyPassword).append("', ")
|
||||
.append("eurekaServerReadTimeoutSeconds=")
|
||||
.append(eurekaServerReadTimeoutSeconds).append(", ")
|
||||
.append("eurekaServerConnectTimeoutSeconds=")
|
||||
.append(eurekaServerConnectTimeoutSeconds).append(", ")
|
||||
.append("backupRegistryImpl='").append(backupRegistryImpl).append("', ")
|
||||
.append("eurekaServerTotalConnections=")
|
||||
.append(eurekaServerTotalConnections).append(", ")
|
||||
.append("eurekaServerTotalConnectionsPerHost=")
|
||||
.append(eurekaServerTotalConnectionsPerHost).append(", ")
|
||||
.append("eurekaServerURLContext='").append(eurekaServerURLContext)
|
||||
.append("', ").append("eurekaServerPort='").append(eurekaServerPort)
|
||||
.append("', ").append("eurekaServerDNSName='").append(eurekaServerDNSName)
|
||||
.append("', ").append("region='").append(region).append("', ")
|
||||
.append("eurekaConnectionIdleTimeoutSeconds=")
|
||||
.append(eurekaConnectionIdleTimeoutSeconds).append(", ")
|
||||
.append("registryRefreshSingleVipAddress='")
|
||||
.append(registryRefreshSingleVipAddress).append("', ")
|
||||
.append("heartbeatExecutorThreadPoolSize=")
|
||||
.append("eurekaServiceUrlPollIntervalSeconds=").append(eurekaServiceUrlPollIntervalSeconds).append(", ")
|
||||
.append("proxyPort='").append(proxyPort).append("', ").append("proxyHost='").append(proxyHost)
|
||||
.append("', ").append("proxyUserName='").append(proxyUserName).append("', ").append("proxyPassword='")
|
||||
.append(proxyPassword).append("', ").append("eurekaServerReadTimeoutSeconds=")
|
||||
.append(eurekaServerReadTimeoutSeconds).append(", ").append("eurekaServerConnectTimeoutSeconds=")
|
||||
.append(eurekaServerConnectTimeoutSeconds).append(", ").append("backupRegistryImpl='")
|
||||
.append(backupRegistryImpl).append("', ").append("eurekaServerTotalConnections=")
|
||||
.append(eurekaServerTotalConnections).append(", ").append("eurekaServerTotalConnectionsPerHost=")
|
||||
.append(eurekaServerTotalConnectionsPerHost).append(", ").append("eurekaServerURLContext='")
|
||||
.append(eurekaServerURLContext).append("', ").append("eurekaServerPort='").append(eurekaServerPort)
|
||||
.append("', ").append("eurekaServerDNSName='").append(eurekaServerDNSName).append("', ")
|
||||
.append("region='").append(region).append("', ").append("eurekaConnectionIdleTimeoutSeconds=")
|
||||
.append(eurekaConnectionIdleTimeoutSeconds).append(", ").append("registryRefreshSingleVipAddress='")
|
||||
.append(registryRefreshSingleVipAddress).append("', ").append("heartbeatExecutorThreadPoolSize=")
|
||||
.append(heartbeatExecutorThreadPoolSize).append(", ")
|
||||
.append("heartbeatExecutorExponentialBackOffBound=")
|
||||
.append(heartbeatExecutorExponentialBackOffBound).append(", ")
|
||||
.append("cacheRefreshExecutorThreadPoolSize=")
|
||||
.append(cacheRefreshExecutorThreadPoolSize).append(", ")
|
||||
.append("cacheRefreshExecutorExponentialBackOffBound=")
|
||||
.append(cacheRefreshExecutorExponentialBackOffBound).append(", ")
|
||||
.append("serviceUrl=").append(serviceUrl).append(", ")
|
||||
.append("gZipContent=").append(gZipContent).append(", ")
|
||||
.append("useDnsForFetchingServiceUrls=")
|
||||
.append(useDnsForFetchingServiceUrls).append(", ")
|
||||
.append("registerWithEureka=").append(registerWithEureka).append(", ")
|
||||
.append("preferSameZoneEureka=").append(preferSameZoneEureka).append(", ")
|
||||
.append("logDeltaDiff=").append(logDeltaDiff).append(", ")
|
||||
.append("disableDelta=").append(disableDelta).append(", ")
|
||||
.append("fetchRemoteRegionsRegistry='").append(fetchRemoteRegionsRegistry)
|
||||
.append("', ").append("availabilityZones=").append(availabilityZones)
|
||||
.append(", ").append("filterOnlyUpInstances=")
|
||||
.append(filterOnlyUpInstances).append(", ").append("fetchRegistry=")
|
||||
.append(fetchRegistry).append(", ").append("dollarReplacement='")
|
||||
.append(dollarReplacement).append("', ").append("escapeCharReplacement='")
|
||||
.append(escapeCharReplacement).append("', ").append("allowRedirects=")
|
||||
.append(allowRedirects).append(", ").append("onDemandUpdateStatusChange=")
|
||||
.append(onDemandUpdateStatusChange).append(", ").append("encoderName='")
|
||||
.append(encoderName).append("', ").append("decoderName='")
|
||||
.append(decoderName).append("', ").append("clientDataAccept='")
|
||||
.append(clientDataAccept).append("', ")
|
||||
.append("heartbeatExecutorExponentialBackOffBound=").append(heartbeatExecutorExponentialBackOffBound)
|
||||
.append(", ").append("cacheRefreshExecutorThreadPoolSize=").append(cacheRefreshExecutorThreadPoolSize)
|
||||
.append(", ").append("cacheRefreshExecutorExponentialBackOffBound=")
|
||||
.append(cacheRefreshExecutorExponentialBackOffBound).append(", ").append("serviceUrl=")
|
||||
.append(serviceUrl).append(", ").append("gZipContent=").append(gZipContent).append(", ")
|
||||
.append("useDnsForFetchingServiceUrls=").append(useDnsForFetchingServiceUrls).append(", ")
|
||||
.append("registerWithEureka=").append(registerWithEureka).append(", ").append("preferSameZoneEureka=")
|
||||
.append(preferSameZoneEureka).append(", ").append("logDeltaDiff=").append(logDeltaDiff).append(", ")
|
||||
.append("disableDelta=").append(disableDelta).append(", ").append("fetchRemoteRegionsRegistry='")
|
||||
.append(fetchRemoteRegionsRegistry).append("', ").append("availabilityZones=").append(availabilityZones)
|
||||
.append(", ").append("filterOnlyUpInstances=").append(filterOnlyUpInstances).append(", ")
|
||||
.append("fetchRegistry=").append(fetchRegistry).append(", ").append("dollarReplacement='")
|
||||
.append(dollarReplacement).append("', ").append("escapeCharReplacement='").append(escapeCharReplacement)
|
||||
.append("', ").append("allowRedirects=").append(allowRedirects).append(", ")
|
||||
.append("onDemandUpdateStatusChange=").append(onDemandUpdateStatusChange).append(", ")
|
||||
.append("encoderName='").append(encoderName).append("', ").append("decoderName='").append(decoderName)
|
||||
.append("', ").append("clientDataAccept='").append(clientDataAccept).append("', ")
|
||||
.append("shouldUnregisterOnShutdown='").append(shouldUnregisterOnShutdown)
|
||||
.append("shouldEnforceRegistrationAtInit='")
|
||||
.append(shouldEnforceRegistrationAtInit).append("', ").append("order='")
|
||||
.append(order).append("'}").toString();
|
||||
.append("shouldEnforceRegistrationAtInit='").append(shouldEnforceRegistrationAtInit).append("', ")
|
||||
.append("order='").append(order).append("'}").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
|
||||
this(eurekaClient, eurekaClient.getEurekaClientConfig());
|
||||
}
|
||||
|
||||
public EurekaDiscoveryClient(EurekaClient eurekaClient,
|
||||
EurekaClientConfig clientConfig) {
|
||||
public EurekaDiscoveryClient(EurekaClient eurekaClient, EurekaClientConfig clientConfig) {
|
||||
this.clientConfig = clientConfig;
|
||||
this.eurekaClient = eurekaClient;
|
||||
}
|
||||
@@ -66,8 +65,7 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(String serviceId) {
|
||||
List<InstanceInfo> infos = this.eurekaClient.getInstancesByVipAddress(serviceId,
|
||||
false);
|
||||
List<InstanceInfo> infos = this.eurekaClient.getInstancesByVipAddress(serviceId, false);
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
for (InstanceInfo info : infos) {
|
||||
instances.add(new EurekaServiceInstance(info));
|
||||
@@ -95,8 +93,7 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return clientConfig instanceof Ordered ? ((Ordered) clientConfig).getOrder()
|
||||
: DiscoveryClient.DEFAULT_ORDER;
|
||||
return clientConfig instanceof Ordered ? ((Ordered) clientConfig).getOrder() : DiscoveryClient.DEFAULT_ORDER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,14 +64,12 @@ public class EurekaDiscoveryClientConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EurekaDiscoveryClient discoveryClient(EurekaClient client,
|
||||
EurekaClientConfig clientConfig) {
|
||||
public EurekaDiscoveryClient discoveryClient(EurekaClient client, EurekaClientConfig clientConfig) {
|
||||
return new EurekaDiscoveryClient(client, clientConfig);
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "eureka.client.healthcheck.enabled",
|
||||
matchIfMissing = false)
|
||||
@ConditionalOnProperty(value = "eureka.client.healthcheck.enabled", matchIfMissing = false)
|
||||
protected static class EurekaHealthCheckHandlerConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -50,8 +50,7 @@ import static com.netflix.appinfo.InstanceInfo.InstanceStatus;
|
||||
* @see HealthCheckHandler
|
||||
* @see StatusAggregator
|
||||
*/
|
||||
public class EurekaHealthCheckHandler
|
||||
implements HealthCheckHandler, ApplicationContextAware, InitializingBean {
|
||||
public class EurekaHealthCheckHandler implements HealthCheckHandler, ApplicationContextAware, InitializingBean {
|
||||
|
||||
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<Status, InstanceInfo.InstanceStatus>() {
|
||||
{
|
||||
@@ -75,15 +74,13 @@ public class EurekaHealthCheckHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
final Map<String, HealthIndicator> healthIndicators = applicationContext
|
||||
.getBeansOfType(HealthIndicator.class);
|
||||
final Map<String, HealthIndicator> healthIndicators = applicationContext.getBeansOfType(HealthIndicator.class);
|
||||
|
||||
populateHealthIndicators(healthIndicators);
|
||||
}
|
||||
@@ -93,11 +90,9 @@ public class EurekaHealthCheckHandler
|
||||
// ignore EurekaHealthIndicator and flatten the rest of the composite
|
||||
// otherwise there is a never ending cycle of down. See gh-643
|
||||
if (entry.getValue() instanceof DiscoveryCompositeHealthContributor) {
|
||||
DiscoveryCompositeHealthContributor indicator = (DiscoveryCompositeHealthContributor) entry
|
||||
.getValue();
|
||||
DiscoveryCompositeHealthContributor indicator = (DiscoveryCompositeHealthContributor) entry.getValue();
|
||||
indicator.forEach(contributor -> {
|
||||
if (!(contributor
|
||||
.getContributor() instanceof EurekaHealthIndicator)) {
|
||||
if (!(contributor.getContributor() instanceof EurekaHealthIndicator)) {
|
||||
this.healthIndicators.put(contributor.getName(),
|
||||
(HealthIndicator) contributor.getContributor());
|
||||
}
|
||||
@@ -121,8 +116,7 @@ public class EurekaHealthCheckHandler
|
||||
|
||||
protected Status getStatus(StatusAggregator statusAggregator) {
|
||||
Status status;
|
||||
Set<Status> statusSet = healthIndicators.values().stream()
|
||||
.map(HealthIndicator::health).map(Health::getStatus)
|
||||
Set<Status> statusSet = healthIndicators.values().stream().map(HealthIndicator::health).map(Health::getStatus)
|
||||
.collect(Collectors.toSet());
|
||||
status = statusAggregator.getAggregateStatus(statusSet);
|
||||
return status;
|
||||
|
||||
@@ -45,8 +45,8 @@ public class EurekaHealthIndicator implements DiscoveryHealthIndicator {
|
||||
|
||||
private final EurekaClientConfig clientConfig;
|
||||
|
||||
public EurekaHealthIndicator(EurekaClient eurekaClient,
|
||||
EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
|
||||
public EurekaHealthIndicator(EurekaClient eurekaClient, EurekaInstanceConfig instanceConfig,
|
||||
EurekaClientConfig clientConfig) {
|
||||
super();
|
||||
this.eurekaClient = eurekaClient;
|
||||
this.instanceConfig = instanceConfig;
|
||||
@@ -62,8 +62,7 @@ public class EurekaHealthIndicator implements DiscoveryHealthIndicator {
|
||||
public Health health() {
|
||||
Builder builder = Health.unknown();
|
||||
Status status = getStatus(builder);
|
||||
return builder.status(status).withDetail("applications", getApplications())
|
||||
.build();
|
||||
return builder.status(status).withDetail("applications", getApplications()).build();
|
||||
}
|
||||
|
||||
private Status getStatus(Builder builder) {
|
||||
@@ -80,10 +79,8 @@ public class EurekaHealthIndicator implements DiscoveryHealthIndicator {
|
||||
else if (lastFetch > clientConfig.getRegistryFetchIntervalSeconds() * 2000) {
|
||||
status = new Status("UP",
|
||||
"Eureka discovery client is reporting failures to connect to a Eureka server");
|
||||
builder.withDetail("renewalPeriod",
|
||||
instanceConfig.getLeaseRenewalIntervalInSeconds());
|
||||
builder.withDetail("failCount",
|
||||
lastFetch / clientConfig.getRegistryFetchIntervalSeconds());
|
||||
builder.withDetail("renewalPeriod", instanceConfig.getLeaseRenewalIntervalInSeconds());
|
||||
builder.withDetail("failCount", lastFetch / clientConfig.getRegistryFetchIntervalSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Gregor Zurowski
|
||||
*/
|
||||
@ConfigurationProperties("eureka.instance")
|
||||
public class EurekaInstanceConfigBean
|
||||
implements CloudEurekaInstanceConfig, EnvironmentAware {
|
||||
public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, EnvironmentAware {
|
||||
|
||||
private static final String UNKNOWN = "unknown";
|
||||
|
||||
@@ -156,8 +155,7 @@ public class EurekaInstanceConfigBean
|
||||
* Returns the data center this instance is deployed. This information is used to get
|
||||
* some AWS specific instance information if the instance is deployed in AWS.
|
||||
*/
|
||||
private DataCenterInfo dataCenterInfo = new MyDataCenterInfo(
|
||||
DataCenterInfo.Name.MyOwn);
|
||||
private DataCenterInfo dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
|
||||
|
||||
/**
|
||||
* Get the IPAdress of the instance. This information is for academic purposes only as
|
||||
@@ -331,8 +329,7 @@ public class EurekaInstanceConfigBean
|
||||
this.environment = environment;
|
||||
// set some defaults from the environment, but allow the defaults to use relaxed
|
||||
// binding
|
||||
String springAppName = this.environment.getProperty("spring.application.name",
|
||||
"");
|
||||
String springAppName = this.environment.getProperty("spring.application.name", "");
|
||||
if (StringUtils.hasText(springAppName)) {
|
||||
setAppname(springAppName);
|
||||
setVirtualHostName(springAppName);
|
||||
@@ -424,8 +421,7 @@ public class EurekaInstanceConfigBean
|
||||
return leaseExpirationDurationInSeconds;
|
||||
}
|
||||
|
||||
public void setLeaseExpirationDurationInSeconds(
|
||||
int leaseExpirationDurationInSeconds) {
|
||||
public void setLeaseExpirationDurationInSeconds(int leaseExpirationDurationInSeconds) {
|
||||
this.leaseExpirationDurationInSeconds = leaseExpirationDurationInSeconds;
|
||||
}
|
||||
|
||||
@@ -578,23 +574,17 @@ public class EurekaInstanceConfigBean
|
||||
return false;
|
||||
}
|
||||
EurekaInstanceConfigBean that = (EurekaInstanceConfigBean) o;
|
||||
return Objects.equals(hostInfo, that.hostInfo)
|
||||
&& Objects.equals(inetUtils, that.inetUtils)
|
||||
&& Objects.equals(appname, that.appname)
|
||||
&& Objects.equals(appGroupName, that.appGroupName)
|
||||
&& instanceEnabledOnit == that.instanceEnabledOnit
|
||||
&& nonSecurePort == that.nonSecurePort && securePort == that.securePort
|
||||
&& nonSecurePortEnabled == that.nonSecurePortEnabled
|
||||
return Objects.equals(hostInfo, that.hostInfo) && Objects.equals(inetUtils, that.inetUtils)
|
||||
&& Objects.equals(appname, that.appname) && Objects.equals(appGroupName, that.appGroupName)
|
||||
&& instanceEnabledOnit == that.instanceEnabledOnit && nonSecurePort == that.nonSecurePort
|
||||
&& securePort == that.securePort && nonSecurePortEnabled == that.nonSecurePortEnabled
|
||||
&& securePortEnabled == that.securePortEnabled
|
||||
&& leaseRenewalIntervalInSeconds == that.leaseRenewalIntervalInSeconds
|
||||
&& leaseExpirationDurationInSeconds == that.leaseExpirationDurationInSeconds
|
||||
&& Objects.equals(virtualHostName, that.virtualHostName)
|
||||
&& Objects.equals(instanceId, that.instanceId)
|
||||
&& Objects.equals(virtualHostName, that.virtualHostName) && Objects.equals(instanceId, that.instanceId)
|
||||
&& Objects.equals(secureVirtualHostName, that.secureVirtualHostName)
|
||||
&& Objects.equals(aSGName, that.aSGName)
|
||||
&& Objects.equals(metadataMap, that.metadataMap)
|
||||
&& Objects.equals(dataCenterInfo, that.dataCenterInfo)
|
||||
&& Objects.equals(ipAddress, that.ipAddress)
|
||||
&& Objects.equals(aSGName, that.aSGName) && Objects.equals(metadataMap, that.metadataMap)
|
||||
&& Objects.equals(dataCenterInfo, that.dataCenterInfo) && Objects.equals(ipAddress, that.ipAddress)
|
||||
&& Objects.equals(statusPageUrlPath, that.statusPageUrlPath)
|
||||
&& Objects.equals(statusPageUrl, that.statusPageUrl)
|
||||
&& Objects.equals(homePageUrlPath, that.homePageUrlPath)
|
||||
@@ -602,65 +592,47 @@ public class EurekaInstanceConfigBean
|
||||
&& Objects.equals(healthCheckUrlPath, that.healthCheckUrlPath)
|
||||
&& Objects.equals(healthCheckUrl, that.healthCheckUrl)
|
||||
&& Objects.equals(secureHealthCheckUrl, that.secureHealthCheckUrl)
|
||||
&& Objects.equals(namespace, that.namespace)
|
||||
&& Objects.equals(hostname, that.hostname)
|
||||
&& preferIpAddress == that.preferIpAddress
|
||||
&& Objects.equals(initialStatus, that.initialStatus)
|
||||
&& Arrays.equals(defaultAddressResolutionOrder,
|
||||
that.defaultAddressResolutionOrder)
|
||||
&& Objects.equals(namespace, that.namespace) && Objects.equals(hostname, that.hostname)
|
||||
&& preferIpAddress == that.preferIpAddress && Objects.equals(initialStatus, that.initialStatus)
|
||||
&& Arrays.equals(defaultAddressResolutionOrder, that.defaultAddressResolutionOrder)
|
||||
&& Objects.equals(environment, that.environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(hostInfo, inetUtils, appname, appGroupName,
|
||||
instanceEnabledOnit, nonSecurePort, securePort, nonSecurePortEnabled,
|
||||
securePortEnabled, leaseRenewalIntervalInSeconds,
|
||||
leaseExpirationDurationInSeconds, virtualHostName, instanceId,
|
||||
secureVirtualHostName, aSGName, metadataMap, dataCenterInfo, ipAddress,
|
||||
statusPageUrlPath, statusPageUrl, homePageUrlPath, homePageUrl,
|
||||
healthCheckUrlPath, healthCheckUrl, secureHealthCheckUrl, namespace,
|
||||
hostname, preferIpAddress, initialStatus, defaultAddressResolutionOrder,
|
||||
environment);
|
||||
return Objects.hash(hostInfo, inetUtils, appname, appGroupName, instanceEnabledOnit, nonSecurePort, securePort,
|
||||
nonSecurePortEnabled, securePortEnabled, leaseRenewalIntervalInSeconds,
|
||||
leaseExpirationDurationInSeconds, virtualHostName, instanceId, secureVirtualHostName, aSGName,
|
||||
metadataMap, dataCenterInfo, ipAddress, statusPageUrlPath, statusPageUrl, homePageUrlPath, homePageUrl,
|
||||
healthCheckUrlPath, healthCheckUrl, secureHealthCheckUrl, namespace, hostname, preferIpAddress,
|
||||
initialStatus, defaultAddressResolutionOrder, environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EurekaInstanceConfigBean{").append("hostInfo=")
|
||||
.append(hostInfo).append(", ").append("inetUtils=").append(inetUtils)
|
||||
.append(", ").append("appname='").append(appname).append("', ")
|
||||
.append("appGroupName='").append(appGroupName).append("', ")
|
||||
.append("instanceEnabledOnit=").append(instanceEnabledOnit).append(", ")
|
||||
.append("nonSecurePort=").append(nonSecurePort).append(", ")
|
||||
.append("securePort=").append(securePort).append(", ")
|
||||
.append("nonSecurePortEnabled=").append(nonSecurePortEnabled).append(", ")
|
||||
.append("securePortEnabled=").append(securePortEnabled).append(", ")
|
||||
.append("leaseRenewalIntervalInSeconds=")
|
||||
.append(leaseRenewalIntervalInSeconds).append(", ")
|
||||
.append("leaseExpirationDurationInSeconds=")
|
||||
.append(leaseExpirationDurationInSeconds).append(", ")
|
||||
.append("virtualHostName='").append(virtualHostName).append("', ")
|
||||
.append("instanceId='").append(instanceId).append("', ")
|
||||
.append("secureVirtualHostName='").append(secureVirtualHostName)
|
||||
.append("', ").append("aSGName='").append(aSGName).append("', ")
|
||||
.append("metadataMap=").append(metadataMap).append(", ")
|
||||
.append("dataCenterInfo=").append(dataCenterInfo).append(", ")
|
||||
.append("ipAddress='").append(ipAddress).append("', ")
|
||||
.append("statusPageUrlPath='").append(statusPageUrlPath).append("', ")
|
||||
.append("statusPageUrl='").append(statusPageUrl).append("', ")
|
||||
.append("homePageUrlPath='").append(homePageUrlPath).append("', ")
|
||||
.append("homePageUrl='").append(homePageUrl).append("', ")
|
||||
.append("healthCheckUrlPath='").append(healthCheckUrlPath).append("', ")
|
||||
.append("healthCheckUrl='").append(healthCheckUrl).append("', ")
|
||||
.append("secureHealthCheckUrl='").append(secureHealthCheckUrl)
|
||||
.append("', ").append("namespace='").append(namespace).append("', ")
|
||||
.append("hostname='").append(hostname).append("', ")
|
||||
.append("preferIpAddress=").append(preferIpAddress).append(", ")
|
||||
.append("initialStatus=").append(initialStatus).append(", ")
|
||||
.append("defaultAddressResolutionOrder=")
|
||||
.append(Arrays.toString(defaultAddressResolutionOrder)).append(", ")
|
||||
.append("environment=").append(environment).append(", ").append("}")
|
||||
.toString();
|
||||
return new StringBuilder("EurekaInstanceConfigBean{").append("hostInfo=").append(hostInfo).append(", ")
|
||||
.append("inetUtils=").append(inetUtils).append(", ").append("appname='").append(appname).append("', ")
|
||||
.append("appGroupName='").append(appGroupName).append("', ").append("instanceEnabledOnit=")
|
||||
.append(instanceEnabledOnit).append(", ").append("nonSecurePort=").append(nonSecurePort).append(", ")
|
||||
.append("securePort=").append(securePort).append(", ").append("nonSecurePortEnabled=")
|
||||
.append(nonSecurePortEnabled).append(", ").append("securePortEnabled=").append(securePortEnabled)
|
||||
.append(", ").append("leaseRenewalIntervalInSeconds=").append(leaseRenewalIntervalInSeconds)
|
||||
.append(", ").append("leaseExpirationDurationInSeconds=").append(leaseExpirationDurationInSeconds)
|
||||
.append(", ").append("virtualHostName='").append(virtualHostName).append("', ").append("instanceId='")
|
||||
.append(instanceId).append("', ").append("secureVirtualHostName='").append(secureVirtualHostName)
|
||||
.append("', ").append("aSGName='").append(aSGName).append("', ").append("metadataMap=")
|
||||
.append(metadataMap).append(", ").append("dataCenterInfo=").append(dataCenterInfo).append(", ")
|
||||
.append("ipAddress='").append(ipAddress).append("', ").append("statusPageUrlPath='")
|
||||
.append(statusPageUrlPath).append("', ").append("statusPageUrl='").append(statusPageUrl).append("', ")
|
||||
.append("homePageUrlPath='").append(homePageUrlPath).append("', ").append("homePageUrl='")
|
||||
.append(homePageUrl).append("', ").append("healthCheckUrlPath='").append(healthCheckUrlPath)
|
||||
.append("', ").append("healthCheckUrl='").append(healthCheckUrl).append("', ")
|
||||
.append("secureHealthCheckUrl='").append(secureHealthCheckUrl).append("', ").append("namespace='")
|
||||
.append(namespace).append("', ").append("hostname='").append(hostname).append("', ")
|
||||
.append("preferIpAddress=").append(preferIpAddress).append(", ").append("initialStatus=")
|
||||
.append(initialStatus).append(", ").append("defaultAddressResolutionOrder=")
|
||||
.append(Arrays.toString(defaultAddressResolutionOrder)).append(", ").append("environment=")
|
||||
.append(environment).append(", ").append("}").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,23 +46,18 @@ public class InstanceInfoFactory {
|
||||
if (!namespace.endsWith(".")) {
|
||||
namespace = namespace + ".";
|
||||
}
|
||||
builder.setNamespace(namespace).setAppName(config.getAppname())
|
||||
.setInstanceId(config.getInstanceId())
|
||||
.setAppGroupName(config.getAppGroupName())
|
||||
.setDataCenterInfo(config.getDataCenterInfo())
|
||||
builder.setNamespace(namespace).setAppName(config.getAppname()).setInstanceId(config.getInstanceId())
|
||||
.setAppGroupName(config.getAppGroupName()).setDataCenterInfo(config.getDataCenterInfo())
|
||||
.setIPAddr(config.getIpAddress()).setHostName(config.getHostName(false))
|
||||
.setPort(config.getNonSecurePort())
|
||||
.enablePort(InstanceInfo.PortType.UNSECURE,
|
||||
config.isNonSecurePortEnabled())
|
||||
.enablePort(InstanceInfo.PortType.UNSECURE, config.isNonSecurePortEnabled())
|
||||
.setSecurePort(config.getSecurePort())
|
||||
.enablePort(InstanceInfo.PortType.SECURE, config.getSecurePortEnabled())
|
||||
.setVIPAddress(config.getVirtualHostName())
|
||||
.setSecureVIPAddress(config.getSecureVirtualHostName())
|
||||
.setVIPAddress(config.getVirtualHostName()).setSecureVIPAddress(config.getSecureVirtualHostName())
|
||||
.setHomePageUrl(config.getHomePageUrlPath(), config.getHomePageUrl())
|
||||
.setStatusPageUrl(config.getStatusPageUrlPath(),
|
||||
config.getStatusPageUrl())
|
||||
.setHealthCheckUrls(config.getHealthCheckUrlPath(),
|
||||
config.getHealthCheckUrl(), config.getSecureHealthCheckUrl())
|
||||
.setStatusPageUrl(config.getStatusPageUrlPath(), config.getStatusPageUrl())
|
||||
.setHealthCheckUrls(config.getHealthCheckUrlPath(), config.getHealthCheckUrl(),
|
||||
config.getSecureHealthCheckUrl())
|
||||
.setASGName(config.getASGName());
|
||||
|
||||
// Start off with the STARTING state to avoid traffic
|
||||
@@ -75,8 +70,7 @@ public class InstanceInfoFactory {
|
||||
}
|
||||
else {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Setting initial instance status as: "
|
||||
+ InstanceInfo.InstanceStatus.UP
|
||||
log.info("Setting initial instance status as: " + InstanceInfo.InstanceStatus.UP
|
||||
+ ". This may be too early for the instance to advertise itself as available. "
|
||||
+ "You would instead want to control this via a healthcheck handler.");
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class DiscoveryClientOptionalArgsConfiguration {
|
||||
|
||||
protected static final Log logger = LogFactory
|
||||
.getLog(DiscoveryClientOptionalArgsConfiguration.class);
|
||||
protected static final Log logger = LogFactory.getLog(DiscoveryClientOptionalArgsConfiguration.class);
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("eureka.client.tls")
|
||||
@@ -58,12 +57,11 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
|
||||
@ConditionalOnMissingClass("com.sun.jersey.api.client.filter.ClientFilter")
|
||||
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class },
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled",
|
||||
matchIfMissing = true, havingValue = "false")
|
||||
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(
|
||||
TlsProperties tlsProperties) throws GeneralSecurityException, IOException {
|
||||
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
|
||||
havingValue = "false")
|
||||
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(TlsProperties tlsProperties)
|
||||
throws GeneralSecurityException, IOException {
|
||||
logger.info("Eureka HTTP Client uses RestTemplate.");
|
||||
RestTemplateDiscoveryClientOptionalArgs result = new RestTemplateDiscoveryClientOptionalArgs();
|
||||
setupTLS(result, tlsProperties);
|
||||
@@ -72,18 +70,17 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "com.sun.jersey.api.client.filter.ClientFilter")
|
||||
@ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
public MutableDiscoveryClientOptionalArgs discoveryClientOptionalArgs(
|
||||
TlsProperties tlsProperties) throws GeneralSecurityException, IOException {
|
||||
@ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT)
|
||||
public MutableDiscoveryClientOptionalArgs discoveryClientOptionalArgs(TlsProperties tlsProperties)
|
||||
throws GeneralSecurityException, IOException {
|
||||
logger.info("Eureka HTTP Client uses Jersey");
|
||||
MutableDiscoveryClientOptionalArgs result = new MutableDiscoveryClientOptionalArgs();
|
||||
setupTLS(result, tlsProperties);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void setupTLS(AbstractDiscoveryClientOptionalArgs<?> args,
|
||||
TlsProperties properties) throws GeneralSecurityException, IOException {
|
||||
private static void setupTLS(AbstractDiscoveryClientOptionalArgs<?> args, TlsProperties properties)
|
||||
throws GeneralSecurityException, IOException {
|
||||
if (properties.isEnabled()) {
|
||||
SSLContextFactory factory = new SSLContextFactory(properties);
|
||||
args.setSSLContext(factory.createSSLContext());
|
||||
@@ -91,10 +88,8 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("com.sun.jersey.api.client.filter.ClientFilter")
|
||||
@ConditionalOnClass(
|
||||
name = "org.springframework.web.reactive.function.client.WebClient")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled",
|
||||
havingValue = "true")
|
||||
@ConditionalOnClass(name = "org.springframework.web.reactive.function.client.WebClient")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", havingValue = "true")
|
||||
protected static class WebClientConfiguration {
|
||||
|
||||
@Autowired
|
||||
@@ -102,12 +97,10 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(
|
||||
value = { AbstractDiscoveryClientOptionalArgs.class,
|
||||
RestTemplateDiscoveryClientOptionalArgs.class },
|
||||
value = { AbstractDiscoveryClientOptionalArgs.class, RestTemplateDiscoveryClientOptionalArgs.class },
|
||||
search = SearchStrategy.CURRENT)
|
||||
public WebClientDiscoveryClientOptionalArgs webClientDiscoveryClientOptionalArgs(
|
||||
ObjectProvider<WebClient.Builder> builder)
|
||||
throws GeneralSecurityException, IOException {
|
||||
ObjectProvider<WebClient.Builder> builder) throws GeneralSecurityException, IOException {
|
||||
logger.info("Eureka HTTP Client uses WebClient.");
|
||||
WebClientDiscoveryClientOptionalArgs result = new WebClientDiscoveryClientOptionalArgs(
|
||||
builder::getIfAvailable);
|
||||
@@ -120,14 +113,13 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
@Configuration
|
||||
@ConditionalOnMissingClass({ "com.sun.jersey.api.client.filter.ClientFilter",
|
||||
"org.springframework.web.reactive.function.client.WebClient" })
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled",
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", havingValue = "true")
|
||||
protected static class WebClientNotFoundConfiguration {
|
||||
|
||||
public WebClientNotFoundConfiguration() {
|
||||
throw new IllegalStateException("eureka.client.webclient.enabled is true, "
|
||||
+ "but WebClient is not on the classpath. Please add "
|
||||
+ "spring-boot-starter-webflux as a dependency.");
|
||||
throw new IllegalStateException(
|
||||
"eureka.client.webclient.enabled is true, " + "but WebClient is not on the classpath. Please add "
|
||||
+ "spring-boot-starter-webflux as a dependency.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties
|
||||
@ConditionalOnClass({ EurekaInstanceConfigBean.class, EurekaClient.class,
|
||||
ConfigServerProperties.class })
|
||||
@ConditionalOnClass({ EurekaInstanceConfigBean.class, EurekaClient.class, ConfigServerProperties.class })
|
||||
public class EurekaClientConfigServerAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -52,8 +51,7 @@ public class EurekaClientConfigServerAutoConfiguration {
|
||||
return;
|
||||
}
|
||||
String prefix = this.server.getPrefix();
|
||||
if (StringUtils.hasText(prefix) && !StringUtils
|
||||
.hasText(this.instance.getMetadataMap().get("configPath"))) {
|
||||
if (StringUtils.hasText(prefix) && !StringUtils.hasText(this.instance.getMetadataMap().get("configPath"))) {
|
||||
this.instance.getMetadataMap().put("configPath", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,36 +61,32 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
|
||||
@ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled",
|
||||
matchIfMissing = false)
|
||||
@ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled", matchIfMissing = false)
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties
|
||||
public class EurekaConfigServerBootstrapConfiguration {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(EurekaConfigServerBootstrapConfiguration.class);
|
||||
private static final Log log = LogFactory.getLog(EurekaConfigServerBootstrapConfiguration.class);
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = EurekaClientConfig.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnMissingBean(value = EurekaClientConfig.class, search = SearchStrategy.CURRENT)
|
||||
public EurekaClientConfigBean eurekaClientConfigBean() {
|
||||
return new EurekaClientConfigBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(EurekaHttpClient.class)
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled",
|
||||
matchIfMissing = true, havingValue = "false")
|
||||
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(
|
||||
EurekaClientConfigBean config, Environment env) {
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
|
||||
havingValue = "false")
|
||||
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(EurekaClientConfigBean config,
|
||||
Environment env) {
|
||||
return (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory()
|
||||
.newClient(new DefaultEndpoint(getEurekaUrl(config, env)));
|
||||
}
|
||||
|
||||
private static String getEurekaUrl(EurekaClientConfigBean config, Environment env) {
|
||||
List<String> urls = EndpointUtils.getDiscoveryServiceUrls(config,
|
||||
EurekaClientConfigBean.DEFAULT_ZONE, new HostnameBasedUrlRandomizer(
|
||||
env.getProperty("eureka.instance.hostname")));
|
||||
List<String> urls = EndpointUtils.getDiscoveryServiceUrls(config, EurekaClientConfigBean.DEFAULT_ZONE,
|
||||
new HostnameBasedUrlRandomizer(env.getProperty("eureka.instance.hostname")));
|
||||
return urls.get(0);
|
||||
}
|
||||
|
||||
@@ -100,16 +96,14 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigServerInstanceProvider.Function eurekaConfigServerInstanceProvider(
|
||||
EurekaHttpClient client, EurekaClientConfig config) {
|
||||
public ConfigServerInstanceProvider.Function eurekaConfigServerInstanceProvider(EurekaHttpClient client,
|
||||
EurekaClientConfig config) {
|
||||
|
||||
return serviceId -> {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("eurekaConfigServerInstanceProvider finding instances for "
|
||||
+ serviceId);
|
||||
log.debug("eurekaConfigServerInstanceProvider finding instances for " + serviceId);
|
||||
}
|
||||
EurekaHttpResponse<Applications> response = client
|
||||
.getApplications(config.getRegion());
|
||||
EurekaHttpResponse<Applications> response = client.getApplications(config.getRegion());
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
if (!isSuccessful(response) || response.getEntity() == null) {
|
||||
return instances;
|
||||
@@ -117,21 +111,19 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
|
||||
Applications applications = response.getEntity();
|
||||
applications.shuffleInstances(config.shouldFilterOnlyUpInstances());
|
||||
List<InstanceInfo> infos = applications
|
||||
.getInstancesByVirtualHostName(serviceId);
|
||||
List<InstanceInfo> infos = applications.getInstancesByVirtualHostName(serviceId);
|
||||
for (InstanceInfo info : infos) {
|
||||
instances.add(new EurekaServiceInstance(info));
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("eurekaConfigServerInstanceProvider found " + infos.size()
|
||||
+ " instance(s) for " + serviceId + ", " + instances);
|
||||
log.debug("eurekaConfigServerInstanceProvider found " + infos.size() + " instance(s) for " + serviceId
|
||||
+ ", " + instances);
|
||||
}
|
||||
return instances;
|
||||
};
|
||||
}
|
||||
|
||||
private static final class HostnameBasedUrlRandomizer
|
||||
implements EndpointUtils.ServiceUrlRandomizer {
|
||||
private static final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
|
||||
|
||||
private final String hostname;
|
||||
|
||||
@@ -164,22 +156,17 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(
|
||||
name = "org.springframework.web.reactive.function.client.WebClient")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled",
|
||||
havingValue = "true")
|
||||
@ImportAutoConfiguration({ CodecsAutoConfiguration.class,
|
||||
WebClientAutoConfiguration.class })
|
||||
@ConditionalOnClass(name = "org.springframework.web.reactive.function.client.WebClient")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", havingValue = "true")
|
||||
@ImportAutoConfiguration({ CodecsAutoConfiguration.class, WebClientAutoConfiguration.class })
|
||||
protected static class WebClientConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(EurekaHttpClient.class)
|
||||
public WebClientEurekaHttpClient configDiscoveryWebClientEurekaHttpClient(
|
||||
EurekaClientConfigBean config, ObjectProvider<WebClient.Builder> builder,
|
||||
Environment env) {
|
||||
return (WebClientEurekaHttpClient) new WebClientTransportClientFactory(
|
||||
builder::getIfAvailable)
|
||||
.newClient(new DefaultEndpoint(getEurekaUrl(config, env)));
|
||||
public WebClientEurekaHttpClient configDiscoveryWebClientEurekaHttpClient(EurekaClientConfigBean config,
|
||||
ObjectProvider<WebClient.Builder> builder, Environment env) {
|
||||
return (WebClientEurekaHttpClient) new WebClientTransportClientFactory(builder::getIfAvailable)
|
||||
.newClient(new DefaultEndpoint(getEurekaUrl(config, env)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
|
||||
/**
|
||||
* @author Daniel Lavoie
|
||||
*/
|
||||
public class RestTemplateDiscoveryClientOptionalArgs
|
||||
extends AbstractDiscoveryClientOptionalArgs<Void> {
|
||||
public class RestTemplateDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs<Void> {
|
||||
|
||||
public RestTemplateDiscoveryClientOptionalArgs() {
|
||||
setTransportClientFactories(new RestTemplateTransportClientFactories());
|
||||
|
||||
@@ -74,38 +74,33 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
|
||||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST,
|
||||
new HttpEntity<>(info, headers), Void.class);
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST, new HttpEntity<>(info, headers),
|
||||
Void.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue())
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> cancel(String appName, String id) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id;
|
||||
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE,
|
||||
null, Void.class);
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue())
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id,
|
||||
InstanceInfo info, InstanceStatus overriddenStatus) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status="
|
||||
+ info.getStatus().toString() + "&lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString() + (overriddenStatus != null
|
||||
? "&overriddenstatus=" + overriddenStatus.name() : "");
|
||||
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info,
|
||||
InstanceStatus overriddenStatus) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
|
||||
+ "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
|
||||
+ (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");
|
||||
|
||||
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath,
|
||||
HttpMethod.PUT, null, InstanceInfo.class);
|
||||
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null,
|
||||
InstanceInfo.class);
|
||||
|
||||
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
|
||||
response.getStatusCodeValue(), InstanceInfo.class)
|
||||
.headers(headersOf(response));
|
||||
response.getStatusCodeValue(), InstanceInfo.class).headers(headersOf(response));
|
||||
|
||||
if (response.hasBody()) {
|
||||
eurekaResponseBuilder.entity(response.getBody());
|
||||
@@ -115,30 +110,24 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> statusUpdate(String appName, String id,
|
||||
InstanceStatus newStatus, InstanceInfo info) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?value="
|
||||
+ newStatus.name() + "&lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString();
|
||||
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus,
|
||||
InstanceInfo info) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?value=" + newStatus.name()
|
||||
+ "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();
|
||||
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT,
|
||||
null, Void.class);
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue())
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id,
|
||||
InstanceInfo info) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id
|
||||
+ "/status?lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();
|
||||
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info) {
|
||||
String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString();
|
||||
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE,
|
||||
null, Void.class);
|
||||
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue())
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,22 +135,19 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
return getApplicationsInternal("apps/", regions);
|
||||
}
|
||||
|
||||
private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath,
|
||||
String[] regions) {
|
||||
private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
|
||||
String url = serviceUrl + urlPath;
|
||||
|
||||
if (regions != null && regions.length > 0) {
|
||||
url = url + (urlPath.contains("?") ? "&" : "?") + "regions="
|
||||
+ StringUtil.join(regions);
|
||||
url = url + (urlPath.contains("?") ? "&" : "?") + "regions=" + StringUtil.join(regions);
|
||||
}
|
||||
|
||||
ResponseEntity<EurekaApplications> response = restTemplate.exchange(url,
|
||||
HttpMethod.GET, null, EurekaApplications.class);
|
||||
ResponseEntity<EurekaApplications> response = restTemplate.exchange(url, HttpMethod.GET, null,
|
||||
EurekaApplications.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue(),
|
||||
response.getStatusCode().value() == HttpStatus.OK.value()
|
||||
&& response.hasBody() ? (Applications) response.getBody() : null)
|
||||
.headers(headersOf(response)).build();
|
||||
response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody()
|
||||
? (Applications) response.getBody() : null).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,8 +161,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress,
|
||||
String... regions) {
|
||||
public EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress, String... regions) {
|
||||
return getApplicationsInternal("svips/" + secureVipAddress, regions);
|
||||
}
|
||||
|
||||
@@ -184,14 +169,12 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
public EurekaHttpResponse<Application> getApplication(String appName) {
|
||||
String urlPath = serviceUrl + "apps/" + appName;
|
||||
|
||||
ResponseEntity<Application> response = restTemplate.exchange(urlPath,
|
||||
HttpMethod.GET, null, Application.class);
|
||||
ResponseEntity<Application> response = restTemplate.exchange(urlPath, HttpMethod.GET, null, Application.class);
|
||||
|
||||
Application application = response.getStatusCodeValue() == HttpStatus.OK.value()
|
||||
&& response.hasBody() ? response.getBody() : null;
|
||||
Application application = response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody()
|
||||
? response.getBody() : null;
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue(), application)
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue(), application).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,13 +190,12 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
|
||||
private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
|
||||
urlPath = serviceUrl + urlPath;
|
||||
|
||||
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath,
|
||||
HttpMethod.GET, null, InstanceInfo.class);
|
||||
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.GET, null,
|
||||
InstanceInfo.class);
|
||||
|
||||
return anEurekaHttpResponse(response.getStatusCodeValue(),
|
||||
response.getStatusCodeValue() == HttpStatus.OK.value()
|
||||
&& response.hasBody() ? response.getBody() : null)
|
||||
.headers(headersOf(response)).build();
|
||||
response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody() ? response.getBody()
|
||||
: null).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,28 +31,24 @@ import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
|
||||
/**
|
||||
* @author Daniel Lavoie
|
||||
*/
|
||||
public class RestTemplateTransportClientFactories
|
||||
implements TransportClientFactories<Void> {
|
||||
public class RestTemplateTransportClientFactories implements TransportClientFactories<Void> {
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
Collection<Void> additionalFilters, EurekaJerseyClient providedJerseyClient) {
|
||||
public TransportClientFactory newTransportClientFactory(Collection<Void> additionalFilters,
|
||||
EurekaJerseyClient providedJerseyClient) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
EurekaClientConfig clientConfig, Collection<Void> additionalFilters,
|
||||
InstanceInfo myInstanceInfo) {
|
||||
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
|
||||
Collection<Void> additionalFilters, InstanceInfo myInstanceInfo) {
|
||||
return new RestTemplateTransportClientFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
final EurekaClientConfig clientConfig,
|
||||
public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig,
|
||||
final Collection<Void> additionalFilters, final InstanceInfo myInstanceInfo,
|
||||
final Optional<SSLContext> sslContext,
|
||||
final Optional<HostnameVerifier> hostnameVerifier) {
|
||||
final Optional<SSLContext> sslContext, final Optional<HostnameVerifier> hostnameVerifier) {
|
||||
return new RestTemplateTransportClientFactory();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,7 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
|
||||
@Override
|
||||
public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
|
||||
return new RestTemplateEurekaHttpClient(restTemplate(serviceUrl.getServiceUrl()),
|
||||
serviceUrl.getServiceUrl());
|
||||
return new RestTemplateEurekaHttpClient(restTemplate(serviceUrl.getServiceUrl()), serviceUrl.getServiceUrl());
|
||||
}
|
||||
|
||||
private RestTemplate restTemplate(String serviceUrl) {
|
||||
@@ -66,8 +65,8 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
if (serviceURI.getUserInfo() != null) {
|
||||
String[] credentials = serviceURI.getUserInfo().split(":");
|
||||
if (credentials.length == 2) {
|
||||
restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(
|
||||
credentials[0], credentials[1]));
|
||||
restTemplate.getInterceptors()
|
||||
.add(new BasicAuthenticationInterceptor(credentials[0], credentials[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,8 +92,7 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
*/
|
||||
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
converter.setObjectMapper(new ObjectMapper()
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
|
||||
converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
|
||||
|
||||
SimpleModule jsonModule = new SimpleModule();
|
||||
jsonModule.setSerializerModifier(createJsonSerializerModifier()); // keyFormatter,
|
||||
@@ -102,12 +100,9 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
converter.getObjectMapper().registerModule(jsonModule);
|
||||
|
||||
converter.getObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, true);
|
||||
converter.getObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE,
|
||||
true);
|
||||
converter.getObjectMapper().addMixIn(Applications.class,
|
||||
ApplicationsJsonMixIn.class);
|
||||
converter.getObjectMapper().addMixIn(InstanceInfo.class,
|
||||
InstanceInfoJsonMixIn.class);
|
||||
converter.getObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
|
||||
converter.getObjectMapper().addMixIn(Applications.class, ApplicationsJsonMixIn.class);
|
||||
converter.getObjectMapper().addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class);
|
||||
|
||||
// converter.getObjectMapper().addMixIn(DataCenterInfo.class,
|
||||
// DataCenterInfoXmlMixIn.class);
|
||||
@@ -130,16 +125,15 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
// {
|
||||
return new BeanSerializerModifier() {
|
||||
@Override
|
||||
public JsonSerializer<?> modifySerializer(SerializationConfig config,
|
||||
BeanDescription beanDesc, JsonSerializer<?> serializer) {
|
||||
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
|
||||
JsonSerializer<?> serializer) {
|
||||
/*
|
||||
* if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) {
|
||||
* return new ApplicationsJsonBeanSerializer((BeanSerializerBase)
|
||||
* serializer, keyFormatter); }
|
||||
*/
|
||||
if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
|
||||
return new InstanceInfoJsonBeanSerializer(
|
||||
(BeanSerializerBase) serializer, false);
|
||||
return new InstanceInfoJsonBeanSerializer((BeanSerializerBase) serializer, false);
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
* @author Daniel Lavoie
|
||||
* @author Haytham Mohamed
|
||||
*/
|
||||
public class WebClientDiscoveryClientOptionalArgs
|
||||
extends AbstractDiscoveryClientOptionalArgs<Void> {
|
||||
public class WebClientDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs<Void> {
|
||||
|
||||
@Deprecated
|
||||
public WebClientDiscoveryClientOptionalArgs() {
|
||||
|
||||
@@ -56,11 +56,10 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> register(InstanceInfo info) {
|
||||
return webClient.post().uri("apps/" + info.getAppName(), Void.class)
|
||||
.body(BodyInserters.fromValue(info))
|
||||
return webClient.post().uri("apps/" + info.getAppName(), Void.class).body(BodyInserters.fromValue(info))
|
||||
.header(HttpHeaders.ACCEPT_ENCODING, "gzip")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.exchange().map(response -> eurekaHttpResponse(response)).block();
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.map(response -> eurekaHttpResponse(response)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,21 +69,18 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id,
|
||||
InstanceInfo info, InstanceStatus overriddenStatus) {
|
||||
String urlPath = "apps/" + appName + '/' + id + "?status="
|
||||
+ info.getStatus().toString() + "&lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString() + (overriddenStatus != null
|
||||
? "&overriddenstatus=" + overriddenStatus.name() : "");
|
||||
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info,
|
||||
InstanceStatus overriddenStatus) {
|
||||
String urlPath = "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
|
||||
+ "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
|
||||
+ (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");
|
||||
|
||||
ClientResponse response = webClient.put().uri(urlPath, InstanceInfo.class)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.block();
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange().block();
|
||||
|
||||
EurekaHttpResponseBuilder<InstanceInfo> builder = anEurekaHttpResponse(
|
||||
statusCodeValueOf(response), InstanceInfo.class)
|
||||
.headers(headersOf(response));
|
||||
EurekaHttpResponseBuilder<InstanceInfo> builder = anEurekaHttpResponse(statusCodeValueOf(response),
|
||||
InstanceInfo.class).headers(headersOf(response));
|
||||
|
||||
InstanceInfo entity = response.toEntity(InstanceInfo.class).block().getBody();
|
||||
|
||||
@@ -97,26 +93,24 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> statusUpdate(String appName, String id,
|
||||
InstanceStatus newStatus, InstanceInfo info) {
|
||||
String urlPath = "apps/" + appName + '/' + id + "/status?value="
|
||||
+ newStatus.name() + "&lastDirtyTimestamp="
|
||||
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus,
|
||||
InstanceInfo info) {
|
||||
String urlPath = "apps/" + appName + '/' + id + "/status?value=" + newStatus.name() + "&lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString();
|
||||
|
||||
return webClient.put().uri(urlPath, Void.class)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.exchange().map(response -> eurekaHttpResponse(response)).block();
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.map(response -> eurekaHttpResponse(response)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id,
|
||||
InstanceInfo info) {
|
||||
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info) {
|
||||
String urlPath = "apps/" + appName + '/' + id + "/status?lastDirtyTimestamp="
|
||||
+ info.getLastDirtyTimestamp().toString();
|
||||
|
||||
return webClient.delete().uri(urlPath, Void.class)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.exchange().map(response -> eurekaHttpResponse(response)).block();
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.map(response -> eurekaHttpResponse(response)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,27 +118,23 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
return getApplicationsInternal("apps/", regions);
|
||||
}
|
||||
|
||||
private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath,
|
||||
String[] regions) {
|
||||
private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
|
||||
String url = urlPath;
|
||||
|
||||
if (regions != null && regions.length > 0) {
|
||||
url = url + (urlPath.contains("?") ? "&" : "?") + "regions="
|
||||
+ StringUtil.join(regions);
|
||||
url = url + (urlPath.contains("?") ? "&" : "?") + "regions=" + StringUtil.join(regions);
|
||||
}
|
||||
|
||||
ClientResponse response = webClient.get().uri(url, Applications.class)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.block();
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange().block();
|
||||
|
||||
int statusCode = statusCodeValueOf(response);
|
||||
|
||||
Applications body = response.toEntity(Applications.class).block().getBody();
|
||||
|
||||
return anEurekaHttpResponse(statusCode,
|
||||
statusCode == HttpStatus.OK.value() && body != null ? body : null)
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(statusCode, statusCode == HttpStatus.OK.value() && body != null ? body : null)
|
||||
.headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,27 +148,22 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress,
|
||||
String... regions) {
|
||||
public EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress, String... regions) {
|
||||
return getApplicationsInternal("svips/" + secureVipAddress, regions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpResponse<Application> getApplication(String appName) {
|
||||
|
||||
ClientResponse response = webClient.get()
|
||||
.uri("apps/" + appName, Application.class)
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.block();
|
||||
ClientResponse response = webClient.get().uri("apps/" + appName, Application.class)
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange().block();
|
||||
|
||||
int statusCode = statusCodeValueOf(response);
|
||||
Application body = response.toEntity(Application.class).block().getBody();
|
||||
|
||||
Application application = statusCode == HttpStatus.OK.value() && body != null
|
||||
? body : null;
|
||||
Application application = statusCode == HttpStatus.OK.value() && body != null ? body : null;
|
||||
|
||||
return anEurekaHttpResponse(statusCode, application).headers(headersOf(response))
|
||||
.build();
|
||||
return anEurekaHttpResponse(statusCode, application).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,15 +178,13 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
|
||||
private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
|
||||
ClientResponse response = webClient.get().uri(urlPath, InstanceInfo.class)
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange()
|
||||
.block();
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).exchange().block();
|
||||
|
||||
int statusCode = statusCodeValueOf(response);
|
||||
InstanceInfo body = response.toEntity(InstanceInfo.class).block().getBody();
|
||||
|
||||
return anEurekaHttpResponse(statusCode,
|
||||
statusCode == HttpStatus.OK.value() && body != null ? body : null)
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(statusCode, statusCode == HttpStatus.OK.value() && body != null ? body : null)
|
||||
.headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,8 +206,8 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
asHeaders.entrySet().stream().forEach(entry -> entry.getValue().stream()
|
||||
.forEach(v -> headers.put(entry.getKey(), v)));
|
||||
asHeaders.entrySet().stream()
|
||||
.forEach(entry -> entry.getValue().stream().forEach(v -> headers.put(entry.getKey(), v)));
|
||||
return headers;
|
||||
}
|
||||
|
||||
@@ -233,8 +216,7 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
|
||||
}
|
||||
|
||||
private EurekaHttpResponse<Void> eurekaHttpResponse(ClientResponse response) {
|
||||
return anEurekaHttpResponse(statusCodeValueOf(response))
|
||||
.headers(headersOf(response)).build();
|
||||
return anEurekaHttpResponse(statusCodeValueOf(response)).headers(headersOf(response)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,24 +44,21 @@ public class WebClientTransportClientFactories implements TransportClientFactori
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
Collection<Void> additionalFilters, EurekaJerseyClient providedJerseyClient) {
|
||||
public TransportClientFactory newTransportClientFactory(Collection<Void> additionalFilters,
|
||||
EurekaJerseyClient providedJerseyClient) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
EurekaClientConfig clientConfig, Collection<Void> additionalFilters,
|
||||
InstanceInfo myInstanceInfo) {
|
||||
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
|
||||
Collection<Void> additionalFilters, InstanceInfo myInstanceInfo) {
|
||||
return new WebClientTransportClientFactory(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(
|
||||
final EurekaClientConfig clientConfig,
|
||||
public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig,
|
||||
final Collection<Void> additionalFilters, final InstanceInfo myInstanceInfo,
|
||||
final Optional<SSLContext> sslContext,
|
||||
final Optional<HostnameVerifier> hostnameVerifier) {
|
||||
final Optional<SSLContext> sslContext, final Optional<HostnameVerifier> hostnameVerifier) {
|
||||
return new WebClientTransportClientFactory(builder);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,10 +89,8 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
|
||||
if (serviceURI.getUserInfo() != null) {
|
||||
String[] credentials = serviceURI.getUserInfo().split(":");
|
||||
if (credentials.length == 2) {
|
||||
builder.filter(ExchangeFilterFunctions
|
||||
.basicAuthentication(credentials[0], credentials[1]));
|
||||
url = serviceUrl.replace(credentials[0] + ":" + credentials[1] + "@",
|
||||
"");
|
||||
builder.filter(ExchangeFilterFunctions.basicAuthentication(credentials[0], credentials[1]));
|
||||
url = serviceUrl.replace(credentials[0] + ":" + credentials[1] + "@", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,12 +102,9 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
|
||||
private void setCodecs(WebClient.Builder builder) {
|
||||
ObjectMapper objectMapper = objectMapper();
|
||||
builder.codecs(configurer -> {
|
||||
ClientCodecConfigurer.ClientDefaultCodecs defaults = configurer
|
||||
.defaultCodecs();
|
||||
defaults.jackson2JsonEncoder(
|
||||
new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON));
|
||||
defaults.jackson2JsonDecoder(
|
||||
new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
|
||||
ClientCodecConfigurer.ClientDefaultCodecs defaults = configurer.defaultCodecs();
|
||||
defaults.jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON));
|
||||
defaults.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
|
||||
|
||||
});
|
||||
}
|
||||
@@ -119,10 +114,8 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
|
||||
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
|
||||
// literally 400 pass the tests, not 4xxClientError
|
||||
if (clientResponse.statusCode().value() == 400) {
|
||||
ClientResponse newResponse = ClientResponse.from(clientResponse)
|
||||
.statusCode(HttpStatus.OK).build();
|
||||
newResponse.body(
|
||||
(clientHttpResponse, context) -> clientHttpResponse.getBody());
|
||||
ClientResponse newResponse = ClientResponse.from(clientResponse).statusCode(HttpStatus.OK).build();
|
||||
newResponse.body((clientHttpResponse, context) -> clientHttpResponse.getBody());
|
||||
return Mono.just(newResponse);
|
||||
}
|
||||
return Mono.just(clientResponse);
|
||||
@@ -177,11 +170,10 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
|
||||
public static BeanSerializerModifier createJsonSerializerModifier() {
|
||||
return new BeanSerializerModifier() {
|
||||
@Override
|
||||
public JsonSerializer<?> modifySerializer(SerializationConfig config,
|
||||
BeanDescription beanDesc, JsonSerializer<?> serializer) {
|
||||
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
|
||||
JsonSerializer<?> serializer) {
|
||||
if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
|
||||
return new InstanceInfoJsonBeanSerializer(
|
||||
(BeanSerializerBase) serializer, false);
|
||||
return new InstanceInfoJsonBeanSerializer((BeanSerializerBase) serializer, false);
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ import static org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancer
|
||||
@ConditionalOnBean({ LoadBalancerZoneConfig.class, EurekaLoadBalancerProperties.class })
|
||||
public class EurekaLoadBalancerClientConfiguration {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(EurekaLoadBalancerClientConfiguration.class);
|
||||
private static final Log LOG = LogFactory.getLog(EurekaLoadBalancerClientConfiguration.class);
|
||||
|
||||
private final EurekaClientConfig clientConfig;
|
||||
|
||||
@@ -56,10 +55,8 @@ public class EurekaLoadBalancerClientConfiguration {
|
||||
|
||||
private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties;
|
||||
|
||||
public EurekaLoadBalancerClientConfiguration(
|
||||
@Autowired(required = false) EurekaClientConfig clientConfig,
|
||||
@Autowired(required = false) EurekaInstanceConfig eurekaInstanceConfig,
|
||||
LoadBalancerZoneConfig zoneConfig,
|
||||
public EurekaLoadBalancerClientConfiguration(@Autowired(required = false) EurekaClientConfig clientConfig,
|
||||
@Autowired(required = false) EurekaInstanceConfig eurekaInstanceConfig, LoadBalancerZoneConfig zoneConfig,
|
||||
EurekaLoadBalancerProperties eurekaLoadBalancerProperties) {
|
||||
this.clientConfig = clientConfig;
|
||||
this.eurekaConfig = eurekaInstanceConfig;
|
||||
@@ -83,17 +80,14 @@ public class EurekaLoadBalancerClientConfiguration {
|
||||
|
||||
private String getZoneFromEureka() {
|
||||
String zone;
|
||||
boolean approximateZoneFromHostname = eurekaLoadBalancerProperties
|
||||
.isApproximateZoneFromHostname();
|
||||
boolean approximateZoneFromHostname = eurekaLoadBalancerProperties.isApproximateZoneFromHostname();
|
||||
if (approximateZoneFromHostname && eurekaConfig != null) {
|
||||
return ZoneUtils.extractApproximateZone(this.eurekaConfig.getHostName(false));
|
||||
}
|
||||
else {
|
||||
zone = eurekaConfig == null ? null
|
||||
: eurekaConfig.getMetadataMap().get("zone");
|
||||
zone = eurekaConfig == null ? null : eurekaConfig.getMetadataMap().get("zone");
|
||||
if (StringUtils.isEmpty(zone) && clientConfig != null) {
|
||||
String[] zones = clientConfig
|
||||
.getAvailabilityZones(clientConfig.getRegion());
|
||||
String[] zones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
|
||||
// Pick the first one from the regions we want to connect to
|
||||
zone = zones != null && zones.length > 0 ? zones[0] : null;
|
||||
}
|
||||
|
||||
@@ -34,29 +34,27 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
|
||||
private static final int RANDOM_PORT = 0;
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(DefaultManagementMetadataProvider.class);
|
||||
private static final Log log = LogFactory.getLog(DefaultManagementMetadataProvider.class);
|
||||
|
||||
@Override
|
||||
public ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort,
|
||||
String serverContextPath, String managementContextPath,
|
||||
Integer managementPort) {
|
||||
public ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath,
|
||||
String managementContextPath, Integer managementPort) {
|
||||
if (isRandom(managementPort)) {
|
||||
return null;
|
||||
}
|
||||
if (managementPort == null && isRandom(serverPort)) {
|
||||
return null;
|
||||
}
|
||||
String healthCheckUrl = getHealthCheckUrl(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort, false);
|
||||
String statusPageUrl = getStatusPageUrl(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
String healthCheckUrl = getHealthCheckUrl(instance, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort, false);
|
||||
String statusPageUrl = getStatusPageUrl(instance, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
ManagementMetadata metadata = new ManagementMetadata(healthCheckUrl,
|
||||
statusPageUrl, managementPort == null ? serverPort : managementPort);
|
||||
ManagementMetadata metadata = new ManagementMetadata(healthCheckUrl, statusPageUrl,
|
||||
managementPort == null ? serverPort : managementPort);
|
||||
if (instance.isSecurePortEnabled()) {
|
||||
metadata.setSecureHealthCheckUrl(getHealthCheckUrl(instance, serverPort,
|
||||
serverContextPath, managementContextPath, managementPort, true));
|
||||
metadata.setSecureHealthCheckUrl(getHealthCheckUrl(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort, true));
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
@@ -65,41 +63,36 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
return port != null && port == RANDOM_PORT;
|
||||
}
|
||||
|
||||
protected String getHealthCheckUrl(EurekaInstanceConfigBean instance, int serverPort,
|
||||
String serverContextPath, String managementContextPath,
|
||||
Integer managementPort, boolean isSecure) {
|
||||
protected String getHealthCheckUrl(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath,
|
||||
String managementContextPath, Integer managementPort, boolean isSecure) {
|
||||
String healthCheckUrlPath = instance.getHealthCheckUrlPath();
|
||||
String healthCheckUrl = getUrl(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort, healthCheckUrlPath, isSecure);
|
||||
String healthCheckUrl = getUrl(instance, serverPort, serverContextPath, managementContextPath, managementPort,
|
||||
healthCheckUrlPath, isSecure);
|
||||
log.debug("Constructed eureka meta-data healthcheckUrl: " + healthCheckUrl);
|
||||
return healthCheckUrl;
|
||||
}
|
||||
|
||||
public String getStatusPageUrl(EurekaInstanceConfigBean instance, int serverPort,
|
||||
String serverContextPath, String managementContextPath,
|
||||
Integer managementPort) {
|
||||
public String getStatusPageUrl(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath,
|
||||
String managementContextPath, Integer managementPort) {
|
||||
String statusPageUrlPath = instance.getStatusPageUrlPath();
|
||||
String statusPageUrl = getUrl(instance, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort, statusPageUrlPath, false);
|
||||
String statusPageUrl = getUrl(instance, serverPort, serverContextPath, managementContextPath, managementPort,
|
||||
statusPageUrlPath, false);
|
||||
log.debug("Constructed eureka meta-data statusPageUrl: " + statusPageUrl);
|
||||
return statusPageUrl;
|
||||
}
|
||||
|
||||
private String getUrl(EurekaInstanceConfigBean instance, int serverPort,
|
||||
String serverContextPath, String managementContextPath,
|
||||
Integer managementPort, String urlPath, boolean isSecure) {
|
||||
managementContextPath = refineManagementContextPath(serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
private String getUrl(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath,
|
||||
String managementContextPath, Integer managementPort, String urlPath, boolean isSecure) {
|
||||
managementContextPath = refineManagementContextPath(serverContextPath, managementContextPath, managementPort);
|
||||
if (managementPort == null) {
|
||||
managementPort = serverPort;
|
||||
}
|
||||
String scheme = isSecure ? "https" : "http";
|
||||
return constructValidUrl(scheme, instance.getHostname(), managementPort,
|
||||
managementContextPath, urlPath);
|
||||
return constructValidUrl(scheme, instance.getHostname(), managementPort, managementContextPath, urlPath);
|
||||
}
|
||||
|
||||
private String refineManagementContextPath(String serverContextPath,
|
||||
String managementContextPath, Integer managementPort) {
|
||||
private String refineManagementContextPath(String serverContextPath, String managementContextPath,
|
||||
Integer managementPort) {
|
||||
// management context path is relative to server context path when no management
|
||||
// port is set
|
||||
if (managementContextPath != null && managementPort == null) {
|
||||
@@ -114,21 +107,18 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
return serverContextPath;
|
||||
}
|
||||
|
||||
private String constructValidUrl(String scheme, String hostname, int port,
|
||||
String contextPath, String statusPath) {
|
||||
private String constructValidUrl(String scheme, String hostname, int port, String contextPath, String statusPath) {
|
||||
try {
|
||||
if (!contextPath.endsWith("/")) {
|
||||
contextPath = contextPath + "/";
|
||||
}
|
||||
String refinedContextPath = '/'
|
||||
+ StringUtils.trimLeadingCharacter(contextPath, '/');
|
||||
String refinedContextPath = '/' + StringUtils.trimLeadingCharacter(contextPath, '/');
|
||||
URL base = new URL(scheme, hostname, port, refinedContextPath);
|
||||
String refinedStatusPath = refinedStatusPath(statusPath, contextPath);
|
||||
return new URL(base, refinedStatusPath).toString();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
String message = getErrorMessage(scheme, hostname, port, contextPath,
|
||||
statusPath);
|
||||
String message = getErrorMessage(scheme, hostname, port, contextPath, statusPath);
|
||||
throw new IllegalStateException(message, e);
|
||||
}
|
||||
}
|
||||
@@ -140,11 +130,10 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
return StringUtils.trimLeadingCharacter(statusPath, '/');
|
||||
}
|
||||
|
||||
private String getErrorMessage(String scheme, String hostname, int port,
|
||||
String contextPath, String statusPath) {
|
||||
private String getErrorMessage(String scheme, String hostname, int port, String contextPath, String statusPath) {
|
||||
return String.format(
|
||||
"Failed to construct url for scheme: %s, hostName: %s port: %s contextPath: %s statusPath: %s",
|
||||
scheme, hostname, port, contextPath, statusPath);
|
||||
"Failed to construct url for scheme: %s, hostName: %s port: %s contextPath: %s statusPath: %s", scheme,
|
||||
hostname, port, contextPath, statusPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ public class ManagementMetadata {
|
||||
|
||||
private String secureHealthCheckUrl;
|
||||
|
||||
public ManagementMetadata(String healthCheckUrl, String statusPageUrl,
|
||||
Integer managementPort) {
|
||||
public ManagementMetadata(String healthCheckUrl, String statusPageUrl, Integer managementPort) {
|
||||
this.healthCheckUrl = healthCheckUrl;
|
||||
this.statusPageUrl = statusPageUrl;
|
||||
this.managementPort = managementPort;
|
||||
@@ -71,8 +70,7 @@ public class ManagementMetadata {
|
||||
return false;
|
||||
}
|
||||
ManagementMetadata that = (ManagementMetadata) o;
|
||||
return Objects.equals(healthCheckUrl, that.healthCheckUrl)
|
||||
&& Objects.equals(statusPageUrl, that.statusPageUrl)
|
||||
return Objects.equals(healthCheckUrl, that.healthCheckUrl) && Objects.equals(statusPageUrl, that.statusPageUrl)
|
||||
&& Objects.equals(managementPort, that.managementPort);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
|
||||
*/
|
||||
public interface ManagementMetadataProvider {
|
||||
|
||||
ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort,
|
||||
String serverContextPath, String managementContextPath,
|
||||
Integer managementPort);
|
||||
ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath,
|
||||
String managementContextPath, Integer managementPort);
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,7 @@ public class EurekaReactiveDiscoveryClient implements ReactiveDiscoveryClient {
|
||||
|
||||
private final EurekaClientConfig clientConfig;
|
||||
|
||||
public EurekaReactiveDiscoveryClient(EurekaClient eurekaClient,
|
||||
EurekaClientConfig clientConfig) {
|
||||
public EurekaReactiveDiscoveryClient(EurekaClient eurekaClient, EurekaClientConfig clientConfig) {
|
||||
this.eurekaClient = eurekaClient;
|
||||
this.clientConfig = clientConfig;
|
||||
}
|
||||
@@ -52,9 +51,7 @@ public class EurekaReactiveDiscoveryClient implements ReactiveDiscoveryClient {
|
||||
|
||||
@Override
|
||||
public Flux<ServiceInstance> getInstances(String serviceId) {
|
||||
return Flux
|
||||
.defer(() -> Flux.fromIterable(
|
||||
eurekaClient.getInstancesByVipAddress(serviceId, false)))
|
||||
return Flux.defer(() -> Flux.fromIterable(eurekaClient.getInstancesByVipAddress(serviceId, false)))
|
||||
.map(EurekaServiceInstance::new);
|
||||
}
|
||||
|
||||
@@ -62,8 +59,8 @@ public class EurekaReactiveDiscoveryClient implements ReactiveDiscoveryClient {
|
||||
public Flux<String> getServices() {
|
||||
return Flux.defer(() -> Mono.justOrEmpty(eurekaClient.getApplications()))
|
||||
.flatMapIterable(Applications::getRegisteredApplications)
|
||||
.filter(application -> !application.getInstances().isEmpty())
|
||||
.map(Application::getName).map(String::toLowerCase);
|
||||
.filter(application -> !application.getInstances().isEmpty()).map(Application::getName)
|
||||
.map(String::toLowerCase);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,26 +48,23 @@ import org.springframework.context.annotation.Configuration;
|
||||
@ConditionalOnReactiveDiscoveryEnabled
|
||||
@ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties
|
||||
@AutoConfigureAfter({ EurekaClientAutoConfiguration.class,
|
||||
ReactiveCompositeDiscoveryClientAutoConfiguration.class })
|
||||
@AutoConfigureAfter({ EurekaClientAutoConfiguration.class, ReactiveCompositeDiscoveryClientAutoConfiguration.class })
|
||||
@AutoConfigureBefore(ReactiveCommonsClientAutoConfiguration.class)
|
||||
@ImportAutoConfiguration(EurekaClientAutoConfiguration.class)
|
||||
public class EurekaReactiveDiscoveryClientConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EurekaReactiveDiscoveryClient eurekaReactiveDiscoveryClient(
|
||||
EurekaClient client, EurekaClientConfig clientConfig) {
|
||||
public EurekaReactiveDiscoveryClient eurekaReactiveDiscoveryClient(EurekaClient client,
|
||||
EurekaClientConfig clientConfig) {
|
||||
return new EurekaReactiveDiscoveryClient(client, clientConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(
|
||||
name = "org.springframework.boot.actuate.health.ReactiveHealthIndicator")
|
||||
@ConditionalOnClass(name = "org.springframework.boot.actuate.health.ReactiveHealthIndicator")
|
||||
@ConditionalOnDiscoveryHealthIndicatorEnabled
|
||||
public ReactiveDiscoveryClientHealthIndicator eurekaReactiveDiscoveryClientHealthIndicator(
|
||||
EurekaReactiveDiscoveryClient client,
|
||||
DiscoveryClientHealthIndicatorProperties properties) {
|
||||
EurekaReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) {
|
||||
return new ReactiveDiscoveryClientHealthIndicator(client, properties);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ import org.springframework.core.Ordered;
|
||||
* @author Jakub Narloch
|
||||
* @author Raiyan Raiyan
|
||||
*/
|
||||
public class EurekaAutoServiceRegistration implements AutoServiceRegistration,
|
||||
SmartLifecycle, Ordered, SmartApplicationListener {
|
||||
public class EurekaAutoServiceRegistration
|
||||
implements AutoServiceRegistration, SmartLifecycle, Ordered, SmartApplicationListener {
|
||||
|
||||
private static final Log log = LogFactory.getLog(EurekaAutoServiceRegistration.class);
|
||||
|
||||
@@ -56,8 +56,8 @@ public class EurekaAutoServiceRegistration implements AutoServiceRegistration,
|
||||
|
||||
private EurekaRegistration registration;
|
||||
|
||||
public EurekaAutoServiceRegistration(ApplicationContext context,
|
||||
EurekaServiceRegistry serviceRegistry, EurekaRegistration registration) {
|
||||
public EurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry,
|
||||
EurekaRegistration registration) {
|
||||
this.context = context;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.registration = registration;
|
||||
@@ -82,8 +82,7 @@ public class EurekaAutoServiceRegistration implements AutoServiceRegistration,
|
||||
|
||||
this.serviceRegistry.register(this.registration);
|
||||
|
||||
this.context.publishEvent(new InstanceRegisteredEvent<>(this,
|
||||
this.registration.getInstanceConfig()));
|
||||
this.context.publishEvent(new InstanceRegisteredEvent<>(this, this.registration.getInstanceConfig()));
|
||||
this.running.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,8 @@ public class EurekaRegistration implements Registration {
|
||||
|
||||
private ObjectProvider<HealthCheckHandler> healthCheckHandler;
|
||||
|
||||
private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig,
|
||||
EurekaClient eurekaClient, ApplicationInfoManager applicationInfoManager,
|
||||
ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient,
|
||||
ApplicationInfoManager applicationInfoManager, ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
this.eurekaClient = eurekaClient;
|
||||
this.instanceConfig = instanceConfig;
|
||||
this.applicationInfoManager = applicationInfoManager;
|
||||
@@ -113,8 +112,7 @@ public class EurekaRegistration implements Registration {
|
||||
public CloudEurekaClient getEurekaClient() {
|
||||
if (this.cloudEurekaClient.get() == null) {
|
||||
try {
|
||||
this.cloudEurekaClient.compareAndSet(null,
|
||||
getTargetObject(eurekaClient, CloudEurekaClient.class));
|
||||
this.cloudEurekaClient.compareAndSet(null, getTargetObject(eurekaClient, CloudEurekaClient.class));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("error getting CloudEurekaClient", e);
|
||||
@@ -146,8 +144,7 @@ public class EurekaRegistration implements Registration {
|
||||
return healthCheckHandler;
|
||||
}
|
||||
|
||||
public void setHealthCheckHandler(
|
||||
ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
public void setHealthCheckHandler(ObjectProvider<HealthCheckHandler> healthCheckHandler) {
|
||||
this.healthCheckHandler = healthCheckHandler;
|
||||
}
|
||||
|
||||
@@ -203,8 +200,7 @@ public class EurekaRegistration implements Registration {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder with(EurekaClientConfig clientConfig,
|
||||
ApplicationEventPublisher publisher) {
|
||||
public Builder with(EurekaClientConfig clientConfig, ApplicationEventPublisher publisher) {
|
||||
this.clientConfig = clientConfig;
|
||||
this.publisher = publisher;
|
||||
return this;
|
||||
@@ -214,22 +210,17 @@ public class EurekaRegistration implements Registration {
|
||||
Assert.notNull(instanceConfig, "instanceConfig may not be null");
|
||||
|
||||
if (this.applicationInfoManager == null) {
|
||||
InstanceInfo instanceInfo = new InstanceInfoFactory()
|
||||
.create(this.instanceConfig);
|
||||
this.applicationInfoManager = new ApplicationInfoManager(
|
||||
this.instanceConfig, instanceInfo);
|
||||
InstanceInfo instanceInfo = new InstanceInfoFactory().create(this.instanceConfig);
|
||||
this.applicationInfoManager = new ApplicationInfoManager(this.instanceConfig, instanceInfo);
|
||||
}
|
||||
if (this.eurekaClient == null) {
|
||||
Assert.notNull(this.clientConfig,
|
||||
"if eurekaClient is null, EurekaClientConfig may not be null");
|
||||
Assert.notNull(this.publisher,
|
||||
"if eurekaClient is null, ApplicationEventPublisher may not be null");
|
||||
Assert.notNull(this.clientConfig, "if eurekaClient is null, EurekaClientConfig may not be null");
|
||||
Assert.notNull(this.publisher, "if eurekaClient is null, ApplicationEventPublisher may not be null");
|
||||
|
||||
this.eurekaClient = new CloudEurekaClient(this.applicationInfoManager,
|
||||
this.clientConfig, this.publisher);
|
||||
this.eurekaClient = new CloudEurekaClient(this.applicationInfoManager, this.clientConfig,
|
||||
this.publisher);
|
||||
}
|
||||
return new EurekaRegistration(instanceConfig, eurekaClient,
|
||||
applicationInfoManager, healthCheckHandler);
|
||||
return new EurekaRegistration(instanceConfig, eurekaClient, applicationInfoManager, healthCheckHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,17 +38,14 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
|
||||
maybeInitializeClient(reg);
|
||||
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Registering application "
|
||||
+ reg.getApplicationInfoManager().getInfo().getAppName()
|
||||
+ " with eureka with status "
|
||||
+ reg.getInstanceConfig().getInitialStatus());
|
||||
log.info("Registering application " + reg.getApplicationInfoManager().getInfo().getAppName()
|
||||
+ " with eureka with status " + reg.getInstanceConfig().getInitialStatus());
|
||||
}
|
||||
|
||||
reg.getApplicationInfoManager()
|
||||
.setInstanceStatus(reg.getInstanceConfig().getInitialStatus());
|
||||
reg.getApplicationInfoManager().setInstanceStatus(reg.getInstanceConfig().getInitialStatus());
|
||||
|
||||
reg.getHealthCheckHandler().ifAvailable(healthCheckHandler -> reg
|
||||
.getEurekaClient().registerHealthCheck(healthCheckHandler));
|
||||
reg.getHealthCheckHandler()
|
||||
.ifAvailable(healthCheckHandler -> reg.getEurekaClient().registerHealthCheck(healthCheckHandler));
|
||||
}
|
||||
|
||||
private void maybeInitializeClient(EurekaRegistration reg) {
|
||||
@@ -62,13 +59,11 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
|
||||
if (reg.getApplicationInfoManager().getInfo() != null) {
|
||||
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Unregistering application "
|
||||
+ reg.getApplicationInfoManager().getInfo().getAppName()
|
||||
log.info("Unregistering application " + reg.getApplicationInfoManager().getInfo().getAppName()
|
||||
+ " with eureka with status DOWN");
|
||||
}
|
||||
|
||||
reg.getApplicationInfoManager()
|
||||
.setInstanceStatus(InstanceInfo.InstanceStatus.DOWN);
|
||||
reg.getApplicationInfoManager().setInstanceStatus(InstanceInfo.InstanceStatus.DOWN);
|
||||
|
||||
// shutdown of eureka client should happen with EurekaRegistration.close()
|
||||
// auto registration will create a bean which will be properly disposed
|
||||
@@ -87,8 +82,7 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
|
||||
}
|
||||
|
||||
// TODO: howto deal with status types across discovery systems?
|
||||
InstanceInfo.InstanceStatus newStatus = InstanceInfo.InstanceStatus
|
||||
.toEnum(status);
|
||||
InstanceInfo.InstanceStatus newStatus = InstanceInfo.InstanceStatus.toEnum(status);
|
||||
registration.getEurekaClient().setStatus(newStatus, info);
|
||||
}
|
||||
|
||||
@@ -96,8 +90,7 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
|
||||
public Object getStatus(EurekaRegistration registration) {
|
||||
String appname = registration.getApplicationInfoManager().getInfo().getAppName();
|
||||
String instanceId = registration.getApplicationInfoManager().getInfo().getId();
|
||||
InstanceInfo info = registration.getEurekaClient().getInstanceInfo(appname,
|
||||
instanceId);
|
||||
InstanceInfo info = registration.getEurekaClient().getInstanceInfo(appname, instanceId);
|
||||
|
||||
HashMap<String, Object> status = new HashMap<>();
|
||||
if (info != null) {
|
||||
|
||||
@@ -36,23 +36,18 @@ public class ConditionalOnRefreshScopeTests {
|
||||
|
||||
@Test
|
||||
public void refreshScopeIncluded() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withUserConfiguration(Beans.class).run(c -> {
|
||||
assertThat(c).hasSingleBean(
|
||||
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
assertThat(c.getBean("foo")).isEqualTo("foo");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshScopeIncludedAndPropertyDisabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withPropertyValues("eureka.client.refresh.enable=false")
|
||||
.withUserConfiguration(Beans.class).run(c -> {
|
||||
assertThat(c).hasSingleBean(
|
||||
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withPropertyValues("eureka.client.refresh.enable=false").withUserConfiguration(Beans.class).run(c -> {
|
||||
assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
assertThat(c).doesNotHaveBean("foo");
|
||||
assertThat(c.getBean("bar")).isEqualTo("bar");
|
||||
});
|
||||
|
||||
@@ -83,8 +83,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
private void setupContext(Class<?>... config) {
|
||||
ConfigurationPropertySources.attach(this.context.getEnvironment());
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class,
|
||||
EurekaDiscoveryClientConfiguration.class);
|
||||
DiscoveryClientOptionalArgsConfiguration.class, EurekaDiscoveryClientConfiguration.class);
|
||||
for (Class<?> value : config) {
|
||||
this.context.register(value);
|
||||
}
|
||||
@@ -93,25 +92,21 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetManagementPortInMetadataMapIfEqualToServerPort()
|
||||
throws Exception {
|
||||
public void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception {
|
||||
TestPropertyValues.of("server.port=8989").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
|
||||
assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("8989");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=0")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=0").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
|
||||
assertThat(instance.getMetadataMap().get("management.port")).isEqualTo(null);
|
||||
assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo(null);
|
||||
@@ -119,27 +114,22 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
|
||||
TestPropertyValues.of("management.server.port=9999",
|
||||
"com.sun.management.jmxremote.port=6789").applyTo(this.context);
|
||||
TestPropertyValues.of("management.server.port=9999", "com.sun.management.jmxremote.port=6789")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("9999");
|
||||
assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo("6789");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
|
||||
TestPropertyValues
|
||||
.of("management.server.port=9999",
|
||||
"eureka.instance.metadata-map.jmx.port=9898",
|
||||
"eureka.instance.metadata-map.management.port=7878")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("management.server.port=9999", "eureka.instance.metadata-map.jmx.port=9898",
|
||||
"eureka.instance.metadata-map.management.port=7878").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("7878");
|
||||
assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo("9898");
|
||||
}
|
||||
@@ -157,8 +147,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void nonSecurePort() {
|
||||
testNonSecurePortSystemProp("PORT");
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName())
|
||||
.isEqualTo("eurekaClient");
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName()).isEqualTo("eurekaClient");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,8 +157,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void securePortUnderscores() {
|
||||
TestPropertyValues.of("eureka.instance.secure-port-enabled=true")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.secure-port-enabled=true").applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(), "SERVER_PORT:8443");
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getSecurePort()).isEqualTo(8443);
|
||||
@@ -178,56 +166,45 @@ public class EurekaClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void securePort() {
|
||||
testSecurePort("PORT");
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName())
|
||||
.isEqualTo("eurekaClient");
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName()).isEqualTo("eurekaClient");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void managementPort() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("9999"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("9999")).as("Wrong status page: " + instance.getStatusPageUrl())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPort() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.statusPageUrlPath=/myStatusPage")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.statusPageUrlPath=/myStatusPage").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathAndManagementPort() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.healthCheckUrlPath=/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.healthCheckUrlPath=/myHealthCheck").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path()
|
||||
throws Exception {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"server.contextPath=/service").applyTo(this.context);
|
||||
public void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throws Exception {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "server.contextPath=/service")
|
||||
.applyTo(this.context);
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":9999/actuator/info"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":9999/actuator/health"))
|
||||
@@ -235,34 +212,25 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path()
|
||||
throws Exception {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989",
|
||||
"management.server.servlet.context-path=/management")
|
||||
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.servlet.context-path=/management")
|
||||
.applyTo(this.context);
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":8989/management/actuator/info"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
assertThat(
|
||||
instance.getHealthCheckUrl().endsWith(":8989/management/actuator/health"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl())
|
||||
.isTrue();
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":8989/management/actuator/health"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port()
|
||||
throws Exception {
|
||||
TestPropertyValues
|
||||
.of("server.port=0", "management.server.servlet.context-path=/management")
|
||||
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() throws Exception {
|
||||
TestPropertyValues.of("server.port=0", "management.server.servlet.context-path=/management")
|
||||
.applyTo(this.context);
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrlPath().equals("/management/actuator/info"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrlPath()).isTrue();
|
||||
assertThat(instance.getHealthCheckUrlPath().equals("/management/actuator/health"))
|
||||
@@ -271,14 +239,11 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPortAndContextPath() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage",
|
||||
"eureka.instance.status-page-url-path=/myStatusPage")
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage", "eureka.instance.status-page-url-path=/myStatusPage")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
@@ -286,27 +251,22 @@ public class EurekaClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void healthCheckUrlPathAndManagementPortAndContextPath() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage",
|
||||
.of("server.port=8989", "management.server.port=9999", "management.server.servlet.context-path=/manage",
|
||||
"eureka.instance.health-check-url-path=/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPortAndContextPathKebobCase() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage",
|
||||
"eureka.instance.status-page-url-path=/myStatusPage")
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage", "eureka.instance.status-page-url-path=/myStatusPage")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
@@ -314,53 +274,44 @@ public class EurekaClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void healthCheckUrlPathAndManagementPortAndContextPathKebobCase() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"management.server.servlet.context-path=/manage",
|
||||
.of("server.port=8989", "management.server.port=9999", "management.server.servlet.context-path=/manage",
|
||||
"eureka.instance.health-check-url-path=/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
|
||||
TestPropertyValues.of("server.port=8989",
|
||||
"server.servlet.context-path=/servletContextPath",
|
||||
"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "server.servlet.context-path=/servletContextPath",
|
||||
"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl())
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl())
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl()).as("Wrong health check: " + instance.getHealthCheckUrl())
|
||||
.endsWith(":8989/servletContextPath/myHealthCheck");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPortKabobCase() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.status-page-url-path=/myStatusPage")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.status-page-url-path=/myStatusPage").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlAndPreferIpAddress() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.hostname=foo", "eureka.instance.prefer-ip-address:true")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo",
|
||||
"eureka.instance.prefer-ip-address:true").applyTo(this.context);
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
|
||||
assertThat(instance.getStatusPageUrl()).as("statusPageUrl is wrong")
|
||||
.isEqualTo("http://" + instance.getIpAddress() + ":9999/actuator/info");
|
||||
@@ -370,14 +321,13 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.hostname=foo",
|
||||
"eureka.instance.ip-address:192.168.13.90",
|
||||
"eureka.instance.prefer-ip-address:true").applyTo(this.context);
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo",
|
||||
"eureka.instance.ip-address:192.168.13.90", "eureka.instance.prefer-ip-address:true")
|
||||
.applyTo(this.context);
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
|
||||
assertThat(instance.getStatusPageUrl()).as("statusPageUrl is wrong")
|
||||
.isEqualTo("http://192.168.13.90:9999/actuator/info");
|
||||
@@ -387,76 +337,62 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathAndManagementPortKabobCase() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.health-check-url-path=/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.health-check-url-path=/myHealthCheck").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPortUpperCase() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999")
|
||||
.applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(),
|
||||
"EUREKA_INSTANCE_STATUS_PAGE_URL_PATH=/myStatusPage");
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(), "EUREKA_INSTANCE_STATUS_PAGE_URL_PATH=/myStatusPage");
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathAndManagementPortUpperCase() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999")
|
||||
.applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(),
|
||||
"EUREKA_INSTANCE_HEALTH_CHECK_URL_PATH=/myHealthCheck");
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(), "EUREKA_INSTANCE_HEALTH_CHECK_URL_PATH=/myHealthCheck");
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostname() {
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
|
||||
"eureka.instance.hostname=foo").applyTo(this.context);
|
||||
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("foo"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().contains("foo")).as("Wrong status page: " + instance.getStatusPageUrl())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshScopedBeans() {
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getBeanClassName())
|
||||
.startsWith(
|
||||
GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
|
||||
assertThat(this.context.getBeanDefinition("eurekaApplicationInfoManager")
|
||||
.getBeanClassName()).startsWith(
|
||||
GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
|
||||
.startsWith(GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
|
||||
assertThat(this.context.getBeanDefinition("eurekaApplicationInfoManager").getBeanClassName())
|
||||
.startsWith(GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
|
||||
TestPropertyValues.of("eureka.client.healthcheck.enabled=true")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class,
|
||||
AutoServiceRegistrationConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.healthcheck.enabled=true").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class);
|
||||
|
||||
EurekaClient oldEurekaClient = getLazyInitEurekaClient();
|
||||
|
||||
HealthCheckHandler healthCheckHandler = this.context
|
||||
.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);
|
||||
HealthCheckHandler healthCheckHandler = this.context.getBean("eurekaHealthCheckHandler",
|
||||
HealthCheckHandler.class);
|
||||
|
||||
assertThat(healthCheckHandler).isInstanceOf(EurekaHealthCheckHandler.class);
|
||||
assertThat(oldEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);
|
||||
@@ -465,8 +401,8 @@ public class EurekaClientAutoConfigurationTests {
|
||||
refresher.refresh();
|
||||
|
||||
EurekaClient newEurekaClient = getLazyInitEurekaClient();
|
||||
HealthCheckHandler newHealthCheckHandler = this.context
|
||||
.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);
|
||||
HealthCheckHandler newHealthCheckHandler = this.context.getBean("eurekaHealthCheckHandler",
|
||||
HealthCheckHandler.class);
|
||||
|
||||
assertThat(healthCheckHandler).isSameAs(newHealthCheckHandler);
|
||||
assertThat(oldEurekaClient).isNotSameAs(newEurekaClient);
|
||||
@@ -475,13 +411,11 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void shouldCloseDiscoveryClient() throws Exception {
|
||||
TestPropertyValues.of("eureka.client.healthcheck.enabled=true")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class,
|
||||
AutoServiceRegistrationConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.healthcheck.enabled=true").applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class);
|
||||
|
||||
AtomicBoolean isShutdown = (AtomicBoolean) ReflectionTestUtils
|
||||
.getField(getLazyInitEurekaClient(), "isShutdown");
|
||||
AtomicBoolean isShutdown = (AtomicBoolean) ReflectionTestUtils.getField(getLazyInitEurekaClient(),
|
||||
"isShutdown");
|
||||
|
||||
assertThat(isShutdown.get()).isFalse();
|
||||
|
||||
@@ -492,8 +426,8 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void basicAuth() {
|
||||
TestPropertyValues.of("server.port=8989",
|
||||
"eureka.client.serviceUrl.defaultZone=https://user:foo@example.com:80/eureka")
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "eureka.client.serviceUrl.defaultZone=https://user:foo@example.com:80/eureka")
|
||||
.applyTo(this.context);
|
||||
setupContext(MockClientConfiguration.class);
|
||||
// ApacheHttpClient4 http = this.context.getBean(ApacheHttpClient4.class);
|
||||
@@ -519,17 +453,14 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testAppNameUpper() throws Exception {
|
||||
addSystemEnvironment(this.context.getEnvironment(),
|
||||
"SPRING_APPLICATION_NAME=mytestupper");
|
||||
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestupper");
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytestupper");
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).isEqualTo("mytestupper");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName())
|
||||
.isEqualTo("mytestupper");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName()).isEqualTo("mytestupper");
|
||||
}
|
||||
|
||||
private void addSystemEnvironment(ConfigurableEnvironment environment,
|
||||
String... pairs) {
|
||||
private void addSystemEnvironment(ConfigurableEnvironment environment, String... pairs) {
|
||||
MutablePropertySources sources = environment.getPropertySources();
|
||||
Map<String, Object> map = getOrAdd(sources, "testsysenv");
|
||||
for (String pair : pairs) {
|
||||
@@ -541,8 +472,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> getOrAdd(MutablePropertySources sources,
|
||||
String name) {
|
||||
private static Map<String, Object> getOrAdd(MutablePropertySources sources, String name) {
|
||||
if (sources.contains(name)) {
|
||||
return (Map<String, Object>) sources.get(name).getSource();
|
||||
}
|
||||
@@ -565,10 +495,8 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testInstanceNamePreferred() throws Exception {
|
||||
addSystemEnvironment(this.context.getEnvironment(),
|
||||
"SPRING_APPLICATION_NAME=mytestspringappname");
|
||||
TestPropertyValues.of("eureka.instance.appname=mytesteurekaappname")
|
||||
.applyTo(this.context);
|
||||
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestspringappname");
|
||||
TestPropertyValues.of("eureka.instance.appname=mytesteurekaappname").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytesteurekaappname");
|
||||
}
|
||||
@@ -591,8 +519,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
|
||||
TestPropertyValues.of("spring.cloud.discovery.enabled=false")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("spring.cloud.discovery.enabled=false").applyTo(this.context);
|
||||
setupContext(TestConfiguration.class);
|
||||
assertBeanNotPresent(EurekaClientConfigBean.class);
|
||||
assertBeanNotPresent(EurekaInstanceConfigBean.class);
|
||||
@@ -606,14 +533,11 @@ public class EurekaClientAutoConfigurationTests {
|
||||
public void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class,
|
||||
EurekaClientAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class, EurekaClientAutoConfiguration.class,
|
||||
EurekaDiscoveryClientConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.discovery.blocking.enabled=false")
|
||||
.run(context -> {
|
||||
.withPropertyValues("spring.cloud.discovery.blocking.enabled=false").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(DiscoveryClient.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(DiscoveryClientHealthIndicator.class);
|
||||
assertThat(context).doesNotHaveBean(DiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -640,9 +564,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
private void testSecurePort(String propName) {
|
||||
TestPropertyValues
|
||||
.of("eureka.instance.secure-port-enabled=true", propName + ":8443")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.secure-port-enabled=true", propName + ":8443").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getSecurePort()).isEqualTo(8443);
|
||||
}
|
||||
@@ -652,8 +574,8 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
private EurekaClient getLazyInitEurekaClient() throws Exception {
|
||||
return (EurekaClient) ((Advised) this.context.getBean("eurekaClient",
|
||||
EurekaClient.class)).getTargetSource().getTarget();
|
||||
return (EurekaClient) ((Advised) this.context.getBean("eurekaClient", EurekaClient.class)).getTargetSource()
|
||||
.getTarget();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -672,10 +594,9 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class,
|
||||
search = SearchStrategy.CURRENT)
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager,
|
||||
EurekaClientConfig config, ApplicationContext context) {
|
||||
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
|
||||
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
|
||||
ApplicationContext context) {
|
||||
return new CloudEurekaClient(manager, config, null, context) {
|
||||
@Override
|
||||
public synchronized void shutdown() {
|
||||
|
||||
@@ -47,75 +47,57 @@ public class EurekaClientConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void basicBinding() {
|
||||
TestPropertyValues.of("eureka.client.proxyHost=example.com")
|
||||
.applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.proxyHost=example.com").applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getProxyHost())
|
||||
.isEqualTo("example.com");
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getProxyHost()).isEqualTo("example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrl() {
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com")
|
||||
.applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com").applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getServiceUrl()
|
||||
.toString()).isEqualTo("{defaultZone=https://example.com}");
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone())
|
||||
.isEqualTo("[https://example.com/]");
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getServiceUrl().toString())
|
||||
.isEqualTo("{defaultZone=https://example.com}");
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone()).isEqualTo("[https://example.com/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlWithCompositePropertySource() {
|
||||
CompositePropertySource source = new CompositePropertySource("composite");
|
||||
this.context.getEnvironment().getPropertySources().addFirst(source);
|
||||
source.addPropertySource(new MapPropertySource("config",
|
||||
Collections.<String, Object>singletonMap(
|
||||
"eureka.client.serviceUrl.defaultZone",
|
||||
"https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com")));
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
source.addPropertySource(new MapPropertySource("config", Collections.<String, Object>singletonMap(
|
||||
"eureka.client.serviceUrl.defaultZone",
|
||||
"https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com")));
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getServiceUrl()
|
||||
.toString()).isEqualTo(
|
||||
"{defaultZone=https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com}");
|
||||
assertThat(this.context.getBean(EurekaClientConfigBean.class).getServiceUrl().toString()).isEqualTo(
|
||||
"{defaultZone=https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com}");
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone()).isEqualTo(
|
||||
"[https://example.com/, https://example2.com/, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlWithDefault() {
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com")
|
||||
.applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com").applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone())
|
||||
.isEqualTo("[https://example.com/]");
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone()).isEqualTo("[https://example.com/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlWithCustomZone() {
|
||||
TestPropertyValues
|
||||
.of("eureka.client.serviceUrl.customZone:https://custom-example.com")
|
||||
.applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.customZone:https://custom-example.com").applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(getEurekaServiceUrls("customZone"))
|
||||
.isEqualTo("[https://custom-example.com/]");
|
||||
assertThat(getEurekaServiceUrls("customZone")).isEqualTo("[https://custom-example.com/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlWithEmptyServiceUrls() {
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:")
|
||||
.applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:").applyTo(this.context);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(getEurekaServiceUrlsForDefaultZone()).isEqualTo("[]");
|
||||
}
|
||||
@@ -125,8 +107,7 @@ public class EurekaClientConfigBeanTests {
|
||||
}
|
||||
|
||||
private String getEurekaServiceUrls(String myZone) {
|
||||
return this.context.getBean(EurekaClientConfigBean.class)
|
||||
.getEurekaServerServiceUrls(myZone).toString();
|
||||
return this.context.getBean(EurekaClientConfigBean.class).getEurekaServerServiceUrls(myZone).toString();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
@@ -96,8 +96,7 @@ public class EurekaHealthCheckHandlerTests {
|
||||
}
|
||||
|
||||
private void initialize(Class<?>... configurations) throws Exception {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
|
||||
configurations);
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(configurations);
|
||||
healthCheckHandler.setApplicationContext(applicationContext);
|
||||
healthCheckHandler.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void basicBinding() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getAppGroupName()).isEqualTo("mygroup");
|
||||
}
|
||||
@@ -92,8 +91,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void initialHostName() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
if (this.hostName != null) {
|
||||
assertThat(getInstanceConfig().getHostname()).isEqualTo(this.hostName);
|
||||
@@ -102,8 +100,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void refreshHostName() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
ReflectionTestUtils.setField(getInstanceConfig(), "hostname", "marvin");
|
||||
assertThat(getInstanceConfig().getHostname()).isEqualTo("marvin");
|
||||
@@ -115,8 +112,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void refreshHostNameWhenSetByUser() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
getInstanceConfig().setHostname("marvin");
|
||||
assertThat(getInstanceConfig().getHostname()).isEqualTo("marvin");
|
||||
@@ -126,8 +122,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void initialIpAddress() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
if (this.ipAddress != null) {
|
||||
assertThat(getInstanceConfig().getIpAddress()).isEqualTo(this.ipAddress);
|
||||
@@ -136,8 +131,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void refreshIpAddress() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
ReflectionTestUtils.setField(getInstanceConfig(), "ipAddress", "10.0.0.1");
|
||||
assertThat(getInstanceConfig().getIpAddress()).isEqualTo("10.0.0.1");
|
||||
@@ -149,8 +143,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void refreshIpAddressWhenSetByUser() {
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
|
||||
setupContext();
|
||||
getInstanceConfig().setIpAddress("10.0.0.1");
|
||||
assertThat(getInstanceConfig().getIpAddress()).isEqualTo("10.0.0.1");
|
||||
@@ -161,8 +154,7 @@ public class EurekaInstanceConfigBeanTests {
|
||||
@Test
|
||||
public void testDefaultInitialStatus() {
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong")
|
||||
.isEqualTo(InstanceStatus.UP);
|
||||
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.UP);
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@@ -173,17 +165,14 @@ public class EurekaInstanceConfigBeanTests {
|
||||
|
||||
@Test
|
||||
public void testCustomInitialStatus() {
|
||||
TestPropertyValues.of("eureka.instance.initial-status:STARTING")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.initial-status:STARTING").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong")
|
||||
.isEqualTo(InstanceStatus.STARTING);
|
||||
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.STARTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferIpAddress() throws Exception {
|
||||
TestPropertyValues.of("eureka.instance.preferIpAddress:true")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.preferIpAddress:true").applyTo(this.context);
|
||||
setupContext();
|
||||
EurekaInstanceConfigBean instance = getInstanceConfig();
|
||||
assertThat(getInstanceConfig().getHostname().equals(instance.getIpAddress()))
|
||||
@@ -195,67 +184,54 @@ public class EurekaInstanceConfigBeanTests {
|
||||
public void testDefaultVirtualHostName() throws Exception {
|
||||
TestPropertyValues.of("spring.application.name:myapp").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong")
|
||||
.isEqualTo("myapp");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName())
|
||||
.as("secureVirtualHostName wrong").isEqualTo("myapp");
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong").isEqualTo("myapp");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName()).as("secureVirtualHostName wrong").isEqualTo("myapp");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomVirtualHostName() throws Exception {
|
||||
TestPropertyValues
|
||||
.of("spring.application.name:myapp",
|
||||
"eureka.instance.virtualHostName=myvirthost",
|
||||
"eureka.instance.secureVirtualHostName=mysecurevirthost")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("spring.application.name:myapp", "eureka.instance.virtualHostName=myvirthost",
|
||||
"eureka.instance.secureVirtualHostName=mysecurevirthost").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong")
|
||||
.isEqualTo("myvirthost");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName())
|
||||
.as("secureVirtualHostName wrong").isEqualTo("mysecurevirthost");
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong").isEqualTo("myvirthost");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName()).as("secureVirtualHostName wrong")
|
||||
.isEqualTo("mysecurevirthost");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultAppName() throws Exception {
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getAppname()).as("default app name is wrong")
|
||||
assertThat(getInstanceConfig().getAppname()).as("default app name is wrong").isEqualTo("unknown");
|
||||
assertThat(getInstanceConfig().getVirtualHostName()).as("default virtual hostname is wrong")
|
||||
.isEqualTo("unknown");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName()).as("default secure virtual hostname is wrong")
|
||||
.isEqualTo("unknown");
|
||||
assertThat(getInstanceConfig().getVirtualHostName())
|
||||
.as("default virtual hostname is wrong").isEqualTo("unknown");
|
||||
assertThat(getInstanceConfig().getSecureVirtualHostName())
|
||||
.as("default secure virtual hostname is wrong").isEqualTo("unknown");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomInstanceId() throws Exception {
|
||||
TestPropertyValues.of("eureka.instance.instanceId=myinstance")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.instanceId=myinstance").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong")
|
||||
.isEqualTo("myinstance");
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomInstanceIdWithMetadata() throws Exception {
|
||||
TestPropertyValues.of("eureka.instance.metadataMap.instanceId=myinstance")
|
||||
.applyTo(this.context);
|
||||
TestPropertyValues.of("eureka.instance.metadataMap.instanceId=myinstance").applyTo(this.context);
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong")
|
||||
.isEqualTo("myinstance");
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultInstanceId() throws Exception {
|
||||
setupContext();
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("default instance id is wrong")
|
||||
.isEqualTo(null);
|
||||
assertThat(getInstanceConfig().getInstanceId()).as("default instance id is wrong").isEqualTo(null);
|
||||
}
|
||||
|
||||
private void setupContext() {
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ public class EurekaServiceInstanceTests {
|
||||
|
||||
@Test
|
||||
public void getSchemeReturnsNonNull() {
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test")
|
||||
.setHostName("myhost").setPort(8080).build();
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test").setHostName("myhost")
|
||||
.setPort(8080).build();
|
||||
EurekaServiceInstance instance = new EurekaServiceInstance(instanceInfo);
|
||||
Assertions.assertThat(instance.getScheme()).isEqualTo("http");
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ public class InstanceInfoFactoryTests {
|
||||
public void instanceIdIsHostNameByDefault() throws IOException {
|
||||
InstanceInfo instanceInfo = setupInstance();
|
||||
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
|
||||
assertThat(instanceInfo.getId())
|
||||
.isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
|
||||
assertThat(instanceInfo.getId()).isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +59,7 @@ public class InstanceInfoFactoryTests {
|
||||
private InstanceInfo setupInstance(String... pairs) {
|
||||
TestPropertyValues.of(pairs).applyTo(this.context);
|
||||
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TestConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
EurekaInstanceConfigBean instanceConfig = getInstanceConfig();
|
||||
|
||||
@@ -35,8 +35,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT,
|
||||
classes = RefreshEurekaSampleApplication.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = RefreshEurekaSampleApplication.class)
|
||||
public class ConfigRefreshTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -34,46 +34,34 @@ public class EurekaClientConfigServerAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void offByDefault() {
|
||||
new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class))
|
||||
.run(c -> {
|
||||
assertThat(
|
||||
c.getBeanNamesForType(EurekaInstanceConfigBean.class).length)
|
||||
.isEqualTo(0);
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class)).run(c -> {
|
||||
assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWhenRequested() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EurekaClientConfigServerAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
|
||||
ConfigServerProperties.class, EurekaInstanceConfigBean.class))
|
||||
.withPropertyValues("spring.cloud.config.server.prefix=/config")
|
||||
.run(c -> {
|
||||
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length)
|
||||
.isEqualTo(1);
|
||||
.withPropertyValues("spring.cloud.config.server.prefix=/config").run(c -> {
|
||||
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1);
|
||||
EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class);
|
||||
assertThat(instance.getMetadataMap().get("configPath"))
|
||||
.isEqualTo("/config");
|
||||
assertThat(instance.getMetadataMap().get("configPath")).isEqualTo("/config");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notOverridingMetamapSettings() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EurekaClientConfigServerAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
|
||||
ConfigServerProperties.class, EurekaInstanceConfigBean.class))
|
||||
.withPropertyValues("spring.cloud.config.server.prefix=/config")
|
||||
.withPropertyValues(
|
||||
"eureka.instance.metadataMap.configPath=/differentpath")
|
||||
.run(c -> {
|
||||
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length)
|
||||
.isEqualTo(1);
|
||||
.withPropertyValues("eureka.instance.metadataMap.configPath=/differentpath").run(c -> {
|
||||
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1);
|
||||
EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class);
|
||||
assertThat(instance.getMetadataMap().get("configPath"))
|
||||
.isEqualTo("/differentpath");
|
||||
assertThat(instance.getMetadataMap().get("configPath")).isEqualTo("/differentpath");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -61,44 +61,36 @@ public class EurekaConfigServerBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void offByDefault() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
|
||||
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
|
||||
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properBeansCreatedWhenEnabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true")
|
||||
.run(context -> {
|
||||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
|
||||
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eurekaDnsConfigurationWorks() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
|
||||
"eureka.instance.hostname=eurekaclient1",
|
||||
"eureka.client.use-dns-for-fetching-service-urls=true",
|
||||
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
|
||||
"eureka.client.eureka-server-u-r-l-context=eureka",
|
||||
"eureka.client.eureka-server-port=30000")
|
||||
"eureka.client.eureka-server-u-r-l-context=eureka", "eureka.client.eureka-server-port=30000")
|
||||
.run(context -> {
|
||||
assertThat(output).contains(
|
||||
"Cannot get cnames bound to the region:txt.us-east-1.myeurekahost");
|
||||
assertThat(output).contains("Cannot get cnames bound to the region:txt.us-east-1.myeurekahost");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,17 +98,13 @@ public class EurekaConfigServerBootstrapConfigurationTests {
|
||||
public void eurekaConfigServerInstanceProviderCalled() {
|
||||
// FIXME: why do I need to do this? (fails in maven build without it.
|
||||
TomcatURLStreamHandlerFactory.disable();
|
||||
new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class).properties(
|
||||
"spring.config.use-legacy-processing=true",
|
||||
"spring.cloud.config.discovery.enabled=true",
|
||||
"spring.main.sources="
|
||||
+ TestConfigDiscoveryBootstrapConfiguration.class.getName(),
|
||||
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
|
||||
new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
|
||||
.properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
|
||||
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
|
||||
.run();
|
||||
assertThat(output).contains(
|
||||
"eurekaConfigServerInstanceProvider finding instances for configserver")
|
||||
.contains(
|
||||
"eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
|
||||
assertThat(output).contains("eurekaConfigServerInstanceProvider finding instances for configserver")
|
||||
.contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@@ -136,13 +124,11 @@ public class EurekaConfigServerBootstrapConfigurationTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Bean
|
||||
public EurekaHttpClient mockEurekaHttpClient() {
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
|
||||
.setAppName("configserver").build();
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("configserver").build();
|
||||
List<InstanceInfo> instanceInfos = Collections.singletonList(instanceInfo);
|
||||
|
||||
Applications applications = mock(Applications.class);
|
||||
when(applications.getInstancesByVirtualHostName("configserver"))
|
||||
.thenReturn(instanceInfos);
|
||||
when(applications.getInstancesByVirtualHostName("configserver")).thenReturn(instanceInfos);
|
||||
|
||||
EurekaHttpResponse<Applications> response = mock(EurekaHttpResponse.class);
|
||||
when(response.getStatusCode()).thenReturn(200);
|
||||
|
||||
@@ -38,10 +38,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootTest(properties = { "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.config.use-legacy-processing=true",
|
||||
"eureka.client.webclient.enabled=true",
|
||||
"spring.codec.max-in-memory-size=310000" }, webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(
|
||||
properties = { "spring.cloud.config.discovery.enabled=true", "spring.config.use-legacy-processing=true",
|
||||
"eureka.client.webclient.enabled=true", "spring.codec.max-in-memory-size=310000" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -53,12 +53,10 @@ public class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
|
||||
@Test
|
||||
public void webClientRespectsCodecProperties() {
|
||||
WebClient webClient = eurekaHttpClient.getWebClient();
|
||||
ClientResponse response = webClient.get().uri("http://localhost:" + port)
|
||||
.exchange().block();
|
||||
ClientResponse response = webClient.get().uri("http://localhost:" + port).exchange().block();
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.bodyToMono(String.class).block()).startsWith("....")
|
||||
.hasSize(300000);
|
||||
assertThat(response.bodyToMono(String.class).block()).startsWith("....").hasSize(300000);
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
@@ -35,30 +35,25 @@ public class EurekaConfigServerBootstrapConfigurationWebClientTests {
|
||||
@Test
|
||||
public void properBeansCreatedWhenEnabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
|
||||
"eureka.client.webclient.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
|
||||
assertThat(context).hasSingleBean(WebClientEurekaHttpClient.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properBeansCreatedWhenEnabledWebClientDisabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true")
|
||||
.run(context -> {
|
||||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
|
||||
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class);
|
||||
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,8 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @author Daniel Lavoie
|
||||
*/
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*",
|
||||
"spring-webflux-*" })
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*", "spring-webflux-*" })
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,45 +35,33 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
*/
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*" })
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class EurekaHttpClientsOptionalArgsConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoadsWithRestTemplate() {
|
||||
new WebApplicationContextRunner()
|
||||
.withUserConfiguration(EurekaSampleApplication.class)
|
||||
.withPropertyValues("eureka.client.webclient.enabled=false")
|
||||
.run(context -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
new WebApplicationContextRunner().withUserConfiguration(EurekaSampleApplication.class)
|
||||
.withPropertyValues("eureka.client.webclient.enabled=false").run(context -> {
|
||||
assertThat(context).hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context).doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextLoadsWithWebClient() {
|
||||
new WebApplicationContextRunner()
|
||||
.withUserConfiguration(EurekaSampleApplication.class)
|
||||
.withPropertyValues("eureka.client.webclient.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(
|
||||
RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
new WebApplicationContextRunner().withUserConfiguration(EurekaSampleApplication.class)
|
||||
.withPropertyValues("eureka.client.webclient.enabled=true").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context).hasSingleBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextLoadsWithRestTemplateAsDefault() {
|
||||
new WebApplicationContextRunner()
|
||||
.withUserConfiguration(EurekaSampleApplication.class).run(context -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
});
|
||||
new WebApplicationContextRunner().withUserConfiguration(EurekaSampleApplication.class).run(context -> {
|
||||
assertThat(context).hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context).doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class JerseyOptionalArgsConfigurationTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -41,8 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaHealthCheckTests.EurekaHealthCheckApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
value = { "eureka.client.healthcheck.enabled=true", "debug=true" })
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT, value = { "eureka.client.healthcheck.enabled=true", "debug=true" })
|
||||
@DirtiesContext
|
||||
public class EurekaHealthCheckTests {
|
||||
|
||||
|
||||
@@ -38,39 +38,36 @@ public abstract class AbstractEurekaHttpClientTest {
|
||||
|
||||
@Test
|
||||
public void testRegister() {
|
||||
assertThat(eurekaHttpClient.register(info).getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(eurekaHttpClient.register(info).getStatusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancel() {
|
||||
assertThat(eurekaHttpClient.cancel("test", "test").getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(eurekaHttpClient.cancel("test", "test").getStatusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendHeartBeat() {
|
||||
assertThat(eurekaHttpClient.sendHeartBeat("test", "test", info, null)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(eurekaHttpClient.sendHeartBeat("test", "test", info, null).getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendHeartBeatFourOFour() {
|
||||
assertThat(eurekaHttpClient.sendHeartBeat("fourOFour", "test", info, null)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(eurekaHttpClient.sendHeartBeat("fourOFour", "test", info, null).getStatusCode())
|
||||
.isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusUpdate() {
|
||||
assertThat(eurekaHttpClient
|
||||
.statusUpdate("test", "test", InstanceInfo.InstanceStatus.UP, info)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(eurekaHttpClient.statusUpdate("test", "test", InstanceInfo.InstanceStatus.UP, info).getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteStatusOverride() {
|
||||
assertThat(eurekaHttpClient.deleteStatusOverride("test", "test", info)
|
||||
.getStatusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(eurekaHttpClient.deleteStatusOverride("test", "test", info).getStatusCode())
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -63,35 +63,26 @@ import static org.springframework.util.Assert.isTrue;
|
||||
@SpringBootApplication
|
||||
public class EurekaServerMockApplication {
|
||||
|
||||
private static final InstanceInfo INFO = InstanceInfo.Builder.newBuilder()
|
||||
.setInstanceId("app1instance1").setAppName("app1")
|
||||
.setAppNameForDeser("app1fordeser").setAppGroupName("app1group")
|
||||
private static final InstanceInfo INFO = InstanceInfo.Builder.newBuilder().setInstanceId("app1instance1")
|
||||
.setAppName("app1").setAppNameForDeser("app1fordeser").setAppGroupName("app1group")
|
||||
.setAppGroupNameForDeser("app1group1fordeser").setHostName("app1host1")
|
||||
.setStatus(InstanceInfo.InstanceStatus.UP)
|
||||
.setOverriddenStatus(InstanceInfo.InstanceStatus.DOWN).setIPAddr("127.0.0.1")
|
||||
.setSID("app1sid").setPort(8080).setSecurePort(4443)
|
||||
.enablePort(InstanceInfo.PortType.UNSECURE, true)
|
||||
.setHomePageUrl("/", "http://localhost/")
|
||||
.setHomePageUrlForDeser("http://localhost/")
|
||||
.setStatusPageUrl("/status", "http://localhost/info")
|
||||
.setStatus(InstanceInfo.InstanceStatus.UP).setOverriddenStatus(InstanceInfo.InstanceStatus.DOWN)
|
||||
.setIPAddr("127.0.0.1").setSID("app1sid").setPort(8080).setSecurePort(4443)
|
||||
.enablePort(InstanceInfo.PortType.UNSECURE, true).setHomePageUrl("/", "http://localhost/")
|
||||
.setHomePageUrlForDeser("http://localhost/").setStatusPageUrl("/status", "http://localhost/info")
|
||||
.setStatusPageUrlForDeser("http://localhost/status")
|
||||
.setHealthCheckUrls("/ping", "http://localhost/ping", null)
|
||||
.setHealthCheckUrlsForDeser("http://localhost/ping", null)
|
||||
.setVIPAddress("localhost:8080").setVIPAddressDeser("localhost:8080")
|
||||
.setSecureVIPAddress("localhost:4443")
|
||||
.setHealthCheckUrlsForDeser("http://localhost/ping", null).setVIPAddress("localhost:8080")
|
||||
.setVIPAddressDeser("localhost:8080").setSecureVIPAddress("localhost:4443")
|
||||
.setSecureVIPAddressDeser("localhost:4443")
|
||||
.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
|
||||
.setLeaseInfo(LeaseInfo.Builder.newBuilder().setDurationInSecs(30)
|
||||
.setRenewalIntervalInSecs(30)
|
||||
.setLeaseInfo(LeaseInfo.Builder.newBuilder().setDurationInSecs(30).setRenewalIntervalInSecs(30)
|
||||
.setEvictionTimestamp(System.currentTimeMillis() + 30000)
|
||||
.setRenewalTimestamp(System.currentTimeMillis() - 1000)
|
||||
.setRegistrationTimestamp(System.currentTimeMillis() - 2000).build())
|
||||
.add("metadatakey1", "metadatavalue1").setASGName("asg1")
|
||||
.setIsCoordinatingDiscoveryServer(false)
|
||||
.setLastUpdatedTimestamp(System.currentTimeMillis())
|
||||
.setLastDirtyTimestamp(System.currentTimeMillis())
|
||||
.setActionType(InstanceInfo.ActionType.ADDED).setNamespace("namespace1")
|
||||
.build();
|
||||
.add("metadatakey1", "metadatavalue1").setASGName("asg1").setIsCoordinatingDiscoveryServer(false)
|
||||
.setLastUpdatedTimestamp(System.currentTimeMillis()).setLastDirtyTimestamp(System.currentTimeMillis())
|
||||
.setActionType(InstanceInfo.ActionType.ADDED).setNamespace("namespace1").build();
|
||||
|
||||
/**
|
||||
* Simulates Eureka Server own's serialization.
|
||||
@@ -99,18 +90,14 @@ public class EurekaServerMockApplication {
|
||||
*/
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
|
||||
return new RestTemplateTransportClientFactory()
|
||||
.mappingJacksonHttpMessageConverter();
|
||||
return new RestTemplateTransportClientFactory().mappingJacksonHttpMessageConverter();
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PostMapping("/apps/{appName}")
|
||||
public void register(@PathVariable String appName,
|
||||
@RequestBody InstanceInfo instanceInfo) {
|
||||
isTrue(instanceInfo.getPort() != DEFAULT_PORT && instanceInfo.getPort() != 0,
|
||||
"Port not received from client");
|
||||
isTrue(instanceInfo.getSecurePort() != DEFAULT_SECURE_PORT
|
||||
&& instanceInfo.getSecurePort() != 0,
|
||||
public void register(@PathVariable String appName, @RequestBody InstanceInfo instanceInfo) {
|
||||
isTrue(instanceInfo.getPort() != DEFAULT_PORT && instanceInfo.getPort() != 0, "Port not received from client");
|
||||
isTrue(instanceInfo.getSecurePort() != DEFAULT_SECURE_PORT && instanceInfo.getSecurePort() != 0,
|
||||
"Secure Port not received from client");
|
||||
// Nothing to do
|
||||
}
|
||||
@@ -122,32 +109,29 @@ public class EurekaServerMockApplication {
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PutMapping(value = "/apps/{appName}/{id}",
|
||||
params = { "status", "lastDirtyTimestamp" })
|
||||
public ResponseEntity sendHeartBeat(@PathVariable String appName,
|
||||
@PathVariable String id, @RequestParam String status,
|
||||
@RequestParam String lastDirtyTimestamp,
|
||||
@PutMapping(value = "/apps/{appName}/{id}", params = { "status", "lastDirtyTimestamp" })
|
||||
public ResponseEntity sendHeartBeat(@PathVariable String appName, @PathVariable String id,
|
||||
@RequestParam String status, @RequestParam String lastDirtyTimestamp,
|
||||
@RequestParam(required = false) String overriddenstatus) {
|
||||
if ("fourOFour".equals(appName)) {
|
||||
return new ResponseEntity(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(new InstanceInfo(null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, 0, null, null, null, null, null,
|
||||
null, null, new HashMap<>(), 0L, 0L, null, null), HttpStatus.OK);
|
||||
return new ResponseEntity<>(new InstanceInfo(null, null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, 0, null, null, null, null, null, null, null, new HashMap<>(), 0L, 0L, null, null),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PutMapping(value = "/apps/{appName}/{id}/status",
|
||||
params = { "value", "lastDirtyTimestamp" })
|
||||
public void statusUpdate(@PathVariable String appName, @PathVariable String id,
|
||||
@RequestParam String value, @RequestParam String lastDirtyTimestamp) {
|
||||
@PutMapping(value = "/apps/{appName}/{id}/status", params = { "value", "lastDirtyTimestamp" })
|
||||
public void statusUpdate(@PathVariable String appName, @PathVariable String id, @RequestParam String value,
|
||||
@RequestParam String lastDirtyTimestamp) {
|
||||
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@DeleteMapping(value = "/apps/{appName}/{id}/status", params = "lastDirtyTimestamp")
|
||||
public void deleteStatusOverride(@PathVariable String appName,
|
||||
@PathVariable String id, @RequestParam String lastDirtyTimestamp) {
|
||||
public void deleteStatusOverride(@PathVariable String appName, @PathVariable String id,
|
||||
@RequestParam String lastDirtyTimestamp) {
|
||||
|
||||
}
|
||||
|
||||
@@ -155,8 +139,7 @@ public class EurekaServerMockApplication {
|
||||
public Applications getApplications(@PathVariable(required = false) String address,
|
||||
@RequestParam(required = false) String regions) {
|
||||
Applications applications = new Applications();
|
||||
applications
|
||||
.addApplication(new Application("app1", Collections.singletonList(INFO)));
|
||||
applications.addApplication(new Application("app1", Collections.singletonList(INFO)));
|
||||
return applications;
|
||||
}
|
||||
|
||||
@@ -166,15 +149,13 @@ public class EurekaServerMockApplication {
|
||||
}
|
||||
|
||||
@GetMapping({ "/apps/{appName}/{id}", "/instances/{id}" })
|
||||
public InstanceInfo getInstance(@PathVariable(required = false) String appName,
|
||||
@PathVariable String id) {
|
||||
public InstanceInfo getInstance(@PathVariable(required = false) String appName, @PathVariable String id) {
|
||||
return INFO;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
protected static class TestSecurityConfiguration
|
||||
extends WebSecurityConfigurerAdapter {
|
||||
protected static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
TestSecurityConfiguration() {
|
||||
super(true);
|
||||
@@ -183,8 +164,7 @@ public class EurekaServerMockApplication {
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(User.withUsername("test").password("{noop}test")
|
||||
.roles("USER").build());
|
||||
manager.createUser(User.withUsername("test").password("{noop}test").roles("USER").build());
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaServerMockApplication.class,
|
||||
properties = { "debug=true", "security.basic.enabled=true" },
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
properties = { "debug=true", "security.basic.enabled=true" }, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
|
||||
|
||||
@@ -48,8 +47,7 @@ public class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTe
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
eurekaHttpClient = new RestTemplateTransportClientFactory()
|
||||
.newClient(new DefaultEndpoint(serviceUrl));
|
||||
eurekaHttpClient = new RestTemplateTransportClientFactory().newClient(new DefaultEndpoint(serviceUrl));
|
||||
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
|
||||
|
||||
|
||||
@@ -40,14 +40,12 @@ public class RestTemplateTransportClientFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testInvalidUserInfo() {
|
||||
transportClientFatory
|
||||
.newClient(new DefaultEndpoint("http://test@localhost:8761"));
|
||||
transportClientFatory.newClient(new DefaultEndpoint("http://test@localhost:8761"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfo() {
|
||||
transportClientFatory
|
||||
.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
|
||||
transportClientFatory.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaServerMockApplication.class,
|
||||
properties = { "debug=true", "security.basic.enabled=true",
|
||||
"eureka.client.webclient.enabled=true" },
|
||||
properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true" },
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
|
||||
|
||||
@@ -27,8 +27,7 @@ public class WebClientTransportClientFactoriesTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testJerseyIsUnsuported() {
|
||||
new WebClientTransportClientFactories(WebClient::builder)
|
||||
.newTransportClientFactory(null, null);
|
||||
new WebClientTransportClientFactories(WebClient::builder).newTransportClientFactory(null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,14 +42,12 @@ public class WebClientTransportClientFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testInvalidUserInfo() {
|
||||
transportClientFatory
|
||||
.newClient(new DefaultEndpoint("http://test@localhost:8761"));
|
||||
transportClientFatory.newClient(new DefaultEndpoint("http://test@localhost:8761"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfo() {
|
||||
transportClientFatory
|
||||
.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
|
||||
transportClientFatory.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -45,8 +45,7 @@ class EurekaLoadBalancerClientConfigurationTests {
|
||||
private EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties();
|
||||
|
||||
private EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration(
|
||||
eurekaClientConfig, eurekaInstanceConfig, zoneConfig,
|
||||
eurekaLoadBalancerProperties);
|
||||
eurekaClientConfig, eurekaInstanceConfig, zoneConfig, eurekaLoadBalancerProperties);
|
||||
|
||||
@Test
|
||||
void shouldSetZoneFromInstanceMetadata() {
|
||||
@@ -77,11 +76,9 @@ class EurekaLoadBalancerClientConfigurationTests {
|
||||
@Test
|
||||
public void disabledViaProperty() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(LoadBalancerEurekaAutoConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(LoadBalancerEurekaAutoConfiguration.class))
|
||||
.withPropertyValues("eureka.client.enabled=false").run(context -> {
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(EurekaLoadBalancerProperties.class);
|
||||
assertThat(context).doesNotHaveBean(EurekaLoadBalancerProperties.class);
|
||||
assertThat(context).doesNotHaveBean(LoadBalancerZoneConfig.class);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class DefaultManagementMetadataProviderTest {
|
||||
|
||||
private static final EurekaInstanceConfigBean INSTANCE = mock(
|
||||
EurekaInstanceConfigBean.class);
|
||||
private static final EurekaInstanceConfigBean INSTANCE = mock(EurekaInstanceConfigBean.class);
|
||||
|
||||
private final ManagementMetadataProvider provider = new DefaultManagementMetadataProvider();
|
||||
|
||||
@@ -47,8 +46,8 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = null;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual).isNull();
|
||||
}
|
||||
@@ -59,8 +58,8 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = 0;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual).isNull();
|
||||
}
|
||||
@@ -71,8 +70,8 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = null;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
@@ -86,8 +85,8 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = 8888;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:8888/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
@@ -101,8 +100,8 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/Server";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = 8888;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:8888/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
@@ -111,20 +110,17 @@ public class DefaultManagementMetadataProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverPortManagementPortServerContextPathManagementContextPath()
|
||||
throws Exception {
|
||||
public void serverPortManagementPortServerContextPathManagementContextPath() throws Exception {
|
||||
int serverPort = 7777;
|
||||
String serverContextPath = "/Server";
|
||||
String managementContextPath = "/Management";
|
||||
Integer managementPort = 8888;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
assertThat(actual.getStatusPageUrl())
|
||||
.isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(8888);
|
||||
}
|
||||
|
||||
@@ -134,14 +130,12 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/Server";
|
||||
String managementContextPath = "/Management";
|
||||
Integer managementPort = null;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:7777/Server/Management/health");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/Server/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
assertThat(actual.getStatusPageUrl())
|
||||
.isEqualTo("http://host:7777/Server/Management/info");
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:7777/Server/Management/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(7777);
|
||||
}
|
||||
|
||||
@@ -151,14 +145,12 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = "/Management";
|
||||
Integer managementPort = null;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:7777/Management/health");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
assertThat(actual.getStatusPageUrl())
|
||||
.isEqualTo("http://host:7777/Management/info");
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:7777/Management/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(7777);
|
||||
}
|
||||
|
||||
@@ -168,11 +160,10 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/Server";
|
||||
String managementContextPath = null;
|
||||
Integer managementPort = null;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:7777/Server/health");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/Server/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:7777/Server/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(7777);
|
||||
@@ -184,14 +175,12 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String serverContextPath = "/";
|
||||
String managementContextPath = "/Management";
|
||||
Integer managementPort = 8888;
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
|
||||
assertThat(actual.getStatusPageUrl())
|
||||
.isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(8888);
|
||||
|
||||
}
|
||||
@@ -203,15 +192,12 @@ public class DefaultManagementMetadataProviderTest {
|
||||
String managementContextPath = "/Management";
|
||||
Integer managementPort = 8888;
|
||||
doReturn(true).when(INSTANCE).isSecurePortEnabled();
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath,
|
||||
managementContextPath, managementPort);
|
||||
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath,
|
||||
managementPort);
|
||||
|
||||
assertThat(actual.getHealthCheckUrl())
|
||||
.isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl())
|
||||
.isEqualTo("https://host:8888/Management/health");
|
||||
assertThat(actual.getStatusPageUrl())
|
||||
.isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:8888/Management/health");
|
||||
assertThat(actual.getSecureHealthCheckUrl()).isEqualTo("https://host:8888/Management/health");
|
||||
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:8888/Management/info");
|
||||
assertThat(actual.getManagementPort()).isEqualTo(8888);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,71 +37,55 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
||||
ReactiveCommonsClientAutoConfiguration.class,
|
||||
EurekaClientAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class,
|
||||
EurekaReactiveDiscoveryClientConfiguration.class));
|
||||
ReactiveCommonsClientAutoConfiguration.class, EurekaClientAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class, EurekaReactiveDiscoveryClientConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithDefaults() {
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
|
||||
contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false")
|
||||
.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(
|
||||
ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
|
||||
contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false")
|
||||
.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(
|
||||
ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenEurekaClientDisabled() {
|
||||
contextRunner.withPropertyValues("eureka.client.enabled=false").run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worksWithoutWebflux() {
|
||||
contextRunner
|
||||
.withClassLoader(
|
||||
new FilteredClassLoader("org.springframework.web.reactive"))
|
||||
.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(
|
||||
ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.web.reactive")).run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worksWithoutActuator() {
|
||||
contextRunner
|
||||
.withClassLoader(
|
||||
new FilteredClassLoader("org.springframework.boot.actuate"))
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(
|
||||
ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ class EurekaReactiveDiscoveryClientTests {
|
||||
|
||||
@Test
|
||||
public void verifyDefaults() {
|
||||
assertThat(client.description())
|
||||
.isEqualTo("Spring Cloud Eureka Reactive Discovery Client");
|
||||
assertThat(client.description()).isEqualTo("Spring Cloud Eureka Reactive Discovery Client");
|
||||
assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER);
|
||||
}
|
||||
|
||||
@@ -64,10 +63,8 @@ class EurekaReactiveDiscoveryClientTests {
|
||||
public void verifyDefaultsWhenUsingEurekaClientConfigBean() {
|
||||
EurekaClientConfigBean configBean = new EurekaClientConfigBean();
|
||||
configBean.setOrder(1);
|
||||
EurekaReactiveDiscoveryClient client = new EurekaReactiveDiscoveryClient(
|
||||
eurekaClient, configBean);
|
||||
assertThat(client.description())
|
||||
.isEqualTo("Spring Cloud Eureka Reactive Discovery Client");
|
||||
EurekaReactiveDiscoveryClient client = new EurekaReactiveDiscoveryClient(eurekaClient, configBean);
|
||||
assertThat(client.description()).isEqualTo("Spring Cloud Eureka Reactive Discovery Client");
|
||||
assertThat(client.getOrder()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -91,9 +88,8 @@ class EurekaReactiveDiscoveryClientTests {
|
||||
public void shouldReturnFluxOfServices() {
|
||||
Applications applications = new Applications();
|
||||
Application app = new Application("my-service");
|
||||
app.addInstance(new InstanceInfo("instance", "my-service", "", "127.0.0.1", "",
|
||||
null, null, "", "", "", "", "", "", 0, null, "", null, null, null, null,
|
||||
null, null, null, null, null, null));
|
||||
app.addInstance(new InstanceInfo("instance", "my-service", "", "127.0.0.1", "", null, null, "", "", "", "", "",
|
||||
"", 0, null, "", null, null, null, null, null, null, null, null, null, null));
|
||||
applications.addApplication(app);
|
||||
when(eurekaClient.getApplications()).thenReturn(applications);
|
||||
Flux<String> services = this.client.getServices();
|
||||
@@ -102,19 +98,17 @@ class EurekaReactiveDiscoveryClientTests {
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyFluxForNonExistingService() {
|
||||
when(eurekaClient.getInstancesByVipAddress("nonexistent-service", false))
|
||||
.thenReturn(emptyList());
|
||||
when(eurekaClient.getInstancesByVipAddress("nonexistent-service", false)).thenReturn(emptyList());
|
||||
Flux<ServiceInstance> instances = this.client.getInstances("nonexistent-service");
|
||||
StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFluxOfServiceInstances() {
|
||||
InstanceInfo instanceInfo = new InstanceInfo(new InstanceInfo("instance",
|
||||
"my-service", "", "127.0.0.1", "", null, null, "", "", "", "", "", "", 0,
|
||||
null, "", null, null, null, null, null, null, null, null, null, null));
|
||||
when(eurekaClient.getInstancesByVipAddress("my-service", false))
|
||||
.thenReturn(singletonList(instanceInfo));
|
||||
InstanceInfo instanceInfo = new InstanceInfo(
|
||||
new InstanceInfo("instance", "my-service", "", "127.0.0.1", "", null, null, "", "", "", "", "", "", 0,
|
||||
null, "", null, null, null, null, null, null, null, null, null, null));
|
||||
when(eurekaClient.getInstancesByVipAddress("my-service", false)).thenReturn(singletonList(instanceInfo));
|
||||
Flux<ServiceInstance> instances = this.client.getInstances("my-service");
|
||||
StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class,
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class ApplicationTests {
|
||||
|
||||
|
||||
@@ -90,8 +90,7 @@ public class EurekaSampleApplication implements ApplicationContextAware, Closeab
|
||||
config.setNonSecurePort(4444);
|
||||
config.setInstanceId("127.0.0.1:customapp:4444");
|
||||
|
||||
this.registration = EurekaRegistration.builder(config)
|
||||
.with(this.clientConfig, this.context).build();
|
||||
this.registration = EurekaRegistration.builder(config).with(this.clientConfig, this.context).build();
|
||||
|
||||
this.serviceRegistry.register(this.registration);
|
||||
return config.getInstanceId();
|
||||
|
||||
@@ -48,16 +48,13 @@ public class EurekaServiceRegistryTests {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
|
||||
ApplicationInfoManager applicationInfoManager = mock(
|
||||
ApplicationInfoManager.class);
|
||||
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
|
||||
|
||||
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
|
||||
|
||||
EurekaRegistration registration = EurekaRegistration
|
||||
.builder(new EurekaInstanceConfigBean(
|
||||
new InetUtils(new InetUtilsProperties())))
|
||||
.with(eurekaClient).with(applicationInfoManager)
|
||||
.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
.builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient)
|
||||
.with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
.build();
|
||||
|
||||
registry.deregister(registration);
|
||||
@@ -69,29 +66,24 @@ public class EurekaServiceRegistryTests {
|
||||
public void eurekaClientGetStatus() {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
|
||||
new InetUtils(new InetUtilsProperties()));
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
|
||||
config.setAppname("myapp");
|
||||
config.setInstanceId("1234");
|
||||
|
||||
InstanceInfo local = InstanceInfo.Builder.newBuilder().setAppName("myapp")
|
||||
.setInstanceId("1234").setStatus(DOWN).build();
|
||||
|
||||
InstanceInfo remote = InstanceInfo.Builder.newBuilder().setAppName("myapp")
|
||||
.setInstanceId("1234").setStatus(DOWN).setOverriddenStatus(OUT_OF_SERVICE)
|
||||
InstanceInfo local = InstanceInfo.Builder.newBuilder().setAppName("myapp").setInstanceId("1234").setStatus(DOWN)
|
||||
.build();
|
||||
|
||||
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
|
||||
when(eurekaClient.getInstanceInfo(local.getAppName(), local.getId()))
|
||||
.thenReturn(remote);
|
||||
InstanceInfo remote = InstanceInfo.Builder.newBuilder().setAppName("myapp").setInstanceId("1234")
|
||||
.setStatus(DOWN).setOverriddenStatus(OUT_OF_SERVICE).build();
|
||||
|
||||
ApplicationInfoManager applicationInfoManager = mock(
|
||||
ApplicationInfoManager.class);
|
||||
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
|
||||
when(eurekaClient.getInstanceInfo(local.getAppName(), local.getId())).thenReturn(remote);
|
||||
|
||||
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
|
||||
when(applicationInfoManager.getInfo()).thenReturn(local);
|
||||
|
||||
EurekaRegistration registration = EurekaRegistration.builder(config)
|
||||
.with(eurekaClient).with(applicationInfoManager)
|
||||
.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
EurekaRegistration registration = EurekaRegistration.builder(config).with(eurekaClient)
|
||||
.with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
.build();
|
||||
|
||||
Object status = registry.getStatus(registration);
|
||||
@@ -102,16 +94,15 @@ public class EurekaServiceRegistryTests {
|
||||
|
||||
Map<Object, Object> map = (Map<Object, Object>) status;
|
||||
|
||||
assertThat(map).hasSize(2).containsEntry("status", DOWN.toString())
|
||||
.containsEntry("overriddenStatus", OUT_OF_SERVICE.toString());
|
||||
assertThat(map).hasSize(2).containsEntry("status", DOWN.toString()).containsEntry("overriddenStatus",
|
||||
OUT_OF_SERVICE.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eurekaClientGetStatusNoInstance() {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
|
||||
new InetUtils(new InetUtilsProperties()));
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
|
||||
config.setAppname("myapp");
|
||||
config.setInstanceId("1234");
|
||||
|
||||
@@ -119,13 +110,11 @@ public class EurekaServiceRegistryTests {
|
||||
|
||||
when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);
|
||||
|
||||
ApplicationInfoManager applicationInfoManager = mock(
|
||||
ApplicationInfoManager.class);
|
||||
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
|
||||
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
|
||||
|
||||
EurekaRegistration registration = EurekaRegistration.builder(config)
|
||||
.with(eurekaClient).with(applicationInfoManager)
|
||||
.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
EurekaRegistration registration = EurekaRegistration.builder(config).with(eurekaClient)
|
||||
.with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
|
||||
.build();
|
||||
|
||||
Object status = registry.getStatus(registration);
|
||||
|
||||
@@ -30,9 +30,7 @@ public class ZoneUtilsTests {
|
||||
public void extractApproximateZoneTest() {
|
||||
assertThat("foo".equals(ZoneUtils.extractApproximateZone("foo"))).isTrue();
|
||||
assertThat("bar".equals(ZoneUtils.extractApproximateZone("foo.bar"))).isTrue();
|
||||
assertThat("world.foo.bar"
|
||||
.equals(ZoneUtils.extractApproximateZone("hello.world.foo.bar")))
|
||||
.isTrue();
|
||||
assertThat("world.foo.bar".equals(ZoneUtils.extractApproximateZone("hello.world.foo.bar"))).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,8 +89,7 @@ public class CloudJacksonJson extends LegacyJacksonJson {
|
||||
String instanceId = info.getMetadata().get("instanceId");
|
||||
if (StringUtils.hasText(instanceId)) {
|
||||
// backwards compatibility for Angel
|
||||
if (StringUtils.hasText(info.getHostName())
|
||||
&& !instanceId.startsWith(info.getHostName())) {
|
||||
if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) {
|
||||
instanceId = info.getHostName() + ":" + instanceId;
|
||||
}
|
||||
return new InstanceInfo.Builder(info).setInstanceId(instanceId).build();
|
||||
@@ -114,38 +113,33 @@ public class CloudJacksonJson extends LegacyJacksonJson {
|
||||
module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer());
|
||||
module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer());
|
||||
module.addSerializer(Application.class, new ApplicationSerializer());
|
||||
module.addSerializer(Applications.class, new ApplicationsSerializer(
|
||||
this.getVersionDeltaKey(), this.getAppHashCodeKey()));
|
||||
module.addSerializer(Applications.class,
|
||||
new ApplicationsSerializer(this.getVersionDeltaKey(), this.getAppHashCodeKey()));
|
||||
|
||||
// TODO: Watch if this causes problems
|
||||
// module.addDeserializer(DataCenterInfo.class,
|
||||
// new DataCenterInfoDeserializer());
|
||||
module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer());
|
||||
module.addDeserializer(InstanceInfo.class,
|
||||
new CloudInstanceInfoDeserializer(mapper));
|
||||
module.addDeserializer(Application.class,
|
||||
new ApplicationDeserializer(mapper));
|
||||
module.addDeserializer(Applications.class, new ApplicationsDeserializer(
|
||||
mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));
|
||||
module.addDeserializer(InstanceInfo.class, new CloudInstanceInfoDeserializer(mapper));
|
||||
module.addDeserializer(Application.class, new ApplicationDeserializer(mapper));
|
||||
module.addDeserializer(Applications.class,
|
||||
new ApplicationsDeserializer(mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));
|
||||
|
||||
mapper.registerModule(module);
|
||||
|
||||
HashMap<Class<?>, Supplier<ObjectReader>> readers = new HashMap<>();
|
||||
readers.put(InstanceInfo.class, () -> mapper.reader()
|
||||
.withType(InstanceInfo.class).withRootName("instance"));
|
||||
readers.put(Application.class, () -> mapper.reader()
|
||||
.withType(Application.class).withRootName("application"));
|
||||
readers.put(Applications.class, () -> mapper.reader()
|
||||
.withType(Applications.class).withRootName("applications"));
|
||||
readers.put(InstanceInfo.class,
|
||||
() -> mapper.reader().withType(InstanceInfo.class).withRootName("instance"));
|
||||
readers.put(Application.class,
|
||||
() -> mapper.reader().withType(Application.class).withRootName("application"));
|
||||
readers.put(Applications.class,
|
||||
() -> mapper.reader().withType(Applications.class).withRootName("applications"));
|
||||
setField("objectReaderByClass", readers);
|
||||
|
||||
HashMap<Class<?>, ObjectWriter> writers = new HashMap<>();
|
||||
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class)
|
||||
.withRootName("instance"));
|
||||
writers.put(Application.class, mapper.writer().withType(Application.class)
|
||||
.withRootName("application"));
|
||||
writers.put(Applications.class, mapper.writer().withType(Applications.class)
|
||||
.withRootName("applications"));
|
||||
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class).withRootName("instance"));
|
||||
writers.put(Application.class, mapper.writer().withType(Application.class).withRootName("application"));
|
||||
writers.put(Applications.class, mapper.writer().withType(Applications.class).withRootName("applications"));
|
||||
setField("objectWriterByClass", writers);
|
||||
|
||||
setField("mapper", mapper);
|
||||
@@ -162,8 +156,8 @@ public class CloudJacksonJson extends LegacyJacksonJson {
|
||||
static class CloudInstanceInfoSerializer extends InstanceInfoSerializer {
|
||||
|
||||
@Override
|
||||
public void serialize(final InstanceInfo info, JsonGenerator jgen,
|
||||
SerializerProvider provider) throws IOException {
|
||||
public void serialize(final InstanceInfo info, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
|
||||
InstanceInfo updated = updateIfNeeded(info);
|
||||
super.serialize(updated, jgen, provider);
|
||||
@@ -178,8 +172,7 @@ public class CloudJacksonJson extends LegacyJacksonJson {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceInfo deserialize(JsonParser jp, DeserializationContext context)
|
||||
throws IOException {
|
||||
public InstanceInfo deserialize(JsonParser jp, DeserializationContext context) throws IOException {
|
||||
InstanceInfo info = super.deserialize(jp, context);
|
||||
InstanceInfo updated = updateIfNeeded(info);
|
||||
return updated;
|
||||
|
||||
@@ -108,8 +108,7 @@ public class EurekaController {
|
||||
protected void populateBase(HttpServletRequest request, Map<String, Object> model) {
|
||||
model.put("time", new Date());
|
||||
model.put("basePath", "/");
|
||||
model.put("dashboardPath",
|
||||
this.dashboardPath.equals("/") ? "" : this.dashboardPath);
|
||||
model.put("dashboardPath", this.dashboardPath.equals("/") ? "" : this.dashboardPath);
|
||||
populateHeader(model);
|
||||
populateNavbar(request, model);
|
||||
}
|
||||
@@ -127,8 +126,7 @@ public class EurekaController {
|
||||
AmazonInfo amazonInfo = (AmazonInfo) info;
|
||||
model.put("amazonInfo", amazonInfo);
|
||||
model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId));
|
||||
model.put("availabilityZone",
|
||||
amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
|
||||
model.put("availabilityZone", amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone));
|
||||
model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId));
|
||||
}
|
||||
}
|
||||
@@ -143,8 +141,7 @@ public class EurekaController {
|
||||
|
||||
private void populateNavbar(HttpServletRequest request, Map<String, Object> model) {
|
||||
Map<String, String> replicas = new LinkedHashMap<>();
|
||||
List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes()
|
||||
.getPeerNodesView();
|
||||
List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
|
||||
for (PeerEurekaNode node : list) {
|
||||
try {
|
||||
URI uri = new URI(node.getServiceUrl());
|
||||
@@ -193,8 +190,7 @@ public class EurekaController {
|
||||
else {
|
||||
zoneCounts.put(zone, 1);
|
||||
}
|
||||
List<Pair<String, String>> list = instancesByStatus
|
||||
.computeIfAbsent(status, k -> new ArrayList<>());
|
||||
List<Pair<String, String>> list = instancesByStatus.computeIfAbsent(status, k -> new ArrayList<>());
|
||||
list.add(new Pair<>(id, url));
|
||||
}
|
||||
appData.put("amiCounts", amiCounts.entrySet());
|
||||
@@ -252,15 +248,12 @@ public class EurekaController {
|
||||
instanceMap.put("status", instanceInfo.getStatus().toString());
|
||||
if (instanceInfo.getDataCenterInfo().getName() == DataCenterInfo.Name.Amazon) {
|
||||
AmazonInfo info = (AmazonInfo) instanceInfo.getDataCenterInfo();
|
||||
instanceMap.put("availability-zone",
|
||||
info.get(AmazonInfo.MetaDataKey.availabilityZone));
|
||||
instanceMap.put("availability-zone", info.get(AmazonInfo.MetaDataKey.availabilityZone));
|
||||
instanceMap.put("public-ipv4", info.get(AmazonInfo.MetaDataKey.publicIpv4));
|
||||
instanceMap.put("instance-id", info.get(AmazonInfo.MetaDataKey.instanceId));
|
||||
instanceMap.put("public-hostname",
|
||||
info.get(AmazonInfo.MetaDataKey.publicHostname));
|
||||
instanceMap.put("public-hostname", info.get(AmazonInfo.MetaDataKey.publicHostname));
|
||||
instanceMap.put("ami-id", info.get(AmazonInfo.MetaDataKey.amiId));
|
||||
instanceMap.put("instance-type",
|
||||
info.get(AmazonInfo.MetaDataKey.instanceType));
|
||||
instanceMap.put("instance-type", info.get(AmazonInfo.MetaDataKey.instanceType));
|
||||
}
|
||||
model.put("instanceInfo", instanceMap);
|
||||
}
|
||||
@@ -268,16 +261,13 @@ public class EurekaController {
|
||||
protected void filterReplicas(Map<String, Object> model, StatusInfo statusInfo) {
|
||||
Map<String, String> applicationStats = statusInfo.getApplicationStats();
|
||||
if (applicationStats.get("registered-replicas").contains("@")) {
|
||||
applicationStats.put("registered-replicas",
|
||||
scrubBasicAuth(applicationStats.get("registered-replicas")));
|
||||
applicationStats.put("registered-replicas", scrubBasicAuth(applicationStats.get("registered-replicas")));
|
||||
}
|
||||
if (applicationStats.get("unavailable-replicas").contains("@")) {
|
||||
applicationStats.put("unavailable-replicas",
|
||||
scrubBasicAuth(applicationStats.get("unavailable-replicas")));
|
||||
applicationStats.put("unavailable-replicas", scrubBasicAuth(applicationStats.get("unavailable-replicas")));
|
||||
}
|
||||
if (applicationStats.get("available-replicas").contains("@")) {
|
||||
applicationStats.put("available-replicas",
|
||||
scrubBasicAuth(applicationStats.get("available-replicas")));
|
||||
applicationStats.put("available-replicas", scrubBasicAuth(applicationStats.get("available-replicas")));
|
||||
}
|
||||
model.put("applicationStats", applicationStats);
|
||||
}
|
||||
@@ -287,8 +277,7 @@ public class EurekaController {
|
||||
StringBuilder filteredUrls = new StringBuilder();
|
||||
for (String u : urls) {
|
||||
if (u.contains("@")) {
|
||||
filteredUrls.append(u, 0, u.indexOf("//") + 2)
|
||||
.append(u.substring(u.indexOf("@") + 1)).append(",");
|
||||
filteredUrls.append(u, 0, u.indexOf("//") + 2).append(u.substring(u.indexOf("@") + 1)).append(",");
|
||||
}
|
||||
else {
|
||||
filteredUrls.append(u).append(",");
|
||||
|
||||
@@ -77,16 +77,14 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(EurekaServerInitializerConfiguration.class)
|
||||
@ConditionalOnBean(EurekaServerMarkerConfiguration.Marker.class)
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class,
|
||||
InstanceRegistryProperties.class })
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class })
|
||||
@PropertySource("classpath:/eureka/server.properties")
|
||||
public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* List of packages containing Jersey resources required by the Eureka server.
|
||||
*/
|
||||
private static final String[] EUREKA_PACKAGES = new String[] {
|
||||
"com.netflix.discovery", "com.netflix.eureka" };
|
||||
private static final String[] EUREKA_PACKAGES = new String[] { "com.netflix.discovery", "com.netflix.eureka" };
|
||||
|
||||
@Autowired
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
@@ -110,13 +108,11 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public HasFeatures eurekaServerFeature() {
|
||||
return HasFeatures.namedFeature("Eureka Server",
|
||||
EurekaServerAutoConfiguration.class);
|
||||
return HasFeatures.namedFeature("Eureka Server", EurekaServerAutoConfiguration.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
|
||||
public EurekaController eurekaController() {
|
||||
return new EurekaController(this.applicationInfoManager);
|
||||
}
|
||||
@@ -138,8 +134,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
private static CodecWrapper getFullXml(EurekaServerConfig serverConfig) {
|
||||
CodecWrapper codec = CodecWrappers.getCodec(serverConfig.getXmlCodecName());
|
||||
return codec == null ? CodecWrappers.getCodec(CodecWrappers.XStreamXml.class)
|
||||
: codec;
|
||||
return codec == null ? CodecWrappers.getCodec(CodecWrappers.XStreamXml.class) : codec;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -149,39 +144,34 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(
|
||||
ServerCodecs serverCodecs) {
|
||||
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs) {
|
||||
this.eurekaClient.getApplications(); // force initialization
|
||||
return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig,
|
||||
serverCodecs, this.eurekaClient,
|
||||
return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig, serverCodecs, this.eurekaClient,
|
||||
this.instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
|
||||
this.instanceRegistryProperties.getDefaultOpenForTrafficCount());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry,
|
||||
ServerCodecs serverCodecs,
|
||||
public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry, ServerCodecs serverCodecs,
|
||||
ReplicationClientAdditionalFilters replicationClientAdditionalFilters) {
|
||||
return new RefreshablePeerEurekaNodes(registry, this.eurekaServerConfig,
|
||||
this.eurekaClientConfig, serverCodecs, this.applicationInfoManager,
|
||||
replicationClientAdditionalFilters);
|
||||
return new RefreshablePeerEurekaNodes(registry, this.eurekaServerConfig, this.eurekaClientConfig, serverCodecs,
|
||||
this.applicationInfoManager, replicationClientAdditionalFilters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs,
|
||||
PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes) {
|
||||
return new DefaultEurekaServerContext(this.eurekaServerConfig, serverCodecs,
|
||||
registry, peerEurekaNodes, this.applicationInfoManager);
|
||||
public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs, PeerAwareInstanceRegistry registry,
|
||||
PeerEurekaNodes peerEurekaNodes) {
|
||||
return new DefaultEurekaServerContext(this.eurekaServerConfig, serverCodecs, registry, peerEurekaNodes,
|
||||
this.applicationInfoManager);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry registry,
|
||||
EurekaServerContext serverContext) {
|
||||
return new EurekaServerBootstrap(this.applicationInfoManager,
|
||||
this.eurekaClientConfig, this.eurekaServerConfig, registry,
|
||||
serverContext);
|
||||
return new EurekaServerBootstrap(this.applicationInfoManager, this.eurekaClientConfig, this.eurekaServerConfig,
|
||||
registry, serverContext);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,13 +180,11 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
* @return a jersey {@link FilterRegistrationBean}
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean<?> jerseyFilterRegistration(
|
||||
javax.ws.rs.core.Application eurekaJerseyApp) {
|
||||
public FilterRegistrationBean<?> jerseyFilterRegistration(javax.ws.rs.core.Application eurekaJerseyApp) {
|
||||
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
|
||||
bean.setFilter(new ServletContainer(eurekaJerseyApp));
|
||||
bean.setOrder(Ordered.LOWEST_PRECEDENCE);
|
||||
bean.setUrlPatterns(
|
||||
Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*"));
|
||||
bean.setUrlPatterns(Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*"));
|
||||
|
||||
return bean;
|
||||
}
|
||||
@@ -209,11 +197,10 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
* @return created {@link Application} object
|
||||
*/
|
||||
@Bean
|
||||
public javax.ws.rs.core.Application jerseyApplication(Environment environment,
|
||||
ResourceLoader resourceLoader) {
|
||||
public javax.ws.rs.core.Application jerseyApplication(Environment environment, ResourceLoader resourceLoader) {
|
||||
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
|
||||
false, environment);
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false,
|
||||
environment);
|
||||
|
||||
// Filter to include only classes that have a particular annotation.
|
||||
//
|
||||
@@ -226,8 +213,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
for (String basePackage : EUREKA_PACKAGES) {
|
||||
Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage);
|
||||
for (BeanDefinition bd : beans) {
|
||||
Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(),
|
||||
resourceLoader.getClassLoader());
|
||||
Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(), resourceLoader.getClassLoader());
|
||||
classes.add(cls);
|
||||
}
|
||||
}
|
||||
@@ -247,8 +233,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(name = "httpTraceFilter")
|
||||
public FilterRegistrationBean<?> traceFilterRegistration(
|
||||
@Qualifier("httpTraceFilter") Filter filter) {
|
||||
public FilterRegistrationBean<?> traceFilterRegistration(@Qualifier("httpTraceFilter") Filter filter) {
|
||||
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
|
||||
bean.setFilter(filter);
|
||||
bean.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
|
||||
@@ -288,31 +273,26 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
private ReplicationClientAdditionalFilters replicationClientAdditionalFilters;
|
||||
|
||||
RefreshablePeerEurekaNodes(final PeerAwareInstanceRegistry registry,
|
||||
final EurekaServerConfig serverConfig,
|
||||
RefreshablePeerEurekaNodes(final PeerAwareInstanceRegistry registry, final EurekaServerConfig serverConfig,
|
||||
final EurekaClientConfig clientConfig, final ServerCodecs serverCodecs,
|
||||
final ApplicationInfoManager applicationInfoManager,
|
||||
final ReplicationClientAdditionalFilters replicationClientAdditionalFilters) {
|
||||
super(registry, serverConfig, clientConfig, serverCodecs,
|
||||
applicationInfoManager);
|
||||
super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager);
|
||||
this.replicationClientAdditionalFilters = replicationClientAdditionalFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) {
|
||||
JerseyReplicationClient replicationClient = JerseyReplicationClient
|
||||
.createReplicationClient(serverConfig, serverCodecs,
|
||||
peerEurekaNodeUrl);
|
||||
JerseyReplicationClient replicationClient = JerseyReplicationClient.createReplicationClient(serverConfig,
|
||||
serverCodecs, peerEurekaNodeUrl);
|
||||
|
||||
this.replicationClientAdditionalFilters.getFilters()
|
||||
.forEach(replicationClient::addReplicationClientFilter);
|
||||
this.replicationClientAdditionalFilters.getFilters().forEach(replicationClient::addReplicationClientFilter);
|
||||
|
||||
String targetHost = hostFromUrl(peerEurekaNodeUrl);
|
||||
if (targetHost == null) {
|
||||
targetHost = "host";
|
||||
}
|
||||
return new PeerEurekaNode(registry, targetHost, peerEurekaNodeUrl,
|
||||
replicationClient, serverConfig);
|
||||
return new PeerEurekaNode(registry, targetHost, peerEurekaNodeUrl, replicationClient, serverConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,10 +333,8 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
class CloudServerCodecs extends DefaultServerCodecs {
|
||||
|
||||
CloudServerCodecs(EurekaServerConfig serverConfig) {
|
||||
super(getFullJson(serverConfig),
|
||||
CodecWrappers.getCodec(CodecWrappers.JacksonJsonMini.class),
|
||||
getFullXml(serverConfig),
|
||||
CodecWrappers.getCodec(CodecWrappers.JacksonXmlMini.class));
|
||||
super(getFullJson(serverConfig), CodecWrappers.getCodec(CodecWrappers.JacksonJsonMini.class),
|
||||
getFullXml(serverConfig), CodecWrappers.getCodec(CodecWrappers.JacksonXmlMini.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ public class EurekaServerBootstrap {
|
||||
|
||||
protected volatile AwsBinder awsBinder;
|
||||
|
||||
public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager,
|
||||
EurekaClientConfig eurekaClientConfig, EurekaServerConfig eurekaServerConfig,
|
||||
PeerAwareInstanceRegistry registry, EurekaServerContext serverContext) {
|
||||
public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager, EurekaClientConfig eurekaClientConfig,
|
||||
EurekaServerConfig eurekaServerConfig, PeerAwareInstanceRegistry registry,
|
||||
EurekaServerContext serverContext) {
|
||||
this.applicationInfoManager = applicationInfoManager;
|
||||
this.eurekaClientConfig = eurekaClientConfig;
|
||||
this.eurekaServerConfig = eurekaServerConfig;
|
||||
@@ -100,14 +100,12 @@ public class EurekaServerBootstrap {
|
||||
|
||||
protected void initEurekaServerContext() throws Exception {
|
||||
// For backward compatibility
|
||||
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(),
|
||||
XStream.PRIORITY_VERY_HIGH);
|
||||
XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(),
|
||||
XStream.PRIORITY_VERY_HIGH);
|
||||
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
|
||||
XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
|
||||
|
||||
if (isAws(this.applicationInfoManager.getInfo())) {
|
||||
this.awsBinder = new AwsBinderDelegate(this.eurekaServerConfig,
|
||||
this.eurekaClientConfig, this.registry, this.applicationInfoManager);
|
||||
this.awsBinder = new AwsBinderDelegate(this.eurekaServerConfig, this.eurekaClientConfig, this.registry,
|
||||
this.applicationInfoManager);
|
||||
this.awsBinder.start();
|
||||
}
|
||||
|
||||
@@ -146,8 +144,7 @@ public class EurekaServerBootstrap {
|
||||
}
|
||||
|
||||
protected boolean isAws(InstanceInfo selfInstanceInfo) {
|
||||
boolean result = DataCenterInfo.Name.Amazon == selfInstanceInfo
|
||||
.getDataCenterInfo().getName();
|
||||
boolean result = DataCenterInfo.Name.Amazon == selfInstanceInfo.getDataCenterInfo().getName();
|
||||
log.info("isAws returned " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -234,8 +234,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
|
||||
@Override
|
||||
public Set<String> getRemoteRegionAppWhitelist(String regionName) {
|
||||
return this.remoteRegionAppWhitelist
|
||||
.get(regionName == null ? "global" : regionName.trim().toLowerCase());
|
||||
return this.remoteRegionAppWhitelist.get(regionName == null ? "global" : regionName.trim().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,8 +284,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
@Override
|
||||
public String getExperimental(String name) {
|
||||
if (this.propertyResolver != null) {
|
||||
return this.propertyResolver.getProperty(PREFIX + ".experimental." + name,
|
||||
String.class, null);
|
||||
return this.propertyResolver.getProperty(PREFIX + ".experimental." + name, String.class, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -349,8 +347,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return eIPBindingRetryIntervalMsWhenUnbound;
|
||||
}
|
||||
|
||||
public void setEIPBindingRetryIntervalMsWhenUnbound(
|
||||
int eIPBindingRetryIntervalMsWhenUnbound) {
|
||||
public void setEIPBindingRetryIntervalMsWhenUnbound(int eIPBindingRetryIntervalMsWhenUnbound) {
|
||||
this.eIPBindingRetryIntervalMsWhenUnbound = eIPBindingRetryIntervalMsWhenUnbound;
|
||||
}
|
||||
|
||||
@@ -381,13 +378,11 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return this.expectedClientRenewalIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setExpectedClientRenewalIntervalSeconds(
|
||||
int expectedClientRenewalIntervalSeconds) {
|
||||
public void setExpectedClientRenewalIntervalSeconds(int expectedClientRenewalIntervalSeconds) {
|
||||
this.expectedClientRenewalIntervalSeconds = expectedClientRenewalIntervalSeconds;
|
||||
}
|
||||
|
||||
public void setRenewalThresholdUpdateIntervalMs(
|
||||
int renewalThresholdUpdateIntervalMs) {
|
||||
public void setRenewalThresholdUpdateIntervalMs(int renewalThresholdUpdateIntervalMs) {
|
||||
this.renewalThresholdUpdateIntervalMs = renewalThresholdUpdateIntervalMs;
|
||||
}
|
||||
|
||||
@@ -414,8 +409,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return peerEurekaStatusRefreshTimeIntervalMs;
|
||||
}
|
||||
|
||||
public void setPeerEurekaStatusRefreshTimeIntervalMs(
|
||||
int peerEurekaStatusRefreshTimeIntervalMs) {
|
||||
public void setPeerEurekaStatusRefreshTimeIntervalMs(int peerEurekaStatusRefreshTimeIntervalMs) {
|
||||
this.peerEurekaStatusRefreshTimeIntervalMs = peerEurekaStatusRefreshTimeIntervalMs;
|
||||
}
|
||||
|
||||
@@ -469,8 +463,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return peerNodeConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
public void setPeerNodeConnectionIdleTimeoutSeconds(
|
||||
int peerNodeConnectionIdleTimeoutSeconds) {
|
||||
public void setPeerNodeConnectionIdleTimeoutSeconds(int peerNodeConnectionIdleTimeoutSeconds) {
|
||||
this.peerNodeConnectionIdleTimeoutSeconds = peerNodeConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
@@ -539,8 +532,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return responseCacheAutoExpirationInSeconds;
|
||||
}
|
||||
|
||||
public void setResponseCacheAutoExpirationInSeconds(
|
||||
long responseCacheAutoExpirationInSeconds) {
|
||||
public void setResponseCacheAutoExpirationInSeconds(long responseCacheAutoExpirationInSeconds) {
|
||||
this.responseCacheAutoExpirationInSeconds = responseCacheAutoExpirationInSeconds;
|
||||
}
|
||||
|
||||
@@ -574,8 +566,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return maxIdleThreadInMinutesAgeForStatusReplication;
|
||||
}
|
||||
|
||||
public void setMaxIdleThreadInMinutesAgeForStatusReplication(
|
||||
long maxIdleThreadInMinutesAgeForStatusReplication) {
|
||||
public void setMaxIdleThreadInMinutesAgeForStatusReplication(long maxIdleThreadInMinutesAgeForStatusReplication) {
|
||||
this.maxIdleThreadInMinutesAgeForStatusReplication = maxIdleThreadInMinutesAgeForStatusReplication;
|
||||
}
|
||||
|
||||
@@ -602,8 +593,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return maxElementsInStatusReplicationPool;
|
||||
}
|
||||
|
||||
public void setMaxElementsInStatusReplicationPool(
|
||||
int maxElementsInStatusReplicationPool) {
|
||||
public void setMaxElementsInStatusReplicationPool(int maxElementsInStatusReplicationPool) {
|
||||
this.maxElementsInStatusReplicationPool = maxElementsInStatusReplicationPool;
|
||||
}
|
||||
|
||||
@@ -638,8 +628,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return maxElementsInPeerReplicationPool;
|
||||
}
|
||||
|
||||
public void setMaxElementsInPeerReplicationPool(
|
||||
int maxElementsInPeerReplicationPool) {
|
||||
public void setMaxElementsInPeerReplicationPool(int maxElementsInPeerReplicationPool) {
|
||||
this.maxElementsInPeerReplicationPool = maxElementsInPeerReplicationPool;
|
||||
}
|
||||
|
||||
@@ -648,8 +637,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return maxIdleThreadAgeInMinutesForPeerReplication;
|
||||
}
|
||||
|
||||
public void setMaxIdleThreadAgeInMinutesForPeerReplication(
|
||||
long maxIdleThreadAgeInMinutesForPeerReplication) {
|
||||
public void setMaxIdleThreadAgeInMinutesForPeerReplication(long maxIdleThreadAgeInMinutesForPeerReplication) {
|
||||
this.maxIdleThreadAgeInMinutesForPeerReplication = maxIdleThreadAgeInMinutesForPeerReplication;
|
||||
}
|
||||
|
||||
@@ -728,8 +716,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return remoteRegionTotalConnectionsPerHost;
|
||||
}
|
||||
|
||||
public void setRemoteRegionTotalConnectionsPerHost(
|
||||
int remoteRegionTotalConnectionsPerHost) {
|
||||
public void setRemoteRegionTotalConnectionsPerHost(int remoteRegionTotalConnectionsPerHost) {
|
||||
this.remoteRegionTotalConnectionsPerHost = remoteRegionTotalConnectionsPerHost;
|
||||
}
|
||||
|
||||
@@ -738,8 +725,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return remoteRegionConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
public void setRemoteRegionConnectionIdleTimeoutSeconds(
|
||||
int remoteRegionConnectionIdleTimeoutSeconds) {
|
||||
public void setRemoteRegionConnectionIdleTimeoutSeconds(int remoteRegionConnectionIdleTimeoutSeconds) {
|
||||
this.remoteRegionConnectionIdleTimeoutSeconds = remoteRegionConnectionIdleTimeoutSeconds;
|
||||
}
|
||||
|
||||
@@ -756,8 +742,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return remoteRegionUrlsWithName;
|
||||
}
|
||||
|
||||
public void setRemoteRegionUrlsWithName(
|
||||
Map<String, String> remoteRegionUrlsWithName) {
|
||||
public void setRemoteRegionUrlsWithName(Map<String, String> remoteRegionUrlsWithName) {
|
||||
this.remoteRegionUrlsWithName = remoteRegionUrlsWithName;
|
||||
}
|
||||
|
||||
@@ -774,8 +759,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return remoteRegionAppWhitelist;
|
||||
}
|
||||
|
||||
public void setRemoteRegionAppWhitelist(
|
||||
Map<String, Set<String>> remoteRegionAppWhitelist) {
|
||||
public void setRemoteRegionAppWhitelist(Map<String, Set<String>> remoteRegionAppWhitelist) {
|
||||
this.remoteRegionAppWhitelist = remoteRegionAppWhitelist;
|
||||
}
|
||||
|
||||
@@ -784,8 +768,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return remoteRegionRegistryFetchInterval;
|
||||
}
|
||||
|
||||
public void setRemoteRegionRegistryFetchInterval(
|
||||
int remoteRegionRegistryFetchInterval) {
|
||||
public void setRemoteRegionRegistryFetchInterval(int remoteRegionRegistryFetchInterval) {
|
||||
this.remoteRegionRegistryFetchInterval = remoteRegionRegistryFetchInterval;
|
||||
}
|
||||
|
||||
@@ -820,8 +803,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return disableTransparentFallbackToOtherRegion;
|
||||
}
|
||||
|
||||
public void setDisableTransparentFallbackToOtherRegion(
|
||||
boolean disableTransparentFallbackToOtherRegion) {
|
||||
public void setDisableTransparentFallbackToOtherRegion(boolean disableTransparentFallbackToOtherRegion) {
|
||||
this.disableTransparentFallbackToOtherRegion = disableTransparentFallbackToOtherRegion;
|
||||
}
|
||||
|
||||
@@ -847,8 +829,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return rateLimiterThrottleStandardClients;
|
||||
}
|
||||
|
||||
public void setRateLimiterThrottleStandardClients(
|
||||
boolean rateLimiterThrottleStandardClients) {
|
||||
public void setRateLimiterThrottleStandardClients(boolean rateLimiterThrottleStandardClients) {
|
||||
this.rateLimiterThrottleStandardClients = rateLimiterThrottleStandardClients;
|
||||
}
|
||||
|
||||
@@ -857,8 +838,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return rateLimiterPrivilegedClients;
|
||||
}
|
||||
|
||||
public void setRateLimiterPrivilegedClients(
|
||||
Set<String> rateLimiterPrivilegedClients) {
|
||||
public void setRateLimiterPrivilegedClients(Set<String> rateLimiterPrivilegedClients) {
|
||||
this.rateLimiterPrivilegedClients = rateLimiterPrivilegedClients;
|
||||
}
|
||||
|
||||
@@ -876,8 +856,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return rateLimiterRegistryFetchAverageRate;
|
||||
}
|
||||
|
||||
public void setRateLimiterRegistryFetchAverageRate(
|
||||
int rateLimiterRegistryFetchAverageRate) {
|
||||
public void setRateLimiterRegistryFetchAverageRate(int rateLimiterRegistryFetchAverageRate) {
|
||||
this.rateLimiterRegistryFetchAverageRate = rateLimiterRegistryFetchAverageRate;
|
||||
}
|
||||
|
||||
@@ -911,8 +890,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return enableReplicatedRequestCompression;
|
||||
}
|
||||
|
||||
public void setEnableReplicatedRequestCompression(
|
||||
boolean enableReplicatedRequestCompression) {
|
||||
public void setEnableReplicatedRequestCompression(boolean enableReplicatedRequestCompression) {
|
||||
this.enableReplicatedRequestCompression = enableReplicatedRequestCompression;
|
||||
}
|
||||
|
||||
@@ -964,8 +942,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return minAvailableInstancesForPeerReplication;
|
||||
}
|
||||
|
||||
public void setMinAvailableInstancesForPeerReplication(
|
||||
int minAvailableInstancesForPeerReplication) {
|
||||
public void setMinAvailableInstancesForPeerReplication(int minAvailableInstancesForPeerReplication) {
|
||||
this.minAvailableInstancesForPeerReplication = minAvailableInstancesForPeerReplication;
|
||||
}
|
||||
|
||||
@@ -978,12 +955,9 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
return false;
|
||||
}
|
||||
EurekaServerConfigBean that = (EurekaServerConfigBean) o;
|
||||
return aSGCacheExpiryTimeoutMs == that.aSGCacheExpiryTimeoutMs
|
||||
&& aSGQueryTimeoutMs == that.aSGQueryTimeoutMs
|
||||
&& aSGUpdateIntervalMs == that.aSGUpdateIntervalMs
|
||||
&& Objects.equals(aWSAccessId, that.aWSAccessId)
|
||||
&& Objects.equals(aWSSecretKey, that.aWSSecretKey)
|
||||
&& batchReplication == that.batchReplication
|
||||
return aSGCacheExpiryTimeoutMs == that.aSGCacheExpiryTimeoutMs && aSGQueryTimeoutMs == that.aSGQueryTimeoutMs
|
||||
&& aSGUpdateIntervalMs == that.aSGUpdateIntervalMs && Objects.equals(aWSAccessId, that.aWSAccessId)
|
||||
&& Objects.equals(aWSSecretKey, that.aWSSecretKey) && batchReplication == that.batchReplication
|
||||
&& bindingStrategy == that.bindingStrategy
|
||||
&& deltaRetentionTimerIntervalInMs == that.deltaRetentionTimerIntervalInMs
|
||||
&& disableDelta == that.disableDelta
|
||||
@@ -997,8 +971,7 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
&& evictionIntervalTimerInMs == that.evictionIntervalTimerInMs
|
||||
&& gZipContentFromRemoteRegion == that.gZipContentFromRemoteRegion
|
||||
&& Objects.equals(jsonCodecName, that.jsonCodecName)
|
||||
&& Objects.equals(listAutoScalingGroupsRoleName,
|
||||
that.listAutoScalingGroupsRoleName)
|
||||
&& Objects.equals(listAutoScalingGroupsRoleName, that.listAutoScalingGroupsRoleName)
|
||||
&& logIdentityHeaders == that.logIdentityHeaders
|
||||
&& maxElementsInPeerReplicationPool == that.maxElementsInPeerReplicationPool
|
||||
&& maxElementsInStatusReplicationPool == that.maxElementsInStatusReplicationPool
|
||||
@@ -1020,11 +993,9 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
&& peerNodeTotalConnectionsPerHost == that.peerNodeTotalConnectionsPerHost
|
||||
&& primeAwsReplicaConnections == that.primeAwsReplicaConnections
|
||||
&& Objects.equals(propertyResolver, that.propertyResolver)
|
||||
&& rateLimiterBurstSize == that.rateLimiterBurstSize
|
||||
&& rateLimiterEnabled == that.rateLimiterEnabled
|
||||
&& rateLimiterBurstSize == that.rateLimiterBurstSize && rateLimiterEnabled == that.rateLimiterEnabled
|
||||
&& rateLimiterFullFetchAverageRate == that.rateLimiterFullFetchAverageRate
|
||||
&& Objects.equals(rateLimiterPrivilegedClients,
|
||||
that.rateLimiterPrivilegedClients)
|
||||
&& Objects.equals(rateLimiterPrivilegedClients, that.rateLimiterPrivilegedClients)
|
||||
&& rateLimiterRegistryFetchAverageRate == that.rateLimiterRegistryFetchAverageRate
|
||||
&& rateLimiterThrottleStandardClients == that.rateLimiterThrottleStandardClients
|
||||
&& registrySyncRetries == that.registrySyncRetries
|
||||
@@ -1038,12 +1009,10 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
&& remoteRegionTotalConnections == that.remoteRegionTotalConnections
|
||||
&& remoteRegionTotalConnectionsPerHost == that.remoteRegionTotalConnectionsPerHost
|
||||
&& Objects.equals(remoteRegionTrustStore, that.remoteRegionTrustStore)
|
||||
&& Objects.equals(remoteRegionTrustStorePassword,
|
||||
that.remoteRegionTrustStorePassword)
|
||||
&& Objects.equals(remoteRegionTrustStorePassword, that.remoteRegionTrustStorePassword)
|
||||
&& Arrays.equals(remoteRegionUrls, that.remoteRegionUrls)
|
||||
&& Objects.equals(remoteRegionUrlsWithName, that.remoteRegionUrlsWithName)
|
||||
&& Double.compare(that.renewalPercentThreshold,
|
||||
renewalPercentThreshold) == 0
|
||||
&& Double.compare(that.renewalPercentThreshold, renewalPercentThreshold) == 0
|
||||
&& renewalThresholdUpdateIntervalMs == that.renewalThresholdUpdateIntervalMs
|
||||
&& responseCacheAutoExpirationInSeconds == that.responseCacheAutoExpirationInSeconds
|
||||
&& responseCacheUpdateIntervalMs == that.responseCacheUpdateIntervalMs
|
||||
@@ -1062,155 +1031,109 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(aSGCacheExpiryTimeoutMs, aSGQueryTimeoutMs,
|
||||
aSGUpdateIntervalMs, aWSAccessId, aWSSecretKey, batchReplication,
|
||||
bindingStrategy, deltaRetentionTimerIntervalInMs, disableDelta,
|
||||
disableDeltaForRemoteRegions, disableTransparentFallbackToOtherRegion,
|
||||
eIPBindRebindRetries, eIPBindingRetryIntervalMs,
|
||||
eIPBindingRetryIntervalMsWhenUnbound, enableReplicatedRequestCompression,
|
||||
enableSelfPreservation, evictionIntervalTimerInMs,
|
||||
gZipContentFromRemoteRegion, jsonCodecName, listAutoScalingGroupsRoleName,
|
||||
logIdentityHeaders, maxElementsInPeerReplicationPool,
|
||||
maxElementsInStatusReplicationPool,
|
||||
maxIdleThreadAgeInMinutesForPeerReplication,
|
||||
maxIdleThreadInMinutesAgeForStatusReplication,
|
||||
maxThreadsForPeerReplication, maxThreadsForStatusReplication,
|
||||
maxTimeForReplication, minAvailableInstancesForPeerReplication,
|
||||
minThreadsForPeerReplication, minThreadsForStatusReplication,
|
||||
numberOfReplicationRetries, peerEurekaNodesUpdateIntervalMs,
|
||||
peerEurekaStatusRefreshTimeIntervalMs, peerNodeConnectTimeoutMs,
|
||||
peerNodeConnectionIdleTimeoutSeconds, peerNodeReadTimeoutMs,
|
||||
peerNodeTotalConnections, peerNodeTotalConnectionsPerHost,
|
||||
primeAwsReplicaConnections, propertyResolver, rateLimiterBurstSize,
|
||||
rateLimiterEnabled, rateLimiterFullFetchAverageRate,
|
||||
rateLimiterPrivilegedClients, rateLimiterRegistryFetchAverageRate,
|
||||
rateLimiterThrottleStandardClients, registrySyncRetries,
|
||||
registrySyncRetryWaitMs, remoteRegionAppWhitelist,
|
||||
remoteRegionConnectTimeoutMs, remoteRegionConnectionIdleTimeoutSeconds,
|
||||
remoteRegionFetchThreadPoolSize, remoteRegionReadTimeoutMs,
|
||||
remoteRegionRegistryFetchInterval, remoteRegionTotalConnections,
|
||||
remoteRegionTotalConnectionsPerHost, remoteRegionTrustStore,
|
||||
remoteRegionTrustStorePassword, remoteRegionUrls,
|
||||
remoteRegionUrlsWithName, renewalPercentThreshold,
|
||||
renewalThresholdUpdateIntervalMs, responseCacheAutoExpirationInSeconds,
|
||||
responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue,
|
||||
route53BindRebindRetries, route53BindingRetryIntervalMs, route53DomainTTL,
|
||||
syncWhenTimestampDiffers, useReadOnlyResponseCache,
|
||||
return Objects.hash(aSGCacheExpiryTimeoutMs, aSGQueryTimeoutMs, aSGUpdateIntervalMs, aWSAccessId, aWSSecretKey,
|
||||
batchReplication, bindingStrategy, deltaRetentionTimerIntervalInMs, disableDelta,
|
||||
disableDeltaForRemoteRegions, disableTransparentFallbackToOtherRegion, eIPBindRebindRetries,
|
||||
eIPBindingRetryIntervalMs, eIPBindingRetryIntervalMsWhenUnbound, enableReplicatedRequestCompression,
|
||||
enableSelfPreservation, evictionIntervalTimerInMs, gZipContentFromRemoteRegion, jsonCodecName,
|
||||
listAutoScalingGroupsRoleName, logIdentityHeaders, maxElementsInPeerReplicationPool,
|
||||
maxElementsInStatusReplicationPool, maxIdleThreadAgeInMinutesForPeerReplication,
|
||||
maxIdleThreadInMinutesAgeForStatusReplication, maxThreadsForPeerReplication,
|
||||
maxThreadsForStatusReplication, maxTimeForReplication, minAvailableInstancesForPeerReplication,
|
||||
minThreadsForPeerReplication, minThreadsForStatusReplication, numberOfReplicationRetries,
|
||||
peerEurekaNodesUpdateIntervalMs, peerEurekaStatusRefreshTimeIntervalMs, peerNodeConnectTimeoutMs,
|
||||
peerNodeConnectionIdleTimeoutSeconds, peerNodeReadTimeoutMs, peerNodeTotalConnections,
|
||||
peerNodeTotalConnectionsPerHost, primeAwsReplicaConnections, propertyResolver, rateLimiterBurstSize,
|
||||
rateLimiterEnabled, rateLimiterFullFetchAverageRate, rateLimiterPrivilegedClients,
|
||||
rateLimiterRegistryFetchAverageRate, rateLimiterThrottleStandardClients, registrySyncRetries,
|
||||
registrySyncRetryWaitMs, remoteRegionAppWhitelist, remoteRegionConnectTimeoutMs,
|
||||
remoteRegionConnectionIdleTimeoutSeconds, remoteRegionFetchThreadPoolSize, remoteRegionReadTimeoutMs,
|
||||
remoteRegionRegistryFetchInterval, remoteRegionTotalConnections, remoteRegionTotalConnectionsPerHost,
|
||||
remoteRegionTrustStore, remoteRegionTrustStorePassword, remoteRegionUrls, remoteRegionUrlsWithName,
|
||||
renewalPercentThreshold, renewalThresholdUpdateIntervalMs, responseCacheAutoExpirationInSeconds,
|
||||
responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue, route53BindRebindRetries,
|
||||
route53BindingRetryIntervalMs, route53DomainTTL, syncWhenTimestampDiffers, useReadOnlyResponseCache,
|
||||
waitTimeInMsWhenSyncEmpty, xmlCodecName, initialCapacityOfResponseCache,
|
||||
expectedClientRenewalIntervalSeconds, useAwsAsgApi, myUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("aSGCacheExpiryTimeoutMs", this.aSGCacheExpiryTimeoutMs)
|
||||
return new ToStringCreator(this).append("aSGCacheExpiryTimeoutMs", this.aSGCacheExpiryTimeoutMs)
|
||||
.append("aSGQueryTimeoutMs", this.aSGQueryTimeoutMs)
|
||||
.append("aSGUpdateIntervalMs", this.aSGUpdateIntervalMs)
|
||||
.append("aWSAccessId", this.aWSAccessId)
|
||||
.append("aWSSecretKey", this.aWSSecretKey)
|
||||
.append("batchReplication", this.batchReplication)
|
||||
.append("aSGUpdateIntervalMs", this.aSGUpdateIntervalMs).append("aWSAccessId", this.aWSAccessId)
|
||||
.append("aWSSecretKey", this.aWSSecretKey).append("batchReplication", this.batchReplication)
|
||||
.append("bindingStrategy", this.bindingStrategy)
|
||||
.append("deltaRetentionTimerIntervalInMs",
|
||||
this.deltaRetentionTimerIntervalInMs)
|
||||
.append("deltaRetentionTimerIntervalInMs", this.deltaRetentionTimerIntervalInMs)
|
||||
.append("disableDelta", this.disableDelta)
|
||||
.append("disableDeltaForRemoteRegions", this.disableDeltaForRemoteRegions)
|
||||
.append("disableTransparentFallbackToOtherRegion",
|
||||
this.disableTransparentFallbackToOtherRegion)
|
||||
.append("disableTransparentFallbackToOtherRegion", this.disableTransparentFallbackToOtherRegion)
|
||||
.append("eIPBindRebindRetries", this.eIPBindRebindRetries)
|
||||
.append("eIPBindingRetryIntervalMs", this.eIPBindingRetryIntervalMs)
|
||||
.append("eIPBindingRetryIntervalMsWhenUnbound",
|
||||
this.eIPBindingRetryIntervalMsWhenUnbound)
|
||||
.append("enableReplicatedRequestCompression",
|
||||
this.enableReplicatedRequestCompression)
|
||||
.append("eIPBindingRetryIntervalMsWhenUnbound", this.eIPBindingRetryIntervalMsWhenUnbound)
|
||||
.append("enableReplicatedRequestCompression", this.enableReplicatedRequestCompression)
|
||||
.append("enableSelfPreservation", this.enableSelfPreservation)
|
||||
.append("evictionIntervalTimerInMs", this.evictionIntervalTimerInMs)
|
||||
.append("gZipContentFromRemoteRegion", this.gZipContentFromRemoteRegion)
|
||||
.append("jsonCodecName", this.jsonCodecName)
|
||||
.append("listAutoScalingGroupsRoleName",
|
||||
this.listAutoScalingGroupsRoleName)
|
||||
.append("listAutoScalingGroupsRoleName", this.listAutoScalingGroupsRoleName)
|
||||
.append("logIdentityHeaders", this.logIdentityHeaders)
|
||||
.append("maxElementsInPeerReplicationPool",
|
||||
this.maxElementsInPeerReplicationPool)
|
||||
.append("maxElementsInStatusReplicationPool",
|
||||
this.maxElementsInStatusReplicationPool)
|
||||
.append("maxIdleThreadAgeInMinutesForPeerReplication",
|
||||
this.maxIdleThreadAgeInMinutesForPeerReplication)
|
||||
.append("maxElementsInPeerReplicationPool", this.maxElementsInPeerReplicationPool)
|
||||
.append("maxElementsInStatusReplicationPool", this.maxElementsInStatusReplicationPool)
|
||||
.append("maxIdleThreadAgeInMinutesForPeerReplication", this.maxIdleThreadAgeInMinutesForPeerReplication)
|
||||
.append("maxIdleThreadInMinutesAgeForStatusReplication",
|
||||
this.maxIdleThreadInMinutesAgeForStatusReplication)
|
||||
.append("maxThreadsForPeerReplication", this.maxThreadsForPeerReplication)
|
||||
.append("maxThreadsForStatusReplication",
|
||||
this.maxThreadsForStatusReplication)
|
||||
.append("maxThreadsForStatusReplication", this.maxThreadsForStatusReplication)
|
||||
.append("maxTimeForReplication", this.maxTimeForReplication)
|
||||
.append("minAvailableInstancesForPeerReplication",
|
||||
this.minAvailableInstancesForPeerReplication)
|
||||
.append("minAvailableInstancesForPeerReplication", this.minAvailableInstancesForPeerReplication)
|
||||
.append("minThreadsForPeerReplication", this.minThreadsForPeerReplication)
|
||||
.append("minThreadsForStatusReplication",
|
||||
this.minThreadsForStatusReplication)
|
||||
.append("minThreadsForStatusReplication", this.minThreadsForStatusReplication)
|
||||
.append("numberOfReplicationRetries", this.numberOfReplicationRetries)
|
||||
.append("peerEurekaNodesUpdateIntervalMs",
|
||||
this.peerEurekaNodesUpdateIntervalMs)
|
||||
.append("peerEurekaStatusRefreshTimeIntervalMs",
|
||||
this.peerEurekaStatusRefreshTimeIntervalMs)
|
||||
.append("peerEurekaNodesUpdateIntervalMs", this.peerEurekaNodesUpdateIntervalMs)
|
||||
.append("peerEurekaStatusRefreshTimeIntervalMs", this.peerEurekaStatusRefreshTimeIntervalMs)
|
||||
.append("peerNodeConnectTimeoutMs", this.peerNodeConnectTimeoutMs)
|
||||
.append("peerNodeConnectionIdleTimeoutSeconds",
|
||||
this.peerNodeConnectionIdleTimeoutSeconds)
|
||||
.append("peerNodeConnectionIdleTimeoutSeconds", this.peerNodeConnectionIdleTimeoutSeconds)
|
||||
.append("peerNodeReadTimeoutMs", this.peerNodeReadTimeoutMs)
|
||||
.append("peerNodeTotalConnections", this.peerNodeTotalConnections)
|
||||
.append("peerNodeTotalConnectionsPerHost",
|
||||
this.peerNodeTotalConnectionsPerHost)
|
||||
.append("peerNodeTotalConnectionsPerHost", this.peerNodeTotalConnectionsPerHost)
|
||||
.append("primeAwsReplicaConnections", this.primeAwsReplicaConnections)
|
||||
.append("propertyResolver", this.propertyResolver)
|
||||
.append("rateLimiterBurstSize", this.rateLimiterBurstSize)
|
||||
.append("rateLimiterEnabled", this.rateLimiterEnabled)
|
||||
.append("rateLimiterFullFetchAverageRate",
|
||||
this.rateLimiterFullFetchAverageRate)
|
||||
.append("rateLimiterFullFetchAverageRate", this.rateLimiterFullFetchAverageRate)
|
||||
.append("rateLimiterPrivilegedClients", this.rateLimiterPrivilegedClients)
|
||||
.append("rateLimiterRegistryFetchAverageRate",
|
||||
this.rateLimiterRegistryFetchAverageRate)
|
||||
.append("rateLimiterThrottleStandardClients",
|
||||
this.rateLimiterThrottleStandardClients)
|
||||
.append("rateLimiterRegistryFetchAverageRate", this.rateLimiterRegistryFetchAverageRate)
|
||||
.append("rateLimiterThrottleStandardClients", this.rateLimiterThrottleStandardClients)
|
||||
.append("registrySyncRetries", this.registrySyncRetries)
|
||||
.append("registrySyncRetryWaitMs", this.registrySyncRetryWaitMs)
|
||||
.append("remoteRegionAppWhitelist", this.remoteRegionAppWhitelist)
|
||||
.append("remoteRegionConnectTimeoutMs", this.remoteRegionConnectTimeoutMs)
|
||||
.append("remoteRegionConnectionIdleTimeoutSeconds",
|
||||
this.remoteRegionConnectionIdleTimeoutSeconds)
|
||||
.append("remoteRegionFetchThreadPoolSize",
|
||||
this.remoteRegionFetchThreadPoolSize)
|
||||
.append("remoteRegionConnectionIdleTimeoutSeconds", this.remoteRegionConnectionIdleTimeoutSeconds)
|
||||
.append("remoteRegionFetchThreadPoolSize", this.remoteRegionFetchThreadPoolSize)
|
||||
.append("remoteRegionReadTimeoutMs", this.remoteRegionReadTimeoutMs)
|
||||
.append("remoteRegionRegistryFetchInterval",
|
||||
this.remoteRegionRegistryFetchInterval)
|
||||
.append("remoteRegionRegistryFetchInterval", this.remoteRegionRegistryFetchInterval)
|
||||
.append("remoteRegionTotalConnections", this.remoteRegionTotalConnections)
|
||||
.append("remoteRegionTotalConnectionsPerHost",
|
||||
this.remoteRegionTotalConnectionsPerHost)
|
||||
.append("remoteRegionTotalConnectionsPerHost", this.remoteRegionTotalConnectionsPerHost)
|
||||
.append("remoteRegionTrustStore", this.remoteRegionTrustStore)
|
||||
.append("remoteRegionTrustStorePassword",
|
||||
this.remoteRegionTrustStorePassword)
|
||||
.append("remoteRegionTrustStorePassword", this.remoteRegionTrustStorePassword)
|
||||
.append("remoteRegionUrls", this.remoteRegionUrls)
|
||||
.append("remoteRegionUrlsWithName", this.remoteRegionUrlsWithName)
|
||||
.append("renewalPercentThreshold", this.renewalPercentThreshold)
|
||||
.append("renewalThresholdUpdateIntervalMs",
|
||||
this.renewalThresholdUpdateIntervalMs)
|
||||
.append("responseCacheAutoExpirationInSeconds",
|
||||
this.responseCacheAutoExpirationInSeconds)
|
||||
.append("responseCacheUpdateIntervalMs",
|
||||
this.responseCacheUpdateIntervalMs)
|
||||
.append("retentionTimeInMSInDeltaQueue",
|
||||
this.retentionTimeInMSInDeltaQueue)
|
||||
.append("renewalThresholdUpdateIntervalMs", this.renewalThresholdUpdateIntervalMs)
|
||||
.append("responseCacheAutoExpirationInSeconds", this.responseCacheAutoExpirationInSeconds)
|
||||
.append("responseCacheUpdateIntervalMs", this.responseCacheUpdateIntervalMs)
|
||||
.append("retentionTimeInMSInDeltaQueue", this.retentionTimeInMSInDeltaQueue)
|
||||
.append("route53BindRebindRetries", this.route53BindRebindRetries)
|
||||
.append("route53BindingRetryIntervalMs",
|
||||
this.route53BindingRetryIntervalMs)
|
||||
.append("route53BindingRetryIntervalMs", this.route53BindingRetryIntervalMs)
|
||||
.append("route53DomainTTL", this.route53DomainTTL)
|
||||
.append("syncWhenTimestampDiffers", this.syncWhenTimestampDiffers)
|
||||
.append("useReadOnlyResponseCache", this.useReadOnlyResponseCache)
|
||||
.append("waitTimeInMsWhenSyncEmpty", this.waitTimeInMsWhenSyncEmpty)
|
||||
.append("xmlCodecName", this.xmlCodecName)
|
||||
.append("initialCapacityOfResponseCache",
|
||||
this.initialCapacityOfResponseCache)
|
||||
.append("expectedClientRenewalIntervalSeconds",
|
||||
this.expectedClientRenewalIntervalSeconds)
|
||||
.append("useAwsAsgApi", this.useAwsAsgApi).append("myUrl", this.myUrl)
|
||||
.toString();
|
||||
.append("initialCapacityOfResponseCache", this.initialCapacityOfResponseCache)
|
||||
.append("expectedClientRenewalIntervalSeconds", this.expectedClientRenewalIntervalSeconds)
|
||||
.append("useAwsAsgApi", this.useAwsAsgApi).append("myUrl", this.myUrl).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,11 +36,9 @@ import org.springframework.web.context.ServletContextAware;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class EurekaServerInitializerConfiguration
|
||||
implements ServletContextAware, SmartLifecycle, Ordered {
|
||||
public class EurekaServerInitializerConfiguration implements ServletContextAware, SmartLifecycle, Ordered {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(EurekaServerInitializerConfiguration.class);
|
||||
private static final Log log = LogFactory.getLog(EurekaServerInitializerConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
private EurekaServerConfig eurekaServerConfig;
|
||||
@@ -67,8 +65,7 @@ public class EurekaServerInitializerConfiguration
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// TODO: is this class even needed now?
|
||||
eurekaServerBootstrap.contextInitialized(
|
||||
EurekaServerInitializerConfiguration.this.servletContext);
|
||||
eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);
|
||||
log.info("Started Eureka Server");
|
||||
|
||||
publish(new EurekaRegistryAvailableEvent(getEurekaServerConfig()));
|
||||
|
||||
@@ -41,8 +41,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
implements ApplicationContextAware {
|
||||
public class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements ApplicationContextAware {
|
||||
|
||||
private static final Log log = LogFactory.getLog(InstanceRegistry.class);
|
||||
|
||||
@@ -50,10 +49,8 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
|
||||
private int defaultOpenForTrafficCount;
|
||||
|
||||
public InstanceRegistry(EurekaServerConfig serverConfig,
|
||||
EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
|
||||
EurekaClient eurekaClient, int expectedNumberOfClientsSendingRenews,
|
||||
int defaultOpenForTrafficCount) {
|
||||
public InstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
|
||||
EurekaClient eurekaClient, int expectedNumberOfClientsSendingRenews, int defaultOpenForTrafficCount) {
|
||||
super(serverConfig, clientConfig, serverCodecs, eurekaClient);
|
||||
|
||||
this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
|
||||
@@ -76,8 +73,7 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
*/
|
||||
@Override
|
||||
public void openForTraffic(ApplicationInfoManager applicationInfoManager, int count) {
|
||||
super.openForTraffic(applicationInfoManager,
|
||||
count == 0 ? this.defaultOpenForTrafficCount : count);
|
||||
super.openForTraffic(applicationInfoManager, count == 0 ? this.defaultOpenForTrafficCount : count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,10 +95,8 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renew(final String appName, final String serverId,
|
||||
boolean isReplication) {
|
||||
log("renew " + appName + " serverId " + serverId + ", isReplication {}"
|
||||
+ isReplication);
|
||||
public boolean renew(final String appName, final String serverId, boolean isReplication) {
|
||||
log("renew " + appName + " serverId " + serverId + ", isReplication {}" + isReplication);
|
||||
List<Application> applications = getSortedApplications();
|
||||
for (Application input : applications) {
|
||||
if (input.getName().equals(appName)) {
|
||||
@@ -113,8 +107,7 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
break;
|
||||
}
|
||||
}
|
||||
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
|
||||
instance, isReplication));
|
||||
publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instance, isReplication));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -128,18 +121,14 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
|
||||
}
|
||||
|
||||
private void handleCancelation(String appName, String id, boolean isReplication) {
|
||||
log("cancel " + appName + ", serverId " + id + ", isReplication "
|
||||
+ isReplication);
|
||||
log("cancel " + appName + ", serverId " + id + ", isReplication " + isReplication);
|
||||
publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
|
||||
}
|
||||
|
||||
private void handleRegistration(InstanceInfo info, int leaseDuration,
|
||||
boolean isReplication) {
|
||||
log("register " + info.getAppName() + ", vip " + info.getVIPAddress()
|
||||
+ ", leaseDuration " + leaseDuration + ", isReplication "
|
||||
+ isReplication);
|
||||
publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration,
|
||||
isReplication));
|
||||
private void handleRegistration(InstanceInfo info, int leaseDuration, boolean isReplication) {
|
||||
log("register " + info.getAppName() + ", vip " + info.getVIPAddress() + ", leaseDuration " + leaseDuration
|
||||
+ ", isReplication " + isReplication);
|
||||
publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration, isReplication));
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
|
||||
@@ -55,13 +55,11 @@ public class InstanceRegistryProperties {
|
||||
return expectedNumberOfClientsSendingRenews;
|
||||
}
|
||||
|
||||
public void setExpectedNumberOfClientsSendingRenews(
|
||||
int expectedNumberOfClientsSendingRenews) {
|
||||
public void setExpectedNumberOfClientsSendingRenews(int expectedNumberOfClientsSendingRenews) {
|
||||
this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
|
||||
}
|
||||
|
||||
@DeprecatedConfigurationProperty(
|
||||
replacement = PREFIX + ".expected-number-of-clients-sending-renews")
|
||||
@DeprecatedConfigurationProperty(replacement = PREFIX + ".expected-number-of-clients-sending-renews")
|
||||
@Deprecated
|
||||
public int getExpectedNumberOfRenewsPerMin() {
|
||||
return getExpectedNumberOfClientsSendingRenews();
|
||||
|
||||
@@ -33,8 +33,7 @@ public class EurekaInstanceCanceledEvent extends ApplicationEvent {
|
||||
|
||||
private boolean replication;
|
||||
|
||||
public EurekaInstanceCanceledEvent(Object source, String appName, String serverId,
|
||||
boolean replication) {
|
||||
public EurekaInstanceCanceledEvent(Object source, String appName, String serverId, boolean replication) {
|
||||
super(source);
|
||||
this.appName = appName;
|
||||
this.serverId = serverId;
|
||||
@@ -74,8 +73,8 @@ public class EurekaInstanceCanceledEvent extends ApplicationEvent {
|
||||
return false;
|
||||
}
|
||||
EurekaInstanceCanceledEvent that = (EurekaInstanceCanceledEvent) o;
|
||||
return Objects.equals(appName, that.appName)
|
||||
&& Objects.equals(serverId, that.serverId) && replication == replication;
|
||||
return Objects.equals(appName, that.appName) && Objects.equals(serverId, that.serverId)
|
||||
&& replication == replication;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,10 +84,9 @@ public class EurekaInstanceCanceledEvent extends ApplicationEvent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EurekaInstanceCanceledEvent{").append("appName='")
|
||||
.append(appName).append("', ").append("serverId='").append(serverId)
|
||||
.append("', ").append("replication=").append(replication).append("}")
|
||||
.toString();
|
||||
return new StringBuilder("EurekaInstanceCanceledEvent{").append("appName='").append(appName).append("', ")
|
||||
.append("serverId='").append(serverId).append("', ").append("replication=").append(replication)
|
||||
.append("}").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ public class EurekaInstanceRegisteredEvent extends ApplicationEvent {
|
||||
|
||||
private boolean replication;
|
||||
|
||||
public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo,
|
||||
int leaseDuration, boolean replication) {
|
||||
public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo, int leaseDuration,
|
||||
boolean replication) {
|
||||
super(source);
|
||||
this.instanceInfo = instanceInfo;
|
||||
this.leaseDuration = leaseDuration;
|
||||
@@ -76,8 +76,8 @@ public class EurekaInstanceRegisteredEvent extends ApplicationEvent {
|
||||
return false;
|
||||
}
|
||||
EurekaInstanceRegisteredEvent that = (EurekaInstanceRegisteredEvent) o;
|
||||
return Objects.equals(instanceInfo, that.instanceInfo)
|
||||
&& leaseDuration == leaseDuration && replication == replication;
|
||||
return Objects.equals(instanceInfo, that.instanceInfo) && leaseDuration == leaseDuration
|
||||
&& replication == replication;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,9 +87,8 @@ public class EurekaInstanceRegisteredEvent extends ApplicationEvent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EurekaInstanceRegisteredEvent{").append("instanceInfo=")
|
||||
.append(instanceInfo).append(", ").append("leaseDuration=")
|
||||
.append(leaseDuration).append(", ").append("replication=")
|
||||
return new StringBuilder("EurekaInstanceRegisteredEvent{").append("instanceInfo=").append(instanceInfo)
|
||||
.append(", ").append("leaseDuration=").append(leaseDuration).append(", ").append("replication=")
|
||||
.append(replication).append("}").toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ public class EurekaInstanceRenewedEvent extends ApplicationEvent {
|
||||
|
||||
private boolean replication;
|
||||
|
||||
public EurekaInstanceRenewedEvent(Object source, String appName, String serverId,
|
||||
InstanceInfo instanceInfo, boolean replication) {
|
||||
public EurekaInstanceRenewedEvent(Object source, String appName, String serverId, InstanceInfo instanceInfo,
|
||||
boolean replication) {
|
||||
super(source);
|
||||
this.appName = appName;
|
||||
this.serverId = serverId;
|
||||
@@ -87,10 +87,8 @@ public class EurekaInstanceRenewedEvent extends ApplicationEvent {
|
||||
return false;
|
||||
}
|
||||
EurekaInstanceRenewedEvent that = (EurekaInstanceRenewedEvent) o;
|
||||
return Objects.equals(appName, that.appName)
|
||||
&& Objects.equals(serverId, that.serverId)
|
||||
&& Objects.equals(instanceInfo, that.instanceInfo)
|
||||
&& replication == that.replication;
|
||||
return Objects.equals(appName, that.appName) && Objects.equals(serverId, that.serverId)
|
||||
&& Objects.equals(instanceInfo, that.instanceInfo) && replication == that.replication;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,10 +98,9 @@ public class EurekaInstanceRenewedEvent extends ApplicationEvent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EurekaInstanceRenewedEvent{").append("appName='")
|
||||
.append(appName).append("', ").append("serverId='").append(serverId)
|
||||
.append("', ").append("instanceInfo=").append(instanceInfo).append(", ")
|
||||
.append("replication=").append(replication).append("}").toString();
|
||||
return new StringBuilder("EurekaInstanceRenewedEvent{").append("appName='").append(appName).append("', ")
|
||||
.append("serverId='").append(serverId).append("', ").append("instanceInfo=").append(instanceInfo)
|
||||
.append(", ").append("replication=").append(replication).append("}").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,10 +42,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.application.name=eureka",
|
||||
"server.servlet.context-path=/context",
|
||||
"management.security.enabled=false",
|
||||
"management.endpoints.web.exposure.include=*" })
|
||||
properties = { "spring.application.name=eureka", "server.servlet.context-path=/context",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationContextTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
@@ -56,39 +54,35 @@ public class ApplicationContextTests {
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/context/eureka/apps", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/apps", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/context/", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
// System.err.println(body);
|
||||
assertThat(body.contains("eureka/js")).isTrue();
|
||||
assertThat(body.contains("eureka/css")).isTrue();
|
||||
// The "DS Replicas"
|
||||
assertThat(
|
||||
body.contains("<a href=\"http://localhost:8761/eureka/\">localhost</a>"))
|
||||
.isTrue();
|
||||
assertThat(body.contains("<a href=\"http://localhost:8761/eureka/\">localhost</a>")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/context/eureka/css/wro.css",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/context/eureka/js/wro.js",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -99,8 +93,8 @@ public class ApplicationContextTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/context" + BASE_PATH + "/env",
|
||||
HttpMethod.GET, new HttpEntity<>("parameters", headers), Map.class);
|
||||
"http://localhost:" + this.port + "/context" + BASE_PATH + "/env", HttpMethod.GET,
|
||||
new HttpEntity<>("parameters", headers), Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,15 +43,15 @@ public class ApplicationDashboardDisabledTests {
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,23 +43,22 @@ public class ApplicationDashboardPathTests {
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/dashboard", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/dashboard", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
// System.err.println(body);
|
||||
assertThat(body.contains("eureka/js")).isTrue();
|
||||
assertThat(body.contains("eureka/css")).isTrue();
|
||||
// The "DS Replicas"
|
||||
assertThat(body.contains("<h1>Instances currently registered with Eureka</h1>"))
|
||||
.isTrue();
|
||||
assertThat(body.contains("<h1>Instances currently registered with Eureka</h1>")).isTrue();
|
||||
// The Home
|
||||
assertThat(body.contains("<a href=\"/dashboard\">Home</a>")).isTrue();
|
||||
// The Lastn
|
||||
@@ -68,15 +67,15 @@ public class ApplicationDashboardPathTests {
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/eureka/css/wro.css", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/eureka/js/wro.js", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = RANDOM_PORT,
|
||||
properties = { "spring.application.name=eureka",
|
||||
"server.servlet.context-path=/servlet",
|
||||
"management.security.enabled=false",
|
||||
"management.endpoints.web.exposure.include=*" })
|
||||
properties = { "spring.application.name=eureka", "server.servlet.context-path=/servlet",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationServletPathTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
@@ -56,38 +54,35 @@ public class ApplicationServletPathTests {
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/servlet/eureka/apps", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/apps", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/servlet/", String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
// System.err.println(body);
|
||||
assertThat(body.contains("eureka/js")).isTrue();
|
||||
assertThat(body.contains("eureka/css")).isTrue();
|
||||
// The "DS Replicas"
|
||||
assertThat(body.contains("<h1>Instances currently registered with Eureka</h1>"))
|
||||
.isTrue();
|
||||
assertThat(body.contains("<h1>Instances currently registered with Eureka</h1>")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/servlet/eureka/css/wro.css",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/servlet/eureka/js/wro.js",
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -98,8 +93,8 @@ public class ApplicationServletPathTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/servlet" + BASE_PATH + "/env",
|
||||
HttpMethod.GET, new HttpEntity<>("parameters", headers), Map.class);
|
||||
"http://localhost:" + this.port + "/servlet" + BASE_PATH + "/env", HttpMethod.GET,
|
||||
new HttpEntity<>("parameters", headers), Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = RANDOM_PORT,
|
||||
properties = { "spring.jmx.enabled=true", "management.security.enabled=false",
|
||||
"management.endpoints.web.exposure.include=*" })
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = RANDOM_PORT, properties = { "spring.jmx.enabled=true",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
@@ -61,8 +60,8 @@ public class ApplicationTests {
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -81,20 +80,17 @@ public class ApplicationTests {
|
||||
@Test
|
||||
public void noDoubleSlashes() {
|
||||
String basePath = "http://localhost:" + this.port + "/";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath,
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
assertThat(body).isNotNull();
|
||||
assertThat(body.contains(basePath + "/")).as("basePath contains double slashes")
|
||||
.isFalse();
|
||||
assertThat(body.contains(basePath + "/")).as("basePath contains double slashes").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssParsedByLess() {
|
||||
String basePath = "http://localhost:" + this.port + "/eureka/css/wro.css";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath,
|
||||
String.class);
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
assertThat(body).isNotNull();
|
||||
@@ -108,8 +104,8 @@ public class ApplicationTests {
|
||||
CodecWrapper codec = this.serverCodecs.getFullJsonCodec();
|
||||
assertThat(codec).as("codec is wrong type").isInstanceOf(CloudJacksonJson.class);
|
||||
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("fooapp")
|
||||
.add("instanceId", "foo").build();
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("fooapp").add("instanceId", "foo")
|
||||
.build();
|
||||
String encoded = codec.encode(instanceInfo);
|
||||
InstanceInfo decoded = codec.decode(encoded, InstanceInfo.class);
|
||||
assertThat(decoded.getInstanceId()).as("instanceId was wrong").isEqualTo("foo");
|
||||
|
||||
@@ -74,9 +74,8 @@ public class EurekaControllerReplicasTests {
|
||||
@Test
|
||||
public void testFilterReplicasNoAuth() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
|
||||
.add("registered-replicas", empty).add("available-replicas", noAuthList1)
|
||||
.add("unavailable-replicas", noAuthList2)
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", empty)
|
||||
.add("available-replicas", noAuthList1).add("unavailable-replicas", noAuthList2)
|
||||
.withInstanceInfo(this.instanceInfo).build();
|
||||
EurekaController controller = new EurekaController(null);
|
||||
|
||||
@@ -93,10 +92,9 @@ public class EurekaControllerReplicasTests {
|
||||
@Test
|
||||
public void testFilterReplicasAuth() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
|
||||
.add("registered-replicas", authList2)
|
||||
.add("available-replicas", authList1).add("unavailable-replicas", empty)
|
||||
.withInstanceInfo(instanceInfo).build();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", authList2)
|
||||
.add("available-replicas", authList1).add("unavailable-replicas", empty).withInstanceInfo(instanceInfo)
|
||||
.build();
|
||||
EurekaController controller = new EurekaController(null);
|
||||
|
||||
controller.filterReplicas(model, statusInfo);
|
||||
@@ -112,10 +110,8 @@ public class EurekaControllerReplicasTests {
|
||||
@Test
|
||||
public void testFilterReplicasAuthWithCombinationList() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
|
||||
.add("registered-replicas", totalAutoList)
|
||||
.add("available-replicas", combinationAuthList1)
|
||||
.add("unavailable-replicas", combinationAuthList2)
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", totalAutoList)
|
||||
.add("available-replicas", combinationAuthList1).add("unavailable-replicas", combinationAuthList2)
|
||||
.withInstanceInfo(instanceInfo).build();
|
||||
EurekaController controller = new EurekaController(null);
|
||||
|
||||
|
||||
@@ -53,12 +53,10 @@ public class EurekaControllerTests {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
|
||||
when(peerEurekaNodes.getPeerNodesView())
|
||||
.thenReturn(Collections.<PeerEurekaNode>emptyList());
|
||||
when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList());
|
||||
|
||||
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test")
|
||||
.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
|
||||
.build();
|
||||
.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
|
||||
|
||||
this.infoManager = mock(ApplicationInfoManager.class);
|
||||
this.original = ApplicationInfoManager.getInstance();
|
||||
@@ -67,8 +65,7 @@ public class EurekaControllerTests {
|
||||
|
||||
Application myapp = new Application("myapp");
|
||||
myapp.addInstance(InstanceInfo.Builder.newBuilder().setAppName("myapp")
|
||||
.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
|
||||
.setInstanceId("myapp:1").build());
|
||||
.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).setInstanceId("myapp:1").build());
|
||||
|
||||
ArrayList<Application> applications = new ArrayList<>();
|
||||
applications.add(myapp);
|
||||
@@ -89,10 +86,8 @@ public class EurekaControllerTests {
|
||||
setInstance(this.original);
|
||||
}
|
||||
|
||||
static void setInstance(ApplicationInfoManager infoManager)
|
||||
throws IllegalAccessException {
|
||||
Field instance = ReflectionUtils.findField(ApplicationInfoManager.class,
|
||||
"instance");
|
||||
static void setInstance(ApplicationInfoManager infoManager) throws IllegalAccessException {
|
||||
Field instance = ReflectionUtils.findField(ApplicationInfoManager.class, "instance");
|
||||
ReflectionUtils.makeAccessible(instance);
|
||||
instance.set(null, infoManager);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = EurekaCustomPeerNodesTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka", "server.contextPath=/context",
|
||||
"management.security.enabled=false" })
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka",
|
||||
"server.contextPath=/context", "management.security.enabled=false" })
|
||||
public class EurekaCustomPeerNodesTests {
|
||||
|
||||
@Autowired
|
||||
@@ -57,23 +56,20 @@ public class EurekaCustomPeerNodesTests {
|
||||
|
||||
@Bean
|
||||
public PeerEurekaNodes myPeerEurekaNodes(PeerAwareInstanceRegistry registry,
|
||||
EurekaServerConfig eurekaServerConfig,
|
||||
EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs,
|
||||
EurekaServerConfig eurekaServerConfig, EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs,
|
||||
ApplicationInfoManager applicationInfoManager) {
|
||||
return new CustomEurekaPeerNodes(registry, eurekaServerConfig,
|
||||
eurekaClientConfig, serverCodecs, applicationInfoManager);
|
||||
return new CustomEurekaPeerNodes(registry, eurekaServerConfig, eurekaClientConfig, serverCodecs,
|
||||
applicationInfoManager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class CustomEurekaPeerNodes extends PeerEurekaNodes {
|
||||
|
||||
CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry,
|
||||
EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
|
||||
ServerCodecs serverCodecs,
|
||||
CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry, EurekaServerConfig serverConfig,
|
||||
EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
|
||||
ApplicationInfoManager applicationInfoManager) {
|
||||
super(registry, serverConfig, clientConfig, serverCodecs,
|
||||
applicationInfoManager);
|
||||
super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,10 +50,9 @@ import static org.mockito.Mockito.doReturn;
|
||||
* @author Bartlomiej Slota
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = TestApplication.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka", "logging.level.org.springframework."
|
||||
+ "cloud.netflix.eureka.server.InstanceRegistry=DEBUG" })
|
||||
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka",
|
||||
"logging.level.org.springframework." + "cloud.netflix.eureka.server.InstanceRegistry=DEBUG" })
|
||||
public class InstanceRegistryTests {
|
||||
|
||||
private static final String APP_NAME = "MY-APP-NAME";
|
||||
@@ -79,20 +78,17 @@ public class InstanceRegistryTests {
|
||||
public void testRegister() throws Exception {
|
||||
// creating instance info
|
||||
final LeaseInfo leaseInfo = getLeaseInfo();
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME,
|
||||
INSTANCE_ID, PORT, leaseInfo);
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo);
|
||||
// calling tested method
|
||||
instanceRegistry.register(instanceInfo, false);
|
||||
// event of proper type is registered
|
||||
assertThat(this.testEvents.applicationEvents.size()).isEqualTo(1);
|
||||
assertThat(this.testEvents.applicationEvents
|
||||
.get(0) instanceof EurekaInstanceRegisteredEvent).isTrue();
|
||||
assertThat(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRegisteredEvent).isTrue();
|
||||
// event details are correct
|
||||
final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents
|
||||
.get(0));
|
||||
assertThat(registeredEvent.getInstanceInfo()).isEqualTo(instanceInfo);
|
||||
assertThat(registeredEvent.getLeaseDuration())
|
||||
.isEqualTo(leaseInfo.getDurationInSecs());
|
||||
assertThat(registeredEvent.getLeaseDuration()).isEqualTo(leaseInfo.getDurationInSecs());
|
||||
assertThat(registeredEvent.getSource()).isEqualTo(instanceRegistry);
|
||||
assertThat(registeredEvent.isReplication()).isFalse();
|
||||
}
|
||||
@@ -100,15 +96,13 @@ public class InstanceRegistryTests {
|
||||
@Test
|
||||
public void testDefaultLeaseDurationRegisterEvent() throws Exception {
|
||||
// creating instance info
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME,
|
||||
INSTANCE_ID, PORT, null);
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
|
||||
// calling tested method
|
||||
instanceRegistry.register(instanceInfo, false);
|
||||
// instance info duration is set to default
|
||||
final EurekaInstanceRegisteredEvent registeredEvent = (EurekaInstanceRegisteredEvent) (this.testEvents.applicationEvents
|
||||
.get(0));
|
||||
assertThat(registeredEvent.getLeaseDuration())
|
||||
.isEqualTo(LeaseInfo.DEFAULT_LEASE_DURATION);
|
||||
assertThat(registeredEvent.getLeaseDuration()).isEqualTo(LeaseInfo.DEFAULT_LEASE_DURATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +111,7 @@ public class InstanceRegistryTests {
|
||||
instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
|
||||
// event of proper type is registered
|
||||
assertThat(this.testEvents.applicationEvents.size()).isEqualTo(1);
|
||||
assertThat(this.testEvents.applicationEvents
|
||||
.get(0) instanceof EurekaInstanceCanceledEvent).isTrue();
|
||||
assertThat(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceCanceledEvent).isTrue();
|
||||
// event details are correct
|
||||
final EurekaInstanceCanceledEvent registeredEvent = (EurekaInstanceCanceledEvent) (this.testEvents.applicationEvents
|
||||
.get(0));
|
||||
@@ -131,13 +124,10 @@ public class InstanceRegistryTests {
|
||||
@Test
|
||||
public void testRenew() throws Exception {
|
||||
// Creating two instances of the app
|
||||
final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME,
|
||||
INSTANCE_ID, PORT, null);
|
||||
final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME,
|
||||
"my-host-name:8009", 8009, null);
|
||||
final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
|
||||
final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME, "my-host-name:8009", 8009, null);
|
||||
// creating application list with an app having two instances
|
||||
final Application application = new Application(APP_NAME,
|
||||
Arrays.asList(instanceInfo1, instanceInfo2));
|
||||
final Application application = new Application(APP_NAME, Arrays.asList(instanceInfo1, instanceInfo2));
|
||||
final List<Application> applications = new ArrayList<>();
|
||||
applications.add(application);
|
||||
// stubbing applications list
|
||||
@@ -147,10 +137,8 @@ public class InstanceRegistryTests {
|
||||
instanceRegistry.renew(APP_NAME, "my-host-name:8009", false);
|
||||
// event of proper type is registered
|
||||
assertThat(this.testEvents.applicationEvents.size()).isEqualTo(2);
|
||||
assertThat(this.testEvents.applicationEvents
|
||||
.get(0) instanceof EurekaInstanceRenewedEvent).isTrue();
|
||||
assertThat(this.testEvents.applicationEvents
|
||||
.get(1) instanceof EurekaInstanceRenewedEvent).isTrue();
|
||||
assertThat(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRenewedEvent).isTrue();
|
||||
assertThat(this.testEvents.applicationEvents.get(1) instanceof EurekaInstanceRenewedEvent).isTrue();
|
||||
// event details are correct
|
||||
final EurekaInstanceRenewedEvent event1 = (EurekaInstanceRenewedEvent) (this.testEvents.applicationEvents
|
||||
.get(0));
|
||||
@@ -172,8 +160,8 @@ public class InstanceRegistryTests {
|
||||
return leaseBuilder.build();
|
||||
}
|
||||
|
||||
private InstanceInfo getInstanceInfo(String appName, String hostName,
|
||||
String instanceId, int port, LeaseInfo leaseInfo) {
|
||||
private InstanceInfo getInstanceInfo(String appName, String hostName, String instanceId, int port,
|
||||
LeaseInfo leaseInfo) {
|
||||
InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
|
||||
builder.setAppName(appName);
|
||||
builder.setHostName(hostName);
|
||||
|
||||
@@ -59,8 +59,7 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RefreshablePeerEurekaNodesTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka-server",
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka-server",
|
||||
"eureka.client.service-url.defaultZone=http://localhost:8678/eureka/" })
|
||||
public class RefreshablePeerEurekaNodesTests {
|
||||
|
||||
@@ -84,11 +83,10 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=true",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://default-host1:8678/eureka/");
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
|
||||
|
||||
assertThat(serviceUrlMatches("https://default-host1:8678/eureka/")).as(
|
||||
"PeerEurekaNodes' are updated when eureka.client.use-dns-for-fetching-service-urls is true")
|
||||
assertThat(serviceUrlMatches("https://default-host1:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are updated when eureka.client.use-dns-for-fetching-service-urls is true")
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@@ -97,54 +95,46 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://default-host2:8678/eureka/");
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
|
||||
|
||||
assertThat(serviceUrlMatches("https://default-host2:8678/eureka/")).as(
|
||||
"PeerEurekaNodes' are not updated when eureka.client.use-dns-for-fetching-service-urls is false")
|
||||
assertThat(serviceUrlMatches("https://default-host2:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are not updated when eureka.client.use-dns-for-fetching-service-urls is false")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedWhenRegionChanged() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=region1",
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region1",
|
||||
"eureka.client.availability-zones.region1=region1-zone",
|
||||
"eureka.client.availability-zones.region2=region2-zone",
|
||||
"eureka.client.service-url.region1-zone=https://region1-zone-host:8678/eureka/",
|
||||
"eureka.client.service-url.region2-zone=https://region2-zone-host:8678/eureka/");
|
||||
this.context
|
||||
.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
|
||||
assertThat(serviceUrlMatches("https://region1-zone-host:8678/eureka/")).as(
|
||||
"PeerEurekaNodes' are not updated when eureka.client.region is changed")
|
||||
.isTrue();
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
|
||||
assertThat(serviceUrlMatches("https://region1-zone-host:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are not updated when eureka.client.region is changed").isTrue();
|
||||
|
||||
changeProperty("eureka.client.region=region2");
|
||||
this.context
|
||||
.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
|
||||
assertThat(serviceUrlMatches("https://region2-zone-host:8678/eureka/")).as(
|
||||
"PeerEurekaNodes' are not updated when eureka.client.region is changed")
|
||||
.isTrue();
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
|
||||
assertThat(serviceUrlMatches("https://region2-zone-host:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are not updated when eureka.client.region is changed").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedWhenAvailabilityZoneChanged() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=region4",
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region4",
|
||||
"eureka.client.availability-zones.region3=region3-zone",
|
||||
"eureka.client.service-url.region4-zone=https://region4-zone-host:8678/eureka/",
|
||||
"eureka.client.service-url.defaultZone=https://default-host3:8678/eureka/");
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
Collections.singleton("eureka.client.availability-zones.region3")));
|
||||
this.context.publishEvent(
|
||||
new EnvironmentChangeEvent(Collections.singleton("eureka.client.availability-zones.region3")));
|
||||
assertThat(this.peerEurekaNodes.getPeerEurekaNodes().get(0).getServiceUrl()
|
||||
.equals("https://default-host3:8678/eureka/")).isTrue();
|
||||
|
||||
changeProperty("eureka.client.availability-zones.region4=region4-zone");
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
Collections.singleton("eureka.client.availability-zones.region4")));
|
||||
assertThat(serviceUrlMatches("https://region4-zone-host:8678/eureka/")).as(
|
||||
"PeerEurekaNodes' are not updated when eureka.client.availability-zones are changed")
|
||||
.isTrue();
|
||||
this.context.publishEvent(
|
||||
new EnvironmentChangeEvent(Collections.singleton("eureka.client.availability-zones.region4")));
|
||||
assertThat(serviceUrlMatches("https://region4-zone-host:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are not updated when eureka.client.availability-zones are changed").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,12 +145,10 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
// Mockito.
|
||||
class VerifyablePeerEurekNode extends RefreshablePeerEurekaNodes {
|
||||
|
||||
VerifyablePeerEurekNode(PeerAwareInstanceRegistry registry,
|
||||
EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
|
||||
ServerCodecs serverCodecs,
|
||||
VerifyablePeerEurekNode(PeerAwareInstanceRegistry registry, EurekaServerConfig serverConfig,
|
||||
EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
|
||||
ApplicationInfoManager applicationInfoManager) {
|
||||
super(registry, serverConfig, clientConfig, serverCodecs,
|
||||
applicationInfoManager,
|
||||
super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager,
|
||||
new ReplicationClientAdditionalFilters(Collections.emptySet()));
|
||||
}
|
||||
|
||||
@@ -171,14 +159,11 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
// Create stubs.
|
||||
final EurekaClientConfigBean configClientBean = mock(
|
||||
EurekaClientConfigBean.class);
|
||||
final EurekaClientConfigBean configClientBean = mock(EurekaClientConfigBean.class);
|
||||
when(configClientBean.isUseDnsForFetchingServiceUrls()).thenReturn(false);
|
||||
final VerifyablePeerEurekNode mock = spy(
|
||||
new VerifyablePeerEurekNode(null, null, configClientBean, null, null));
|
||||
final VerifyablePeerEurekNode mock = spy(new VerifyablePeerEurekNode(null, null, configClientBean, null, null));
|
||||
|
||||
mock.onApplicationEvent(new EnvironmentChangeEvent(
|
||||
Collections.singleton("some.irrelevant.property")));
|
||||
mock.onApplicationEvent(new EnvironmentChangeEvent(Collections.singleton("some.irrelevant.property")));
|
||||
verify(mock, never()).updatePeerEurekaNodes(anyList());
|
||||
}
|
||||
|
||||
@@ -186,8 +171,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
public void peerEurekaNodesIsRefreshablePeerEurekaNodes() {
|
||||
assertThat(this.peerEurekaNodes).isNotNull();
|
||||
assertThat(this.peerEurekaNodes instanceof RefreshablePeerEurekaNodes)
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes")
|
||||
.isTrue();
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,14 +179,13 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
changeProperty(
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host3:8678/eureka/,http://defaul-host4:8678/eureka/");
|
||||
forceUpdate();
|
||||
assertThat(this.peerEurekaNodes.getPeerEurekaNodes().size())
|
||||
.as("PeerEurekaNodes' peer count is incorrect.").isEqualTo(2);
|
||||
assertThat(this.peerEurekaNodes.getPeerEurekaNodes().size()).as("PeerEurekaNodes' peer count is incorrect.")
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlsValueAsSoonAsRefreshed() {
|
||||
changeProperty(
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host4:8678/eureka/");
|
||||
changeProperty("eureka.client.service-url.defaultZone=https://defaul-host4:8678/eureka/");
|
||||
forceUpdate();
|
||||
assertThat(serviceUrlMatches("https://defaul-host4:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' new peer[0] is incorrect").isTrue();
|
||||
@@ -210,11 +193,10 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
|
||||
@Test
|
||||
public void dashboardUpdatedAsSoonAsRefreshed() {
|
||||
changeProperty(
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host5:8678/eureka/");
|
||||
changeProperty("eureka.client.service-url.defaultZone=https://defaul-host5:8678/eureka/");
|
||||
forceUpdate();
|
||||
final ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/", String.class);
|
||||
final ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
final String body = entity.getBody();
|
||||
assertThat(body).isNotNull();
|
||||
@@ -227,11 +209,10 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host6:8678/eureka/");
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
Collections.singleton("eureka.client.serviceUrl.defaultZone")));
|
||||
this.context.publishEvent(
|
||||
new EnvironmentChangeEvent(Collections.singleton("eureka.client.serviceUrl.defaultZone")));
|
||||
assertThat(serviceUrlMatches("https://defaul-host6:8678/eureka/"))
|
||||
.as("PeerEurekaNodes' are updated for keys with relaxed binding")
|
||||
.isFalse();
|
||||
.as("PeerEurekaNodes' are updated for keys with relaxed binding").isFalse();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -247,16 +228,15 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
private void forceUpdate() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=unavailable-region"); // to force defaultZone
|
||||
this.context.publishEvent(new EnvironmentChangeEvent(
|
||||
Collections.singleton("eureka.client.service-url.defaultZone")));
|
||||
this.context.publishEvent(
|
||||
new EnvironmentChangeEvent(Collections.singleton("eureka.client.service-url.defaultZone")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Whether the first element in PeerEurekaNodes matches the given url.
|
||||
*/
|
||||
private boolean serviceUrlMatches(final String serviceUrl) {
|
||||
return this.peerEurekaNodes.getPeerEurekaNodes().get(0).getServiceUrl()
|
||||
.equals(serviceUrl);
|
||||
return this.peerEurekaNodes.getPeerEurekaNodes().get(0).getServiceUrl().equals(serviceUrl);
|
||||
}
|
||||
|
||||
@EnableEurekaServer
|
||||
|
||||
@@ -42,11 +42,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Yuxin Bai
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
classes = RefreshablePeerEurekaNodesWithCustomFiltersTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka", "server.contextPath=/context",
|
||||
"management.security.enabled=false" })
|
||||
@SpringBootTest(classes = RefreshablePeerEurekaNodesWithCustomFiltersTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka",
|
||||
"server.contextPath=/context", "management.security.enabled=false" })
|
||||
public class RefreshablePeerEurekaNodesWithCustomFiltersTests {
|
||||
|
||||
@Autowired
|
||||
@@ -55,20 +53,14 @@ public class RefreshablePeerEurekaNodesWithCustomFiltersTests {
|
||||
@Test
|
||||
public void testCustomPeerNodesShouldTakePrecedenceOverDefault() {
|
||||
assertThat(peerEurekaNodes instanceof RefreshablePeerEurekaNodes)
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes")
|
||||
.isTrue();
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes").isTrue();
|
||||
|
||||
ReplicationClientAdditionalFilters filters = getField(
|
||||
RefreshablePeerEurekaNodes.class,
|
||||
(RefreshablePeerEurekaNodes) peerEurekaNodes,
|
||||
"replicationClientAdditionalFilters");
|
||||
assertThat(filters.getFilters()).as(
|
||||
"PeerEurekaNodes'should have only one filter set on replicationClientAdditionalFilters")
|
||||
.hasSize(1);
|
||||
assertThat(filters.getFilters().iterator()
|
||||
.next() instanceof Application.CustomClientFilter).as(
|
||||
"The type of the filter should be CustomClientFilter as user declared so")
|
||||
.isTrue();
|
||||
ReplicationClientAdditionalFilters filters = getField(RefreshablePeerEurekaNodes.class,
|
||||
(RefreshablePeerEurekaNodes) peerEurekaNodes, "replicationClientAdditionalFilters");
|
||||
assertThat(filters.getFilters())
|
||||
.as("PeerEurekaNodes'should have only one filter set on replicationClientAdditionalFilters").hasSize(1);
|
||||
assertThat(filters.getFilters().iterator().next() instanceof Application.CustomClientFilter)
|
||||
.as("The type of the filter should be CustomClientFilter as user declared so").isTrue();
|
||||
}
|
||||
|
||||
private static <T, R> R getField(Class<T> clazz, T target, String fieldName) {
|
||||
@@ -86,8 +78,7 @@ public class RefreshablePeerEurekaNodesWithCustomFiltersTests {
|
||||
|
||||
@Bean
|
||||
public ReplicationClientAdditionalFilters customFilters() {
|
||||
return new ReplicationClientAdditionalFilters(
|
||||
Collections.singletonList(new CustomClientFilter()));
|
||||
return new ReplicationClientAdditionalFilters(Collections.singletonList(new CustomClientFilter()));
|
||||
}
|
||||
|
||||
protected class CustomClientFilter extends ClientFilter {
|
||||
|
||||
@@ -79,8 +79,7 @@ public abstract class AbstractDocumentationTests {
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
|
||||
@Rule
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(
|
||||
"target/generated-snippets");
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
|
||||
|
||||
@After
|
||||
public void init() {
|
||||
@@ -116,8 +115,7 @@ public abstract class AbstractDocumentationTests {
|
||||
|
||||
private RestDocumentationFilter filter(String name) {
|
||||
return RestAssuredRestDocumentation.document(name,
|
||||
preprocessRequest(modifyUris().host("eureka.example.com").removePort(),
|
||||
prettyPrint()),
|
||||
preprocessRequest(modifyUris().host("eureka.example.com").removePort(), prettyPrint()),
|
||||
preprocessResponse(prettyPrint()));
|
||||
}
|
||||
|
||||
@@ -164,20 +162,17 @@ public abstract class AbstractDocumentationTests {
|
||||
@EnableEurekaServer
|
||||
protected static class Application {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(DefaultEurekaServerContext.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultEurekaServerContext.class);
|
||||
|
||||
@Bean
|
||||
public EurekaServerContext testEurekaServerContext(ServerCodecs serverCodecs,
|
||||
PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes,
|
||||
ApplicationInfoManager applicationInfoManager,
|
||||
EurekaServerConfig eurekaServerConfig) {
|
||||
return new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs,
|
||||
registry, peerEurekaNodes, applicationInfoManager) {
|
||||
ApplicationInfoManager applicationInfoManager, EurekaServerConfig eurekaServerConfig) {
|
||||
return new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, peerEurekaNodes,
|
||||
applicationInfoManager) {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
logger.info(
|
||||
"Shutting down (except ServoControl and EurekaMonitors)..");
|
||||
logger.info("Shutting down (except ServoControl and EurekaMonitors)..");
|
||||
registry.shutdown();
|
||||
peerEurekaNodes.shutdown();
|
||||
// ServoControl.shutdown();
|
||||
|
||||
@@ -41,10 +41,8 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
|
||||
@Test
|
||||
public void startingApp() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps").then()
|
||||
.assertThat()
|
||||
.body("applications.application", hasSize(1),
|
||||
"applications.application[0].instance[0].status",
|
||||
document().accept("application/json").when().get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", hasSize(1), "applications.application[0].instance[0].status",
|
||||
equalTo("STARTING"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
@@ -52,10 +50,8 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
|
||||
@Test
|
||||
public void addInstance() throws Exception {
|
||||
document(instance("foo"))
|
||||
.filter(verify("$.instance.app").json("$.instance.hostName")
|
||||
.json("$.instance[?(@.status=='STARTING')]")
|
||||
.json("$.instance.instanceId")
|
||||
.json("$.instance.dataCenterInfo.name"))
|
||||
.filter(verify("$.instance.app").json("$.instance.hostName").json("$.instance[?(@.status=='STARTING')]")
|
||||
.json("$.instance.instanceId").json("$.instance.dataCenterInfo.name"))
|
||||
.when().post("/eureka/apps/FOO").then().assertThat().statusCode(is(204));
|
||||
}
|
||||
|
||||
@@ -63,63 +59,58 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
|
||||
public void setStatus() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document()
|
||||
.filter(verify(put(urlPathMatching("/eureka/apps/FOO/.*/status"))
|
||||
.withQueryParam("value", matching("UP"))))
|
||||
.when().put("/eureka/apps/FOO/{id}/status?value={value}", id, "UP").then()
|
||||
.assertThat().statusCode(is(200));
|
||||
.filter(verify(
|
||||
put(urlPathMatching("/eureka/apps/FOO/.*/status")).withQueryParam("value", matching("UP"))))
|
||||
.when().put("/eureka/apps/FOO/{id}/status?value={value}", id, "UP").then().assertThat()
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allApps() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps").then()
|
||||
.assertThat().body("applications.application", hasSize(1))
|
||||
.statusCode(is(200));
|
||||
document().accept("application/json").when().get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", hasSize(1)).statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delta() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps/delta").then()
|
||||
.assertThat().body("applications.application", hasSize(1))
|
||||
.statusCode(is(200));
|
||||
document().accept("application/json").when().get("/eureka/apps/delta").then().assertThat()
|
||||
.body("applications.application", hasSize(1)).statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneInstance() throws Exception {
|
||||
String id = UUID.randomUUID().toString();
|
||||
register("foo", id);
|
||||
document().filter(verify(get(urlPathMatching("/eureka/apps/FOO/.*"))))
|
||||
.accept("application/json").when().get("/eureka/apps/FOO/{id}", id).then()
|
||||
.assertThat().body("instance.app", equalTo("FOO")).statusCode(is(200));
|
||||
document().filter(verify(get(urlPathMatching("/eureka/apps/FOO/.*")))).accept("application/json").when()
|
||||
.get("/eureka/apps/FOO/{id}", id).then().assertThat().body("instance.app", equalTo("FOO"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupInstance() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(get(urlPathMatching("/eureka/instances/.*"))))
|
||||
.accept("application/json").when().get("/eureka/instances/{id}", id)
|
||||
.then().assertThat().body("instance.app", equalTo("FOO"))
|
||||
document().filter(verify(get(urlPathMatching("/eureka/instances/.*")))).accept("application/json").when()
|
||||
.get("/eureka/instances/{id}", id).then().assertThat().body("instance.app", equalTo("FOO"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renew() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(put(urlPathMatching("/eureka/apps/FOO/.*"))))
|
||||
.accept("application/json").when().put("/eureka/apps/FOO/{id}", id).then()
|
||||
.assertThat().statusCode(is(200));
|
||||
document().filter(verify(put(urlPathMatching("/eureka/apps/FOO/.*")))).accept("application/json").when()
|
||||
.put("/eureka/apps/FOO/{id}", id).then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateMetadata() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document()
|
||||
.filter(verify(put(urlPathMatching("/eureka/apps/FOO/.*/metadata"))
|
||||
.withQueryParam("key", matching(".*"))))
|
||||
.accept("application/json").when()
|
||||
.put("/eureka/apps/FOO/{id}/metadata?key=value", id).then().assertThat()
|
||||
.statusCode(is(200));
|
||||
.filter(verify(
|
||||
put(urlPathMatching("/eureka/apps/FOO/.*/metadata")).withQueryParam("key", matching(".*"))))
|
||||
.accept("application/json").when().put("/eureka/apps/FOO/{id}/metadata?key=value", id).then()
|
||||
.assertThat().statusCode(is(200));
|
||||
assertThat(instance().getMetadata()).containsEntry("key", "value");
|
||||
}
|
||||
|
||||
@@ -127,15 +118,13 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
|
||||
public void deleteInstance() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(delete(urlPathMatching("/eureka/apps/FOO/.*")))).when()
|
||||
.delete("/eureka/apps/FOO/{id}", id).then().assertThat()
|
||||
.statusCode(is(200));
|
||||
.delete("/eureka/apps/FOO/{id}", id).then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyApps() {
|
||||
document().when().accept("application/json").get("/eureka/apps").then()
|
||||
.assertThat().body("applications.application", emptyIterable())
|
||||
.statusCode(is(200));
|
||||
document().when().accept("application/json").get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", emptyIterable()).statusCode(is(200));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ final class EurekaObjectMapper implements io.restassured.mapper.ObjectMapper {
|
||||
public Object serialize(ObjectMapperSerializationContext context) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
converter.write(context.getObjectToSerialize(), out,
|
||||
MediaType.APPLICATION_JSON_TYPE);
|
||||
converter.write(context.getObjectToSerialize(), out, MediaType.APPLICATION_JSON_TYPE);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot serialize", e);
|
||||
@@ -45,8 +44,8 @@ final class EurekaObjectMapper implements io.restassured.mapper.ObjectMapper {
|
||||
@Override
|
||||
public Object deserialize(ObjectMapperDeserializationContext context) {
|
||||
try {
|
||||
return converter.read(context.getDataToDeserialize().asInputStream(),
|
||||
(Class) context.getType(), MediaType.APPLICATION_JSON_TYPE);
|
||||
return converter.read(context.getDataToDeserialize().asInputStream(), (Class) context.getType(),
|
||||
MediaType.APPLICATION_JSON_TYPE);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot deserialize", e);
|
||||
|
||||
@@ -31,16 +31,15 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
// TODO: maybe this should be the default (the test fails without it because the JSON is
|
||||
// invalid)
|
||||
@TestPropertySource(
|
||||
properties = { "eureka.server.minAvailableInstancesForPeerReplication=0",
|
||||
"spring.jmx.enabled=false" })
|
||||
properties = { "eureka.server.minAvailableInstancesForPeerReplication=0", "spring.jmx.enabled=false" })
|
||||
public class EurekaServerTests extends AbstractDocumentationTests {
|
||||
|
||||
@Test
|
||||
public void serverStatus() throws Exception {
|
||||
register("foo", UUID.randomUUID().toString());
|
||||
document().accept("application/json").when().get("/eureka/status").then()
|
||||
.assertThat().body("generalStats", notNullValue(), "applicationStats",
|
||||
notNullValue(), "instanceInfo", notNullValue())
|
||||
document()
|
||||
.accept("application/json").when().get("/eureka/status").then().assertThat().body("generalStats",
|
||||
notNullValue(), "applicationStats", notNullValue(), "instanceInfo", notNullValue())
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
|
||||
@@ -94,50 +94,43 @@ public class RequestVerifierFilter implements Filter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response filter(FilterableRequestSpecification requestSpec,
|
||||
FilterableResponseSpecification responseSpec, FilterContext context) {
|
||||
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec,
|
||||
FilterContext context) {
|
||||
Map<String, Object> configuration = getConfiguration(requestSpec, context);
|
||||
configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
|
||||
Response response = context.next(requestSpec, responseSpec);
|
||||
if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
|
||||
String actual = new String((byte[]) requestSpec.getBody());
|
||||
for (JsonPath jsonPath : this.jsonPaths.values()) {
|
||||
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class,
|
||||
"an object");
|
||||
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class, "an object");
|
||||
}
|
||||
}
|
||||
if (this.builder != null) {
|
||||
this.builder.willReturn(getResponseDefinition(response));
|
||||
StubMapping stubMapping = this.builder.build();
|
||||
MatchResult match = stubMapping.getRequest()
|
||||
.match(new WireMockRestAssuredRequestAdapter(requestSpec));
|
||||
assertThat(match.isExactMatch()).as("wiremock did not match request")
|
||||
.isTrue();
|
||||
MatchResult match = stubMapping.getRequest().match(new WireMockRestAssuredRequestAdapter(requestSpec));
|
||||
assertThat(match.isExactMatch()).as("wiremock did not match request").isTrue();
|
||||
configuration.put("contract.stubMapping", stubMapping);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private ResponseDefinitionBuilder getResponseDefinition(Response response) {
|
||||
ResponseDefinitionBuilder definition = ResponseDefinitionBuilder
|
||||
.responseDefinition().withBody(response.getBody().asString())
|
||||
.withStatus(response.getStatusCode());
|
||||
ResponseDefinitionBuilder definition = ResponseDefinitionBuilder.responseDefinition()
|
||||
.withBody(response.getBody().asString()).withStatus(response.getStatusCode());
|
||||
addResponseHeaders(definition, response);
|
||||
return definition;
|
||||
}
|
||||
|
||||
private void addResponseHeaders(ResponseDefinitionBuilder definition,
|
||||
Response input) {
|
||||
private void addResponseHeaders(ResponseDefinitionBuilder definition, Response input) {
|
||||
for (Header header : input.getHeaders().asList()) {
|
||||
String name = header.getName();
|
||||
definition.withHeader(name, input.getHeader(name));
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, Object> getConfiguration(
|
||||
FilterableRequestSpecification requestSpec, FilterContext context) {
|
||||
Map<String, Object> configuration = context
|
||||
.<Map<String, Object>>getValue(CONTEXT_KEY_CONFIGURATION);
|
||||
protected Map<String, Object> getConfiguration(FilterableRequestSpecification requestSpec, FilterContext context) {
|
||||
Map<String, Object> configuration = context.<Map<String, Object>>getValue(CONTEXT_KEY_CONFIGURATION);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@@ -197,8 +190,7 @@ class JsonPathValue {
|
||||
}
|
||||
|
||||
private String getExpectedValueMessage(String expectedDescription) {
|
||||
return String.format("Expected %s at JSON path \"%s\" but found: %s",
|
||||
expectedDescription, this.expression,
|
||||
return String.format("Expected %s at JSON path \"%s\" but found: %s", expectedDescription, this.expression,
|
||||
ObjectUtils.nullSafeToString(StringUtils.quoteIfString(getValue(false))));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user