Implement custom logging in participant-intermediary 29/142029/12
authorwaynedunican <wayne.dunican@est.tech>
Thu, 4 Sep 2025 10:34:51 +0000 (11:34 +0100)
committerWayne Dunican <wayne.dunican@est.tech>
Thu, 18 Sep 2025 13:15:00 +0000 (13:15 +0000)
- Moved NetLoggerUtil class to common
- Modified the toString() in AutomationCompositionElementInfo
- Updated the logging in ParticipantMessagePublisher
- Added custom logging in ParticipantListener

Issue-ID: POLICY-5452
Change-Id: If2b2de8641dd4de6b819252d9dfb39a084ff7f5d
Signed-off-by: waynedunican <wayne.dunican@est.tech>
15 files changed:
common/pom.xml
common/src/main/java/org/onap/policy/clamp/common/acm/utils/NetLoggerUtil.java [moved from runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java with 94% similarity]
common/src/test/java/org/onap/policy/clamp/common/acm/utils/NetLoggerUtilTest.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantListener.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantDeregisterListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimeAckListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRegisterListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantReqSyncListener.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantStatusListener.java

index a9276ca..67960ac 100644 (file)
             <artifactId>policy-models-errors</artifactId>
             <version>${policy.models.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>message-bus</artifactId>
+            <version>${policy.common.version}</version>
+        </dependency>
         <dependency>
             <groupId>jakarta.ws.rs</groupId>
             <artifactId>jakarta.ws.rs-api</artifactId>
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2025 Nordix Foundation.
+ *  Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.clamp.acm.runtime.main.utils;
+package org.onap.policy.clamp.common.acm.utils;
 
 import lombok.Getter;
 import org.onap.policy.common.message.bus.event.Topic;
diff --git a/common/src/test/java/org/onap/policy/clamp/common/acm/utils/NetLoggerUtilTest.java b/common/src/test/java/org/onap/policy/clamp/common/acm/utils/NetLoggerUtilTest.java
new file mode 100644 (file)
index 0000000..3e0e595
--- /dev/null
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.common.acm.utils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+import org.onap.policy.common.message.bus.event.Topic;
+
+class NetLoggerUtilTest {
+
+    @Test
+    void testLog() {
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, Topic.CommInfrastructure.KAFKA, "someTopic", "message1");
+
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, null, "message2");
+
+        assertEquals("acm-network", NetLoggerUtil.getNetworkLogger().getName());
+    }
+}
index 8894c3f..c55336f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import java.util.UUID;
 import java.util.function.UnaryOperator;
 import lombok.Data;
 import lombok.NoArgsConstructor;
-import lombok.ToString;
 import org.onap.policy.models.base.PfUtils;
 
 /**
@@ -34,7 +33,6 @@ import org.onap.policy.models.base.PfUtils;
  */
 @NoArgsConstructor
 @Data
-@ToString
 public class AutomationCompositionElementInfo {
 
     private UUID automationCompositionElementId;
@@ -62,4 +60,15 @@ public class AutomationCompositionElementInfo {
         this.useState = otherElement.useState;
         this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
     }
+
+    @Override
+    public String toString() {
+        return "AutomationCompositionElementInfo{"
+                + "automationCompositionElementId=" + automationCompositionElementId
+                + ", deployState=" + deployState
+                + ", lockState=" + lockState
+                + ", operationalState='" + operationalState + '\''
+                + ", useState='" + useState + '\''
+                + '}';
+    }
 }
index 283ff0b..30803d4 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021,2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.comm;
 import java.util.function.Consumer;
 import org.onap.policy.clamp.acm.participant.intermediary.handler.Listener;
 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessage;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
 import org.onap.policy.common.message.bus.event.Topic.CommInfrastructure;
@@ -53,6 +54,8 @@ public abstract class ParticipantListener<T extends ParticipantMessage> extends
     @Override
     public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco, T message) {
         if (participantHandler.appliesTo(message)) {
+            NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic,
+                    String.format("{\"type\":\"IN\", \"topic\":\"%s\", \"message\":%s}", topic, message));
             consumer.accept(message);
         }
     }
index c64317d..f520efc 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import lombok.Getter;
 import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher;
 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
@@ -35,8 +36,6 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRe
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
 import org.onap.policy.common.message.bus.event.TopicSink;
 import org.onap.policy.common.message.bus.event.client.TopicSinkClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 /**
@@ -45,7 +44,6 @@ import org.springframework.stereotype.Component;
  */
 @Component
 public class ParticipantMessagePublisher implements Publisher {
-    private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class);
     private static final String NOT_ACTIVE_TEXT = "Not Active!";
 
     @Getter
@@ -75,7 +73,9 @@ public class ParticipantMessagePublisher implements Publisher {
     public void sendParticipantReqSync(final ParticipantReqSync participantReqSync) {
         validate();
         topicSinkClient.send(participantReqSync);
-        LOGGER.info("Sent Participant Request Sync to CLAMP - {}", participantReqSync);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent Participant Request Sync to CLAMP - "
+                        + participantReqSync.toString());
     }
 
     /**
@@ -87,7 +87,9 @@ public class ParticipantMessagePublisher implements Publisher {
     public void sendParticipantStatus(final ParticipantStatus participantStatus) {
         validate();
         topicSinkClient.send(participantStatus);
-        LOGGER.info("Sent Participant Status message to CLAMP - {}", participantStatus);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent Participant Status message to CLAMP - "
+                        + participantStatus.toString());
     }
 
     /**
@@ -99,7 +101,9 @@ public class ParticipantMessagePublisher implements Publisher {
     public void sendParticipantRegister(final ParticipantRegister participantRegister) {
         validate();
         topicSinkClient.send(participantRegister);
-        LOGGER.info("Sent Participant Register message to CLAMP - {}", participantRegister);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent Participant Register message to CLAMP - "
+                        + participantRegister.toString());
     }
 
     /**
@@ -111,7 +115,9 @@ public class ParticipantMessagePublisher implements Publisher {
     public void sendParticipantDeregister(final ParticipantDeregister participantDeregister) {
         validate();
         topicSinkClient.send(participantDeregister);
-        LOGGER.debug("Sent Participant Deregister message to CLAMP - {}", participantDeregister);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent Participant Deregister message to CLAMP - "
+                        + participantDeregister.toString());
     }
 
     /**
@@ -123,7 +129,9 @@ public class ParticipantMessagePublisher implements Publisher {
     public void sendParticipantPrimeAck(final ParticipantPrimeAck participantPrimeAck) {
         validate();
         topicSinkClient.send(participantPrimeAck);
-        LOGGER.debug("Sent Participant Prime Ack message to CLAMP - {}", participantPrimeAck);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent Participant Prime Ack message to CLAMP - "
+                        + participantPrimeAck.toString());
     }
 
     /**
@@ -135,8 +143,9 @@ public class ParticipantMessagePublisher implements Publisher {
             description = "AUTOMATION_COMPOSITION_UPDATE_ACK/AUTOMATION_COMPOSITION_STATECHANGE_ACK messages published")
     public void sendAutomationCompositionAck(final AutomationCompositionDeployAck automationCompositionAck) {
         validate();
-        topicSinkClient.send(automationCompositionAck);
-        LOGGER.debug("Sent AutomationComposition Update/StateChange Ack to runtime - {}", automationCompositionAck);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), "Sent AutomationComposition Update/StateChange Ack to runtime - "
+                        + automationCompositionAck.toString());
     }
 
     private void validate() {
index 1fcd9fe..6b248fa 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,12 +23,14 @@ package org.onap.policy.clamp.acm.participant.intermediary.comm;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.function.Consumer;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
@@ -36,6 +38,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.Common
 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister;
+import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessage;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister;
@@ -43,7 +46,9 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRe
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantReqSync;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
+import org.onap.policy.common.message.bus.event.Topic;
 import org.onap.policy.common.message.bus.event.TopicSink;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
 
 class ParticipantCommTest {
 
@@ -153,4 +158,25 @@ class ParticipantCommTest {
         assertFalse(messageSender.makeTimerPool().isTerminated());
         messageSender.close();
     }
+
+    @Test
+    void testOnTopicEvent() {
+        ParticipantHandler handler = Mockito.mock(ParticipantHandler.class);
+        Consumer<ParticipantMessage> consumer = Mockito.mock(Consumer.class);
+        ParticipantMessage message = Mockito.mock(ParticipantMessage.class);
+
+        Mockito.when(handler.appliesTo(message)).thenReturn(true);
+
+        ParticipantListener<ParticipantMessage> listener =
+                new ParticipantListener<>(ParticipantMessage.class, handler, consumer) {
+                @Override
+                public String getType() {
+                    return "";
+                }
+            };
+        assertNotNull(listener);
+        listener.onTopicEvent(Mockito.mock(Topic.CommInfrastructure.class),
+                "topic", Mockito.mock(StandardCoderObject.class), message);
+        Mockito.verify(handler).appliesTo(message);
+    }
 }
index 80cd477..55c9418 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021,2025 Nordix Foundation.
+ *  Copyright (C) 2021,2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import jakarta.ws.rs.core.Response.Status;
 import org.onap.policy.clamp.acm.runtime.config.messaging.Publisher;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessage;
 import org.onap.policy.common.message.bus.event.TopicSink;
 import org.onap.policy.common.message.bus.event.client.TopicSinkClient;
index 50abff1..a8c3a0b 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index 20c1e5b..59801c7 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index 740f489..9a52f00 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index c40aac2..38b60db 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index 40a88d3..49d1d2c 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index 71a545d..0a6c1ca 100644 (file)
@@ -21,8 +21,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantReqSync;
 import org.onap.policy.common.endpoints.listeners.ScoListener;
index b3429fc..02e3223 100644 (file)
@@ -22,8 +22,8 @@
 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
 import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.main.utils.NetLoggerUtil;
 import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
+import org.onap.policy.clamp.common.acm.utils.NetLoggerUtil;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
 import org.onap.policy.common.endpoints.listeners.ScoListener;