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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.service;
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;
30 public class MicrowaveHistoricalPerformanceWriterService {
32 private static final Logger LOG = LoggerFactory.getLogger(MicrowaveHistoricalPerformanceWriterService.class);
33 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
36 private final HtDatabaseClient client;
37 private HtDataBaseReaderAndWriter<EsHistoricalPerformance15Minutes> historicalPerformance15mRW;
38 private HtDataBaseReaderAndWriter<EsHistoricalPerformance24Hours> historicalPerformance24hRW;
39 private HtDataBaseReaderAndWriter<EsHistoricalPerformanceLogEntry> historicalPerformanceLogRW;
41 public MicrowaveHistoricalPerformanceWriterService(HtDatabaseClient client) {
43 LOG.info("Create {} start", MicrowaveHistoricalPerformanceWriterService.class);
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);
54 } catch (Exception e) {
56 LOG.error("Can not start database client. Exception: {}", e.getMessage());
59 LOG.info("Create {} finished. DB Service {} started.", MicrowaveHistoricalPerformanceWriterService.class,
60 client != null ? "sucessfully" : "not");
64 public void writePM(AllPm pm) {
66 LOG.debug("Write {} pm records", pm.size());
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");
76 public void writePMLog(String mountpointName, String layerProtocolName, String msg) {
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");
87 static public boolean isAvailable(MicrowaveHistoricalPerformanceWriterService s) {
89 if (s == null || s.client == null) {