ef57b1088662adc5c2b28cfd151ffe841ded5400
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.service;
19
20 import org.onap.ccsdk.features.sdnr.wt.base.netconf.util.NetconfTimeStamp;
21 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.container.AllPm;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.HtDataBaseReaderAndWriter;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformanceLogEntry;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class MicrowaveHistoricalPerformanceWriterService {
31
32     private static final Logger LOG = LoggerFactory.getLogger(MicrowaveHistoricalPerformanceWriterService.class);
33     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
34
35
36     private final HtDatabaseClient client;
37     private HtDataBaseReaderAndWriter<EsHistoricalPerformance15Minutes> historicalPerformance15mRW;
38     private HtDataBaseReaderAndWriter<EsHistoricalPerformance24Hours> historicalPerformance24hRW;
39     private HtDataBaseReaderAndWriter<EsHistoricalPerformanceLogEntry> historicalPerformanceLogRW;
40
41     public MicrowaveHistoricalPerformanceWriterService(HtDatabaseClient client) {
42
43         LOG.info("Create {} start", MicrowaveHistoricalPerformanceWriterService.class);
44         this.client = client;
45         try {
46
47             historicalPerformance15mRW = new HtDataBaseReaderAndWriter<>(client,
48                     EsHistoricalPerformance15Minutes.ESDATATYPENAME, EsHistoricalPerformance15Minutes.class);
49             historicalPerformance24hRW = new HtDataBaseReaderAndWriter<>(client,
50                     EsHistoricalPerformance24Hours.ESDATATYPENAME, EsHistoricalPerformance24Hours.class);
51             historicalPerformanceLogRW = new HtDataBaseReaderAndWriter<>(client,
52                     EsHistoricalPerformanceLogEntry.ESDATATYPENAME, EsHistoricalPerformanceLogEntry.class);
53
54         } catch (Exception e) {
55             client = null;
56             LOG.error("Can not start database client. Exception: {}", e.getMessage());
57         }
58
59         LOG.info("Create {} finished. DB Service {} started.", MicrowaveHistoricalPerformanceWriterService.class,
60                 client != null ? "sucessfully" : "not");
61     }
62
63
64     public void writePM(AllPm pm) {
65
66         LOG.debug("Write {} pm records", pm.size());
67
68         LOG.debug("Write 15m write to DB");
69         historicalPerformance15mRW.doWrite(pm.getPm15());
70         LOG.debug("Write 15m done, Write 24h write to DB");
71         historicalPerformance24hRW.doWrite(pm.getPm24());
72         LOG.debug("Write 24h done");
73
74     }
75
76     public void writePMLog(String mountpointName, String layerProtocolName, String msg) {
77
78         LOG.debug("Write PM Log: {}", msg);
79         EsHistoricalPerformanceLogEntry logEntry = new EsHistoricalPerformanceLogEntry(mountpointName,
80                 layerProtocolName, NETCONFTIME_CONVERTER.getTimeStamp().getValue(), msg);
81         historicalPerformanceLogRW.doWrite(logEntry);
82         LOG.debug("Write PM Log done");
83
84     }
85
86
87     static public boolean isAvailable(MicrowaveHistoricalPerformanceWriterService s) {
88
89         if (s == null || s.client == null) {
90             return false;
91         }
92         return true;
93     }
94
95 }