44c8b8d6d479939400ddc8824401be2b64ed77d6
[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.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;
42
43 /**
44  * @author Shabnam Sultana
45  *
46  *         Listener for Open roadm device specific change notifications
47  **/
48
49 public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDeviceListener {
50     // variables
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();
56     // end of variables
57
58     // constructors
59     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
60         this.netconfAccessor = netconfAccessor;
61         this.databaseProvider = databaseService;
62     }
63     // end of constructors
64
65     // public methods
66     @Override
67     public void onOtdrScanResult(OtdrScanResult notification) {
68         // TODO Auto-generated method stub
69
70     }
71
72     @Override
73     public void onChangeNotification(ChangeNotification notification) {
74         log.info("onDeviceConfigChange(1){}", notification);
75         StringBuffer sb = new StringBuffer();
76
77         @NonNull
78         List<Edit> editList = notification.nonnullEdit();
79         for (Edit edit : editList) {
80             if (sb.length() > 0) {
81                 sb.append(", ");
82             }
83             sb.append(edit);
84             EventlogBuilder eventlogBuilder = new EventlogBuilder();
85             InstanceIdentifier<?> target = edit.getTarget();
86             if (target != null) {
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);
91                 }
92                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
93             }
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);
101             counter++;
102         }
103     }
104
105     @Override
106     public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
107
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 ");
116         counter++;
117     }
118     // end of public methods
119
120 }