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.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.dataprovider.model.NetconfTimeStamp;
 
  28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
 
  29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
 
  30 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
 
  31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
 
  32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
 
  33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OrgOpenroadmDeviceListener;
 
  34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OtdrScanResult;
 
  35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
 
  36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
 
  37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
 
  38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
 
  39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
  40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
  41 import org.slf4j.Logger;
 
  42 import org.slf4j.LoggerFactory;
 
  45  * @author Shabnam Sultana
 
  47  *         Listener for Open roadm device specific change notifications
 
  50 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
 
  52     private static final Logger log = LoggerFactory.getLogger(OpenroadmDeviceChangeNotificationListener.class);
 
  53     private Integer counter = 1;
 
  54     private final NetconfAccessor netconfAccessor;
 
  55     private final DataProvider databaseProvider;
 
  56     private final WebsocketManagerService notificationServiceService;
 
  57     private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
 
  61     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService,
 
  62             WebsocketManagerService faultService) {
 
  63         this.netconfAccessor = netconfAccessor;
 
  64         this.databaseProvider = databaseService;
 
  65         this.notificationServiceService = faultService;
 
  67     // end of constructors
 
  71     public void onOtdrScanResult(OtdrScanResult notification) {
 
  72         // TODO Auto-generated method stub
 
  77     public void onChangeNotification(ChangeNotification notification) {
 
  78         log.info("onDeviceConfigChange(1){}", notification);
 
  79         StringBuffer sb = new StringBuffer();
 
  82         List<Edit> editList = notification.nonnullEdit();
 
  83         for (Edit edit : editList) {
 
  84             if (sb.length() > 0) {
 
  88             EventlogBuilder eventlogBuilder = new EventlogBuilder();
 
  89             InstanceIdentifier<?> target = edit.getTarget();
 
  91                 eventlogBuilder.setObjectId(target.getPathArguments().toString());
 
  92                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
 
  93                 for (PathArgument pa : target.getPathArguments()) {
 
  94                     log.info("PathArgument {}", pa);
 
  96                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
 
  98             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
 
  99             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
 
 100             eventlogBuilder.setTimestamp(notification.getChangeTime());
 
 101             eventlogBuilder.setCounter(counter);
 
 102             eventlogBuilder.setSourceType(SourceType.Netconf);
 
 103             databaseProvider.writeEventLog(eventlogBuilder.build());
 
 104             log.info("onDeviceConfigChange (2) {}", sb);
 
 107         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
 
 108                 ChangeNotification.QNAME, notification.getChangeTime());
 
 112     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
 
 114         DateAndTime now = NetconfTimeStampImpl.getConverter().getTimeStamp();
 
 115         log.info("onCreateTechInfoNotification(1){}", notification);
 
 116         EventlogBuilder eventlogBuilder = new EventlogBuilder();
 
 117         eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId())
 
 118                 .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue())
 
 119                 .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf)
 
 121         databaseProvider.writeEventLog(eventlogBuilder.build());
 
 122         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
 
 123                 CreateTechInfoNotification.QNAME, now);
 
 124         log.info("Create-techInfo Notification written ");
 
 127     // end of public methods