2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
23 package org.openecomp.sdc.be.auditing.impl;
25 import org.onap.logging.ref.slf4j.ONAPLogConstants;
26 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
27 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
28 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
29 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
30 import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
31 import org.openecomp.sdc.common.log.enums.LogLevel;
32 import org.openecomp.sdc.common.log.enums.Severity;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
35 import org.slf4j.MarkerFactory;
36 import org.springframework.stereotype.Component;
39 public class AuditingManager {
41 private static final Logger log = Logger.getLogger(AuditingManager.class.getName());
43 private final AuditCassandraDao cassandraDao;
44 private final ConfigurationProvider configurationProvider;
46 public AuditingManager(AuditCassandraDao cassandraDao, ConfigurationProvider configurationProvider) {
47 this.cassandraDao = cassandraDao;
48 this.configurationProvider = configurationProvider;
51 public String auditEvent(AuditEventFactory factory) {
52 if (configurationProvider.getConfiguration().isDisableAudit()) {
55 String msg = factory.getLogMessage();
58 saveEventToCassandra(factory.getDbEvent());
62 public String auditEvent(AuditEventFactory factory, LoggerSdcAudit audit) {
63 String msg = auditEvent(factory);
64 logAuditEvent(msg, audit, factory.getDbEvent().getRequestId());
68 private void logAuditEvent(String msg, LoggerSdcAudit audit, String requestId) {
70 audit.logEntry(LogLevel.INFO, Severity.OK, msg,
71 MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), requestId);
75 private void saveEventToCassandra(AuditingGenericEvent event) {
76 CassandraOperationStatus result = cassandraDao.saveRecord(event);
77 if (result != CassandraOperationStatus.OK) {
78 log.warn("Failed to persist to cassandra auditing event: {}", result.name());
82 private void logAuditEvent(final String formattedString) {
83 log.trace("logAuditEvent - start");
84 log.debug(formattedString);
85 LogFieldsMdcHandler.getInstance()
86 .setAuditMessage(formattedString);
87 if (!LoggerSdcAudit.isFlowBeingTakenCare()){
88 log.debug("MOVED FROM AUDIT LOG: {}", formattedString);
90 log.trace("logAuditEvent - end");