Remove deprecated HealthIndicator and HealthAggregator 2.2 code
See gh-19699pull/19789/head
parent
1f1b06dfe2
commit
2e32cb2af1
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,100 +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.elasticsearch;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.Requests;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link HealthIndicator} for an Elasticsearch cluster.
|
|
||||||
*
|
|
||||||
* @author Binwei Yang
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
|
|
||||||
* deprecated upstream
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {
|
|
||||||
|
|
||||||
private static final String[] ALL_INDICES = { "_all" };
|
|
||||||
|
|
||||||
private final Client client;
|
|
||||||
|
|
||||||
private final String[] indices;
|
|
||||||
|
|
||||||
private final long responseTimeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ElasticsearchHealthIndicator} instance.
|
|
||||||
* @param client the Elasticsearch client
|
|
||||||
* @param responseTimeout the request timeout in milliseconds
|
|
||||||
* @param indices the indices to check
|
|
||||||
*/
|
|
||||||
public ElasticsearchHealthIndicator(Client client, long responseTimeout, List<String> indices) {
|
|
||||||
this(client, responseTimeout, (indices != null) ? StringUtils.toStringArray(indices) : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ElasticsearchHealthIndicator} instance.
|
|
||||||
* @param client the Elasticsearch client
|
|
||||||
* @param responseTimeout the request timeout in milliseconds
|
|
||||||
* @param indices the indices to check
|
|
||||||
*/
|
|
||||||
public ElasticsearchHealthIndicator(Client client, long responseTimeout, String... indices) {
|
|
||||||
super("Elasticsearch health check failed");
|
|
||||||
this.client = client;
|
|
||||||
this.responseTimeout = responseTimeout;
|
|
||||||
this.indices = indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
|
||||||
ClusterHealthRequest request = Requests
|
|
||||||
.clusterHealthRequest(ObjectUtils.isEmpty(this.indices) ? ALL_INDICES : this.indices);
|
|
||||||
ClusterHealthResponse response = this.client.admin().cluster().health(request).actionGet(this.responseTimeout);
|
|
||||||
switch (response.getStatus()) {
|
|
||||||
case GREEN:
|
|
||||||
case YELLOW:
|
|
||||||
builder.up();
|
|
||||||
break;
|
|
||||||
case RED:
|
|
||||||
default:
|
|
||||||
builder.down();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
builder.withDetail("clusterName", response.getClusterName());
|
|
||||||
builder.withDetail("numberOfNodes", response.getNumberOfNodes());
|
|
||||||
builder.withDetail("numberOfDataNodes", response.getNumberOfDataNodes());
|
|
||||||
builder.withDetail("activePrimaryShards", response.getActivePrimaryShards());
|
|
||||||
builder.withDetail("activeShards", response.getActiveShards());
|
|
||||||
builder.withDetail("relocatingShards", response.getRelocatingShards());
|
|
||||||
builder.withDetail("initializingShards", response.getInitializingShards());
|
|
||||||
builder.withDetail("unassignedShards", response.getUnassignedShards());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,63 +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.health;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base {@link HealthAggregator} implementation to allow subclasses to focus on
|
|
||||||
* aggregating the {@link Status} instances and not deal with contextual details etc.
|
|
||||||
*
|
|
||||||
* @author Christian Dupuis
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @since 1.1.0
|
|
||||||
* @deprecated since 2.2.0 as {@link HealthAggregator} has been deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class AbstractHealthAggregator implements HealthAggregator {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final Health aggregate(Map<String, Health> healths) {
|
|
||||||
List<Status> statusCandidates = healths.values().stream().map(Health::getStatus).collect(Collectors.toList());
|
|
||||||
Status status = aggregateStatus(statusCandidates);
|
|
||||||
Map<String, Object> details = aggregateDetails(healths);
|
|
||||||
return new Health.Builder(status, details).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the single 'aggregate' status that should be used from the specified
|
|
||||||
* candidates.
|
|
||||||
* @param candidates the candidates
|
|
||||||
* @return a single status
|
|
||||||
*/
|
|
||||||
protected abstract Status aggregateStatus(List<Status> candidates);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the map of 'aggregate' details that should be used from the specified
|
|
||||||
* healths.
|
|
||||||
* @param healths the health instances to aggregate
|
|
||||||
* @return a map of details
|
|
||||||
* @since 1.3.1
|
|
||||||
*/
|
|
||||||
protected Map<String, Object> aggregateDetails(Map<String, Health> healths) {
|
|
||||||
return new LinkedHashMap<>(healths);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +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.health;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link HealthIndicator} that returns {@link Status#UP}.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
* @author Christian Dupuis
|
|
||||||
* @since 1.2.0
|
|
||||||
* @see Status#UP
|
|
||||||
* @deprecated since 2.2 in favor of {@link PingHealthIndicator}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ApplicationHealthIndicator extends AbstractHealthIndicator {
|
|
||||||
|
|
||||||
public ApplicationHealthIndicator() {
|
|
||||||
super("Application health check failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
|
||||||
builder.up();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,77 +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.health;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link HealthIndicator} that returns health indications from all registered delegates.
|
|
||||||
*
|
|
||||||
* @author Tyler J. Frederick
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Christian Dupuis
|
|
||||||
* @since 1.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of a {@link CompositeHealthContributor}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class CompositeHealthIndicator implements HealthIndicator {
|
|
||||||
|
|
||||||
private final HealthIndicatorRegistry registry;
|
|
||||||
|
|
||||||
private final HealthAggregator aggregator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link CompositeHealthIndicator} from the specified indicators.
|
|
||||||
* @param healthAggregator the health aggregator
|
|
||||||
* @param indicators a map of {@link HealthIndicator HealthIndicators} with the key
|
|
||||||
* being used as an indicator name.
|
|
||||||
*/
|
|
||||||
public CompositeHealthIndicator(HealthAggregator healthAggregator, Map<String, HealthIndicator> indicators) {
|
|
||||||
this(healthAggregator, new DefaultHealthIndicatorRegistry(indicators));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link CompositeHealthIndicator} from the indicators in the given
|
|
||||||
* {@code registry}.
|
|
||||||
* @param healthAggregator the health aggregator
|
|
||||||
* @param registry the registry of {@link HealthIndicator HealthIndicators}.
|
|
||||||
*/
|
|
||||||
public CompositeHealthIndicator(HealthAggregator healthAggregator, HealthIndicatorRegistry registry) {
|
|
||||||
this.aggregator = healthAggregator;
|
|
||||||
this.registry = registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the {@link HealthIndicatorRegistry} of this instance.
|
|
||||||
* @return the registry of nested {@link HealthIndicator health indicators}
|
|
||||||
* @since 2.1.0
|
|
||||||
*/
|
|
||||||
public HealthIndicatorRegistry getRegistry() {
|
|
||||||
return this.registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Health health() {
|
|
||||||
Map<String, Health> healths = new LinkedHashMap<>();
|
|
||||||
for (Map.Entry<String, HealthIndicator> entry : this.registry.getAll().entrySet()) {
|
|
||||||
healths.put(entry.getKey(), entry.getValue().health());
|
|
||||||
}
|
|
||||||
return this.aggregator.aggregate(healths);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,89 +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.health;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import reactor.util.function.Tuple2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link ReactiveHealthIndicator} that returns health indications from all registered
|
|
||||||
* delegates. Provides an alternative {@link Health} for a delegate that reaches a
|
|
||||||
* configurable timeout.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 in favor of a {@link CompositeReactiveHealthContributor}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator {
|
|
||||||
|
|
||||||
private final ReactiveHealthIndicatorRegistry registry;
|
|
||||||
|
|
||||||
private final HealthAggregator healthAggregator;
|
|
||||||
|
|
||||||
private Long timeout;
|
|
||||||
|
|
||||||
private Health timeoutHealth;
|
|
||||||
|
|
||||||
private final Function<Mono<Health>, Mono<Health>> timeoutCompose;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link CompositeReactiveHealthIndicator} from the indicators in the
|
|
||||||
* given {@code registry}.
|
|
||||||
* @param healthAggregator the health aggregator
|
|
||||||
* @param registry the registry of {@link ReactiveHealthIndicator HealthIndicators}.
|
|
||||||
*/
|
|
||||||
public CompositeReactiveHealthIndicator(HealthAggregator healthAggregator,
|
|
||||||
ReactiveHealthIndicatorRegistry registry) {
|
|
||||||
this.registry = registry;
|
|
||||||
this.healthAggregator = healthAggregator;
|
|
||||||
this.timeoutCompose = (mono) -> (this.timeout != null)
|
|
||||||
? mono.timeout(Duration.ofMillis(this.timeout), Mono.just(this.timeoutHealth)) : mono;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify an alternative timeout {@link Health} if a {@link HealthIndicator} failed
|
|
||||||
* to reply after specified {@code timeout}.
|
|
||||||
* @param timeout number of milliseconds to wait before using the
|
|
||||||
* {@code timeoutHealth}
|
|
||||||
* @param timeoutHealth the {@link Health} to use if an health indicator reached the
|
|
||||||
* {@code timeout}
|
|
||||||
* @return this instance
|
|
||||||
*/
|
|
||||||
public CompositeReactiveHealthIndicator timeoutStrategy(long timeout, Health timeoutHealth) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
this.timeoutHealth = (timeoutHealth != null) ? timeoutHealth : Health.unknown().build();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReactiveHealthIndicatorRegistry getRegistry() {
|
|
||||||
return this.registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Health> health() {
|
|
||||||
return Flux.fromIterable(this.registry.getAll().entrySet())
|
|
||||||
.flatMap((entry) -> Mono.zip(Mono.just(entry.getKey()),
|
|
||||||
entry.getValue().health().transformDeferred(this.timeoutCompose)))
|
|
||||||
.collectMap(Tuple2::getT1, Tuple2::getT2).map(this.healthAggregator::aggregate);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,92 +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.health;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link HealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link DefaultContributorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class DefaultHealthIndicatorRegistry implements HealthIndicatorRegistry {
|
|
||||||
|
|
||||||
private final Object monitor = new Object();
|
|
||||||
|
|
||||||
private final Map<String, HealthIndicator> healthIndicators;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link DefaultHealthIndicatorRegistry}.
|
|
||||||
*/
|
|
||||||
public DefaultHealthIndicatorRegistry() {
|
|
||||||
this(new LinkedHashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link DefaultHealthIndicatorRegistry} from the specified indicators.
|
|
||||||
* @param healthIndicators a map of {@link HealthIndicator}s with the key being used
|
|
||||||
* as an indicator name.
|
|
||||||
*/
|
|
||||||
public DefaultHealthIndicatorRegistry(Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
|
||||||
this.healthIndicators = new LinkedHashMap<>(healthIndicators);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(String name, HealthIndicator healthIndicator) {
|
|
||||||
Assert.notNull(healthIndicator, "HealthIndicator must not be null");
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
HealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator);
|
|
||||||
if (existing != null) {
|
|
||||||
throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HealthIndicator unregister(String name) {
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return this.healthIndicators.remove(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HealthIndicator get(String name) {
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return this.healthIndicators.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, HealthIndicator> getAll() {
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,93 +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.health;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default implementation of {@link ReactiveHealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link DefaultContributorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class DefaultReactiveHealthIndicatorRegistry implements ReactiveHealthIndicatorRegistry {
|
|
||||||
|
|
||||||
private final Object monitor = new Object();
|
|
||||||
|
|
||||||
private final Map<String, ReactiveHealthIndicator> healthIndicators;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link DefaultReactiveHealthIndicatorRegistry}.
|
|
||||||
*/
|
|
||||||
public DefaultReactiveHealthIndicatorRegistry() {
|
|
||||||
this(new LinkedHashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link DefaultReactiveHealthIndicatorRegistry} from the specified
|
|
||||||
* indicators.
|
|
||||||
* @param healthIndicators a map of {@link HealthIndicator}s with the key being used
|
|
||||||
* as an indicator name.
|
|
||||||
*/
|
|
||||||
public DefaultReactiveHealthIndicatorRegistry(Map<String, ReactiveHealthIndicator> healthIndicators) {
|
|
||||||
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
|
||||||
this.healthIndicators = new LinkedHashMap<>(healthIndicators);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(String name, ReactiveHealthIndicator healthIndicator) {
|
|
||||||
Assert.notNull(healthIndicator, "HealthIndicator must not be null");
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
ReactiveHealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator);
|
|
||||||
if (existing != null) {
|
|
||||||
throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ReactiveHealthIndicator unregister(String name) {
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return this.healthIndicators.remove(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ReactiveHealthIndicator get(String name) {
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return this.healthIndicators.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, ReactiveHealthIndicator> getAll() {
|
|
||||||
synchronized (this.monitor) {
|
|
||||||
return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,48 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strategy interface used to aggregate {@link Health} instances into a final one.
|
|
||||||
* <p>
|
|
||||||
* This is especially useful to combine subsystem states expressed through
|
|
||||||
* {@link Health#getStatus()} into one state for the entire system. The default
|
|
||||||
* implementation {@link OrderedHealthAggregator} sorts {@link Status} instances based on
|
|
||||||
* a priority list.
|
|
||||||
* <p>
|
|
||||||
* 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
|
|
||||||
* need to register a custom {@link HealthAggregator} as bean.
|
|
||||||
*
|
|
||||||
* @author Christian Dupuis
|
|
||||||
* @since 1.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link StatusAggregator}
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
@Deprecated
|
|
||||||
public interface HealthAggregator {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aggregate several given {@link Health} instances into one.
|
|
||||||
* @param healths the health instances to aggregate
|
|
||||||
* @return the aggregated health
|
|
||||||
*/
|
|
||||||
Health aggregate(Map<String, Health> healths);
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +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.health;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a sensible health indicator name based on its bean name.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link HealthContributorNameFactory}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class HealthIndicatorNameFactory extends HealthContributorNameFactory {
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A mutable registry of {@link HealthIndicator HealthIndicators}.
|
|
||||||
* <p>
|
|
||||||
* Implementations <strong>must</strong> be thread-safe.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @see HealthEndpoint
|
|
||||||
* @deprecated since 2.2.0 in favor of a {@link HealthContributorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface HealthIndicatorRegistry {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the given {@link HealthIndicator}, associating it with the given
|
|
||||||
* {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @param healthIndicator the indicator
|
|
||||||
* @throws IllegalStateException if the indicator cannot be registered with the given
|
|
||||||
* {@code name}.
|
|
||||||
*/
|
|
||||||
void register(String name, HealthIndicator healthIndicator);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters the {@link HealthIndicator} previously registered with the given
|
|
||||||
* {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @return the unregistered indicator, or {@code null} if no indicator was found in
|
|
||||||
* the registry for the given {@code name}.
|
|
||||||
*/
|
|
||||||
HealthIndicator unregister(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link HealthIndicator} registered with the given {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @return the health indicator, or {@code null} if no indicator was registered with
|
|
||||||
* the given {@code name}.
|
|
||||||
*/
|
|
||||||
HealthIndicator get(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a snapshot of the registered health indicators and their names. The
|
|
||||||
* contents of the map do not reflect subsequent changes to the registry.
|
|
||||||
* @return the snapshot of registered health indicators
|
|
||||||
*/
|
|
||||||
Map<String, HealthIndicator> getAll();
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory to create a {@link HealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link DefaultHealthIndicatorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class HealthIndicatorRegistryFactory {
|
|
||||||
|
|
||||||
private final Function<String, String> healthIndicatorNameFactory;
|
|
||||||
|
|
||||||
public HealthIndicatorRegistryFactory(Function<String, String> healthIndicatorNameFactory) {
|
|
||||||
this.healthIndicatorNameFactory = healthIndicatorNameFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HealthIndicatorRegistryFactory() {
|
|
||||||
this(new HealthIndicatorNameFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a {@link HealthIndicatorRegistry} based on the specified health indicators.
|
|
||||||
* @param healthIndicators the {@link HealthIndicator} instances mapped by name
|
|
||||||
* @return a {@link HealthIndicator} that delegates to the specified
|
|
||||||
* {@code healthIndicators}.
|
|
||||||
*/
|
|
||||||
public HealthIndicatorRegistry createHealthIndicatorRegistry(Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
|
||||||
return initialize(new DefaultHealthIndicatorRegistry(), healthIndicators);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <T extends HealthIndicatorRegistry> T initialize(T registry,
|
|
||||||
Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) {
|
|
||||||
String name = this.healthIndicatorNameFactory.apply(entry.getKey());
|
|
||||||
registry.register(name, entry.getValue());
|
|
||||||
}
|
|
||||||
return registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,127 +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.health;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map a {@link Status} to an HTTP status code.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link HttpCodeStatusMapper} or
|
|
||||||
* {@link SimpleHttpCodeStatusMapper}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class HealthStatusHttpMapper {
|
|
||||||
|
|
||||||
private Map<String, Integer> statusMapping = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance.
|
|
||||||
*/
|
|
||||||
public HealthStatusHttpMapper() {
|
|
||||||
setupDefaultStatusMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupDefaultStatusMapping() {
|
|
||||||
addStatusMapping(Status.DOWN, WebEndpointResponse.STATUS_SERVICE_UNAVAILABLE);
|
|
||||||
addStatusMapping(Status.OUT_OF_SERVICE, WebEndpointResponse.STATUS_SERVICE_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set specific status mappings.
|
|
||||||
* @param statusMapping a map of health status code to HTTP status code
|
|
||||||
*/
|
|
||||||
public void setStatusMapping(Map<String, Integer> statusMapping) {
|
|
||||||
Assert.notNull(statusMapping, "StatusMapping must not be null");
|
|
||||||
this.statusMapping = new HashMap<>(statusMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add specific status mappings to the existing set.
|
|
||||||
* @param statusMapping a map of health status code to HTTP status code
|
|
||||||
*/
|
|
||||||
public void addStatusMapping(Map<String, Integer> statusMapping) {
|
|
||||||
Assert.notNull(statusMapping, "StatusMapping must not be null");
|
|
||||||
this.statusMapping.putAll(statusMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a status mapping to the existing set.
|
|
||||||
* @param status the status to map
|
|
||||||
* @param httpStatus the http status
|
|
||||||
*/
|
|
||||||
public void addStatusMapping(Status status, Integer httpStatus) {
|
|
||||||
Assert.notNull(status, "Status must not be null");
|
|
||||||
Assert.notNull(httpStatus, "HttpStatus must not be null");
|
|
||||||
addStatusMapping(status.getCode(), httpStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a status mapping to the existing set.
|
|
||||||
* @param statusCode the status code to map
|
|
||||||
* @param httpStatus the http status
|
|
||||||
*/
|
|
||||||
public void addStatusMapping(String statusCode, Integer httpStatus) {
|
|
||||||
Assert.notNull(statusCode, "StatusCode must not be null");
|
|
||||||
Assert.notNull(httpStatus, "HttpStatus must not be null");
|
|
||||||
this.statusMapping.put(statusCode, httpStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an immutable view of the status mapping.
|
|
||||||
* @return the http status codes mapped by status name
|
|
||||||
*/
|
|
||||||
public Map<String, Integer> getStatusMapping() {
|
|
||||||
return Collections.unmodifiableMap(this.statusMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the specified {@link Status} to an HTTP status code.
|
|
||||||
* @param status the health {@link Status}
|
|
||||||
* @return the corresponding HTTP status code
|
|
||||||
*/
|
|
||||||
public int mapStatus(Status status) {
|
|
||||||
String code = getUniformValue(status.getCode());
|
|
||||||
if (code != null) {
|
|
||||||
return this.statusMapping.entrySet().stream()
|
|
||||||
.filter((entry) -> code.equals(getUniformValue(entry.getKey()))).map(Map.Entry::getValue)
|
|
||||||
.findFirst().orElse(WebEndpointResponse.STATUS_OK);
|
|
||||||
}
|
|
||||||
return WebEndpointResponse.STATUS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUniformValue(String code) {
|
|
||||||
if (code == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (char ch : code.toCharArray()) {
|
|
||||||
if (Character.isAlphabetic(ch) || Character.isDigit(ch)) {
|
|
||||||
builder.append(Character.toLowerCase(ch));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,140 +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.health;
|
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
|
||||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a {@link Health} to a {@link WebEndpointResponse}.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link HealthEndpointWebExtension} or
|
|
||||||
* {@link ReactiveHealthEndpointWebExtension}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class HealthWebEndpointResponseMapper {
|
|
||||||
|
|
||||||
private final HealthStatusHttpMapper statusHttpMapper;
|
|
||||||
|
|
||||||
private final ShowDetails showDetails;
|
|
||||||
|
|
||||||
private final Set<String> authorizedRoles;
|
|
||||||
|
|
||||||
public HealthWebEndpointResponseMapper(HealthStatusHttpMapper statusHttpMapper, ShowDetails showDetails,
|
|
||||||
Set<String> authorizedRoles) {
|
|
||||||
this.statusHttpMapper = statusHttpMapper;
|
|
||||||
this.showDetails = showDetails;
|
|
||||||
this.authorizedRoles = authorizedRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the given {@code health} details to a {@link WebEndpointResponse}, honouring
|
|
||||||
* the mapper's default {@link ShowDetails} using the given {@code securityContext}.
|
|
||||||
* <p>
|
|
||||||
* If the current user does not have the right to see the details, the
|
|
||||||
* {@link Supplier} is not invoked and a 404 response is returned instead.
|
|
||||||
* @param health the provider of health details, invoked if the current user has the
|
|
||||||
* right to see them
|
|
||||||
* @param securityContext the security context
|
|
||||||
* @return the mapped response
|
|
||||||
*/
|
|
||||||
public WebEndpointResponse<Health> mapDetails(Supplier<Health> health, SecurityContext securityContext) {
|
|
||||||
if (canSeeDetails(securityContext, this.showDetails)) {
|
|
||||||
Health healthDetails = health.get();
|
|
||||||
if (healthDetails != null) {
|
|
||||||
return createWebEndpointResponse(healthDetails);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the given {@code health} to a {@link WebEndpointResponse}, honouring the
|
|
||||||
* mapper's default {@link ShowDetails} using the given {@code securityContext}.
|
|
||||||
* @param health the health to map
|
|
||||||
* @param securityContext the security context
|
|
||||||
* @return the mapped response
|
|
||||||
*/
|
|
||||||
public WebEndpointResponse<Health> map(Health health, SecurityContext securityContext) {
|
|
||||||
return map(health, securityContext, this.showDetails);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the given {@code health} to a {@link WebEndpointResponse}, honouring the given
|
|
||||||
* {@code showDetails} using the given {@code securityContext}.
|
|
||||||
* @param health the health to map
|
|
||||||
* @param securityContext the security context
|
|
||||||
* @param showDetails when to show details in the response
|
|
||||||
* @return the mapped response
|
|
||||||
*/
|
|
||||||
public WebEndpointResponse<Health> map(Health health, SecurityContext securityContext, ShowDetails showDetails) {
|
|
||||||
if (!canSeeDetails(securityContext, showDetails)) {
|
|
||||||
health = Health.status(health.getStatus()).build();
|
|
||||||
}
|
|
||||||
return createWebEndpointResponse(health);
|
|
||||||
}
|
|
||||||
|
|
||||||
private WebEndpointResponse<Health> createWebEndpointResponse(Health health) {
|
|
||||||
int status = this.statusHttpMapper.mapStatus(health.getStatus());
|
|
||||||
return new WebEndpointResponse<>(health, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) {
|
|
||||||
return showDetails != ShowDetails.NEVER && (showDetails != ShowDetails.WHEN_AUTHORIZED
|
|
||||||
|| (securityContext.getPrincipal() != null && isUserInRole(securityContext)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUserInRole(SecurityContext securityContext) {
|
|
||||||
if (CollectionUtils.isEmpty(this.authorizedRoles)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Principal principal = securityContext.getPrincipal();
|
|
||||||
boolean checkAuthorities = isSpringSecurityAuthentication(principal);
|
|
||||||
for (String role : this.authorizedRoles) {
|
|
||||||
if (securityContext.isUserInRole(role)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (checkAuthorities) {
|
|
||||||
Authentication authentication = (Authentication) principal;
|
|
||||||
for (GrantedAuthority authority : authentication.getAuthorities()) {
|
|
||||||
String name = authority.getAuthority();
|
|
||||||
if (role.equals(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSpringSecurityAuthentication(Principal principal) {
|
|
||||||
return ClassUtils.isPresent("org.springframework.security.core.Authentication", null)
|
|
||||||
&& (principal instanceof Authentication);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
* 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.health;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default {@link HealthAggregator} implementation that aggregates {@link Health}
|
|
||||||
* instances and determines the final system state based on a simple ordered list.
|
|
||||||
* <p>
|
|
||||||
* 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)}.
|
|
||||||
*
|
|
||||||
* @author Christian Dupuis
|
|
||||||
* @since 1.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link SimpleStatusAggregator}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class OrderedHealthAggregator extends AbstractHealthAggregator {
|
|
||||||
|
|
||||||
private List<String> statusOrder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link OrderedHealthAggregator} instance.
|
|
||||||
*/
|
|
||||||
public OrderedHealthAggregator() {
|
|
||||||
setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the ordering of the status.
|
|
||||||
* @param statusOrder an ordered list of the status
|
|
||||||
*/
|
|
||||||
public void setStatusOrder(Status... statusOrder) {
|
|
||||||
String[] order = new String[statusOrder.length];
|
|
||||||
for (int i = 0; i < statusOrder.length; i++) {
|
|
||||||
order[i] = statusOrder[i].getCode();
|
|
||||||
}
|
|
||||||
setStatusOrder(Arrays.asList(order));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the ordering of the status.
|
|
||||||
* @param statusOrder an ordered list of the status codes
|
|
||||||
*/
|
|
||||||
public void setStatusOrder(List<String> statusOrder) {
|
|
||||||
Assert.notNull(statusOrder, "StatusOrder must not be null");
|
|
||||||
this.statusOrder = statusOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Status aggregateStatus(List<Status> candidates) {
|
|
||||||
// Only sort those status instances that we know about
|
|
||||||
List<Status> filteredCandidates = new ArrayList<>();
|
|
||||||
for (Status candidate : candidates) {
|
|
||||||
if (this.statusOrder.contains(candidate.getCode())) {
|
|
||||||
filteredCandidates.add(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If no status is given return UNKNOWN
|
|
||||||
if (filteredCandidates.isEmpty()) {
|
|
||||||
return Status.UNKNOWN;
|
|
||||||
}
|
|
||||||
// Sort given Status instances by configured order
|
|
||||||
filteredCandidates.sort(new StatusComparator(this.statusOrder));
|
|
||||||
return filteredCandidates.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Comparator} used to order {@link Status}.
|
|
||||||
*/
|
|
||||||
private static class StatusComparator implements Comparator<Status> {
|
|
||||||
|
|
||||||
private final List<String> statusOrder;
|
|
||||||
|
|
||||||
StatusComparator(List<String> statusOrder) {
|
|
||||||
this.statusOrder = statusOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Status s1, Status s2) {
|
|
||||||
int i1 = this.statusOrder.indexOf(s1.getCode());
|
|
||||||
int i2 = this.statusOrder.indexOf(s2.getCode());
|
|
||||||
return (i1 < i2) ? -1 : (i1 != i2) ? 1 : s1.getCode().compareTo(s2.getCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A registry of {@link ReactiveHealthIndicator ReactiveHealthIndicators}.
|
|
||||||
* <p>
|
|
||||||
* Implementations <strong>must</strong> be thread-safe.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @see HealthIndicatorRegistry
|
|
||||||
* @deprecated since 2.2.0 in favor of a {@link ReactiveHealthContributorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface ReactiveHealthIndicatorRegistry {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the given {@link ReactiveHealthIndicator}, associating it with the given
|
|
||||||
* {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @param healthIndicator the indicator
|
|
||||||
* @throws IllegalStateException if an indicator with the given {@code name} is
|
|
||||||
* already registered.
|
|
||||||
*/
|
|
||||||
void register(String name, ReactiveHealthIndicator healthIndicator);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters the {@link ReactiveHealthIndicator} previously registered with the
|
|
||||||
* given {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @return the unregistered indicator, or {@code null} if no indicator was found in
|
|
||||||
* the registry for the given {@code name}.
|
|
||||||
*/
|
|
||||||
ReactiveHealthIndicator unregister(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link ReactiveHealthIndicator} registered with the given {@code name}.
|
|
||||||
* @param name the name of the indicator
|
|
||||||
* @return the health indicator, or {@code null} if no indicator was registered with
|
|
||||||
* the given {@code name}.
|
|
||||||
*/
|
|
||||||
ReactiveHealthIndicator get(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a snapshot of the registered health indicators and their names. The
|
|
||||||
* contents of the map do not reflect subsequent changes to the registry.
|
|
||||||
* @return the snapshot of registered health indicators
|
|
||||||
*/
|
|
||||||
Map<String, ReactiveHealthIndicator> getAll();
|
|
||||||
|
|
||||||
}
|
|
@ -1,88 +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.health;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory to create a {@link HealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@link DefaultReactiveHealthIndicatorRegistry}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ReactiveHealthIndicatorRegistryFactory {
|
|
||||||
|
|
||||||
private final Function<String, String> healthIndicatorNameFactory;
|
|
||||||
|
|
||||||
public ReactiveHealthIndicatorRegistryFactory(Function<String, String> healthIndicatorNameFactory) {
|
|
||||||
this.healthIndicatorNameFactory = healthIndicatorNameFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReactiveHealthIndicatorRegistryFactory() {
|
|
||||||
this(new HealthIndicatorNameFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a {@link ReactiveHealthIndicatorRegistry} based on the specified health
|
|
||||||
* indicators. Each {@link HealthIndicator} are wrapped to a
|
|
||||||
* {@link HealthIndicatorReactiveAdapter}. If two instances share the same name, the
|
|
||||||
* reactive variant takes precedence.
|
|
||||||
* @param reactiveHealthIndicators the {@link ReactiveHealthIndicator} instances
|
|
||||||
* mapped by name
|
|
||||||
* @param healthIndicators the {@link HealthIndicator} instances mapped by name if
|
|
||||||
* any.
|
|
||||||
* @return a {@link ReactiveHealthIndicator} that delegates to the specified
|
|
||||||
* {@code reactiveHealthIndicators}.
|
|
||||||
*/
|
|
||||||
public ReactiveHealthIndicatorRegistry createReactiveHealthIndicatorRegistry(
|
|
||||||
Map<String, ReactiveHealthIndicator> reactiveHealthIndicators,
|
|
||||||
Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
Assert.notNull(reactiveHealthIndicators, "ReactiveHealthIndicators must not be null");
|
|
||||||
return initialize(new DefaultReactiveHealthIndicatorRegistry(), reactiveHealthIndicators, healthIndicators);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <T extends ReactiveHealthIndicatorRegistry> T initialize(T registry,
|
|
||||||
Map<String, ReactiveHealthIndicator> reactiveHealthIndicators,
|
|
||||||
Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
merge(reactiveHealthIndicators, healthIndicators).forEach((beanName, indicator) -> {
|
|
||||||
String name = this.healthIndicatorNameFactory.apply(beanName);
|
|
||||||
registry.register(name, indicator);
|
|
||||||
});
|
|
||||||
return registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, ReactiveHealthIndicator> merge(Map<String, ReactiveHealthIndicator> reactiveHealthIndicators,
|
|
||||||
Map<String, HealthIndicator> healthIndicators) {
|
|
||||||
if (ObjectUtils.isEmpty(healthIndicators)) {
|
|
||||||
return reactiveHealthIndicators;
|
|
||||||
}
|
|
||||||
Map<String, ReactiveHealthIndicator> allIndicators = new LinkedHashMap<>(reactiveHealthIndicators);
|
|
||||||
healthIndicators.forEach((beanName, indicator) -> {
|
|
||||||
String name = this.healthIndicatorNameFactory.apply(beanName);
|
|
||||||
allIndicators.computeIfAbsent(name, (n) -> new HealthIndicatorReactiveAdapter(indicator));
|
|
||||||
});
|
|
||||||
return allIndicators;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +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.health;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options for showing details in responses from the {@link HealthEndpoint} web
|
|
||||||
* extensions.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 in favor of {@code HealthEndpointProperties.ShowDetails}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public enum ShowDetails {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Never show details in the response.
|
|
||||||
*/
|
|
||||||
NEVER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show details in the response when accessed by an authorized user.
|
|
||||||
*/
|
|
||||||
WHEN_AUTHORIZED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Always show details in the response.
|
|
||||||
*/
|
|
||||||
ALWAYS
|
|
||||||
|
|
||||||
}
|
|
@ -1,225 +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.elasticsearch;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
|
||||||
import org.elasticsearch.ElasticsearchTimeoutException;
|
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
||||||
import org.elasticsearch.action.support.PlainActionFuture;
|
|
||||||
import org.elasticsearch.client.AdminClient;
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.ClusterAdminClient;
|
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
|
||||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
|
||||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.Status;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for {@link ElasticsearchHealthIndicator}.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class ElasticsearchHealthIndicatorTests {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private AdminClient admin;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ClusterAdminClient cluster;
|
|
||||||
|
|
||||||
private ElasticsearchHealthIndicator indicator;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
given(this.client.admin()).willReturn(this.admin);
|
|
||||||
given(this.admin.cluster()).willReturn(this.cluster);
|
|
||||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 100L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultConfigurationQueriesAllIndicesWith100msTimeout() {
|
|
||||||
TestActionFuture responseFuture = new TestActionFuture();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
|
||||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
|
||||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
|
||||||
Health health = this.indicator.health();
|
|
||||||
assertThat(responseFuture.getTimeout).isEqualTo(100L);
|
|
||||||
assertThat(requestCaptor.getValue().indices()).contains("_all");
|
|
||||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void certainIndices() {
|
|
||||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 100L, "test-index-1", "test-index-2");
|
|
||||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
|
||||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
|
||||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
|
||||||
Health health = this.indicator.health();
|
|
||||||
assertThat(requestCaptor.getValue().indices()).contains("test-index-1", "test-index-2");
|
|
||||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void customTimeout() {
|
|
||||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 1000L);
|
|
||||||
TestActionFuture responseFuture = new TestActionFuture();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
|
||||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
|
||||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
|
||||||
this.indicator.health();
|
|
||||||
assertThat(responseFuture.getTimeout).isEqualTo(1000L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void healthDetails() {
|
|
||||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
|
||||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
|
||||||
Health health = this.indicator.health();
|
|
||||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
|
||||||
Map<String, Object> details = health.getDetails();
|
|
||||||
assertDetail(details, "clusterName", "test-cluster");
|
|
||||||
assertDetail(details, "activeShards", 1);
|
|
||||||
assertDetail(details, "relocatingShards", 2);
|
|
||||||
assertDetail(details, "activePrimaryShards", 3);
|
|
||||||
assertDetail(details, "initializingShards", 4);
|
|
||||||
assertDetail(details, "unassignedShards", 5);
|
|
||||||
assertDetail(details, "numberOfNodes", 6);
|
|
||||||
assertDetail(details, "numberOfDataNodes", 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void redResponseMapsToDown() {
|
|
||||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED));
|
|
||||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
|
||||||
assertThat(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yellowResponseMapsToUp() {
|
|
||||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
|
||||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW));
|
|
||||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
|
||||||
assertThat(this.indicator.health().getStatus()).isEqualTo(Status.UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void responseTimeout() {
|
|
||||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
|
||||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
|
||||||
Health health = this.indicator.health();
|
|
||||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
assertThat((String) health.getDetails().get("error")).contains(ElasticsearchTimeoutException.class.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> void assertDetail(Map<String, Object> details, String detail, T value) {
|
|
||||||
assertThat((T) details.get(detail)).isEqualTo(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class StubClusterHealthResponse extends ClusterHealthResponse {
|
|
||||||
|
|
||||||
private final ClusterHealthStatus status;
|
|
||||||
|
|
||||||
private StubClusterHealthResponse() {
|
|
||||||
this(ClusterHealthStatus.GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private StubClusterHealthResponse(ClusterHealthStatus status) {
|
|
||||||
super("test-cluster", new String[0], new ClusterState(null, 0, null, null, RoutingTable.builder().build(),
|
|
||||||
DiscoveryNodes.builder().build(), ClusterBlocks.builder().build(), null, 1, false));
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getActiveShards() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRelocatingShards() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getActivePrimaryShards() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInitializingShards() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getUnassignedShards() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumberOfNodes() {
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumberOfDataNodes() {
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClusterHealthStatus getStatus() {
|
|
||||||
return this.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TestActionFuture extends PlainActionFuture<ClusterHealthResponse> {
|
|
||||||
|
|
||||||
private long getTimeout = -1L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClusterHealthResponse actionGet(long timeoutMillis) throws ElasticsearchException {
|
|
||||||
this.getTimeout = timeoutMillis;
|
|
||||||
return super.actionGet(timeoutMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +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.health;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ApplicationHealthIndicator}.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class ApplicationHealthIndicatorTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void indicatesUp() {
|
|
||||||
ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator();
|
|
||||||
assertThat(healthIndicator.health().getStatus()).isEqualTo(Status.UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,90 +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.health;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link CompositeHealthIndicator}
|
|
||||||
*
|
|
||||||
* @author Tyler J. Frederick
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Christian Dupuis
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class CompositeHealthIndicatorTests {
|
|
||||||
|
|
||||||
private HealthAggregator healthAggregator;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private HealthIndicator one;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private HealthIndicator two;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build());
|
|
||||||
given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build());
|
|
||||||
|
|
||||||
this.healthAggregator = new OrderedHealthAggregator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void createWithIndicators() {
|
|
||||||
Map<String, HealthIndicator> indicators = new HashMap<>();
|
|
||||||
indicators.put("one", this.one);
|
|
||||||
indicators.put("two", this.two);
|
|
||||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator, indicators);
|
|
||||||
Health result = composite.health();
|
|
||||||
assertThat(result.getDetails()).hasSize(2);
|
|
||||||
assertThat(result.getDetails()).containsEntry("one",
|
|
||||||
new Health.Builder().unknown().withDetail("1", "1").build());
|
|
||||||
assertThat(result.getDetails()).containsEntry("two",
|
|
||||||
new Health.Builder().unknown().withDetail("2", "2").build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testSerialization() throws Exception {
|
|
||||||
Map<String, HealthIndicator> indicators = new LinkedHashMap<>();
|
|
||||||
indicators.put("db1", this.one);
|
|
||||||
indicators.put("db2", this.two);
|
|
||||||
CompositeHealthIndicator innerComposite = new CompositeHealthIndicator(this.healthAggregator, indicators);
|
|
||||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator,
|
|
||||||
Collections.singletonMap("db", innerComposite));
|
|
||||||
Health result = composite.health();
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
assertThat(mapper.writeValueAsString(result))
|
|
||||||
.isEqualTo("{\"status\":\"UNKNOWN\",\"details\":{\"db\":{\"status\":\"UNKNOWN\""
|
|
||||||
+ ",\"details\":{\"db1\":{\"status\":\"UNKNOWN\",\"details\""
|
|
||||||
+ ":{\"1\":\"1\"}},\"db2\":{\"status\":\"UNKNOWN\",\"details\":{\"2\":\"2\"}}}}}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,120 +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.health;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import reactor.test.StepVerifier;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link CompositeReactiveHealthIndicator}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class CompositeReactiveHealthIndicatorTests {
|
|
||||||
|
|
||||||
private static final Health UNKNOWN_HEALTH = Health.unknown().withDetail("detail", "value").build();
|
|
||||||
|
|
||||||
private static final Health HEALTHY = Health.up().build();
|
|
||||||
|
|
||||||
private OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void singleIndicator() {
|
|
||||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
|
||||||
new DefaultReactiveHealthIndicatorRegistry(Collections.singletonMap("test", () -> Mono.just(HEALTHY))));
|
|
||||||
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
|
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
|
||||||
assertThat(h.getDetails()).containsOnlyKeys("test");
|
|
||||||
assertThat(h.getDetails().get("test")).isEqualTo(HEALTHY);
|
|
||||||
}).verifyComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void longHealth() {
|
|
||||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
indicators.put("test" + i, new TimeoutHealth(10000, Status.UP));
|
|
||||||
}
|
|
||||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
|
||||||
new DefaultReactiveHealthIndicatorRegistry(indicators));
|
|
||||||
StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000))
|
|
||||||
.consumeNextWith((h) -> {
|
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
|
||||||
assertThat(h.getDetails()).hasSize(50);
|
|
||||||
}).verifyComplete();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void timeoutReachedUsesFallback() {
|
|
||||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
|
||||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
|
||||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
|
||||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
|
||||||
new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(100, UNKNOWN_HEALTH);
|
|
||||||
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
|
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
|
||||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
|
||||||
assertThat(h.getDetails().get("slow")).isEqualTo(UNKNOWN_HEALTH);
|
|
||||||
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
|
|
||||||
}).verifyComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void timeoutNotReached() {
|
|
||||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
|
||||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
|
||||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
|
||||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
|
||||||
new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(20000, null);
|
|
||||||
StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000))
|
|
||||||
.consumeNextWith((h) -> {
|
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
|
||||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
|
||||||
assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY);
|
|
||||||
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
|
|
||||||
}).verifyComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TimeoutHealth implements ReactiveHealthIndicator {
|
|
||||||
|
|
||||||
private final long timeout;
|
|
||||||
|
|
||||||
private final Status status;
|
|
||||||
|
|
||||||
TimeoutHealth(long timeout, Status status) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<Health> health() {
|
|
||||||
return Mono.delay(Duration.ofMillis(this.timeout)).map((l) -> Health.status(this.status).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,103 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link DefaultHealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class DefaultHealthIndicatorRegistryTests {
|
|
||||||
|
|
||||||
private HealthIndicator one = mock(HealthIndicator.class);
|
|
||||||
|
|
||||||
private HealthIndicator two = mock(HealthIndicator.class);
|
|
||||||
|
|
||||||
private DefaultHealthIndicatorRegistry registry;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build());
|
|
||||||
given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build());
|
|
||||||
this.registry = new DefaultHealthIndicatorRegistry();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void register() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(2);
|
|
||||||
assertThat(this.registry.get("one")).isSameAs(this.one);
|
|
||||||
assertThat(this.registry.get("two")).isSameAs(this.two);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void registerAlreadyUsedName() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
|
||||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void unregister() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(2);
|
|
||||||
HealthIndicator two = this.registry.unregister("two");
|
|
||||||
assertThat(two).isSameAs(this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void unregisterUnknown() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
HealthIndicator two = this.registry.unregister("two");
|
|
||||||
assertThat(two).isNull();
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllIsASnapshot() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
|
||||||
assertThat(snapshot).containsOnlyKeys("one");
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(snapshot).containsOnlyKeys("one");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllIsImmutable() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,104 +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.health;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link DefaultReactiveHealthIndicatorRegistry}.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class DefaultReactiveHealthIndicatorRegistryTests {
|
|
||||||
|
|
||||||
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
|
||||||
|
|
||||||
private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class);
|
|
||||||
|
|
||||||
private DefaultReactiveHealthIndicatorRegistry registry;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
given(this.one.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("1", "1").build()));
|
|
||||||
given(this.two.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("2", "2").build()));
|
|
||||||
this.registry = new DefaultReactiveHealthIndicatorRegistry();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void register() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(2);
|
|
||||||
assertThat(this.registry.get("one")).isSameAs(this.one);
|
|
||||||
assertThat(this.registry.get("two")).isSameAs(this.two);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void registerAlreadyUsedName() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
|
||||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void unregister() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(2);
|
|
||||||
ReactiveHealthIndicator two = this.registry.unregister("two");
|
|
||||||
assertThat(two).isSameAs(this.two);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void unregisterUnknown() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
ReactiveHealthIndicator two = this.registry.unregister("two");
|
|
||||||
assertThat(two).isNull();
|
|
||||||
assertThat(this.registry.getAll()).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllIsASnapshot() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
|
||||||
assertThat(snapshot).containsOnlyKeys("one");
|
|
||||||
this.registry.register("two", this.two);
|
|
||||||
assertThat(snapshot).containsOnlyKeys("one");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllIsImmutable() {
|
|
||||||
this.registry.register("one", this.one);
|
|
||||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,155 +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.health;
|
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
|
||||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link HealthWebEndpointResponseMapper}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class HealthWebEndpointResponseMapperTests {
|
|
||||||
|
|
||||||
private final HealthStatusHttpMapper statusHttpMapper = new HealthStatusHttpMapper();
|
|
||||||
|
|
||||||
private Set<String> authorizedRoles = Collections.singleton("ACTUATOR");
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithDisableDetailsDoesNotInvokeSupplier() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.NEVER);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
SecurityContext securityContext = mock(SecurityContext.class);
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
|
||||||
verifyNoInteractions(supplier);
|
|
||||||
verifyNoInteractions(securityContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithUnauthorizedUserDoesNotInvokeSupplier() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
SecurityContext securityContext = mockSecurityContext("USER");
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
|
||||||
assertThat(response.getBody()).isNull();
|
|
||||||
verifyNoInteractions(supplier);
|
|
||||||
verify(securityContext).isUserInRole("ACTUATOR");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithAuthorizedUserInvokesSupplier() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
given(supplier.get()).willReturn(Health.down().build());
|
|
||||||
SecurityContext securityContext = mockSecurityContext("ACTUATOR");
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
|
||||||
assertThat(response.getBody().getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
verify(supplier).get();
|
|
||||||
verify(securityContext).isUserInRole("ACTUATOR");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithRightAuthoritiesInvokesSupplier() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
given(supplier.get()).willReturn(Health.down().build());
|
|
||||||
SecurityContext securityContext = getSecurityContext("ACTUATOR");
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
|
||||||
assertThat(response.getBody().getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
verify(supplier).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithOtherAuthoritiesShouldNotInvokeSupplier() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
given(supplier.get()).willReturn(Health.down().build());
|
|
||||||
SecurityContext securityContext = getSecurityContext("OTHER");
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
|
||||||
assertThat(response.getBody()).isNull();
|
|
||||||
verifyNoInteractions(supplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecurityContext getSecurityContext(String other) {
|
|
||||||
SecurityContext securityContext = mock(SecurityContext.class);
|
|
||||||
Authentication principal = mock(Authentication.class);
|
|
||||||
given(securityContext.getPrincipal()).willReturn(principal);
|
|
||||||
given(principal.getAuthorities())
|
|
||||||
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority(other)));
|
|
||||||
return securityContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mapDetailsWithUnavailableHealth() {
|
|
||||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.ALWAYS);
|
|
||||||
Supplier<Health> supplier = mockSupplier();
|
|
||||||
SecurityContext securityContext = mock(SecurityContext.class);
|
|
||||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
|
||||||
assertThat(response.getBody()).isNull();
|
|
||||||
verify(supplier).get();
|
|
||||||
verifyNoInteractions(securityContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Supplier<Health> mockSupplier() {
|
|
||||||
return mock(Supplier.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecurityContext mockSecurityContext(String... roles) {
|
|
||||||
List<String> associatedRoles = Arrays.asList(roles);
|
|
||||||
SecurityContext securityContext = mock(SecurityContext.class);
|
|
||||||
given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
|
|
||||||
given(securityContext.isUserInRole(anyString())).will((Answer<Boolean>) (invocation) -> {
|
|
||||||
String expectedRole = invocation.getArgument(0);
|
|
||||||
return associatedRoles.contains(expectedRole);
|
|
||||||
});
|
|
||||||
return securityContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HealthWebEndpointResponseMapper createMapper(ShowDetails showDetails) {
|
|
||||||
return new HealthWebEndpointResponseMapper(this.statusHttpMapper, showDetails, this.authorizedRoles);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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.health;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link OrderedHealthAggregator}.
|
|
||||||
*
|
|
||||||
* @author Christian Dupuis
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class OrderedHealthAggregatorTests {
|
|
||||||
|
|
||||||
private OrderedHealthAggregator healthAggregator;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setup() {
|
|
||||||
this.healthAggregator = new OrderedHealthAggregator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultOrder() {
|
|
||||||
Map<String, Health> healths = new HashMap<>();
|
|
||||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
|
||||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
|
||||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
|
||||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
|
||||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void customOrder() {
|
|
||||||
this.healthAggregator.setStatusOrder(Status.UNKNOWN, Status.UP, Status.OUT_OF_SERVICE, Status.DOWN);
|
|
||||||
Map<String, Health> healths = new HashMap<>();
|
|
||||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
|
||||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
|
||||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
|
||||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
|
||||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.UNKNOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultOrderWithCustomStatus() {
|
|
||||||
Map<String, Health> healths = new HashMap<>();
|
|
||||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
|
||||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
|
||||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
|
||||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
|
||||||
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
|
|
||||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void customOrderWithCustomStatus() {
|
|
||||||
this.healthAggregator.setStatusOrder(Arrays.asList("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN", "CUSTOM"));
|
|
||||||
Map<String, Health> healths = new HashMap<>();
|
|
||||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
|
||||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
|
||||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
|
||||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
|
||||||
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
|
|
||||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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.health;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
import reactor.test.StepVerifier;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ReactiveHealthIndicatorRegistryFactory}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class ReactiveHealthIndicatorRegistryFactoryTests {
|
|
||||||
|
|
||||||
private static final Health UP = new Health.Builder().status(Status.UP).build();
|
|
||||||
|
|
||||||
private static final Health DOWN = new Health.Builder().status(Status.DOWN).build();
|
|
||||||
|
|
||||||
private final ReactiveHealthIndicatorRegistryFactory factory = new ReactiveHealthIndicatorRegistryFactory();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void defaultHealthIndicatorNameFactory() {
|
|
||||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
|
||||||
Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
|
|
||||||
assertThat(registry.getAll()).containsOnlyKeys("my");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void healthIndicatorIsAdapted() {
|
|
||||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
|
||||||
Collections.singletonMap("test", () -> Mono.just(UP)), Collections.singletonMap("regular", () -> DOWN));
|
|
||||||
assertThat(registry.getAll()).containsOnlyKeys("test", "regular");
|
|
||||||
StepVerifier.create(registry.get("regular").health()).consumeNextWith((h) -> {
|
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
|
||||||
assertThat(h.getDetails()).isEmpty();
|
|
||||||
}).verifyComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue