dcb299a8eb4b7002c77a1eeef7cf2de49d75ee81
[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.database.FaultEntityManager;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
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.rev190801.Faultcurrent;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
34 import org.slf4j.Logger;
35
36 @XmlRootElement(name = "ProblemNotification")
37 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType {
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
53      * 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     /**
91      * Create a specific ES id for the current log.
92      * @return a string with the generated ES Id
93      */
94     @JsonIgnore
95     public String genSpecificEsId() {
96         return FaultEntityManager.genSpecificEsId(getNodeName(), getObjectId(), getProblem());
97     }
98
99     @JsonIgnore
100     public Faultlog getFaultlog(SourceType sourceType) {
101         return new FaultlogBuilder().setNodeId(getNodeName()).setCounter(Integer.parseInt(getCounter()))
102                 .setObjectId(getObjectId()).setProblem(getProblem()).setSourceType(sourceType)
103                 .setSeverity(getSeverity().toDataProviderSeverityType()).setTimestamp(new DateAndTime(getTimeStamp()))
104                 .build();
105     }
106
107     @JsonIgnore
108     public Faultcurrent getFaultcurrent() {
109         return new FaultcurrentBuilder().setNodeId(getNodeName()).setCounter(Integer.parseInt(getCounter()))
110                 .setObjectId(genSpecificEsId()).setProblem(getProblem())
111                 .setSeverity(getSeverity().toDataProviderSeverityType()).setTimestamp(new DateAndTime(getTimeStamp()))
112                 .build();
113     }
114
115     @Override
116     public String toString() {
117         return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
118                 + super.toString() + "]";
119     }
120
121     @Override
122     public String getEventType() {
123         return EVENTTYPE;
124     }
125
126     /**
127      * LOG the newly added problems of the interface pac
128      * @param log of logger
129      * @param uuid as log info
130      * @param resultList with all problems
131      * @param idxStart start of listing till end
132      */
133     public static void debugResultList(Logger log, String uuid, List<ProblemNotificationXml> resultList, int idxStart) {
134         if (log.isDebugEnabled()) {
135             StringBuffer sb = new StringBuffer();
136             int idx = 0;
137             for (int t = idxStart; t < resultList.size(); t++) {
138                 sb.append(idx++);
139                 sb.append(":{");
140                 sb.append(resultList.get(t));
141                 sb.append('}');
142             }
143             log.debug("Found problems {} {}", uuid, sb.toString());
144         }
145     }
146 }