32f8cb0cb0eafcc15e3f465452c6446c4f10ed25
[ccsdk/features.git] /
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
82             EventlogBuilder eventlogBuilder = new EventlogBuilder();
83
84             InstanceIdentifier<?> target = edit.getTarget();
85             if (target != null) {
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);
90                 }
91                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
92             }
93             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
94
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
101             log.info("onDeviceConfigChange (2) {}", sb);
102             counter++;
103         }
104     }
105
106     @Override
107     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
108         // TODO Auto-generated method stub
109         log.info("onCreateTechInfoNotification(1){}", notification);
110
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 ");
117         counter++;
118
119     }
120     // end of public methods
121
122 }