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.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.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDeviceListener;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OtdrScanResult;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * @author Shabnam Sultana
46 * Listener for Open roadm device specific change notifications
49 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
51 private static final Logger log = LoggerFactory.getLogger(OpenroadmDeviceChangeNotificationListener.class);
52 private Integer counter = 1;
53 private final NetconfAccessor netconfAccessor;
54 private final DataProvider databaseProvider;
55 private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
59 public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
60 this.netconfAccessor = netconfAccessor;
61 this.databaseProvider = databaseService;
63 // end of constructors
67 public void onOtdrScanResult(OtdrScanResult notification) {
68 // TODO Auto-generated method stub
73 public void onChangeNotification(ChangeNotification notification) {
74 log.info("onDeviceConfigChange(1){}", notification);
75 StringBuffer sb = new StringBuffer();
78 List<Edit> editList = notification.nonnullEdit();
79 for (Edit edit : editList) {
80 if (sb.length() > 0) {
84 EventlogBuilder eventlogBuilder = new EventlogBuilder();
85 InstanceIdentifier<?> target = edit.getTarget();
87 eventlogBuilder.setObjectId(target.getPathArguments().toString());
88 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
89 for (PathArgument pa : target.getPathArguments()) {
90 log.info("PathArgument {}", pa);
92 eventlogBuilder.setAttributeName(target.getTargetType().getName());
94 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());
100 log.info("onDeviceConfigChange (2) {}", sb);
106 public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
108 log.info("onCreateTechInfoNotification(1){}", notification);
109 EventlogBuilder eventlogBuilder = new EventlogBuilder();
110 eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId())
111 .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue())
112 .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf)
113 .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp()));
114 databaseProvider.writeEventLog(eventlogBuilder.build());
115 log.info("Create-techInfo Notification written ");
118 // end of public methods