2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.holmes.common.api.stat;
\r
19 import java.io.Serializable;
\r
20 import java.io.StringReader;
\r
21 import java.lang.reflect.Field;
\r
22 import java.util.Date;
\r
23 import java.util.HashMap;
\r
24 import java.util.HashSet;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
27 import java.util.Set;
\r
28 import lombok.Getter;
\r
29 import lombok.Setter;
\r
30 import org.jdom.Attribute;
\r
31 import org.jdom.Element;
\r
32 import org.jdom.input.SAXBuilder;
\r
33 import org.jdom.output.XMLOutputter;
\r
38 public class Alarm implements AplusData, Cloneable, Serializable {
\r
40 public static final byte EVENT_CLEARED_ALARM = 3;
\r
42 public static final byte EVENT_CHANGED = 2;
\r
44 public static final byte EVENT_CLEARED = 1;
\r
46 public static final byte EVENT_RAISED = 0;
\r
48 private static final long serialVersionUID = 4520003737132012000L;
\r
49 private final static Date clearedServerTime = null;
\r
50 private final Map<Integer, Integer> linkIdNodeIdxMap = new HashMap<Integer, Integer>();
\r
51 private byte eventType = EVENT_RAISED;
\r
52 private long id = 0L;
\r
53 private String alarmKey = "";
\r
54 private String network = "";
\r
55 private String neType = "";
\r
56 private String equipType = "";
\r
57 private String position1 = "";
\r
58 private String subPosition1 = null;
\r
59 private String position2 = null;
\r
60 private String subPosition2 = null;
\r
61 private byte severity = -1;
\r
62 private byte alarmType = -1;
\r
63 private long probableCause = -1;
\r
64 private String specificProblem = null;
\r
65 private String additionalText = null;
\r
66 private Date raisedTime = new Date();
\r
67 private Date raisedServerTime = new Date();
\r
68 private Date clearedTime = null;
\r
69 private String region = null;
\r
70 private String site = null;
\r
71 private String aid = null;
\r
72 private short systemType = -1;
\r
73 private boolean rootAlarmFlag = false;
\r
74 private int linkId = -1;
\r
75 private int nodeIdx = -1;
\r
76 private Set<Integer> linkIds = new HashSet<Integer>();
\r
77 private HashMap<String, Integer> priorityMap = new HashMap<String, Integer>();
\r
78 private HashMap<String, Integer> rootAlarmTypeMap = new HashMap<String, Integer>();
\r
79 private int rootAlarmType = -1;
\r
80 private boolean keyAlarmFlag = false;
\r
81 private int keyAlarmType = -1;
\r
82 private int networkLevel = -1;
\r
83 private int linkType = -1;
\r
84 private int centerType;
\r
86 public static Alarm valueOf(String xmlString) {
\r
89 StringReader sb = new StringReader(xmlString);
\r
90 element = new SAXBuilder().build(sb).getRootElement();
\r
92 } catch (Exception e) {
\r
93 throw new RuntimeException(e);
\r
96 Alarm alarm = new Alarm();
\r
97 @SuppressWarnings("unchecked")
\r
98 List<Attribute> list = element.getAttributes();
\r
99 for (Attribute attr : list) {
\r
100 String attrName = attr.getName();
\r
102 Field field = Alarm.class.getDeclaredField(attrName);
\r
103 if (!attrName.endsWith("Time")) {
\r
104 String type = field.getType().getSimpleName();
\r
105 if ("byte".equals(type)) {
\r
106 field.set(alarm, Byte.parseByte(attr.getValue()));
\r
107 } else if ("long".equals(type)) {
\r
108 field.set(alarm, Long.parseLong(attr.getValue()));
\r
109 } else if ("String".equals(type)) {
\r
110 field.set(alarm, attr.getValue());
\r
112 throw new RuntimeException("unknow attr type: " + type.toString());
\r
115 Date date = new Date();
\r
116 date.setTime(Long.parseLong(attr.getValue()));
\r
117 field.set(alarm, date);
\r
119 } catch (Exception e) {
\r
120 throw new RuntimeException(e);
\r
127 public void addLinkIdNodeIdx(int linkId, int index) {
\r
128 linkIdNodeIdxMap.put(linkId, index);
\r
132 * Comparison of the location of different links: 999 the same link: the location of the node
\r
133 * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1,
\r
134 * the same link: the node position number is equal to the number of position in the otherIdIdx
\r
135 * (in the same site otherIdIdx):0, the same link: the node location number is greater than the
\r
136 * number of locations in otherIdIdx (otherIdIdx) with the site):1,
\r
138 public int CompareLinkPosition(Map<Integer, Integer> otherIdIdx) {
\r
139 Set<Integer> myIdSet = new HashSet<Integer>();
\r
140 myIdSet.addAll(this.linkIdNodeIdxMap.keySet());
\r
141 myIdSet.retainAll(otherIdIdx.keySet());
\r
143 if (myIdSet.isEmpty()) {
\r
147 for (int tempLinkId : myIdSet) {
\r
148 return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId);
\r
153 public boolean containNode(int linkId, int index) {
\r
154 return linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index;
\r
158 public byte getDataType() {
\r
159 return APLUS_EVENT;
\r
163 public String toString() {
\r
164 final String nullStr = "<null>";
\r
166 Element el = new Element("Alarm");
\r
167 el.setAttribute("id", String.valueOf(id));
\r
168 el.setAttribute("aid", String.valueOf(aid));
\r
169 el.setAttribute("alarmKey", String.valueOf(alarmKey));
\r
170 el.setAttribute("eventType", String.valueOf(eventType));
\r
171 el.setAttribute("region", region == null ? nullStr : region);
\r
172 el.setAttribute("site", site == null ? nullStr : site);
\r
173 el.setAttribute("network", network);
\r
174 el.setAttribute("neType", neType);
\r
175 el.setAttribute("equipType", equipType);
\r
176 el.setAttribute("position1", position1);
\r
177 el.setAttribute("subPosition1", subPosition1 == null ? nullStr : subPosition1);
\r
178 el.setAttribute("position2", position2 == null ? nullStr : position2);
\r
179 el.setAttribute("subPosition2", subPosition2 == null ? nullStr : subPosition2);
\r
180 el.setAttribute("severity", String.valueOf(severity));
\r
181 el.setAttribute("alarmType", String.valueOf(alarmType));
\r
182 el.setAttribute("probableCause", String.valueOf(probableCause));
\r
183 el.setAttribute("specificProblem", specificProblem == null ? nullStr : specificProblem);
\r
184 el.setAttribute("additionalText", additionalText == null ? nullStr : additionalText);
\r
185 el.setAttribute("raisedTime", String.valueOf(raisedTime.getTime()));
\r
186 el.setAttribute("raisedServerTime", String.valueOf(raisedServerTime.getTime()));
\r
187 if (clearedTime != null) {
\r
188 el.setAttribute("clearedTime", String.valueOf(clearedTime.getTime()));
\r
190 if (clearedServerTime != null) {
\r
191 el.setAttribute("clearedServerTime", String.valueOf(clearedServerTime.getTime()));
\r
194 return new XMLOutputter().outputString(el);
\r
198 public int hashCode() {
\r
199 return this.getAlarmKey().hashCode();
\r
203 public boolean equals(Object arg0) {
\r
204 if (arg0 == null || !(arg0 instanceof Alarm)) {
\r
207 return this.alarmKey.equals(((Alarm) arg0).getAlarmKey());
\r
211 public Object clone() throws CloneNotSupportedException {
\r
214 Alarm alarm = new Alarm();
\r
216 alarm.setEventType(this.getEventType());
\r
218 alarm.setAid(this.getAid());
\r
219 alarm.setId(this.getId());
\r
220 alarm.setAlarmKey(this.getAlarmKey());
\r
222 alarm.setNetwork(this.getNetwork());
\r
223 alarm.setEquipType(this.getEquipType());
\r
224 alarm.setNeType(this.getNeType());
\r
225 alarm.setPosition1(this.getPosition1());
\r
226 alarm.setSubPosition1(this.getSubPosition1());
\r
227 alarm.setPosition2(this.getPosition2());
\r
228 alarm.setSubPosition2(this.getSubPosition2());
\r
229 alarm.setRegion(this.getRegion());
\r
230 alarm.setSite(this.getSite());
\r
232 alarm.setSeverity(this.getSeverity());
\r
233 alarm.setAlarmType(this.getAlarmType());
\r
234 alarm.setSystemType(this.getSystemType());
\r
235 alarm.setSpecificProblem(this.getSpecificProblem());
\r
236 alarm.setAdditionalText(this.getAdditionalText());
\r
237 alarm.setProbableCause(this.getProbableCause());
\r
239 alarm.setRaisedTime(this.getRaisedTime());
\r
240 alarm.setRaisedServerTime(this.getRaisedServerTime());
\r
241 alarm.setClearedTime(this.getClearedTime());
\r
247 public String getObjectId() {
\r
248 return String.valueOf(id);
\r
251 public void addLinkIds(int linkId) {
\r
252 linkIds.add(linkId);
\r
256 public boolean containsPriority(String ruleId) {
\r
257 if (priorityMap.keySet().contains(ruleId)) {
\r
263 public int getPriority(String ruleId) {
\r
264 Integer priority = this.priorityMap.get(ruleId);
\r
265 if (priority == null) {
\r
271 public int getRootAlarmType(String ruleId) {
\r
272 Integer rootAlarmType = this.rootAlarmTypeMap.get(ruleId);
\r
273 if (rootAlarmType == null) {
\r
274 rootAlarmType = -1;
\r
276 return rootAlarmType;
\r