From 6ad4a485b8d8ae75033ce644c4d592cda276d822 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Sun, 25 Aug 2024 20:24:12 -0400 Subject: [PATCH 1/3] DATAGO-83040 poc --- .../agent/plugin/config/VMRProperties.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java index a775ffa5..cfee3bed 100644 --- a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java +++ b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java @@ -9,10 +9,13 @@ import com.solacesystems.solclientj.core.handle.SessionHandle; import lombok.Data; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; @@ -86,7 +89,9 @@ public void parseVmrProperties() { } username = messagingServiceUsersProperties.getUsername(); password = messagingServiceUsersProperties.getPassword(); - clientName = messagingServiceUsersProperties.getClientName(); + String computedClientName = determineClientName(); + clientName = StringUtils.isEmpty(computedClientName) ? messagingServiceUsersProperties.getClientName() : computedClientName; + log.debug("Client name: {}", clientName); } catch (NoSuchElementException e) { log.error("An error occurred while connecting to EP gateway: {}", e.getMessage()); } @@ -132,4 +137,17 @@ public List getRTOSessionProperties() { return sessionProperties; } + + private String determineClientName() { + String hostName = null; + try { + hostName = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + log.warn("Could not determine host name", e); + return StringUtils.EMPTY; + } + String agentId = eventPortalPluginProperties.getRuntimeAgentId(); + return String.format("%s-%s", hostName, agentId); + } + } From 19b5173cf2c2f167f96d3740e776e80e0e3b7ccc Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Mon, 26 Aug 2024 13:17:42 -0400 Subject: [PATCH 2/3] DATAGO-83040 poc --- .../agent/config/SolaceConfiguration.java | 19 +++++++++++++++-- .../agent/plugin/config/VMRProperties.java | 21 ++++--------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java index 441b7866..0d60fd84 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java @@ -14,6 +14,7 @@ import com.solace.messaging.publisher.DirectMessagePublisher; import com.solace.messaging.publisher.OutboundMessageBuilder; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -23,6 +24,8 @@ import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Scope; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -62,9 +65,10 @@ public String getTopicPrefix() { @ConditionalOnMissingBean(EnableRtoCondition.class) @ConditionalOnProperty(name = "event-portal.gateway.messaging.standalone", havingValue = "false") public MessagingService messagingService() { - String clientName = "runtimeAgent-" + eventPortalProperties.getRuntimeAgentId(); + String computedClientName = determineClientName(); + String clientName = StringUtils.isEmpty(computedClientName) ? + "runtimeAgent-" + eventPortalProperties.getRuntimeAgentId() : computedClientName; vmrConfiguration.setProperty(SolaceProperties.ClientProperties.NAME, clientName); - log.info("Connecting to event portal using EMA client {}.", clientName); return MessagingService.builder(ConfigurationProfile.V1) .fromProperties(vmrConfiguration) @@ -114,4 +118,15 @@ public SolacePublisher solacePublisher() { directMessagePublisher()); } + private String determineClientName() { + String hostName = null; + try { + hostName = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + log.warn("Could not determine host name", e); + return StringUtils.EMPTY; + } + String agentId = eventPortalProperties.getRuntimeAgentId(); + return String.format("%s-%s", hostName, agentId); + } } diff --git a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java index cfee3bed..550a9f8b 100644 --- a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java +++ b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java @@ -9,7 +9,6 @@ import com.solacesystems.solclientj.core.handle.SessionHandle; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; @@ -89,11 +88,12 @@ public void parseVmrProperties() { } username = messagingServiceUsersProperties.getUsername(); password = messagingServiceUsersProperties.getPassword(); - String computedClientName = determineClientName(); - clientName = StringUtils.isEmpty(computedClientName) ? messagingServiceUsersProperties.getClientName() : computedClientName; - log.debug("Client name: {}", clientName); + String hostName = InetAddress.getLocalHost().getHostName(); + clientName = messagingServiceUsersProperties.getClientName(); } catch (NoSuchElementException e) { log.error("An error occurred while connecting to EP gateway: {}", e.getMessage()); + } catch (UnknownHostException e) { + throw new RuntimeException(e); } } @@ -137,17 +137,4 @@ public List getRTOSessionProperties() { return sessionProperties; } - - private String determineClientName() { - String hostName = null; - try { - hostName = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - log.warn("Could not determine host name", e); - return StringUtils.EMPTY; - } - String agentId = eventPortalPluginProperties.getRuntimeAgentId(); - return String.format("%s-%s", hostName, agentId); - } - } From c3a49646dfde952b9b3dbd94dae9e7dab4d8d4d7 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Tue, 27 Aug 2024 09:48:37 -0400 Subject: [PATCH 3/3] DATAGO-83040 poc --- .../management/agent/config/SolaceConfiguration.java | 8 ++++++-- .../management/agent/plugin/config/VMRProperties.java | 5 ----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java index 0d60fd84..0eda1f46 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/SolaceConfiguration.java @@ -14,6 +14,7 @@ import com.solace.messaging.publisher.DirectMessagePublisher; import com.solace.messaging.publisher.OutboundMessageBuilder; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -69,7 +70,8 @@ public MessagingService messagingService() { String clientName = StringUtils.isEmpty(computedClientName) ? "runtimeAgent-" + eventPortalProperties.getRuntimeAgentId() : computedClientName; vmrConfiguration.setProperty(SolaceProperties.ClientProperties.NAME, clientName); - log.info("Connecting to event portal using EMA client {}.", clientName); + log.info("Event Management Agent with ID {} connecting to event portal using EMA client {}.", + eventPortalProperties.getRuntimeAgentId(), clientName); return MessagingService.builder(ConfigurationProfile.V1) .fromProperties(vmrConfiguration) .withReconnectionRetryStrategy(RetryStrategy.foreverRetry(15_000)) @@ -126,7 +128,9 @@ private String determineClientName() { log.warn("Could not determine host name", e); return StringUtils.EMPTY; } + + String hostNameHash = DigestUtils.sha256Hex(hostName); String agentId = eventPortalProperties.getRuntimeAgentId(); - return String.format("%s-%s", hostName, agentId); + return String.format("%s-%s", agentId, hostNameHash); } } diff --git a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java index 550a9f8b..a775ffa5 100644 --- a/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java +++ b/service/plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/config/VMRProperties.java @@ -13,8 +13,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; @@ -88,12 +86,9 @@ public void parseVmrProperties() { } username = messagingServiceUsersProperties.getUsername(); password = messagingServiceUsersProperties.getPassword(); - String hostName = InetAddress.getLocalHost().getHostName(); clientName = messagingServiceUsersProperties.getClientName(); } catch (NoSuchElementException e) { log.error("An error occurred while connecting to EP gateway: {}", e.getMessage()); - } catch (UnknownHostException e) { - throw new RuntimeException(e); } }