Skip to content

Commit

Permalink
Merge pull request #204 from SolaceProducts/DATAGO-85215-support-roll…
Browse files Browse the repository at this point in the history
…ing-update

DATAGO-85215: EMA generates its own client name based on hostname and runtime agent id
  • Loading branch information
rudraneel-chakraborty authored Sep 24, 2024
2 parents 6644cdf + 653f3e3 commit 7c0b3fa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public String getTopicPrefix() {
@ConditionalOnMissingBean(EnableRtoCondition.class)
@ConditionalOnProperty(name = "event-portal.gateway.messaging.standalone", havingValue = "false")
public MessagingService messagingService() {
String clientName = "runtimeAgent-" + eventPortalProperties.getRuntimeAgentId();
vmrConfiguration.setProperty(SolaceProperties.ClientProperties.NAME, clientName);

String clientName = vmrConfiguration.getProperty(SolaceProperties.ClientProperties.NAME);
log.info("Connecting to event portal using EMA client {}.", clientName);
return MessagingService.builder(ConfigurationProfile.V1)
.fromProperties(vmrConfiguration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.solace.maas.ep.event.management.agent.applicationContextTests;

import com.solace.maas.ep.event.management.agent.plugin.config.VMRProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -20,13 +24,17 @@
"eventPortal.gateway.messaging.standalone=false",
"eventPortal.managed=true",
"eventPortal.incomingRequestQueueName = ep_core_ema_requests_123456_123123",
"event-portal.gateway.messaging.rto-session=false"
"event-portal.gateway.messaging.rto-session=false",
"event-portal.runtimeAgentId = testManagedAgentId",
})
class ManagedAgentMessageHandlerBeansTests {

@Autowired
private ApplicationContext applicationContext;

@Autowired
private VMRProperties vmrProperties;

@Test
void testPersistentMessageHandlerBeansAreLoaded() {
String[] allBeanNames = applicationContext.getBeanDefinitionNames();
Expand Down Expand Up @@ -70,4 +78,11 @@ void testCommandLogStreamingProcessorBeanIsNotLoaded() {
.doesNotContain(StringUtils.lowerCase("commandLogStreamingProcessor"));

}

@Test
void testClientNameIsGeneratedBasedOnHostNameAndAgentId() throws UnknownHostException {
String hostnameHash = DigestUtils.sha256Hex(InetAddress.getLocalHost().getHostName());
assertThat(vmrProperties.getClientName()).isEqualTo("ema-testManagedAgentId-" + hostnameHash);

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.solace.maas.ep.event.management.agent.applicationContextTests;

import com.solace.maas.ep.event.management.agent.plugin.config.VMRProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -18,13 +22,17 @@
@ActiveProfiles("TEST")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
"eventPortal.gateway.messaging.standalone=false",
"eventPortal.managed=false"
"eventPortal.managed=false",
"event-portal.runtimeAgentId = testSelfManagedAgentId",
})
class SelfManagedAgentMessageHandlerBeansTests {

@Autowired
private ApplicationContext applicationContext;

@Autowired
private VMRProperties vmrProperties;

@Test
void testPersistentMessageHandlerBeansAreNotLoaded() {
String[] allBeanNames = applicationContext.getBeanDefinitionNames();
Expand Down Expand Up @@ -65,4 +73,11 @@ void testCommandLogStreamingProcessorBeanIsLoaded() {
.collect(Collectors.toSet())).contains(StringUtils.lowerCase("commandLogStreamingProcessor"));

}

@Test
void testClientNameIsGeneratedBasedOnHostNameAndAgentId() throws UnknownHostException {
String hostnameHash = DigestUtils.sha256Hex(InetAddress.getLocalHost().getHostName());
assertThat(vmrProperties.getClientName()).isEqualTo("ema-testSelfManagedAgentId-" + hostnameHash);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import com.solacesystems.solclientj.core.handle.SessionHandle;
import lombok.Data;
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.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;
Expand Down Expand Up @@ -86,7 +90,10 @@ public void parseVmrProperties() {
}
username = messagingServiceUsersProperties.getUsername();
password = messagingServiceUsersProperties.getPassword();
clientName = messagingServiceUsersProperties.getClientName();
String computedClientName = determineClientName();
clientName = StringUtils.isEmpty(computedClientName)
? messagingServiceUsersProperties.getClientName()
: computedClientName;
} catch (NoSuchElementException e) {
log.error("An error occurred while connecting to EP gateway: {}", e.getMessage());
}
Expand Down Expand Up @@ -132,4 +139,15 @@ public List<String> getRTOSessionProperties() {

return sessionProperties;
}

private String determineClientName() {
try {
String hostName = InetAddress.getLocalHost().getHostName();
String hostNameHash = DigestUtils.sha256Hex(hostName);
return String.format("%s-%s-%s", "ema", eventPortalPluginProperties.getRuntimeAgentId(), hostNameHash);
} catch (UnknownHostException e) {
log.warn("Could not determine host name when determining client name.", e);
return StringUtils.EMPTY;
}
}
}

0 comments on commit 7c0b3fa

Please sign in to comment.