3f69e18861dbff6a60ea6261a7e870a759980ede
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
19
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
31 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
38 import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
42 import org.opendaylight.yangtools.concepts.ListenerRegistration;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.opendaylight.yangtools.yang.binding.NotificationListener;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  */
50 public class ORanNetworkElement implements NetworkElement {
51
52     private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class);
53
54     private final NetconfAccessor netconfAccessor;
55
56     private final DataProvider databaseService;
57
58     private final VESCollectorService vesCollectorService;
59
60     private final ORanToInternalDataModel oRanMapper;
61
62     private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult;
63     private @NonNull final ORanChangeNotificationListener oRanListener;
64     private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult;
65     private @NonNull final ORanFaultNotificationListener oRanFaultListener;
66
67     ORanNetworkElement(NetconfAccessor netconfAccess, DataProvider databaseService,
68             VESCollectorService vesCollectorService) {
69         log.info("Create {}", ORanNetworkElement.class.getSimpleName());
70         this.netconfAccessor = netconfAccess;
71         this.databaseService = databaseService;
72         this.vesCollectorService = vesCollectorService;
73
74         this.oRanListenerRegistrationResult = null;
75         this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService);
76
77         this.oRanFaultListenerRegistrationResult = null;
78         this.oRanFaultListener = new ORanFaultNotificationListener();
79
80         this.oRanMapper = new ORanToInternalDataModel();
81
82     }
83
84     public void initialReadFromNetworkElement() {
85         Hardware hardware = readHardware(netconfAccessor);
86         if (hardware != null) {
87             Collection<Component> componentList = YangHelper.getCollection(hardware.getComponent());
88             if (componentList != null) {
89                 for (Component component : componentList) {
90                     databaseService
91                             .writeInventory(oRanMapper.getInternalEquipment(netconfAccessor.getNodeId(), component));
92                 }
93             }
94         }
95         System1 sys = getOnapSystemData(netconfAccessor);
96         if (sys != null) {
97             GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder();
98             gcBuilder.setId(sys.getName()).setName(sys.getName()).setWeburi(sys.getWebUi().getValue());
99             databaseService.writeGuiCutThroughData(gcBuilder.build());
100         }
101     }
102
103     @Override
104     public NetworkElementDeviceType getDeviceType() {
105         return NetworkElementDeviceType.ORAN;
106     }
107
108     private System1 getOnapSystemData(NetconfAccessor accessData) {
109         InstanceIdentifier<System1> system1IID =
110         InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class)
111         .augmentation(System1.class).build();
112
113         System1 res = accessData.getTransactionUtils().readData(accessData.getDataBroker(), LogicalDatastoreType.OPERATIONAL, system1IID);
114         log.debug("Result of getOnapSystemData = {}", res);
115         return res;
116     }
117
118     private Hardware readHardware(NetconfAccessor accessData) {
119
120         final Class<Hardware> clazzPac = Hardware.class;
121
122         log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
123                 accessData.getNodeId().getValue());
124
125         InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build();
126
127         Hardware res = accessData.getTransactionUtils().readData(accessData.getDataBroker(),
128                 LogicalDatastoreType.OPERATIONAL, hardwareIID);
129
130         return res;
131     }
132
133     @Override
134     public void register() {
135
136         initialReadFromNetworkElement();
137         // Register call back class for receiving notifications
138         this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener);
139         this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener);
140         // Register notifications stream
141         if (netconfAccessor.isNCNotificationsSupported()) {
142             List<Stream> streamList = netconfAccessor.getNotificationStreams();
143             netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream); // Always register first to default stream
144             netconfAccessor.registerNotificationsStream(streamList);
145         } else {
146             netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
147         }
148     }
149
150     @Override
151     public void deregister() {
152         if (oRanListenerRegistrationResult != null) {
153             this.oRanListenerRegistrationResult.close();
154         }
155         if (oRanFaultListenerRegistrationResult != null) {
156             this.oRanFaultListenerRegistrationResult.close();
157         } ;
158     }
159
160
161     @Override
162     public NodeId getNodeId() {
163         return netconfAccessor.getNodeId();
164     }
165
166     @Override
167     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
168         return Optional.empty();
169     }
170
171     @Override
172     public void warmstart() {}
173
174     @Override
175     public Optional<NetconfAccessor> getAcessor() {
176         return Optional.of(netconfAccessor);
177     }
178
179 }