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=========================================================
21 package org.openecomp.sdc.be.auditing.impl;
23 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
24 import org.openecomp.sdc.be.config.ConfigurationManager;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
27 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
28 import org.openecomp.sdc.be.dao.impl.AuditingDao;
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.wrappers.Logger;
32 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
33 import org.springframework.stereotype.Component;
36 public class AuditingManager {
38 private static final Logger log = Logger.getLogger(AuditingManager.class.getName());
40 private final AuditingDao auditingDao;
41 private final AuditCassandraDao cassandraDao;
43 public AuditingManager(AuditingDao auditingDao, AuditCassandraDao cassandraDao) {
44 this.auditingDao = auditingDao;
45 this.cassandraDao = cassandraDao;
49 public String auditEvent(AuditEventFactory factory) {
50 if (ConfigurationManager.getConfigurationManager().getConfiguration().isDisableAudit()) {
53 String msg = factory.getLogMessage();
56 //TODO - remove this method after we got rid of ES
57 saveEventToElasticSearch(factory);
58 saveEventToCassandra(factory.getDbEvent());
62 private void saveEventToCassandra(AuditingGenericEvent event) {
63 CassandraOperationStatus result = cassandraDao.saveRecord(event);
64 if (!result.equals(CassandraOperationStatus.OK)) {
65 log.warn("Failed to persist to cassandra auditing event: {}", result.name());
69 private void saveEventToElasticSearch(AuditEventFactory factory) {
70 ActionStatus addRecordStatus = auditingDao.addRecord(factory.getDbEvent(), factory.getAuditingEsType());
71 if (!addRecordStatus.equals(ActionStatus.OK)) {
72 log.warn("Failed to persist auditing event: {}", addRecordStatus.name());
76 private void logAuditEvent(final String formattedString) {
77 log.trace("logAuditEvent - start");
78 log.debug(formattedString);
79 LogFieldsMdcHandler.getInstance()
80 .setAuditMessage(formattedString);
81 if (!LoggerSdcAudit.isFlowBeingTakenCare()){
82 log.debug("MOVED FROM AUDIT LOG: {}", formattedString);
84 log.trace("logAuditEvent - end");