Add data-provider
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / performancemanager / impl / database / types / EsHistoricalPerformanceBase.java
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.types;
19
20 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.EsObject;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.LinkIdentifyingObject;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp;
23 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
24 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.OtnHistoryDataG;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import com.fasterxml.jackson.annotation.JsonGetter;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30
31 public class EsHistoricalPerformanceBase extends EsObject {
32
33     private static final Logger LOG = LoggerFactory.getLogger(EsHistoricalPerformanceBase.class);
34     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
35
36     @JsonIgnore private final String nodeName;
37     @JsonIgnore private final String uuidInterface;
38     @JsonIgnore private final String layerProtocolName;
39
40     @JsonIgnore private String radioSignalId = null;  //Meaning of connection Id
41     @JsonIgnore private String timeStamp = null;
42     @JsonIgnore private Boolean suspectIntervalFlag = null;
43     @JsonIgnore private String granularityPeriod = null;  //Representation of GranularityPeriodType
44     @JsonIgnore private String scannerId = null;
45     @JsonIgnore private Object performanceData = null;
46
47
48     public EsHistoricalPerformanceBase(String nodeName, Lp actualInterface) {
49         this.nodeName = nodeName;
50         this.uuidInterface = actualInterface.getUuid().getValue();
51         this.layerProtocolName = actualInterface.getLayerProtocolName().getValue();
52
53     }
54
55     protected <T extends OtnHistoryDataG> void set(T record) {
56         if (record == null) {
57             LOG.warn("PM Record: null record. Can not handle");
58             return;
59         }
60
61         if (LOG.isTraceEnabled()) {
62             LOG.trace("PM Record: class {} '{}' ", record.getClass().getSimpleName(), record);
63         }
64
65         timeStamp = NETCONFTIME_CONVERTER.getTimeStampFromNetconf(record.getPeriodEndTime().getValue());
66         suspectIntervalFlag = record.isSuspectIntervalFlag();
67         granularityPeriod = getYangGranularityPeriodString( record.getGranularityPeriod() );
68         scannerId = record.getHistoryDataId();
69
70         if (record instanceof LinkIdentifyingObject) {
71             radioSignalId = ((LinkIdentifyingObject) record).getSignalId();
72         }
73
74         performanceData = new EsPerformanceData(record);
75         setEsId(genSpecificEsId(record.getPeriodEndTime().getValue()));
76     }
77
78
79     @JsonGetter("node-name")
80     public String getNodeName() {
81         return nodeName;
82     }
83
84     @JsonGetter("uuid-interface")
85     public String getUuidInterface() {
86         return uuidInterface;
87     }
88
89     @JsonGetter("layer-protocol-name")
90     public String getLayerProtocolName() {
91         return layerProtocolName;
92     }
93
94     @JsonGetter("radio-signal-id")
95     public String getRadioSignalId() {
96         return radioSignalId;
97     }
98
99     @JsonGetter("time-stamp")
100     public String getTimeStamp() {
101         return timeStamp;
102     }
103
104     @JsonGetter("suspect-interval-flag")
105     public Boolean getSuspect() {
106         return suspectIntervalFlag;
107     }
108
109     @JsonGetter("granularity-period")
110     public String getGranularityPeriod() {
111         return granularityPeriod;
112     }
113
114     @JsonGetter("scanner-id")
115     public String getScannerId() {
116         return scannerId;
117     }
118
119     @JsonGetter("performance-data")
120     public Object getData() {
121         return performanceData;
122     }
123
124
125
126     //Adapt JSON Text
127     //@JsonGetter("granularityPeriod")
128
129     private static String getYangGranularityPeriodString(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType yangGanularityPeriod) {
130         switch(yangGanularityPeriod == null ? org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType.Unknown : yangGanularityPeriod) {
131             case Period15Min:
132                 return "PERIOD_15MIN";
133             case Period24Hours:
134                 return "PERIOD_24HOURS";
135             default:
136                 return "PERIOD_UNKOWN";
137         }
138     }
139
140     /**
141      * Create a specific ES id for the current log.
142      * @param time is the input.
143      * @return a string with the generated ES Id
144      */
145     protected String genSpecificEsId(String time) {
146
147         StringBuffer strBuf = new StringBuffer();
148         strBuf.append(nodeName);
149         strBuf.append("/");
150         strBuf.append(uuidInterface);
151         strBuf.append("/");
152         strBuf.append(time == null || time.isEmpty() ? "Empty" : time);
153
154         return strBuf.toString();
155     }
156
157     @Override
158     public String toString() {
159         return "EsHistoricalPerformanceBase [nodeName=" + nodeName + ", uuidInterface=" + uuidInterface
160                 + ", layerProtocolName=" + layerProtocolName + ", radioSignalId=" + radioSignalId + ", timeStamp="
161                 + timeStamp + ", suspectIntervalFlag=" + suspectIntervalFlag + ", granularityPeriod="
162                 + granularityPeriod + ", scannerId=" + scannerId + ", performanceData=" + performanceData + "]";
163     }
164
165 }