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.devicemanager.base.database.HtDataBaseReaderAndWriter;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseClientAbstract;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.IndexClientBuilder;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.AllPm;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformanceLogEntry;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class MicrowaveHistoricalPerformanceWriterService {
34 private static final Logger LOG = LoggerFactory.getLogger(MicrowaveHistoricalPerformanceWriterService.class);
35 private static final String INDEX = "sdnperformance";
36 private static final String MAPPING = "/elasticsearch/index/sdnperformance/sdnperformanceMapping.json";
37 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
40 private HtDatabaseClientAbstract client;
41 private HtDataBaseReaderAndWriter<EsHistoricalPerformance15Minutes> historicalPerformance15mRW;
42 private HtDataBaseReaderAndWriter<EsHistoricalPerformance24Hours> historicalPerformance24hRW;
43 private HtDataBaseReaderAndWriter<EsHistoricalPerformanceLogEntry> historicalPerformanceLogRW;
45 public MicrowaveHistoricalPerformanceWriterService(HtDatabaseNode database) {
47 LOG.info("Create {} start", MicrowaveHistoricalPerformanceWriterService.class);
51 IndexClientBuilder clientBuilder =
52 IndexClientBuilder.getBuilder(INDEX).setMappingSettingJsonFileName(MAPPING);
53 client = clientBuilder.create(database);
54 clientBuilder.close();
56 historicalPerformance15mRW = new HtDataBaseReaderAndWriter<>(client,
57 EsHistoricalPerformance15Minutes.ESDATATYPENAME, EsHistoricalPerformance15Minutes.class);
58 historicalPerformance24hRW = new HtDataBaseReaderAndWriter<>(client,
59 EsHistoricalPerformance24Hours.ESDATATYPENAME, EsHistoricalPerformance24Hours.class);
60 historicalPerformanceLogRW = new HtDataBaseReaderAndWriter<>(client,
61 EsHistoricalPerformanceLogEntry.ESDATATYPENAME, EsHistoricalPerformanceLogEntry.class);
63 } catch (Exception e) {
65 LOG.error("Can not start database client. Exception: {}", e.getMessage());
68 LOG.info("Create {} finished. DB Service {} started.", MicrowaveHistoricalPerformanceWriterService.class,
69 client != null ? "sucessfully" : "not");
73 public void writePM(AllPm pm) {
75 LOG.debug("Write {} pm records", pm.size());
77 LOG.debug("Write 15m write to DB");
78 historicalPerformance15mRW.doWrite(pm.getPm15());
79 LOG.debug("Write 15m done, Write 24h write to DB");
80 historicalPerformance24hRW.doWrite(pm.getPm24());
81 LOG.debug("Write 24h done");
85 public void writePMLog(String mountpointName, String layerProtocolName, String msg) {
87 LOG.debug("Write PM Log: {}", msg);
88 EsHistoricalPerformanceLogEntry logEntry = new EsHistoricalPerformanceLogEntry(mountpointName,
89 layerProtocolName, NETCONFTIME_CONVERTER.getTimeStamp().getValue(), msg);
90 historicalPerformanceLogRW.doWrite(logEntry);
91 LOG.debug("Write PM Log done");
96 static public boolean isAvailable(MicrowaveHistoricalPerformanceWriterService s) {
98 if (s == null || s.client == null) {