From eb2a7c97c0007b013bd1784ac17d57be02b63d03 Mon Sep 17 00:00:00 2001 From: Michael DÜrre Date: Thu, 10 Mar 2022 10:39:16 +0100 Subject: migrate sdnr features to phosphorus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix mapper and switch to dom api Updated to use phosphorus version of parent poms Issue-ID: CCSDK-3566 Signed-off-by: Michael DÜrre Change-Id: I98c5bef9286622e0d66b53db687557d798cd53f5 Signed-off-by: Michael DÜrre --- .../oran/impl/DeviceManagerORanImpl.java | 89 ------- .../oran/impl/ORanChangeNotificationListener.java | 138 ---------- .../oran/impl/ORanFaultNotificationListener.java | 166 ------------ .../oran/impl/ORanFaultToVESFaultMapper.java | 164 ------------ .../oran/impl/ORanNetworkElement.java | 258 ------------------ .../oran/impl/ORanNetworkElementFactory.java | 56 ---- .../oran/impl/ORanNotifToVESEventAssembly.java | 99 ------- ...ORanRegistrationToVESpnfRegistrationMapper.java | 90 ------- .../oran/impl/ORanToInternalDataModel.java | 276 ------------------- .../oran/impl/binding/DeviceManagerORanImpl.java | 90 +++++++ .../binding/ORanChangeNotificationListener.java | 138 ++++++++++ .../binding/ORanFaultNotificationListener.java | 166 ++++++++++++ .../impl/binding/ORanFaultToVESFaultMapper.java | 164 ++++++++++++ .../oran/impl/binding/ORanNetworkElement.java | 278 +++++++++++++++++++ .../impl/binding/ORanNotifToVESEventAssembly.java | 99 +++++++ ...ORanRegistrationToVESpnfRegistrationMapper.java | 114 ++++++++ .../oran/impl/binding/ORanToInternalDataModel.java | 276 +++++++++++++++++++ .../oran/impl/dom/DOMNotificationToXPath.java | 235 +++++++++++++++++ .../oran/impl/dom/ORanDMDOMUtility.java | 90 +++++++ .../dom/ORanDOMChangeNotificationListener.java | 150 +++++++++++ .../impl/dom/ORanDOMFaultNotificationListener.java | 171 ++++++++++++ .../impl/dom/ORanDOMFaultToVESFaultMapper.java | 155 +++++++++++ .../oran/impl/dom/ORanDOMNetworkElement.java | 283 ++++++++++++++++++++ .../impl/dom/ORanDOMNotifToVESEventAssembly.java | 102 +++++++ .../oran/impl/dom/ORanDOMToInternalDataModel.java | 293 +++++++++++++++++++++ .../oran/impl/dom/ORanDeviceManagerQNames.java | 114 ++++++++ .../impl/startup/ORanNetworkElementFactory.java | 59 +++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 2 +- 28 files changed, 2978 insertions(+), 1337 deletions(-) delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/DeviceManagerORanImpl.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElementFactory.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanRegistrationToVESpnfRegistrationMapper.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/DeviceManagerORanImpl.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanChangeNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultToVESFaultMapper.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNetworkElement.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNotifToVESEventAssembly.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanRegistrationToVESpnfRegistrationMapper.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanToInternalDataModel.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/DOMNotificationToXPath.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDMDOMUtility.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMChangeNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultToVESFaultMapper.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNetworkElement.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNotifToVESEventAssembly.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMToInternalDataModel.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDeviceManagerQNames.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/startup/ORanNetworkElementFactory.java (limited to 'sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main') diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/DeviceManagerORanImpl.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/DeviceManagerORanImpl.java deleted file mode 100644 index 87157e8ce..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/DeviceManagerORanImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DeviceManagerORanImpl implements AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerORanImpl.class); - private static final String APPLICATION_NAME = "DeviceManagerORan"; - @SuppressWarnings("unused") - private static final String CONFIGURATIONFILE = "etc/devicemanager-oran.properties"; - - - private NetconfNetworkElementService netconfNetworkElementService; - - private HtDatabaseClient htDatabaseClient; - private Boolean devicemanagerInitializationOk = false; - private FactoryRegistration resORan; - - // Blueprint begin - public DeviceManagerORanImpl() { - LOG.info("Creating provider for {}", APPLICATION_NAME); - resORan = null; - } - - public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) { - this.netconfNetworkElementService = netconfNetworkElementService; - } - - public void init() throws Exception { - - LOG.info("Session Initiated start {}", APPLICATION_NAME); - - resORan = netconfNetworkElementService.registerBindingNetworkElementFactory(new ORanNetworkElementFactory()); - - - netconfNetworkElementService.writeToEventLog(APPLICATION_NAME, "startup", "done"); - this.devicemanagerInitializationOk = true; - - LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk); - } - // Blueprint end - - @Override - public void close() throws Exception { - LOG.info("closing ..."); - close(htDatabaseClient); - close(resORan); - LOG.info("closing done"); - } - - /** - * Used to close all Services, that should support AutoCloseable Pattern - * - * @param toClose - * @throws Exception - */ - private void close(AutoCloseable... toCloseList) { - for (AutoCloseable element : toCloseList) { - if (element != null) { - try { - element.close(); - } catch (Exception e) { - LOG.warn("Fail during close: ", e); - } - } - } - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java deleted file mode 100644 index c0aa0ac9b..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.util.List; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Listener for change notifications - */ -public class ORanChangeNotificationListener implements IetfNetconfNotificationsListener { - - private static final Logger log = LoggerFactory.getLogger(ORanChangeNotificationListener.class); - - private final NetconfBindingAccessor netconfAccessor; - private final DataProvider databaseService; - private final NotificationService notificationService; - private final VESCollectorService vesCollectorService; - private final NotificationProxyParser notificationProxyParser; - private ORanNotifToVESEventAssembly mapper = null; - - private static int sequenceNo = 0; - - public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, - DeviceManagerServiceProvider serviceProvider) { - this.netconfAccessor = netconfAccessor; - this.databaseService = serviceProvider.getDataProvider(); - this.notificationService = serviceProvider.getNotificationService(); - this.vesCollectorService = serviceProvider.getVESCollectorService(); - this.notificationProxyParser = vesCollectorService.getNotificationProxyParser(); - } - - @Override - public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) { - log.info("onNetconfConfirmedCommit {}", notification); - } - - @Override - public void onNetconfSessionStart(NetconfSessionStart notification) { - log.info("onNetconfSessionStart {}", notification); - } - - @Override - public void onNetconfSessionEnd(NetconfSessionEnd notification) { - log.info("onNetconfSessionEnd {}", notification); - } - - @Override - public void onNetconfCapabilityChange(NetconfCapabilityChange notification) { - log.info("onNetconfCapabilityChange {}", notification); - } - - @Override - public void onNetconfConfigChange(NetconfConfigChange notification) { - log.info("onNetconfConfigChange (1) {}", notification.toString()); - - StringBuffer sb = new StringBuffer(); - List editList = notification.nonnullEdit(); - for (Edit edit : editList) { - if (sb.length() > 0) { - sb.append(", "); - } - sb.append(edit); - - InstanceIdentifier target = edit.getTarget(); - if (target != null) { - log.info("TARGET: {} {}", target.getClass(), target.getTargetType()); - for (PathArgument pa : target.getPathArguments()) { - log.info("PathArgument {} Type {}", pa, pa.getType().getFields()); - } - - EventlogEntity eventLogEntity1 = new EventlogBuilder().setNodeId(netconfAccessor.getNodeId().getValue()) - .setCounter(sequenceNo++).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) - .setObjectId(target.getTargetType().getCanonicalName()).setAttributeName("N.A") - .setSourceType(SourceType.Netconf).setNewValue(String.valueOf(edit.getOperation())).build(); - databaseService.writeEventLog(eventLogEntity1); - } - } - log.info("onNetconfConfigChange (2) {}", sb); - - if (vesCollectorService.getConfig().isVESCollectorEnabled()) { - if (mapper == null) { - this.mapper = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService); - } - VESCommonEventHeaderPOJO header = - mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification), - NetconfConfigChange.class.getSimpleName(), sequenceNo); - VESNotificationFieldsPOJO body = - mapper.createVESNotificationFields(notificationProxyParser.parseNotificationProxy(notification), - NetconfConfigChange.class.getSimpleName()); - try { - vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); - } catch (JsonProcessingException e) { - log.warn("Exception while generating JSON object ", e); - - } - } - - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java deleted file mode 100644 index a17dcd726..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.time.Instant; -import java.time.format.DateTimeParseException; -import java.util.Collection; -import java.util.Date; -import java.util.Objects; -import org.eclipse.jdt.annotation.NonNull; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.ORanFmListener; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanFaultNotificationListener implements ORanFmListener { - - private static final Logger LOG = LoggerFactory.getLogger(ORanFaultNotificationListener.class); - - private final @NonNull NetconfBindingAccessor netconfAccessor; - private final @NonNull VESCollectorService vesCollectorService; - private final @NonNull ORanFaultToVESFaultMapper mapper; - private final @NonNull FaultService faultService; - private final @NonNull WebsocketManagerService websocketManagerService; - private final @NonNull DataProvider databaseService; - private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter(); - - private Integer counter; //Local counter is assigned to Notifications - - public ORanFaultNotificationListener(@NonNull NetconfBindingAccessor netconfAccessor, - @NonNull VESCollectorService vesCollectorService, @NonNull FaultService faultService, - @NonNull WebsocketManagerService websocketManagerService, @NonNull DataProvider databaseService) { - this.netconfAccessor = Objects.requireNonNull(netconfAccessor); - this.vesCollectorService = Objects.requireNonNull(vesCollectorService); - this.faultService = Objects.requireNonNull(faultService); - this.websocketManagerService = Objects.requireNonNull(websocketManagerService); - this.databaseService = Objects.requireNonNull(databaseService); - - this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService, - AlarmNotif.class.getSimpleName()); - this.counter = 0; - } - - /** - * Gets the mfg name, mode-name and Uuid of the root component (Ex: Chassis.) - * In cases where there are multiple root components i.e., components with no parent, - * the Uuid of the last occurred component from the componentList will be considered. - * Till now we haven't seen Uuid set for root components, so not an issue for now. - * @param componentList - */ - public void setComponentList(Collection componentList) { - for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) { - mapper.setMfgName(component.getMfgName()); - mapper.setUuid(component.getUuid()!=null?component.getUuid().getValue():netconfAccessor.getNodeId().getValue()); - mapper.setModelName(component.getModelName()); - } - } - - @Override - public void onAlarmNotif(AlarmNotif notification) { - - LOG.debug("onAlarmNotif {}", notification.getClass().getSimpleName()); - counter++; - - // Send devicemanager specific notification for database and ODLUX - Instant eventTimeInstant = ORanToInternalDataModel.getInstantTime(notification.getEventTime()); - faultService.faultNotification( - ORanToInternalDataModel.getFaultLog(notification, netconfAccessor.getNodeId(), counter)); - // Send model specific notification to WebSocketManager - websocketManagerService.sendNotification(notification, netconfAccessor.getNodeId(), AlarmNotif.QNAME); - - try { - if (vesCollectorService.getConfig().isVESCollectorEnabled()) { - VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); - VESFaultFieldsPOJO body = mapper.mapFaultFields(notification); - VESMessage vesMsg = vesCollectorService.generateVESEvent(header, body); - vesCollectorService.publishVESMessage(vesMsg); - LOG.info("VES Message is {}",vesMsg.getMessage()); - writeToEventLog(vesMsg.getMessage(), eventTimeInstant, AlarmNotif.QNAME.toString(), counter); - } - } catch (JsonProcessingException | DateTimeParseException e) { - LOG.debug("Can not convert event into VES message {}", notification, e); - } - } - - private void writeToEventLog(String data, Instant instant, String notificationName, - int sequenceNo) { - EventlogBuilder eventlogBuilder = new EventlogBuilder(); - - eventlogBuilder.setObjectId("Device"); - eventlogBuilder.setCounter(sequenceNo); - eventlogBuilder.setAttributeName(notificationName); - eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()); - String eventLogMsgLvl = vesCollectorService.getConfig().getEventLogMsgDetail(); - if (eventLogMsgLvl.equalsIgnoreCase("SHORT")) { - data = getShortEventLogMessage(data); - } else if (eventLogMsgLvl.equalsIgnoreCase("MEDIUM")) { - data = getMediumEventLogMessage(data); - } else if (eventLogMsgLvl.equalsIgnoreCase("LONG")) { - // do nothing, data already contains long message - } else { // Unknown value, default to "SHORT" - data = getShortEventLogMessage(data); - } - eventlogBuilder.setNewValue(data); - eventlogBuilder.setSourceType(SourceType.Netconf); - - Date eventDate = Date.from(instant); - eventlogBuilder.setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp(eventDate))); - - databaseService.writeEventLog(eventlogBuilder.build()); - } - - private String getShortEventLogMessage(String data) { - try { - JSONObject jsonObj = new JSONObject(data); - String domain = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("domain"); - String eventId = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("eventId"); - return "domain:" + domain + " eventId:" + eventId; - } catch (JSONException e) { - LOG.debug("{}", e); - return "Invalid message received"; - } - } - - private String getMediumEventLogMessage(String data) { - try { - JSONObject jsonObj = new JSONObject(data); - return jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").toString(); - } catch (JSONException e) { - LOG.debug("{}", e); - return "Invalid message received"; - } - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java deleted file mode 100644 index ec8eaa7b7..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import java.time.Instant; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -//@formatter:off -/* - * Maps ORAN Fault fields to VES fault domain fields and VES commonEventHeader fields - * - * - * VES Fields Mapping - * ---------- ------- - * domain "fault" - * eventId "nt:network-topology/nt:topology/nt:node/nt:node-id" - * eventName "nt:network-topology/nt:topology/nt:node/nt:node-id" - * eventType "O-RAN-RU-Fault" - * lastEpochMicrosec TimeStamp represented by field in NetConf notification header in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. - * nfcNamingCode always "" - * nfNamingCode always "" - * nfVendorName /ietf-hardware:hardware/component[not(parent)][1]/mfg-name - * priority "Normal" - * reportingEntityId The OAM-Controller identifier with in the SMO - e.g. the fully qualified domain name or IP-Address. - * reportingEntityName as configured by helm charts for the OpenDaylight cluster name ?????? - * sequence As per NetConf notification increasing sequence number as unsigned integer 32 bits. The value is reused in the eventId field. - * sourceId Value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/uuid or 'nt:network-topology/nt:topology/nt:node/nt:node-id' if ietf component not found. - * sourceName "nt:network-topology/nt:topology/nt:node/nt:node-id" - * startEpochMicrosec Current OAM-Controller Node timestamp in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. - * timeZoneOffset Static text: "+00:00" - * version "4.1" - * vesEventListenerVersion "7.2.1" - * - * - * alarmAdditionalInformation - * alarmCondition Value of "o-ran-fm:alarm-notif/fault-id" - * alarmInterfaceA Value of "o-ran-fm:alarm-notif/fault-source" - * eventCategory Static text "O-RU failure" - * eventSeverity Value of "o-ran-fm:alarm-notif/fault-severity". But if "o-ran-fm:alarm-notif/is-cleared" then "NORMAL" - * eventSourceType The value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/model-name or "O-RU" if not found. - * faultFieldsVersion "4.0" - * specificProblem A mapping of the fault-id to its description according to O-RAN OpenFronthaul specification. - * vfStatus "Active" - * - */ -//@formatter:on - -public class ORanFaultToVESFaultMapper { - - @SuppressWarnings("unused") - private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class); - private static final String VES_EVENT_DOMAIN = "fault"; - private static final String VES_EVENTTYPE = "ORAN_Fault"; - private static final String VES_EVENT_PRIORITY = "Normal"; - private static final String VES_EVENT_CATEGORY = "O-RU Failure"; - private static final String VES_FAULT_FIELDS_VERSION = "4.0"; - private static final String VES_FAULT_FIELDS_VFSTATUS = "Active"; //virtual function status - - private final VESCollectorService vesProvider; - private final String notifName; // Name - private final String nodeIdString; // Sourcename - private String mfgName; - private String uuid; - private String modelName; - - public ORanFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService, - String notifName) { - this.nodeIdString = nodeId.getValue(); - this.vesProvider = vesCollectorService; - this.notifName = notifName; - } - - public void setMfgName(String mfgName) { - this.mfgName= mfgName; - } - - private String getMfgName() { - return mfgName; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - private String getUuid() { - return uuid; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - private String getModelName() { - return modelName; - } - - public VESCommonEventHeaderPOJO mapCommonEventHeader(AlarmNotif notification, Instant eventTime, int sequenceNo) { - VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); - vesCEH.setDomain(VES_EVENT_DOMAIN); - vesCEH.setEventName(notifName); - vesCEH.setEventType(VES_EVENTTYPE); - vesCEH.setPriority(VES_EVENT_PRIORITY); - - String eventId; - - eventId = notifName + "-" + Long.toUnsignedString(sequenceNo); - - vesCEH.setEventId(eventId); - vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000); - vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000); - vesCEH.setNfVendorName(getMfgName()); - vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); - vesCEH.setSequence(sequenceNo); - vesCEH.setSourceId(getUuid()); - vesCEH.setSourceName(nodeIdString); - - return vesCEH; - } - - public VESFaultFieldsPOJO mapFaultFields(AlarmNotif alarmNotif) { - VESFaultFieldsPOJO vesFaultFields = new VESFaultFieldsPOJO(); - - vesFaultFields.setAlarmCondition(alarmNotif.getFaultId().toString()); - vesFaultFields.setAlarmInterfaceA(alarmNotif.getFaultSource()); - vesFaultFields.setEventCategory(VES_EVENT_CATEGORY); - if (alarmNotif.getIsCleared()) { - vesFaultFields.setEventSeverity("NORMAL"); - } else { - vesFaultFields.setEventSeverity(alarmNotif.getFaultSeverity().getName()); - } - vesFaultFields.setEventSourceType(getModelName()); - vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION); - vesFaultFields.setSpecificProblem(alarmNotif.getFaultText()); - vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS); - - return vesFaultFields; - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java deleted file mode 100644 index d3ae5014e..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import com.fasterxml.jackson.core.JsonProcessingException; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; -import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.NotificationListener; -import org.opendaylight.yangtools.yang.common.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanNetworkElement implements NetworkElement { - - private static final Logger LOG = LoggerFactory.getLogger(ORanNetworkElement.class); - - public static final QName ONAP_SYSTEM = - org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.$YangModuleInfoImpl.getInstance().getName(); - private static final InstanceIdentifier SYSTEM1_IID = InstanceIdentifier - .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class) - .augmentation(System1.class).build(); - - private final NetconfBindingAccessor netconfAccessor; - private final DataProvider databaseService; - private final ORanRegistrationToVESpnfRegistrationMapper mapper; - private final VESCollectorService vesCollectorService; - - private ListenerRegistration oRanListenerRegistrationResult; - private @NonNull final ORanChangeNotificationListener oRanListener; - private ListenerRegistration oRanFaultListenerRegistrationResult; - private @NonNull final ORanFaultNotificationListener oRanFaultListener; - - ORanNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { - LOG.info("Create {}", ORanNetworkElement.class.getSimpleName()); - // Read parameters - this.netconfAccessor = netconfAccess; - - // Get services - this.databaseService = serviceProvider.getDataProvider(); - this.vesCollectorService = serviceProvider.getVESCollectorService(); - - this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, vesCollectorService); - - // Register callbacks - this.oRanListenerRegistrationResult = null; - this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, serviceProvider); - - this.oRanFaultListenerRegistrationResult = null; - this.oRanFaultListener = new ORanFaultNotificationListener(netconfAccessor, vesCollectorService, - serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService); - } - - private Collection initialReadFromNetworkElement() { - Collection componentList; - Hardware hardware = readHardware(); - if (hardware != null) { - componentList = YangHelper.getCollection(hardware.nonnullComponent()); - List inventoryList = - ORanToInternalDataModel.getInventoryList(netconfAccessor.getNodeId(), componentList); - databaseService.writeInventory(netconfAccessor.getNodeId().getValue(), inventoryList); - } else { - componentList = Collections.emptyList(); - } - - Optional oGuicutthrough = ORanToInternalDataModel.getGuicutthrough(getOnapSystemData()); - if (oGuicutthrough.isPresent()) { - databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfAccessor.getNodeId().getValue()); - } - return componentList; - } - - @Override - public NetworkElementDeviceType getDeviceType() { - return NetworkElementDeviceType.ORAN; - } - - @Override - public void register() { - // Read data from device - Collection componentList = initialReadFromNetworkElement(); - oRanFaultListener.setComponentList(componentList); - // Publish the mountpoint to VES if enabled - publishMountpointToVES(componentList); - // Register call back class for receiving notifications - this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener); - this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener); - // Register notifications stream - if (netconfAccessor.isNotificationsRFC5277Supported()) { - netconfAccessor.registerNotificationsStream(); - } - } - - @Override - public void deregister() { - if (oRanListenerRegistrationResult != null) { - this.oRanListenerRegistrationResult.close(); - } - if (oRanFaultListenerRegistrationResult != null) { - this.oRanFaultListenerRegistrationResult.close(); - } ; - databaseService.clearGuiCutThroughEntriesOfNode(getMountpointId()); - } - - @Override - public NodeId getNodeId() { - return netconfAccessor.getNodeId(); - } - - @Override - public Optional getService(Class clazz) { - return Optional.empty(); - } - - @Override - public void warmstart() {} - - @Override - public Optional getAcessor() { - return Optional.of(netconfAccessor); - } - - // Private functions - - private String getMountpointId() { - return getNodeId().getValue(); - } - - // Read from device - /** - * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported. - * - * @return System1 data with GUI cut through information or null if not available. - */ - private @Nullable System1 getOnapSystemData() { - LOG.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue()); - Capabilities x = netconfAccessor.getCapabilites(); - LOG.info("Capabilites: {}", x); - if (x.isSupportingNamespace(ONAP_SYSTEM)) { - @Nullable - System1 res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), - LogicalDatastoreType.OPERATIONAL, SYSTEM1_IID); - LOG.debug("Result of System1 = {}", res); - return res; - } else { - LOG.debug("No GUI cut through support"); - return null; - } - } - - private Hardware readHardware() { - final Class clazzPac = Hardware.class; - LOG.info("DBRead Get hardware for class {} from mountpoint {}", clazzPac.getSimpleName(), - netconfAccessor.getNodeId().getValue()); - InstanceIdentifier hardwareIID = InstanceIdentifier.builder(clazzPac).build(); - Hardware res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), - LogicalDatastoreType.OPERATIONAL, hardwareIID); - LOG.debug("Result of Hardware = {}", res); - return res; - } - - // VES related - private void publishMountpointToVES(Collection componentList) { - - LOG.debug("In publishMountpointToVES()"); - - /* - * 1. Check if this device is in the list of allowed-devices. 2. If device - * exists in allowed-devices, then create VES pnfRegistration event and publish - * to VES - */ - if (inAllowedDevices(getMountpointId())) { - if (vesCollectorService.getConfig().isVESCollectorEnabled()) { - for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) { - // Just get one component. At the moment we don't care which one. Also since - // there is only one management address, we assume there will be only one - // chassis. - // If the device supports subtended configuration then it is assumed that the - // Chassis containing the management interface will be the root component and - // there will be only one root. - VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(component); - VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(component); - try { - vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); - } catch (JsonProcessingException e) { - LOG.warn("Error while serializing VES Event to String ", e); - e.printStackTrace(); - } - } - } - } - } - - private boolean inAllowedDevices(String mountpointName) { - final InstanceIdentifier ALL_DEVICES = - InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class); - - AllowedDevices allowedDevices = netconfAccessor.getTransactionUtils().readData( - netconfAccessor.getControllerBindingDataBroker(), LogicalDatastoreType.CONFIGURATION, ALL_DEVICES); - - if (allowedDevices != null) { - Collection deviceList = YangHelper.getCollection(allowedDevices.nonnullDevice()); - for (Device device : deviceList) { - LOG.info("Device in allowed-devices is - {}", device.getUniqueId()); - if (device.getUniqueId().equals(netconfAccessor.getNodeId().getValue())) { - LOG.info("Mountpoint is part of allowed-devices list"); - return true; - } - } - } - - LOG.info("Mountpoint {} is not part of allowed-devices list", mountpointName); - return false; - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElementFactory.java deleted file mode 100644 index fff1fba79..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElementFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import java.util.Optional; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT; -import org.opendaylight.yangtools.yang.common.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanNetworkElementFactory implements NetworkElementFactory { - - private static final Logger log = LoggerFactory.getLogger(ORanNetworkElementFactory.class); - //Workaround - private static final QName OneCell = - QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern(); - - @Override - public Optional create(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) { - Capabilities capabilites = accessor.getCapabilites(); - if (!capabilites.isSupportingNamespace(OneCell)) { - if (capabilites.isSupportingNamespace(ORANHWCOMPONENT.QNAME)) { - log.info("Create device {} ", ORanNetworkElement.class.getName()); - Optional bindingAccessor = accessor.getNetconfBindingAccessor(); - if (bindingAccessor.isPresent()) { - return Optional.of(new ORanNetworkElement(bindingAccessor.get(), serviceProvider)); - } - } - } - return Optional.empty(); - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java deleted file mode 100644 index d99f1c874..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanNotifToVESEventAssembly { - - private static final Logger log = LoggerFactory.getLogger(ORanNotifToVESEventAssembly.class); - private static final String VES_EVENT_DOMAIN = "notification"; - private static final String VES_EVENTTYPE = "ORAN_notification"; - private static final String VES_EVENT_PRIORITY = "Normal"; - private NetconfBindingAccessor netconfAccessor; - private VESCollectorService vesProvider; - - public ORanNotifToVESEventAssembly(NetconfBindingAccessor netconfAccessor, VESCollectorService vesProvider) { - this.netconfAccessor = netconfAccessor; - this.vesProvider = vesProvider; - } - - // VES CommonEventHeader fields - public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName, - long sequenceNo) { - VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); - vesCEH.setDomain(VES_EVENT_DOMAIN); - vesCEH.setEventName(notificationTypeName); - vesCEH.setEventType(VES_EVENTTYPE); - vesCEH.setPriority(VES_EVENT_PRIORITY); - - String eventId; - - eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo); - - vesCEH.setEventId(eventId); - vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000); - vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000); - vesCEH.setNfVendorName("ORAN"); - vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); - vesCEH.setSequence(sequenceNo); - vesCEH.setSourceId("ORAN"); - vesCEH.setSourceName(netconfAccessor.getNodeId().getValue()); - return vesCEH; - } - - // Notification fields - public VESNotificationFieldsPOJO createVESNotificationFields(HashMap xPathFields, - String notificationTypeName) { - VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO(); - - vesNotifFields.setChangeType(notificationTypeName); - vesNotifFields.setChangeIdentifier(netconfAccessor.getNodeId().getValue()); - - StringBuffer buf = new StringBuffer(); - Iterator> it = xPathFields.entrySet().iterator(); - while (it.hasNext()) { - Entry pair = it.next(); - buf.append("\n" + pair.getKey() + " = " + pair.getValue()); - } - log.info("Resultlist({}):{}", xPathFields.size(), buf.toString()); - - ArrayList> arrayOfNamedHashMap = new ArrayList>(); - HashMap namedHashMap = new HashMap(); - namedHashMap.put("hashMap", xPathFields); - namedHashMap.put("name", notificationTypeName); - arrayOfNamedHashMap.add(namedHashMap); - vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap); - return vesNotifFields; - - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanRegistrationToVESpnfRegistrationMapper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanRegistrationToVESpnfRegistrationMapper.java deleted file mode 100644 index 3524383f2..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanRegistrationToVESpnfRegistrationMapper.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import java.time.Instant; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanRegistrationToVESpnfRegistrationMapper { - - @SuppressWarnings("unused") - private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class); - //CommonEventHeader fields - private static final String VES_EVENT_DOMAIN = "pnfRegistration"; - private static final String VES_EVENTTYPE = "NetConf Callhome Registration"; - private static final String VES_EVENT_PRIORITY = "Normal"; - - private final VESCollectorService vesProvider; - private final NetconfAccessor netconfAccessor; - - private Integer sequenceNo; - - - public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor, - VESCollectorService vesCollectorService) { - this.netconfAccessor = netconfAccessor; - this.vesProvider = vesCollectorService; - - this.sequenceNo = 0; - } - - public VESCommonEventHeaderPOJO mapCommonEventHeader(Component component) { - VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); - vesCEH.setDomain(VES_EVENT_DOMAIN); - vesCEH.setEventId(netconfAccessor.getNodeId().getValue()); - vesCEH.setEventName(netconfAccessor.getNodeId().getValue()); - vesCEH.setEventType(VES_EVENTTYPE); - vesCEH.setPriority(VES_EVENT_PRIORITY); - - vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000); - vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000); - vesCEH.setNfVendorName(component.getMfgName()); - vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); - vesCEH.setSequence(sequenceNo++); - vesCEH.setSourceId(component.getUuid() != null ? component.getUuid().toString():netconfAccessor.getNodeId().getValue()); - vesCEH.setSourceName(netconfAccessor.getNodeId().getValue()); - - return vesCEH; - } - - public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(Component component) { - VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO(); - vesPnfFields.setModelNumber(component.getModelName()); - vesPnfFields.setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address()!=null?netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue():null); - vesPnfFields.setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address()!=null?netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue():null); - vesPnfFields.setSerialNumber(component.getSerialNum()); - vesPnfFields.setVendorName(component.getMfgName()); - vesPnfFields.setSoftwareVersion(component.getSoftwareRev()); - vesPnfFields.setUnitType(component.getAlias()); - vesPnfFields.setUnitFamily(component.getXmlClass().toString()); - vesPnfFields.setManufactureDate(component.getMfgDate()!=null?component.getMfgDate().toString():"Unknown"); - //vesPnfFields.setLastServiceDate(component.getLastChange()); - - return vesPnfFields; - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java deleted file mode 100644 index 71ab613d2..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.Alarm.FaultSeverity; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; -import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.binding.CodeHelpers; -import org.opendaylight.yangtools.yang.common.Uint32; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Convert data to data-provider model and perform consistency checks.
- * Component list characteristics:
- *
    - *
  • component list is a flat list tree structure specified - *
  • via "component.getParent()": - *
      - *
    • If null we have a root element - *
    • if not null it is a child element with generated child level
      - *
    - *
- * Example of List:
- * - * - */ -public class ORanToInternalDataModel { - - private static final Logger log = LoggerFactory.getLogger(ORanToInternalDataModel.class); - - public static List getInventoryList(NodeId nodeId, Collection componentList) { - - List inventoryResultList = new ArrayList(); - for (Component component : getRootComponents(componentList)) { - inventoryResultList = recurseGetInventory(nodeId, component, componentList, 0, inventoryResultList); - } - // Verify if result is complete - if (componentList.size() != inventoryResultList.size()) { - log.warn( - "Not all data were written to the Inventory. Potential entries with missing " - + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}", - nodeId.getValue(), componentList.size(), inventoryResultList.size()); - } - return inventoryResultList; - } - - private static List recurseGetInventory(NodeId nodeId, Component component, - Collection componentList, int treeLevel, List inventoryResultList) { - - //Add element to list, if conversion successfull - Optional oInventory = getInternalEquipment(nodeId, component, treeLevel); - if (oInventory.isPresent()) { - inventoryResultList.add(oInventory.get()); - } - //Walk trough list of child keys and add to list - for (String childUuid : CodeHelpers.nonnull(component.getContainsChild())) { - for (Component c : getComponentsByName(childUuid, componentList)) { - inventoryResultList = recurseGetInventory(nodeId, c, componentList, treeLevel + 1, inventoryResultList); - } - } - return inventoryResultList; - } - - public static List getRootComponents(Collection componentList) { - List resultList = new ArrayList<>(); - for (Component c : componentList) { - if (c.getParent() == null) { // Root elements do not have a parent - resultList.add(c); - } - } - return resultList; - } - - private static List getComponentsByName(String name, Collection componentList) { - List resultList = new ArrayList<>(); - for (Component c : componentList) { - if (name.equals(c.getName())) { // <-- Component list is flat search for child's of name - resultList.add(c); - } - } - return resultList; - } - - /** - * Convert equipment into Inventory. Decide if inventory can by created from content or not. Public for test case. - * - * @param nodeId of node (Similar to mountpointId) - * @param component to handle - * @param treeLevel of components - * @return Inventory if possible to be created. - */ - public static Optional getInternalEquipment(NodeId nodeId, Component component, int treeLevel) { - - // Make sure that expected data are not null - Objects.requireNonNull(nodeId); - Objects.requireNonNull(component); - - // Read manadatory data - - @Nullable - String nodeIdString = nodeId.getValue(); - @Nullable - String uuid = component.getName(); - @Nullable - String idParent = component.getParent(); - @Nullable - String uuidParent = idParent != null ? idParent : uuid; //<- Passt nicht - - // do consistency check if all mandatory parameters are there - if (treeLevel >= 0 && nodeIdString != null && uuid != null && uuidParent != null) { - - // Build output data - - InventoryBuilder inventoryBuilder = new InventoryBuilder(); - - // General assumed as mandatory - inventoryBuilder.setNodeId(nodeIdString); - inventoryBuilder.setUuid(uuid); - inventoryBuilder.setParentUuid(uuidParent); - inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel)); - - // -- String list with ids of holders (optional) - inventoryBuilder.setContainedHolder(CodeHelpers.nonnull(component.getContainsChild())); - - // -- Manufacturer related things (optional) - @Nullable - String mfgName = component.getMfgName(); - inventoryBuilder.setManufacturerName(mfgName); - inventoryBuilder.setManufacturerIdentifier(mfgName); - - // Equipment type (optional) - inventoryBuilder.setDescription(component.getDescription()); - inventoryBuilder.setModelIdentifier(component.getModelName()); - @Nullable - Class xmlClass = component.getXmlClass(); - if (xmlClass != null) { - inventoryBuilder.setPartTypeId(xmlClass.getName()); - } - inventoryBuilder.setTypeName(component.getName()); - inventoryBuilder.setVersion(component.getHardwareRev()); - - // Equipment instance (optional) - @Nullable - DateAndTime mfgDate = component.getMfgDate(); - if (mfgDate != null) { - inventoryBuilder.setDate(mfgDate.getValue()); - } - inventoryBuilder.setSerial(component.getSerialNum()); - - return Optional.of(inventoryBuilder.build()); - } - return Optional.empty(); - } - - /** - * If system data is available convert - * - * @param sys - * @return - */ - public static Optional getGuicutthrough(@Nullable System1 sys) { - if (sys != null) { - String name = sys.getName(); - @Nullable - Uri uri = sys.getWebUi(); - if (uri != null) { - GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder(); - if (name != null) { - gcBuilder.setName(name); - } - gcBuilder.setWeburi(uri.getValue()); - return Optional.of(gcBuilder.build()); - } - log.warn("Uri not set to invoke a Gui cut through session to the device. Please set the Uri in the device"); - } - log.warn("Retrieving augmented System details failed. Gui cut through information not available"); - return Optional.empty(); - } - - /** - * Convert netconf time into Instant - * - * @param eventTime with netconf time - * @return Instant with converted time. If not convertable provide Instant.Min - */ - public static Instant getInstantTime(@Nullable DateAndTime eventTime) { - return eventTime != null ? Instant.parse(eventTime.getValue()) : Instant.MIN; - } - - /** - * Convert fault notification into data-provider FaultLogEntity - * - * @param notification with O-RAN notification - * @param nodeId of node to handle - * @param counter to be integrated into data - * @return FaultlogEntity with data - */ - public static FaultlogEntity getFaultLog(AlarmNotif notification, NodeId nodeId, Integer counter) { - FaultlogBuilder faultAlarm = new FaultlogBuilder(); - faultAlarm.setNodeId(nodeId.getValue()); - faultAlarm.setObjectId(notification.getFaultSource()); - faultAlarm.setProblem(notification.getFaultText()); - faultAlarm.setSeverity(getSeverityType(notification.getFaultSeverity(), notification.isIsCleared())); - faultAlarm.setCounter(counter); - faultAlarm.setId(String.valueOf(notification.getFaultId())); - faultAlarm.setSourceType(SourceType.Netconf); - faultAlarm.setTimestamp(notification.getEventTime()); - return faultAlarm.build(); - } - - /** - * Convert O-RAN specific severity into data-provider severity - * - * @param faultSeverity O-RAN severity - * @param isCleared clear indicator - * @return data-provider severity type - * @throws IllegalArgumentException if conversion not possible. - */ - public static SeverityType getSeverityType(@Nullable FaultSeverity faultSeverity, @Nullable Boolean isCleared) - throws IllegalArgumentException { - if (isCleared != null && isCleared) { - return SeverityType.NonAlarmed; - } - if (faultSeverity != null) { - switch (faultSeverity) { - case CRITICAL: - return SeverityType.Critical; - case MAJOR: - return SeverityType.Major; - case MINOR: - return SeverityType.Minor; - case WARNING: - return SeverityType.Warning; - } - } - throw new IllegalArgumentException("Unknown Alarm state represent as Critical. isCleared=" + isCleared - + " faultSeverity=" + faultSeverity); - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/DeviceManagerORanImpl.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/DeviceManagerORanImpl.java new file mode 100644 index 000000000..7e04e8c1a --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/DeviceManagerORanImpl.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup.ORanNetworkElementFactory; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeviceManagerORanImpl implements AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerORanImpl.class); + private static final String APPLICATION_NAME = "DeviceManagerORan"; + @SuppressWarnings("unused") + private static final String CONFIGURATIONFILE = "etc/devicemanager-oran.properties"; + + + private NetconfNetworkElementService netconfNetworkElementService; + + private HtDatabaseClient htDatabaseClient; + private Boolean devicemanagerInitializationOk = false; + private FactoryRegistration resORan; + + // Blueprint begin + public DeviceManagerORanImpl() { + LOG.info("Creating provider for {}", APPLICATION_NAME); + resORan = null; + } + + public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) { + this.netconfNetworkElementService = netconfNetworkElementService; + } + + public void init() throws Exception { + + LOG.info("Session Initiated start {}", APPLICATION_NAME); + + resORan = netconfNetworkElementService.registerBindingNetworkElementFactory(new ORanNetworkElementFactory()); + + + netconfNetworkElementService.writeToEventLog(APPLICATION_NAME, "startup", "done"); + this.devicemanagerInitializationOk = true; + + LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk); + } + // Blueprint end + + @Override + public void close() throws Exception { + LOG.info("closing ..."); + close(htDatabaseClient); + close(resORan); + LOG.info("closing done"); + } + + /** + * Used to close all Services, that should support AutoCloseable Pattern + * + * @param toClose + * @throws Exception + */ + private void close(AutoCloseable... toCloseList) { + for (AutoCloseable element : toCloseList) { + if (element != null) { + try { + element.close(); + } catch (Exception e) { + LOG.warn("Fail during close: ", e); + } + } + } + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanChangeNotificationListener.java new file mode 100644 index 000000000..abed01a44 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanChangeNotificationListener.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.util.List; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Listener for change notifications + */ +public class ORanChangeNotificationListener implements IetfNetconfNotificationsListener { + + private static final Logger log = LoggerFactory.getLogger(ORanChangeNotificationListener.class); + + private final NetconfBindingAccessor netconfAccessor; + private final DataProvider databaseService; + private final NotificationService notificationService; + private final VESCollectorService vesCollectorService; + private final NotificationProxyParser notificationProxyParser; + private ORanNotifToVESEventAssembly mapper = null; + + private static int sequenceNo = 0; + + public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, + DeviceManagerServiceProvider serviceProvider) { + this.netconfAccessor = netconfAccessor; + this.databaseService = serviceProvider.getDataProvider(); + this.notificationService = serviceProvider.getNotificationService(); + this.vesCollectorService = serviceProvider.getVESCollectorService(); + this.notificationProxyParser = vesCollectorService.getNotificationProxyParser(); + } + + @Override + public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) { + log.info("onNetconfConfirmedCommit {}", notification); + } + + @Override + public void onNetconfSessionStart(NetconfSessionStart notification) { + log.info("onNetconfSessionStart {}", notification); + } + + @Override + public void onNetconfSessionEnd(NetconfSessionEnd notification) { + log.info("onNetconfSessionEnd {}", notification); + } + + @Override + public void onNetconfCapabilityChange(NetconfCapabilityChange notification) { + log.info("onNetconfCapabilityChange {}", notification); + } + + @Override + public void onNetconfConfigChange(NetconfConfigChange notification) { + log.info("onNetconfConfigChange (1) {}", notification.toString()); + + StringBuffer sb = new StringBuffer(); + List editList = notification.nonnullEdit(); + for (Edit edit : editList) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(edit); + + InstanceIdentifier target = edit.getTarget(); + if (target != null) { + log.info("TARGET: {} {}", target.getClass(), target.getTargetType()); + for (PathArgument pa : target.getPathArguments()) { + log.info("PathArgument {} Type {}", pa, pa.getType().getFields()); + } + + EventlogEntity eventLogEntity1 = new EventlogBuilder().setNodeId(netconfAccessor.getNodeId().getValue()) + .setCounter(sequenceNo++).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) + .setObjectId(target.getTargetType().getCanonicalName()).setAttributeName("N.A") + .setSourceType(SourceType.Netconf).setNewValue(String.valueOf(edit.getOperation())).build(); + databaseService.writeEventLog(eventLogEntity1); + } + } + log.info("onNetconfConfigChange (2) {}", sb); + + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + if (mapper == null) { + this.mapper = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService); + } + VESCommonEventHeaderPOJO header = + mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification), + NetconfConfigChange.class.getSimpleName(), sequenceNo); + VESNotificationFieldsPOJO body = + mapper.createVESNotificationFields(notificationProxyParser.parseNotificationProxy(notification), + NetconfConfigChange.class.getSimpleName()); + try { + vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + } catch (JsonProcessingException e) { + log.warn("Exception while generating JSON object ", e); + + } + } + + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultNotificationListener.java new file mode 100644 index 000000000..d03b39480 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultNotificationListener.java @@ -0,0 +1,166 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.time.Instant; +import java.time.format.DateTimeParseException; +import java.util.Collection; +import java.util.Date; +import java.util.Objects; +import org.eclipse.jdt.annotation.NonNull; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.ORanFmListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanFaultNotificationListener implements ORanFmListener { + + private static final Logger LOG = LoggerFactory.getLogger(ORanFaultNotificationListener.class); + + private final @NonNull NetconfBindingAccessor netconfAccessor; + private final @NonNull VESCollectorService vesCollectorService; + private final @NonNull ORanFaultToVESFaultMapper mapper; + private final @NonNull FaultService faultService; + private final @NonNull WebsocketManagerService websocketManagerService; + private final @NonNull DataProvider databaseService; + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter(); + + private Integer counter; //Local counter is assigned to Notifications + + public ORanFaultNotificationListener(@NonNull NetconfBindingAccessor netconfAccessor, + @NonNull VESCollectorService vesCollectorService, @NonNull FaultService faultService, + @NonNull WebsocketManagerService websocketManagerService, @NonNull DataProvider databaseService) { + this.netconfAccessor = Objects.requireNonNull(netconfAccessor); + this.vesCollectorService = Objects.requireNonNull(vesCollectorService); + this.faultService = Objects.requireNonNull(faultService); + this.websocketManagerService = Objects.requireNonNull(websocketManagerService); + this.databaseService = Objects.requireNonNull(databaseService); + + this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService, + AlarmNotif.class.getSimpleName()); + this.counter = 0; + } + + /** + * Gets the mfg name, mode-name and Uuid of the root component (Ex: Chassis.) + * In cases where there are multiple root components i.e., components with no parent, + * the Uuid of the last occurred component from the componentList will be considered. + * Till now we haven't seen Uuid set for root components, so not an issue for now. + * @param componentList + */ + public void setComponentList(Collection componentList) { + for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) { + mapper.setMfgName(component.getMfgName()); + mapper.setUuid(component.getUuid()!=null?component.getUuid().getValue():netconfAccessor.getNodeId().getValue()); + mapper.setModelName(component.getModelName()); + } + } + + @Override + public void onAlarmNotif(AlarmNotif notification) { + + LOG.debug("onAlarmNotif {}", notification.getClass().getSimpleName()); + counter++; + + // Send devicemanager specific notification for database and ODLUX + Instant eventTimeInstant = ORanToInternalDataModel.getInstantTime(notification.getEventTime()); + faultService.faultNotification( + ORanToInternalDataModel.getFaultLog(notification, netconfAccessor.getNodeId(), counter)); + // Send model specific notification to WebSocketManager + websocketManagerService.sendNotification(notification, netconfAccessor.getNodeId(), AlarmNotif.QNAME); + + try { + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); + VESFaultFieldsPOJO body = mapper.mapFaultFields(notification); + VESMessage vesMsg = vesCollectorService.generateVESEvent(header, body); + vesCollectorService.publishVESMessage(vesMsg); + LOG.info("VES Message is {}",vesMsg.getMessage()); + writeToEventLog(vesMsg.getMessage(), eventTimeInstant, AlarmNotif.QNAME.toString(), counter); + } + } catch (JsonProcessingException | DateTimeParseException e) { + LOG.debug("Can not convert event into VES message {}", notification, e); + } + } + + private void writeToEventLog(String data, Instant instant, String notificationName, + int sequenceNo) { + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + + eventlogBuilder.setObjectId("Device"); + eventlogBuilder.setCounter(sequenceNo); + eventlogBuilder.setAttributeName(notificationName); + eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()); + String eventLogMsgLvl = vesCollectorService.getConfig().getEventLogMsgDetail(); + if (eventLogMsgLvl.equalsIgnoreCase("SHORT")) { + data = getShortEventLogMessage(data); + } else if (eventLogMsgLvl.equalsIgnoreCase("MEDIUM")) { + data = getMediumEventLogMessage(data); + } else if (eventLogMsgLvl.equalsIgnoreCase("LONG")) { + // do nothing, data already contains long message + } else { // Unknown value, default to "SHORT" + data = getShortEventLogMessage(data); + } + eventlogBuilder.setNewValue(data); + eventlogBuilder.setSourceType(SourceType.Netconf); + + Date eventDate = Date.from(instant); + eventlogBuilder.setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp(eventDate))); + + databaseService.writeEventLog(eventlogBuilder.build()); + } + + private String getShortEventLogMessage(String data) { + try { + JSONObject jsonObj = new JSONObject(data); + String domain = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("domain"); + String eventId = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("eventId"); + return "domain:" + domain + " eventId:" + eventId; + } catch (JSONException e) { + LOG.debug("{}", e); + return "Invalid message received"; + } + } + + private String getMediumEventLogMessage(String data) { + try { + JSONObject jsonObj = new JSONObject(data); + return jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").toString(); + } catch (JSONException e) { + LOG.debug("{}", e); + return "Invalid message received"; + } + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultToVESFaultMapper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultToVESFaultMapper.java new file mode 100644 index 000000000..f5873df96 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanFaultToVESFaultMapper.java @@ -0,0 +1,164 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import java.time.Instant; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +//@formatter:off +/* + * Maps ORAN Fault fields to VES fault domain fields and VES commonEventHeader fields + * + * + * VES Fields Mapping + * ---------- ------- + * domain "fault" + * eventId "nt:network-topology/nt:topology/nt:node/nt:node-id" + * eventName "nt:network-topology/nt:topology/nt:node/nt:node-id" + * eventType "O-RAN-RU-Fault" + * lastEpochMicrosec TimeStamp represented by field in NetConf notification header in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. + * nfcNamingCode always "" + * nfNamingCode always "" + * nfVendorName /ietf-hardware:hardware/component[not(parent)][1]/mfg-name + * priority "Normal" + * reportingEntityId The OAM-Controller identifier with in the SMO - e.g. the fully qualified domain name or IP-Address. + * reportingEntityName as configured by helm charts for the OpenDaylight cluster name ?????? + * sequence As per NetConf notification increasing sequence number as unsigned integer 32 bits. The value is reused in the eventId field. + * sourceId Value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/uuid or 'nt:network-topology/nt:topology/nt:node/nt:node-id' if ietf component not found. + * sourceName "nt:network-topology/nt:topology/nt:node/nt:node-id" + * startEpochMicrosec Current OAM-Controller Node timestamp in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. + * timeZoneOffset Static text: "+00:00" + * version "4.1" + * vesEventListenerVersion "7.2.1" + * + * + * alarmAdditionalInformation + * alarmCondition Value of "o-ran-fm:alarm-notif/fault-id" + * alarmInterfaceA Value of "o-ran-fm:alarm-notif/fault-source" + * eventCategory Static text "O-RU failure" + * eventSeverity Value of "o-ran-fm:alarm-notif/fault-severity". But if "o-ran-fm:alarm-notif/is-cleared" then "NORMAL" + * eventSourceType The value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/model-name or "O-RU" if not found. + * faultFieldsVersion "4.0" + * specificProblem A mapping of the fault-id to its description according to O-RAN OpenFronthaul specification. + * vfStatus "Active" + * + */ +//@formatter:on + +public class ORanFaultToVESFaultMapper { + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class); + private static final String VES_EVENT_DOMAIN = "fault"; + private static final String VES_EVENTTYPE = "ORAN_Fault"; + private static final String VES_EVENT_PRIORITY = "Normal"; + private static final String VES_EVENT_CATEGORY = "O-RU Failure"; + private static final String VES_FAULT_FIELDS_VERSION = "4.0"; + private static final String VES_FAULT_FIELDS_VFSTATUS = "Active"; //virtual function status + + private final VESCollectorService vesProvider; + private final String notifName; // Name + private final String nodeIdString; // Sourcename + private String mfgName; + private String uuid; + private String modelName; + + public ORanFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService, + String notifName) { + this.nodeIdString = nodeId.getValue(); + this.vesProvider = vesCollectorService; + this.notifName = notifName; + } + + public void setMfgName(String mfgName) { + this.mfgName= mfgName; + } + + private String getMfgName() { + return mfgName; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + private String getUuid() { + return uuid; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + private String getModelName() { + return modelName; + } + + public VESCommonEventHeaderPOJO mapCommonEventHeader(AlarmNotif notification, Instant eventTime, int sequenceNo) { + VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); + vesCEH.setDomain(VES_EVENT_DOMAIN); + vesCEH.setEventName(notifName); + vesCEH.setEventType(VES_EVENTTYPE); + vesCEH.setPriority(VES_EVENT_PRIORITY); + + String eventId; + + eventId = notifName + "-" + Long.toUnsignedString(sequenceNo); + + vesCEH.setEventId(eventId); + vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000); + vesCEH.setNfVendorName(getMfgName()); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo); + vesCEH.setSourceId(getUuid()); + vesCEH.setSourceName(nodeIdString); + + return vesCEH; + } + + public VESFaultFieldsPOJO mapFaultFields(AlarmNotif alarmNotif) { + VESFaultFieldsPOJO vesFaultFields = new VESFaultFieldsPOJO(); + + vesFaultFields.setAlarmCondition(alarmNotif.getFaultId().toString()); + vesFaultFields.setAlarmInterfaceA(alarmNotif.getFaultSource()); + vesFaultFields.setEventCategory(VES_EVENT_CATEGORY); + if (alarmNotif.getIsCleared()) { + vesFaultFields.setEventSeverity("NORMAL"); + } else { + vesFaultFields.setEventSeverity(alarmNotif.getFaultSeverity().getName()); + } + vesFaultFields.setEventSourceType(getModelName()); + vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION); + vesFaultFields.setSpecificProblem(alarmNotif.getFaultText()); + vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS); + + return vesFaultFields; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNetworkElement.java new file mode 100644 index 000000000..e16df1d1c --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNetworkElement.java @@ -0,0 +1,278 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.common.QName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanNetworkElement implements NetworkElement { + + private static final Logger LOG = LoggerFactory.getLogger(ORanNetworkElement.class); + + public static final QName ONAP_SYSTEM = + org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.$YangModuleInfoImpl.getInstance().getName(); + private static final InstanceIdentifier SYSTEM1_IID = InstanceIdentifier + .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class) + .augmentation(System1.class).build(); + + private final NetconfBindingAccessor netconfAccessor; + private final Optional netconfAccessorOpt; + + private final Optional netconfDomAccessor; + private final DataProvider databaseService; + private final ORanRegistrationToVESpnfRegistrationMapper mapper; + private final VESCollectorService vesCollectorService; + + private ListenerRegistration oRanListenerRegistrationResult; + //private @NonNull final ORanChangeNotificationListener oRanListener; + private ListenerRegistration oRanFaultListenerRegistrationResult; + private @NonNull final ORanFaultNotificationListener oRanFaultListener; + + //ORanNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + ORanNetworkElement(NetconfAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + LOG.info("Create {}", ORanNetworkElement.class.getSimpleName()); + // Read parameters + this.netconfAccessorOpt = netconfAccess.getNetconfBindingAccessor(); + this.netconfAccessor = netconfAccessorOpt.get(); + this.netconfDomAccessor = netconfAccess.getNetconfDomAccessor(); + // Get services + this.databaseService = serviceProvider.getDataProvider(); + this.vesCollectorService = serviceProvider.getVESCollectorService(); + + this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, vesCollectorService); + + // Register callbacks + this.oRanListenerRegistrationResult = null; + //this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, serviceProvider); + + this.oRanFaultListenerRegistrationResult = null; + this.oRanFaultListener = new ORanFaultNotificationListener(netconfAccessor, vesCollectorService, + serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService); + + } + + private Collection initialReadFromNetworkElement() { + Collection componentList; + Hardware hardware = readHardware(); + if (hardware != null) { + componentList = YangHelper.getCollection(hardware.nonnullComponent()); + List inventoryList = + ORanToInternalDataModel.getInventoryList(netconfAccessor.getNodeId(), componentList); + databaseService.writeInventory(netconfAccessor.getNodeId().getValue(), inventoryList); + } else { + componentList = Collections.emptyList(); + } + + Optional oGuicutthrough = ORanToInternalDataModel.getGuicutthrough(getOnapSystemData()); + if (oGuicutthrough.isPresent()) { + databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfAccessor.getNodeId().getValue()); + } + return componentList; + } + + @Override + public NetworkElementDeviceType getDeviceType() { + return NetworkElementDeviceType.ORAN; + } + + @Override + public void register() { + // Read data from device + Collection componentList = initialReadFromNetworkElement(); + oRanFaultListener.setComponentList(componentList); + // Publish the mountpoint to VES if enabled + publishMountpointToVES(componentList); + // Register call back class for receiving notifications + //this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener); + this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener); + // Register notifications stream + /*if (netconfAccessor.isNotificationsRFC5277Supported()) { + netconfAccessor.registerNotificationsStream(); + }*/ + + QName[] notifications = { NetconfConfigChange.QNAME, NetconfConfirmedCommit.QNAME, + NetconfSessionStart.QNAME, NetconfSessionEnd.QNAME, NetconfCapabilityChange.QNAME }; + //netconfDomAccessor.get().doRegisterNotificationListener(new ORanDOMChangeNotificationListener(netconfDomAccessor.get(), databaseService), notifications); + // Output notification streams to LOG + Map streams = netconfDomAccessor.get().getNotificationStreamsAsMap(); + LOG.info("Available notifications streams: {}", streams); + // Register to default stream + netconfDomAccessor.get().invokeCreateSubscription(); + } + + @Override + public void deregister() { + if (oRanListenerRegistrationResult != null) { + this.oRanListenerRegistrationResult.close(); + } + if (oRanFaultListenerRegistrationResult != null) { + this.oRanFaultListenerRegistrationResult.close(); + } ; + databaseService.clearGuiCutThroughEntriesOfNode(getMountpointId()); + } + + @Override + public NodeId getNodeId() { + return netconfAccessor.getNodeId(); + } + + @Override + public Optional getService(Class clazz) { + return Optional.empty(); + } + + @Override + public void warmstart() {} + + @Override + public Optional getAcessor() { + return Optional.of(netconfAccessor); + } + + // Private functions + + private String getMountpointId() { + return getNodeId().getValue(); + } + + // Read from device + /** + * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported. + * + * @return System1 data with GUI cut through information or null if not available. + */ + private @Nullable System1 getOnapSystemData() { + LOG.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue()); + Capabilities x = netconfAccessor.getCapabilites(); + LOG.info("Capabilites: {}", x); + if (x.isSupportingNamespace(ONAP_SYSTEM)) { + @Nullable + System1 res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, SYSTEM1_IID); + LOG.debug("Result of System1 = {}", res); + return res; + } else { + LOG.debug("No GUI cut through support"); + return null; + } + } + + private Hardware readHardware() { + final Class clazzPac = Hardware.class; + LOG.info("DBRead Get hardware for class {} from mountpoint {}", clazzPac.getSimpleName(), + netconfAccessor.getNodeId().getValue()); + InstanceIdentifier hardwareIID = InstanceIdentifier.builder(clazzPac).build(); + Hardware res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, hardwareIID); + LOG.debug("Result of Hardware = {}", res); + return res; + } + + // VES related + private void publishMountpointToVES(Collection componentList) { + + LOG.debug("In publishMountpointToVES()"); + + /* + * 1. Check if this device is in the list of allowed-devices. 2. If device + * exists in allowed-devices, then create VES pnfRegistration event and publish + * to VES + */ + if (inAllowedDevices(getMountpointId())) { + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) { + // Just get one component. At the moment we don't care which one. Also since + // there is only one management address, we assume there will be only one + // chassis. + // If the device supports subtended configuration then it is assumed that the + // Chassis containing the management interface will be the root component and + // there will be only one root. + /*VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(component); + VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(component); + try { + vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + } catch (JsonProcessingException e) { + LOG.warn("Error while serializing VES Event to String ", e); + }*/ + } + } + } + } + + private boolean inAllowedDevices(String mountpointName) { + final InstanceIdentifier ALL_DEVICES = + InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class); + + AllowedDevices allowedDevices = netconfAccessor.getTransactionUtils().readData( + netconfAccessor.getControllerBindingDataBroker(), LogicalDatastoreType.CONFIGURATION, ALL_DEVICES); + + if (allowedDevices != null) { + Collection deviceList = YangHelper.getCollection(allowedDevices.nonnullDevice()); + for (Device device : deviceList) { + LOG.info("Device in allowed-devices is - {}", device.getUniqueId()); + if (device.getUniqueId().equals(netconfAccessor.getNodeId().getValue())) { + LOG.info("Mountpoint is part of allowed-devices list"); + return true; + } + } + } + + LOG.info("Mountpoint {} is not part of allowed-devices list", mountpointName); + return false; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNotifToVESEventAssembly.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNotifToVESEventAssembly.java new file mode 100644 index 000000000..6e31ffb6f --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanNotifToVESEventAssembly.java @@ -0,0 +1,99 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanNotifToVESEventAssembly { + + private static final Logger log = LoggerFactory.getLogger(ORanNotifToVESEventAssembly.class); + private static final String VES_EVENT_DOMAIN = "notification"; + private static final String VES_EVENTTYPE = "ORAN_notification"; + private static final String VES_EVENT_PRIORITY = "Normal"; + private NetconfBindingAccessor netconfAccessor; + private VESCollectorService vesProvider; + + public ORanNotifToVESEventAssembly(NetconfBindingAccessor netconfAccessor, VESCollectorService vesProvider) { + this.netconfAccessor = netconfAccessor; + this.vesProvider = vesProvider; + } + + // VES CommonEventHeader fields + public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName, + long sequenceNo) { + VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); + vesCEH.setDomain(VES_EVENT_DOMAIN); + vesCEH.setEventName(notificationTypeName); + vesCEH.setEventType(VES_EVENTTYPE); + vesCEH.setPriority(VES_EVENT_PRIORITY); + + String eventId; + + eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo); + + vesCEH.setEventId(eventId); + vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000); + vesCEH.setNfVendorName("ORAN"); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo); + vesCEH.setSourceId("ORAN"); + vesCEH.setSourceName(netconfAccessor.getNodeId().getValue()); + return vesCEH; + } + + // Notification fields + public VESNotificationFieldsPOJO createVESNotificationFields(HashMap xPathFields, + String notificationTypeName) { + VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO(); + + vesNotifFields.setChangeType(notificationTypeName); + vesNotifFields.setChangeIdentifier(netconfAccessor.getNodeId().getValue()); + + StringBuffer buf = new StringBuffer(); + Iterator> it = xPathFields.entrySet().iterator(); + while (it.hasNext()) { + Entry pair = it.next(); + buf.append("\n" + pair.getKey() + " = " + pair.getValue()); + } + log.info("Resultlist({}):{}", xPathFields.size(), buf.toString()); + + ArrayList> arrayOfNamedHashMap = new ArrayList>(); + HashMap namedHashMap = new HashMap(); + namedHashMap.put("hashMap", xPathFields); + namedHashMap.put("name", notificationTypeName); + arrayOfNamedHashMap.add(namedHashMap); + vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap); + return vesNotifFields; + + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanRegistrationToVESpnfRegistrationMapper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanRegistrationToVESpnfRegistrationMapper.java new file mode 100644 index 000000000..206abb5d7 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanRegistrationToVESpnfRegistrationMapper.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import java.time.Instant; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom.ORanDMDOMUtility; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom.ORanDeviceManagerQNames; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanRegistrationToVESpnfRegistrationMapper { + + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class); + //CommonEventHeader fields + private static final String VES_EVENT_DOMAIN = "pnfRegistration"; + private static final String VES_EVENTTYPE = "NetConf Callhome Registration"; + private static final String VES_EVENT_PRIORITY = "Normal"; + + private final VESCollectorService vesProvider; + private final NetconfAccessor netconfAccessor; + + private Integer sequenceNo; + + + public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor, + VESCollectorService vesCollectorService) { + this.netconfAccessor = netconfAccessor; + this.vesProvider = vesCollectorService; + + this.sequenceNo = 0; + } + + public VESCommonEventHeaderPOJO mapCommonEventHeader(MapEntryNode component) { + VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); + vesCEH.setDomain(VES_EVENT_DOMAIN); + vesCEH.setEventId(netconfAccessor.getNodeId().getValue()); + vesCEH.setEventName(netconfAccessor.getNodeId().getValue()); + vesCEH.setEventType(VES_EVENTTYPE); + vesCEH.setPriority(VES_EVENT_PRIORITY); + + vesCEH.setStartEpochMicrosec(Instant.now().toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000); + vesCEH.setNfVendorName( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME)); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo++); + vesCEH.setSourceId( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null + ? ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) + : netconfAccessor.getNodeId().getValue()); + vesCEH.setSourceName(netconfAccessor.getNodeId().getValue()); + + return vesCEH; + } + + public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(MapEntryNode component) { + VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO(); + vesPnfFields.setModelNumber( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME)); + vesPnfFields + .setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address() != null + ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv4Address().getValue() + : null); + vesPnfFields + .setOamV6IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address() != null + ? netconfAccessor.getNetconfNode().getHost().getIpAddress().getIpv6Address().getValue() + : null); + vesPnfFields.setSerialNumber( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SER_NUM)); + vesPnfFields.setVendorName( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME)); + vesPnfFields.setSoftwareVersion( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SW_REV)); + vesPnfFields.setUnitType( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_ALIAS)); + vesPnfFields.setUnitFamily( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CLASS)); + vesPnfFields + .setManufactureDate( + ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE) != null + ? ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE) + : "Unknown"); + //vesPnfFields.setLastServiceDate(component.getLastChange()); + + return vesPnfFields; + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanToInternalDataModel.java new file mode 100644 index 000000000..2469e46b7 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/binding/ORanToInternalDataModel.java @@ -0,0 +1,276 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.Alarm.FaultSeverity; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif; +import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.CodeHelpers; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Convert data to data-provider model and perform consistency checks.
+ * Component list characteristics:
+ *
    + *
  • component list is a flat list tree structure specified + *
  • via "component.getParent()": + *
      + *
    • If null we have a root element + *
    • if not null it is a child element with generated child level
      + *
    + *
+ * Example of List:
+ * + * + */ +public class ORanToInternalDataModel { + + private static final Logger log = LoggerFactory.getLogger(ORanToInternalDataModel.class); + + public static List getInventoryList(NodeId nodeId, Collection componentList) { + + List inventoryResultList = new ArrayList(); + for (Component component : getRootComponents(componentList)) { + inventoryResultList = recurseGetInventory(nodeId, component, componentList, 0, inventoryResultList); + } + // Verify if result is complete + if (componentList.size() != inventoryResultList.size()) { + log.warn( + "Not all data were written to the Inventory. Potential entries with missing " + + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}", + nodeId.getValue(), componentList.size(), inventoryResultList.size()); + } + return inventoryResultList; + } + + private static List recurseGetInventory(NodeId nodeId, Component component, + Collection componentList, int treeLevel, List inventoryResultList) { + + //Add element to list, if conversion successfull + Optional oInventory = getInternalEquipment(nodeId, component, treeLevel); + if (oInventory.isPresent()) { + inventoryResultList.add(oInventory.get()); + } + //Walk trough list of child keys and add to list + for (String childUuid : CodeHelpers.nonnull(component.getContainsChild())) { + for (Component c : getComponentsByName(childUuid, componentList)) { + inventoryResultList = recurseGetInventory(nodeId, c, componentList, treeLevel + 1, inventoryResultList); + } + } + return inventoryResultList; + } + + public static List getRootComponents(Collection componentList) { + List resultList = new ArrayList<>(); + for (Component c : componentList) { + if (c.getParent() == null) { // Root elements do not have a parent + resultList.add(c); + } + } + return resultList; + } + + private static List getComponentsByName(String name, Collection componentList) { + List resultList = new ArrayList<>(); + for (Component c : componentList) { + if (name.equals(c.getName())) { // <-- Component list is flat search for child's of name + resultList.add(c); + } + } + return resultList; + } + + /** + * Convert equipment into Inventory. Decide if inventory can by created from content or not. Public for test case. + * + * @param nodeId of node (Similar to mountpointId) + * @param component to handle + * @param treeLevel of components + * @return Inventory if possible to be created. + */ + public static Optional getInternalEquipment(NodeId nodeId, Component component, int treeLevel) { + + // Make sure that expected data are not null + Objects.requireNonNull(nodeId); + Objects.requireNonNull(component); + + // Read manadatory data + + @Nullable + String nodeIdString = nodeId.getValue(); + @Nullable + String uuid = component.getName(); + @Nullable + String idParent = component.getParent(); + @Nullable + String uuidParent = idParent != null ? idParent : uuid; //<- Passt nicht + + // do consistency check if all mandatory parameters are there + if (treeLevel >= 0 && nodeIdString != null && uuid != null && uuidParent != null) { + + // Build output data + + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + + // General assumed as mandatory + inventoryBuilder.setNodeId(nodeIdString); + inventoryBuilder.setUuid(uuid); + inventoryBuilder.setParentUuid(uuidParent); + inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel)); + + // -- String list with ids of holders (optional) + inventoryBuilder.setContainedHolder(CodeHelpers.nonnull(component.getContainsChild())); + + // -- Manufacturer related things (optional) + @Nullable + String mfgName = component.getMfgName(); + inventoryBuilder.setManufacturerName(mfgName); + inventoryBuilder.setManufacturerIdentifier(mfgName); + + // Equipment type (optional) + inventoryBuilder.setDescription(component.getDescription()); + inventoryBuilder.setModelIdentifier(component.getModelName()); + @Nullable + Class xmlClass = component.getXmlClass(); + if (xmlClass != null) { + inventoryBuilder.setPartTypeId(xmlClass.getName()); + } + inventoryBuilder.setTypeName(component.getName()); + inventoryBuilder.setVersion(component.getHardwareRev()); + + // Equipment instance (optional) + @Nullable + DateAndTime mfgDate = component.getMfgDate(); + if (mfgDate != null) { + inventoryBuilder.setDate(mfgDate.getValue()); + } + inventoryBuilder.setSerial(component.getSerialNum()); + + return Optional.of(inventoryBuilder.build()); + } + return Optional.empty(); + } + + /** + * If system data is available convert + * + * @param sys + * @return + */ + public static Optional getGuicutthrough(@Nullable System1 sys) { + if (sys != null) { + String name = sys.getName(); + @Nullable + Uri uri = sys.getWebUi(); + if (uri != null) { + GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder(); + if (name != null) { + gcBuilder.setName(name); + } + gcBuilder.setWeburi(uri.getValue()); + return Optional.of(gcBuilder.build()); + } + log.warn("Uri not set to invoke a Gui cut through session to the device. Please set the Uri in the device"); + } + log.warn("Retrieving augmented System details failed. Gui cut through information not available"); + return Optional.empty(); + } + + /** + * Convert netconf time into Instant + * + * @param eventTime with netconf time + * @return Instant with converted time. If not convertable provide Instant.Min + */ + public static Instant getInstantTime(@Nullable DateAndTime eventTime) { + return eventTime != null ? Instant.parse(eventTime.getValue()) : Instant.MIN; + } + + /** + * Convert fault notification into data-provider FaultLogEntity + * + * @param notification with O-RAN notification + * @param nodeId of node to handle + * @param counter to be integrated into data + * @return FaultlogEntity with data + */ + public static FaultlogEntity getFaultLog(AlarmNotif notification, NodeId nodeId, Integer counter) { + FaultlogBuilder faultAlarm = new FaultlogBuilder(); + faultAlarm.setNodeId(nodeId.getValue()); + faultAlarm.setObjectId(notification.getFaultSource()); + faultAlarm.setProblem(notification.getFaultText()); + faultAlarm.setSeverity(getSeverityType(notification.getFaultSeverity(), notification.getIsCleared())); + faultAlarm.setCounter(counter); + faultAlarm.setId(String.valueOf(notification.getFaultId())); + faultAlarm.setSourceType(SourceType.Netconf); + faultAlarm.setTimestamp(notification.getEventTime()); + return faultAlarm.build(); + } + + /** + * Convert O-RAN specific severity into data-provider severity + * + * @param faultSeverity O-RAN severity + * @param isCleared clear indicator + * @return data-provider severity type + * @throws IllegalArgumentException if conversion not possible. + */ + public static SeverityType getSeverityType(@Nullable FaultSeverity faultSeverity, @Nullable Boolean isCleared) + throws IllegalArgumentException { + if (isCleared != null && isCleared) { + return SeverityType.NonAlarmed; + } + if (faultSeverity != null) { + switch (faultSeverity) { + case CRITICAL: + return SeverityType.Critical; + case MAJOR: + return SeverityType.Major; + case MINOR: + return SeverityType.Minor; + case WARNING: + return SeverityType.Warning; + } + } + throw new IllegalArgumentException("Unknown Alarm state represent as Critical. isCleared=" + isCleared + + " faultSeverity=" + faultSeverity); + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/DOMNotificationToXPath.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/DOMNotificationToXPath.java new file mode 100644 index 000000000..64fb9b857 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/DOMNotificationToXPath.java @@ -0,0 +1,235 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import java.time.Instant; +import java.util.Collection; +import java.util.HashMap; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.mdsal.dom.api.DOMEvent; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.VerifyException; + +public class DOMNotificationToXPath { + private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationToXPath.class); + + public HashMap convertDomNotifToXPath(@NonNull DOMNotification domNotification) { + @NonNull + ContainerNode notifContainer = domNotification.getBody(); + HashMap xPathData = new HashMap(); + + Collection data = notifContainer.body(); + for (DataContainerChild data1 : data) { + String namePath = ""; + recurseDOMData(notifContainer, data1, notifContainer, xPathData, namePath); + } + LOG.debug("XPath Data = {}", xPathData); + return xPathData; + + } + + private void recurseDOMData(@NonNull ContainerNode notifContainer, DataContainerChild domData, DataContainerNode cn, + HashMap result, String namePath) { + PathArgument pa1 = domData.getIdentifier(); + namePath += "/" + pa1.getNodeType().getLocalName(); + if (domData.getClass().getSimpleName().equals("ImmutableContainerNode")) { + try { + ContainerNode cn1 = (ContainerNode) cn.getChildByArg(pa1); + for (DataContainerChild data1 : cn1.body()) { + recurseDOMData(notifContainer, data1, cn1, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (domData.getClass().getSimpleName().equals("ImmutableChoiceNode")) { + try { + ChoiceNode cn1 = (ChoiceNode) cn.getChildByArg(pa1); + for (DataContainerChild data1 : cn1.body()) { + // recurseChoiceData(data1, cn1, namePath); + recurseDOMData(notifContainer, data1, cn1, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (domData.getClass().getSimpleName().equals("ImmutableUnkeyedListNode")) { + try { + UnkeyedListNode cn1 = (UnkeyedListNode) cn.getChildByArg(pa1); + for (UnkeyedListEntryNode data1 : cn1.body()) { + recurseUnkeyedListEntryNodeData(data1, cn1, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (domData.getClass().getSimpleName().equals("ImmutableMapNode")) { + try { + MapNode cn1 = (MapNode) cn.getChildByArg(pa1); + for (MapEntryNode data1 : cn1.body()) { + recurseMapEntryNodeData(notifContainer, data1, cn1, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (domData.getClass().getSimpleName().equals("ImmutableLeafSetNode")) { + try { + LeafSetNode cn1 = (LeafSetNode) cn.getChildByArg(pa1); + for (LeafSetEntryNode data1 : cn1.body()) { + recurseLeafSetEntryNodeData(data1, cn1, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (domData.getClass().getSimpleName().equals("ImmutableLeafNode")) { + recurseLeafNode(domData, result, namePath); + } + } + + private void recurseLeafSetEntryNodeData(LeafSetEntryNode data, LeafSetNode cn1, + HashMap result, String namePath) { + PathArgument pa1 = data.getIdentifier(); + namePath += "/" + pa1.getNodeType().getLocalName(); + + if (data.getClass().getSimpleName().equals("ImmutableLeafSetEntryNode")) { + LOG.debug("{}={}", namePath, data.body()); + result.put(namePath, data.body().toString()); + } + } + + private void recurseMapEntryNodeData(@NonNull ContainerNode notifContainer, MapEntryNode data, MapNode cn1, + HashMap result, String namePath) { + PathArgument pa1 = data.getIdentifier(); + NodeIdentifierWithPredicates ni = data.getIdentifier(); + + for (QName qn : ni.keySet()) { + namePath += "/" + ni.getValue(qn); + } + + if (data.getClass().getSimpleName().equals("ImmutableMapEntryNode")) { + for (DataContainerChild data1 : data.body()) { + if (data1.getClass().getSimpleName().equals("ImmutableLeafSetNode")) { + try { + LeafSetNode cn2 = (LeafSetNode) data.getChildByArg(data1.getIdentifier()); + for (LeafSetEntryNode data2 : cn2.body()) { + recurseLeafSetEntryNodeData(data2, cn2, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", data1.getIdentifier()); + } + } else { + recurseLeafNode(data1, result, namePath); + } + } + } + + if (data.getClass().getSimpleName().equals("ImmutableLeafSetNode")) { + try { + LeafSetNode cn2 = (LeafSetNode) notifContainer.getChildByArg(pa1); + for (LeafSetEntryNode data1 : cn2.body()) { + recurseLeafSetEntryNodeData(data1, cn2, result, namePath); + } + } catch (VerifyException ve) { + LOG.debug("{} does not exist", pa1); + } + } + + if (data.getClass().getSimpleName().equals("ImmutableLeafNode")) { + LOG.debug("{}={}", namePath, data.body()); + result.put(namePath, data.body().toString()); + } + } + + private void recurseUnkeyedListEntryNodeData(UnkeyedListEntryNode data, UnkeyedListNode cn1, + HashMap result, String namePath) { + PathArgument pa1 = data.getIdentifier(); + namePath += "/" + pa1.getNodeType().getLocalName(); + + if (data.getClass().getSimpleName().equals("ImmutableUnkeyedListEntryNode")) { + for (DataContainerChild data1 : data.body()) { + recurseLeafNode(data1, result, namePath); + } + } + + if (data.getClass().getSimpleName().equals("ImmutableLeafNode")) { + LOG.debug("{}={}", namePath, data.body()); + result.put(namePath, data.body().toString()); + } + } + + public void recurseLeafNode(DataContainerChild data, HashMap result, String namePath) { + PathArgument pa1 = data.getIdentifier(); + if (!(data.getClass().getSimpleName().equals("ImmutableAugmentationNode"))) + namePath += "/" + pa1.getNodeType().getLocalName(); + if (data.getClass().getSimpleName().equals("ImmutableLeafNode")) { + LOG.debug("{}={}", namePath, data.body()); + result.put(namePath, data.body().toString()); + } + } + + public void recurseChoiceData(HashMap result, DataContainerChild data, ChoiceNode cn, + String namePath) { + PathArgument pa1 = data.getIdentifier(); + namePath += "/" + pa1.getNodeType().getLocalName(); + // NodeIdentifier nodeId = new NodeIdentifier(pa1.getNodeType()); + if (data.getClass().getSimpleName().equals("ImmutableLeafNode")) { + LOG.debug("{}={}", namePath, data.body()); + result.put(namePath, data.body().toString()); + } + } + + public Instant getTime(@NonNull DOMNotification domNotification) { + @NonNull + Instant eventTime; + if (domNotification instanceof DOMEvent) { + eventTime = ((DOMEvent) domNotification).getEventInstant(); + LOG.info("Event time {}", eventTime); + } else { + eventTime = Instant.now(); + LOG.info("Defaulting to actual time of processing the notification - {}", eventTime); + } + return eventTime; + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDMDOMUtility.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDMDOMUtility.java new file mode 100644 index 000000000..947677bb6 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDMDOMUtility.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import org.opendaylight.mdsal.dom.api.DOMEvent; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.VerifyException; + +public class ORanDMDOMUtility { + public static final Logger LOG = LoggerFactory.getLogger(ORanDMDOMUtility.class); + + public static String getKeyValue(MapEntryNode componentEntry) { + NodeIdentifierWithPredicates componentKey = componentEntry.getIdentifier(); // list key + return (String) componentKey.getValue(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_KEY); + } + + public static String getLeafValue(DataContainerNode componentEntry, QName leafQName) { + NodeIdentifier leafNodeIdentifier = new NodeIdentifier(leafQName); + try { + LeafNode optLeafNode = (LeafNode) componentEntry.getChildByArg(leafNodeIdentifier); + if (optLeafNode.body() instanceof QName) { + LOG.debug("Leaf is of type QName"); + } + return optLeafNode.body().toString(); + } catch (VerifyException ve) { + LOG.debug("Leaf with QName {} not found", leafQName.toString()); + return null; + } + } + + public static List getLeafListValue(DataContainerNode componentEntry, QName leafListQName) { + List containsChildList = new ArrayList(); + try { + DataContainerChild childSet = componentEntry.getChildByArg(new NodeIdentifier(leafListQName)); + Collection childEntry = (Collection) childSet.body(); + Iterator childEntryItr = childEntry.iterator(); + while (childEntryItr.hasNext()) { + LeafSetEntryNode childEntryNode = (LeafSetEntryNode) childEntryItr.next(); + containsChildList.add(childEntryNode.body().toString()); + } + } catch (VerifyException ve) { + LOG.debug("Child for {} does not exist", leafListQName); + } + return containsChildList; + } + + public static Instant getNotificationInstant(DOMNotification notification) { + if (notification instanceof DOMEvent) { + return ((DOMEvent) notification).getEventInstant(); + } else { + return Instant.now(); + } + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMChangeNotificationListener.java new file mode 100644 index 000000000..aa375eff7 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMChangeNotificationListener.java @@ -0,0 +1,150 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.time.Instant; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.opendaylight.mdsal.dom.api.DOMEvent; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.mdsal.dom.api.DOMNotificationListener; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.yang.binding.CodeHelpers; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanDOMChangeNotificationListener implements DOMNotificationListener { + + private static final Logger log = LoggerFactory.getLogger(ORanDOMChangeNotificationListener.class); + + private final NetconfDomAccessor netconfDomAccessor; + private final DataProvider databaseService; + private @NonNull VESCollectorService vesCollectorService; + private final DOMNotificationToXPath domNotificationXPath; + private ORanDOMNotifToVESEventAssembly mapper = null; + private static int sequenceNo = 0; + + public ORanDOMChangeNotificationListener(NetconfDomAccessor netconfDomAccessor, + @NonNull VESCollectorService vesCollectorService, DataProvider databaseService) { + this.netconfDomAccessor = netconfDomAccessor; + this.databaseService = databaseService; + this.vesCollectorService = vesCollectorService; + domNotificationXPath = new DOMNotificationToXPath(); + } + + @Override + public void onNotification(@NonNull DOMNotification domNotification) { + if (domNotification.getType() + .equals(Absolute.of(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE))) { + handleNetconfConfigChange(domNotification); + } + } + + private void handleNetconfConfigChange(@NonNull DOMNotification domNotification) { + DateAndTime eventTime; + Instant notificationEventTime = null; + if (domNotification instanceof DOMEvent) { + notificationEventTime = ((DOMEvent) domNotification).getEventInstant(); + eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp(notificationEventTime.toString()); + } else { + eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp(); + } + + ContainerNode cn = domNotification.getBody(); + + // Process the changed-by child +// ContainerNode changedByContainerNode = (ContainerNode) cn +// .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_CHANGEDBY)); +// ChoiceNode serverOrUserIDVal = (ChoiceNode) changedByContainerNode +// .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SERVERORUSER)); +// @SuppressWarnings("unused") +// String userIDValue = serverOrUserIDVal +// .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_USERNAME)).body() +// .toString(); +// @SuppressWarnings("unused") +// Integer sessionIDVal = Integer.valueOf(serverOrUserIDVal +// .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_SESSIONID)).body() +// .toString()); +// +// // Process the datastore child +// @SuppressWarnings("unused") +// String datastoreValue = cn +// .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_DATASTORE)).body() +// .toString(); + + // Process the edit child + UnkeyedListNode editList = (UnkeyedListNode) cn + .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_EDITNODE)); + if (editList != null) { + for (int listCnt = 0; listCnt < editList.size(); listCnt++) { + String operationValue = editList.childAt(listCnt) + .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_OPERATION)) + .body().toString(); + String targetValue = editList.childAt(listCnt) + .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_TARGET)) + .body().toString(); + + EventlogEntity eventLogEntity1 = new EventlogBuilder() + .setNodeId(netconfDomAccessor.getNodeId().getValue()).setCounter(sequenceNo++) + .setTimestamp(eventTime).setObjectId(targetValue).setAttributeName("N.A") + .setSourceType(SourceType.Netconf).setNewValue(String.valueOf(operationValue)).build(); + databaseService.writeEventLog(eventLogEntity1); + } + } + + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + if (mapper == null) { + this.mapper = new ORanDOMNotifToVESEventAssembly(netconfDomAccessor, vesCollectorService); + } + VESCommonEventHeaderPOJO header = mapper.createVESCommonEventHeader( + domNotificationXPath.getTime(domNotification), + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE.getLocalName(), + sequenceNo); + VESNotificationFieldsPOJO body = mapper.createVESNotificationFields( + domNotificationXPath.convertDomNotifToXPath(domNotification), + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE.getLocalName()); + log.info("domNotification in XPath format = {}", + domNotificationXPath.convertDomNotifToXPath(domNotification)); + try { + vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + } catch (JsonProcessingException e) { + log.warn("Exception while generating JSON object ", e); + + } + } + + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultNotificationListener.java new file mode 100644 index 000000000..494a01f71 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultNotificationListener.java @@ -0,0 +1,171 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.time.Instant; +import java.time.format.DateTimeParseException; +import java.util.Collection; +import java.util.Objects; +import org.eclipse.jdt.annotation.NonNull; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.mdsal.dom.api.DOMNotificationListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanDOMFaultNotificationListener implements DOMNotificationListener { + + private static final Logger LOG = LoggerFactory.getLogger(ORanDOMFaultNotificationListener.class); + + private final @NonNull NetconfDomAccessor netconfDomAccessor; + private final @NonNull VESCollectorService vesCollectorService; + private final @NonNull ORanDOMFaultToVESFaultMapper mapper; + private final @NonNull FaultService faultService; + private final @NonNull WebsocketManagerService websocketManagerService; + private final @NonNull DataProvider databaseService; + + private Integer counter; //Local counter is assigned to Notifications + + public ORanDOMFaultNotificationListener(@NonNull NetconfDomAccessor netconfDomAccessor, + @NonNull VESCollectorService vesCollectorService, @NonNull FaultService faultService, + @NonNull WebsocketManagerService websocketManagerService, @NonNull DataProvider databaseService) { + this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor); + this.vesCollectorService = Objects.requireNonNull(vesCollectorService); + this.faultService = Objects.requireNonNull(faultService); + this.websocketManagerService = Objects.requireNonNull(websocketManagerService); + this.databaseService = Objects.requireNonNull(databaseService); + + this.mapper = + new ORanDOMFaultToVESFaultMapper(netconfDomAccessor.getNodeId(), vesCollectorService, "AlarmNotif"); + this.counter = 0; + } + + @Override + public void onNotification(@NonNull DOMNotification notification) { + onAlarmNotif(notification); + } + + /** + * Gets the mfg name, mode-name and Uuid of the root component (Ex: Chassis.) In cases where there are multiple root + * components i.e., components with no parent, the Uuid of the last occurred component from the componentList will + * be considered. Till now we haven't seen Uuid set for root components, so not an issue for now. + * + * @param componentList + */ + public void setComponentList(Collection componentList) { + for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) { + mapper.setMfgName( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME)); + mapper.setUuid(ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) != null + ? ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_UUID) + : netconfDomAccessor.getNodeId().getValue()); + mapper.setModelName(ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MODEL_NAME)); + } + } + + public void onAlarmNotif(DOMNotification notification) { + + LOG.debug("onAlarmNotif {}", notification.getClass().getSimpleName()); + counter++; + // Send devicemanager specific notification for database and ODLUX + Instant eventTimeInstant = ORanDMDOMUtility.getNotificationInstant(notification); + faultService.faultNotification( + ORanDOMToInternalDataModel.getFaultLog(notification, netconfDomAccessor.getNodeId(), counter)); + // Send model specific notification to WebSocketManager + websocketManagerService.sendNotification(notification, netconfDomAccessor.getNodeId(), ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF); + + try { + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); + VESFaultFieldsPOJO body = mapper.mapFaultFields(notification); + VESMessage vesMsg = vesCollectorService.generateVESEvent(header, body); + vesCollectorService.publishVESMessage(vesMsg); + LOG.info("VES Message is {}", vesMsg.getMessage()); + writeToEventLog(vesMsg.getMessage(), eventTimeInstant, ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF.getLocalName(), counter); + } + } catch (JsonProcessingException | DateTimeParseException e) { + LOG.debug("Can not convert event into VES message {}", notification, e); + } + } + + private void writeToEventLog(String data, Instant eventTimeInstant, String notificationName, int sequenceNo) { + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + + eventlogBuilder.setObjectId("Device"); + eventlogBuilder.setCounter(sequenceNo); + eventlogBuilder.setAttributeName(notificationName); + eventlogBuilder.setNodeId(netconfDomAccessor.getNodeId().getValue()); + String eventLogMsgLvl = vesCollectorService.getConfig().getEventLogMsgDetail(); + if (eventLogMsgLvl.equalsIgnoreCase("SHORT")) { + data = getShortEventLogMessage(data); + } else if (eventLogMsgLvl.equalsIgnoreCase("MEDIUM")) { + data = getMediumEventLogMessage(data); + } else if (eventLogMsgLvl.equalsIgnoreCase("LONG")) { + // do nothing, data already contains long message + } else { // Unknown value, default to "SHORT" + data = getShortEventLogMessage(data); + } + eventlogBuilder.setNewValue(data); + eventlogBuilder.setSourceType(SourceType.Netconf); + eventlogBuilder.setTimestamp(ORanDOMToInternalDataModel.getDateAndTimeOfInstant(eventTimeInstant)); + + databaseService.writeEventLog(eventlogBuilder.build()); + } + + private String getShortEventLogMessage(String data) { + try { + JSONObject jsonObj = new JSONObject(data); + String domain = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("domain"); + String eventId = jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").getString("eventId"); + return "domain:" + domain + " eventId:" + eventId; + } catch (JSONException e) { + LOG.debug("{}", e); + return "Invalid message received"; + } + } + + private String getMediumEventLogMessage(String data) { + try { + JSONObject jsonObj = new JSONObject(data); + return jsonObj.getJSONObject("event").getJSONObject("commonEventHeader").toString(); + } catch (JSONException e) { + LOG.debug("{}", e); + return "Invalid message received"; + } + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultToVESFaultMapper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultToVESFaultMapper.java new file mode 100644 index 000000000..b05e83f9a --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMFaultToVESFaultMapper.java @@ -0,0 +1,155 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import java.time.Instant; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanFaultToVESFaultMapper; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +//@formatter:off +/* +* Maps ORAN Fault fields to VES fault domain fields and VES commonEventHeader fields +* +* +* VES Fields Mapping +* ---------- ------- +* domain "fault" +* eventId "nt:network-topology/nt:topology/nt:node/nt:node-id" +* eventName "nt:network-topology/nt:topology/nt:node/nt:node-id" +* eventType "O-RAN-RU-Fault" +* lastEpochMicrosec TimeStamp represented by field in NetConf notification header in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. +* nfcNamingCode always "" +* nfNamingCode always "" +* nfVendorName /ietf-hardware:hardware/component[not(parent)][1]/mfg-name +* priority "Normal" +* reportingEntityId The OAM-Controller identifier with in the SMO - e.g. the fully qualified domain name or IP-Address. +* reportingEntityName as configured by helm charts for the OpenDaylight cluster name ?????? +* sequence As per NetConf notification increasing sequence number as unsigned integer 32 bits. The value is reused in the eventId field. +* sourceId Value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/uuid or 'nt:network-topology/nt:topology/nt:node/nt:node-id' if ietf component not found. +* sourceName "nt:network-topology/nt:topology/nt:node/nt:node-id" +* startEpochMicrosec Current OAM-Controller Node timestamp in unix time format - as microseconds elapsed since 1 Jan 1970 not including leap seconds. +* timeZoneOffset Static text: "+00:00" +* version "4.1" +* vesEventListenerVersion "7.2.1" +* +* +* alarmAdditionalInformation +* alarmCondition Value of "o-ran-fm:alarm-notif/fault-id" +* alarmInterfaceA Value of "o-ran-fm:alarm-notif/fault-source" +* eventCategory Static text "O-RU failure" +* eventSeverity Value of "o-ran-fm:alarm-notif/fault-severity". But if "o-ran-fm:alarm-notif/is-cleared" then "NORMAL" +* eventSourceType The value of ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/model-name or "O-RU" if not found. +* faultFieldsVersion "4.0" +* specificProblem A mapping of the fault-id to its description according to O-RAN OpenFronthaul specification. +* vfStatus "Active" +* +*/ +//@formatter:on + +public class ORanDOMFaultToVESFaultMapper { + @SuppressWarnings("unused") + private static final Logger LOG = LoggerFactory.getLogger(ORanFaultToVESFaultMapper.class); + private static final String VES_EVENT_DOMAIN = "fault"; + private static final String VES_EVENTTYPE = "ORAN_Fault"; + private static final String VES_EVENT_PRIORITY = "Normal"; + private static final String VES_EVENT_CATEGORY = "O-RU Failure"; + private static final String VES_FAULT_FIELDS_VERSION = "4.0"; + private static final String VES_FAULT_FIELDS_VFSTATUS = "Active"; //virtual function status + + private final VESCollectorService vesProvider; + private final String notifName; // Name + private final String nodeIdString; // Sourcename + //Initialized during registration + private String mfgName; + private String uuid; + private String modelName; + + public ORanDOMFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService, String notifName) { + this.nodeIdString = nodeId.getValue(); + this.vesProvider = vesCollectorService; + this.notifName = notifName; + } + + public void setMfgName(String mfgName) { + this.mfgName = mfgName; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public VESCommonEventHeaderPOJO mapCommonEventHeader(DOMNotification notification, Instant eventTime, + int sequenceNo) { + VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); + vesCEH.setDomain(VES_EVENT_DOMAIN); + vesCEH.setEventName(notifName); + vesCEH.setEventType(VES_EVENTTYPE); + vesCEH.setPriority(VES_EVENT_PRIORITY); + + String eventId = notifName + "-" + Long.toUnsignedString(sequenceNo); + + vesCEH.setEventId(eventId); + vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000); + vesCEH.setNfVendorName(mfgName); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo); + vesCEH.setSourceId(uuid); + vesCEH.setSourceName(nodeIdString); + + return vesCEH; + } + + public VESFaultFieldsPOJO mapFaultFields(DOMNotification alarmNotif) { + VESFaultFieldsPOJO vesFaultFields = new VESFaultFieldsPOJO(); + ContainerNode cn = alarmNotif.getBody(); + vesFaultFields.setAlarmCondition(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_ID)); + vesFaultFields + .setAlarmInterfaceA(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_SOURCE)); + vesFaultFields.setEventCategory(VES_EVENT_CATEGORY); + if (ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_IS_CLEARED).equals("true")) { + vesFaultFields.setEventSeverity("NORMAL"); + } else { + vesFaultFields.setEventSeverity( + ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_SEVERITY)); + } + vesFaultFields.setEventSourceType(modelName); + vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION); + vesFaultFields + .setSpecificProblem(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_TEXT)); + vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS); + + return vesFaultFields; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNetworkElement.java new file mode 100644 index 000000000..64006339d --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNetworkElement.java @@ -0,0 +1,283 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.Sets; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanRegistrationToVESpnfRegistrationMapper; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanDOMNetworkElement implements NetworkElement { + + private static final Logger LOG = LoggerFactory.getLogger(ORanDOMNetworkElement.class); + + private final @NonNull NetconfDomAccessor netconfDomAccessor; + private final @NonNull DataProvider databaseService; + private final @NonNull FaultService faultService; + private final @NonNull NotificationService notificationService; + private final @NonNull ORanDOMChangeNotificationListener oranDomChangeNotificationListener; + private final @NonNull ORanDOMFaultNotificationListener oranDomFaultNotificationListener; + private final @NonNull VESCollectorService vesCollectorService; + private final @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper; + + public ORanDOMNetworkElement(@NonNull NetconfDomAccessor netconfDomAccessor, + @NonNull DeviceManagerServiceProvider serviceProvider) { + LOG.info("Create {}", ORanDOMNetworkElement.class.getSimpleName()); + this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor); + Objects.requireNonNull(serviceProvider); + this.databaseService = serviceProvider.getDataProvider(); + this.vesCollectorService = serviceProvider.getVESCollectorService(); + this.faultService = serviceProvider.getFaultService(); + this.notificationService = serviceProvider.getNotificationService(); + + this.oranDomChangeNotificationListener = + new ORanDOMChangeNotificationListener(netconfDomAccessor, vesCollectorService, databaseService); + + this.oranDomFaultNotificationListener = + new ORanDOMFaultNotificationListener(netconfDomAccessor, vesCollectorService, + serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService); + + this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfDomAccessor, vesCollectorService); + } + + @Override + public void register() { + Collection componentList = initialReadFromNetworkElement(); + oranDomFaultNotificationListener.setComponentList(componentList); + publishMountpointToVES(componentList); + QName[] notifications = {ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE, + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIRMED_COMMIT, + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_START, + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_END, + ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CAPABILITY_CHANGE}; + netconfDomAccessor.doRegisterNotificationListener(oranDomChangeNotificationListener, notifications); + QName[] faultNotification = {ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF}; + netconfDomAccessor.doRegisterNotificationListener(oranDomFaultNotificationListener, faultNotification); + // Output notification streams to LOG + @SuppressWarnings("unused") + Map streams = netconfDomAccessor.getNotificationStreamsAsMap(); + // Register to default stream + netconfDomAccessor.invokeCreateSubscription(); + } + + public Collection initialReadFromNetworkElement() { + Collection componentMapEntries = null; + NormalizedNode hwData = readHardware(); + + if (hwData != null) { + ContainerNode hwContainer = (ContainerNode) hwData; + MapNode componentMap = (MapNode) hwContainer + .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST)); + if (componentMap != null) { + componentMapEntries = componentMap.body(); + List inventoryList = + ORanDOMToInternalDataModel.getInventoryList(netconfDomAccessor.getNodeId(), hwData); + databaseService.writeInventory(netconfDomAccessor.getNodeId().getValue(), inventoryList); + } + } else { + componentMapEntries = Collections.emptyList(); + } + + Optional oGuicutthrough = ORanDOMToInternalDataModel.getGuicutthrough(getOnapSystemData()); + if (oGuicutthrough.isPresent()) { + databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfDomAccessor.getNodeId().getValue()); + } + return componentMapEntries; + } + + @Override + public void deregister() { + /* + * if (oranDomChangeNotificationListener != null) { + * this.oranDomChangeNotificationListener.close(); } if + * (oRanFaultListenerRegistrationResult != null) { + * this.oRanFaultListenerRegistrationResult.close(); } ; + */ + databaseService.clearGuiCutThroughEntriesOfNode(getMountpointId()); + } + + @Override + public NodeId getNodeId() { + return netconfDomAccessor.getNodeId(); + } + + @Override + public NetworkElementDeviceType getDeviceType() { + return NetworkElementDeviceType.ORAN; + } + + @Override + public Optional getService(Class clazz) { + return Optional.empty(); + } + + @Override + public void warmstart() {} + + @Override + public Optional getAcessor() { + return Optional.of(netconfDomAccessor); + } + + // Private functions + + private String getMountpointId() { + return getNodeId().getValue(); + } + + private NormalizedNode readHardware() { + InstanceIdentifierBuilder hardwareIIDBuilder = + YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_HW_CONTAINER); + + Optional oData = + netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, hardwareIIDBuilder.build()); + if (oData.isPresent()) { + return oData.get(); + } + return null; + } + + // Read from device + /** + * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported. + * + * @return NormalizedNode data with GUI cut through information or null if not available. + */ + private @Nullable NormalizedNode getOnapSystemData() { + LOG.info("Get System1 for mountpoint {}", netconfDomAccessor.getNodeId().getValue()); + @NonNull + InstanceIdentifierBuilder ietfSystemIID = + YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_SYSTEM_CONTAINER); + @NonNull + AugmentationIdentifier onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier.create( + Sets.newHashSet(ORanDeviceManagerQNames.ONAP_SYSTEM_NAME, ORanDeviceManagerQNames.ONAP_SYSTEM_WEB_UI)); + InstanceIdentifierBuilder augmentedOnapSystem = + YangInstanceIdentifier.builder(ietfSystemIID.build()).node(onapSystemIID); + Capabilities x = netconfDomAccessor.getCapabilites(); + LOG.info("Capabilites: {}", x); + if (x.isSupportingNamespace(ORanDeviceManagerQNames.ONAP_SYSTEM_QNAME)) { + Optional res = + netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, augmentedOnapSystem.build()); + LOG.debug("Result of System1 = {}", res); + return res.isPresent() ? res.get() : null; + } else { + LOG.debug("No GUI cut through support"); + return null; + } + } + + // VES related + private void publishMountpointToVES(Collection componentList) { + /* + * 1. Check if this device is in the list of allowed-devices. 2. If device + * exists in allowed-devices, then create VES pnfRegistration event and publish + * to VES + */ + if (vesCollectorService.getConfig().isVESCollectorEnabled() && inAllowedDevices(getMountpointId())) { + for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) { + // Just get one component. At the moment we don't care which one. Also since + // there is only one management address, we assume there will be only one + // chassis. + // If the device supports subtended configuration then it is assumed that the + // Chassis containing the management interface will be the root component and + // there will be only one root. + VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(component); + VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(component); + try { + vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + } catch (JsonProcessingException e) { + LOG.warn("Error while serializing VES Event to String ", e); + } + } + } + } + + private boolean inAllowedDevices(String mountpointName) { + InstanceIdentifierBuilder callhomeServerIID = + YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.CALLHOME_SERVER_CONTAINER); + final InstanceIdentifierBuilder allowedDevicesIID = YangInstanceIdentifier.builder(callhomeServerIID.build()) + .node(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE); + + Optional allowedDevices = netconfDomAccessor + .readControllerDataNode(LogicalDatastoreType.CONFIGURATION, allowedDevicesIID.build()); + + if (allowedDevices.isPresent()) { + ContainerNode allowedDevicesNode = (ContainerNode) allowedDevices.get(); + MapNode deviceList = (MapNode) allowedDevicesNode + .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_DEVICE_LIST)); + if (deviceList != null) { + Collection deviceListCollection = deviceList.body(); + for (MapEntryNode device : deviceListCollection) { + // String deviceName = device.getIdentifier() + // .getValue(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY).toString(); + String deviceName = ORanDMDOMUtility.getLeafValue(device, + ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY); + if (deviceName != null && deviceName.equals(mountpointName)) { + LOG.info("Mountpoint {} is part of allowed-devices list", mountpointName); + return true; + } + } + } + } + + LOG.info("Mountpoint {} is not part of allowed-devices list", mountpointName); + return false; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNotifToVESEventAssembly.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNotifToVESEventAssembly.java new file mode 100644 index 000000000..b8b5151fe --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMNotifToVESEventAssembly.java @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Objects; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanDOMNotifToVESEventAssembly { + + private static final Logger log = LoggerFactory.getLogger(ORanDOMNotifToVESEventAssembly.class); + private static final String VES_EVENT_DOMAIN = "notification"; + private static final String VES_EVENTTYPE = "ORAN_notification"; + private static final String VES_EVENT_PRIORITY = "Normal"; + private NetconfDomAccessor netconfDomAccessor; + private VESCollectorService vesProvider; + + public ORanDOMNotifToVESEventAssembly(@NonNull NetconfDomAccessor netconfDomAccessor, + @NonNull VESCollectorService vesCollectorService) { + this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor); + this.vesProvider = Objects.requireNonNull(vesCollectorService); + } + + // VES CommonEventHeader fields + public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName, + long sequenceNo) { + VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); + vesCEH.setDomain(VES_EVENT_DOMAIN); + vesCEH.setEventName(notificationTypeName); + vesCEH.setEventType(VES_EVENTTYPE); + vesCEH.setPriority(VES_EVENT_PRIORITY); + + String eventId; + + eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo); + + vesCEH.setEventId(eventId); + vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000); + vesCEH.setNfVendorName("ORAN"); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo); + vesCEH.setSourceId("ORAN"); + vesCEH.setSourceName(netconfDomAccessor.getNodeId().getValue()); + return vesCEH; + } + + // Notification fields + public VESNotificationFieldsPOJO createVESNotificationFields(HashMap xPathFields, + String notificationTypeName) { + VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO(); + + vesNotifFields.setChangeType(notificationTypeName); + vesNotifFields.setChangeIdentifier(netconfDomAccessor.getNodeId().getValue()); + + StringBuffer buf = new StringBuffer(); + Iterator> it = xPathFields.entrySet().iterator(); + while (it.hasNext()) { + Entry pair = it.next(); + buf.append("\n" + pair.getKey() + " = " + pair.getValue()); + } + log.info("Resultlist({}):{}", xPathFields.size(), buf.toString()); + + ArrayList> arrayOfNamedHashMap = new ArrayList>(); + HashMap namedHashMap = new HashMap(); + namedHashMap.put("hashMap", xPathFields); + namedHashMap.put("name", notificationTypeName); + arrayOfNamedHashMap.add(namedHashMap); + vesNotifFields.setArrayOfNamedHashMap(arrayOfNamedHashMap); + return vesNotifFields; + + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMToInternalDataModel.java new file mode 100644 index 000000000..b157ae4b5 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDOMToInternalDataModel.java @@ -0,0 +1,293 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.mdsal.dom.api.DOMEvent; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.CodeHelpers; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanDOMToInternalDataModel { + + private static final Logger LOG = LoggerFactory.getLogger(ORanDOMToInternalDataModel.class); + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter(); + + public static List getInventoryList(NodeId nodeId, NormalizedNode hwData) { + + List inventoryResultList = new ArrayList(); + ContainerNode hwContainer = (ContainerNode) hwData; + MapNode componentMap = (MapNode) hwContainer + .getChildByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST)); + Collection componentMapEntries = componentMap.body(); + + for (MapEntryNode componentMapEntryNode : getRootComponents(componentMapEntries)) { + inventoryResultList = + recurseGetInventory(nodeId, componentMapEntryNode, componentMapEntries, 0, inventoryResultList); + } + // Verify if result is complete + if (componentMapEntries.size() != inventoryResultList.size()) { + LOG.warn( + "Not all data were written to the Inventory. Potential entries with missing " + + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}", + nodeId.getValue(), componentMapEntries.size(), inventoryResultList.size()); + } + return inventoryResultList; + } + + private static List recurseGetInventory(NodeId nodeId, MapEntryNode component, + Collection componentList, int treeLevel, List inventoryResultList) { + //Add element to list, if conversion successfull + Optional oInventory = getInternalEquipment(nodeId, component, treeLevel); + if (oInventory.isPresent()) { + inventoryResultList.add(oInventory.get()); + } + //Walk through list of child keys and add to list + for (String childUuid : CodeHelpers.nonnull(ORanDMDOMUtility.getLeafListValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CONTAINS_CHILD))) { + for (MapEntryNode c : getComponentsByName(childUuid, componentList)) { + inventoryResultList = recurseGetInventory(nodeId, c, componentList, treeLevel + 1, inventoryResultList); + } + } + return inventoryResultList; + } + + public static List getRootComponents(Collection componentMapEntries) { + List resultList = new ArrayList<>(); + for (MapEntryNode componentMapEntryNode : componentMapEntries) { + if (ORanDMDOMUtility.getLeafValue(componentMapEntryNode, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_PARENT) == null) { // Root elements do not have a parent + resultList.add(componentMapEntryNode); + } + } + return resultList; + } + + private static List getComponentsByName(String name, Collection componentList) { + List resultList = new ArrayList<>(); + for (MapEntryNode c : componentList) { + if (name.equals(ORanDMDOMUtility.getKeyValue(c))) { // <-- Component list is flat search for child's of name + resultList.add(c); + } + } + return resultList; + } + + public static Optional getInternalEquipment(NodeId nodeId, MapEntryNode component, int treeLevel) { + + // Make sure that expected data are not null + Objects.requireNonNull(nodeId); + Objects.requireNonNull(component); + + // Read mandatory data + + @Nullable + String nodeIdString = nodeId.getValue(); + @Nullable + String uuid = ORanDMDOMUtility.getKeyValue(component); + @Nullable + String idParent = + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_PARENT); + @Nullable + String uuidParent = idParent != null ? idParent : uuid; //<- Passt nicht + + // do consistency check if all mandatory parameters are there + if (treeLevel >= 0 && nodeIdString != null && uuid != null && uuidParent != null) { + // Build output data + + InventoryBuilder inventoryBuilder = new InventoryBuilder(); + + // General assumed as mandatory + inventoryBuilder.setNodeId(nodeIdString); + inventoryBuilder.setUuid(uuid); + inventoryBuilder.setParentUuid(uuidParent); + inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel)); + + // -- String list with ids of holders (optional) + inventoryBuilder.setContainedHolder(ORanDMDOMUtility.getLeafListValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CONTAINS_CHILD)); + + // -- Manufacturer related things (optional) + @Nullable + String mfgName = + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_NAME); + inventoryBuilder.setManufacturerName(mfgName); + inventoryBuilder.setManufacturerIdentifier(mfgName); + + // Equipment type (optional) + inventoryBuilder.setDescription( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_DESC)); + inventoryBuilder.setModelIdentifier(ORanDMDOMUtility.getLeafValue(component, + ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MODEL_NAME)); + + inventoryBuilder.setPartTypeId( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_CLASS)); + + inventoryBuilder.setTypeName(ORanDMDOMUtility.getKeyValue(component)); + inventoryBuilder.setVersion( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_HW_REV)); + + // Equipment instance (optional) + @Nullable + String mfgDate = + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_MFG_DATE); + if (mfgDate != null) { + inventoryBuilder.setDate(mfgDate); + } + inventoryBuilder.setSerial( + ORanDMDOMUtility.getLeafValue(component, ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_SER_NUM)); + + return Optional.of(inventoryBuilder.build()); + } + return Optional.empty(); + } + + /** + * If system data is available convert + * + * @param sys + * @return + */ + public static Optional getGuicutthrough(@Nullable NormalizedNode sys) { + AugmentationNode onapSys = (AugmentationNode) sys; + if (onapSys != null) { + String name = ORanDMDOMUtility.getLeafValue(onapSys, ORanDeviceManagerQNames.ONAP_SYSTEM_NAME); + @Nullable + Uri uri = new Uri(ORanDMDOMUtility.getLeafValue(onapSys, ORanDeviceManagerQNames.ONAP_SYSTEM_WEB_UI)); + if (uri.getValue() != null) { + GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder(); + if (name != null) { + gcBuilder.setName(name); + } + gcBuilder.setWeburi(uri.getValue()); + return Optional.of(gcBuilder.build()); + } + LOG.warn("Uri not set to invoke a Gui cut through session to the device. Please set the Uri in the device"); + } + LOG.warn("Retrieving augmented System details failed. Gui cut through information not available"); + return Optional.empty(); + } + + /** + * Convert fault notification into data-provider FaultLogEntity + * + * @param notification with O-RAN notification + * @param nodeId of node to handle + * @param counter to be integrated into data + * @return FaultlogEntity with data + */ + public static FaultlogEntity getFaultLog(DOMNotification notification, NodeId nodeId, Integer counter) { + ContainerNode cn = notification.getBody(); + FaultlogBuilder faultAlarm = new FaultlogBuilder(); + faultAlarm.setNodeId(nodeId.getValue()); + faultAlarm.setObjectId(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_SOURCE)); + faultAlarm.setProblem(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_TEXT)); + faultAlarm.setSeverity(getSeverityType( + ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_SEVERITY), + ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_IS_CLEARED).equals("true"))); + faultAlarm.setCounter(counter); + faultAlarm.setId(ORanDMDOMUtility.getLeafValue(cn, ORanDeviceManagerQNames.ORAN_FM_FAULT_ID)); + faultAlarm.setSourceType(SourceType.Netconf); + faultAlarm.setTimestamp(getEventTime(notification)); + return faultAlarm.build(); + } + + public static DateAndTime getEventTime(DOMNotification notification) { + DateAndTime eventTime; + Instant notificationEventTime = null; + if (notification instanceof DOMEvent) { + notificationEventTime = ((DOMEvent) notification).getEventInstant(); + eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp(notificationEventTime.toString()); + } else { + eventTime = NetconfTimeStampImpl.getConverter().getTimeStamp(); + } + return eventTime; + } + + /** + * Convert O-RAN specific severity into data-provider severity + * + * @param faultSeverity O-RAN severity + * @param isCleared clear indicator + * @return data-provider severity type + * @throws IllegalArgumentException if conversion not possible. + */ + public static SeverityType getSeverityType(@Nullable String faultSeverity, @Nullable Boolean isCleared) + throws IllegalArgumentException { + if (isCleared != null && isCleared) { + return SeverityType.NonAlarmed; + } + if (faultSeverity != null) { + switch (faultSeverity) { + case "CRITICAL": + return SeverityType.Critical; + case "MAJOR": + return SeverityType.Major; + case "MINOR": + return SeverityType.Minor; + case "WARNING": + return SeverityType.Warning; + } + } + throw new IllegalArgumentException("Unknown Alarm state represent as Critical. isCleared=" + isCleared + + " faultSeverity=" + faultSeverity); + } + + /** + * Convert Instant to NETCONF DataAndTime + * @param eventTimeInstant + * @return DateAndTime + */ + public static DateAndTime getDateAndTimeOfInstant(Instant eventTimeInstant) { + Date eventDate = Date.from(eventTimeInstant); + return new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp(eventDate)); + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDeviceManagerQNames.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDeviceManagerQNames.java new file mode 100644 index 000000000..e86168abd --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/ORanDeviceManagerQNames.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.yang.common.QName; + +public class ORanDeviceManagerQNames { + + //ietf-system + public static final String IETF_SYSTEM_NS = "urn:ietf:params:xml:ns:yang:ietf-system"; + public static final String IETF_SYSTEM_REVISION = "2014-08-06"; + public static final @NonNull QName IETF_SYSTEM_QNAME = + QName.create(IETF_SYSTEM_NS, IETF_SYSTEM_REVISION, "ietf-system"); + public static final @NonNull QName IETF_SYSTEM_CONTAINER = QName.create(IETF_SYSTEM_QNAME, "system"); + + // onap-system.yang + public static final String ONAP_SYSTEM_NS = "urn:onap:system"; + public static final String ONAP_SYSTEM_REVISION = "2020-10-26"; + public static final @NonNull QName ONAP_SYSTEM_QNAME = + QName.create(ONAP_SYSTEM_NS, ONAP_SYSTEM_REVISION, "onap-system"); + public static final @NonNull QName ONAP_SYSTEM_NAME = QName.create(ONAP_SYSTEM_QNAME, "name"); + public static final @NonNull QName ONAP_SYSTEM_WEB_UI = QName.create(ONAP_SYSTEM_QNAME, "web-ui"); + + //ietf-hardware.yang + public static final String IETF_HW_NS = "urn:ietf:params:xml:ns:yang:ietf-hardware"; + public static final String IETF_HW_REVISION = "2018-03-13"; + public static final @NonNull QName IETF_HW_MODULE_NAME = + QName.create(IETF_HW_NS, IETF_HW_REVISION, "ietf-hardware"); + public static final @NonNull QName IETF_HW_CONTAINER = QName.create(IETF_HW_MODULE_NAME, "hardware"); + public static final @NonNull QName IETF_HW_COMPONENT_LIST = QName.create(IETF_HW_MODULE_NAME, "component"); + public static final @NonNull QName IETF_HW_COMPONENT_LIST_KEY = QName.create(IETF_HW_MODULE_NAME, "name"); + public static final @NonNull QName IETF_HW_COMPONENT_LIST_MFG_NAME = QName.create(IETF_HW_MODULE_NAME, "mfg-name"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_UUID = QName.create(IETF_HW_MODULE_NAME, "uuid"); //leaf:yang:uuid + public static final @NonNull QName IETF_HW_COMPONENT_LIST_MODEL_NAME = QName.create(IETF_HW_MODULE_NAME, "model-name"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_SER_NUM = QName.create(IETF_HW_MODULE_NAME, "serial-num"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_SW_REV = QName.create(IETF_HW_MODULE_NAME, "software-rev"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_ALIAS = QName.create(IETF_HW_MODULE_NAME, "alias"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_CLASS = QName.create(IETF_HW_MODULE_NAME, "class"); + public static final @NonNull QName IETF_HW_COMPONENT_LIST_MFG_DATE = QName.create(IETF_HW_MODULE_NAME, "mfg-date"); //leaf:yang:date-and-time + public static final @NonNull QName IETF_HW_COMPONENT_LIST_CONTAINS_CHILD = QName.create(IETF_HW_MODULE_NAME, "contains-child"); //leaf-list:leafref + public static final @NonNull QName IETF_HW_COMPONENT_LIST_PARENT = QName.create(IETF_HW_MODULE_NAME, "parent"); //leaf:leafref + public static final @NonNull QName IETF_HW_COMPONENT_LIST_DESC = QName.create(IETF_HW_MODULE_NAME, "description"); //leaf:String + public static final @NonNull QName IETF_HW_COMPONENT_LIST_HW_REV = QName.create(IETF_HW_MODULE_NAME, "hardware-rev"); //leaf:String + + //odl-netconf-callhome-server.yang + public static final String CALLHOME_SERVER_NS = "urn:opendaylight:params:xml:ns:yang:netconf-callhome-server"; + public static final String CALLHOME_SERVER_REVISION = "2020-10-15"; + public static final @NonNull QName CALLHOME_SERVER_MODULE = + QName.create(CALLHOME_SERVER_NS, CALLHOME_SERVER_REVISION, "odl-netconf-callhome-server"); + public static final @NonNull QName CALLHOME_SERVER_CONTAINER = + QName.create(CALLHOME_SERVER_MODULE, "netconf-callhome-server"); + public static final @NonNull QName CALLHOME_SERVER_ALLOWED_DEVICE = + QName.create(CALLHOME_SERVER_MODULE, "allowed-devices"); + public static final @NonNull QName CALLHOME_SERVER_ALLOWED_DEVICE_DEVICE_LIST = + QName.create(CALLHOME_SERVER_MODULE, "device"); + public static final @NonNull QName CALLHOME_SERVER_ALLOWED_DEVICE_KEY = + QName.create(CALLHOME_SERVER_MODULE, "unique-id"); + + //o-ran-hardware.yang + public static final String ORAN_HW_NS = "urn:o-ran:hardware:1.0"; + public static final String ORAN_HW_REVISION = "2019-03-28"; + public static final @NonNull QName ORAN_HW_MODULE = QName.create(ORAN_HW_NS, ORAN_HW_REVISION, "o-ran-hardware").intern(); + public static final @NonNull QName ORAN_HW_COMPONENT = QName.create(ORAN_HW_MODULE, "O-RAN-HW-COMPONENT"); + + //o-ran-fm.yang + public static final String ORAN_FM_NS = "urn:o-ran:fm:1.0"; + public static final String ORAN_FM_REVISION = "2019-02-04"; + public static final @NonNull QName ORAN_FM_MODULE = QName.create(ORAN_FM_NS, ORAN_FM_REVISION, "o-ran-fm"); + public static final @NonNull QName ORAN_FM_ALARM_NOTIF = QName.create(ORAN_FM_MODULE, "alarm-notif"); + public static final @NonNull QName ORAN_FM_FAULT_ID = QName.create(ORAN_FM_MODULE, "fault-id"); + public static final @NonNull QName ORAN_FM_FAULT_SOURCE = QName.create(ORAN_FM_MODULE, "fault-source"); + public static final @NonNull QName ORAN_FM_FAULT_SEVERITY = QName.create(ORAN_FM_MODULE, "fault-severity"); + public static final @NonNull QName ORAN_FM_FAULT_TEXT = QName.create(ORAN_FM_MODULE, "fault-text"); + public static final @NonNull QName ORAN_FM_FAULT_IS_CLEARED = QName.create(ORAN_FM_MODULE, "is-cleared"); + + //ietf-netconf-notifications.yang + public static final String IETF_NETCONF_NOTIFICATIONS_NS = "urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"; + public static final String IETF_NETCONF_NOTIFICATIONS_REVISION = "2012-02-06"; + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_MODULE = QName.create(IETF_NETCONF_NOTIFICATIONS_NS, IETF_NETCONF_NOTIFICATIONS_REVISION, "ietf-netconf-notifications").intern(); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "netconf-config-change"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIRMED_COMMIT = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "netconf-confirmed-commit"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_START = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "netconf-session-start"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_END = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "netconf-session-end"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_NETCONF_CAPABILITY_CHANGE = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "netconf-capability-change"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_CHANGEDBY = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "changed-by"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_SERVERORUSER = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "server-or-user"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_EDITNODE = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "edit"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_USERNAME = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "username"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_SESSIONID = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "session-id"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_OPERATION = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "operation"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_TARGET = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "target"); + public static final @NonNull QName IETF_NETCONF_NOTIFICATIONS_DATASTORE = QName.create(IETF_NETCONF_NOTIFICATIONS_MODULE, "datastore"); + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/startup/ORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/startup/ORanNetworkElementFactory.java new file mode 100644 index 000000000..afeac1932 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/startup/ORanNetworkElementFactory.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup; + +import java.util.Optional; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom.ORanDOMNetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom.ORanDeviceManagerQNames; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; +import org.opendaylight.yangtools.yang.common.QName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ORanNetworkElementFactory implements NetworkElementFactory { + + private static final Logger log = LoggerFactory.getLogger(ORanNetworkElementFactory.class); + //Workaround + private static final QName OneCell = + QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern(); + + @Override + public Optional create(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) { + Capabilities capabilites = accessor.getCapabilites(); + if (!capabilites.isSupportingNamespace(OneCell)) { + if (capabilites.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)) { + log.info("Create device {} ", ORanDOMNetworkElement.class.getName()); + //Optional bindingAccessor = accessor.getNetconfBindingAccessor(); + Optional domAccessor = accessor.getNetconfDomAccessor(); + if (domAccessor.isPresent()) { + //return Optional.of(new ORanNetworkElement(bindingAccessor.get(), serviceProvider)); + return Optional.of(new ORanDOMNetworkElement(domAccessor.get(), serviceProvider)); + } + } + } + return Optional.empty(); + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 21b761ce2..b4cc2d927 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -31,7 +31,7 @@ interface="org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService"/> -- cgit 1.2.3-korg