-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAGO-64297: Added message subscriber/publisher (#134)
- Loading branch information
1 parent
a96d82d
commit 9f100aa
Showing
16 changed files
with
330 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...src/main/java/com/solace/maas/ep/event/management/agent/command/mapper/CommandMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.solace.maas.ep.event.management.agent.command.mapper; | ||
|
||
import com.solace.maas.ep.common.messages.CommandMessage; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandRequest; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface CommandMapper { | ||
|
||
CommandRequest map(CommandMessage input); | ||
|
||
CommandMessage map(CommandRequest input); | ||
} |
28 changes: 0 additions & 28 deletions
28
...c/main/java/com/solace/maas/ep/event/management/agent/command/rest/CommandController.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...n/src/main/java/com/solace/maas/ep/event/management/agent/publisher/CommandPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.solace.maas.ep.event.management.agent.publisher; | ||
|
||
import com.solace.maas.ep.event.management.agent.config.SolaceConfiguration; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessage; | ||
import com.solace.maas.ep.event.management.agent.plugin.publisher.SolacePublisher; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
@ConditionalOnProperty(name = "event-portal.gateway.messaging.standalone", havingValue = "false") | ||
public class CommandPublisher { | ||
|
||
private final SolacePublisher solacePublisher; | ||
private final SolaceConfiguration solaceConfiguration; | ||
|
||
public CommandPublisher(SolacePublisher solacePublisher, SolaceConfiguration solaceConfiguration) { | ||
this.solacePublisher = solacePublisher; | ||
this.solaceConfiguration = solaceConfiguration; | ||
} | ||
|
||
/** | ||
* Sends the command response to EP. | ||
* <p> | ||
* The topic for command response: | ||
* sc/ep/runtime/{orgId}/{runtimeAgentId}/commandResponse/v1/{correlationId} | ||
*/ | ||
|
||
public void sendCommandResponse(MOPMessage message, Map<String, String> topicDetails) { | ||
|
||
String topicString = | ||
String.format("%scommandResponse/v1/%s", | ||
solaceConfiguration.getTopicPrefix(), | ||
topicDetails.get("correlationId")); | ||
|
||
solacePublisher.publish(message, topicString); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/com/solace/maas/ep/event/management/agent/subscriber/CommandMessageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.solace.maas.ep.event.management.agent.subscriber; | ||
|
||
import com.solace.maas.ep.common.messages.CommandMessage; | ||
import com.solace.maas.ep.event.management.agent.command.CommandManager; | ||
import com.solace.maas.ep.event.management.agent.config.SolaceConfiguration; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@ConditionalOnProperty(name = "event-portal.gateway.messaging.standalone", havingValue = "false") | ||
public class CommandMessageHandler extends SolaceMessageHandler<CommandMessage> { | ||
|
||
private final CommandManager commandManager; | ||
|
||
public CommandMessageHandler( | ||
SolaceConfiguration solaceConfiguration, | ||
SolaceSubscriber solaceSubscriber, CommandManager commandManager) { | ||
super(solaceConfiguration.getTopicPrefix() + "command/v1/>", solaceSubscriber); | ||
this.commandManager = commandManager; | ||
} | ||
|
||
@Override | ||
public void receiveMessage(String destinationName, CommandMessage message) { | ||
log.debug("receiveMessage {}\n{}", destinationName, message); | ||
commandManager.execute(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...st/java/com/solace/maas/ep/event/management/agent/commandManager/CommandManagerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.solace.maas.ep.event.management.agent.commandManager; | ||
|
||
import com.solace.maas.ep.common.messages.CommandMessage; | ||
import com.solace.maas.ep.event.management.agent.TestConfig; | ||
import com.solace.maas.ep.event.management.agent.command.CommandManager; | ||
import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.Command; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandBundle; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandType; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.ExecutionType; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPSvcType; | ||
import com.solace.maas.ep.event.management.agent.plugin.service.MessagingServiceDelegateService; | ||
import com.solace.maas.ep.event.management.agent.plugin.solace.processor.semp.SempClient; | ||
import com.solace.maas.ep.event.management.agent.plugin.solace.processor.semp.SolaceHttpSemp; | ||
import com.solace.maas.ep.event.management.agent.plugin.terraform.manager.TerraformManager; | ||
import com.solace.maas.ep.event.management.agent.publisher.CommandPublisher; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType.generic; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ActiveProfiles("TEST") | ||
@EnableAutoConfiguration | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) | ||
public class CommandManagerTests { | ||
|
||
@Autowired | ||
CommandManager commandManager; | ||
|
||
@Autowired | ||
TerraformManager terraformManager; | ||
|
||
@Autowired | ||
CommandPublisher commandPublisher; | ||
|
||
@Autowired | ||
MessagingServiceDelegateService messagingServiceDelegateService; | ||
|
||
@Autowired | ||
EventPortalProperties eventPortalProperties; | ||
|
||
@Test | ||
public void testCommandManager() { | ||
// Create a command request message | ||
CommandMessage message = new CommandMessage(); | ||
message.setOrigType(MOPSvcType.maasEventMgmt); | ||
message.withMessageType(generic); | ||
message.setContext("abc"); | ||
message.setActorId("myActorId"); | ||
message.setOrgId(eventPortalProperties.getOrganizationId()); | ||
message.setTraceId("myTraceId"); | ||
message.setCorrelationId("myCorrelationId"); | ||
message.setCommandBundles(List.of( | ||
CommandBundle.builder() | ||
.executionType(ExecutionType.serial) | ||
.exitOnFailure(false) | ||
.commands(List.of( | ||
Command.builder() | ||
.commandType(CommandType.terraform) | ||
.body("asdfasdfadsf") | ||
.command("apply") | ||
.build())) | ||
.build())); | ||
|
||
doNothing().when(terraformManager).execute(any(), any(), any()); | ||
|
||
ArgumentCaptor<Map<String, String>> topicArgCaptor = ArgumentCaptor.forClass(Map.class); | ||
doNothing().when(commandPublisher).sendCommandResponse(any(), any()); | ||
when(messagingServiceDelegateService.getMessagingServiceClient(any())).thenReturn( | ||
new SolaceHttpSemp(SempClient.builder() | ||
.username("myUsername") | ||
.password("myPassword") | ||
.connectionUrl("myConnectionUrl") | ||
.build())); | ||
commandManager.execute(message); | ||
|
||
// Verify terraform manager is called | ||
ArgumentCaptor<Map<String, String>> envArgCaptor = ArgumentCaptor.forClass(Map.class); | ||
verify(terraformManager, times(1)).execute(any(), any(), envArgCaptor.capture()); | ||
|
||
// Verify the env vars are set with the terraform manager is called | ||
Map<String, String> envVars = envArgCaptor.getValue(); | ||
assert envVars.get("TF_VAR_password").equals("myPassword"); | ||
assert envVars.get("TF_VAR_username").equals("myUsername"); | ||
assert envVars.get("TF_VAR_url").equals("myConnectionUrl"); | ||
|
||
verify(commandPublisher, times(1)).sendCommandResponse(any(), topicArgCaptor.capture()); | ||
|
||
Map<String, String> topicVars = topicArgCaptor.getValue(); | ||
assert topicVars.get("orgId").equals(eventPortalProperties.getOrganizationId()); | ||
assert topicVars.get("runtimeAgentId").equals(eventPortalProperties.getRuntimeAgentId()); | ||
assert topicVars.get("correlationId").equals(message.getCorrelationId()); | ||
} | ||
} |
Oops, something went wrong.