6c3ebd60a23632a62b87c7e9139529bbfb981090
[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.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.AlarmNotification;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * @author Shabnam Sultana
37  *
38  *         Listener for Open roadm device specific alarm notifications
39  **/
40 public class OpenroadmFaultNotificationListener implements OrgOpenroadmAlarmListener {
41     private static final Logger log = LoggerFactory.getLogger(OpenroadmFaultNotificationListener.class);
42     // variables
43     private final @NonNull FaultService faultEventListener;
44     private Integer count = 1;
45     // end of variables
46     // constructors
47     public OpenroadmFaultNotificationListener(DeviceManagerServiceProvider serviceProvider) {
48         this.faultEventListener = serviceProvider.getFaultService();
49
50     }
51     // end of constructors
52     // public methods
53     @Override
54     public void onAlarmNotification(AlarmNotification notification) {
55
56
57         log.info("AlarmNotification {} \t {}", notification.getId(), notification.getAdditionalDetail());
58
59         FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(notification.getCircuitId())
60                 .setProblem(notification.getProbableCause().getCause().getName())
61                 .setTimestamp(notification.getRaiseTime()).setId(notification.getId())
62                 .setNodeId(notification.getResource().getDevice().getNodeId().getValue())
63                 .setSeverity(InitialDeviceAlarmReader.checkSeverityValue(notification.getSeverity())).setCounter(count)
64                 .build();
65
66         this.faultEventListener.faultNotification(faultAlarm);
67         count++;
68         log.info("Notification is written into the database {}", faultAlarm.getObjectId());
69
70     }
71
72     // end of public methods
73
74 }