-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
dc2b308
5e58b0b
3005b5a
67048e3
e0c75eb
333400d
8ad7d6b
d82f78f
84367c5
376e8d4
cbc4d9f
5b1b283
59bbd61
560f637
4e48e59
b1f9a73
ed510b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
|
There was a problem hiding this comment.
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