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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.oransc.oam.features.devicemanager.oran.impl;
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;
40 public class ORanNetworkElement implements NetworkElement {
42 private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class);
44 private final NetconfAccessor netconfAccessor;
46 private final DataProvider databaseService;
48 private final ORanToInternalDataModel oRanMapper;
50 private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult;
51 private @NonNull final ORanChangeNotificationListener oRanListener;
52 private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult;
53 private @NonNull final ORanFaultNotificationListener oRanFaultListener;
55 ORanNetworkElement(NetconfAccessor netconfAccess, DataProvider databaseService) {
56 log.info("Create {}",ORanNetworkElement.class.getSimpleName());
57 this.netconfAccessor = netconfAccess;
58 this.databaseService = databaseService;
60 this.oRanListenerRegistrationResult = null;
61 this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService);
63 this.oRanFaultListenerRegistrationResult = null;
64 this.oRanFaultListener = new ORanFaultNotificationListener();
66 this.oRanMapper = new ORanToInternalDataModel();
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.writeInventory( oRanMapper.getInternalEquipment(netconfAccessor.getNodeId(), component));
83 public NetworkElementDeviceType getDeviceType() {
84 return NetworkElementDeviceType.ORAN;
87 private Hardware readHardware(NetconfAccessor accessData) {
89 final Class<Hardware> clazzPac = Hardware.class;
91 log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
92 accessData.getNodeId().getValue());
94 InstanceIdentifier<Hardware> hardwareIID =
95 InstanceIdentifier.builder(clazzPac).build();
97 Hardware res = accessData.getTransactionUtils().readData(accessData.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
104 public void register() {
106 initialReadFromNetworkElement();
107 // Register call back class for receiving notifications
108 this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener);
109 this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener);
110 // Register netconf stream
111 netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
117 public void deregister() {
118 if (oRanListenerRegistrationResult != null) {
119 this.oRanListenerRegistrationResult.close();
121 if (oRanFaultListenerRegistrationResult != null) {
122 this.oRanFaultListenerRegistrationResult.close();
128 public NodeId getNodeId() {
129 return netconfAccessor.getNodeId();
133 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
134 return Optional.empty();
138 public void warmstart() {
142 public Optional<NetconfAccessor> getAcessor() {
143 return Optional.of(netconfAccessor);