Polish
This commit is contained in:
parent
344fb4616d
commit
f9aeb6aefe
|
|
@ -75,7 +75,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
* different port to {@link ServerProperties} a new child context is created, otherwise it
|
* different port to {@link ServerProperties} a new child context is created, otherwise it
|
||||||
* is assumed that endpoint requests will be mapped and handled via an already registered
|
* is assumed that endpoint requests will be mapped and handled via an already registered
|
||||||
* {@link DispatcherServlet}.
|
* {@link DispatcherServlet}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
|
|
@ -84,8 +84,8 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
|
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
|
||||||
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||||
ManagementServerPropertiesAutoConfiguration.class })
|
ManagementServerPropertiesAutoConfiguration.class })
|
||||||
@EnableConfigurationProperties(HealthMvcEndpointProperties.class)
|
@EnableConfigurationProperties(HealthMvcEndpointProperties.class)
|
||||||
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
ApplicationListener<ContextRefreshedEvent> {
|
ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
@ -109,8 +109,8 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public EndpointHandlerMapping endpointHandlerMapping() {
|
public EndpointHandlerMapping endpointHandlerMapping() {
|
||||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(mvcEndpoints()
|
||||||
mvcEndpoints().getEndpoints());
|
.getEndpoints());
|
||||||
boolean disabled = ManagementServerPort.get(this.applicationContext) != ManagementServerPort.SAME;
|
boolean disabled = ManagementServerPort.get(this.applicationContext) != ManagementServerPort.SAME;
|
||||||
mapping.setDisabled(disabled);
|
mapping.setDisabled(disabled);
|
||||||
if (!disabled) {
|
if (!disabled) {
|
||||||
|
|
@ -169,7 +169,8 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) {
|
public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) {
|
||||||
HealthMvcEndpoint healthMvcEndpoint = new HealthMvcEndpoint(delegate);
|
HealthMvcEndpoint healthMvcEndpoint = new HealthMvcEndpoint(delegate);
|
||||||
if (this.healthMvcEndpointProperties.getMapping() != null) {
|
if (this.healthMvcEndpointProperties.getMapping() != null) {
|
||||||
healthMvcEndpoint.setStatusMapping(this.healthMvcEndpointProperties.getMapping());
|
healthMvcEndpoint.setStatusMapping(this.healthMvcEndpointProperties
|
||||||
|
.getMapping());
|
||||||
}
|
}
|
||||||
return healthMvcEndpoint;
|
return healthMvcEndpoint;
|
||||||
}
|
}
|
||||||
|
|
@ -205,25 +206,28 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
|
|
||||||
// Ensure close on the parent also closes the child
|
// Ensure close on the parent also closes the child
|
||||||
if (this.applicationContext instanceof ConfigurableApplicationContext) {
|
if (this.applicationContext instanceof ConfigurableApplicationContext) {
|
||||||
((ConfigurableApplicationContext) this.applicationContext).addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
|
((ConfigurableApplicationContext) this.applicationContext)
|
||||||
|
.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ContextClosedEvent event) {
|
public void onApplicationEvent(ContextClosedEvent event) {
|
||||||
if (event.getApplicationContext() == EndpointWebMvcAutoConfiguration.this.applicationContext) {
|
if (event.getApplicationContext() == EndpointWebMvcAutoConfiguration.this.applicationContext) {
|
||||||
childContext.close();
|
childContext.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
childContext.refresh();
|
childContext.refresh();
|
||||||
} catch (RuntimeException ex) {
|
}
|
||||||
|
catch (RuntimeException ex) {
|
||||||
// No support currently for deploying a war with management.port=<different>,
|
// No support currently for deploying a war with management.port=<different>,
|
||||||
// and this is the signature of that happening
|
// and this is the signature of that happening
|
||||||
if (ex instanceof EmbeddedServletContainerException
|
if (ex instanceof EmbeddedServletContainerException
|
||||||
|| ex.getCause() instanceof EmbeddedServletContainerException) {
|
|| ex.getCause() instanceof EmbeddedServletContainerException) {
|
||||||
logger.warn("Could not start embedded container (management endpoints are still available through JMX)");
|
logger.warn("Could not start embedded container (management endpoints are still available through JMX)");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -238,14 +242,17 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
ServerProperties serverProperties;
|
ServerProperties serverProperties;
|
||||||
try {
|
try {
|
||||||
serverProperties = beanFactory.getBean(ServerProperties.class);
|
serverProperties = beanFactory.getBean(ServerProperties.class);
|
||||||
} catch (NoSuchBeanDefinitionException ex) {
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
serverProperties = new ServerProperties();
|
serverProperties = new ServerProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagementServerProperties managementServerProperties;
|
ManagementServerProperties managementServerProperties;
|
||||||
try {
|
try {
|
||||||
managementServerProperties = beanFactory.getBean(ManagementServerProperties.class);
|
managementServerProperties = beanFactory
|
||||||
} catch (NoSuchBeanDefinitionException ex) {
|
.getBean(ManagementServerProperties.class);
|
||||||
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
managementServerProperties = new ManagementServerProperties();
|
managementServerProperties = new ManagementServerProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties for the {@link HealthMvcEndpoint}.
|
* Configuration properties for the {@link HealthMvcEndpoint}.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
|
||||||
|
|
||||||
if (healthIndicators.size() == 1) {
|
if (healthIndicators.size() == 1) {
|
||||||
this.healthIndicator = healthIndicators.values().iterator().next();
|
this.healthIndicator = healthIndicators.values().iterator().next();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
|
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
|
||||||
healthAggregator);
|
healthAggregator);
|
||||||
for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) {
|
for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link HealthIndicator} that returns health indications from all registered delegates.
|
* {@link HealthIndicator} that returns health indications from all registered delegates.
|
||||||
*
|
*
|
||||||
* @author Tyler J. Frederick
|
* @author Tyler J. Frederick
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,15 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||||
/**
|
/**
|
||||||
* Value object used to carry information about the health information of a component or
|
* Value object used to carry information about the health information of a component or
|
||||||
* subsystem.
|
* subsystem.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* {@link Health} contains a {@link Status} to express the state of a component or
|
* {@link Health} contains a {@link Status} to express the state of a component or
|
||||||
* subsystem and some additional details to carry some contextual information.
|
* subsystem and some additional details to carry some contextual information.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* {@link Health} has a fluent API to make it easy to construct instances. Typical usage
|
* {@link Health} has a fluent API to make it easy to construct instances. Typical usage
|
||||||
* in a {@link HealthIndicator} would be:
|
* in a {@link HealthIndicator} would be:
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* Health health = new Health();
|
* Health health = new Health();
|
||||||
* try {
|
* try {
|
||||||
|
|
@ -52,7 +52,7 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||||
* }
|
* }
|
||||||
* return health;
|
* return health;
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,18 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* Strategy interface used by {@link CompositeHealthIndicator} to aggregate {@link Health}
|
* Strategy interface used by {@link CompositeHealthIndicator} to aggregate {@link Health}
|
||||||
* instances into a final one.
|
* instances into a final one.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This is especially useful to combine subsystem states expressed through
|
* This is especially useful to combine subsystem states expressed through
|
||||||
* {@link Health#getStatus()} into one state for the entire system. The default
|
* {@link Health#getStatus()} into one state for the entire system. The default
|
||||||
* implementation {@link OrderedHealthAggregator} sorts {@link Status} instances based on
|
* implementation {@link OrderedHealthAggregator} sorts {@link Status} instances based on
|
||||||
* a priority list.
|
* a priority list.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* It is possible to add more complex {@link Status} types to the system. In that case
|
* It is possible to add more complex {@link Status} types to the system. In that case
|
||||||
* either the {@link OrderedHealthAggregator} needs to be properly configured or users
|
* either the {@link OrderedHealthAggregator} needs to be properly configured or users
|
||||||
* need to register a custom {@link HealthAggregator} as bean.
|
* need to register a custom {@link HealthAggregator} as bean.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy interface used to provide an indication of application health.
|
* Strategy interface used to provide an indication of application health.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @see VanillaHealthIndicator
|
* @see VanillaHealthIndicator
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import com.mongodb.CommandResult;
|
||||||
/**
|
/**
|
||||||
* Simple implementation of a {@link HealthIndicator} returning status information for
|
* Simple implementation of a {@link HealthIndicator} returning status information for
|
||||||
* Mongo data stores.
|
* Mongo data stores.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* Default {@link HealthAggregator} implementation that aggregates {@link Health}
|
* Default {@link HealthAggregator} implementation that aggregates {@link Health}
|
||||||
* instances and determines the final system state based on a simple ordered list.
|
* instances and determines the final system state based on a simple ordered list.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* If a different order is required or a new {@link Status} type will be used, the order
|
* If a different order is required or a new {@link Status} type will be used, the order
|
||||||
* can be set by calling {@link #setStatusOrder(List)}.
|
* can be set by calling {@link #setStatusOrder(List)}.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -67,8 +67,10 @@ public class OrderedHealthAggregator implements HealthAggregator {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Status s1, Status s2) {
|
public int compare(Status s1, Status s2) {
|
||||||
return Integer.valueOf(
|
return Integer.valueOf(
|
||||||
OrderedHealthAggregator.this.statusOrder.indexOf(s1.getCode())).compareTo(
|
OrderedHealthAggregator.this.statusOrder.indexOf(s1.getCode()))
|
||||||
Integer.valueOf(OrderedHealthAggregator.this.statusOrder.indexOf(s2.getCode())));
|
.compareTo(
|
||||||
|
Integer.valueOf(OrderedHealthAggregator.this.statusOrder
|
||||||
|
.indexOf(s2.getCode())));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import com.rabbitmq.client.Channel;
|
||||||
/**
|
/**
|
||||||
* Simple implementation of a {@link HealthIndicator} returning status information for the
|
* Simple implementation of a {@link HealthIndicator} returning status information for the
|
||||||
* RabbitMQ messaging system.
|
* RabbitMQ messaging system.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import org.springframework.util.Assert;
|
||||||
/**
|
/**
|
||||||
* Simple implementation of a {@link HealthIndicator} returning status information for
|
* Simple implementation of a {@link HealthIndicator} returning status information for
|
||||||
* Redis data stores.
|
* Redis data stores.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import org.springframework.util.StringUtils;
|
||||||
/**
|
/**
|
||||||
* Simple implementation of {@link HealthIndicator} that returns a status and also
|
* Simple implementation of {@link HealthIndicator} that returns a status and also
|
||||||
* attempts a simple database test.
|
* attempts a simple database test.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
|
|
@ -88,7 +88,8 @@ public class SimpleDataSourceHealthIndicator implements HealthIndicator {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
health.withDetail("database", product);
|
health.withDetail("database", product);
|
||||||
} catch (DataAccessException ex) {
|
}
|
||||||
|
catch (DataAccessException ex) {
|
||||||
health.down().withException(ex);
|
health.down().withException(ex);
|
||||||
}
|
}
|
||||||
String query = detectQuery(product);
|
String query = detectQuery(product);
|
||||||
|
|
@ -96,7 +97,8 @@ public class SimpleDataSourceHealthIndicator implements HealthIndicator {
|
||||||
try {
|
try {
|
||||||
health.withDetail("hello",
|
health.withDetail("hello",
|
||||||
this.jdbcTemplate.queryForObject(query, Object.class));
|
this.jdbcTemplate.queryForObject(query, Object.class));
|
||||||
} catch (Exception ex) {
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
health.down().withException(ex);
|
health.down().withException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value object to express state of a component or subsystem.
|
* Value object to express state of a component or subsystem.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Status provides convenient constants for commonly used states like {@link #UP},
|
* Status provides convenient constants for commonly used states like {@link #UP},
|
||||||
* {@link #DOWN} or {@link #OUT_OF_SERVICE}.
|
* {@link #DOWN} or {@link #OUT_OF_SERVICE}.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Custom states can also be created and used throughout the Spring Boot Health subsystem.
|
* Custom states can also be created and used throughout the Spring Boot Health subsystem.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.health;
|
package org.springframework.boot.actuate.health;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of {@link HealthIndicator} that simply returns {@literal "ok"}.
|
* Default implementation of {@link HealthIndicator} that simply returns {@literal "ok"}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue