8b8a9bdb4832f9aa0f6c183fd28e07444175991e
[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.List;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
27 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.binding.NotificationListener;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  */
40 public class ORanNetworkElement implements NetworkElement {
41
42     private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class);
43
44     private final NetconfAccessor netconfAccessor;
45
46     private final DataProvider databaseService;
47
48     private final ORanToInternalDataModel oRanMapper;
49
50     private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult;
51     private @NonNull final ORanChangeNotificationListener oRanListener;
52     private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult;
53     private @NonNull final ORanFaultNotificationListener oRanFaultListener;
54
55     ORanNetworkElement(NetconfAccessor netconfAccess, DataProvider databaseService) {
56         log.info("Create {}", ORanNetworkElement.class.getSimpleName());
57         this.netconfAccessor = netconfAccess;
58         this.databaseService = databaseService;
59
60         this.oRanListenerRegistrationResult = null;
61         this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService);
62
63         this.oRanFaultListenerRegistrationResult = null;
64         this.oRanFaultListener = new ORanFaultNotificationListener();
65
66         this.oRanMapper = new ORanToInternalDataModel();
67
68     }
69
70     public void initialReadFromNetworkElement() {
71         Hardware hardware = readHardware(netconfAccessor);
72         if (hardware != null) {
73             List<Component> componentList = hardware.getComponent();
74             if (componentList != null) {
75                 for (Component component : componentList) {
76                     databaseService
77                             .writeInventory(oRanMapper.getInternalEquipment(netconfAccessor.getNodeId(), component));
78                 }
79             }
80         }
81     }
82
83     @Override
84     public NetworkElementDeviceType getDeviceType() {
85         return NetworkElementDeviceType.ORAN;
86     }
87
88     private Hardware readHardware(NetconfAccessor accessData) {
89
90         final Class<Hardware> clazzPac = Hardware.class;
91
92         log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
93                 accessData.getNodeId().getValue());
94
95         InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build();
96
97         Hardware res = accessData.getTransactionUtils().readData(accessData.getDataBroker(),
98                 LogicalDatastoreType.OPERATIONAL, hardwareIID);
99
100         return res;
101     }
102
103     @Override
104     public void register() {
105         initialReadFromNetworkElement();
106         this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener);
107         this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener);
108     }
109
110     @Override
111     public void deregister() {
112         if (oRanListenerRegistrationResult != null) {
113             this.oRanListenerRegistrationResult.close();
114         }
115         if (oRanFaultListenerRegistrationResult != null) {
116             this.oRanFaultListenerRegistrationResult.close();
117         } ;
118     }
119
120
121     @Override
122     public NodeId getNodeId() {
123         return netconfAccessor.getNodeId();
124     }
125
126     @Override
127     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
128         return Optional.empty();
129     }
130
131     @Override
132     public void warmstart() {}
133
134     @Override
135     public Optional<NetconfAccessor> getAcessor() {
136         return Optional.of(netconfAccessor);
137     }
138
139 }