Skip to content

Commit de1a26c

Browse files
Revert "Remove deprecated HealthIndicator and HealthAggregator 2.2 code"
This reverts commit df1837a.
1 parent 256dee6 commit de1a26c

File tree

54 files changed

+3581
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3581
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.health;
18+
19+
import java.util.Map;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
23+
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
24+
import org.springframework.boot.actuate.health.HealthAggregator;
25+
import org.springframework.boot.actuate.health.HealthIndicator;
26+
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
27+
import org.springframework.core.ResolvableType;
28+
29+
/**
30+
* Base class for configurations that can combine source beans using a
31+
* {@link CompositeHealthIndicator}.
32+
*
33+
* @param <H> the health indicator type
34+
* @param <S> the bean source type
35+
* @author Stephane Nicoll
36+
* @since 2.0.0
37+
* @deprecated since 2.2.0 in favor of {@link CompositeHealthContributorConfiguration}
38+
*/
39+
@Deprecated
40+
public abstract class CompositeHealthIndicatorConfiguration<H extends HealthIndicator, S> {
41+
42+
@Autowired
43+
private HealthAggregator healthAggregator;
44+
45+
protected HealthIndicator createHealthIndicator(Map<String, S> beans) {
46+
if (beans.size() == 1) {
47+
return createHealthIndicator(beans.values().iterator().next());
48+
}
49+
HealthIndicatorRegistry registry = new DefaultHealthIndicatorRegistry();
50+
beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
51+
return new CompositeHealthIndicator(this.healthAggregator, registry);
52+
}
53+
54+
@SuppressWarnings("unchecked")
55+
protected H createHealthIndicator(S source) {
56+
Class<?>[] generics = ResolvableType.forClass(CompositeHealthIndicatorConfiguration.class, getClass())
57+
.resolveGenerics();
58+
Class<H> indicatorClass = (Class<H>) generics[0];
59+
Class<S> sourceClass = (Class<S>) generics[1];
60+
try {
61+
return indicatorClass.getConstructor(sourceClass).newInstance(source);
62+
}
63+
catch (Exception ex) {
64+
throw new IllegalStateException(
65+
"Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
66+
}
67+
}
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.health;
18+
19+
import java.util.Map;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.actuate.health.CompositeReactiveHealthIndicator;
23+
import org.springframework.boot.actuate.health.DefaultReactiveHealthIndicatorRegistry;
24+
import org.springframework.boot.actuate.health.HealthAggregator;
25+
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
26+
import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
27+
import org.springframework.core.ResolvableType;
28+
29+
/**
30+
* Reactive variant of {@link CompositeHealthIndicatorConfiguration}.
31+
*
32+
* @param <H> the health indicator type
33+
* @param <S> the bean source type
34+
* @author Stephane Nicoll
35+
* @since 2.0.0
36+
* @deprecated since 2.2.0 in favor of
37+
* {@link CompositeReactiveHealthContributorConfiguration}
38+
*/
39+
@Deprecated
40+
public abstract class CompositeReactiveHealthIndicatorConfiguration<H extends ReactiveHealthIndicator, S> {
41+
42+
@Autowired
43+
private HealthAggregator healthAggregator;
44+
45+
protected ReactiveHealthIndicator createHealthIndicator(Map<String, S> beans) {
46+
if (beans.size() == 1) {
47+
return createHealthIndicator(beans.values().iterator().next());
48+
}
49+
ReactiveHealthIndicatorRegistry registry = new DefaultReactiveHealthIndicatorRegistry();
50+
beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
51+
return new CompositeReactiveHealthIndicator(this.healthAggregator, registry);
52+
}
53+
54+
@SuppressWarnings("unchecked")
55+
protected H createHealthIndicator(S source) {
56+
Class<?>[] generics = ResolvableType.forClass(CompositeReactiveHealthIndicatorConfiguration.class, getClass())
57+
.resolveGenerics();
58+
Class<H> indicatorClass = (Class<H>) generics[0];
59+
Class<S> sourceClass = (Class<S>) generics[1];
60+
try {
61+
return indicatorClass.getConstructor(sourceClass).newInstance(source);
62+
}
63+
catch (Exception ex) {
64+
throw new IllegalStateException(
65+
"Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
66+
}
67+
}
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.health;
18+
19+
import java.util.LinkedHashMap;
20+
import java.util.Map;
21+
import java.util.Set;
22+
23+
import org.springframework.boot.actuate.health.Health;
24+
import org.springframework.boot.actuate.health.HealthAggregator;
25+
import org.springframework.boot.actuate.health.Status;
26+
import org.springframework.boot.actuate.health.StatusAggregator;
27+
28+
/**
29+
* Adapter class to convert a legacy {@link HealthAggregator} to a
30+
* {@link StatusAggregator}.
31+
*
32+
* @author Phillip Webb
33+
*/
34+
@SuppressWarnings("deprecation")
35+
class HealthAggregatorStatusAggregatorAdapter implements StatusAggregator {
36+
37+
private HealthAggregator healthAggregator;
38+
39+
HealthAggregatorStatusAggregatorAdapter(HealthAggregator healthAggregator) {
40+
this.healthAggregator = healthAggregator;
41+
}
42+
43+
@Override
44+
public Status getAggregateStatus(Set<Status> statuses) {
45+
int index = 0;
46+
Map<String, Health> healths = new LinkedHashMap<>();
47+
for (Status status : statuses) {
48+
index++;
49+
healths.put("health" + index, asHealth(status));
50+
}
51+
Health aggregate = this.healthAggregator.aggregate(healths);
52+
return aggregate.getStatus();
53+
}
54+
55+
private Health asHealth(Status status) {
56+
return Health.status(status).build();
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.health;
18+
19+
import java.util.LinkedHashMap;
20+
import java.util.Map;
21+
22+
import org.springframework.boot.actuate.health.HealthContributor;
23+
import org.springframework.boot.actuate.health.HealthContributorRegistry;
24+
import org.springframework.boot.actuate.health.HealthIndicator;
25+
import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
26+
import org.springframework.boot.actuate.health.NamedContributor;
27+
import org.springframework.util.Assert;
28+
29+
/**
30+
* Adapter class to convert a {@link HealthContributorRegistry} to a legacy
31+
* {@link HealthIndicatorRegistry}.
32+
*
33+
* @author Phillip Webb
34+
*/
35+
@SuppressWarnings("deprecation")
36+
class HealthContributorRegistryHealthIndicatorRegistryAdapter implements HealthIndicatorRegistry {
37+
38+
private final HealthContributorRegistry contributorRegistry;
39+
40+
HealthContributorRegistryHealthIndicatorRegistryAdapter(HealthContributorRegistry contributorRegistry) {
41+
Assert.notNull(contributorRegistry, "ContributorRegistry must not be null");
42+
this.contributorRegistry = contributorRegistry;
43+
}
44+
45+
@Override
46+
public void register(String name, HealthIndicator healthIndicator) {
47+
this.contributorRegistry.registerContributor(name, healthIndicator);
48+
}
49+
50+
@Override
51+
public HealthIndicator unregister(String name) {
52+
HealthContributor contributor = this.contributorRegistry.unregisterContributor(name);
53+
if (contributor instanceof HealthIndicator) {
54+
return (HealthIndicator) contributor;
55+
}
56+
return null;
57+
}
58+
59+
@Override
60+
public HealthIndicator get(String name) {
61+
HealthContributor contributor = this.contributorRegistry.getContributor(name);
62+
if (contributor instanceof HealthIndicator) {
63+
return (HealthIndicator) contributor;
64+
}
65+
return null;
66+
}
67+
68+
@Override
69+
public Map<String, HealthIndicator> getAll() {
70+
Map<String, HealthIndicator> all = new LinkedHashMap<>();
71+
for (NamedContributor<?> namedContributor : this.contributorRegistry) {
72+
if (namedContributor.getContributor() instanceof HealthIndicator) {
73+
all.put(namedContributor.getName(), (HealthIndicator) namedContributor.getContributor());
74+
}
75+
}
76+
return all;
77+
}
78+
79+
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import org.springframework.boot.actuate.health.HealthEndpoint;
2121
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2222
import org.springframework.boot.context.properties.EnableConfigurationProperties;
23+
import org.springframework.context.annotation.Bean;
2324
import org.springframework.context.annotation.Configuration;
2425
import org.springframework.context.annotation.Import;
2526

@@ -29,14 +30,23 @@
2930
* @author Andy Wilkinson
3031
* @author Stephane Nicoll
3132
* @author Phillip Webb
32-
* @author Scott Frederick
3333
* @since 2.0.0
3434
*/
3535
@Configuration(proxyBeanMethods = false)
3636
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class)
37-
@EnableConfigurationProperties(HealthEndpointProperties.class)
38-
@Import({ HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
37+
@EnableConfigurationProperties
38+
@Import({ LegacyHealthEndpointAdaptersConfiguration.class, LegacyHealthEndpointCompatibilityConfiguration.class,
39+
HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
3940
HealthEndpointWebExtensionConfiguration.class, HealthEndpointReactiveWebExtensionConfiguration.class })
4041
public class HealthEndpointAutoConfiguration {
4142

43+
@Bean
44+
@SuppressWarnings("deprecation")
45+
HealthEndpointProperties healthEndpointProperties(HealthIndicatorProperties healthIndicatorProperties) {
46+
HealthEndpointProperties healthEndpointProperties = new HealthEndpointProperties();
47+
healthEndpointProperties.getStatus().getOrder().addAll(healthIndicatorProperties.getOrder());
48+
healthEndpointProperties.getStatus().getHttpMapping().putAll(healthIndicatorProperties.getHttpMapping());
49+
return healthEndpointProperties;
50+
}
51+
4252
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.health;
18+
19+
import org.springframework.boot.actuate.health.HealthContributor;
20+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
/**
24+
* {@link EnableAutoConfiguration Auto-configuration} for {@link HealthContributor health
25+
* contributors}.
26+
*
27+
* @author Andy Wilkinson
28+
* @author Stephane Nicoll
29+
* @author Phillip Webb
30+
* @author Vedran Pavic
31+
* @since 2.0.0
32+
* @deprecated since 2.2.0 in favor of {@link HealthContributorAutoConfiguration}
33+
*/
34+
@Deprecated
35+
@Configuration(proxyBeanMethods = false)
36+
public class HealthIndicatorAutoConfiguration {
37+
38+
}

0 commit comments

Comments
 (0)