From 28c349eca537a2b1f89f26ddf93d406d27003f8d Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Sun, 16 Jun 2024 16:37:23 -0400 Subject: [PATCH 01/13] DATAGO-75198 wip --- .../ep/common/messages/CommandMessage.java | 24 +- .../agent/command/CommandManager.java | 18 +- .../SolacePersistentMessageHandler.java | 22 +- .../CommandMessageProcessor.java | 12 +- .../messageProcessors/MessageProcessor.java | 2 + .../ScanCommandMessageProcessor.java | 5 + .../src/main/resources/application.yml | 382 +++--------------- 7 files changed, 130 insertions(+), 335 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/common/messages/CommandMessage.java b/service/application/src/main/java/com/solace/maas/ep/common/messages/CommandMessage.java index 84c71c492..4755c295f 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/messages/CommandMessage.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/messages/CommandMessage.java @@ -1,5 +1,7 @@ package com.solace.maas.ep.common.messages; +import com.solace.maas.ep.common.model.CommandMessageWithResources; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandBundle; import com.solace.maas.ep.event.management.agent.plugin.command.model.JobStatus; import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessage; @@ -11,13 +13,14 @@ import java.util.List; @Data -public class CommandMessage extends MOPMessage { +public class CommandMessage extends MOPMessage implements CommandMessageWithResources { private String commandCorrelationId; private String context; private String serviceId; private JobStatus status; private List commandBundles; + private List resources; public CommandMessage() { super(); @@ -40,6 +43,25 @@ public CommandMessage(String serviceId, this.commandBundles = commandBundles; } + public CommandMessage(String serviceId, + String commandCorrelationId, + String context, + JobStatus status, + List commandBundles, + List resources) { + super(); + withMessageType(MOPMessageType.generic) + .withProtocol(MOPProtocol.epConfigPush) + .withVersion("1") + .withUhFlag(MOPUHFlag.ignore); + this.serviceId = serviceId; + this.commandCorrelationId = commandCorrelationId; + this.context = context; + this.status = status; + this.commandBundles = commandBundles; + this.resources = resources; + } + @Override public String toLog() { return null; diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/command/CommandManager.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/command/CommandManager.java index 591a8122d..e312728cd 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/command/CommandManager.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/command/CommandManager.java @@ -73,13 +73,21 @@ public void execute(CommandMessage request) { CompletableFuture.runAsync(() -> configPush(requestBO), configPushPool) .exceptionally(e -> { log.error("Error running command", e); - Command firstCommand = requestBO.getCommandBundles().get(0).getCommands().get(0); - setCommandError(firstCommand, (Exception) e); - finalizeAndSendResponse(requestBO); + handleError((Exception) e, requestBO); return null; }); } + public void handleError(Exception e, CommandMessage message) { + handleError(e, commandMapper.map(message)); + } + + private void handleError(Exception e, CommandRequest requestBO) { + Command firstCommand = requestBO.getCommandBundles().get(0).getCommands().get(0); + setCommandError(firstCommand, e); + finalizeAndSendResponse(requestBO); + } + @SuppressWarnings("PMD") public void configPush(CommandRequest request) { Map envVars; @@ -87,9 +95,7 @@ public void configPush(CommandRequest request) { 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); - finalizeAndSendResponse(request); + handleError(e, request); return; } List executionLogFilesToClean = new ArrayList<>(); diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java index cba94e92e..739668245 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java @@ -8,6 +8,7 @@ import com.solace.messaging.receiver.MessageReceiver; import com.solace.messaging.receiver.PersistentMessageReceiver; import com.solace.messaging.resources.Queue; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -31,6 +32,7 @@ public class SolacePersistentMessageHandler extends BaseSolaceMessageHandler imp private final Map messageProcessorsByClassType; private final MessagingService messagingService; private final EventPortalProperties eventPortalProperties; + @Getter private PersistentMessageReceiver persistentMessageReceiver; protected SolacePersistentMessageHandler(MessagingService messagingService, @@ -48,7 +50,8 @@ protected SolacePersistentMessageHandler(MessagingService messagingService, @Override public void onMessage(InboundMessage inboundMessage) { String mopMessageSubclass = ""; - + MessageProcessor processor = null; + Object message = null; try { mopMessageSubclass = inboundMessage.getProperty(MOPConstants.MOP_MSG_META_DECODER); String messageAsString = inboundMessage.getPayloadAsString(); @@ -57,26 +60,29 @@ public void onMessage(InboundMessage inboundMessage) { messageClass = Class.forName(mopMessageSubclass); cachedJSONDecoders.put(mopMessageSubclass, messageClass); } - MessageProcessor processor = messageProcessorsByClassType.get(messageClass); + processor = messageProcessorsByClassType.get(messageClass); if (processor == null) { throw new UnsupportedOperationException("Could not find message processor for message of class " + messageClass.getCanonicalName()); } setupMDC(messageAsString, messageClass.getSimpleName()); log.trace("onMessage: {}\n{}", messageClass, messageAsString); - processor.processMessage(processor.castToMessageClass(toMessage(messageAsString, messageClass))); + message = toMessage(messageAsString, messageClass); + processor.processMessage(processor.castToMessageClass(message)); } catch (Exception e) { - log.error("Error while processing inbound message from queue for mopMessageSubclass: {}", mopMessageSubclass); + if (processor != null && message != null) { + log.error("Error while processing inbound message from queue for mopMessageSubclass: {}", mopMessageSubclass); + processor.onFailure(e, processor.castToMessageClass(message)); + } else { + log.error("Unsupported message type and/or processor encountered. Skipping processing", e); + } + throw new IllegalArgumentException(e); } finally { persistentMessageReceiver.ack(inboundMessage); } } - public PersistentMessageReceiver getPersistentMessageReceiver() { - return this.persistentMessageReceiver; - } - private PersistentMessageReceiver buildPersistentMessageReceiver(Queue queue) { return messagingService .createPersistentMessageReceiverBuilder() diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java index 323323b76..c1553ca56 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java @@ -13,14 +13,17 @@ public class CommandMessageProcessor implements MessageProcessor private final CommandManager commandManager; + private final DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; - public CommandMessageProcessor(CommandManager commandManager) { - + public CommandMessageProcessor(CommandManager commandManager, + DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper) { this.commandManager = commandManager; + this.dynamicResourceConfigurationHelper = dynamicResourceConfigurationHelper; } @Override public void processMessage(CommandMessage message) { + dynamicResourceConfigurationHelper.loadSolaceBrokerResourceConfigurations(message.getResources()); commandManager.execute(message); } @@ -33,4 +36,9 @@ public Class supportedClass() { public CommandMessage castToMessageClass(Object message) { return (CommandMessage) message; } + + @Override + public void onFailure(Exception e, CommandMessage message) { + commandManager.handleError(e, message); + } } diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/MessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/MessageProcessor.java index 49f6ddbb9..ba2322961 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/MessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/MessageProcessor.java @@ -9,4 +9,6 @@ public interface MessageProcessor { Class supportedClass(); T castToMessageClass(Object message); + + void onFailure(Exception e, T message); } diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java index 0c82a8380..e15f1e4c7 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java @@ -72,4 +72,9 @@ public Class supportedClass() { public ScanCommandMessage castToMessageClass(Object message) { return (ScanCommandMessage) message; } + + @Override + public void onFailure(Exception e, ScanCommandMessage message) { + log.debug("Requires implementation"); + } } diff --git a/service/application/src/main/resources/application.yml b/service/application/src/main/resources/application.yml index 31385b9af..fa8c4af19 100644 --- a/service/application/src/main/resources/application.yml +++ b/service/application/src/main/resources/application.yml @@ -4,354 +4,100 @@ springdoc: path: /docs/event-management-agent swagger-ui: path: /event-management-agent/swagger-ui.html - server: port: 8180 - -idGenerator: - originId: event_management_agent_${EP_EVENT_MANAGEMENT_AGENT_ID} - spring: + servlet: + multipart: + max-request-size: ${MAX_REQUEST_SIZE:5MB} + max-file-size: ${MAX_FILE_SIZE:5MB} + main: + allow-bean-definition-overriding: true + h2: + console: + path: /h2 + enabled: true + settings: + web-allow-others: true datasource: url: jdbc:h2:file:./data/cache;DB_CLOSE_ON_EXIT=FALSE - username: sa password: password driver-class-name: org.h2.Driver + username: sa jpa: - database-platform: org.hibernate.dialect.H2Dialect hibernate: ddl-auto: create-drop + database-platform: org.hibernate.dialect.H2Dialect defer-datasource-initialization: true - h2: - console: - path: /h2 - enabled: true - settings: - web-allow-others: true - servlet: - multipart: - max-request-size: ${MAX_REQUEST_SIZE:5MB} - max-file-size: ${MAX_FILE_SIZE:5MB} - main: - allow-bean-definition-overriding: true - camel: springboot: use-mdc-logging: true - errorHandling: - maximumRedeliveries: 10 - maximumRedeliveryDelay: 60000 - redeliveryDelay: 1000 - kafka: client: config: connections: - timeout: - value: 60_000 - unit: milliseconds max-idle: - value: 10_000 unit: milliseconds + value: 10000 request-timeout: - value: 5_000 unit: milliseconds - reconnections: - backoff: - value: 50 + value: 5000 + timeout: unit: milliseconds + value: 60000 + reconnections: max-backoff: - value: 1_000 unit: milliseconds - + value: 1000 + backoff: + unit: milliseconds + value: 50 eventPortal: - runtimeAgentId: ${EP_RUNTIME_AGENT_ID:defaultAgentId} - organizationId: ${EP_ORGANIZATION_ID:defaultOrgId} + runtimeAgentId: ${EP_RUNTIME_AGENT_ID:av60o82f4ir} + organizationId: ${EP_ORGANIZATION_ID:localrcorg} topicPrefix: ${EP_TOPIC_PREFIX:sc/ep/runtime} gateway: - id: gateway - name: evmr1 + id: f0ydyzsr1jp + name: POCCloudManagedEMAEVMR messaging: - standalone: true + standalone: false rtoSession: false - enableHeartbeats: false - testHeartbeats: false + enableHeartbeats: true + testHeartbeats: true connections: - name: eventPortalGateway - authenticationType: ${EP_GATEWAY_AUTH} - url: ${EP_GATEWAY_URL} - msgVpn: ${EP_GATEWAY_MSGVPN} - trustStoreDir: ${SSL_STORE_DIR} + authenticationType: ${EP_GATEWAY_AUTH:basicAuthentication} + msgVpn: ${EP_GATEWAY_MSGVPN:poccloudmanagedemaevmr} + url: ${EP_GATEWAY_URL:tcps://mr-connection-i41xmmlismp.messaging.solace.cloud:55443} users: - - name: messaging1 - username: ${EP_GATEWAY_USERNAME} - password: ${EP_GATEWAY_PASSWORD} - clientName: runtime_agent_${EP_RUNTIME_AGENT_ID} # 'client_' + runtimeAgentId - -# Below is an example of how to set up messaging service configuration in the application.yml file. - -#plugins: -# resources: -# # Confluent Schema Registry No Auth example -# - id: someConfluentId -# name: no auth confluent example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# - id2 -# - id3 -# connections: -# - name: myConfluentNoAuth -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# # Confluent Schema Registry Basic Auth example -# - id: someConfluentId -# name: no auth confluent example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# connections: -# - name: myConfluentBasicAuth -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# authentication: -# - protocol: BASIC -# credentials: -# - properties: -# - name: username -# value: ${CONFLUENT_USERNAME} -# - name: password -# value: ${CONFLUENT_PASSWORD} -# source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# # Confluent Schema Registry Basic Auth With SSL example -# - id: someConfluentId -# name: no auth confluent example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# connections: -# - name: myConfluentBasicAuthWithSSL -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# authentication: -# - protocol: BASIC_SSL -# credentials: -# - properties: -# - name: username -# value: ${CONFLUENT_USERNAME} -# - name: password -# value: ${CONFLUENT_PASSWORD} -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# # Confluent Schema Registry Basic Auth With mTLS example -# - id: someConfluentId -# name: Basic Auth With mTLS example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# connections: -# - name: myConfluentBasicAuthWithMTLS -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# authentication: -# - protocol: BASIC_MTLS -# credentials: -# - properties: -# - name: username -# value: ${CONFLUENT_USERNAME} -# - name: password -# value: ${CONFLUENT_PASSWORD} -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# - name: ssl.keystore.location -# value: ${KEYSTORE_LOCATION} -# - name: ssl.keystore.password -# value: ${KEYSTORE_PASSWORD} -# - name: ssl.key.password -# value: ${KEY_PASSWORD} -# source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# # Confluent Schema Registry TLS example -# - id: someConfluentId -# name: no auth confluent example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# connections: -# - name: myConfluentTLS -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# authentication: -# - protocol: TLS -# credentials: -# - properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# # Confluent Schema Registry MTLS example -# - id: someConfluentId -# name: no auth confluent example -# type: confluent_schema_registry -# relatedServices: -# - id1 -# connections: -# - name: myConfluentMTLS -# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} -# authentication: -# - protocol: MTLS -# credentials: -# - properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# - name: ssl.keystore.password -# value: ${KEYSTORE_PASSWORD} -# - name: ssl.keystore.location -# value: ${KEYSTORE_LOCATION} -# - name: ssl.key.password -# value: ${KEY_PASSWORD} -# source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# # Solace example -# - id: solaceDefaultService -# type: SOLACE -# name: staging service -# connections: -# - name: mySolaceServiceSemp -# url: ${SOLACE_SEMP_URL} -# authentication: -# - protocol: SEMP -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: username -# value: ${SOLACE_SEMP_USERNAME} -# - name: password -# value: ${SOLACE_SEMP_PASSWORD} -# properties: -# - name: msgVpn -# value: ${SOLACE_VPN_NAME} -# - name: sempPageSize -# value: 100 -# # MTLS example -# - id: kafkaMTLSServiceExample -# name: mtls kafka cluster example -# type: KAFKA -# connections: -# - name: kafkaMTLSConnection -# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:11091,kafka2:11092} -# authentication: -# - protocol: SSL -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# - name: ssl.keystore.password -# value: ${KEYSTORE_PASSWORD} -# - name: ssl.keystore.location -# value: ${KEYSTORE_LOCATION} -# - name: ssl.key.password -# value: ${KEY_PASSWORD} -# # SASL SCRAM -# - id: kafkaSASLSCRAMServiceExample -# name: sasl scram kafka cluster example -# type: KAFKA -# connections: -# - name: kafkaSASLSCRAMConnection -# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:14091,kafka2:14092} -# authentication: -# - protocol: SASL_SSL -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: ssl.truststore.password -# value: ${TRUSTSTORE_PASSWORD} -# - name: sasl.jaas.config -# value: org.apache.kafka.common.security.scram.ScramLoginModule required username= password=; -# - name: sasl.mechanism -# value: SCRAM-SHA-256 -# # SASL Plain example -# - id: saslplain -# name: saslplain -# type: KAFKA -# connections: -# - name: saslplainconn -# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:9091,kafka2:9092} -# authentication: -# - protocol: SASL_PLAINTEXT -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: sasl.mechanism -# value: PLAIN -# - name: sasl.jaas.config -# value: org.apache.kafka.common.security.plain.PlainLoginModule required username=">" password=""; -# # SASL Plain over SSL -# - id: saslplainssl -# name: saslplainssl -# type: KAFKA -# connections: -# - name: saslplainsslconn -# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:13091,kafka2:13092} -# authentication: -# - protocol: SASL_SSL -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: sasl.mechanism -# value: PLAIN -# - name: sasl.jaas.config -# value: org.apache.kafka.common.security.plain.PlainLoginModule required username=">" password=""; -# # AWS IAM Example. -# # NOTE: Remember to set the aws access id and password in the environment or credentials! -# - id: iam -# name: iam -# type: KAFKA -# connections: -# - name: iamConn -# url: ${KAFKA_BOOTSTRAP_SERVERS:awsservers:9098} -# authentication: -# - protocol: SASL_SSL -# credentials: -# - source: ENVIRONMENT_VARIABLE -# operations: -# - name: ALL -# properties: -# - name: ssl.truststore.location -# value: ${TRUSTSTORE_LOCATION} -# - name: security.protocol -# value: SASL_SSL -# - name: sasl.mechanism -# value: AWS_MSK_IAM -# - name: sasl.jaas.config -# value: software.amazon.msk.auth.iam.IAMLoginModule required; -# - name: sasl.client.callback.handler.class -# value: software.amazon.msk.auth.iam.IAMClientCallbackHandler + - clientName: client_av60o82f4ir + name: messaging1 + password: ADttr7Dxf--x9S=wIivwR!qc + username: ${EP_GATEWAY_USERNAME:localrcorg-v6693yiarsp-av60o82f4ir} +plugins: + resources: + - id: 26dn6j9g9s0 + type: solace + name: rchakraborty-dev + connections: + - name: rchakraborty-dev + url: https://ep-ivmrs-for-devs.messaging.solace.cloud:943 + properties: + - value: rchakraborty-dev + name: msgVpn + - value: 100 + name: sempPageSize + authentication: + - properties: + - value: basicAuthentication + name: type + protocol: semp + credentials: + - properties: + - name: username + value: rchakraborty-dev + - name: password + value: rchakraborty-dev + operations: + - name: ALL + source: ENVIRONMENT_VARIABLE From 7dee706c2e14bb473e730229faef1812b3da0556 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Mon, 17 Jun 2024 18:29:13 -0400 Subject: [PATCH 02/13] DATAGO-75198 wip --- .../agent/subscriber/SolacePersistentMessageHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java index 739668245..8ae5c055b 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java @@ -74,10 +74,9 @@ public void onMessage(InboundMessage inboundMessage) { log.error("Error while processing inbound message from queue for mopMessageSubclass: {}", mopMessageSubclass); processor.onFailure(e, processor.castToMessageClass(message)); } else { - log.error("Unsupported message type and/or processor encountered. Skipping processing", e); + log.error("Unsupported message and/or processor encountered. Skipping processing", e); } - throw new IllegalArgumentException(e); } finally { persistentMessageReceiver.ack(inboundMessage); } From b630765ebd84c66702dfdda13a7151245993034e Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Tue, 18 Jun 2024 09:33:06 -0400 Subject: [PATCH 03/13] DATAGO-75198 wip --- .../CommandMessageProcessor.java | 9 ++ .../src/main/resources/application.yml | 91 +++++++------------ 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java index c1553ca56..aac54049f 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java @@ -1,8 +1,10 @@ package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; +import com.fasterxml.jackson.databind.ObjectMapper; import com.solace.maas.ep.common.messages.CommandMessage; import com.solace.maas.ep.event.management.agent.command.CommandManager; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @@ -15,6 +17,8 @@ public class CommandMessageProcessor implements MessageProcessor private final DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; + @Autowired + private ObjectMapper objectMapper; public CommandMessageProcessor(CommandManager commandManager, DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper) { this.commandManager = commandManager; @@ -23,6 +27,11 @@ public CommandMessageProcessor(CommandManager commandManager, @Override public void processMessage(CommandMessage message) { + try{ + System.out.println(objectMapper.writeValueAsString(message)); + } catch (Exception e){ + + } dynamicResourceConfigurationHelper.loadSolaceBrokerResourceConfigurations(message.getResources()); commandManager.execute(message); } diff --git a/service/application/src/main/resources/application.yml b/service/application/src/main/resources/application.yml index fa8c4af19..5e91a75a8 100644 --- a/service/application/src/main/resources/application.yml +++ b/service/application/src/main/resources/application.yml @@ -7,58 +7,59 @@ springdoc: server: port: 8180 spring: - servlet: - multipart: - max-request-size: ${MAX_REQUEST_SIZE:5MB} - max-file-size: ${MAX_FILE_SIZE:5MB} - main: - allow-bean-definition-overriding: true + jpa: + defer-datasource-initialization: true + database-platform: org.hibernate.dialect.H2Dialect + hibernate: + ddl-auto: create-drop + datasource: + driver-class-name: org.h2.Driver + password: password + url: jdbc:h2:file:./data/cache;DB_CLOSE_ON_EXIT=FALSE + username: sa h2: console: path: /h2 - enabled: true settings: web-allow-others: true - datasource: - url: jdbc:h2:file:./data/cache;DB_CLOSE_ON_EXIT=FALSE - password: password - driver-class-name: org.h2.Driver - username: sa - jpa: - hibernate: - ddl-auto: create-drop - database-platform: org.hibernate.dialect.H2Dialect - defer-datasource-initialization: true + enabled: true + main: + allow-bean-definition-overriding: true + servlet: + multipart: + max-file-size: ${MAX_FILE_SIZE:5MB} + max-request-size: ${MAX_REQUEST_SIZE:5MB} camel: springboot: use-mdc-logging: true kafka: client: config: + reconnections: + max-backoff: + value: 1000 + unit: milliseconds + backoff: + value: 50 + unit: milliseconds connections: max-idle: - unit: milliseconds value: 10000 - request-timeout: unit: milliseconds + request-timeout: value: 5000 - timeout: unit: milliseconds + timeout: value: 60000 - reconnections: - max-backoff: unit: milliseconds - value: 1000 - backoff: - unit: milliseconds - value: 50 eventPortal: - runtimeAgentId: ${EP_RUNTIME_AGENT_ID:av60o82f4ir} + runtimeAgentId: ${EP_RUNTIME_AGENT_ID:13k1j7c913c} organizationId: ${EP_ORGANIZATION_ID:localrcorg} - topicPrefix: ${EP_TOPIC_PREFIX:sc/ep/runtime} gateway: id: f0ydyzsr1jp name: POCCloudManagedEMAEVMR + managed: true + incomingRequestQueueName: ep_core_ema_requests_fakedcid messaging: standalone: false rtoSession: false @@ -70,34 +71,8 @@ eventPortal: msgVpn: ${EP_GATEWAY_MSGVPN:poccloudmanagedemaevmr} url: ${EP_GATEWAY_URL:tcps://mr-connection-i41xmmlismp.messaging.solace.cloud:55443} users: - - clientName: client_av60o82f4ir + - password: b{w{Z3Xh{0dsp3tbl0Nw6cql name: messaging1 - password: ADttr7Dxf--x9S=wIivwR!qc - username: ${EP_GATEWAY_USERNAME:localrcorg-v6693yiarsp-av60o82f4ir} -plugins: - resources: - - id: 26dn6j9g9s0 - type: solace - name: rchakraborty-dev - connections: - - name: rchakraborty-dev - url: https://ep-ivmrs-for-devs.messaging.solace.cloud:943 - properties: - - value: rchakraborty-dev - name: msgVpn - - value: 100 - name: sempPageSize - authentication: - - properties: - - value: basicAuthentication - name: type - protocol: semp - credentials: - - properties: - - name: username - value: rchakraborty-dev - - name: password - value: rchakraborty-dev - operations: - - name: ALL - source: ENVIRONMENT_VARIABLE + clientName: client_13k1j7c913c + username: ${EP_GATEWAY_USERNAME:localrcorg-v6693yiarsp-13k1j7c913c} + topicPrefix: ${EP_TOPIC_PREFIX:sc/ep/runtime} From 9fedafffb09996671daedf0b7bf71a8d4bdf1054 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Tue, 18 Jun 2024 09:33:53 -0400 Subject: [PATCH 04/13] DATAGO-75198 wip --- .../src/main/resources/application.yml | 355 ++++++++++++++++-- 1 file changed, 317 insertions(+), 38 deletions(-) diff --git a/service/application/src/main/resources/application.yml b/service/application/src/main/resources/application.yml index 5e91a75a8..31385b9af 100644 --- a/service/application/src/main/resources/application.yml +++ b/service/application/src/main/resources/application.yml @@ -4,75 +4,354 @@ springdoc: path: /docs/event-management-agent swagger-ui: path: /event-management-agent/swagger-ui.html + server: port: 8180 + +idGenerator: + originId: event_management_agent_${EP_EVENT_MANAGEMENT_AGENT_ID} + spring: + datasource: + url: jdbc:h2:file:./data/cache;DB_CLOSE_ON_EXIT=FALSE + username: sa + password: password + driver-class-name: org.h2.Driver jpa: - defer-datasource-initialization: true database-platform: org.hibernate.dialect.H2Dialect hibernate: ddl-auto: create-drop - datasource: - driver-class-name: org.h2.Driver - password: password - url: jdbc:h2:file:./data/cache;DB_CLOSE_ON_EXIT=FALSE - username: sa + defer-datasource-initialization: true h2: console: path: /h2 + enabled: true settings: web-allow-others: true - enabled: true - main: - allow-bean-definition-overriding: true servlet: multipart: - max-file-size: ${MAX_FILE_SIZE:5MB} max-request-size: ${MAX_REQUEST_SIZE:5MB} + max-file-size: ${MAX_FILE_SIZE:5MB} + main: + allow-bean-definition-overriding: true + camel: springboot: use-mdc-logging: true + errorHandling: + maximumRedeliveries: 10 + maximumRedeliveryDelay: 60000 + redeliveryDelay: 1000 + kafka: client: config: - reconnections: - max-backoff: - value: 1000 - unit: milliseconds - backoff: - value: 50 - unit: milliseconds connections: + timeout: + value: 60_000 + unit: milliseconds max-idle: - value: 10000 + value: 10_000 unit: milliseconds request-timeout: - value: 5000 + value: 5_000 unit: milliseconds - timeout: - value: 60000 + reconnections: + backoff: + value: 50 unit: milliseconds + max-backoff: + value: 1_000 + unit: milliseconds + eventPortal: - runtimeAgentId: ${EP_RUNTIME_AGENT_ID:13k1j7c913c} - organizationId: ${EP_ORGANIZATION_ID:localrcorg} + runtimeAgentId: ${EP_RUNTIME_AGENT_ID:defaultAgentId} + organizationId: ${EP_ORGANIZATION_ID:defaultOrgId} + topicPrefix: ${EP_TOPIC_PREFIX:sc/ep/runtime} gateway: - id: f0ydyzsr1jp - name: POCCloudManagedEMAEVMR - managed: true - incomingRequestQueueName: ep_core_ema_requests_fakedcid + id: gateway + name: evmr1 messaging: - standalone: false + standalone: true rtoSession: false - enableHeartbeats: true - testHeartbeats: true + enableHeartbeats: false + testHeartbeats: false connections: - name: eventPortalGateway - authenticationType: ${EP_GATEWAY_AUTH:basicAuthentication} - msgVpn: ${EP_GATEWAY_MSGVPN:poccloudmanagedemaevmr} - url: ${EP_GATEWAY_URL:tcps://mr-connection-i41xmmlismp.messaging.solace.cloud:55443} + authenticationType: ${EP_GATEWAY_AUTH} + url: ${EP_GATEWAY_URL} + msgVpn: ${EP_GATEWAY_MSGVPN} + trustStoreDir: ${SSL_STORE_DIR} users: - - password: b{w{Z3Xh{0dsp3tbl0Nw6cql - name: messaging1 - clientName: client_13k1j7c913c - username: ${EP_GATEWAY_USERNAME:localrcorg-v6693yiarsp-13k1j7c913c} - topicPrefix: ${EP_TOPIC_PREFIX:sc/ep/runtime} + - name: messaging1 + username: ${EP_GATEWAY_USERNAME} + password: ${EP_GATEWAY_PASSWORD} + clientName: runtime_agent_${EP_RUNTIME_AGENT_ID} # 'client_' + runtimeAgentId + +# Below is an example of how to set up messaging service configuration in the application.yml file. + +#plugins: +# resources: +# # Confluent Schema Registry No Auth example +# - id: someConfluentId +# name: no auth confluent example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# - id2 +# - id3 +# connections: +# - name: myConfluentNoAuth +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# # Confluent Schema Registry Basic Auth example +# - id: someConfluentId +# name: no auth confluent example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# connections: +# - name: myConfluentBasicAuth +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# authentication: +# - protocol: BASIC +# credentials: +# - properties: +# - name: username +# value: ${CONFLUENT_USERNAME} +# - name: password +# value: ${CONFLUENT_PASSWORD} +# source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# # Confluent Schema Registry Basic Auth With SSL example +# - id: someConfluentId +# name: no auth confluent example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# connections: +# - name: myConfluentBasicAuthWithSSL +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# authentication: +# - protocol: BASIC_SSL +# credentials: +# - properties: +# - name: username +# value: ${CONFLUENT_USERNAME} +# - name: password +# value: ${CONFLUENT_PASSWORD} +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# # Confluent Schema Registry Basic Auth With mTLS example +# - id: someConfluentId +# name: Basic Auth With mTLS example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# connections: +# - name: myConfluentBasicAuthWithMTLS +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# authentication: +# - protocol: BASIC_MTLS +# credentials: +# - properties: +# - name: username +# value: ${CONFLUENT_USERNAME} +# - name: password +# value: ${CONFLUENT_PASSWORD} +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# - name: ssl.keystore.location +# value: ${KEYSTORE_LOCATION} +# - name: ssl.keystore.password +# value: ${KEYSTORE_PASSWORD} +# - name: ssl.key.password +# value: ${KEY_PASSWORD} +# source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# # Confluent Schema Registry TLS example +# - id: someConfluentId +# name: no auth confluent example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# connections: +# - name: myConfluentTLS +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# authentication: +# - protocol: TLS +# credentials: +# - properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# # Confluent Schema Registry MTLS example +# - id: someConfluentId +# name: no auth confluent example +# type: confluent_schema_registry +# relatedServices: +# - id1 +# connections: +# - name: myConfluentMTLS +# url: ${CONFLUENT_SCHEMA_REGISTRY_URL} +# authentication: +# - protocol: MTLS +# credentials: +# - properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# - name: ssl.keystore.password +# value: ${KEYSTORE_PASSWORD} +# - name: ssl.keystore.location +# value: ${KEYSTORE_LOCATION} +# - name: ssl.key.password +# value: ${KEY_PASSWORD} +# source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# # Solace example +# - id: solaceDefaultService +# type: SOLACE +# name: staging service +# connections: +# - name: mySolaceServiceSemp +# url: ${SOLACE_SEMP_URL} +# authentication: +# - protocol: SEMP +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: username +# value: ${SOLACE_SEMP_USERNAME} +# - name: password +# value: ${SOLACE_SEMP_PASSWORD} +# properties: +# - name: msgVpn +# value: ${SOLACE_VPN_NAME} +# - name: sempPageSize +# value: 100 +# # MTLS example +# - id: kafkaMTLSServiceExample +# name: mtls kafka cluster example +# type: KAFKA +# connections: +# - name: kafkaMTLSConnection +# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:11091,kafka2:11092} +# authentication: +# - protocol: SSL +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# - name: ssl.keystore.password +# value: ${KEYSTORE_PASSWORD} +# - name: ssl.keystore.location +# value: ${KEYSTORE_LOCATION} +# - name: ssl.key.password +# value: ${KEY_PASSWORD} +# # SASL SCRAM +# - id: kafkaSASLSCRAMServiceExample +# name: sasl scram kafka cluster example +# type: KAFKA +# connections: +# - name: kafkaSASLSCRAMConnection +# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:14091,kafka2:14092} +# authentication: +# - protocol: SASL_SSL +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: ssl.truststore.password +# value: ${TRUSTSTORE_PASSWORD} +# - name: sasl.jaas.config +# value: org.apache.kafka.common.security.scram.ScramLoginModule required username= password=; +# - name: sasl.mechanism +# value: SCRAM-SHA-256 +# # SASL Plain example +# - id: saslplain +# name: saslplain +# type: KAFKA +# connections: +# - name: saslplainconn +# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:9091,kafka2:9092} +# authentication: +# - protocol: SASL_PLAINTEXT +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: sasl.mechanism +# value: PLAIN +# - name: sasl.jaas.config +# value: org.apache.kafka.common.security.plain.PlainLoginModule required username=">" password=""; +# # SASL Plain over SSL +# - id: saslplainssl +# name: saslplainssl +# type: KAFKA +# connections: +# - name: saslplainsslconn +# url: ${KAFKA_BOOTSTRAP_SERVERS:kafka1:13091,kafka2:13092} +# authentication: +# - protocol: SASL_SSL +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: sasl.mechanism +# value: PLAIN +# - name: sasl.jaas.config +# value: org.apache.kafka.common.security.plain.PlainLoginModule required username=">" password=""; +# # AWS IAM Example. +# # NOTE: Remember to set the aws access id and password in the environment or credentials! +# - id: iam +# name: iam +# type: KAFKA +# connections: +# - name: iamConn +# url: ${KAFKA_BOOTSTRAP_SERVERS:awsservers:9098} +# authentication: +# - protocol: SASL_SSL +# credentials: +# - source: ENVIRONMENT_VARIABLE +# operations: +# - name: ALL +# properties: +# - name: ssl.truststore.location +# value: ${TRUSTSTORE_LOCATION} +# - name: security.protocol +# value: SASL_SSL +# - name: sasl.mechanism +# value: AWS_MSK_IAM +# - name: sasl.jaas.config +# value: software.amazon.msk.auth.iam.IAMLoginModule required; +# - name: sasl.client.callback.handler.class +# value: software.amazon.msk.auth.iam.IAMClientCallbackHandler From 43d0bf86289c6a678dd9351e694ff2bbeceb198a Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Wed, 19 Jun 2024 20:05:25 -0400 Subject: [PATCH 05/13] DATAGO-75198 IT tests --- service/application/pom.xml | 6 +- ...ventBrokerAuthenticationConfiguration.java | 4 + .../EventBrokerConnectionConfiguration.java | 10 ++ .../EventBrokerCredentialConfiguration.java | 3 + .../EventBrokerResourceConfiguration.java | 11 +- .../agent/config/ValidationConfiguration.java | 30 ++++ ...ResourceConfigurationToEventConverter.java | 16 +- .../CommandMessageProcessor.java | 12 +- ...rceConfigurationToEventConverterTests.java | 169 ++++++++++++++++++ .../PersistentMessageHandlerTests.java | 37 ++-- .../CommandMessageProcessorTests.java | 77 ++++++++ ...namicResourceConfigurationHelperTests.java | 62 +++++++ .../EventBrokerResourceConfigTestHelper.java | 41 +++++ 13 files changed, 448 insertions(+), 30 deletions(-) create mode 100644 service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/ValidationConfiguration.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverterTests.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessorTests.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/EventBrokerResourceConfigTestHelper.java diff --git a/service/application/pom.xml b/service/application/pom.xml index 7a022aba7..8abbffbab 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -97,6 +97,10 @@ org.springframework.boot spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-validation + org.springframework.security spring-security-rsa @@ -213,7 +217,7 @@ org.hibernate hibernate-validator - 6.2.0.Final + 8.0.1.Final junit diff --git a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerAuthenticationConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerAuthenticationConfiguration.java index 5a2848d5b..ffe0dc903 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerAuthenticationConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerAuthenticationConfiguration.java @@ -1,11 +1,15 @@ package com.solace.maas.ep.common.model; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Data; @Data public class EventBrokerAuthenticationConfiguration { private String type; private String protocol; + @NotNull + @Valid private EventBrokerCredentialConfiguration credential; } \ No newline at end of file diff --git a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerConnectionConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerConnectionConfiguration.java index ca975816c..ad60c3f66 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerConnectionConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerConnectionConfiguration.java @@ -1,13 +1,23 @@ package com.solace.maas.ep.common.model; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; @Data public class EventBrokerConnectionConfiguration { + + @NotBlank private String msgVpn; + private String sempPageSize; + @NotNull + @Valid private EventBrokerAuthenticationConfiguration authentication; + @NotBlank private String name; + @NotBlank private String url; } \ No newline at end of file diff --git a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerCredentialConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerCredentialConfiguration.java index d1647eaf3..6666e0cf9 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerCredentialConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerCredentialConfiguration.java @@ -1,9 +1,12 @@ package com.solace.maas.ep.common.model; +import jakarta.validation.constraints.NotBlank; import lombok.Data; @Data public class EventBrokerCredentialConfiguration { + @NotBlank private String userName; + @NotBlank private String password; } \ No newline at end of file diff --git a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerResourceConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerResourceConfiguration.java index 57035f428..c516fe7ee 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerResourceConfiguration.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/model/EventBrokerResourceConfiguration.java @@ -1,14 +1,21 @@ package com.solace.maas.ep.common.model; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import lombok.Data; import java.util.List; @Data public class EventBrokerResourceConfiguration extends ResourceConfiguration { + @NotBlank private String id; - private String brokerType; + @NotBlank private String name; - private List connections; + @NotEmpty + private List<@Valid EventBrokerConnectionConfiguration> connections; + @NotNull private ResourceConfigurationType resourceConfigurationType; } \ No newline at end of file diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/ValidationConfiguration.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/ValidationConfiguration.java new file mode 100644 index 000000000..481fa1fa4 --- /dev/null +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/config/ValidationConfiguration.java @@ -0,0 +1,30 @@ +package com.solace.maas.ep.event.management.agent.config; + +import jakarta.validation.Validator; +import org.springframework.boot.validation.MessageInterpolatorFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; +import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; + +@Configuration +public class ValidationConfiguration { + + @Bean + public static LocalValidatorFactoryBean defaultValidator() { + LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean(); + MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory(); + factoryBean.setMessageInterpolator(interpolatorFactory.getObject()); + return factoryBean; + } + + @Bean + public static MethodValidationPostProcessor methodValidationPostProcessor(Environment environment, Validator validator) { + MethodValidationPostProcessor processor = new MethodValidationPostProcessor(); + boolean proxyTargetClass = environment.getProperty("spring.aop.proxy-target-class", Boolean.class, true); + processor.setProxyTargetClass(proxyTargetClass); + processor.setValidator(validator); + return processor; + } +} \ No newline at end of file diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java index f726c403d..8b8255134 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java @@ -10,17 +10,21 @@ import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.ConnectionDetailsEvent; import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.CredentialDetailsEvent; import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.EventProperty; +import jakarta.validation.Valid; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import java.util.List; import java.util.Objects; @Service +@Validated public class SolaceResourceConfigurationToEventConverter { - public MessagingServiceEvent mapToMessagingServiceEvent(EventBrokerResourceConfiguration eventBrokerResource) { - Objects.requireNonNull(eventBrokerResource); + + public MessagingServiceEvent mapToMessagingServiceEvent(@Valid EventBrokerResourceConfiguration eventBrokerResource) { + Objects.requireNonNull(eventBrokerResource, "eventBrokerResource cannot be null."); MessagingServiceEvent serviceEvent = new MessagingServiceEvent(); - serviceEvent.setMessagingServiceType(eventBrokerResource.getBrokerType()); serviceEvent.setName(eventBrokerResource.getName()); serviceEvent.setId(eventBrokerResource.getId()); serviceEvent.setMessagingServiceType(eventBrokerResource.getResourceConfigurationType().name()); @@ -34,7 +38,7 @@ public MessagingServiceEvent mapToMessagingServiceEvent(EventBrokerResourceConfi connectionDetailsEvent.setProperties(List.of( EventProperty.builder() .name("sempPageSize") - .value(connectionDetail.getSempPageSize()) + .value(StringUtils.isEmpty(connectionDetail.getSempPageSize()) ? "100" : connectionDetail.getSempPageSize()) .build(), EventProperty.builder() .name("msgVpn") @@ -44,11 +48,11 @@ public MessagingServiceEvent mapToMessagingServiceEvent(EventBrokerResourceConfi ); EventBrokerAuthenticationConfiguration authentication = connectionDetail.getAuthentication(); AuthenticationDetailsEvent authEvent = new AuthenticationDetailsEvent(); - authEvent.setProtocol(authentication.getProtocol()); + authEvent.setProtocol(StringUtils.isEmpty(authentication.getProtocol()) ? "semp" : authentication.getProtocol()); authEvent.setProperties(List.of( EventProperty.builder() .name("type") - .value(authentication.getType()) + .value(StringUtils.isEmpty(authentication.getType()) ? "basicAuthentication" : authentication.getType()) .build() )); diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java index aac54049f..8a9e30fe1 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessor.java @@ -1,10 +1,9 @@ package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; -import com.fasterxml.jackson.databind.ObjectMapper; import com.solace.maas.ep.common.messages.CommandMessage; import com.solace.maas.ep.event.management.agent.command.CommandManager; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @@ -17,8 +16,6 @@ public class CommandMessageProcessor implements MessageProcessor private final DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; - @Autowired - private ObjectMapper objectMapper; public CommandMessageProcessor(CommandManager commandManager, DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper) { this.commandManager = commandManager; @@ -27,12 +24,9 @@ public CommandMessageProcessor(CommandManager commandManager, @Override public void processMessage(CommandMessage message) { - try{ - System.out.println(objectMapper.writeValueAsString(message)); - } catch (Exception e){ - + if (CollectionUtils.isNotEmpty(message.getResources())) { + dynamicResourceConfigurationHelper.loadSolaceBrokerResourceConfigurations(message.getResources()); } - dynamicResourceConfigurationHelper.loadSolaceBrokerResourceConfigurations(message.getResources()); commandManager.execute(message); } diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverterTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverterTests.java new file mode 100644 index 000000000..65a067cb7 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverterTests.java @@ -0,0 +1,169 @@ +package com.solace.maas.ep.event.management.agent.service; + +import com.solace.maas.ep.common.model.EventBrokerAuthenticationConfiguration; +import com.solace.maas.ep.common.model.EventBrokerConnectionConfiguration; +import com.solace.maas.ep.common.model.EventBrokerCredentialConfiguration; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +import com.solace.maas.ep.event.management.agent.TestConfig; +import com.solace.maas.ep.event.management.agent.event.MessagingServiceEvent; +import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.AuthenticationDetailsEvent; +import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.ConnectionDetailsEvent; +import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.CredentialDetailsEvent; +import com.solace.maas.ep.event.management.agent.plugin.messagingService.event.EventProperty; +import jakarta.validation.ConstraintViolationException; +import org.junit.Assert; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + + +@ActiveProfiles("TEST") +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) +class SolaceResourceConfigurationToEventConverterTests { + + private static final String PROTOCOL_SEMP = "semp"; + private static final String BASIC_AUTHENTICATION = "basicAuthentication"; + @Autowired + private SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter; + + + @Test + void testMapToMessagingServiceEvent() { + + EventBrokerResourceConfiguration resourceConfiguration = buildResourceConfiguration(); + EventBrokerConnectionConfiguration connection = buildConnectionConfiguration(); + EventBrokerAuthenticationConfiguration auth = new EventBrokerAuthenticationConfiguration(); + EventBrokerCredentialConfiguration cred = new EventBrokerCredentialConfiguration(); + cred.setUserName("someUserName"); + cred.setPassword("somePass"); + auth.setCredential(cred); + connection.setAuthentication(auth); + resourceConfiguration.setConnections(List.of(connection)); + MessagingServiceEvent mappedEvent = solaceResourceConfigurationToEventConverter.mapToMessagingServiceEvent(resourceConfiguration); + + assertThat(mappedEvent.getId()).isEqualTo(resourceConfiguration.getId()); + assertThat(mappedEvent.getName()).isEqualTo(resourceConfiguration.getName()); + assertThat(mappedEvent.getMessagingServiceType()).isEqualTo(resourceConfiguration.getResourceConfigurationType().name()); + + List connections = mappedEvent.getConnectionDetails(); + assertThat(connections).hasSize(1); + ConnectionDetailsEvent connectionDetails = connections.get(0); + assertThat(connectionDetails.getName()).isEqualTo(resourceConfiguration.getName()); + assertThat(connectionDetails.getUrl()).isEqualTo(connection.getUrl()); + + assertThat(connectionDetails.getProperties()).containsExactly(EventProperty.builder().name("sempPageSize").value("100").build(), + EventProperty.builder().name("msgVpn").value(connection.getMsgVpn()).build()); + + assertThat(connectionDetails.getAuthenticationDetails()).hasSize(1); + AuthenticationDetailsEvent authenticationDetailsEvent = connectionDetails.getAuthenticationDetails().get(0); + assertThat(authenticationDetailsEvent.getProtocol()).isEqualTo(PROTOCOL_SEMP); + assertThat(authenticationDetailsEvent.getProperties()) + .containsExactlyInAnyOrder(EventProperty.builder().name("type").value(BASIC_AUTHENTICATION).build() + + ); + + assertThat(authenticationDetailsEvent.getCredentials()).hasSize(1); + CredentialDetailsEvent credentialDetailsEvent = authenticationDetailsEvent.getCredentials().get(0); + assertThat(credentialDetailsEvent.getProperties()) + .containsExactlyInAnyOrder( + EventProperty.builder().name("username").value(cred.getUserName()).build(), + EventProperty.builder().name("password").value(cred.getPassword()).build() + + ); + + + } + + @Nested + class BeanValidations { + @Test + void nullInputFailsValidationCheck() { + NullPointerException thrown = Assert.assertThrows(NullPointerException.class, + () -> solaceResourceConfigurationToEventConverter.mapToMessagingServiceEvent(null)); + assertThat(thrown.getMessage()).isEqualTo("eventBrokerResource cannot be null."); + } + + + @Test + void beanValidationFailsIfBrokerResourceConfigurationIsInvalid() { + EventBrokerResourceConfiguration invalidResource = buildResourceConfiguration(); + invalidResource.setId(null); + invalidResource.setName(null); + invalidResource.setConnections(List.of()); + invalidResource.setResourceConfigurationType(ResourceConfigurationType.SOLACE); + + validateConstraintViolationException(invalidResource, Set.of("mapToMessagingServiceEvent.eventBrokerResource.name: must not be blank", + "mapToMessagingServiceEvent.eventBrokerResource.id: must not be blank", "mapToMessagingServiceEvent.eventBrokerResource.connections: must" + + " not be empty")); + } + + @Test + void beanValidationFailsIfConnectionConfigurationIsInvalid() { + EventBrokerResourceConfiguration resourceWithInvalidConnection = buildResourceConfiguration(); + EventBrokerConnectionConfiguration connectionConfiguration = new EventBrokerConnectionConfiguration(); + resourceWithInvalidConnection.setConnections(List.of(connectionConfiguration)); + + validateConstraintViolationException(resourceWithInvalidConnection, Set.of("mapToMessagingServiceEvent.eventBrokerResource.connections[0].name: " + + "must not be blank", "mapToMessagingServiceEvent.eventBrokerResource.connections[0].msgVpn: must not be blank", + "mapToMessagingServiceEvent.eventBrokerResource.connections[0].authentication: must not be null", "mapToMessagingServiceEvent" + + ".eventBrokerResource.connections[0].url: must not be blank")); + + } + + @Test + void beanValidationFailsIfCredentialConfigurationIsInvalid() { + EventBrokerResourceConfiguration resourceWithInvalidCredentials = buildResourceConfiguration(); + EventBrokerConnectionConfiguration connection2 = buildConnectionConfiguration(); + EventBrokerAuthenticationConfiguration auth = new EventBrokerAuthenticationConfiguration(); + EventBrokerCredentialConfiguration cred = new EventBrokerCredentialConfiguration(); + auth.setCredential(cred); + connection2.setAuthentication(auth); + resourceWithInvalidCredentials.setConnections(List.of(connection2)); + + + validateConstraintViolationException(resourceWithInvalidCredentials, Set.of("mapToMessagingServiceEvent.eventBrokerResource.connections[0]" + + ".authentication.credential.password: must not be blank", "mapToMessagingServiceEvent.eventBrokerResource.connections[0].authentication" + + ".credential.userName: must not be blank")); + } + + } + + private static EventBrokerConnectionConfiguration buildConnectionConfiguration() { + EventBrokerConnectionConfiguration connection2 = new EventBrokerConnectionConfiguration(); + connection2.setMsgVpn("someVpn"); + connection2.setUrl("https://localhost:8080/test-messaging-service"); + connection2.setName("someName"); + return connection2; + } + + + private static EventBrokerResourceConfiguration buildResourceConfiguration() { + EventBrokerResourceConfiguration resourceWithInvalidConnection = new EventBrokerResourceConfiguration(); + resourceWithInvalidConnection.setName("someFakeName"); + resourceWithInvalidConnection.setResourceConfigurationType(ResourceConfigurationType.SOLACE); + resourceWithInvalidConnection.setId("someSvcId"); + return resourceWithInvalidConnection; + } + + + private void validateConstraintViolationException(EventBrokerResourceConfiguration resource, + Set expectedViolations) { + ConstraintViolationException thrown = Assert.assertThrows(ConstraintViolationException.class, + () -> solaceResourceConfigurationToEventConverter.mapToMessagingServiceEvent(resource)); + + assertThat(thrown.getConstraintViolations() + .stream().map( + violation -> violation.getPropertyPath().toString() + ": " + violation.getMessage() + ).collect(Collectors.toSet())) + .containsExactlyInAnyOrderElementsOf(expectedViolations); + } +} diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/PersistentMessageHandlerTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/PersistentMessageHandlerTests.java index 9ae26c3cb..a3e3d32a4 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/PersistentMessageHandlerTests.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/PersistentMessageHandlerTests.java @@ -1,5 +1,8 @@ package com.solace.maas.ep.event.management.agent.subscriber; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.solace.maas.ep.common.messages.CommandMessage; @@ -18,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -30,7 +34,6 @@ import static com.solace.maas.ep.common.model.ScanType.SOLACE_ALL; import static com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType.generic; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -70,8 +73,14 @@ public class PersistentMessageHandlerTests { private InboundMessage inboundMessage; + private ListAppender listAppender; + @BeforeEach void setup() { + Logger scanLogger = (Logger) LoggerFactory.getLogger(SolacePersistentMessageHandler.class); + listAppender = new ListAppender<>(); + listAppender.start(); + scanLogger.addAppender(listAppender); inboundMessage = mock(InboundMessage.class); } @@ -141,14 +150,13 @@ void testUnsupportedMessageHandling() { when(inboundMessage.getProperty(MOPConstants.MOP_MSG_META_DECODER)).thenReturn( ScanDataImportMessage.class.getCanonicalName() ); - - Exception e = assertThrows(IllegalArgumentException.class, () -> solacePersistentMessageHandler.onMessage(inboundMessage)); - - assertThat(e.getMessage()).isEqualTo("java.lang.UnsupportedOperationException: Could not find message processor for message of class " - + ScanDataImportMessage.class.getCanonicalName()); - - // message will be acked + solacePersistentMessageHandler.onMessage(inboundMessage); + List logs = listAppender.list; + assertThat(logs.get(logs.size() - 1).getFormattedMessage()).isEqualTo("Unsupported message and/or processor encountered. Skipping processing"); verify(solacePersistentMessageHandler.getPersistentMessageReceiver(), times(1)).ack(inboundMessage); + //unsupported message type, so we don't have an appropriate processor to handle the failure scenario + verify(scanCommandMessageProcessor, times(0)).onFailure(any(), any()); + verify(commandMessageProcessor, times(0)).onFailure(any(), any()); } @@ -164,12 +172,17 @@ void testMessageAcknowledgementWhenProcessingError() { ScanCommandMessage.class.getCanonicalName() ); - Exception e = assertThrows(IllegalArgumentException.class, () -> solacePersistentMessageHandler.onMessage(inboundMessage)); + solacePersistentMessageHandler.onMessage(inboundMessage); + List logs = listAppender.list; + assertThat(logs.get(logs.size() - 1).getFormattedMessage()) + .isEqualTo("Error while processing inbound message from queue for mopMessageSubclass: " + ScanCommandMessage.class.getCanonicalName()); + verify(solacePersistentMessageHandler.getPersistentMessageReceiver(), times(1)).ack(inboundMessage); - assertThat(e.getMessage()).isEqualTo("java.lang.IllegalArgumentException: Test processing error msg"); + // scan command message processor MUST handle the exception + verify(scanCommandMessageProcessor, times(1)).onFailure(any(), any()); - // message will be acked - verify(solacePersistentMessageHandler.getPersistentMessageReceiver(), times(1)).ack(inboundMessage); + //commandMessageProcessor MUST do nothing (not a config push command) + verify(commandMessageProcessor, times(0)).onFailure(any(), any()); } diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessorTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessorTests.java new file mode 100644 index 000000000..c88879c60 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/CommandMessageProcessorTests.java @@ -0,0 +1,77 @@ +package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; + +import com.solace.maas.ep.common.messages.CommandMessage; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +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.plugin.command.model.CommandBundle; +import com.solace.maas.ep.event.management.agent.plugin.command.model.ExecutionType; +import com.solace.maas.ep.event.management.agent.plugin.mop.MOPSvcType; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; + +import static com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType.generic; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) +@ActiveProfiles("TEST") +class CommandMessageProcessorTests { + + @MockBean + private CommandManager commandManager; + @SpyBean + private CommandMessageProcessor commandMessageProcessor; + + @MockBean + private DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; + + @Test + void processMessageWithoutResourceConfig() { + + CommandMessage messageWithoutResources = buildCommandMessage(List.of()); + commandMessageProcessor.processMessage(messageWithoutResources); + verifyNoInteractions(dynamicResourceConfigurationHelper); + verify(commandManager, times(1)).execute(any()); + + } + + @Test + void processMessageWithResourceConfig() { + CommandMessage messageWithoutResources = buildCommandMessage(List.of( + EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)) + ); + commandMessageProcessor.processMessage(messageWithoutResources); + verify(dynamicResourceConfigurationHelper, times(1)).loadSolaceBrokerResourceConfigurations(any()); + verify(commandManager, times(1)).execute(any()); + } + + private CommandMessage buildCommandMessage(List resources) { + CommandMessage message = new CommandMessage(); + message.setOrigType(MOPSvcType.maasEventMgmt); + message.withMessageType(generic); + message.setContext("abc"); + message.setServiceId("someId"); + message.setActorId("myActorId"); + message.setResources(resources); + message.setOrgId("someOrgId"); + message.setTraceId("myTraceId"); + message.setCommandCorrelationId("someId"); + message.setCommandBundles(List.of( + CommandBundle.builder() + .executionType(ExecutionType.serial) + .exitOnFailure(true) + .commands(List.of()) + .build())); + + return message; + } +} diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java new file mode 100644 index 000000000..d31290903 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java @@ -0,0 +1,62 @@ +package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; + +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +import com.solace.maas.ep.event.management.agent.TestConfig; +import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl; +import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anySet; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) +@ActiveProfiles("TEST") +class DynamicResourceConfigurationHelperTests { + + @SpyBean + private SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter; + + @SpyBean + private MessagingServiceDelegateServiceImpl messagingServiceDelegateServiceImpl; + + @SpyBean + private DynamicResourceConfigurationHelper helper; + + + @Test + void emptyResourceListResultsInNoOperation() { + helper.loadSolaceBrokerResourceConfigurations(List.of()); + Mockito.verifyNoInteractions(messagingServiceDelegateServiceImpl); + Mockito.verifyNoInteractions(solaceResourceConfigurationToEventConverter); + } + + + @Test + void testLoadSolaceBrokerResourceConfigurations() { + + List resources = List.of( + EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE) + ); + doNothing().when(messagingServiceDelegateServiceImpl).deleteMessagingServiceByIds(anySet()); + helper.loadSolaceBrokerResourceConfigurations(resources); + verify(messagingServiceDelegateServiceImpl, times(1)).deleteMessagingServiceByIds( + resources.stream() + .map(EventBrokerResourceConfiguration::getId) + .collect(Collectors.toSet()) + ); + verify(messagingServiceDelegateServiceImpl, times(1)).addMessagingServices(any()); + } + + +} diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/EventBrokerResourceConfigTestHelper.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/EventBrokerResourceConfigTestHelper.java new file mode 100644 index 000000000..e4b57b4e9 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/EventBrokerResourceConfigTestHelper.java @@ -0,0 +1,41 @@ +package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; + +import com.solace.maas.ep.common.model.EventBrokerAuthenticationConfiguration; +import com.solace.maas.ep.common.model.EventBrokerConnectionConfiguration; +import com.solace.maas.ep.common.model.EventBrokerCredentialConfiguration; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +import org.apache.commons.lang3.RandomStringUtils; + +import java.util.List; + +public final class EventBrokerResourceConfigTestHelper { + + private EventBrokerResourceConfigTestHelper() { + throw new UnsupportedOperationException("Instantiation not allowed"); + + } + + public static EventBrokerResourceConfiguration buildResourceConfiguration(ResourceConfigurationType resourceConfigurationType) { + EventBrokerResourceConfiguration resourceConfiguration = new EventBrokerResourceConfiguration(); + resourceConfiguration.setId(RandomStringUtils.randomAlphabetic(11)); + resourceConfiguration.setName(RandomStringUtils.randomAlphabetic(5)); + resourceConfiguration.setResourceConfigurationType(resourceConfigurationType); + + EventBrokerConnectionConfiguration connection = new EventBrokerConnectionConfiguration(); + connection.setUrl("https://localhost:8080"); + connection.setMsgVpn("myVpn"); + connection.setName(resourceConfiguration.getName()); + + EventBrokerAuthenticationConfiguration auth = new EventBrokerAuthenticationConfiguration(); + + EventBrokerCredentialConfiguration cred = new EventBrokerCredentialConfiguration(); + cred.setUserName(RandomStringUtils.randomAlphabetic(11)); + cred.setPassword(RandomStringUtils.randomAlphabetic(11)); + auth.setCredential(cred); + connection.setAuthentication(auth); + resourceConfiguration.setConnections(List.of(connection)); + return resourceConfiguration; + } + +} From eb7f46f2f75fdff42ee38b4af634e7820f3f718d Mon Sep 17 00:00:00 2001 From: moodiRealist <40175386+moodiRealist@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:01:24 -0400 Subject: [PATCH 06/13] [DATAGO-78507] fix vulnerability --- service/application/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/application/pom.xml b/service/application/pom.xml index 7a022aba7..75ba92bfa 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -15,7 +15,7 @@ 3.2.5 2.0 - 1.1.1 + 1.1.3 3.0.10 3.5.0 2.16.1 From 1c4e2be7cdac5cda2edb3ef48ccde0d20292d926 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Mon, 24 Jun 2024 15:39:13 +0000 Subject: [PATCH 07/13] [ci skip] prepare release v1.6.8 --- service/application/pom.xml | 16 ++++++++-------- service/confluent-schema-registry-plugin/pom.xml | 4 ++-- service/kafka-plugin/pom.xml | 4 ++-- service/local-storage-plugin/pom.xml | 4 ++-- service/plugin/pom.xml | 4 ++-- service/pom.xml | 4 ++-- service/rabbitmq-plugin/pom.xml | 4 ++-- service/solace-plugin/pom.xml | 4 ++-- service/terraform-plugin/pom.xml | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/service/application/pom.xml b/service/application/pom.xml index 75ba92bfa..5d7ef33b3 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -4,11 +4,11 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8-SNAPSHOT + 1.6.8 .. event-management-agent - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Application Solace Event Management Agent - Application @@ -223,32 +223,32 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 com.solace.maas.plugin.kafka kafka-plugin - 1.6.8-SNAPSHOT + 1.6.8 com.solace.maas.plugin.solace solace-plugin - 1.6.8-SNAPSHOT + 1.6.8 com.solace.maas.plugin.localstorage local-storage-plugin - 1.6.8-SNAPSHOT + 1.6.8 com.solace.maas.plugin.confluent-schema-registry confluent-schema-registry-plugin - 1.6.8-SNAPSHOT + 1.6.8 com.solace.maas.plugin.terraform terraform-plugin - 1.6.8-SNAPSHOT + 1.6.8 diff --git a/service/confluent-schema-registry-plugin/pom.xml b/service/confluent-schema-registry-plugin/pom.xml index f00df879e..60e4bf3fe 100644 --- a/service/confluent-schema-registry-plugin/pom.xml +++ b/service/confluent-schema-registry-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.confluent-schema-registry confluent-schema-registry-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Confluent Schema Registry Plugin Solace Event Management Agent - Confluent Schema Registry Plugin @@ -22,7 +22,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 org.springframework.boot diff --git a/service/kafka-plugin/pom.xml b/service/kafka-plugin/pom.xml index bd44fc476..703420a1e 100644 --- a/service/kafka-plugin/pom.xml +++ b/service/kafka-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.kafka kafka-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Kafka Plugin Solace Event Management Agent - Kafka Plugin @@ -81,7 +81,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 org.junit.jupiter diff --git a/service/local-storage-plugin/pom.xml b/service/local-storage-plugin/pom.xml index 927ef5133..40de704f7 100644 --- a/service/local-storage-plugin/pom.xml +++ b/service/local-storage-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.localstorage local-storage-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Local Storage Plugin Solace Event Management Agent - Local Storage Plugin @@ -115,7 +115,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 org.json diff --git a/service/plugin/pom.xml b/service/plugin/pom.xml index 4cc17d6f0..f4ced0005 100644 --- a/service/plugin/pom.xml +++ b/service/plugin/pom.xml @@ -4,12 +4,12 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8-SNAPSHOT + 1.6.8 .. com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Plugin Solace Event Management Agent - Plugin diff --git a/service/pom.xml b/service/pom.xml index 4cd2f0208..8209841f6 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -9,7 +9,7 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8-SNAPSHOT + 1.6.8 pom Solace Event Management Agent Maven Parent Solace Solace Event Management Agent Maven Parent @@ -388,7 +388,7 @@ scm:git:${project.scm.url} scm:git:${project.scm.url} git@github.com:SolaceProducts/event-management-agent.git - HEAD + v1.6.8 diff --git a/service/rabbitmq-plugin/pom.xml b/service/rabbitmq-plugin/pom.xml index d08da3406..d093cd6a0 100644 --- a/service/rabbitmq-plugin/pom.xml +++ b/service/rabbitmq-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.rabbitmq rabbitmq-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - RabbitMQ Plugin Solace Event Management Agent - RabbitMQ Plugin @@ -27,7 +27,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 diff --git a/service/solace-plugin/pom.xml b/service/solace-plugin/pom.xml index cb21a1256..1b259d980 100644 --- a/service/solace-plugin/pom.xml +++ b/service/solace-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.solace solace-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Solace Plugin Solace Event Management Agent - Solace Plugin @@ -91,7 +91,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 org.yaml diff --git a/service/terraform-plugin/pom.xml b/service/terraform-plugin/pom.xml index a66c63ee5..643cc1fc1 100644 --- a/service/terraform-plugin/pom.xml +++ b/service/terraform-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.terraform terraform-plugin - 1.6.8-SNAPSHOT + 1.6.8 jar Solace Event Management Agent - Terraform Plugin Solace Event Management Agent - Terraform Plugin @@ -65,7 +65,7 @@ com.solace.maas plugin - 1.6.8-SNAPSHOT + 1.6.8 org.yaml From 2917be9a405c0817692b6c396afd61e4daa8b938 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Mon, 24 Jun 2024 15:39:15 +0000 Subject: [PATCH 08/13] [ci skip] prepare for next development iteration --- service/application/pom.xml | 16 ++++++++-------- service/confluent-schema-registry-plugin/pom.xml | 4 ++-- service/kafka-plugin/pom.xml | 4 ++-- service/local-storage-plugin/pom.xml | 4 ++-- service/plugin/pom.xml | 4 ++-- service/pom.xml | 4 ++-- service/rabbitmq-plugin/pom.xml | 4 ++-- service/solace-plugin/pom.xml | 4 ++-- service/terraform-plugin/pom.xml | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/service/application/pom.xml b/service/application/pom.xml index 5d7ef33b3..5b9e24866 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -4,11 +4,11 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8 + 1.6.9-SNAPSHOT .. event-management-agent - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Application Solace Event Management Agent - Application @@ -223,32 +223,32 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT com.solace.maas.plugin.kafka kafka-plugin - 1.6.8 + 1.6.9-SNAPSHOT com.solace.maas.plugin.solace solace-plugin - 1.6.8 + 1.6.9-SNAPSHOT com.solace.maas.plugin.localstorage local-storage-plugin - 1.6.8 + 1.6.9-SNAPSHOT com.solace.maas.plugin.confluent-schema-registry confluent-schema-registry-plugin - 1.6.8 + 1.6.9-SNAPSHOT com.solace.maas.plugin.terraform terraform-plugin - 1.6.8 + 1.6.9-SNAPSHOT diff --git a/service/confluent-schema-registry-plugin/pom.xml b/service/confluent-schema-registry-plugin/pom.xml index 60e4bf3fe..008e0d3e5 100644 --- a/service/confluent-schema-registry-plugin/pom.xml +++ b/service/confluent-schema-registry-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.confluent-schema-registry confluent-schema-registry-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Confluent Schema Registry Plugin Solace Event Management Agent - Confluent Schema Registry Plugin @@ -22,7 +22,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT org.springframework.boot diff --git a/service/kafka-plugin/pom.xml b/service/kafka-plugin/pom.xml index 703420a1e..3a16299fa 100644 --- a/service/kafka-plugin/pom.xml +++ b/service/kafka-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.kafka kafka-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Kafka Plugin Solace Event Management Agent - Kafka Plugin @@ -81,7 +81,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT org.junit.jupiter diff --git a/service/local-storage-plugin/pom.xml b/service/local-storage-plugin/pom.xml index 40de704f7..d9e572f06 100644 --- a/service/local-storage-plugin/pom.xml +++ b/service/local-storage-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.localstorage local-storage-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Local Storage Plugin Solace Event Management Agent - Local Storage Plugin @@ -115,7 +115,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT org.json diff --git a/service/plugin/pom.xml b/service/plugin/pom.xml index f4ced0005..bd28e8cba 100644 --- a/service/plugin/pom.xml +++ b/service/plugin/pom.xml @@ -4,12 +4,12 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8 + 1.6.9-SNAPSHOT .. com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Plugin Solace Event Management Agent - Plugin diff --git a/service/pom.xml b/service/pom.xml index 8209841f6..6e59cb9dc 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -9,7 +9,7 @@ com.solace.maas maas-event-management-agent-parent - 1.6.8 + 1.6.9-SNAPSHOT pom Solace Event Management Agent Maven Parent Solace Solace Event Management Agent Maven Parent @@ -388,7 +388,7 @@ scm:git:${project.scm.url} scm:git:${project.scm.url} git@github.com:SolaceProducts/event-management-agent.git - v1.6.8 + HEAD diff --git a/service/rabbitmq-plugin/pom.xml b/service/rabbitmq-plugin/pom.xml index d093cd6a0..e3592efb8 100644 --- a/service/rabbitmq-plugin/pom.xml +++ b/service/rabbitmq-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.rabbitmq rabbitmq-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - RabbitMQ Plugin Solace Event Management Agent - RabbitMQ Plugin @@ -27,7 +27,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT diff --git a/service/solace-plugin/pom.xml b/service/solace-plugin/pom.xml index 1b259d980..a75593efc 100644 --- a/service/solace-plugin/pom.xml +++ b/service/solace-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.solace solace-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Solace Plugin Solace Event Management Agent - Solace Plugin @@ -91,7 +91,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT org.yaml diff --git a/service/terraform-plugin/pom.xml b/service/terraform-plugin/pom.xml index 643cc1fc1..f899a7ac9 100644 --- a/service/terraform-plugin/pom.xml +++ b/service/terraform-plugin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.solace.maas.plugin.terraform terraform-plugin - 1.6.8 + 1.6.9-SNAPSHOT jar Solace Event Management Agent - Terraform Plugin Solace Event Management Agent - Terraform Plugin @@ -65,7 +65,7 @@ com.solace.maas plugin - 1.6.8 + 1.6.9-SNAPSHOT org.yaml From 91b9cd649f52b9f7e399320a98ba88e2d08a7379 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Wed, 26 Jun 2024 12:29:30 -0400 Subject: [PATCH 09/13] DATAGO-75198 bug fix --- .../MessagingServiceDelegateServiceImpl.java | 22 +++++++++++++++---- .../DynamicResourceConfigurationHelper.java | 13 ++--------- ...namicResourceConfigurationHelperTests.java | 11 +--------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java index 83e6fb306..e822e689d 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java @@ -28,6 +28,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static java.util.stream.Collectors.toCollection; + /** * Manages the creation and retrieval of Messaging Service information. */ @@ -75,12 +77,24 @@ public Iterable addMessagingServices(List messagingServiceIds) { - if(CollectionUtils.isEmpty(messagingServiceIds)){ - return; + public Iterable upsertMessagingServiceEvents(List messagingServiceEvents) { + if (CollectionUtils.isEmpty(messagingServiceEvents)) { + return List.of(); } - repository.deleteAllById(messagingServiceIds); + List messagingServiceEntities = messagingServiceEvents.stream() + .map(toBeUpserted -> { + MessagingServiceEntity updated = eventToEntityConverter.convert(toBeUpserted); + Optional existing = repository.findById(toBeUpserted.getId()); + if (existing.isPresent()) { + MessagingServiceEntity existingEntity = existing.get(); + updated.setScanEntities(existingEntity.getScanEntities()); + } + return updated; + + }).collect(toCollection(ArrayList::new)); + return repository.saveAll(messagingServiceEntities); } /** diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java index e26ea01a4..c699ad7af 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java @@ -3,15 +3,13 @@ import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; import com.solace.maas.ep.common.model.ResourceConfigurationType; import com.solace.maas.ep.event.management.agent.event.MessagingServiceEvent; -import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter; import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl; +import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.util.List; -import java.util.stream.Collectors; @Component @Slf4j @@ -38,14 +36,7 @@ public void loadSolaceBrokerResourceConfigurations(List log.debug("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.", messagingServiceEntity.getType(), diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java index d31290903..361bb68b8 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelperTests.java @@ -12,11 +12,8 @@ import org.springframework.test.context.ActiveProfiles; import java.util.List; -import java.util.stream.Collectors; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -48,14 +45,8 @@ void testLoadSolaceBrokerResourceConfigurations() { List resources = List.of( EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE) ); - doNothing().when(messagingServiceDelegateServiceImpl).deleteMessagingServiceByIds(anySet()); helper.loadSolaceBrokerResourceConfigurations(resources); - verify(messagingServiceDelegateServiceImpl, times(1)).deleteMessagingServiceByIds( - resources.stream() - .map(EventBrokerResourceConfiguration::getId) - .collect(Collectors.toSet()) - ); - verify(messagingServiceDelegateServiceImpl, times(1)).addMessagingServices(any()); + verify(messagingServiceDelegateServiceImpl, times(1)).upsertMessagingServiceEvents(any()); } From 2ba49c32543738e6809bf93be36a675e9a2e84a5 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Thu, 27 Jun 2024 09:50:12 -0400 Subject: [PATCH 10/13] DATAGO-75198 pr comments --- .../agent/subscriber/SolacePersistentMessageHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java index 8ae5c055b..ac3c7f8d6 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/SolacePersistentMessageHandler.java @@ -72,7 +72,12 @@ public void onMessage(InboundMessage inboundMessage) { } catch (Exception e) { if (processor != null && message != null) { log.error("Error while processing inbound message from queue for mopMessageSubclass: {}", mopMessageSubclass); - processor.onFailure(e, processor.castToMessageClass(message)); + try { + processor.onFailure(e, processor.castToMessageClass(message)); + } catch (Exception e1) { + log.error("error while handling message processing failure for mopMessageSubclass: {}", mopMessageSubclass, e); + } + } else { log.error("Unsupported message and/or processor encountered. Skipping processing", e); } From 8183c186003740da8f9946e46f400e7cfc0b45f3 Mon Sep 17 00:00:00 2001 From: Greg Meldrum Date: Fri, 28 Jun 2024 10:38:31 -0400 Subject: [PATCH 11/13] DATAGO-78232: Add new spring variable to override the use of user.home (#189) --- .../application/src/main/resources/command-configs.properties | 2 +- .../plugin/terraform/configuration/TerraformProperties.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/application/src/main/resources/command-configs.properties b/service/application/src/main/resources/command-configs.properties index 952145351..c10c875c5 100644 --- a/service/application/src/main/resources/command-configs.properties +++ b/service/application/src/main/resources/command-configs.properties @@ -1 +1 @@ -COMMAND_PATH=${user.home}${file.separator}commands \ No newline at end of file +COMMAND_PATH=${app.commandroot:-${user.home}}${file.separator}commands diff --git a/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/configuration/TerraformProperties.java b/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/configuration/TerraformProperties.java index c285e4746..8cf7f52d0 100644 --- a/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/configuration/TerraformProperties.java +++ b/service/terraform-plugin/src/main/java/com/solace/maas/ep/event/management/agent/plugin/terraform/configuration/TerraformProperties.java @@ -7,6 +7,6 @@ @Service @Data public class TerraformProperties { - @Value("${COMMAND_PATH:${user.home}${file.separator}tfcommands}") + @Value("${app.commandroot:${user.home}}${file.separator}tfcommands") private String workingDirectoryRoot; } From 5ac553435da572fb038114d153904f6221e353ba Mon Sep 17 00:00:00 2001 From: Jochen Traunecker Date: Fri, 28 Jun 2024 17:09:52 +0200 Subject: [PATCH 12/13] DATAGO-77217 EMA dynamic configuration for scan jobs (#186) --- .gitignore | 3 + .../common/messages/ScanCommandMessage.java | 18 ++++- .../agent/scanManager/ScanManager.java | 35 +++++++++- .../ScanCommandMessageProcessor.java | 12 +++- .../messages/ScanCommandMessageTests.java | 63 ++++++++++++++++++ .../ScanManagerHandleErrorTest.java | 66 +++++++++++++++++++ .../agent/scanManager/ScanManagerTest.java | 3 + .../ScanCommandMessageProcessorTests.java | 63 ++++++++++++++++++ 8 files changed, 258 insertions(+), 5 deletions(-) create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/common/messages/ScanCommandMessageTests.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerHandleErrorTest.java create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessorTests.java diff --git a/.gitignore b/.gitignore index e9b873869..9e0b02207 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ hs_err_pid* **/application-DEV.yml application.properties application.yml +**/application-*-local.yml + .idea .DS_Store @@ -46,3 +48,4 @@ application-mysql-*.yml .env *dependency-reduced-pom.xml + diff --git a/service/application/src/main/java/com/solace/maas/ep/common/messages/ScanCommandMessage.java b/service/application/src/main/java/com/solace/maas/ep/common/messages/ScanCommandMessage.java index d650210bf..cfb17c9f0 100644 --- a/service/application/src/main/java/com/solace/maas/ep/common/messages/ScanCommandMessage.java +++ b/service/application/src/main/java/com/solace/maas/ep/common/messages/ScanCommandMessage.java @@ -1,5 +1,7 @@ package com.solace.maas.ep.common.messages; +import com.solace.maas.ep.common.model.CommandMessageWithResources; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; import com.solace.maas.ep.common.model.ScanDestination; import com.solace.maas.ep.common.model.ScanType; import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessage; @@ -11,12 +13,13 @@ import java.util.List; @Data -public class ScanCommandMessage extends MOPMessage { +public class ScanCommandMessage extends MOPMessage implements CommandMessageWithResources { private String messagingServiceId; private String scanId; private List scanTypes; private List destinations; + private List resources; public ScanCommandMessage() { super(); @@ -25,7 +28,8 @@ public ScanCommandMessage() { public ScanCommandMessage(String messagingServiceId, String scanId, List scanTypes, - List destinations) { + List destinations, + List resources) { super(); withMessageType(MOPMessageType.generic) .withProtocol(MOPProtocol.scanDataControl) @@ -35,8 +39,18 @@ public ScanCommandMessage(String messagingServiceId, this.scanId = scanId; this.scanTypes = scanTypes; this.destinations = destinations; + this.resources = resources; } + public ScanCommandMessage(String messagingServiceId, + String scanId, + List scanTypes, + List destinations) { + this(messagingServiceId, scanId, scanTypes, destinations, null); + } + + + @Override public String toLog() { return null; diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManager.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManager.java index 4f5225c21..93e5b01e6 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManager.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManager.java @@ -1,10 +1,15 @@ package com.solace.maas.ep.event.management.agent.scanManager; +import com.solace.maas.ep.common.messages.ScanCommandMessage; +import com.solace.maas.ep.common.messages.ScanStatusMessage; +import com.solace.maas.ep.common.model.ScanType; import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties; import com.solace.maas.ep.event.management.agent.plugin.constants.RouteConstants; +import com.solace.maas.ep.event.management.agent.plugin.constants.ScanStatus; import com.solace.maas.ep.event.management.agent.plugin.manager.loader.PluginLoader; import com.solace.maas.ep.event.management.agent.plugin.route.RouteBundle; import com.solace.maas.ep.event.management.agent.plugin.route.handler.base.MessagingServiceRouteDelegate; +import com.solace.maas.ep.event.management.agent.publisher.ScanStatusPublisher; import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.MessagingServiceEntity; import com.solace.maas.ep.event.management.agent.scanManager.model.ScanItemBO; import com.solace.maas.ep.event.management.agent.scanManager.model.ScanRequestBO; @@ -25,6 +30,7 @@ import java.util.UUID; import java.util.stream.Collectors; + @Slf4j @Service public class ScanManager { @@ -32,13 +38,19 @@ public class ScanManager { private final MessagingServiceDelegateServiceImpl messagingServiceDelegateService; private final ScanService scanService; private final String runtimeAgentId; + private final String orgId; + private final ScanStatusPublisher scanStatusPublisher; @Autowired public ScanManager(MessagingServiceDelegateServiceImpl messagingServiceDelegateService, - ScanService scanService, EventPortalProperties eventPortalProperties) { + ScanService scanService, + EventPortalProperties eventPortalProperties, + ScanStatusPublisher scanStatusPublisher) { this.messagingServiceDelegateService = messagingServiceDelegateService; this.scanService = scanService; + this.scanStatusPublisher = scanStatusPublisher; runtimeAgentId = eventPortalProperties.getRuntimeAgentId(); + orgId = eventPortalProperties.getOrganizationId(); } public String scan(ScanRequestBO scanRequestBO) { @@ -102,6 +114,27 @@ public String scan(ScanRequestBO scanRequestBO) { return scanService.singleScan(routes, groupId, scanId, traceId, actorId, messagingServiceEntity, runtimeAgentId); } + public void handleError(Exception e, ScanCommandMessage message){ + + List scanTypeNames = message.getScanTypes().stream().map(ScanType::name).toList(); + + ScanStatusMessage response = new ScanStatusMessage( + message.getOrgId(), + message.getScanId(), + MDC.get(RouteConstants.TRACE_ID), + MDC.get(RouteConstants.ACTOR_ID), + ScanStatus.FAILED.name(), + "Scan failed", + scanTypeNames + ); + + Map topicVars = Map.of( + "orgId", orgId, + "runtimeAgentId", runtimeAgentId + ); + scanStatusPublisher.sendOverallScanStatus(response,topicVars); + } + private MessagingServiceEntity retrieveMessagingServiceEntity(String messagingServiceId) { return messagingServiceDelegateService.getMessagingServiceById(messagingServiceId); } diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java index e15f1e4c7..1a61d6529 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessor.java @@ -5,6 +5,7 @@ import com.solace.maas.ep.event.management.agent.scanManager.model.ScanRequestBO; import lombok.extern.slf4j.Slf4j; import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; +import org.apache.commons.collections4.CollectionUtils; import org.slf4j.MDC; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @@ -20,9 +21,12 @@ public class ScanCommandMessageProcessor implements MessageProcessor entityTypes.add(scanType.name())); if (message.getDestinations() == null) { @@ -75,6 +83,6 @@ public ScanCommandMessage castToMessageClass(Object message) { @Override public void onFailure(Exception e, ScanCommandMessage message) { - log.debug("Requires implementation"); + scanManager.handleError(e,message); } } diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/common/messages/ScanCommandMessageTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/common/messages/ScanCommandMessageTests.java new file mode 100644 index 000000000..abe50185b --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/common/messages/ScanCommandMessageTests.java @@ -0,0 +1,63 @@ +package com.solace.maas.ep.event.management.agent.common.messages; + +import com.solace.maas.ep.common.messages.ScanCommandMessage; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +import com.solace.maas.ep.common.model.ScanDestination; +import com.solace.maas.ep.common.model.ScanType; +import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType; +import com.solace.maas.ep.event.management.agent.plugin.mop.MOPProtocol; +import com.solace.maas.ep.event.management.agent.plugin.mop.MOPUHFlag; +import com.solace.maas.ep.event.management.agent.subscriber.messageProcessors.EventBrokerResourceConfigTestHelper; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + + +public class ScanCommandMessageTests { + + private void assertMopMessageProperties(ScanCommandMessage scanCommandMessage) { + assertNotNull(scanCommandMessage); + assertEquals(MOPMessageType.generic, scanCommandMessage.getMopMsgType()); + assertEquals(MOPProtocol.scanDataControl, scanCommandMessage.getMopProtocol()); + assertEquals("1", scanCommandMessage.getMopVer()); + assertEquals(MOPUHFlag.ignore, scanCommandMessage.getMsgUh()); + } + + @Test + void instantiateScanCommandMessage() { + ScanCommandMessage scanCommandMessage = new ScanCommandMessage( + "messagingServiceId1", + "scanId1", + List.of(ScanType.SOLACE_ALL), + List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER) + ); + assertMopMessageProperties(scanCommandMessage); + assertEquals("messagingServiceId1", scanCommandMessage.getMessagingServiceId()); + assertEquals("scanId1", scanCommandMessage.getScanId()); + assertEquals(List.of(ScanType.SOLACE_ALL), scanCommandMessage.getScanTypes()); + assertEquals(List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), scanCommandMessage.getDestinations()); + assertNull(scanCommandMessage.getResources()); + } + + @Test + void instantiateScanCommandMessageWithResources() { + ScanCommandMessage scanCommandMessage = new ScanCommandMessage( + "messagingServiceId1", + "scanId1", + List.of(ScanType.SOLACE_ALL), + List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), + List.of(EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)) + ); + assertMopMessageProperties(scanCommandMessage); + assertEquals("messagingServiceId1", scanCommandMessage.getMessagingServiceId()); + assertEquals("scanId1", scanCommandMessage.getScanId()); + assertEquals(List.of(ScanType.SOLACE_ALL), scanCommandMessage.getScanTypes()); + assertEquals(List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), scanCommandMessage.getDestinations()); + assertNotNull(scanCommandMessage.getResources()); + assertEquals(1, scanCommandMessage.getResources().size()); + } +} diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerHandleErrorTest.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerHandleErrorTest.java new file mode 100644 index 000000000..33e7ee641 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerHandleErrorTest.java @@ -0,0 +1,66 @@ +package com.solace.maas.ep.event.management.agent.scanManager; + +import com.solace.maas.ep.common.messages.ScanCommandMessage; +import com.solace.maas.ep.common.model.ScanDestination; +import com.solace.maas.ep.common.model.ScanType; +import com.solace.maas.ep.event.management.agent.TestConfig; +import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties; +import com.solace.maas.ep.event.management.agent.publisher.ScanStatusPublisher; +import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl; +import com.solace.maas.ep.event.management.agent.service.ScanService; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ActiveProfiles("TEST") +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) +class ScanManagerHandleErrorTest { + + @Mock + EventPortalProperties eventPortalProperties; + + @Mock + MessagingServiceDelegateServiceImpl messagingServiceDelegateService; + + @Mock + private ScanService scanService; + + @Mock + private ScanStatusPublisher scanStatusPublisher; + + @Test + void testScanManagerHandleError(){ + when(eventPortalProperties.getOrganizationId()).thenReturn("orgId"); + when(eventPortalProperties.getRuntimeAgentId()).thenReturn("runtimeAgentId"); + + RuntimeException mockEx = new RuntimeException("Mock Exception"); + + ScanManager scanManagerUnderTest = new ScanManager( + messagingServiceDelegateService, + scanService, + eventPortalProperties, + scanStatusPublisher + ); + scanManagerUnderTest.handleError(mockEx,createScanCommandMessage()); + verify(scanStatusPublisher, times(1)).sendOverallScanStatus(any(),any()); + } + + + + private ScanCommandMessage createScanCommandMessage(){ + return new ScanCommandMessage( + "messageServiceId", + "scanId", + List.of(ScanType.SOLACE_ALL), + List.of(ScanDestination.EVENT_PORTAL), + null); + } +} diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerTest.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerTest.java index e97d51b29..ed5e46e66 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerTest.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerTest.java @@ -49,6 +49,7 @@ class ScanManagerTest { @Mock private ScanService scanService; + @Test @SneakyThrows void testScanManagerExceptions() { @@ -237,4 +238,6 @@ private List getKafkaRoutes(List destinations, String .build() ); } + + } diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessorTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessorTests.java new file mode 100644 index 000000000..bbb954652 --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessorTests.java @@ -0,0 +1,63 @@ +package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; + +import com.solace.maas.ep.common.messages.ScanCommandMessage; +import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; +import com.solace.maas.ep.common.model.ResourceConfigurationType; +import com.solace.maas.ep.common.model.ScanDestination; +import com.solace.maas.ep.common.model.ScanType; +import com.solace.maas.ep.event.management.agent.TestConfig; +import com.solace.maas.ep.event.management.agent.scanManager.ScanManager; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) +@ActiveProfiles("TEST") +class ScanCommandMessageProcessorTests { + + @MockBean + private ScanManager scanManager; + + @SpyBean + private ScanCommandMessageProcessor scanCommandMessageProcessor; + + @MockBean + private DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; + + @Test + void processMessageWithoutResourceConfiguration(){ + ScanCommandMessage message = buildScanCommandMessage(null); + scanCommandMessageProcessor.processMessage(message); + verifyNoInteractions(dynamicResourceConfigurationHelper); + verify(scanManager,times(1)).scan(any()); + } + + @Test + void processMessageWithResourceConfiguration(){ + ScanCommandMessage message = buildScanCommandMessage(List.of( + EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)) + ); + scanCommandMessageProcessor.processMessage(message); + verify(dynamicResourceConfigurationHelper, times(1)).loadSolaceBrokerResourceConfigurations(any()); + verify(scanManager,times(1)).scan(any()); + } + + + private ScanCommandMessage buildScanCommandMessage(List resources){ + return new ScanCommandMessage( + "messageServiceId", + "scanId", + List.of(ScanType.SOLACE_ALL), + List.of(ScanDestination.EVENT_PORTAL), + resources); + } +} From 082a1684c77d2033edfe624edd0a193afe107d98 Mon Sep 17 00:00:00 2001 From: Jochen Traunecker Date: Tue, 2 Jul 2024 16:29:44 +0200 Subject: [PATCH 13/13] Datago-74735: Add micrometer / StatsD metrics support (#190) --- service/application/pom.xml | 4 ++ .../src/main/resources/application.yml | 25 ++++++++ .../MicrometerStatsDConfigTest.java | 62 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 service/application/src/test/java/com/solace/maas/ep/event/management/agent/micrometer/MicrometerStatsDConfigTest.java diff --git a/service/application/pom.xml b/service/application/pom.xml index 262cafe07..59a870d73 100644 --- a/service/application/pom.xml +++ b/service/application/pom.xml @@ -274,6 +274,10 @@ micrometer-observation-test test + + io.micrometer + micrometer-registry-statsd + org.springframework.boot spring-boot-starter-actuator diff --git a/service/application/src/main/resources/application.yml b/service/application/src/main/resources/application.yml index 31385b9af..02d6f8758 100644 --- a/service/application/src/main/resources/application.yml +++ b/service/application/src/main/resources/application.yml @@ -5,6 +5,31 @@ springdoc: swagger-ui: path: /event-management-agent/swagger-ui.html +# micrometer / statsd +management: + metrics: + tags: + # key - value pairs + maas_id: my-maas-id + enable: + # enable / disable specific metrics + all: false + # sample metrics to be exposed + application: + started: + time: true + jvm: + info: true + statsd: + metrics: + export: + # enable / disable shipping metrics to StatsD endpoint + enabled: false + flavor: datadog + host: 127.0.0.1 + port: 8125 + protocol: udp + server: port: 8180 diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/micrometer/MicrometerStatsDConfigTest.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/micrometer/MicrometerStatsDConfigTest.java new file mode 100644 index 000000000..4b70b4c2a --- /dev/null +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/micrometer/MicrometerStatsDConfigTest.java @@ -0,0 +1,62 @@ +package com.solace.maas.ep.event.management.agent.micrometer; + +import io.micrometer.statsd.StatsdConfig; +import io.micrometer.statsd.StatsdFlavor; +import io.micrometer.statsd.StatsdProtocol; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; + +@SuppressWarnings("PMD") +@ActiveProfiles("TEST") +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { + "management.metrics.tags.maas_id=my-maas-id", + "management.metrics.enable.all=false", + "management.metrics.enable.application.started.time=true", + "management.metrics.enable.jvm.info=true", + "management.statsd.metrics.export.enabled=true", + "management.statsd.metrics.export.flavor=datadog", + "management.statsd.metrics.export.host=127.0.0.1", + "management.statsd.metrics.export.port=8128", + "management.statsd.metrics.export.protocol=udp" +}) +@DirtiesContext(classMode = AFTER_CLASS) +class MicrometerStatsDConfigTest { + + @Autowired + private StatsdConfig statsdConfig; + + @Autowired + private MetricsProperties metricsProperties; + + @Test + void testStatsdConfig(){ + assertNotNull(statsdConfig); + Assertions.assertTrue(statsdConfig.enabled()); + Assertions.assertEquals(StatsdFlavor.DATADOG,statsdConfig.flavor()); + Assertions.assertEquals("127.0.0.1", statsdConfig.host()); + Assertions.assertEquals(8128, statsdConfig.port()); + Assertions.assertEquals(StatsdProtocol.UDP, statsdConfig.protocol()); + } + + @Test + void testMicrometerRegistryConfig(){ + assertNotNull(metricsProperties); + Assertions.assertTrue(metricsProperties.getTags().containsKey("maas_id")); + Assertions.assertEquals("my-maas-id", metricsProperties.getTags().get("maas_id")); + Assertions.assertTrue(metricsProperties.getEnable().containsKey("all")); + Assertions.assertEquals(false, metricsProperties.getEnable().get("all")); + Assertions.assertTrue(metricsProperties.getEnable().containsKey("application.started.time")); + Assertions.assertEquals(true, metricsProperties.getEnable().get("application.started.time")); + Assertions.assertTrue(metricsProperties.getEnable().containsKey("jvm.info")); + Assertions.assertEquals(true, metricsProperties.getEnable().get("jvm.info")); + + } +}