Add custom network logging for clamp runtime 68/140368/2
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Tue, 25 Feb 2025 12:06:43 +0000 (12:06 +0000)
committerRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>
Wed, 5 Mar 2025 10:22:38 +0000 (10:22 +0000)
Override network logging from policy-common
Excluded instance properties in kafka logs

Issue-ID: POLICY-5134
Signed-off-by: rameshiyer27 <ramesh.murugan.iyer@est.tech>
Change-Id: I7d3086562f8f21701de83939e3fdae6968b2ba06

models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java [new file with mode: 0644]
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/ParticipantStatusListener.java
runtime-acm/src/test/resources/logback.xml

index 22f3cd8..7684fec 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation.
+ * Copyright (C) 2023-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import java.util.function.UnaryOperator;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import lombok.ToString;
 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfUtils;
@@ -39,7 +38,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
  */
 @NoArgsConstructor
 @Data
-@ToString
 public class AcElementDeploy {
 
     @NonNull
@@ -70,4 +68,15 @@ public class AcElementDeploy {
         this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
         this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
     }
+
+    @Override
+    public String toString() {
+        // Exclude instance properties
+        return "AcElementDeploy{"
+                + "id=" + id
+                + ", definition=" + definition
+                + ", orderedState=" + orderedState
+                + ", toscaServiceTemplateFragment="
+                + toscaServiceTemplateFragment + '}';
+    }
 }
index 687a2cf..4acb42a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2024 Nordix Foundation.
+ *  Copyright (C) 2023-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import java.util.function.UnaryOperator;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import lombok.ToString;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -35,7 +34,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 @NoArgsConstructor
 @Data
-@ToString
 public class AcElementRestart {
 
     @NonNull
@@ -82,4 +80,19 @@ public class AcElementRestart {
         this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
     }
 
+    @Override
+    public String toString() {
+        // Exclude instance properties
+        return "AcElementRestart{"
+                + "id=" + id
+                + ", definition=" + definition
+                + ", participantId=" + participantId
+                + ", deployState=" + deployState
+                + ", lockState=" + lockState
+                + ", operationalState='" + operationalState + '\''
+                + ", useState='" + useState + '\''
+                + ", toscaServiceTemplateFragment=" + toscaServiceTemplateFragment
+                + ", outProperties=" + outProperties
+                + '}';
+    }
 }
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java
new file mode 100644 (file)
index 0000000..0a19f03
--- /dev/null
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2025 Nordix Foundation.
+ * ================================================================================
+ * 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.acm.runtime.main.utils;
+
+import lombok.Getter;
+import org.onap.policy.common.message.bus.event.Topic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NetLoggerUtil {
+
+    /**
+     * Loggers.
+     */
+    @Getter
+    private static final Logger networkLogger = LoggerFactory.getLogger("acm-network");
+
+    /**
+     * Constant for the system line separator.
+     */
+    public static final String SYSTEM_LS = System.lineSeparator();
+
+    /**
+     * Specifies if the message is coming in or going out.
+     */
+    public enum EventType {
+        IN, OUT
+    }
+
+    /**
+     * Logs a message to the network logger.
+     *
+     * @param type can either be IN or OUT
+     * @param protocol the protocol used to receive/send the message
+     * @param topic the topic the message came from or null if the type is REST
+     * @param message message to be logged
+     */
+    public static void log(EventType type, Topic.CommInfrastructure protocol, String topic, String message) {
+        networkLogger.info("[{}|{}|{}]{}{}", type, protocol, topic, SYSTEM_LS, message);
+    }
+
+}
index d3222ca..80cd477 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021,2024 Nordix Foundation.
+ *  Copyright (C) 2021,2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ 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.models.acm.messages.kafka.participant.ParticipantMessage;
 import org.onap.policy.common.message.bus.event.TopicSink;
@@ -42,6 +43,9 @@ public abstract class AbstractParticipantPublisher<E extends ParticipantMessage>
         if (!active) {
             throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, "Not Active!");
         }
+        //Custom network logging
+        NetLoggerUtil.log(NetLoggerUtil.EventType.OUT, topicSinkClient.getSink().getTopicCommInfrastructure(),
+                topicSinkClient.getTopic(), participantMessage.toString());
         topicSinkClient.send(participantMessage);
     }
 
index a0b74b5..3d6ed75 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021,2023-2024 Nordix Foundation.
+ * Copyright (C) 2021,2023-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
@@ -53,8 +54,8 @@ public class AutomationCompositionStateChangeAckListener extends ScoListener<Aut
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
         final AutomationCompositionDeployAck automationCompositionStateChangeAckMessage) {
-        LOGGER.debug("AutomationCompositionStateChangeAck received from participant - {}",
-            automationCompositionStateChangeAckMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic,
+                automationCompositionStateChangeAckMessage.toString());
         supervisionHandler.handleAutomationCompositionStateChangeAckMessage(automationCompositionStateChangeAckMessage);
     }
 
index 551a27c..edae442 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021,2023-2024 Nordix Foundation.
+ * Copyright (C) 2021,2023-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
@@ -53,8 +54,7 @@ public class AutomationCompositionUpdateAckListener extends ScoListener<Automati
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
         final AutomationCompositionDeployAck automationCompositionUpdateAckMessage) {
-        LOGGER.debug("AutomationCompositionUpdateAck message received from participant - {}",
-            automationCompositionUpdateAckMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic, automationCompositionUpdateAckMessage.toString());
         supervisionHandler.handleAutomationCompositionUpdateAckMessage(automationCompositionUpdateAckMessage);
     }
 
index 1649c25..ee756ec 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.ParticipantDeregister;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
@@ -53,7 +54,7 @@ public class ParticipantDeregisterListener extends ScoListener<ParticipantDeregi
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
             final ParticipantDeregister participantDeregisterMessage) {
-        LOGGER.debug("ParticipantDeregister message received from participant - {}", participantDeregisterMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic, participantDeregisterMessage.toString());
         supervisionHandler.handleParticipantMessage(participantDeregisterMessage);
     }
 
index a6a3ab6..c3b044a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
@@ -53,7 +54,7 @@ public class ParticipantPrimeAckListener extends ScoListener<ParticipantPrimeAck
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
             final ParticipantPrimeAck participantPrimeAckMessage) {
-        LOGGER.debug("ParticipantPrimeAck message received from participant - {}", participantPrimeAckMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic, participantPrimeAckMessage.toString());
         supervisionHandler.handleParticipantMessage(participantPrimeAckMessage);
     }
 
index d78cec7..0be7392 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister;
@@ -53,7 +54,7 @@ public class ParticipantRegisterListener extends ScoListener<ParticipantRegister
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
             final ParticipantRegister participantRegisterMessage) {
-        LOGGER.debug("ParticipantRegister message received from participant - {}", participantRegisterMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic, participantRegisterMessage.toString());
         supervisionHandler.handleParticipantMessage(participantRegisterMessage);
     }
 
index 0a7a5eb..575b2fa 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-2025 Nordix Foundation.
  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 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.models.acm.messages.kafka.participant.ParticipantMessageType;
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
@@ -52,7 +53,7 @@ public class ParticipantStatusListener extends ScoListener<ParticipantStatus> im
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
             final ParticipantStatus participantStatusMessage) {
-        LOGGER.debug("ParticipantStatus message received from participant - {}", participantStatusMessage);
+        NetLoggerUtil.log(NetLoggerUtil.EventType.IN, infra, topic, participantStatusMessage.toString());
         supervisionHandler.handleParticipantMessage(participantStatusMessage);
     }
 
index b8934df..8d65b80 100644 (file)
@@ -1,6 +1,6 @@
 <!--
   ============LICENSE_START=======================================================
-   Copyright (C) 2024 Nordix Foundation.
+   Copyright (C) 2024-2025 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
         </encoder>
     </appender>
 
-    <logger name="network" level="INFO" additivity="false">
+    <logger name="acm-network" level="INFO" additivity="false">
         <appender-ref ref="STDOUT" />
     </logger>