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.openroadm.impl;
 
  24 import java.util.Collection;
 
  25 import java.util.List;
 
  26 import org.eclipse.jdt.annotation.NonNull;
 
  27 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
 
  28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
 
  31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
 
  32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
 
  33 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 
  34 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList;
 
  35 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity;
 
  36 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms;
 
  37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog;
 
  38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
 
  39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  40 import org.slf4j.Logger;
 
  41 import org.slf4j.LoggerFactory;
 
  44  * @author Shabnam Sultana
 
  46  *         Class to read the initial alarms at the time of device registration
 
  50 public class InitialDeviceAlarmReader {
 
  52     private Integer count = 1;
 
  53     private static final Logger log = LoggerFactory.getLogger(InitialDeviceAlarmReader.class);
 
  54     private final NetconfBindingAccessor netConfAccesor;
 
  55     private final @NonNull FaultService faultEventListener;
 
  56     private final DataProvider dataProvider;
 
  60     public InitialDeviceAlarmReader(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
 
  61         this.netConfAccesor = accessor;
 
  62         this.faultEventListener = serviceProvider.getFaultService();
 
  63         this.dataProvider = serviceProvider.getDataProvider();
 
  65     // end of constructors
 
  68     // Mapping the alarm data with the fault data
 
  69     protected FaultData writeFaultData() {
 
  70         FaultData faultData = new FaultData();
 
  71         ActiveAlarmList actAlarmList = this.getActiveAlarmList(this.netConfAccesor);
 
  72         if (actAlarmList != null) {
 
  73             Collection<ActiveAlarms> activeAlarms = YangHelper.getCollection(actAlarmList.getActiveAlarms());
 
  74             if (!activeAlarms.isEmpty()) {
 
  75                 for (ActiveAlarms activeAlarm : activeAlarms) {
 
  76                     faultData.add(this.netConfAccesor.getNodeId(), this.count, activeAlarm.getRaiseTime(),
 
  77                             activeAlarm.getResource().getDevice().getNodeId().getValue(),
 
  78                             activeAlarm.getProbableCause().getCause().getName(),
 
  79                             checkSeverityValue(activeAlarm.getSeverity()));
 
  88     // Write into the FaultLog
 
  89     protected void writeAlarmLog(FaultData faultData) {
 
  90         if (faultData != null) {
 
  91             List<Faultlog> faultLog = faultData.getProblemList();
 
  92             for (Faultlog fe : faultLog) {
 
  93                 this.dataProvider.writeFaultLog(fe);
 
  98     // Use the FaultService for Alarm notifications
 
  99     protected void faultService() {
 
 100         this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData());
 
 101         writeAlarmLog(writeFaultData());
 
 103     // Mapping Severity of AlarmNotification to SeverityType of FaultLog
 
 104     protected static SeverityType checkSeverityValue(Severity severity) {
 
 105         SeverityType severityType = null;
 
 106         log.info("Device Severity: {}", severity.getName());
 
 108         switch (severity.getName()) {
 
 110                 severityType = SeverityType.Warning;
 
 113                 severityType = SeverityType.Major;
 
 116                 severityType = SeverityType.Minor;
 
 119                 severityType = SeverityType.NonAlarmed;
 
 122                 severityType = SeverityType.Critical;
 
 124             case ("indeterminate"):
 
 125                 severityType = SeverityType.Critical;
 
 128                 severityType = SeverityType.Critical;
 
 135     // end of protected methods
 
 140     private ActiveAlarmList getActiveAlarmList(NetconfBindingAccessor accessor) {
 
 141         final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
 
 142         log.info("Get Alarm data for element {}", accessor.getNodeId().getValue());
 
 143         InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
 
 145         ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
 
 146                 LogicalDatastoreType.OPERATIONAL, alarmDataIid);
 
 148         log.info("AlarmData {}", alarmData);
 
 153     // end of private methods