f055c598a8ebfe5c086d7c088b474ed79f8520ad
[ccsdk/features.git] / sdnr / wt / devicemanager-openroadm / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / openroadm / impl / OpenroadmDeviceChangeNotificationListener.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
23
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;
40
41 /**
42  * @author Shabnam Sultana
43  *
44  *         Listener for Open roadm device specific change notifications
45  **/
46
47 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
48     // variables
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;
53     // end of variables
54
55     // constructors
56     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
57         this.netconfAccessor = netconfAccessor;
58         this.databaseProvider = databaseService;
59     }
60     // end of constructors
61
62     // public methods
63     @Override
64     public void onOtdrScanResult(OtdrScanResult notification) {
65         // TODO Auto-generated method stub
66
67     }
68
69     @Override
70     public void onChangeNotification(ChangeNotification notification) {
71         log.info("onDeviceConfigChange(1){}", notification);
72         StringBuffer sb = new StringBuffer();
73
74         @NonNull
75         List<Edit> editList = notification.nonnullEdit();
76         for (Edit edit : editList) {
77             if (sb.length() > 0) {
78                 sb.append(", ");
79             }
80             sb.append(edit);
81             EventlogBuilder eventlogBuilder = new EventlogBuilder();
82             InstanceIdentifier<?> target = edit.getTarget();
83             if (target != null) {
84                 eventlogBuilder.setObjectId(target.getPathArguments().toString());
85                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
86                 for (PathArgument pa : target.getPathArguments()) {
87                     log.info("PathArgument {}", pa);
88                 }
89                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
90             }
91             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
92             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
93             eventlogBuilder.setTimestamp(notification.getChangeTime());
94             eventlogBuilder.setCounter(counter);
95             eventlogBuilder.setSourceType(SourceType.Netconf);
96             databaseProvider.writeEventLog(eventlogBuilder.build());
97             log.info("onDeviceConfigChange (2) {}", sb);
98             counter++;
99         }
100     }
101
102     @Override
103     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
104         // TODO Auto-generated method stub
105         log.info("onCreateTechInfoNotification(1){}", notification);
106         EventlogBuilder eventlogBuilder = new EventlogBuilder();
107         eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId())
108                 .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue())
109                 .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf);
110         databaseProvider.writeEventLog(eventlogBuilder.build());
111         log.info("Create-techInfo Notification written ");
112         counter++;
113     }
114     // end of public methods
115
116 }