Skip to content

Commit

Permalink
Merge pull request #141 from SolaceProducts/moodiRealist/DATAGO-64298…
Browse files Browse the repository at this point in the history
…-delete-old-log-files

[DATAGO-64298] rename correlationId to commandCorrelationId in missed spots
  • Loading branch information
moodiRealist authored Dec 12, 2023
2 parents 7d1879c + de92abf commit e84cbef
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import static com.solace.maas.ep.event.management.agent.constants.Command.COMMAND_CORRELATION_ID;
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;

Expand Down Expand Up @@ -88,7 +89,7 @@ private void sendResponse(CommandMessage request) {
Map<String, String> topicVars = Map.of(
"orgId", request.getOrgId(),
"runtimeAgentId", eventPortalProperties.getRuntimeAgentId(),
"correlationId", request.getCommandCorrelationId()
COMMAND_CORRELATION_ID, request.getCommandCorrelationId()
);
commandPublisher.sendCommandResponse(request, topicVars);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.solace.maas.ep.event.management.agent.constants;

import com.solace.maas.ep.event.management.agent.plugin.jacoco.ExcludeFromJacocoGeneratedReport;

@ExcludeFromJacocoGeneratedReport
public class Command {
public static final String COMMAND_CORRELATION_ID = "commandCorrelationId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.solace.maas.ep.common.messages.CommandLogMessage;
import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties;
import com.solace.maas.ep.event.management.agent.constants.Command;
import com.solace.maas.ep.event.management.agent.plugin.constants.RouteConstants;
import com.solace.maas.ep.event.management.agent.publisher.CommandLogsPublisher;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void process(Exchange exchange) throws Exception {
topicDetails.put("orgId", orgId);
topicDetails.put("runtimeAgentId", runtimeAgentId);
topicDetails.put("messagingServiceId", messagingServiceId);
topicDetails.put("commandCorrelationId", commandCorrelationId);
topicDetails.put(Command.COMMAND_CORRELATION_ID, commandCorrelationId);

logDataPublisher.sendCommandLogData(logDataMessage, topicDetails);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.solace.maas.ep.common.messages.CommandLogMessage;
import com.solace.maas.ep.event.management.agent.config.SolaceConfiguration;
import com.solace.maas.ep.event.management.agent.constants.Command;
import com.solace.maas.ep.event.management.agent.plugin.publisher.SolacePublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -26,7 +27,7 @@ public CommandLogsPublisher(SolacePublisher solacePublisher, SolaceConfiguration

public void sendCommandLogData(CommandLogMessage message, Map<String, String> topicDetails) {
String topicString = solaceConfiguration.getTopicPrefix() +
String.format("commandLogs/v1/%s", topicDetails.get("commandCorrelationId"));
String.format("commandLogs/v1/%s", topicDetails.get(Command.COMMAND_CORRELATION_ID));

solacePublisher.publish(message, topicString);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.constants.Command;
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;
Expand All @@ -24,15 +25,15 @@ public CommandPublisher(SolacePublisher solacePublisher, SolaceConfiguration sol
* Sends the command response to EP.
* <p>
* The topic for command response:
* sc/ep/runtime/{orgId}/{runtimeAgentId}/commandResponse/v1/{correlationId}
* sc/ep/runtime/{orgId}/{runtimeAgentId}/commandResponse/v1/{commandCorrelationId}
*/

public void sendCommandResponse(MOPMessage message, Map<String, String> topicDetails) {

String topicString =
String.format("%scommandResponse/v1/%s",
solaceConfiguration.getTopicPrefix(),
topicDetails.get("correlationId"));
topicDetails.get(Command.COMMAND_CORRELATION_ID));

solacePublisher.publish(message, topicString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.solace.maas.ep.event.management.agent.constants.Command;
import com.solace.maas.ep.event.management.agent.plugin.constants.RouteConstants;
import com.solace.maas.ep.event.management.agent.plugin.mop.EnumDeserializer;
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPConstants;
Expand Down Expand Up @@ -97,7 +98,7 @@ private static void setupMDC(String messageAsString, String receivedClassName) t
}

if (commandClassNames.contains(receivedClassName)) {
MDC.put(RouteConstants.COMMAND_CORRELATION_ID, map.get("correlationId"));
MDC.put(RouteConstants.COMMAND_CORRELATION_ID, map.get(Command.COMMAND_CORRELATION_ID));
MDC.put(RouteConstants.MESSAGING_SERVICE_ID, map.get("serviceId"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;

import static com.solace.maas.ep.event.management.agent.constants.Command.COMMAND_CORRELATION_ID;
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;
Expand Down Expand Up @@ -101,6 +102,6 @@ public void testCommandManager() {
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.getCommandCorrelationId());
assert topicVars.get(COMMAND_CORRELATION_ID).equals(message.getCommandCorrelationId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class CommandRequest {
private String correlationId;
private String commandCorrelationId;
private String context;
private String serviceId;
private List<CommandBundle> commandBundles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void saveLogToFile(CommandRequest request, List<String> logs) throws IOEx
}

Path out = Files.createTempFile(logPath, System.currentTimeMillis() + "-"
+ request.getCorrelationId() + "-job", ".log");
+ request.getCommandCorrelationId() + "-job", ".log");

Files.write(out, logs, Charset.defaultCharset());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public TerraformManager(TerraformLogProcessingService terraformLogProcessingServ

public void execute(CommandRequest request, Command command, Map<String, String> envVars) {

MDC.put(RouteConstants.COMMAND_CORRELATION_ID, request.getCorrelationId());
MDC.put(RouteConstants.COMMAND_CORRELATION_ID, request.getCommandCorrelationId());
MDC.put(RouteConstants.MESSAGING_SERVICE_ID, request.getServiceId());

log.debug("Executing command {} for serviceId {} correlationId {} context {}", command.getCommand(), request.getServiceId(),
request.getCorrelationId(), request.getContext());
request.getCommandCorrelationId(), request.getContext());

try (TerraformClient terraformClient = terraformClientFactory.createClient()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private static CommandRequest generateCommandRequest(Command commandRequest) {
.exitOnFailure(false)
.commands(List.of(commandRequest))
.build()))
.correlationId("234")
.commandCorrelationId("234")
.context("app123")
.serviceId("ms1234")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void importResource() {
.build();

CommandRequest terraformRequest = CommandRequest.builder()
.correlationId("abc123")
.commandCorrelationId("abc123")
.context("app123-consumer")
.commandBundles(List.of(
CommandBundle.builder()
Expand Down Expand Up @@ -156,7 +156,7 @@ private List<CommandBundle> executeTerraformCommand(String hclFileName, String t
.build()))
.context(context)
.serviceId("abc123")
.correlationId("myCorrelationId")
.commandCorrelationId("myCorrelationId")
.build();

for (Command command : terraformRequest.getCommandBundles().get(0).getCommands()) {
Expand Down

0 comments on commit e84cbef

Please sign in to comment.