1 package org.opendaylight.mwtn.performancemanager.impl.database.service;
3 import org.opendaylight.mwtn.base.database.HtDataBaseReaderAndWriter;
4 import org.opendaylight.mwtn.base.database.HtDatabaseClientAbstract;
5 import org.opendaylight.mwtn.base.database.HtDatabaseNode;
6 import org.opendaylight.mwtn.base.database.IndexClientBuilder;
7 import org.opendaylight.mwtn.base.netconf.AllPm;
8 import org.opendaylight.mwtn.base.netconf.NetconfTimeStamp;
9 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
10 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
11 import org.opendaylight.mwtn.performancemanager.impl.database.types.EsHistoricalPerformanceLogEntry;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public class MicrowaveHistoricalPerformanceWriterService {
17 private static final Logger LOG = LoggerFactory.getLogger(MicrowaveHistoricalPerformanceWriterService.class);
18 private static final String INDEX = "sdnperformance";
19 private static final String MAPPING = "/elasticsearch/index/sdnperformance/sdnperformanceMapping.json";
22 private HtDatabaseClientAbstract client;
23 private HtDataBaseReaderAndWriter<EsHistoricalPerformance15Minutes> historicalPerformance15mRW;
24 private HtDataBaseReaderAndWriter<EsHistoricalPerformance24Hours> historicalPerformance24hRW;
25 private HtDataBaseReaderAndWriter<EsHistoricalPerformanceLogEntry> historicalPerformanceLogRW;
27 public MicrowaveHistoricalPerformanceWriterService(HtDatabaseNode database) {
29 LOG.info("Create {} start", MicrowaveHistoricalPerformanceWriterService.class);
33 IndexClientBuilder clientBuilder = IndexClientBuilder.getBuilder(INDEX).setMappingSettingJsonFileName(MAPPING);
34 client = clientBuilder.create(database);
36 historicalPerformance15mRW = new HtDataBaseReaderAndWriter<>(client, EsHistoricalPerformance15Minutes.ESDATATYPENAME, EsHistoricalPerformance15Minutes.class);
37 historicalPerformance24hRW = new HtDataBaseReaderAndWriter<>(client, EsHistoricalPerformance24Hours.ESDATATYPENAME, EsHistoricalPerformance24Hours.class);
38 historicalPerformanceLogRW = new HtDataBaseReaderAndWriter<>(client, EsHistoricalPerformanceLogEntry.ESDATATYPENAME, EsHistoricalPerformanceLogEntry.class);
40 } catch (Exception e) {
42 LOG.error("Can not start database client. Exception: {}", e.getMessage());
45 LOG.info("Create {} finished. DB Service {} started.", MicrowaveHistoricalPerformanceWriterService.class, client != null ? "sucessfully" : "not" );
49 public void writePM(AllPm pm) {
51 LOG.debug("Write {} pm records", pm.size());
53 LOG.debug("Write 15m write to DB");
54 historicalPerformance15mRW.doWrite(pm.getPm15());
55 LOG.debug("Write 15m done, Write 24h write to DB");
56 historicalPerformance24hRW.doWrite(pm.getPm24());
57 LOG.debug("Write 24h done");
61 public void writePMLog(String mountpointName, String layerProtocolName, String msg) {
63 LOG.debug("Write PM Log: {}", msg);
64 EsHistoricalPerformanceLogEntry logEntry = new EsHistoricalPerformanceLogEntry(mountpointName,layerProtocolName,NetconfTimeStamp.getTimeStamp().getValue() , msg );
65 historicalPerformanceLogRW.doWrite(logEntry);
66 LOG.debug("Write PM Log done");
71 static public boolean isAvailable(MicrowaveHistoricalPerformanceWriterService s) {
73 if (s == null || s.client == null) {