-
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.
Added message publisher. Changed CommandResponse to only have logs, n…
…ot errors and logs. Error logs are determined by the log level.
- Loading branch information
1 parent
a96d82d
commit dc2b308
Showing
14 changed files
with
339 additions
and
57 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
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.
37 changes: 37 additions & 0 deletions
37
...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,37 @@ | ||
package com.solace.maas.ep.event.management.agent.publisher; | ||
|
||
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; | ||
|
||
public CommandPublisher(SolacePublisher solacePublisher) { | ||
this.solacePublisher = solacePublisher; | ||
} | ||
|
||
/** | ||
* 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("sc/ep/runtime/%s/%s/commandResponse/v1/%s", | ||
topicDetails.get("orgId"), | ||
topicDetails.get("runtimeAgentId"), | ||
topicDetails.get("correlationId")); | ||
|
||
solacePublisher.publish(message, topicString); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...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,34 @@ | ||
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; | ||
|
||
/** | ||
* This is here for developers to test that messages are flowing without having to test with ep-core. | ||
* <p> | ||
* This should normally be disabled. | ||
*/ | ||
@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.