This commit is contained in:
Phillip Webb
2015-08-03 11:03:32 -07:00
parent 5c1f700c3a
commit 891dd5a0f6
25 changed files with 139 additions and 129 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -33,9 +34,10 @@ import org.springframework.context.annotation.Conditional;
* @author Stephane Nicoll
* @since 1.3.0
*/
@Conditional(OnEnabledHealthIndicatorCondition.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnEnabledHealthIndicatorCondition.class)
public @interface ConditionalOnEnablednHealthIndicator {
/**

View File

@@ -66,4 +66,5 @@ class LinksEnhancer {
resource.add(linkTo(type).slash(fullPath).withRel(rel));
}
}
}

View File

@@ -28,37 +28,38 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
* {@link Condition} that checks if a health indicator is enabled.
*
* @author Stephane Nicoll
* @since 1.3.0
*/
class OnEnabledHealthIndicatorCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
.getAnnotationAttributes(ConditionalOnEnablednHealthIndicator.class.getName()));
private static final String ANNOTATION_CLASS = ConditionalOnEnablednHealthIndicator.class
.getName();
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
.getAnnotationAttributes(ANNOTATION_CLASS));
String endpointName = annotationAttributes.getString("value");
ConditionOutcome outcome = determineHealthIndicatorOutcome(endpointName, context);
ConditionOutcome outcome = getHealthIndicatorOutcome(context, endpointName);
if (outcome != null) {
return outcome;
}
return determineDefaultIndicatorsOutcome(context);
return getDefaultIndicatorsOutcome(context);
}
private ConditionOutcome determineHealthIndicatorOutcome(String endpointName,
ConditionContext context) {
private ConditionOutcome getHealthIndicatorOutcome(ConditionContext context,
String endpointName) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "management.health." + endpointName + ".");
if (resolver.containsProperty("enabled")) {
boolean match = resolver.getProperty("enabled", Boolean.class,
true);
return new ConditionOutcome(match, "The health indicator " + endpointName +
" is " + (match ? "enabled" : "disabled"));
boolean match = resolver.getProperty("enabled", Boolean.class, true);
return new ConditionOutcome(match, "The health indicator " + endpointName
+ " is " + (match ? "enabled" : "disabled"));
}
return null;
}
private ConditionOutcome determineDefaultIndicatorsOutcome(ConditionContext context) {
private ConditionOutcome getDefaultIndicatorsOutcome(ConditionContext context) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "management.health.defaults.");
boolean match = Boolean.valueOf(resolver.getProperty("enabled", "true"));

View File

@@ -36,10 +36,6 @@ public class SimpleInMemoryRepository<T> {
private final ConcurrentMap<String, Object> locks = new ConcurrentReferenceHashMap<String, Object>();
public interface Callback<T> {
T modify(T current);
}
public T update(String name, Callback<T> callback) {
Object lock = this.locks.putIfAbsent(name, new Object());
if (lock == null) {
@@ -101,4 +97,8 @@ public class SimpleInMemoryRepository<T> {
return this.values;
}
public interface Callback<T> {
T modify(T current);
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.After;
@@ -105,16 +106,15 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void defaultHealthIndicatorsDisabledWithCustomOne() {
this.context.register(CustomHealthIndicator.class,
HealthIndicatorAutoConfiguration.class,
ManagementServerProperties.class);
HealthIndicatorAutoConfiguration.class, ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.defaults.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertEquals(1, beans.size());
assertSame(this.context.getBean("customHealthIndicator"), beans.values().
iterator().next());
assertSame(this.context.getBean("customHealthIndicator"), beans.values()
.iterator().next());
}
@Test
@@ -445,6 +445,7 @@ public class HealthIndicatorAutoConfigurationTests {
}
};
}
}
}

View File

@@ -135,11 +135,13 @@ public class JolokiaAutoConfigurationTests {
@Configuration
protected static class EndpointsConfig extends Config {
@Bean
public EndpointHandlerMapping endpointHandlerMapping(
Collection<? extends MvcEndpoint> endpoints) {
return new EndpointHandlerMapping(endpoints);
}
}
@Configuration