From 9d01f340ad6dc0803cf9dd8e13a955bac1d59a96 Mon Sep 17 00:00:00 2001 From: Puck Wang Date: Tue, 3 Oct 2023 10:51:31 -0400 Subject: [PATCH 1/3] add EMA version to heartbeat message --- service/application/pom.xml | 14 +++++++++++++- .../maas/ep/common/messages/HeartbeatMessage.java | 12 ++++++++++++ .../agent/publisher/HeartbeatGenerator.java | 9 ++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/service/application/pom.xml b/service/application/pom.xml index b9fabafb..3e04a3f9 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.solace.maas @@ -341,6 +342,17 @@ + + org.springframework.boot + spring-boot-maven-plugin + + + + build-info + + + + diff --git a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java index 1e1a17a1..c2998667 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java @@ -12,6 +12,7 @@ public class HeartbeatMessage extends MOPMessage { private String orgId; private String runtimeAgentId; private String timestamp; + private String runtimeAgentVersion; public HeartbeatMessage() { super(); @@ -27,6 +28,17 @@ public HeartbeatMessage(String runtimeAgentId, String timestamp) { this.timestamp = timestamp; } + public HeartbeatMessage(String runtimeAgentId, String timestamp, String runtimeAgentVersion) { + super(); + withMessageType(MOPMessageType.generic) + .withProtocol(MOPProtocol.EMAHeartbeat) + .withVersion("1") + .withUhFlag(MOPUHFlag.ignore); + this.runtimeAgentId = runtimeAgentId; + this.timestamp = timestamp; + this.runtimeAgentVersion = runtimeAgentVersion; + } + @Override public String toLog() { return null; diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java index 3f4026b8..d62f4b9f 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java @@ -6,6 +6,7 @@ import com.solace.maas.ep.event.management.agent.plugin.jacoco.ExcludeFromJacocoGeneratedReport; import com.solace.maas.ep.event.management.agent.plugin.publisher.SolacePublisher; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.info.BuildProperties; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -19,19 +20,21 @@ public class HeartbeatGenerator { private final SolacePublisher solacePublisher; private final String runtimeAgentId; private final String topic; + private final String runtimeAgentVersion; public HeartbeatGenerator(SolaceConfiguration solaceConfiguration, EventPortalProperties eventPortalProperties, - SolacePublisher solacePublisher) { + SolacePublisher solacePublisher, + BuildProperties buildProperties) { this.solacePublisher = solacePublisher; this.runtimeAgentId = eventPortalProperties.getRuntimeAgentId(); topic = solaceConfiguration.getTopicPrefix() + "heartbeat/v1"; - + this.runtimeAgentVersion = buildProperties.getVersion().substring(0, buildProperties.getVersion().indexOf('-')); } @Scheduled(fixedRate = 5000) public void sendHeartbeat() { - HeartbeatMessage message = new HeartbeatMessage(runtimeAgentId, Instant.now().toString()); + HeartbeatMessage message = new HeartbeatMessage(runtimeAgentId, Instant.now().toString(), runtimeAgentVersion); solacePublisher.publish(message, topic); } From 8699fe0929f3ac24141ebd3a3c923bee896f1d38 Mon Sep 17 00:00:00 2001 From: Puck Wang Date: Tue, 10 Oct 2023 09:20:04 -0400 Subject: [PATCH 2/3] clean up --- .../maas/ep/common/messages/HeartbeatMessage.java | 12 +----------- .../maas/ep/event/management/agent/mop/MopTests.java | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java index c2998667..83a591f0 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/messages/HeartbeatMessage.java @@ -18,17 +18,7 @@ public HeartbeatMessage() { super(); } - public HeartbeatMessage(String runtimeAgentId, String timestamp) { - super(); - withMessageType(MOPMessageType.generic) - .withProtocol(MOPProtocol.EMAHeartbeat) - .withVersion("1") - .withUhFlag(MOPUHFlag.ignore); - this.runtimeAgentId = runtimeAgentId; - this.timestamp = timestamp; - } - - public HeartbeatMessage(String runtimeAgentId, String timestamp, String runtimeAgentVersion) { + public HeartbeatMessage(String runtimeAgentId, String timestamp, String runtimeAgentVersion) { super(); withMessageType(MOPMessageType.generic) .withProtocol(MOPProtocol.EMAHeartbeat) diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java index 44bc5dd2..04ebc961 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/mop/MopTests.java @@ -52,7 +52,7 @@ public void ack() { @Test public void testHeartbeatAgentMOPProtocol() { - HeartbeatMessage message = new HeartbeatMessage("runtimeId", "timestamp"); + HeartbeatMessage message = new HeartbeatMessage("runtimeId", "timestamp", "1.1.2"); assertEquals(message.getMopProtocol(), MOPProtocol.EMAHeartbeat); } } From 48290c265ff3864b847921923f39d9243c3d13c6 Mon Sep 17 00:00:00 2001 From: Puck Wang Date: Wed, 11 Oct 2023 11:06:08 -0400 Subject: [PATCH 3/3] fix bug --- .../management/agent/publisher/HeartbeatGenerator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java index d62f4b9f..bead520e 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/publisher/HeartbeatGenerator.java @@ -29,7 +29,7 @@ public HeartbeatGenerator(SolaceConfiguration solaceConfiguration, this.solacePublisher = solacePublisher; this.runtimeAgentId = eventPortalProperties.getRuntimeAgentId(); topic = solaceConfiguration.getTopicPrefix() + "heartbeat/v1"; - this.runtimeAgentVersion = buildProperties.getVersion().substring(0, buildProperties.getVersion().indexOf('-')); + this.runtimeAgentVersion = getFormattedVersion(buildProperties.getVersion()); } @Scheduled(fixedRate = 5000) @@ -38,4 +38,10 @@ public void sendHeartbeat() { solacePublisher.publish(message, topic); } + private String getFormattedVersion(String version) { + if (version.endsWith("-SNAPSHOT")) { + return version.replace("-SNAPSHOT", ""); + } + return version; + } }