Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATAGO-64300: Test negative scenarios #135

Merged
merged 17 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want the "real" tests to run as part of unit tests

<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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added error handling when we are unable to find the messaging service from the service id

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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send back an error when the command type is unknown

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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send back an error if any other type of exception occurs.

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
Loading