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.openroadm71.impl;
 
  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.netconfnodestateservice.NetconfBindingAccessor;
 
  29 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
 
  30 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.AlarmNotification;
 
  31 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.OrgOpenroadmAlarmListener;
 
  32 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCause;
 
  33 import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev200529.ProbableCauseEnum;
 
  34 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.Resource;
 
  35 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.CircuitPack;
 
  36 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Connection;
 
  37 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Degree;
 
  38 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Device;
 
  39 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Interface;
 
  40 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.InternalLink;
 
  41 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.LineAmplifier;
 
  42 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.OduSncpPg;
 
  43 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Other;
 
  44 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.PhysicalLink;
 
  45 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Port;
 
  46 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Service;
 
  47 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Shelf;
 
  48 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Srg;
 
  49 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.TempService;
 
  50 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.VersionedService;
 
  51 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.Xponder;
 
  52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
 
  53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
 
  54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
 
  55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
  56 import org.slf4j.Logger;
 
  57 import org.slf4j.LoggerFactory;
 
  60  * @author Shabnam Sultana
 
  62  *         Listener for Open roadm device specific alarm notifications
 
  64 public class OpenroadmFaultNotificationListener implements OrgOpenroadmAlarmListener {
 
  65     private static final Logger log = LoggerFactory.getLogger(OpenroadmFaultNotificationListener.class);
 
  67     private final @NonNull FaultService faultEventListener;
 
  68     private @NonNull WebsocketManagerService notificationService;
 
  69     private Integer count = 1;
 
  71     private NetconfBindingAccessor netconfAccessor;
 
  74     public OpenroadmFaultNotificationListener(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
 
  75         this.netconfAccessor = accessor;
 
  76         this.faultEventListener = serviceProvider.getFaultService();
 
  77         this.notificationService = serviceProvider.getWebsocketService();
 
  82     public void onAlarmNotification(AlarmNotification notification) {
 
  83         log.info("AlarmNotification is {} \t {}", notification.getId(), notification.getAdditionalDetail());
 
  84         String affectedResourceName = getAffectedResourceName(notification.getResource().getResource().getResource());
 
  85         String probableCauseName = getProbableCauseName(notification.getProbableCause());
 
  87         if (notification.getId() == null) {
 
  88             log.warn("Alarm ID is null. Not logging alarm information to the DB. Alarm ID should not be null. Please fix the same in the Device");
 
  91         FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(affectedResourceName)
 
  92                 .setProblem(probableCauseName).setSourceType(SourceType.Netconf)
 
  93                 .setTimestamp(notification.getRaiseTime()).setId(notification.getId()).setNodeId(netconfAccessor.getNodeId().getValue())
 
  94                 .setSeverity(InitialDeviceAlarmReader.checkSeverityValue(notification.getSeverity())).setCounter(count)
 
  97         this.faultEventListener.faultNotification(faultAlarm);
 
  98         this.notificationService.sendNotification(notification,new NodeId(netconfAccessor.getNodeId().getValue()), AlarmNotification.QNAME,
 
  99                 notification.getRaiseTime());
 
 101         log.info("Notification is written into the database {}", faultAlarm.getObjectId());
 
 105     public String getAffectedResourceName(Resource affectedResource) {
 
 106         if (affectedResource instanceof CircuitPack) {
 
 107             return ((CircuitPack)affectedResource).getCircuitPackName();
 
 108         } else if (affectedResource instanceof Port) {
 
 109             return ((Port)affectedResource).getPort().getPortName();
 
 110         } else if (affectedResource instanceof Connection) {
 
 111             return ((Connection)affectedResource).getConnectionName();
 
 112         } else if (affectedResource instanceof PhysicalLink) {
 
 113             return ((PhysicalLink)affectedResource).getPhysicalLinkName();
 
 114         } else if (affectedResource instanceof InternalLink) {
 
 115             return ((InternalLink)affectedResource).getInternalLinkName();
 
 116         } else if (affectedResource instanceof Shelf) {
 
 117             return ((Shelf)affectedResource).getShelfName();
 
 118         } else if (affectedResource instanceof Srg) {
 
 119             return "SRG #- " + ((Srg)affectedResource).getSrgNumber().toString();
 
 120         } else if (affectedResource instanceof Degree) {
 
 121             return "Degree - " + ((Degree)affectedResource).getDegreeNumber().toString();
 
 122         } else if (affectedResource instanceof Service) {
 
 123             return ((Service)affectedResource).getServiceName();
 
 124         } else if (affectedResource instanceof Interface) {
 
 125             return ((Interface)affectedResource).getInterfaceName();
 
 126         } else if (affectedResource instanceof OduSncpPg) {
 
 127             return ((OduSncpPg)affectedResource).getOduSncpPgName();
 
 128         } else if (affectedResource instanceof Device) {
 
 129             return ((Device)affectedResource).getNodeId().getValue();
 
 130         } else if (affectedResource instanceof LineAmplifier) {
 
 131             return "LineAmplifier # - " + ((LineAmplifier)affectedResource).getAmpNumber().toString();
 
 132         } else if (affectedResource instanceof Xponder) {
 
 133             return "Xponder # - "+ ((Xponder)affectedResource).getXpdrNumber().toString();
 
 134         } else if (affectedResource instanceof Other) {
 
 135             return ((Other)affectedResource).getOtherResourceId();
 
 136         } else if (affectedResource instanceof VersionedService) {
 
 137             return ((VersionedService)affectedResource).getVersionedServiceName();
 
 138         } else if (affectedResource instanceof TempService) {
 
 139             return ((TempService)affectedResource).getCommonId();
 
 142         log.warn("Unknown Resource {} received from Notification", affectedResource.getClass().getSimpleName());
 
 143         return "Unknown Resource";
 
 146     public String getProbableCauseName(ProbableCause probableCause) {
 
 147         if (probableCause != null) {
 
 148             ProbableCauseEnum pce = probableCause.getCause();
 
 150                 return pce.getName();
 
 152             log.warn("ProbableCauseEnum is NULL");
 
 153             return "Unknown Cause";
 
 155         log.warn("ProbableCause is NULL");
 
 156         return "Unknown Cause";