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;
 
  24 import java.util.Collection;
 
  25 import java.util.List;
 
  26 import java.util.Optional;
 
  27 import org.eclipse.jdt.annotation.NonNull;
 
  28 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
 
  29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
 
  31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
 
  32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
 
  33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
 
  34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 
  35 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.ActiveAlarmList;
 
  36 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.Severity;
 
  37 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarms;
 
  38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog;
 
  39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
 
  40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  41 import org.slf4j.Logger;
 
  42 import org.slf4j.LoggerFactory;
 
  45  * @author Shabnam Sultana
 
  47  *         Class to read the initial alarms at the time of device registration
 
  51 public class InitialDeviceAlarmReader {
 
  53     // in fact there is no alarm counter in the alarm obj, we have to do it on our own globally per device
 
  54     private Integer alarmCounter = 1;
 
  55     private static final Logger log = LoggerFactory.getLogger(InitialDeviceAlarmReader.class);
 
  56     private final NetconfBindingAccessor netConfAccesor;
 
  57     private final @NonNull FaultService faultEventListener;
 
  58     private final DataProvider dataProvider;
 
  62     public InitialDeviceAlarmReader(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
 
  63         this.netConfAccesor = accessor;
 
  64         this.faultEventListener = serviceProvider.getFaultService();
 
  65         this.dataProvider = serviceProvider.getDataProvider();
 
  67     // end of constructors
 
  70     // Mapping the alarm data with the fault data
 
  71     protected FaultData writeFaultData() {
 
  72         FaultData faultData = new FaultData();
 
  73         Optional<ActiveAlarmList> list = this.getActiveAlarmList(this.netConfAccesor);
 
  74         if (list.isPresent() && list.get().getActiveAlarms() != null) {
 
  75             Collection<ActiveAlarms> activeAlarms = YangHelper.getCollection(list.get().getActiveAlarms());
 
  76             if (!activeAlarms.isEmpty()) {
 
  77                 for (ActiveAlarms activeAlarm : activeAlarms) {
 
  78                     faultData.add(this.netConfAccesor.getNodeId(), this.alarmCounter, activeAlarm.getRaiseTime(),
 
  79                             activeAlarm.getResource().getDevice().getNodeId().getValue(),
 
  80                             activeAlarm.getProbableCause().getCause().getName(),
 
  81                             checkSeverityValue(activeAlarm.getSeverity()));
 
  90     // Write into the FaultLog
 
  91     protected void writeAlarmLog(FaultData faultData) {
 
  92         if (faultData != null) {
 
  93             List<Faultlog> faultLog = faultData.getProblemList();
 
  94             for (Faultlog fe : faultLog) {
 
  95                 this.dataProvider.writeFaultLog(fe);
 
 100     // Use the FaultService for Alarm notifications
 
 101     protected void faultService() {
 
 102         this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData());
 
 103         writeAlarmLog(writeFaultData());
 
 105     // Mapping Severity of AlarmNotification to SeverityType of FaultLog
 
 106     protected static SeverityType checkSeverityValue(Severity severity) {
 
 107         SeverityType severityType = null;
 
 108         log.info("Device Severity: {}", severity.getName());
 
 110         switch (severity.getName()) {
 
 112                 severityType = SeverityType.Warning;
 
 115                 severityType = SeverityType.Major;
 
 118                 severityType = SeverityType.Minor;
 
 121                 severityType = SeverityType.NonAlarmed;
 
 124                 severityType = SeverityType.Critical;
 
 126             case ("indeterminate"):
 
 127                 severityType = SeverityType.Critical;
 
 130                 severityType = SeverityType.Critical;
 
 137     // end of protected methods
 
 142     private Optional<ActiveAlarmList> getActiveAlarmList(NetconfBindingAccessor accessor) {
 
 143         final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
 
 144         log.info("Get Alarm data for element {}", accessor.getNodeId().getValue());
 
 145         InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
 
 147         ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
 
 148                 LogicalDatastoreType.OPERATIONAL, alarmDataIid);
 
 150         log.info("AlarmData {}", alarmData);
 
 151         return Optional.ofNullable(alarmData);
 
 155     // end of private methods