Bump parent version to 2.5.4-SNAPSHOT
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / openroadm71 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / openroadm71 / 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.openroadm71.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.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;
43
44 /**
45  * @author Shabnam Sultana
46  *
47  *         Listener for Open roadm device specific change notifications
48  **/
49
50 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
51     // variables
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();
58     // end of variables
59
60     // constructors
61     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService,
62             WebsocketManagerService faultService) {
63         this.netconfAccessor = netconfAccessor;
64         this.databaseProvider = databaseService;
65         this.notificationServiceService = faultService;
66     }
67     // end of constructors
68
69     // public methods
70     @Override
71     public void onOtdrScanResult(OtdrScanResult notification) {
72         // TODO Auto-generated method stub
73
74     }
75
76     @Override
77     public void onChangeNotification(ChangeNotification notification) {
78         log.info("onDeviceConfigChange(1){}", notification);
79         StringBuffer sb = new StringBuffer();
80
81         @NonNull
82         List<Edit> editList = notification.nonnullEdit();
83         for (Edit edit : editList) {
84             if (sb.length() > 0) {
85                 sb.append(", ");
86             }
87             sb.append(edit);
88             EventlogBuilder eventlogBuilder = new EventlogBuilder();
89             InstanceIdentifier<?> target = edit.getTarget();
90             if (target != null) {
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);
95                 }
96                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
97             }
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);
105             counter++;
106         }
107         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
108                 ChangeNotification.QNAME, notification.getChangeTime());
109     }
110
111     @Override
112     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
113
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)
120                 .setTimestamp(now);
121         databaseProvider.writeEventLog(eventlogBuilder.build());
122         this.notificationServiceService.sendNotification(notification, this.netconfAccessor.getNodeId(),
123                 CreateTechInfoNotification.QNAME, now);
124         log.info("Create-techInfo Notification written ");
125         counter++;
126     }
127     // end of public methods
128
129 }