Remove deprecated HealthIndicator and HealthAggregator 2.2 code

See gh-19699
This commit is contained in:
Scott Frederick
2020-01-14 13:44:38 -06:00
committed by Stephane Nicoll
parent 1f1b06dfe2
commit 2e32cb2af1
54 changed files with 18 additions and 3581 deletions

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
import org.springframework.core.ResolvableType;
/**
* Base class for configurations that can combine source beans using a
* {@link CompositeHealthIndicator}.
*
* @param <H> the health indicator type
* @param <S> the bean source type
* @author Stephane Nicoll
* @since 2.0.0
* @deprecated since 2.2.0 in favor of {@link CompositeHealthContributorConfiguration}
*/
@Deprecated
public abstract class CompositeHealthIndicatorConfiguration<H extends HealthIndicator, S> {
@Autowired
private HealthAggregator healthAggregator;
protected HealthIndicator createHealthIndicator(Map<String, S> beans) {
if (beans.size() == 1) {
return createHealthIndicator(beans.values().iterator().next());
}
HealthIndicatorRegistry registry = new DefaultHealthIndicatorRegistry();
beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
return new CompositeHealthIndicator(this.healthAggregator, registry);
}
@SuppressWarnings("unchecked")
protected H createHealthIndicator(S source) {
Class<?>[] generics = ResolvableType.forClass(CompositeHealthIndicatorConfiguration.class, getClass())
.resolveGenerics();
Class<H> indicatorClass = (Class<H>) generics[0];
Class<S> sourceClass = (Class<S>) generics[1];
try {
return indicatorClass.getConstructor(sourceClass).newInstance(source);
}
catch (Exception ex) {
throw new IllegalStateException(
"Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
}
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.CompositeReactiveHealthIndicator;
import org.springframework.boot.actuate.health.DefaultReactiveHealthIndicatorRegistry;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
import org.springframework.core.ResolvableType;
/**
* Reactive variant of {@link CompositeHealthIndicatorConfiguration}.
*
* @param <H> the health indicator type
* @param <S> the bean source type
* @author Stephane Nicoll
* @since 2.0.0
* @deprecated since 2.2.0 in favor of
* {@link CompositeReactiveHealthContributorConfiguration}
*/
@Deprecated
public abstract class CompositeReactiveHealthIndicatorConfiguration<H extends ReactiveHealthIndicator, S> {
@Autowired
private HealthAggregator healthAggregator;
protected ReactiveHealthIndicator createHealthIndicator(Map<String, S> beans) {
if (beans.size() == 1) {
return createHealthIndicator(beans.values().iterator().next());
}
ReactiveHealthIndicatorRegistry registry = new DefaultReactiveHealthIndicatorRegistry();
beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
return new CompositeReactiveHealthIndicator(this.healthAggregator, registry);
}
@SuppressWarnings("unchecked")
protected H createHealthIndicator(S source) {
Class<?>[] generics = ResolvableType.forClass(CompositeReactiveHealthIndicatorConfiguration.class, getClass())
.resolveGenerics();
Class<H> indicatorClass = (Class<H>) generics[0];
Class<S> sourceClass = (Class<S>) generics[1];
try {
return indicatorClass.getConstructor(sourceClass).newInstance(source);
}
catch (Exception ex) {
throw new IllegalStateException(
"Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
}
}
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.health.StatusAggregator;
/**
* Adapter class to convert a legacy {@link HealthAggregator} to a
* {@link StatusAggregator}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class HealthAggregatorStatusAggregatorAdapter implements StatusAggregator {
private HealthAggregator healthAggregator;
HealthAggregatorStatusAggregatorAdapter(HealthAggregator healthAggregator) {
this.healthAggregator = healthAggregator;
}
@Override
public Status getAggregateStatus(Set<Status> statuses) {
int index = 0;
Map<String, Health> healths = new LinkedHashMap<>();
for (Status status : statuses) {
index++;
healths.put("health" + index, asHealth(status));
}
Health aggregate = this.healthAggregator.aggregate(healths);
return aggregate.getStatus();
}
private Health asHealth(Status status) {
return Health.status(status).build();
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.util.Assert;
/**
* Adapter class to convert a {@link HealthContributorRegistry} to a legacy
* {@link HealthIndicatorRegistry}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class HealthContributorRegistryHealthIndicatorRegistryAdapter implements HealthIndicatorRegistry {
private final HealthContributorRegistry contributorRegistry;
HealthContributorRegistryHealthIndicatorRegistryAdapter(HealthContributorRegistry contributorRegistry) {
Assert.notNull(contributorRegistry, "ContributorRegistry must not be null");
this.contributorRegistry = contributorRegistry;
}
@Override
public void register(String name, HealthIndicator healthIndicator) {
this.contributorRegistry.registerContributor(name, healthIndicator);
}
@Override
public HealthIndicator unregister(String name) {
HealthContributor contributor = this.contributorRegistry.unregisterContributor(name);
if (contributor instanceof HealthIndicator) {
return (HealthIndicator) contributor;
}
return null;
}
@Override
public HealthIndicator get(String name) {
HealthContributor contributor = this.contributorRegistry.getContributor(name);
if (contributor instanceof HealthIndicator) {
return (HealthIndicator) contributor;
}
return null;
}
@Override
public Map<String, HealthIndicator> getAll() {
Map<String, HealthIndicator> all = new LinkedHashMap<>();
for (NamedContributor<?> namedContributor : this.contributorRegistry) {
if (namedContributor.getContributor() instanceof HealthIndicator) {
all.put(namedContributor.getName(), (HealthIndicator) namedContributor.getContributor());
}
}
return all;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.condition.Conditi
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -30,23 +29,14 @@ import org.springframework.context.annotation.Import;
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Phillip Webb
* @author Scott Frederick
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class)
@EnableConfigurationProperties
@Import({ LegacyHealthEndpointAdaptersConfiguration.class, LegacyHealthEndpointCompatibilityConfiguration.class,
HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
@EnableConfigurationProperties(HealthEndpointProperties.class)
@Import({ HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
HealthEndpointWebExtensionConfiguration.class, HealthEndpointReactiveWebExtensionConfiguration.class })
public class HealthEndpointAutoConfiguration {
@Bean
@SuppressWarnings("deprecation")
HealthEndpointProperties healthEndpointProperties(HealthIndicatorProperties healthIndicatorProperties) {
HealthEndpointProperties healthEndpointProperties = new HealthEndpointProperties();
healthEndpointProperties.getStatus().getOrder().addAll(healthIndicatorProperties.getOrder());
healthEndpointProperties.getStatus().getHttpMapping().putAll(healthIndicatorProperties.getHttpMapping());
return healthEndpointProperties;
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link HealthContributor health
* contributors}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Phillip Webb
* @author Vedran Pavic
* @since 2.0.0
* @deprecated since 2.2.0 in favor of {@link HealthContributorAutoConfiguration}
*/
@Deprecated
@Configuration(proxyBeanMethods = false)
public class HealthIndicatorAutoConfiguration {
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Configuration properties for some health properties.
*
* @author Christian Dupuis
* @since 2.0.0
* @deprecated since 2.2.0 in favor of {@link HealthEndpointProperties}
*/
@Deprecated
@ConfigurationProperties(prefix = "management.health.status")
public class HealthIndicatorProperties {
private List<String> order = new ArrayList<>();
private final Map<String, Integer> httpMapping = new LinkedHashMap<>();
@DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.order")
public List<String> getOrder() {
return this.order;
}
public void setOrder(List<String> order) {
this.order = order;
}
@DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.http-mapping")
public Map<String, Integer> getHttpMapping() {
return this.httpMapping;
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.Status;
/**
* Adapter class to convert a legacy {@link HealthStatusHttpMapper} to a
* {@link HttpCodeStatusMapper}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class HealthStatusHttpMapperHttpCodeStatusMapperAdapter implements HttpCodeStatusMapper {
private final HealthStatusHttpMapper healthStatusHttpMapper;
HealthStatusHttpMapperHttpCodeStatusMapperAdapter(HealthStatusHttpMapper healthStatusHttpMapper) {
this.healthStatusHttpMapper = healthStatusHttpMapper;
}
@Override
public int getStatusCode(Status status) {
return this.healthStatusHttpMapper.mapStatus(status);
}
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.StatusAggregator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration to adapt legacy deprecated health endpoint classes and interfaces.
*
* @author Phillip Webb
* @see HealthEndpointAutoConfiguration
*/
@Configuration(proxyBeanMethods = false)
@SuppressWarnings("deprecation")
class LegacyHealthEndpointAdaptersConfiguration {
@Bean
@ConditionalOnBean(org.springframework.boot.actuate.health.HealthAggregator.class)
StatusAggregator healthAggregatorStatusAggregatorAdapter(
org.springframework.boot.actuate.health.HealthAggregator healthAggregator) {
return new HealthAggregatorStatusAggregatorAdapter(healthAggregator);
}
@Bean
@ConditionalOnBean(org.springframework.boot.actuate.health.HealthStatusHttpMapper.class)
HttpCodeStatusMapper healthStatusHttpMapperHttpCodeStatusMapperAdapter(
org.springframework.boot.actuate.health.HealthStatusHttpMapper healthStatusHttpMapper) {
return new HealthStatusHttpMapperHttpCodeStatusMapperAdapter(healthStatusHttpMapper);
}
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
import org.springframework.boot.actuate.health.OrderedHealthAggregator;
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
/**
* Configuration to adapt legacy deprecated health endpoint classes and interfaces.
*
* @author Phillip Webb
* @see HealthEndpointAutoConfiguration
*/
@Configuration(proxyBeanMethods = false)
@SuppressWarnings("deprecation")
@EnableConfigurationProperties(HealthIndicatorProperties.class)
class LegacyHealthEndpointCompatibilityConfiguration {
@Bean
@ConditionalOnMissingBean
HealthAggregator healthAggregator(HealthIndicatorProperties healthIndicatorProperties) {
OrderedHealthAggregator aggregator = new OrderedHealthAggregator();
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getOrder())) {
aggregator.setStatusOrder(healthIndicatorProperties.getOrder());
}
return aggregator;
}
@Bean
@ConditionalOnMissingBean
HealthStatusHttpMapper healthStatusHttpMapper(HealthIndicatorProperties healthIndicatorProperties) {
HealthStatusHttpMapper mapper = new HealthStatusHttpMapper();
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getHttpMapping())) {
mapper.setStatusMapping(healthIndicatorProperties.getHttpMapping());
}
return mapper;
}
@Bean
@ConditionalOnMissingBean(HealthIndicatorRegistry.class)
HealthContributorRegistryHealthIndicatorRegistryAdapter healthIndicatorRegistry(
HealthContributorRegistry healthContributorRegistry) {
return new HealthContributorRegistryHealthIndicatorRegistryAdapter(healthContributorRegistry);
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Mono.class)
static class LegacyReactiveHealthEndpointCompatibilityConfiguration {
@Bean
@ConditionalOnMissingBean(ReactiveHealthIndicatorRegistry.class)
ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter reactiveHealthIndicatorRegistry(
ReactiveHealthContributorRegistry reactiveHealthContributorRegistry) {
return new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(
reactiveHealthContributorRegistry);
}
}
}

View File

@@ -1,81 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
import org.springframework.util.Assert;
/**
* Adapter class to convert a {@link ReactiveHealthContributorRegistry} to a legacy
* {@link ReactiveHealthIndicatorRegistry}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter
implements ReactiveHealthIndicatorRegistry {
private final ReactiveHealthContributorRegistry contributorRegistry;
ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(
ReactiveHealthContributorRegistry contributorRegistry) {
Assert.notNull(contributorRegistry, "ContributorRegistry must not be null");
this.contributorRegistry = contributorRegistry;
}
@Override
public void register(String name, ReactiveHealthIndicator healthIndicator) {
this.contributorRegistry.registerContributor(name, healthIndicator);
}
@Override
public ReactiveHealthIndicator unregister(String name) {
ReactiveHealthContributor contributor = this.contributorRegistry.unregisterContributor(name);
if (contributor instanceof ReactiveHealthIndicator) {
return (ReactiveHealthIndicator) contributor;
}
return null;
}
@Override
public ReactiveHealthIndicator get(String name) {
ReactiveHealthContributor contributor = this.contributorRegistry.getContributor(name);
if (contributor instanceof ReactiveHealthIndicator) {
return (ReactiveHealthIndicator) contributor;
}
return null;
}
@Override
public Map<String, ReactiveHealthIndicator> getAll() {
Map<String, ReactiveHealthIndicator> all = new LinkedHashMap<>();
for (NamedContributor<?> namedContributor : this.contributorRegistry) {
if (namedContributor.getContributor() instanceof ReactiveHealthIndicator) {
all.put(namedContributor.getName(), (ReactiveHealthIndicator) namedContributor.getContributor());
}
}
return all;
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.AbstractHealthAggregator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.health.StatusAggregator;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link HealthAggregatorStatusAggregatorAdapter}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class HealthAggregatorStatusAggregatorAdapterTests {
@Test
void getAggregateStatusDelegateToHealthAggregator() {
StatusAggregator adapter = new HealthAggregatorStatusAggregatorAdapter(new TestHealthAggregator());
Status status = adapter.getAggregateStatus(Status.UP, Status.DOWN);
assertThat(status.getCode()).isEqualTo("called2");
}
private static class TestHealthAggregator extends AbstractHealthAggregator {
@Override
protected Status aggregateStatus(List<Status> candidates) {
return new Status("called" + candidates.size());
}
}
}

View File

@@ -1,109 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.CompositeHealthContributor;
import org.springframework.boot.actuate.health.DefaultHealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthIndicator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link HealthContributorRegistryHealthIndicatorRegistryAdapter}.
*
* @author Phillip Webb
*/
class HealthContributorRegistryHealthIndicatorRegistryAdapterTests {
private HealthContributorRegistry contributorRegistry = new DefaultHealthContributorRegistry();
private HealthContributorRegistryHealthIndicatorRegistryAdapter adapter = new HealthContributorRegistryHealthIndicatorRegistryAdapter(
this.contributorRegistry);
@Test
void createWhenContributorRegistryIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new HealthContributorRegistryHealthIndicatorRegistryAdapter(null))
.withMessage("ContributorRegistry must not be null");
}
@Test
void registerDelegatesToContributorRegistry() {
HealthIndicator healthIndicator = mock(HealthIndicator.class);
this.adapter.register("test", healthIndicator);
assertThat(this.contributorRegistry.getContributor("test")).isSameAs(healthIndicator);
}
@Test
void unregisterDelegatesToContributorRegistry() {
HealthIndicator healthIndicator = mock(HealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
HealthIndicator unregistered = this.adapter.unregister("test");
assertThat(unregistered).isSameAs(healthIndicator);
assertThat(this.contributorRegistry.getContributor("test")).isNull();
}
@Test
void unregisterWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() {
CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class);
this.contributorRegistry.registerContributor("test", healthContributor);
HealthIndicator unregistered = this.adapter.unregister("test");
assertThat(unregistered).isNull();
assertThat(this.contributorRegistry.getContributor("test")).isNull();
}
@Test
void getDelegatesToContributorRegistry() {
HealthIndicator healthIndicator = mock(HealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
assertThat(this.adapter.get("test")).isSameAs(healthIndicator);
}
@Test
void getWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() {
CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class);
this.contributorRegistry.registerContributor("test", healthContributor);
assertThat(this.adapter.get("test")).isNull();
}
@Test
void getAllDelegatesToContributorRegistry() {
HealthIndicator healthIndicator = mock(HealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
Map<String, HealthIndicator> all = this.adapter.getAll();
assertThat(all).containsOnly(entry("test", healthIndicator));
}
@Test
void getAllWhenContributorRegistryContainsNonHealthIndicatorInstancesReturnsFilteredMap() {
CompositeHealthContributor healthContributor = mock(CompositeHealthContributor.class);
this.contributorRegistry.registerContributor("test1", healthContributor);
HealthIndicator healthIndicator = mock(HealthIndicator.class);
this.contributorRegistry.registerContributor("test2", healthIndicator);
Map<String, HealthIndicator> all = this.adapter.getAll();
assertThat(all).containsOnly(entry("test2", healthIndicator));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
@@ -28,24 +25,20 @@ import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.http.ApiVersion;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.boot.actuate.health.AbstractHealthAggregator;
import org.springframework.boot.actuate.health.DefaultHealthContributorRegistry;
import org.springframework.boot.actuate.health.DefaultReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthComponent;
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.health.HealthEndpointGroups;
import org.springframework.boot.actuate.health.HealthEndpointWebExtension;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.health.StatusAggregator;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -66,7 +59,6 @@ import static org.mockito.Mockito.mock;
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
@SuppressWarnings("deprecation")
class HealthEndpointAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
@@ -91,22 +83,6 @@ class HealthEndpointAutoConfigurationTests {
});
}
@Test
void runWhenHasHealthAggregatorAdaptsToStatusAggregator() {
this.contextRunner.withUserConfiguration(HealthAggregatorConfiguration.class).run((context) -> {
StatusAggregator aggregator = context.getBean(StatusAggregator.class);
assertThat(aggregator.getAggregateStatus(Status.UP, Status.DOWN)).isEqualTo(Status.UNKNOWN);
});
}
@Test
void runWhenHasHealthStatusHttpMapperAdaptsToHttpCodeStatusMapper() {
this.contextRunner.withUserConfiguration(HealthStatusHttpMapperConfiguration.class).run((context) -> {
HttpCodeStatusMapper mapper = context.getBean(HttpCodeStatusMapper.class);
assertThat(mapper.getStatusCode(Status.UP)).isEqualTo(123);
});
}
@Test
void runCreatesStatusAggregatorFromProperties() {
this.contextRunner.withPropertyValues("management.endpoint.health.status.order=up,down").run((context) -> {
@@ -115,14 +91,6 @@ class HealthEndpointAutoConfigurationTests {
});
}
@Test
void runWhenUsingDeprecatedPropertyCreatesStatusAggregatorFromProperties() {
this.contextRunner.withPropertyValues("management.health.status.order=up,down").run((context) -> {
StatusAggregator aggregator = context.getBean(StatusAggregator.class);
assertThat(aggregator.getAggregateStatus(Status.UP, Status.DOWN)).isEqualTo(Status.UP);
});
}
@Test
void runWhenHasStatusAggregatorBeanIgnoresProperties() {
this.contextRunner.withUserConfiguration(StatusAggregatorConfiguration.class)
@@ -141,14 +109,6 @@ class HealthEndpointAutoConfigurationTests {
});
}
@Test
void runUsingDeprecatedPropertyCreatesHttpCodeStatusMapperFromProperties() {
this.contextRunner.withPropertyValues("management.health.status.http-mapping.up=123").run((context) -> {
HttpCodeStatusMapper mapper = context.getBean(HttpCodeStatusMapper.class);
assertThat(mapper.getStatusCode(Status.UP)).isEqualTo(123);
});
}
@Test
void runWhenHasHttpCodeStatusMapperBeanIgnoresProperties() {
this.contextRunner.withUserConfiguration(HttpCodeStatusMapperConfiguration.class)
@@ -286,37 +246,6 @@ class HealthEndpointAutoConfigurationTests {
});
}
@Test // gh-18354
void runCreatesLegacyHealthAggregator() {
this.contextRunner.run((context) -> {
HealthAggregator aggregator = context.getBean(HealthAggregator.class);
Map<String, Health> healths = new LinkedHashMap<>();
healths.put("one", Health.up().build());
healths.put("two", Health.down().build());
Health result = aggregator.aggregate(healths);
assertThat(result.getStatus()).isEqualTo(Status.DOWN);
});
}
@Test // gh-18354
void runCreatesLegacyHealthStatusHttpMapper() {
this.contextRunner.run((context) -> {
HealthStatusHttpMapper mapper = context.getBean(HealthStatusHttpMapper.class);
assertThat(mapper.mapStatus(Status.DOWN)).isEqualTo(503);
});
}
@Test
void runWhenReactorAvailableCreatesReactiveHealthIndicatorRegistryBean() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ReactiveHealthIndicatorRegistry.class));
}
@Test // gh-18570
void runWhenReactorUnavailableDoesNotCreateReactiveHealthIndicatorRegistryBean() {
this.contextRunner.withClassLoader(new FilteredClassLoader(Mono.class.getPackage().getName()))
.run((context) -> assertThat(context).doesNotHaveBean(ReactiveHealthIndicatorRegistry.class));
}
@Configuration(proxyBeanMethods = false)
static class HealthIndicatorsConfiguration {
@@ -337,40 +266,6 @@ class HealthEndpointAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class HealthAggregatorConfiguration {
@Bean
HealthAggregator healthAggregator() {
return new AbstractHealthAggregator() {
@Override
protected Status aggregateStatus(List<Status> candidates) {
return Status.UNKNOWN;
}
};
}
}
@Configuration(proxyBeanMethods = false)
static class HealthStatusHttpMapperConfiguration {
@Bean
HealthStatusHttpMapper healthStatusHttpMapper() {
return new HealthStatusHttpMapper() {
@Override
public int mapStatus(Status status) {
return 123;
}
};
}
}
@Configuration(proxyBeanMethods = false)
static class StatusAggregatorConfiguration {

View File

@@ -1,86 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test to ensure that the legacy {@link HealthIndicatorRegistry} can still be
* injected.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
public class HealthIndicatorRegistryInjectionIntegrationTests {
// gh-18194
@Test
void meterRegistryBeanHasBeenConfigured(@Autowired MeterRegistry meterRegistry) {
assertThat(meterRegistry).isNotNull();
assertThat(meterRegistry.get("health").gauge()).isNotNull();
}
@Configuration
@ImportAutoConfiguration({ HealthEndpointAutoConfiguration.class, HealthContributorAutoConfiguration.class,
CompositeMeterRegistryAutoConfiguration.class, MetricsAutoConfiguration.class })
static class Config {
Config(HealthAggregator healthAggregator, HealthIndicatorRegistry healthIndicatorRegistry,
MeterRegistry registry) {
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(healthAggregator,
healthIndicatorRegistry);
Gauge.builder("health", healthIndicator, this::getGuageValue)
.description("Spring boot health indicator. 3=UP, 2=OUT_OF_SERVICE, 1=DOWN, 0=UNKNOWN")
.strongReference(true).register(registry);
}
private double getGuageValue(CompositeHealthIndicator health) {
Status status = health.health().getStatus();
switch (status.getCode()) {
case "UP":
return 3;
case "OUT_OF_SERVICE":
return 2;
case "DOWN":
return 1;
case "UNKNOWN":
default:
return 0;
}
}
}
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.Status;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link HealthStatusHttpMapperHttpCodeStatusMapperAdapter}.
*
* @author Phillip Webb
*/
@SuppressWarnings("deprecation")
class HealthStatusHttpMapperHttpCodeStatusMapperAdapterTests {
@Test
void getStatusCodeDelegatesToHealthStatusHttpMapper() {
HttpCodeStatusMapper adapter = new HealthStatusHttpMapperHttpCodeStatusMapperAdapter(
new TestHealthStatusHttpMapper());
assertThat(adapter.getStatusCode(Status.UP)).isEqualTo(123);
}
static class TestHealthStatusHttpMapper extends HealthStatusHttpMapper {
@Override
public int mapStatus(Status status) {
return 123;
}
}
}

View File

@@ -1,110 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.health;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
import org.springframework.boot.actuate.health.DefaultReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
/**
* Test for
* {@link ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter}.
*
* @author Phillip Webb
*/
class ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapterTests {
private ReactiveHealthContributorRegistry contributorRegistry = new DefaultReactiveHealthContributorRegistry();
private ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter adapter = new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(
this.contributorRegistry);
@Test
void createWhenContributorRegistryIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(null))
.withMessage("ContributorRegistry must not be null");
}
@Test
void registerDelegatesToContributorRegistry() {
ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class);
this.adapter.register("test", healthIndicator);
assertThat(this.contributorRegistry.getContributor("test")).isSameAs(healthIndicator);
}
@Test
void unregisterDelegatesToContributorRegistry() {
ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
ReactiveHealthIndicator unregistered = this.adapter.unregister("test");
assertThat(unregistered).isSameAs(healthIndicator);
assertThat(this.contributorRegistry.getContributor("test")).isNull();
}
@Test
void unregisterWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() {
CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class);
this.contributorRegistry.registerContributor("test", healthContributor);
ReactiveHealthIndicator unregistered = this.adapter.unregister("test");
assertThat(unregistered).isNull();
assertThat(this.contributorRegistry.getContributor("test")).isNull();
}
@Test
void getDelegatesToContributorRegistry() {
ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
assertThat(this.adapter.get("test")).isSameAs(healthIndicator);
}
@Test
void getWhenContributorRegistryResultIsNotHealthIndicatorReturnsNull() {
CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class);
this.contributorRegistry.registerContributor("test", healthContributor);
assertThat(this.adapter.get("test")).isNull();
}
@Test
void getAllDelegatesToContributorRegistry() {
ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class);
this.contributorRegistry.registerContributor("test", healthIndicator);
Map<String, ReactiveHealthIndicator> all = this.adapter.getAll();
assertThat(all).containsOnly(entry("test", healthIndicator));
}
@Test
void getAllWhenContributorRegistryContainsNonHealthIndicatorInstancesReturnsFilteredMap() {
CompositeReactiveHealthContributor healthContributor = mock(CompositeReactiveHealthContributor.class);
this.contributorRegistry.registerContributor("test1", healthContributor);
ReactiveHealthIndicator healthIndicator = mock(ReactiveHealthIndicator.class);
this.contributorRegistry.registerContributor("test2", healthIndicator);
Map<String, ReactiveHealthIndicator> all = this.adapter.getAll();
assertThat(all).containsOnly(entry("test2", healthIndicator));
}
}