Skip to content

Commit

Permalink
DATAGO-64300: Test negative scenarios (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmeldrum authored Dec 4, 2023
1 parent 9f100aa commit 3d1db1a
Show file tree
Hide file tree
Showing 27 changed files with 1,890 additions and 15 deletions.
3 changes: 3 additions & 0 deletions service/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@
<configuration>
<!--suppress UnresolvedMavenProperty -->
<argLine>${jacocoSurefire}</argLine>
<excludes>
<exclude>**/realTests/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
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.CommandResult;
import com.solace.maas.ep.event.management.agent.plugin.command.model.JobStatus;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.solace.maas.ep.event.management.agent.plugin.terraform.manager.TerraformManager.LOG_LEVEL_ERROR;
import static com.solace.maas.ep.event.management.agent.plugin.terraform.manager.TerraformManager.setCommandError;

@Slf4j
@Service
@ConditionalOnProperty(name = "event-portal.gateway.messaging.standalone", havingValue = "false")
public class CommandManager {
private final TerraformManager terraformManager;
private final CommandMapper commandMapper;
Expand All @@ -36,20 +45,46 @@ public CommandManager(TerraformManager terraformManager, CommandMapper commandMa
}

public void execute(CommandMessage request) {
Map<String, String> envVars = setBrokerSpecificEnvVars(request.getServiceId());
Map<String, String> envVars;
try {
envVars = setBrokerSpecificEnvVars(request.getServiceId());
} catch (Exception e) {
log.error("Error getting terraform variables", e);
Command firstCommand = request.getCommandBundles().get(0).getCommands().get(0);
setCommandError(firstCommand, e);
sendResponse(request);
return;
}

for (CommandBundle bundle : request.getCommandBundles()) {
// For now everything is run serially
for (Command command : bundle.getCommands()) {
switch (command.getCommandType()) {
case terraform:
terraformManager.execute(commandMapper.map(request), command, envVars);
break;
default:
throw new IllegalStateException("Unexpected value: " + command.getCommandType());
try {
switch (command.getCommandType()) {
case terraform:
terraformManager.execute(commandMapper.map(request), command, envVars);
break;
default:
command.setResult(CommandResult.builder()
.status(JobStatus.error)
.logs(List.of(
Map.of("message", "unknown command type " + command.getCommandType(),
"errorType", "UnknownCommandType",
"level", LOG_LEVEL_ERROR,
"timestamp", OffsetDateTime.now())))
.build());
break;
}
} catch (Exception e) {
log.error("Error executing command", e);
setCommandError(command, e);
}
}
}
sendResponse(request);
}

private void sendResponse(CommandMessage request) {
Map<String, String> topicVars = Map.of(
"orgId", request.getOrgId(),
"runtimeAgentId", eventPortalProperties.getRuntimeAgentId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.solace.maas.ep.event.management.agent;

import com.solace.maas.ep.event.management.agent.command.CommandManager;
import com.solace.maas.ep.event.management.agent.command.mapper.CommandMapper;
import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties;
import com.solace.maas.ep.event.management.agent.messagingServices.RtoMessagingService;
import com.solace.maas.ep.event.management.agent.plugin.config.VMRProperties;
import com.solace.maas.ep.event.management.agent.plugin.config.eventPortal.EventPortalPluginProperties;
Expand Down Expand Up @@ -140,6 +143,15 @@ public CommandPublisher getCommandPublisher() {
return mock(CommandPublisher.class);
}

@Bean
@Primary
public CommandManager getCommandManager(TerraformManager terraformManager, CommandMapper commandMapper,
CommandPublisher commandPublisher, MessagingServiceDelegateService messagingServiceDelegateService,
EventPortalProperties eventPortalProperties) {
return new CommandManager(terraformManager, commandMapper, commandPublisher,
messagingServiceDelegateService, eventPortalProperties);
}

@Bean
@Primary
KafkaClientConnection kafkaClientConnection() {
Expand Down
Loading

0 comments on commit 3d1db1a

Please sign in to comment.