a79bed706d2b34c22c167c4ddbc34cb8e7afbd63
[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.alarm.rev191129.OrgOpenroadmAlarmListener;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDeviceListener;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OtdrScanResult;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.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(OrgOpenroadmAlarmListener.class);
53     private Integer counter = 1;
54     private final NetconfAccessor netconfAccessor;
55     private final DataProvider databaseProvider;
56     private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter();
57     // end of variables
58
59     // constructors
60     public OpenroadmDeviceChangeNotificationListener(NetconfAccessor netconfAccessor, DataProvider databaseService) {
61         this.netconfAccessor = netconfAccessor;
62         this.databaseProvider = databaseService;
63     }
64     // end of constructors
65
66     // public methods
67     @Override
68     public void onOtdrScanResult(OtdrScanResult notification) {
69         // TODO Auto-generated method stub
70
71     }
72
73     @Override
74     public void onChangeNotification(ChangeNotification notification) {
75         log.info("onDeviceConfigChange(1){}", notification);
76         StringBuffer sb = new StringBuffer();
77
78         @NonNull
79         List<Edit> editList = notification.nonnullEdit();
80         for (Edit edit : editList) {
81             if (sb.length() > 0) {
82                 sb.append(", ");
83             }
84             sb.append(edit);
85             EventlogBuilder eventlogBuilder = new EventlogBuilder();
86             InstanceIdentifier<?> target = edit.getTarget();
87             if (target != null) {
88                 eventlogBuilder.setObjectId(target.getPathArguments().toString());
89                 log.info("TARGET: {} {}", target.getClass(), target.getTargetType());
90                 for (PathArgument pa : target.getPathArguments()) {
91                     log.info("PathArgument {}", pa);
92                 }
93                 eventlogBuilder.setAttributeName(target.getTargetType().getName());
94             }
95             eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
96             eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
97             eventlogBuilder.setTimestamp(notification.getChangeTime());
98             eventlogBuilder.setCounter(counter);
99             eventlogBuilder.setSourceType(SourceType.Netconf);
100             databaseProvider.writeEventLog(eventlogBuilder.build());
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         EventlogBuilder eventlogBuilder = new EventlogBuilder();
111         eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId())
112                 .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue())
113                 .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf)
114                 .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp()));
115         databaseProvider.writeEventLog(eventlogBuilder.build());
116         log.info("Create-techInfo Notification written ");
117         counter++;
118     }
119     // end of public methods
120
121 }