Skip to content

Commit

Permalink
Add InstanceEvents to Jackson module
Browse files Browse the repository at this point in the history
  • Loading branch information
srempfer committed Apr 28, 2020
1 parent 53ce34a commit 5d25c6b
Show file tree
Hide file tree
Showing 14 changed files with 963 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.InstanceId;

/**
Expand All @@ -30,14 +33,18 @@
@lombok.ToString(callSuper = true)
public class InstanceDeregisteredEvent extends InstanceEvent {

public static final String TYPE = "DEREGISTERED";

private static final long serialVersionUID = 1L;

public InstanceDeregisteredEvent(InstanceId instance, long version) {
this(instance, version, Instant.now());
}

public InstanceDeregisteredEvent(InstanceId instance, long version, Instant timestamp) {
super(instance, version, "DEREGISTERED", timestamp);
@JsonCreator
public InstanceDeregisteredEvent(@JsonProperty("instance") InstanceId instance,
@JsonProperty("version") long version, @JsonProperty("timestamp") Instant timestamp) {
super(instance, version, TYPE, timestamp);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.Endpoints;
import de.codecentric.boot.admin.server.domain.values.InstanceId;

Expand All @@ -31,6 +34,8 @@
@lombok.ToString(callSuper = true)
public class InstanceEndpointsDetectedEvent extends InstanceEvent {

public static final String TYPE = "ENDPOINTS_DETECTED";

private static final long serialVersionUID = 1L;

private final Endpoints endpoints;
Expand All @@ -39,8 +44,11 @@ public InstanceEndpointsDetectedEvent(InstanceId instance, long version, Endpoin
this(instance, version, Instant.now(), endpoints);
}

public InstanceEndpointsDetectedEvent(InstanceId instance, long version, Instant timestamp, Endpoints endpoints) {
super(instance, version, "ENDPOINTS_DETECTED", timestamp);
@JsonCreator
public InstanceEndpointsDetectedEvent(@JsonProperty("instance") InstanceId instance,
@JsonProperty("version") long version, @JsonProperty("timestamp") Instant timestamp,
@JsonProperty("endpoints") Endpoints endpoints) {
super(instance, version, TYPE, timestamp);
this.endpoints = endpoints;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.Info;
import de.codecentric.boot.admin.server.domain.values.InstanceId;

Expand All @@ -31,6 +34,8 @@
@lombok.ToString(callSuper = true)
public class InstanceInfoChangedEvent extends InstanceEvent {

public static final String TYPE = "INFO_CHANGED";

private static final long serialVersionUID = 1L;

private final Info info;
Expand All @@ -39,8 +44,11 @@ public InstanceInfoChangedEvent(InstanceId instance, long version, Info info) {
this(instance, version, Instant.now(), info);
}

public InstanceInfoChangedEvent(InstanceId instance, long version, Instant timestamp, Info info) {
super(instance, version, "INFO_CHANGED", timestamp);
@JsonCreator
public InstanceInfoChangedEvent(@JsonProperty("instance") InstanceId instance,
@JsonProperty("version") long version, @JsonProperty("timestamp") Instant timestamp,
@JsonProperty("info") Info info) {
super(instance, version, TYPE, timestamp);
this.info = info;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
import de.codecentric.boot.admin.server.domain.values.Registration;

Expand All @@ -31,6 +34,8 @@
@lombok.ToString(callSuper = true)
public class InstanceRegisteredEvent extends InstanceEvent {

public static final String TYPE = "REGISTERED";

private static final long serialVersionUID = 1L;

private final Registration registration;
Expand All @@ -39,8 +44,10 @@ public InstanceRegisteredEvent(InstanceId instance, long version, Registration r
this(instance, version, Instant.now(), registration);
}

public InstanceRegisteredEvent(InstanceId instance, long version, Instant timestamp, Registration registration) {
super(instance, version, "REGISTERED", timestamp);
@JsonCreator
public InstanceRegisteredEvent(@JsonProperty("instance") InstanceId instance, @JsonProperty("version") long version,
@JsonProperty("timestamp") Instant timestamp, @JsonProperty("registration") Registration registration) {
super(instance, version, TYPE, timestamp);
this.registration = registration;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
import de.codecentric.boot.admin.server.domain.values.Registration;

Expand All @@ -31,6 +34,8 @@
@lombok.ToString(callSuper = true)
public class InstanceRegistrationUpdatedEvent extends InstanceEvent {

public static final String TYPE = "REGISTRATION_UPDATED";

private static final long serialVersionUID = 1L;

private final Registration registration;
Expand All @@ -39,9 +44,11 @@ public InstanceRegistrationUpdatedEvent(InstanceId instance, long version, Regis
this(instance, version, Instant.now(), registration);
}

public InstanceRegistrationUpdatedEvent(InstanceId instance, long version, Instant timestamp,
Registration registration) {
super(instance, version, "REGISTRATION_UPDATED", timestamp);
@JsonCreator
public InstanceRegistrationUpdatedEvent(@JsonProperty("instance") InstanceId instance,
@JsonProperty("version") long version, @JsonProperty("timestamp") Instant timestamp,
@JsonProperty("registration") Registration registration) {
super(instance, version, TYPE, timestamp);
this.registration = registration;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,9 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
import de.codecentric.boot.admin.server.domain.values.StatusInfo;

Expand All @@ -31,6 +34,8 @@
@lombok.ToString(callSuper = true)
public class InstanceStatusChangedEvent extends InstanceEvent {

public static final String TYPE = "STATUS_CHANGED";

private static final long serialVersionUID = 1L;

private final StatusInfo statusInfo;
Expand All @@ -39,8 +44,11 @@ public InstanceStatusChangedEvent(InstanceId instance, long version, StatusInfo
this(instance, version, Instant.now(), statusInfo);
}

public InstanceStatusChangedEvent(InstanceId instance, long version, Instant timestamp, StatusInfo statusInfo) {
super(instance, version, "STATUS_CHANGED", timestamp);
@JsonCreator
public InstanceStatusChangedEvent(@JsonProperty("instance") InstanceId instance,
@JsonProperty("version") long version, @JsonProperty("timestamp") Instant timestamp,
@JsonProperty("statusInfo") StatusInfo statusInfo) {
super(instance, version, TYPE, timestamp);
this.statusInfo = statusInfo;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -18,6 +18,8 @@

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.Assert;

@lombok.Data
Expand Down Expand Up @@ -52,7 +54,8 @@ private Endpoint(String id, String url) {
this.url = url;
}

public static Endpoint of(String id, String url) {
@JsonCreator
public static Endpoint of(@JsonProperty("id") String id, @JsonProperty("url") String url) {
return new Endpoint(id, url);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-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.
Expand Down Expand Up @@ -28,6 +28,8 @@

import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonCreator;

import static java.util.stream.Collectors.toMap;

@lombok.EqualsAndHashCode
Expand Down Expand Up @@ -68,6 +70,7 @@ public static Endpoints single(String id, String url) {
return new Endpoints(Collections.singletonList(Endpoint.of(id, url)));
}

@JsonCreator
public static Endpoints of(@Nullable Collection<Endpoint> endpoints) {
if (endpoints == null || endpoints.isEmpty()) {
return empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -24,6 +24,7 @@
import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonCreator;

/**
* Represents the info fetched from the info actuator endpoint
Expand All @@ -46,6 +47,7 @@ private Info(Map<String, Object> values) {
}
}

@JsonCreator
public static Info from(@Nullable Map<String, Object> values) {
if (values == null || values.isEmpty()) {
return empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-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.
Expand All @@ -25,7 +25,9 @@

import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.Assert;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -63,7 +65,9 @@ private StatusInfo(String status, @Nullable Map<String, ?> details) {
this.details = (details != null) ? new HashMap<>(details) : Collections.emptyMap();
}

public static StatusInfo valueOf(String statusCode, @Nullable Map<String, ?> details) {
@JsonCreator
public static StatusInfo valueOf(@JsonProperty("status") String statusCode,
@JsonProperty("details") @Nullable Map<String, ?> details) {
return new StatusInfo(statusCode, details);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@

import com.fasterxml.jackson.databind.module.SimpleModule;

import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.domain.values.Registration;

/**
* Jackson module for Spring Boot Admin Server.
* Jackson module for Spring Boot Admin Server. <br>
* In order to use this module just add this modules into your ObjectMapper configuration.
* <pre>
* ObjectMapper mapper = new ObjectMapper();
* mapper.registerModule(new AdminServerModule());
* mapper.registerModule(new JavaTimeModule());
* </pre>
*
* @author Stefan Rempfer
*/
Expand All @@ -37,6 +44,7 @@ public AdminServerModule(String[] metadataKeyPatterns) {

addDeserializer(Registration.class, new RegistrationDeserializer());
setSerializerModifier(new RegistrationBeanSerializerModifier(new SanitizingMapSerializer(metadataKeyPatterns)));
setMixInAnnotation(InstanceEvent.class, InstanceEventMixin.class);
}

}
Loading

0 comments on commit 5d25c6b

Please sign in to comment.