10d0a5640cff3a0e1bf92cf31c63d5f95a7599c0
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
23
24
25 import org.eclipse.jdt.annotation.NonNull;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
28 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.AlarmNotification;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener;
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 import org.slf4j.LoggerFactory;
36
37 /**
38  * @author Shabnam Sultana
39  *
40  *         Listener for Open roadm device specific alarm notifications
41  **/
42 public class OpenroadmFaultNotificationListener implements OrgOpenroadmAlarmListener {
43     private static final Logger log = LoggerFactory.getLogger(OpenroadmFaultNotificationListener.class);
44
45     private final @NonNull FaultService faultEventListener;
46     private @NonNull WebsocketManagerService notificationService;
47     private Integer count = 1;
48
49
50     public OpenroadmFaultNotificationListener(DeviceManagerServiceProvider serviceProvider) {
51         this.faultEventListener = serviceProvider.getFaultService();
52         this.notificationService = serviceProvider.getWebsocketService();
53
54     }
55
56     @Override
57     public void onAlarmNotification(AlarmNotification notification) {
58
59
60         log.info("AlarmNotification {} \t {}", notification.getId(), notification.getAdditionalDetail());
61         final String nodeId = notification.getResource().getDevice().getNodeId().getValue();
62         FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(notification.getCircuitId())
63                 .setProblem(notification.getProbableCause().getCause().getName()).setSourceType(SourceType.Netconf)
64                 .setTimestamp(notification.getRaiseTime()).setId(notification.getId()).setNodeId(nodeId)
65                 .setSeverity(InitialDeviceAlarmReader.checkSeverityValue(notification.getSeverity())).setCounter(count)
66                 .build();
67
68         this.faultEventListener.faultNotification(faultAlarm);
69         this.notificationService.sendNotification(notification, nodeId, AlarmNotification.QNAME,
70                 notification.getRaiseTime());
71         count++;
72         log.info("Notification is written into the database {}", faultAlarm.getObjectId());
73
74     }
75
76
77
78 }