33db3baedf951bf350fe3a97ba1f398f0ebd084c
[ccsdk/features.git] /
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.impl.xml;
19
20 import com.fasterxml.jackson.annotation.JsonIgnore;
21 import java.util.List;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.ToggleAlarmFilterable;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultcurrent;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
34 import org.slf4j.Logger;
35
36 @Deprecated
37 @XmlRootElement(name = "ProblemNotification")
38 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType, ToggleAlarmFilterable {
39
40     private static String EVENTTYPE = "ProblemNotification";
41
42     @XmlElement(name = "problem")
43     private String problem;
44
45     @XmlElement(name = "severity")
46     private InternalSeverity severity;
47
48     public ProblemNotificationXml() {
49
50     }
51
52     /**
53      * Generic Problem. All the parameters are of type Strings according to YANG specification.
54      *
55      * @param nodeName Name of mountpoint
56      * @param uuId Name of Interface Pac
57      * @param problemNameString Name of the problem
58      * @param problemSeverityString Severitycode of the problem
59      * @param counter Counter from device
60      * @param internaltimeStampString Timestamp according to internal format.
61      */
62     public ProblemNotificationXml(String nodeName, String uuId, String problemNameString,
63             InternalSeverity problemSeverityString, Integer counter, InternalDateAndTime internaltimeStampString) {
64         super(nodeName, counter, internaltimeStampString, uuId);
65         this.problem = problemNameString;
66         this.severity = problemSeverityString;
67     }
68
69     public ProblemNotificationXml(FaultlogEntity input) {
70         this(input.getNodeId(), input.getObjectId(), input.getProblem(), InternalSeverity.valueOf(input.getSeverity()),
71                 input.getCounter(), InternalDateAndTime.valueOf(input.getTimestamp()));
72     }
73
74     public String getProblem() {
75         return problem;
76     }
77
78     public InternalSeverity getSeverity() {
79         return severity;
80     }
81
82     public boolean isNotManagedAsCurrentProblem() {
83         return !FaultEntityManager.isManagedAsCurrentProblem(getProblem());
84     }
85
86     public boolean isNoAlarmIndication() {
87         return severity.isNoAlarmIndication();
88     }
89
90     @Override
91     public String getUuidForMountpoint() {
92         return genSpecificEsId();
93     }
94
95     @Override
96     public boolean isCleared() {
97         return !isNotManagedAsCurrentProblem() && isNoAlarmIndication();
98     }
99
100
101     /**
102      * Create a specific ES id for the current log.
103      *
104      * @return a string with the generated ES Id
105      */
106     @JsonIgnore
107     public String genSpecificEsId() {
108         return FaultEntityManager.genSpecificEsId(getNodeName(), getObjectId(), getProblem());
109     }
110
111     @JsonIgnore
112     public Faultlog getFaultlog(SourceType sourceType) {
113         return new FaultlogBuilder().setNodeId(getNodeName()).setCounter(Integer.parseInt(getCounter()))
114                 .setObjectId(getObjectId()).setProblem(getProblem()).setSourceType(sourceType)
115                 .setSeverity(getSeverity().toDataProviderSeverityType()).setTimestamp(new DateAndTime(getTimeStamp()))
116                 .build();
117     }
118
119     @JsonIgnore
120     public Faultcurrent getFaultcurrent() {
121         return new FaultcurrentBuilder().setNodeId(getNodeName()).setCounter(Integer.parseInt(getCounter()))
122                 .setObjectId(genSpecificEsId()).setProblem(getProblem())
123                 .setSeverity(getSeverity().toDataProviderSeverityType()).setTimestamp(new DateAndTime(getTimeStamp()))
124                 .build();
125     }
126
127     @Override
128     public String toString() {
129         return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
130                 + super.toString() + "]";
131     }
132
133
134     @Override
135     public String getEventType() {
136         return EVENTTYPE;
137     }
138
139     /**
140      * LOG the newly added problems of the interface pac
141      *
142      * @param log of logger
143      * @param uuid as log info
144      * @param resultList with all problems
145      * @param idxStart start of listing till end
146      */
147     public static void debugResultList(Logger log, String uuid, List<ProblemNotificationXml> resultList, int idxStart) {
148         if (log.isDebugEnabled()) {
149             StringBuffer sb = new StringBuffer();
150             int idx = 0;
151             for (int t = idxStart; t < resultList.size(); t++) {
152                 sb.append(idx++);
153                 sb.append(":{");
154                 sb.append(resultList.get(t));
155                 sb.append('}');
156             }
157             log.debug("Found problems {} {}", uuid, sb.toString());
158         }
159     }
160
161 }