Commit 756c6742 by Johannes Edmeier Committed by Johannes Edmeier

Rename client properties to `spring.boot.admin.client.*`

The Spring team discourages the use of the `spring.*` configuration namespace, hence I use the major update and move all properties. With this commit all client related properties are moved to `sbadmin.client`.
parent c60473e0
...@@ -68,65 +68,65 @@ TIP: There are plenty of properties to influence the way how the SBA Client regi ...@@ -68,65 +68,65 @@ TIP: There are plenty of properties to influence the way how the SBA Client regi
| Enables the Spring Boot Admin Client. | Enables the Spring Boot Admin Client.
| `true` | `true`
| spring.boot.admin.url | spring.boot.admin.client.url
| Comma separated ordered list of URLs of the Spring Boot Admin server to register at. This triggers the AutoConfiguration. *Mandatory*. | Comma separated ordered list of URLs of the Spring Boot Admin server to register at. This triggers the AutoConfiguration. *Mandatory*.
| |
| spring.boot.admin.api-path | spring.boot.admin.client.api-path
| Http-path of registration endpoint at your admin server. | Http-path of registration endpoint at your admin server.
| `"api/applications"` | `"api/applications"`
| spring.boot.admin.username + | spring.boot.admin.client.username +
spring.boot.admin.password spring.boot.admin.client.password
| Username and password in case the SBA Server api is protected with HTTP Basic authentication. | Username and password in case the SBA Server api is protected with HTTP Basic authentication.
| |
| spring.boot.admin.period | spring.boot.admin.client.period
| Interval for repeating the registration (in ms). | Interval for repeating the registration (in ms).
| `10.000` | `10.000`
| spring.boot.admin.auto-registration | spring.boot.admin.client.auto-registration
| If set to true the periodic task to register the application is automatically scheduled after the application is ready. | If set to true the periodic task to register the application is automatically scheduled after the application is ready.
| `true` | `true`
| spring.boot.admin.auto-deregistration | spring.boot.admin.client.auto-deregistration
| Switch to enable auto-deregistration at Spring Boot Admin server when context is closed. | Switch to enable auto-deregistration at Spring Boot Admin server when context is closed.
| `false` | `false`
| spring.boot.admin.register-once | spring.boot.admin.client.register-once
| If set to true the client will only register against one admin server (in order defined by `spring.boot.admin.url`); if that admin server goes down, will automatically register against the next admin server. If false, will register against all admin servers. | If set to true the client will only register against one admin server (in order defined by `spring.boot.admin.instance.url`); if that admin server goes down, will automatically register against the next admin server. If false, will register against all admin servers.
| `true` | `true`
| spring.boot.admin.client.health-url | spring.boot.admin.client.instance.health-url
| Client-health-url to register with. Can be overridden in case the reachable URL is different (e.g. Docker). Must be unique in registry. | Health-url to register with. Can be overridden in case the reachable URL is different (e.g. Docker). Must be unique in registry.
| Guessed based on management-url and `endpoints.health.id`. | Guessed based on management-url and `endpoints.health.id`.
| spring.boot.admin.client.management-base-url | spring.boot.admin.client.instance.management-base-url
| Base url for computing the management-url to register with. The path is inferred at runtime, and appended to the base url. | Base url for computing the management-url to register with. The path is inferred at runtime, and appended to the base url.
| Guessed based on `management.port`, service-url and `server.servlet-path`. | Guessed based on `management.port`, service-url and `server.servlet-path`.
| spring.boot.admin.client.management-url | spring.boot.admin.client.instance.management-url
| Management-url to register with. Can be overridden in case the reachable url is different (e.g. Docker). | Management-url to register with. Can be overridden in case the reachable url is different (e.g. Docker).
| Guessed based on managment-base-url and `management.context-path`. | Guessed based on managment-base-url and `management.context-path`.
| spring.boot.admin.client.service-base-url | spring.boot.admin.client.instance.service-base-url
| Base url for computing the service-url to register with. The path is inferred at runtime, and appended to the base url. | Base url for computing the service-url to register with. The path is inferred at runtime, and appended to the base url.
| Guessed based on hostname, `server.port`. | Guessed based on hostname, `server.port`.
| spring.boot.admin.client.service-url | spring.boot.admin.client.instance.service-url
| Client-service-url to register with. Can be overridden in case the reachable url is different (e.g. Docker). | Service-url to register with. Can be overridden in case the reachable url is different (e.g. Docker).
| Guessed based on service-base-url and `server.context-path`. | Guessed based on service-base-url and `server.context-path`.
| spring.boot.admin.client.name | spring.boot.admin.client.instance.name
| Name to register with. | Name to register with.
| `${spring.application.name}` if set, `"spring-boot-application"` otherwise. | `${spring.application.name}` if set, `"spring-boot-application"` otherwise.
| spring.boot.admin.client.prefer-ip | spring.boot.admin.client.instance.prefer-ip
| Use the ip-address rather then the hostname in the guessed urls. If `server.address` / `management.address` is set, it get used. Otherwise the IP address returned from `InetAddress.getLocalHost()` gets used. | Use the ip-address rather then the hostname in the guessed urls. If `server.address` / `management.address` is set, it get used. Otherwise the IP address returned from `InetAddress.getLocalHost()` gets used.
| `false` | `false`
| spring.boot.admin.client.metadata.* | spring.boot.admin.client.instance.metadata.*
| Metadata key-value-pairs to be associated with this instance. | Metadata key-value-pairs to be asscoiated with this instance.
| |
|=== |===
......
...@@ -68,7 +68,7 @@ Each application that wants to register has to include the Spring Boot Admin Cli ...@@ -68,7 +68,7 @@ Each application that wants to register has to include the Spring Boot Admin Cli
[source,yml] [source,yml]
.application.yml .application.yml
---- ----
spring.boot.admin.url: http://localhost:8080 #<1> spring.boot.admin.client.url: http://localhost:8080 #<1>
management.security.enabled: false #<2> management.security.enabled: false #<2>
---- ----
<1> The URL of the Spring Boot Admin Server to register at. <1> The URL of the Spring Boot Admin Server to register at.
......
...@@ -14,7 +14,7 @@ include::{samples-dir}/spring-boot-admin-sample/src/main/java/de/codecentric/boo ...@@ -14,7 +14,7 @@ include::{samples-dir}/spring-boot-admin-sample/src/main/java/de/codecentric/boo
For a complete sample look at https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample/[spring-boot-admin-sample]. For a complete sample look at https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample/[spring-boot-admin-sample].
NOTE: If you protect the `/api/applications` endpoint don't forget to configure the username and password on your SBA-Client using `spring.boot.admin.username` and `spring.boot.admin.password`. NOTE: If you protect the `/api/applications` endpoint don't forget to configure the username and password on your SBA-Client using `spring.boot.admin.client.username` and `spring.boot.admin.instance.password`.
TIP: There are more samples (e.g. using OAuth2) in https://github.com/joshiste/spring-boot-admin-samples[joshiste/spring-boot-admin-samples^]. TIP: There are more samples (e.g. using OAuth2) in https://github.com/joshiste/spring-boot-admin-samples[joshiste/spring-boot-admin-samples^].
...@@ -26,9 +26,9 @@ Submitting the credentials using SBA Client: ...@@ -26,9 +26,9 @@ Submitting the credentials using SBA Client:
[source,yaml] [source,yaml]
.application.yml .application.yml
---- ----
spring.boot.admin: spring.boot.admin.client:
url: http://localhost:8080 url: http://localhost:8080
client: instance:
metadata: metadata:
user.name: ${security.user.name} user.name: ${security.user.name}
user.password: ${security.user.password} user.password: ${security.user.password}
......
...@@ -3,5 +3,4 @@ server.port=8081 ...@@ -3,5 +3,4 @@ server.port=8081
info.stage=test info.stage=test
logging.file=/tmp/log.log logging.file=/tmp/log.log
spring.application.name=@pom.artifactId@ spring.application.name=@pom.artifactId@
spring.boot.admin.client.url=http://localhost:8081
spring.boot.admin.url=http://localhost:8081 \ No newline at end of file
\ No newline at end of file
...@@ -15,6 +15,7 @@ spring: ...@@ -15,6 +15,7 @@ spring:
name: "@pom.artifactId@" name: "@pom.artifactId@"
boot: boot:
admin: admin:
client:
url: http://localhost:8080 url: http://localhost:8080
profiles: profiles:
active: active:
...@@ -37,9 +38,10 @@ spring: ...@@ -37,9 +38,10 @@ spring:
profiles: secure profiles: secure
boot: boot:
admin: admin:
client:
username: "${security.user.name}" #These two are needed so that the client username: "${security.user.name}" #These two are needed so that the client
password: "${security.user.password}" #can register at the protected server api password: "${security.user.password}" #can register at the protected server api
client: instance:
metadata: metadata:
user.name: "${security.user.name}" #These two are needed so that the server user.name: "${security.user.name}" #These two are needed so that the server
user.password: "${security.user.password}" #can access the proteceted client endpoints user.password: "${security.user.password}" #can access the proteceted client endpoints
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2923,7 +2923,7 @@ sntp@1.x.x: ...@@ -2923,7 +2923,7 @@ sntp@1.x.x:
sockjs-client@^1.0.3: sockjs-client@^1.0.3:
version "1.1.4" version "1.1.4"
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12" resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-instance-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12"
dependencies: dependencies:
debug "^2.6.6" debug "^2.6.6"
eventsource "0.1.6" eventsource "0.1.6"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin</artifactId> <artifactId>spring-boot-admin</artifactId>
<version>1.5.1-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-boot-admin-server-ui-login</artifactId> <artifactId>spring-boot-admin-server-ui-login</artifactId>
......
...@@ -2907,7 +2907,7 @@ sntp@1.x.x: ...@@ -2907,7 +2907,7 @@ sntp@1.x.x:
sockjs-client@^1.0.3: sockjs-client@^1.0.3:
version "1.1.4" version "1.1.4"
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12" resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-instance-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12"
dependencies: dependencies:
debug "^2.6.6" debug "^2.6.6"
eventsource "0.1.6" eventsource "0.1.6"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -963,7 +963,7 @@ encoding@^0.1.11: ...@@ -963,7 +963,7 @@ encoding@^0.1.11:
engine.io-client@1.6.9: engine.io-client@1.6.9:
version "1.6.9" version "1.6.9"
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-1.6.9.tgz#1d6ad48048a5083c95096943b29d36efdb212401" resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-instance-1.6.9.tgz#1d6ad48048a5083c95096943b29d36efdb212401"
dependencies: dependencies:
component-emitter "1.1.2" component-emitter "1.1.2"
component-inherit "0.0.3" component-inherit "0.0.3"
...@@ -3565,7 +3565,7 @@ socket.io-adapter@0.4.0: ...@@ -3565,7 +3565,7 @@ socket.io-adapter@0.4.0:
socket.io-client@1.4.6: socket.io-client@1.4.6:
version "1.4.6" version "1.4.6"
resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-1.4.6.tgz#49b0ba537efd15b8297c84016e642e1c7c752c3d" resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-instance-1.4.6.tgz#49b0ba537efd15b8297c84016e642e1c7c752c3d"
dependencies: dependencies:
backo2 "1.0.2" backo2 "1.0.2"
component-bind "1.0.0" component-bind "1.0.0"
...@@ -3612,7 +3612,7 @@ socket.io@1.4.7: ...@@ -3612,7 +3612,7 @@ socket.io@1.4.7:
sockjs-client@^1.0.3: sockjs-client@^1.0.3:
version "1.1.4" version "1.1.4"
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12" resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-instance-1.1.4.tgz#5babe386b775e4cf14e7520911452654016c8b12"
dependencies: dependencies:
debug "^2.6.6" debug "^2.6.6"
eventsource "0.1.6" eventsource "0.1.6"
......
...@@ -17,8 +17,8 @@ package de.codecentric.boot.admin.client.config; ...@@ -17,8 +17,8 @@ package de.codecentric.boot.admin.client.config;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.boot.admin") @ConfigurationProperties(prefix = "spring.boot.admin.client")
public class AdminProperties { public class ClientProperties {
/** /**
* The admin server urls to register at * The admin server urls to register at
......
...@@ -20,8 +20,8 @@ import java.util.Map; ...@@ -20,8 +20,8 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.boot.admin.client") @ConfigurationProperties(prefix = "spring.boot.admin.client.instance")
public class AdminClientProperties { public class InstanceProperties {
/** /**
* Management-url to register with. Inferred at runtime, can be overridden in case the * Management-url to register with. Inferred at runtime, can be overridden in case the
* reachable URL is different (e.g. Docker). * reachable URL is different (e.g. Docker).
......
...@@ -37,31 +37,31 @@ import org.springframework.scheduling.TaskScheduler; ...@@ -37,31 +37,31 @@ import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@Configuration @Configuration
@EnableConfigurationProperties({AdminProperties.class, AdminClientProperties.class}) @EnableConfigurationProperties({ClientProperties.class, InstanceProperties.class})
@Conditional(SpringBootAdminClientEnabledCondition.class) @Conditional(SpringBootAdminClientEnabledCondition.class)
public class SpringBootAdminClientAutoConfiguration { public class SpringBootAdminClientAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ApplicationRegistrator registrator(AdminProperties admin, public ApplicationRegistrator registrator(ClientProperties client,
ApplicationFactory applicationFactory, ApplicationFactory applicationFactory,
RestTemplateBuilder restTemplBuilder) { RestTemplateBuilder restTemplBuilder) {
RestTemplateBuilder builder = restTemplBuilder.messageConverters(new MappingJackson2HttpMessageConverter()) RestTemplateBuilder builder = restTemplBuilder.messageConverters(new MappingJackson2HttpMessageConverter())
.requestFactory(SimpleClientHttpRequestFactory.class); .requestFactory(SimpleClientHttpRequestFactory.class);
if (admin.getUsername() != null) { if (client.getUsername() != null) {
builder = builder.basicAuthorization(admin.getUsername(), admin.getPassword()); builder = builder.basicAuthorization(client.getUsername(), client.getPassword());
} }
return new ApplicationRegistrator(builder.build(), admin, applicationFactory); return new ApplicationRegistrator(builder.build(), client, applicationFactory);
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ApplicationFactory applicationFactory(AdminClientProperties client, public ApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath, @Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath,
ServletContext servletContext) { ServletContext servletContext) {
return new DefaultApplicationFactory(client, management, server, servletContext, healthEndpointPath); return new DefaultApplicationFactory(instance, management, server, servletContext, healthEndpointPath);
} }
@Bean @Bean
...@@ -76,13 +76,13 @@ public class SpringBootAdminClientAutoConfiguration { ...@@ -76,13 +76,13 @@ public class SpringBootAdminClientAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public RegistrationApplicationListener registrationListener(AdminProperties admin, public RegistrationApplicationListener registrationListener(ClientProperties client,
ApplicationRegistrator registrator) { ApplicationRegistrator registrator) {
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator,
registrationTaskScheduler()); registrationTaskScheduler());
listener.setAutoRegister(admin.isAutoRegistration()); listener.setAutoRegister(client.isAutoRegistration());
listener.setAutoDeregister(admin.isAutoDeregistration()); listener.setAutoDeregister(client.isAutoDeregistration());
listener.setRegisterPeriod(admin.getPeriod()); listener.setRegisterPeriod(client.getPeriod());
return listener; return listener;
} }
} }
...@@ -25,9 +25,9 @@ import org.springframework.util.StringUtils; ...@@ -25,9 +25,9 @@ import org.springframework.util.StringUtils;
/** /**
* This condition checks if the client should be enabled. Two properties are checked: * This condition checks if the client should be enabled. Two properties are checked:
* spring.boot.admin.client.enabled and spring.boot.admin.url. The following table shows under which * spring.boot.admin.client.enabled and spring.boot.admin.url. The following table shows under which conditions the
* conditions the client is active. * client is active.
* * <p>
* <pre> * <pre>
* | enabled: false | enabled: true (default) | * | enabled: false | enabled: true (default) |
* --------- | -------------- | ----------------------- | * --------- | -------------- | ----------------------- |
...@@ -39,8 +39,7 @@ import org.springframework.util.StringUtils; ...@@ -39,8 +39,7 @@ import org.springframework.util.StringUtils;
*/ */
public class SpringBootAdminClientEnabledCondition extends SpringBootCondition { public class SpringBootAdminClientEnabledCondition extends SpringBootCondition {
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
AnnotatedTypeMetadata annotatedTypeMetadata) {
if (!isEnabled(context.getEnvironment())) { if (!isEnabled(context.getEnvironment())) {
return ConditionOutcome.noMatch( return ConditionOutcome.noMatch(
...@@ -56,13 +55,12 @@ public class SpringBootAdminClientEnabledCondition extends SpringBootCondition { ...@@ -56,13 +55,12 @@ public class SpringBootAdminClientEnabledCondition extends SpringBootCondition {
} }
private boolean isEnabled(Environment env) { private boolean isEnabled(Environment env) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(env, RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(env, "spring.boot.admin.client.");
"spring.boot.admin.client.");
return resolver.getProperty("enabled", Boolean.class, Boolean.TRUE); return resolver.getProperty("enabled", Boolean.class, Boolean.TRUE);
} }
private boolean isUrlEmpty(Environment env) { private boolean isUrlEmpty(Environment env) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(env, "spring.boot.admin."); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(env, "spring.boot.admin.client.");
return StringUtils.isEmpty(resolver.getProperty("url", "")); return StringUtils.isEmpty(resolver.getProperty("url", ""));
} }
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package de.codecentric.boot.admin.client.registration; package de.codecentric.boot.admin.client.registration;
import de.codecentric.boot.admin.client.config.AdminProperties; import de.codecentric.boot.admin.client.config.ClientProperties;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
...@@ -38,12 +38,14 @@ public class ApplicationRegistrator { ...@@ -38,12 +38,14 @@ public class ApplicationRegistrator {
private static final HttpHeaders HTTP_HEADERS = createHttpHeaders(); private static final HttpHeaders HTTP_HEADERS = createHttpHeaders();
private final AtomicInteger unsuccessfulAttempts = new AtomicInteger(0); private final AtomicInteger unsuccessfulAttempts = new AtomicInteger(0);
private final AtomicReference<String> registeredId = new AtomicReference<>(); private final AtomicReference<String> registeredId = new AtomicReference<>();
private final AdminProperties admin; private final ClientProperties client;
private final RestTemplate template; private final RestTemplate template;
private final ApplicationFactory applicationFactory; private final ApplicationFactory applicationFactory;
public ApplicationRegistrator(RestTemplate template, AdminProperties admin, ApplicationFactory applicationFactory) { public ApplicationRegistrator(RestTemplate template,
this.admin = admin; ClientProperties client,
ApplicationFactory applicationFactory) {
this.client = client;
this.template = template; this.template = template;
this.applicationFactory = applicationFactory; this.applicationFactory = applicationFactory;
} }
...@@ -63,7 +65,7 @@ public class ApplicationRegistrator { ...@@ -63,7 +65,7 @@ public class ApplicationRegistrator {
public boolean register() { public boolean register() {
boolean isRegistrationSuccessful = false; boolean isRegistrationSuccessful = false;
Application self = createApplication(); Application self = createApplication();
for (String adminUrl : admin.getAdminUrl()) { for (String adminUrl : client.getAdminUrl()) {
try { try {
@SuppressWarnings("rawtypes") ResponseEntity<Map> response = template.postForEntity(adminUrl, @SuppressWarnings("rawtypes") ResponseEntity<Map> response = template.postForEntity(adminUrl,
new HttpEntity<>(self, HTTP_HEADERS), Map.class); new HttpEntity<>(self, HTTP_HEADERS), Map.class);
...@@ -76,7 +78,7 @@ public class ApplicationRegistrator { ...@@ -76,7 +78,7 @@ public class ApplicationRegistrator {
} }
isRegistrationSuccessful = true; isRegistrationSuccessful = true;
if (admin.isRegisterOnce()) { if (client.isRegisterOnce()) {
break; break;
} }
} else { } else {
...@@ -93,10 +95,10 @@ public class ApplicationRegistrator { ...@@ -93,10 +95,10 @@ public class ApplicationRegistrator {
if (unsuccessfulAttempts.get() == 0) { if (unsuccessfulAttempts.get() == 0) {
LOGGER.warn( LOGGER.warn(
"Failed to register application as {} at spring-boot-admin ({}): {}. Further attempts are logged on DEBUG level", "Failed to register application as {} at spring-boot-admin ({}): {}. Further attempts are logged on DEBUG level",
self, admin.getAdminUrl(), ex.getMessage()); self, client.getAdminUrl(), ex.getMessage());
} else { } else {
LOGGER.debug("Failed to register application as {} at spring-boot-admin ({}): {}", self, LOGGER.debug("Failed to register application as {} at spring-boot-admin ({}): {}", self,
admin.getAdminUrl(), ex.getMessage()); client.getAdminUrl(), ex.getMessage());
} }
} }
} }
...@@ -111,11 +113,11 @@ public class ApplicationRegistrator { ...@@ -111,11 +113,11 @@ public class ApplicationRegistrator {
public void deregister() { public void deregister() {
String id = registeredId.get(); String id = registeredId.get();
if (id != null) { if (id != null) {
for (String adminUrl : admin.getAdminUrl()) { for (String adminUrl : client.getAdminUrl()) {
try { try {
template.delete(adminUrl + "/" + id); template.delete(adminUrl + "/" + id);
registeredId.compareAndSet(id, null); registeredId.compareAndSet(id, null);
if (admin.isRegisterOnce()) { if (client.isRegisterOnce()) {
break; break;
} }
} catch (Exception ex) { } catch (Exception ex) {
...@@ -127,10 +129,8 @@ public class ApplicationRegistrator { ...@@ -127,10 +129,8 @@ public class ApplicationRegistrator {
} }
/** /**
* Returns the id of this client as given by the admin server. * @return the id of this client as given by the admin server.
* Returns null if the client has not registered against the admin server yet. * Returns null if the client has not registered against the admin server yet.
*
* @return
*/ */
public String getRegisteredId() { public String getRegisteredId() {
return registeredId.get(); return registeredId.get();
......
package de.codecentric.boot.admin.client.registration; package de.codecentric.boot.admin.client.registration;
import de.codecentric.boot.admin.client.config.AdminClientProperties; import de.codecentric.boot.admin.client.config.InstanceProperties;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
...@@ -23,21 +23,20 @@ import org.springframework.web.util.UriComponentsBuilder; ...@@ -23,21 +23,20 @@ import org.springframework.web.util.UriComponentsBuilder;
* @author Rene Felgenträger * @author Rene Felgenträger
*/ */
public class DefaultApplicationFactory implements ApplicationFactory { public class DefaultApplicationFactory implements ApplicationFactory {
private InstanceProperties instance;
private AdminClientProperties client;
private ServerProperties server; private ServerProperties server;
private ManagementServerProperties management; private ManagementServerProperties management;
private Integer localServerPort; private Integer localServerPort;
private Integer localManagementPort; private Integer localManagementPort;
private final ServletContext servletContext; private ServletContext servletContext;
private String healthEndpointPath; private String healthEndpointPath;
public DefaultApplicationFactory(AdminClientProperties client, public DefaultApplicationFactory(InstanceProperties instance,
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
ServletContext servletContext, ServletContext servletContext,
String healthEndpointPath) { String healthEndpointPath) {
this.client = client; this.instance = instance;
this.management = management; this.management = management;
this.server = server; this.server = server;
this.servletContext = servletContext; this.servletContext = servletContext;
...@@ -55,15 +54,15 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -55,15 +54,15 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected String getName() { protected String getName() {
return client.getName(); return instance.getName();
} }
protected String getServiceUrl() { protected String getServiceUrl() {
if (client.getServiceUrl() != null) { if (instance.getServiceUrl() != null) {
return UriComponentsBuilder.fromUriString(client.getServiceUrl()).toUriString(); return UriComponentsBuilder.fromUriString(instance.getServiceUrl()).toUriString();
} }
String baseUrl = client.getServiceBaseUrl(); String baseUrl = instance.getServiceBaseUrl();
if (getLocalServerPort() == null && StringUtils.isEmpty(baseUrl)) { if (getLocalServerPort() == null && StringUtils.isEmpty(baseUrl)) {
throw new IllegalStateException("service-base-url must be set when deployed to servlet-container"); throw new IllegalStateException("service-base-url must be set when deployed to servlet-container");
} }
...@@ -82,11 +81,11 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -82,11 +81,11 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected String getManagementUrl() { protected String getManagementUrl() {
if (client.getManagementUrl() != null) { if (instance.getManagementUrl() != null) {
return client.getManagementUrl(); return instance.getManagementUrl();
} }
String baseUrl = client.getManagementBaseUrl(); String baseUrl = instance.getManagementBaseUrl();
UriComponentsBuilder builder; UriComponentsBuilder builder;
if (!StringUtils.isEmpty(baseUrl)) { if (!StringUtils.isEmpty(baseUrl)) {
...@@ -109,8 +108,8 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -109,8 +108,8 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected String getHealthUrl() { protected String getHealthUrl() {
if (client.getHealthUrl() != null) { if (instance.getHealthUrl() != null) {
return client.getHealthUrl(); return instance.getHealthUrl();
} }
return UriComponentsBuilder.fromHttpUrl(getManagementUrl()) return UriComponentsBuilder.fromHttpUrl(getManagementUrl())
.path("/") .path("/")
...@@ -120,7 +119,7 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -120,7 +119,7 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected Map<String, String> getMetadata() { protected Map<String, String> getMetadata() {
return client.getMetadata(); return instance.getMetadata();
} }
protected String getServiceHost() { protected String getServiceHost() {
...@@ -164,7 +163,7 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -164,7 +163,7 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected String getHost(InetAddress address) { protected String getHost(InetAddress address) {
return client.isPreferIp() ? address.getHostAddress() : address.getCanonicalHostName(); return instance.isPreferIp() ? address.getHostAddress() : address.getCanonicalHostName();
} }
@EventListener @EventListener
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{ {
"name": "spring.boot.admin.client.enabled", "name": "spring.boot.admin.client.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Enable Spring Admin Client.", "description": "Enable Spring Boot Admin Client.",
"defaultValue": "true" "defaultValue": "true"
} }
]} ]}
package de.codecentric.boot.admin.client.config; package de.codecentric.boot.admin.client.config;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -12,15 +9,16 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; ...@@ -12,15 +9,16 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import de.codecentric.boot.admin.client.config.AdminProperties; import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = TestClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = { @SpringBootTest(classes = TestClientApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.port=0", "spring.boot.admin.url=http://example.com" }) "management.port=0", "spring.boot.admin.client.url=http://example.com"})
public class ClientApplicationTest { public class ClientApplicationTest {
@Autowired @Autowired
private AdminProperties properties; private ClientProperties properties;
@Test @Test
public void test_context() { public void test_context() {
......
...@@ -14,7 +14,6 @@ import org.springframework.context.annotation.Configuration; ...@@ -14,7 +14,6 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class SpringBootAdminClientAutoConfigurationTest { public class SpringBootAdminClientAutoConfigurationTest {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
@After @After
...@@ -32,28 +31,24 @@ public class SpringBootAdminClientAutoConfigurationTest { ...@@ -32,28 +31,24 @@ public class SpringBootAdminClientAutoConfigurationTest {
@Test @Test
public void active() { public void active() {
load("spring.boot.admin.url:http://localhost:8081"); load("spring.boot.admin.client.url:http://localhost:8081");
context.getBean(ApplicationRegistrator.class); context.getBean(ApplicationRegistrator.class);
} }
@Test @Test
public void disabled() { public void disabled() {
load("spring.boot.admin.url:http://localhost:8081", "spring.boot.admin.client.enabled:false"); load("spring.boot.admin.client.url:http://localhost:8081", "spring.boot.admin.client.enabled:false");
assertTrue(context.getBeansOfType(ApplicationRegistrator.class).isEmpty()); assertTrue(context.getBeansOfType(ApplicationRegistrator.class).isEmpty());
} }
private void load(final String... environment) { private void load(final String... environment) {
SpringApplication springApplication = new SpringApplication(TestClientApplication.class); SpringApplication springApplication = new SpringApplication(TestClientApplication.class);
springApplication.addInitializers(new ApplicationContextInitializer<ConfigurableApplicationContext>() { springApplication.addInitializers(
@Override (ApplicationContextInitializer<ConfigurableApplicationContext>) applicationContext -> EnvironmentTestUtils
public void initialize(ConfigurableApplicationContext applicationContext) { .addEnvironment(applicationContext, environment));
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
}
});
this.context = springApplication.run("--server.port=0"); this.context = springApplication.run("--server.port=0");
} }
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
static class TestClientApplication { static class TestClientApplication {
......
package de.codecentric.boot.admin.client.config; package de.codecentric.boot.admin.client.config;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.BDDMockito; import org.mockito.BDDMockito;
...@@ -11,7 +7,9 @@ import org.springframework.context.annotation.ConditionContext; ...@@ -11,7 +7,9 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockEnvironment;
import de.codecentric.boot.admin.client.config.SpringBootAdminClientEnabledCondition; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public class SpringBootAdminClientEnabledConditionTest { public class SpringBootAdminClientEnabledConditionTest {
...@@ -45,7 +43,7 @@ public class SpringBootAdminClientEnabledConditionTest { ...@@ -45,7 +43,7 @@ public class SpringBootAdminClientEnabledConditionTest {
public void test_nonEmptyUrl_disabled() { public void test_nonEmptyUrl_disabled() {
MockEnvironment environment = new MockEnvironment(); MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.boot.admin.client.enabled", "false"); environment.setProperty("spring.boot.admin.client.enabled", "false");
environment.setProperty("spring.boot.admin.url", "http://localhost:8080/management"); environment.setProperty("spring.boot.admin.client.url", "http://localhost:8080/management");
BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment); BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment);
assertFalse(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch()); assertFalse(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch());
} }
...@@ -53,7 +51,7 @@ public class SpringBootAdminClientEnabledConditionTest { ...@@ -53,7 +51,7 @@ public class SpringBootAdminClientEnabledConditionTest {
@Test @Test
public void test_nonEmptyUrl_enabled() { public void test_nonEmptyUrl_enabled() {
MockEnvironment environment = new MockEnvironment(); MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.boot.admin.url", "http://localhost:8080/management"); environment.setProperty("spring.boot.admin.client.url", "http://localhost:8080/management");
BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment); BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment);
assertTrue(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch()); assertTrue(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch());
} }
......
...@@ -37,14 +37,14 @@ import org.springframework.http.ResponseEntity; ...@@ -37,14 +37,14 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import de.codecentric.boot.admin.client.config.AdminProperties; import de.codecentric.boot.admin.client.config.ClientProperties;
import de.codecentric.boot.admin.client.registration.Application; import de.codecentric.boot.admin.client.registration.Application;
import de.codecentric.boot.admin.client.registration.ApplicationFactory; import de.codecentric.boot.admin.client.registration.ApplicationFactory;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator; import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;
public class ApplicationRegistratorTest { public class ApplicationRegistratorTest {
private AdminProperties adminProps; private ClientProperties client;
private ApplicationRegistrator registrator; private ApplicationRegistrator registrator;
private RestTemplate restTemplate; private RestTemplate restTemplate;
private HttpHeaders headers; private HttpHeaders headers;
...@@ -53,8 +53,8 @@ public class ApplicationRegistratorTest { ...@@ -53,8 +53,8 @@ public class ApplicationRegistratorTest {
public void setup() { public void setup() {
restTemplate = mock(RestTemplate.class); restTemplate = mock(RestTemplate.class);
adminProps = new AdminProperties(); client = new ClientProperties();
adminProps.setUrl(new String[] { "http://sba:8080", "http://sba2:8080" }); client.setUrl(new String[] { "http://sba:8080", "http://sba2:8080" });
ApplicationFactory factory = mock(ApplicationFactory.class); ApplicationFactory factory = mock(ApplicationFactory.class);
when(factory.createApplication()).thenReturn(Application.create("AppName") when(factory.createApplication()).thenReturn(Application.create("AppName")
...@@ -63,7 +63,7 @@ public class ApplicationRegistratorTest { ...@@ -63,7 +63,7 @@ public class ApplicationRegistratorTest {
.withServiceUrl("http://localhost:8080") .withServiceUrl("http://localhost:8080")
.build()); .build());
registrator = new ApplicationRegistrator(restTemplate, adminProps, factory); registrator = new ApplicationRegistrator(restTemplate, client, factory);
headers = new HttpHeaders(); headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
...@@ -127,7 +127,7 @@ public class ApplicationRegistratorTest { ...@@ -127,7 +127,7 @@ public class ApplicationRegistratorTest {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Test @Test
public void register_multiple() { public void register_multiple() {
adminProps.setRegisterOnce(false); client.setRegisterOnce(false);
when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class)))
.thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"),
...@@ -156,7 +156,7 @@ public class ApplicationRegistratorTest { ...@@ -156,7 +156,7 @@ public class ApplicationRegistratorTest {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Test @Test
public void register_multiple_one_failure() { public void register_multiple_one_failure() {
adminProps.setRegisterOnce(false); client.setRegisterOnce(false);
when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class)))
.thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"),
...@@ -185,7 +185,7 @@ public class ApplicationRegistratorTest { ...@@ -185,7 +185,7 @@ public class ApplicationRegistratorTest {
@Test @Test
public void register_multiple_all_failures() { public void register_multiple_all_failures() {
adminProps.setRegisterOnce(false); client.setRegisterOnce(false);
when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class)))
.thenThrow(new RestClientException("Error")) .thenThrow(new RestClientException("Error"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment