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.List;
 
  25 import org.eclipse.jdt.annotation.NonNull;
 
  26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
 
  27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
 
  28 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener;
 
  29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
 
  30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification;
 
  31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDeviceListener;
 
  32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OtdrScanResult;
 
  33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit;
 
  34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
 
  35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
 
  36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
  38 import org.slf4j.Logger;
 
  39 import org.slf4j.LoggerFactory;
 
  42  * @author Shabnam Sultana
 
  44  *         Listener for Open roadm device specific change notifications
 
  47 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
 
  49     private static final Logger log = LoggerFactory.getLogger(OrgOpenroadmAlarmListener.class);
 
  50     private Integer counter = 1;
 
  51     private final NetconfAccessor netconfAccessor;
 
  52     private final DataProvider databaseProvider;
 
  56     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
 
  57         this.netconfAccessor = netconfAccessor;
 
  58         this.databaseProvider = databaseService;
 
  60     // end of constructors
 
  64     public void onOtdrScanResult(OtdrScanResult notification) {
 
  65         // TODO Auto-generated method stub
 
  70     public void onChangeNotification(ChangeNotification notification) {
 
  71         log.info("onDeviceConfigChange(1){}", notification);
 
  72         StringBuffer sb = new StringBuffer();
 
  75         List<Edit> editList = notification.nonnullEdit();
 
  76         for (Edit edit : editList) {
 
  77             if (sb.length() > 0) {
 
  82             EventlogBuilder eventlogBuilder = new EventlogBuilder();
 
  84             InstanceIdentifier<?> target = edit.getTarget();
 
  86                 eventlogBuilder.setObjectId(target.getPathArguments().toString());
 
  87                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
 
  88                 for (PathArgument pa : target.getPathArguments()) {
 
  89                     log.info("PathArgument {}", pa);
 
  91                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
 
  93             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
 
  95             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
 
  96             eventlogBuilder.setTimestamp(notification.getChangeTime());
 
  97             eventlogBuilder.setCounter(counter);
 
  98             eventlogBuilder.setSourceType(SourceType.Netconf);
 
  99             databaseProvider.writeEventLog(eventlogBuilder.build());
 
 101             log.info("onDeviceConfigChange (2) {}", sb);
 
 107     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
 
 108         // TODO Auto-generated method stub
 
 109         log.info("onCreateTechInfoNotification(1){}", notification);
 
 111         EventlogBuilder eventlogBuilder = new EventlogBuilder();
 
 112         eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId())
 
 113                 .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue())
 
 114                 .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf);
 
 115         databaseProvider.writeEventLog(eventlogBuilder.build());
 
 116         log.info("Create-techInfo Notification written ");
 
 120     // end of public methods