2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs;
24 import com.google.common.collect.Sets;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.Optional;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.mdsal.dom.api.DOMNotification;
37 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
42 import org.opendaylight.yangtools.yang.common.QName;
43 import org.opendaylight.yangtools.yang.common.QNameModule;
44 import org.opendaylight.yangtools.yang.common.Revision;
45 import org.opendaylight.yangtools.yang.common.XMLNamespace;
46 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
47 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
48 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
49 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
50 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
51 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
53 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
54 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
55 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
59 public class Alarms10 extends YangModule {
61 private static final Logger LOG = LoggerFactory.getLogger(Alarms10.class);
63 private static final String NAMESPACE = "urn:onf:yang:alarms-1-0";
64 private static final List<QNameModule> MODULES =
65 Arrays.asList(QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2022-03-02")),
66 QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2022-07-29")));
68 private final QName ALARM_PAC;
69 private final QName CURRENT_ALARMS;
70 private final QName CURRENT_ALARM_LIST;
71 private final QName CURRENT_ALARM_IDENTIFIER;
72 private final QName ALARM_TYPE_ID;
73 private final QName ALARM_TYPE_QUALIFIER;
74 private final QName RESOURCE;
75 private final QName ALARM_SEVERITY;
76 private final QName ALARM_TIMESTAMP;
77 private final QName ALARM_EVENT_SEQUENCE_NUMBER;
78 private final QName PROBLEM_SEVERITY;
79 private final QName ALARM_AVC_NOTIFICATION;
80 private final QName ALARM_EVENT_NOTIFICATION;
82 private final CoreModel14 coreModel14;
84 private Alarms10(NetconfDomAccessor netconfDomAccessor, QNameModule module, CoreModel14 coreModel14) {
85 super(netconfDomAccessor, module);
86 this.coreModel14 = coreModel14;
88 ALARM_PAC = QName.create(module, "alarm-pac");
89 CURRENT_ALARMS = QName.create(module, "current-alarms");
90 CURRENT_ALARM_LIST = QName.create(module, "current-alarm-list");
91 CURRENT_ALARM_IDENTIFIER = QName.create(module, "current-alarm-identifier");
92 ALARM_TYPE_ID = QName.create(module, "alarm-type-id");
93 ALARM_TYPE_QUALIFIER = QName.create(module, "alarm-type-qualifier");
94 RESOURCE = QName.create(module, "resource");
95 ALARM_SEVERITY = QName.create(module, "alarm-severity");
96 ALARM_TIMESTAMP = QName.create(module, "timestamp");
97 ALARM_EVENT_SEQUENCE_NUMBER = QName.create(module, "alarm-event-sequence-number");
98 PROBLEM_SEVERITY = QName.create(module, "problem-severity");
99 ALARM_AVC_NOTIFICATION = QName.create(module, "attribute-value-changed-notification");
100 ALARM_EVENT_NOTIFICATION = QName.create(module, "alarm-event-notification");
103 public QNameModule getModule() {
107 public FaultlogEntity getFaultlogEntity(ContainerNode cn) {
108 return new FaultlogBuilder().setNodeId(getNodeId().getValue()).setSourceType(SourceType.Netconf)
109 .setObjectId(Onf14DMDOMUtility.getLeafValueUuid(cn, RESOURCE))
110 .setProblem(Onf14DMDOMUtility.getLeafValue(cn, ALARM_TYPE_QUALIFIER))
111 .setTimestamp(Onf14DMDOMUtility.getLeafValueDateAndTime(cn, ALARM_TIMESTAMP))
112 .setSeverity(Onf14DMDOMUtility.getLeafValueInternalSeverity(cn, PROBLEM_SEVERITY))
113 .setCounter(Onf14DMDOMUtility.getLeafValueInt(cn, ALARM_EVENT_SEQUENCE_NUMBER)).build();
116 public boolean isAlarmEventNotification(DOMNotification domNotification) {
117 return domNotification.getType().equals(Absolute.of(ALARM_EVENT_NOTIFICATION));
120 public void doRegisterNotificationListener(DOMNotificationListener alarmNotifListener) {
121 QName[] alarmNotifications = {ALARM_AVC_NOTIFICATION, ALARM_EVENT_NOTIFICATION};
122 netconfDomAccessor.doRegisterNotificationListener(alarmNotifListener, alarmNotifications);
125 public void sendNotification(@NonNull WebsocketManagerService websocketService, DOMNotification domNotification,
127 websocketService.sendNotification(domNotification, getNodeId(), ALARM_TYPE_QUALIFIER,
128 Onf14DMDOMUtility.getLeafValueDateAndTime(cn, ALARM_TIMESTAMP));
131 public FaultData getCurrentAlarms() {
133 YangInstanceIdentifier alarmsPacIID =
134 YangInstanceIdentifier.builder().node(coreModel14.getControlConstructQName()).build();
137 AugmentationIdentifier alarmsContainerIID =
138 YangInstanceIdentifier.AugmentationIdentifier.create(Sets.newHashSet(ALARM_PAC));
140 InstanceIdentifierBuilder augmentedAlarmsIID =
141 YangInstanceIdentifier.builder(alarmsPacIID).node(alarmsContainerIID);
143 // reading all the alarms
144 Optional<NormalizedNode> alarms =
145 this.getNetconfDomAccessor().readDataNode(LogicalDatastoreType.OPERATIONAL, augmentedAlarmsIID.build());
147 FaultData resultList = new FaultData();
148 if (alarms.isPresent()) {
149 AugmentationNode alarmsDataNode = (AugmentationNode) alarms.get();
150 ContainerNode alarmsContainer = (ContainerNode) alarmsDataNode.childByArg(new NodeIdentifier(ALARM_PAC));
151 ContainerNode currentAlarmsContainer =
152 (ContainerNode) alarmsContainer.childByArg(new NodeIdentifier(CURRENT_ALARMS));
153 MapNode currentAlarmsList =
154 (MapNode) currentAlarmsContainer.childByArg(new NodeIdentifier(CURRENT_ALARM_LIST));
155 if (currentAlarmsList != null) {
156 Collection<MapEntryNode> currentAlarmsCollection = currentAlarmsList.body();
157 for (MapEntryNode currentAlarm : currentAlarmsCollection) {
158 resultList.add(getNodeId(),
159 Onf14DMDOMUtility.getLeafValueInt(currentAlarm, CURRENT_ALARM_IDENTIFIER),
160 Onf14DMDOMUtility.getLeafValueDateAndTime(currentAlarm, ALARM_TIMESTAMP),
161 Onf14DMDOMUtility.getLeafValueUuid(currentAlarm, RESOURCE),
162 Onf14DMDOMUtility.getLeafValue(currentAlarm, ALARM_TYPE_QUALIFIER),
163 Onf14DMDOMUtility.getLeafValueInternalSeverity(currentAlarm, ALARM_SEVERITY));
166 LOG.debug("DBRead empty CurrentProblemList");
172 public boolean isSupported(Capabilities capabilites) {
173 return netconfDomAccessor.getCapabilites().isSupportingNamespace(NAMESPACE);
176 private NodeId getNodeId() {
177 return netconfDomAccessor.getNodeId();
181 * Get specific instance, depending on capabilities
183 * @param capabilities
186 public static Optional<Alarms10> getModule(NetconfDomAccessor netconfDomAccessor, CoreModel14 coreModel14) {
187 Capabilities capabilities = netconfDomAccessor.getCapabilites();
188 for (QNameModule module : MODULES) {
189 if (capabilities.isSupportingNamespaceAndRevision(module)) {
190 return Optional.of(new Alarms10(netconfDomAccessor, module, coreModel14));
193 return Optional.empty();