Commit fd89e519 by Johannes Edmeier

Change the status updater to respect the new /health format.

parent 2a1ec2a1
...@@ -30,13 +30,13 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter; ...@@ -30,13 +30,13 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter;
public class Info implements Serializable { public class Info implements Serializable {
private static final Info EMPTY = new Info(null); private static final Info EMPTY = new Info(null);
private final Map<String, Serializable> values; private final Map<String, Object> values;
private Info(Map<String, ? extends Serializable> values) { private Info(Map<String, Object> values) {
this.values = values != null ? new LinkedHashMap<>(values) : Collections.emptyMap(); this.values = values != null ? new LinkedHashMap<>(values) : Collections.emptyMap();
} }
public static Info from(Map<String, ? extends Serializable> values) { public static Info from(Map<String, Object> values) {
return new Info(values); return new Info(values);
} }
...@@ -61,7 +61,7 @@ public class Info implements Serializable { ...@@ -61,7 +61,7 @@ public class Info implements Serializable {
} }
@JsonAnyGetter @JsonAnyGetter
public Map<String, Serializable> getValues() { public Map<String, Object> getValues() {
return Collections.unmodifiableMap(values); return Collections.unmodifiableMap(values);
} }
} }
...@@ -43,15 +43,15 @@ public class StatusInfo implements Serializable { ...@@ -43,15 +43,15 @@ public class StatusInfo implements Serializable {
STATUS_UNKNOWN, STATUS_RESTRICTED, STATUS_UP); STATUS_UNKNOWN, STATUS_RESTRICTED, STATUS_UP);
private final String status; private final String status;
private final Map<String, Serializable> details; private final Map<String, Object> details;
private StatusInfo(String status, Map<String, ? extends Serializable> details) { private StatusInfo(String status, Map<String, ?> details) {
Assert.hasText(status, "'status' must not be empty."); Assert.hasText(status, "'status' must not be empty.");
this.status = status.toUpperCase(); this.status = status.toUpperCase();
this.details = details != null ? new HashMap<>(details) : Collections.emptyMap(); this.details = details != null ? new HashMap<>(details) : Collections.emptyMap();
} }
public static StatusInfo valueOf(String statusCode, Map<String, ? extends Serializable> details) { public static StatusInfo valueOf(String statusCode, Map<String, ?> details) {
return new StatusInfo(statusCode, details); return new StatusInfo(statusCode, details);
} }
...@@ -75,19 +75,19 @@ public class StatusInfo implements Serializable { ...@@ -75,19 +75,19 @@ public class StatusInfo implements Serializable {
return ofOffline(null); return ofOffline(null);
} }
public static StatusInfo ofUp(Map<String, ? extends Serializable> details) { public static StatusInfo ofUp(Map<String, Object> details) {
return valueOf(STATUS_UP, details); return valueOf(STATUS_UP, details);
} }
public static StatusInfo ofDown(Map<String, ? extends Serializable> details) { public static StatusInfo ofDown(Map<String, Object> details) {
return valueOf(STATUS_DOWN, details); return valueOf(STATUS_DOWN, details);
} }
public static StatusInfo ofOffline(Map<String, ? extends Serializable> details) { public static StatusInfo ofOffline(Map<String, Object> details) {
return valueOf(STATUS_OFFLINE, details); return valueOf(STATUS_OFFLINE, details);
} }
public Map<String, Serializable> getDetails() { public Map<String, Object> getDetails() {
return Collections.unmodifiableMap(details); return Collections.unmodifiableMap(details);
} }
......
...@@ -23,7 +23,6 @@ import de.codecentric.boot.admin.server.domain.values.InstanceId; ...@@ -23,7 +23,6 @@ import de.codecentric.boot.admin.server.domain.values.InstanceId;
import de.codecentric.boot.admin.server.web.client.InstanceOperations; import de.codecentric.boot.admin.server.web.client.InstanceOperations;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -68,7 +67,7 @@ public class InfoUpdater { ...@@ -68,7 +67,7 @@ public class InfoUpdater {
.map(instance::withInfo); .map(instance::withInfo);
} }
protected Info convertInfo(Instance instance, ResponseEntity<Map<String, Serializable>> response) { protected Info convertInfo(Instance instance, ResponseEntity<Map<String, Object>> response) {
if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) { if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) {
return Info.from(response.getBody()); return Info.from(response.getBody());
} else { } else {
......
...@@ -22,7 +22,6 @@ import de.codecentric.boot.admin.server.domain.values.StatusInfo; ...@@ -22,7 +22,6 @@ import de.codecentric.boot.admin.server.domain.values.StatusInfo;
import de.codecentric.boot.admin.server.web.client.InstanceOperations; import de.codecentric.boot.admin.server.web.client.InstanceOperations;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -65,14 +64,23 @@ public class StatusUpdater { ...@@ -65,14 +64,23 @@ public class StatusUpdater {
.map(instance::withStatusInfo); .map(instance::withStatusInfo);
} }
protected StatusInfo convertStatusInfo(ResponseEntity<Map<String, Serializable>> response) { @SuppressWarnings("unchecked")
protected StatusInfo convertStatusInfo(ResponseEntity<Map<String, Object>> response) {
if (response.hasBody() && response.getBody().get("status") instanceof String) { if (response.hasBody() && response.getBody().get("status") instanceof String) {
return StatusInfo.valueOf((String) response.getBody().get("status"), response.getBody()); Map<String, Object> body = response.getBody();
String status = (String) body.get("status");
Map<String, Object> details = body;
if (body.get("details") instanceof Map) {
details = (Map<String, Object>) body.get("details");
} }
return StatusInfo.valueOf(status, details);
}
if (response.getStatusCode().is2xxSuccessful()) { if (response.getStatusCode().is2xxSuccessful()) {
return StatusInfo.ofUp(); return StatusInfo.ofUp();
} }
Map<String, Serializable> details = new HashMap<>();
Map<String, Object> details = new HashMap<>();
details.put("status", response.getStatusCodeValue()); details.put("status", response.getStatusCodeValue());
details.put("error", response.getStatusCode().getReasonPhrase()); details.put("error", response.getStatusCode().getReasonPhrase());
if (response.hasBody()) { if (response.hasBody()) {
...@@ -90,7 +98,7 @@ public class StatusUpdater { ...@@ -90,7 +98,7 @@ public class StatusUpdater {
} }
protected StatusInfo convertStatusInfo(Throwable ex) { protected StatusInfo convertStatusInfo(Throwable ex) {
Map<String, Serializable> details = new HashMap<>(); Map<String, Object> details = new HashMap<>();
details.put("message", ex.getMessage()); details.put("message", ex.getMessage());
details.put("exception", ex.getClass().getName()); details.put("exception", ex.getClass().getName());
return StatusInfo.ofOffline(details); return StatusInfo.ofOffline(details);
......
...@@ -19,7 +19,6 @@ import de.codecentric.boot.admin.server.domain.entities.Instance; ...@@ -19,7 +19,6 @@ import de.codecentric.boot.admin.server.domain.entities.Instance;
import de.codecentric.boot.admin.server.domain.values.Endpoint; import de.codecentric.boot.admin.server.domain.values.Endpoint;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -40,7 +39,7 @@ import org.springframework.web.util.UriComponentsBuilder; ...@@ -40,7 +39,7 @@ import org.springframework.web.util.UriComponentsBuilder;
public class InstanceOperations { public class InstanceOperations {
private static final Logger log = LoggerFactory.getLogger(InstanceOperations.class); private static final Logger log = LoggerFactory.getLogger(InstanceOperations.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static final Class<Map<String, Serializable>> RESPONSE_TYPE_MAP = (Class<Map<String, Serializable>>) (Class<?>) Map.class; private static final Class<Map<String, Object>> RESPONSE_TYPE_MAP = (Class<Map<String, Object>>) (Class<?>) Map.class;
private final WebClient webClient; private final WebClient webClient;
private final HttpHeadersProvider httpHeadersProvider; private final HttpHeadersProvider httpHeadersProvider;
...@@ -49,16 +48,16 @@ public class InstanceOperations { ...@@ -49,16 +48,16 @@ public class InstanceOperations {
this.httpHeadersProvider = httpHeadersProvider; this.httpHeadersProvider = httpHeadersProvider;
} }
public Mono<ResponseEntity<Map<String, Serializable>>> getHealth(Instance instance) { public Mono<ResponseEntity<Map<String, Object>>> getHealth(Instance instance) {
URI uri = UriComponentsBuilder.fromHttpUrl(instance.getRegistration().getHealthUrl()).build().toUri(); URI uri = UriComponentsBuilder.fromHttpUrl(instance.getRegistration().getHealthUrl()).build().toUri();
return this.exchange(HttpMethod.GET, instance, uri).flatMap(r -> r.toEntity(RESPONSE_TYPE_MAP)); return this.exchange(HttpMethod.GET, instance, uri).flatMap(r -> r.toEntity(RESPONSE_TYPE_MAP));
} }
public Mono<ResponseEntity<Map<String, Serializable>>> getInfo(Instance instance) { public Mono<ResponseEntity<Map<String, Object>>> getInfo(Instance instance) {
return getEndpoint(instance, Endpoint.INFO); return getEndpoint(instance, Endpoint.INFO);
} }
public Mono<ResponseEntity<Map<String, Serializable>>> getEndpoint(Instance instance, String endpointId) { public Mono<ResponseEntity<Map<String, Object>>> getEndpoint(Instance instance, String endpointId) {
URI uri = URI.create(instance.getEndpoints().get(endpointId).getUrl()); URI uri = URI.create(instance.getEndpoints().get(endpointId).getUrl());
return this.exchange(HttpMethod.GET, instance, uri).flatMap(r -> r.toEntity(RESPONSE_TYPE_MAP)); return this.exchange(HttpMethod.GET, instance, uri).flatMap(r -> r.toEntity(RESPONSE_TYPE_MAP));
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package de.codecentric.boot.admin.server.domain.values; package de.codecentric.boot.admin.server.domain.values;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -38,16 +37,15 @@ public class InfoTest { ...@@ -38,16 +37,15 @@ public class InfoTest {
public void should_return_version() { public void should_return_version() {
assertThat(Info.empty().getVersion()).isEqualTo(""); assertThat(Info.empty().getVersion()).isEqualTo("");
assertThat(Info.from(singletonMap("version", "1.0.0")).getVersion()).isEqualTo("1.0.0"); assertThat(Info.from(singletonMap("version", "1.0.0")).getVersion()).isEqualTo("1.0.0");
assertThat(Info.from(singletonMap("build", (Serializable) singletonMap("version", "1.0.0"))) assertThat(Info.from(singletonMap("build", singletonMap("version", "1.0.0"))).getVersion()).isEqualTo("1.0.0");
.getVersion()).isEqualTo("1.0.0");
} }
@Test @Test
public void test_json_serialize() throws Exception { public void test_json_serialize() throws Exception {
Map<String, Serializable> values = new HashMap<>(); Map<String, Object> values = new HashMap<>();
values.put("foo", "bar"); values.put("foo", "bar");
values.put("build", (Serializable) singletonMap("version", "1.0.0")); values.put("build", singletonMap("version", "1.0.0"));
Info info = Info.from(values); Info info = Info.from(values);
String json = objectMapper.writeValueAsString(info); String json = objectMapper.writeValueAsString(info);
...@@ -59,7 +57,7 @@ public class InfoTest { ...@@ -59,7 +57,7 @@ public class InfoTest {
@Test @Test
public void test_retain_order() { public void test_retain_order() {
Map<String, String> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
map.put("z", "1"); map.put("z", "1");
map.put("x", "2"); map.put("x", "2");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment