Skip to content

Commit

Permalink
DATAGO-85215 cema generates its own client name
Browse files Browse the repository at this point in the history
  • Loading branch information
rudraneel-chakraborty committed Sep 19, 2024
1 parent a5278ee commit 0fbbb32
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
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("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("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", 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 0fbbb32

Please sign in to comment.