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