Commit 668d19c1 by Johannes Edmeier

Return null on missing version

Don't output metadata in Registration.toString()
parent d76e16c8
......@@ -11,10 +11,10 @@ management:
endpoints:
web:
base-path: "/actuator"
expose: "*"
jolokia:
enabled: true
spring:
application:
name: "@pom.artifactId@"
......@@ -26,26 +26,6 @@ spring:
active:
- insecure
endpoints:
health:
enabled: true
metrics:
enabled: true
logfile:
enabled: true
loggers:
enabled: true
trace:
enabled: true
auditevents:
enabled: true
heapdump:
enabled: true
threaddump:
enabled: true
env:
enabled: true
---
spring:
profiles: insecure
......
......@@ -57,7 +57,7 @@ public class Info implements Serializable {
if (version instanceof String) {
return (String) version;
}
return "";
return null;
}
@JsonAnyGetter
......
......@@ -16,6 +16,8 @@
package de.codecentric.boot.admin.server.domain.values;
import lombok.ToString;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
......@@ -44,6 +46,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
*/
@lombok.Data
@JsonDeserialize(using = Registration.Deserializer.class)
@ToString(exclude = "metadata")
public class Registration implements Serializable {
private final String name;
private final String managementUrl;
......
......@@ -53,7 +53,7 @@ public class InstanceRegistry {
instance = Instance.create(key);
}
return Mono.just(instance.register(registration));
}).then(Mono.just(id));
}).map(Instance::getId);
}
/**
......
......@@ -50,12 +50,11 @@ import static java.util.stream.Collectors.toMap;
@ResponseBody
public class ApplicationsController {
private static final Logger log = LoggerFactory.getLogger(ApplicationsController.class);
private static final ServerSentEvent<?> PING = ServerSentEvent.builder().comment("ping").build();
private static final Flux<ServerSentEvent<?>> PING_FLUX = Flux.interval(Duration.ZERO, Duration.ofSeconds(10L))
.map(tick -> PING);
private final InstanceRegistry registry;
private final InstanceEventPublisher eventPublisher;
private static final ServerSentEvent<Application> PING = ServerSentEvent.<Application>builder().comment("ping")
.build();
private static final Flux<ServerSentEvent<Application>> PING_FLUX = Flux.interval(Duration.ZERO,
Duration.ofSeconds(10L)).map(tick -> PING);
public ApplicationsController(InstanceRegistry registry, InstanceEventPublisher eventPublisher) {
this.registry = registry;
......@@ -77,7 +76,7 @@ public class ApplicationsController {
.map(this::getApplicationForInstance)
.flatMap(group -> toApplication(group.getT1(), group.getT2()))
.map(application -> ServerSentEvent.builder(application).build())
.mergeWith(PING_FLUX);
.mergeWith(ping());
}
@DeleteMapping(path = "/applications/{name}")
......@@ -152,6 +151,11 @@ public class ApplicationsController {
.orElse(Tuples.of(StatusInfo.STATUS_UNKNOWN, -1L));
}
@SuppressWarnings("unchecked")
private static <T> Flux<ServerSentEvent<T>> ping() {
return (Flux<ServerSentEvent<T>>) (Flux) PING_FLUX;
}
@lombok.Data
public static class Application {
private final String name;
......
......@@ -66,13 +66,12 @@ import static org.springframework.web.reactive.function.client.WebClient.Request
@ResponseBody
public class InstancesController {
private static final Logger LOGGER = LoggerFactory.getLogger(InstancesController.class);
private static final ServerSentEvent<InstanceEvent> PING = ServerSentEvent.<InstanceEvent>builder().comment("ping")
.build();
private static final ServerSentEvent<?> PING = ServerSentEvent.builder().comment("ping").build();
private static final Flux<ServerSentEvent<?>> PING_FLUX = Flux.interval(Duration.ZERO, Duration.ofSeconds(10L))
.map(tick -> (ServerSentEvent<?>) PING);
private final InstanceRegistry registry;
private final InstanceEventStore eventStore;
private final InstanceWebClient instanceWebClient;
private static final Flux<ServerSentEvent<InstanceEvent>> PING_FLUX = Flux.interval(Duration.ZERO,
Duration.ofSeconds(10L)).map(tick -> PING);
public InstancesController(InstanceRegistry registry,
InstanceEventStore eventStore,
......@@ -151,7 +150,16 @@ public class InstancesController {
@GetMapping(path = "/instances/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ServerSentEvent<InstanceEvent>> eventStream() {
return Flux.from(eventStore).map(event -> ServerSentEvent.builder(event).build()).mergeWith(PING_FLUX);
return Flux.from(eventStore).map(event -> ServerSentEvent.builder(event).build()).mergeWith(ping());
}
@GetMapping(path = "/instances/{id}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ServerSentEvent<Instance>> instanceStream(@PathVariable String id) {
return Flux.from(eventStore)
.filter(event -> event.getInstance().equals(InstanceId.of(id)))
.flatMap(event -> registry.getInstance(event.getInstance()))
.map(event -> ServerSentEvent.builder(event).build())
.mergeWith(ping());
}
private static final String[] HOP_BY_HOP_HEADERS = new String[]{"Connection", "Keep-Alive", "Proxy-Authenticate",
......@@ -204,4 +212,10 @@ public class InstancesController {
return false;
}
}
@SuppressWarnings("unchecked")
private static <T> Flux<ServerSentEvent<T>> ping() {
return (Flux<ServerSentEvent<T>>) (Flux) PING_FLUX;
}
}
......@@ -35,7 +35,7 @@ public class InfoTest {
@Test
public void should_return_version() {
assertThat(Info.empty().getVersion()).isEqualTo("");
assertThat(Info.empty().getVersion()).isNull();
assertThat(Info.from(singletonMap("version", "1.0.0")).getVersion()).isEqualTo("1.0.0");
assertThat(Info.from(singletonMap("build", singletonMap("version", "1.0.0"))).getVersion()).isEqualTo("1.0.0");
......
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