Add configuration meta-data property for the number of members in the DistributedSystem.

Guard against null/unset URLs for the DistributedSystem standard gemfire properties and security properties locations.
This commit is contained in:
John Blum
2018-09-21 15:07:28 -07:00
parent f9ef704ab2
commit e5f31b56d4
2 changed files with 29 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.geode.boot.actuate;
import java.net.URL;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Function;
@@ -29,6 +30,7 @@ import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.geode.boot.actuate.health.AbstractGeodeHealthIndicator;
import org.springframework.util.StringUtils;
/**
* The {@link GeodeCacheHealthIndicator} class is a Spring Boot {@link HealthIndicator} providing details about
@@ -135,12 +137,23 @@ public class GeodeCacheHealthIndicator extends AbstractGeodeHealthIndicator {
return healthBuilder -> getGemFireCache()
.map(GemFireCache::getDistributedSystem)
.map(distributedSystem -> healthBuilder
.withDetail("geode.distributed-system.member-count", Optional.of(distributedSystem)
.map(DistributedSystem::getAllOtherMembers)
.map(Collection::size)
.map(size -> size + 1)
.orElse(1))
.withDetail("geode.distributed-system.connection", toConnectedNoConnectedString(distributedSystem.isConnected()))
.withDetail("geode.distributed-system.reconnecting", toYesNoString(distributedSystem.isReconnecting()))
.withDetail("geode.distributed-system.properties-location",
Optional.ofNullable(DistributedSystem.getPropertiesFileURL()).map(URL::toExternalForm))
Optional.ofNullable(DistributedSystem.getPropertiesFileURL())
.map(URL::toExternalForm)
.filter(StringUtils::hasText)
.orElse(""))
.withDetail("geode.distributed-system.security-properties-location",
Optional.ofNullable(DistributedSystem.getSecurityPropertiesFileURL()).map(URL::toExternalForm))
Optional.ofNullable(DistributedSystem.getSecurityPropertiesFileURL())
.map(URL::toExternalForm)
.filter(StringUtils::hasText)
.orElse(""))
)
.orElse(healthBuilder);
}

View File

@@ -24,6 +24,9 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.geode.CancelCriterion;
import org.apache.geode.cache.GemFireCache;
@@ -70,6 +73,15 @@ public class GeodeCacheHealthIndicatorUnitTests {
public void setup() {
this.cacheHealthIndicator = new GeodeCacheHealthIndicator(this.mockGemFireCache);
}
@SuppressWarnings("all")
private Set<DistributedMember> mockDistributedMembers(int size) {
return IntStream.range(0, size)
.mapToObj(it -> mock(DistributedMember.class))
.collect(Collectors.toSet());
}
@Test
public void healthCheckCapturesDetails() throws Exception {
@@ -81,6 +93,7 @@ public class GeodeCacheHealthIndicatorUnitTests {
DistributedSystem mockDistributedSystem = CacheMockObjects.mockDistributedSystem(mockDistributedMember);
when(mockDistributedSystem.getAllOtherMembers()).thenAnswer(invocation -> mockDistributedMembers(8));
when(mockDistributedSystem.isConnected()).thenReturn(true);
when(mockDistributedSystem.isReconnecting()).thenReturn(false);
@@ -118,6 +131,7 @@ public class GeodeCacheHealthIndicatorUnitTests {
assertThat(healthDetails).containsEntry("geode.distributed-member.groups", Arrays.asList("TestGroup", "MockGroup"));
assertThat(healthDetails).containsEntry("geode.distributed-member.host", "Skullbox");
assertThat(healthDetails).containsEntry("geode.distributed-member.process-id", 12345);
assertThat(healthDetails).containsEntry("geode.distributed-system.member-count", 9);
assertThat(healthDetails).containsEntry("geode.distributed-system.connection", "Connected");
assertThat(healthDetails).containsEntry("geode.distributed-system.reconnecting", "No");
//assertThat(healthDetails).containsKey("geode.distributed-member.properties-location");