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.components.impl;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.dao.impl.MonitoringDao;
26 import org.openecomp.sdc.be.impl.ComponentsUtils;
27 import org.openecomp.sdc.common.log.wrappers.Logger;
28 import org.openecomp.sdc.common.monitoring.MonitoringEvent;
29 import org.openecomp.sdc.exception.ResponseFormat;
30 import org.springframework.stereotype.Component;
32 @Component("monitoringBusinessLogic")
33 public class MonitoringBusinessLogic {
35 private static final Logger log = Logger.getLogger(MonitoringBusinessLogic.class);
37 @javax.annotation.Resource
38 private MonitoringDao monitoringDao;
40 @javax.annotation.Resource
41 private ComponentsUtils componentsUtils;
43 public Either<Boolean, ResponseFormat> logMonitoringEvent(MonitoringEvent monitoringEvent) {
44 if (monitoringDao == null) {
45 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
47 ActionStatus status = monitoringDao.addRecord(monitoringEvent);
48 if (!status.equals(ActionStatus.OK)) {
49 log.warn("Failed to persist monitoring event: {}", status);
50 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
52 return Either.left(true);
55 public String getEsHost() {
57 String res = monitoringDao.getEsHost();
58 res = res.replaceAll("[\\[\\]]", "");
59 res = res.split(",")[0];
60 res = res.replaceAll("[']", "");
61 res = res.split(":")[0];
65 public String getEsPort() {
66 return monitoringDao.getEsPort();