CSIT Fix for SDC-2585
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / MonitoringBusinessLogic.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  */
20
21 package org.openecomp.sdc.be.components.impl;
22
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;
31
32 @Component("monitoringBusinessLogic")
33 public class MonitoringBusinessLogic {
34
35     private static final Logger log = Logger.getLogger(MonitoringBusinessLogic.class);
36
37     @javax.annotation.Resource
38     private MonitoringDao monitoringDao;
39
40     @javax.annotation.Resource
41     private ComponentsUtils componentsUtils;
42
43     public Either<Boolean, ResponseFormat> logMonitoringEvent(MonitoringEvent monitoringEvent) {
44         if (monitoringDao == null) {
45             return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
46         }
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));
51         }
52         return Either.left(true);
53     }
54
55     public String getEsHost() {
56
57         String res = monitoringDao.getEsHost();
58         res = res.replaceAll("[\\[\\]]", "");
59         res = res.split(",")[0];
60         res = res.replaceAll("[']", "");
61         res = res.split(":")[0];
62         return res;
63     }
64
65     public String getEsPort() {
66         return monitoringDao.getEsPort();
67     }
68
69 }