From 3bf88d59cf34db6ef450b35815459502633b3292 Mon Sep 17 00:00:00 2001 From: rameshiyer27 Date: Tue, 25 Feb 2025 12:06:43 +0000 Subject: Add custom network logging for clamp runtime Override network logging from policy-common Excluded instance properties in kafka logs Issue-ID: POLICY-5134 Signed-off-by: rameshiyer27 Change-Id: I7d3086562f8f21701de83939e3fdae6968b2ba06 --- .../clamp/models/acm/concepts/AcElementDeploy.java | 15 ++++-- .../models/acm/concepts/AcElementRestart.java | 19 +++++-- .../acm/runtime/main/utils/NetLoggerUtil.java | 60 ++++++++++++++++++++++ .../comm/AbstractParticipantPublisher.java | 6 ++- ...utomationCompositionStateChangeAckListener.java | 7 +-- .../AutomationCompositionUpdateAckListener.java | 6 +-- .../comm/ParticipantDeregisterListener.java | 5 +- .../comm/ParticipantPrimeAckListener.java | 5 +- .../comm/ParticipantRegisterListener.java | 5 +- .../comm/ParticipantStatusListener.java | 5 +- runtime-acm/src/test/resources/logback.xml | 4 +- 11 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java index 22f3cd830..7684fecf0 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java @@ -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 + '}'; + } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java index 687a2cfb0..4acb42ad8 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java @@ -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 index 000000000..0a19f0367 --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/NetLoggerUtil.java @@ -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); + } + +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java index d3222caf5..80cd4772e 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java @@ -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 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); } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java index a0b74b574..3d6ed7568 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java @@ -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 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); } diff --git a/runtime-acm/src/test/resources/logback.xml b/runtime-acm/src/test/resources/logback.xml index b8934df2d..8d65b8075 100644 --- a/runtime-acm/src/test/resources/logback.xml +++ b/runtime-acm/src/test/resources/logback.xml @@ -1,6 +1,6 @@