diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-03-29 09:04:05 +0200 |
---|---|---|
committer | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-03-29 09:04:33 +0200 |
commit | 9fb395380431345b7da7a765651185815a9ac91d (patch) | |
tree | e9915a557d158c3f446c5dcd108afba9e307633a /sdnr/wt/devicemanager-oran/provider/src/main | |
parent | 38c3dd74dc9c43a6606680cc6df82062cd7cbd81 (diff) |
Map ORAN alarm-notif to VES fault
O-RAN (FrontHaul) deviceManager: o-ran-fm.yang/alarm-notif to VES:fault
Issue-ID: CCSDK-3161
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: I3c0854ac3096160119220c341a2d8f2010facd8b
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/devicemanager-oran/provider/src/main')
10 files changed, 436 insertions, 855 deletions
diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java index baa86b4c7..63d8f2787 100644 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanChangeNotificationListener.java @@ -17,11 +17,13 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; -import java.time.Instant; -import java.util.HashMap; +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.devicemanager.service.NotificationProxyParser; 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; @@ -46,13 +48,17 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL private final NetconfBindingAccessor netconfAccessor; private final DataProvider databaseService; private final VESCollectorService vesCollectorService; + private final NotificationProxyParser notificationProxyParser; + private ORanNotifToVESEventAssembly mapper = null; private static int sequenceNo = 0; - public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService, VESCollectorService vesCollectorService) { + public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService, + VESCollectorService vesCollectorService, NotificationProxyParser notificationProxyParser) { this.netconfAccessor = netconfAccessor; this.databaseService = databaseService; this.vesCollectorService = vesCollectorService; + this.notificationProxyParser = notificationProxyParser; } @Override @@ -102,17 +108,23 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL databaseService.writeEventLog(eventlogBuilder.build()); } log.info("onNetconfConfigChange (2) {}", sb); - ORanNotificationMapper mapper = new ORanNotificationMapper(); - HashMap<String, String> xPathFieldsMap = mapper.performMapping(notification); - log.info("MappingInfo after mapping notification - {}", xPathFieldsMap); - Instant instant = mapper.getTime(notification); - ORanNotifToVESEventAssembly oranVESEventAssembly = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService); - String data = oranVESEventAssembly.performAssembly(xPathFieldsMap, instant, NetconfConfigChange.class.getSimpleName(), - sequenceNo); - vesCollectorService.publishVESMessage(data); + 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-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java index cae1bca52..6f5de9677 100644 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultNotificationListener.java @@ -17,8 +17,21 @@ */ 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 org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +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.netconfnodestateservice.NetconfBindingAccessor; +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.o.ran.fm._1._0.rev190204.ORanFmListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,11 +42,69 @@ import org.slf4j.LoggerFactory; public class ORanFaultNotificationListener implements ORanFmListener { private static final Logger log = LoggerFactory.getLogger(ORanFaultNotificationListener.class); + private NetconfBindingAccessor netconfAccessor; + private DataProvider databaseService; + private VESCollectorService vesCollectorService; + private int counter = 0; + private ORanFaultToVESFaultMapper mapper = null; + + public ORanFaultNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService, + VESCollectorService vesCollectorService) { + this.netconfAccessor = netconfAccessor; + this.databaseService = databaseService; + this.vesCollectorService = vesCollectorService; + } @Override public void onAlarmNotif(AlarmNotif notification) { - log.info("onAlarmNotif {}", notification); + log.info("onAlarmNotif {}", notification.getClass().getSimpleName()); + @Nullable + DateAndTime eventTime = notification.getEventTime(); + try { + Instant eventTimeInstant = Instant.parse(eventTime.getValue()); + + FaultcurrentBuilder faultCurrent = new FaultcurrentBuilder(); + faultCurrent.setNodeId(netconfAccessor.getNodeId().getValue()); + faultCurrent.setObjectId(notification.getFaultSource()); + faultCurrent.setProblem(notification.getFaultText()); + faultCurrent.setSeverity(getSeverityType(notification.getFaultSeverity())); + faultCurrent.setCounter(Integer.valueOf(counter++)); + faultCurrent.setId(notification.getFaultId().toString()); + faultCurrent.setTimestamp(eventTime); + + databaseService.updateFaultCurrent(faultCurrent.build()); + + if (vesCollectorService.getConfig().isVESCollectorEnabled()) { + if (mapper == null) { + this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService, + AlarmNotif.class.getSimpleName()); + } + VESCommonEventHeaderPOJO header = + mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); + VESFaultFieldsPOJO body = mapper.mapFaultFields(notification); + vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + } + } catch (JsonProcessingException | DateTimeParseException e) { + log.debug("Can not convert event into VES message {}", notification, e); + } + + } + + private SeverityType getSeverityType(FaultSeverity faultSeverity) { + String severity = faultSeverity.getName(); + switch (severity) { + case "CRITICAL": + return SeverityType.Critical; + case "MAJOR": + return SeverityType.Major; + case "MINOR": + return SeverityType.Minor; + case "WARNING": + return SeverityType.Warning; + default: + return SeverityType.NonAlarmed; + } } } diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java new file mode 100644 index 000000000..1790f82c7 --- /dev/null +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanFaultToVESFaultMapper.java @@ -0,0 +1,131 @@ +/* + * ============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 <eventTime> 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 ??? + * 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 ????? + * sourceName "nt:network-topology/nt:topology/nt:node/nt:node-id" + * startEpochMicrosec + * timeZoneOffset + * version "4.1" + * vesEventListenerVersion "7.2" + * + * + * 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]/mfg-model 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 { + + 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 + + + public ORanFaultToVESFaultMapper(NodeId nodeId, VESCollectorService vesCollectorService, + String notifName) { + this.nodeIdString = nodeId.getValue(); + this.vesProvider = vesCollectorService; + this.notifName = notifName; + } + + 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("ORAN"); + vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); + vesCEH.setSequence(sequenceNo); + vesCEH.setSourceId("ORAN"); + 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); + vesFaultFields.setEventSeverity(alarmNotif.getFaultSeverity().getName()); + vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION); + vesFaultFields.setSpecificProblem(alarmNotif.getFaultText()); + vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS); + + return vesFaultFields; + } + +} diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java index 757768573..47ea3eadd 100644 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNetworkElement.java @@ -17,6 +17,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; +import com.fasterxml.jackson.core.JsonProcessingException; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -25,7 +26,10 @@ 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.NotificationProxyParser; 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.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications; @@ -34,7 +38,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.r 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.GuicutthroughBuilder; +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.concepts.ListenerRegistration; @@ -43,8 +48,6 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - */ public class ORanNetworkElement implements NetworkElement { private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class); @@ -56,12 +59,12 @@ public class ORanNetworkElement implements NetworkElement { @SuppressWarnings("unused") private final VESCollectorService vesCollectorService; - private final ORanToInternalDataModel oRanMapper; - private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult; private @NonNull final ORanChangeNotificationListener oRanListener; private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult; private @NonNull final ORanFaultNotificationListener oRanFaultListener; + private final NotificationProxyParser notificationProxyParser; + private Collection<Component> componentList; ORanNetworkElement(NetconfBindingAccessor netconfAccess, DataProvider databaseService, VESCollectorService vesCollectorService) { @@ -69,97 +72,39 @@ public class ORanNetworkElement implements NetworkElement { this.netconfAccessor = netconfAccess; this.databaseService = databaseService; this.vesCollectorService = vesCollectorService; + this.notificationProxyParser = vesCollectorService.getNotificationProxyParser(); this.oRanListenerRegistrationResult = null; - this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService); + this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService, + notificationProxyParser); this.oRanFaultListenerRegistrationResult = null; - this.oRanFaultListener = new ORanFaultNotificationListener(); - - this.oRanMapper = new ORanToInternalDataModel(); - + this.oRanFaultListener = + new ORanFaultNotificationListener(netconfAccessor, databaseService, vesCollectorService); } - public void initialReadFromNetworkElement() { - Hardware hardware = readHardware(netconfAccessor); + private void initialReadFromNetworkElement() { + Hardware hardware = readHardware(); if (hardware != null) { - Collection<Component> componentList = YangHelper.getCollection(hardware.getComponent()); - if (componentList != null) { - int componentListSize = componentList.size(); - int writeCount = 0; - - for (Component component : componentList) { - if (component.getParent() == null) { - writeCount += writeInventory(component, componentList, 0); - } - } - if (componentListSize != writeCount) { - log.warn("Not all data were written to the Inventory. Potential entries with missing " - + "contained-child. Node Id = {}, Components Found = {}, Entries written to Database = {}", - netconfAccessor.getNodeId().getValue(), componentListSize, writeCount); - } - } + componentList = YangHelper.getCollection(hardware.nonnullComponent()); + List<Inventory> inventoryList = + ORanToInternalDataModel.getInventoryList(netconfAccessor.getNodeId(), componentList); + inventoryList.forEach(databaseService::writeInventory); } - System1 sys = getOnapSystemData(netconfAccessor); - if (sys != null) { - GuicutthroughBuilder gcBuilder = new GuicutthroughBuilder(); - gcBuilder.setId(sys.getName()).setName(sys.getName()).setWeburi(sys.getWebUi().getValue()); - databaseService.writeGuiCutThroughData(gcBuilder.build()); + Optional<Guicutthrough> oGuicutthrough = ORanToInternalDataModel.getGuicutthrough(getOnapSystemData()); + if (oGuicutthrough.isPresent()) { + databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfAccessor.getNodeId().getValue()); } } - private int writeInventory(Component component, Collection<Component> componentList, int treeLevel) { - databaseService - .writeInventory(oRanMapper.getInternalEquipment(netconfAccessor.getNodeId(), component, treeLevel)); - int count = 1; - if (component.getContainsChild() != null) { - List<String> containerHolderList = component.getContainsChild(); - for (String containerHolder : containerHolderList) { - for (Component c : componentList) { - if (containerHolder.equals(c.getName())) { - count += writeInventory(c, componentList, treeLevel + 1); - } - } - } - } - return count; - } - @Override public NetworkElementDeviceType getDeviceType() { return NetworkElementDeviceType.ORAN; } - private System1 getOnapSystemData(NetconfBindingAccessor accessData) { - InstanceIdentifier<System1> system1IID = InstanceIdentifier - .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class) - .augmentation(System1.class).build(); - - System1 res = accessData.getTransactionUtils().readData(accessData.getDataBroker(), - LogicalDatastoreType.OPERATIONAL, system1IID); - log.debug("Result of getOnapSystemData = {}", res); - return res; - } - - private Hardware readHardware(NetconfBindingAccessor accessData) { - - final Class<Hardware> clazzPac = Hardware.class; - - log.info("DBRead Get equipment for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(), - accessData.getNodeId().getValue()); - - InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build(); - - Hardware res = accessData.getTransactionUtils().readData(accessData.getDataBroker(), - LogicalDatastoreType.OPERATIONAL, hardwareIID); - - return res; - } - @Override public void register() { - initialReadFromNetworkElement(); // Register call back class for receiving notifications Optional<NetconfNotifications> oNotifications = netconfAccessor.getNotificationAccessor(); @@ -208,4 +153,28 @@ public class ORanNetworkElement implements NetworkElement { return Optional.of(netconfAccessor); } + // Read from device + private System1 getOnapSystemData() { + log.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue()); + + InstanceIdentifier<System1> system1IID = InstanceIdentifier + .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class) + .augmentation(System1.class).build(); + System1 res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, system1IID); + log.debug("Result of System1 = {}", res); + return res; + } + + private Hardware readHardware() { + final Class<Hardware> clazzPac = Hardware.class; + log.info("DBRead Get hardware for class {} from mountpoint {}", clazzPac.getSimpleName(), + netconfAccessor.getNodeId().getValue()); + InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build(); + Hardware res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(), + LogicalDatastoreType.OPERATIONAL, hardwareIID); + log.debug("Result of Hardware = {}", res); + return res; + } + } diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java index b7506e50c..d99f1c874 100644 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotifToVESEventAssembly.java @@ -21,19 +21,15 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; 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.oran.impl.VESCommonEventHeaderPOJO; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.VESEvent; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.VESNotificationFieldsPOJO; +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.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,38 +47,8 @@ public class ORanNotifToVESEventAssembly { this.vesProvider = vesProvider; } - public String performAssembly(HashMap<String, String> xPathFieldsMap, Instant instant, String notificationTypeName, - long sequenceNo) { - VESEvent data = assembleVESEventMsg(xPathFieldsMap, instant, notificationTypeName, sequenceNo); - return createVESEventJSON(data); - } - - public VESEvent assembleVESEventMsg(HashMap<String, String> xPathFieldsMap, Instant instant, - String notificationTypeName, long sequenceNo) { - VESCommonEventHeaderPOJO vesCEH = createVESCommonEventHeader(instant, notificationTypeName, sequenceNo); - VESNotificationFieldsPOJO vesNotifFields = createVESNotificationFields(xPathFieldsMap, notificationTypeName); - - VESEvent vesEvent = new VESEvent(); - vesEvent.addEventObjects(vesCEH); - vesEvent.addEventObjects(vesNotifFields); - - return vesEvent; - } - - public String createVESEventJSON(VESEvent vesEvent) { - String oranVESMsg = ""; - try { - ObjectMapper objMapper = new ObjectMapper(); - oranVESMsg = objMapper.writeValueAsString(vesEvent); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - log.debug("VES Message generated from ORAN Netconf Notification is - {}", oranVESMsg); - return oranVESMsg; - } - // VES CommonEventHeader fields - private VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName, + public VESCommonEventHeaderPOJO createVESCommonEventHeader(Instant time, String notificationTypeName, long sequenceNo) { VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); vesCEH.setDomain(VES_EVENT_DOMAIN); @@ -95,8 +61,8 @@ public class ORanNotifToVESEventAssembly { eventId = notificationTypeName + "-" + Long.toUnsignedString(sequenceNo); vesCEH.setEventId(eventId); - vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 100); - vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 100); + vesCEH.setStartEpochMicrosec(time.toEpochMilli() * 1000); + vesCEH.setLastEpochMicrosec(time.toEpochMilli() * 1000); vesCEH.setNfVendorName("ORAN"); vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); vesCEH.setSequence(sequenceNo); @@ -106,7 +72,7 @@ public class ORanNotifToVESEventAssembly { } // Notification fields - private VESNotificationFieldsPOJO createVESNotificationFields(HashMap<String, String> xPathFields, + public VESNotificationFieldsPOJO createVESNotificationFields(HashMap<String, String> xPathFields, String notificationTypeName) { VESNotificationFieldsPOJO vesNotifFields = new VESNotificationFieldsPOJO(); diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotificationMapper.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotificationMapper.java deleted file mode 100644 index ccb1ac098..000000000 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanNotificationMapper.java +++ /dev/null @@ -1,339 +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.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.time.Instant; -import java.util.HashMap; -import java.util.List; -import org.eclipse.jdt.annotation.NonNull; -import org.opendaylight.yangtools.concepts.Identifier; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.EventInstantAware; -import org.opendaylight.yangtools.yang.binding.Identifiable; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.common.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ORanNotificationMapper { - - /* - * Converter of TR069 notifications to VES key, value hashmap. - * Notifications are received as cascade if proxy object. - * References: https://stackoverflow.com/questions/19633534/what-is-com-sun-proxy-proxy - * - * Attributes are provided by getters starting with "get", "is", "key". - * Proxy received: "com.sun.proxy.$ProxyNN". NN is a number. - * - * Example result: - * - * Expected output via VES in JSON - * { - * "event": { - * "commonEventHeader": { - * "domain": "notification", - * "eventId": "ABCD", - * "eventName": "Notification_LTE_Enterprise_C-RANSC_Cntrl-ACME", - * "eventType": "TR069_RAN_notification", - * "sequence": 0, - * "priority": "High", - * "reportingEntityId": "0005B942CDB4", - * "reportingEntityName": "ABCD", - * "sourceId": "0005B942CDB4", - * "sourceName": "ABCD", - * "startEpochMicrosec": 1569579510211, - * "lastEpochMicrosec": 1569579510211, - * "nfcNamingCode": "", - * "nfNamingCode": "", - * "nfVendorName": "", - * "timeZoneOffset": "+00:00", - * "version": "4.0.1", - * "vesEventListenerVersion": "7.0.1" - * }, - * "notificationFields": { - * "arrayOfNamedHashMap": [ - * { - * "name": "VALUECHANGE", - * "hashMap": { - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/serial-number": "0005B94238A0", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/software-version": "4.3.00.244", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/hardware-version": "1", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/provisioning-code": "", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/manufacturer": "ACME", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/product-class": "LTE_Enterprise_C-RANSC_Cntrl", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/device-info/manufacturer-oui": "0005B9", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/index": "1", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/fap-control/lte/rf-tx-status": "false", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[1]/fap-control/lte/op-state": "true", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/index": "2", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/fap-control/lte/rf-tx-status": "false", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/fap-control/lte/op-state": "true", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/services/fap-service[2]/cell-config/lte/ran/rf/phy-cell-id": "201", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-url": "http://10.220.68.2/acscall", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/parameter-key": "none", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-password": "password", - * "/notification/VALUECHANGE[@xmlns=\"urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notification\"]/device/management-server/connection-request-username": "0005B9-LTE_Enterprise_C-RANSC_Cntrl-0005B94238A0" - * }, - * } - * ], - * "changeContact": "", - * "changeIdentifier": "SessionID", - * "changeType": "ValueChange", - * "newState": "", - * "oldState": "", - * "stateInterface": "", - * "notificationFieldsVersion": "2.0", - * } - * } - * } - * - */ - private static final Logger log = LoggerFactory.getLogger(ORanNotificationMapper.class); - private Notification notification; - - public HashMap<String, String> performMapping(Notification notification) - /*throws ORanNotificationMapperException*/ { - - try { - return extractFields(notification); - } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException - | InvocationTargetException e) { - //throw new ORanNotificationMapperException("Mapping/JSON Creation problem", e); - log.info("Exception in performMapping method {}",e); - return null; - } - - } - - private HashMap<String, String> extractFields(Object o) throws IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchFieldException, SecurityException { - String start = "/notification/" + getExtendedInterfaceName(Notification.class, o) + getXmlNameSpace(o); - return recurseExtractData(o, start, 0, new HashMap<String, String>()); - } - - private HashMap<String, String> recurseExtractData(Object o, String namePath, int level, - HashMap<String, String> result) - throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - log.debug("In recurseExtractData - {} {} {}", namePath, level, log.isTraceEnabled() ? result : result.size()); - if (level > 20) { - log.warn("Level to deep protection ended the recusive loop."); - } else { - if (o != null) { - Class<?> classz = o.getClass(); - //notification/VALUECHANGE$$$eventInstantAware[@xmlns=urn:org:onap:ccsdk:features:sdnr:northbound:onecell-notificationon] 0 {} - //org.opendaylight.yang.gen.v1.urn.org.onap.ccsdk.features.sdnr.northbound.onecell.notification.rev200622.VALUECHANGE$$$eventInstantAware - //if (Proxy.isProxyClass(classz)) { - handleInterface(classz, o, namePath, level, result); - //} - } else { - log.warn("Null not expected here."); - } - } - return result; - } - - private void handleInterface(Class<?> clazz, Object o, String namePath, int level, HashMap<String, String> result) - throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - log.debug("In extract Interface {}", clazz); - if (clazz == null) { - log.warn("Loop with null class"); - return; - } - if (level > 20) { - log.warn("Level to deep protection ended the recusive loop."); - } - if (clazz.getName().contentEquals("org.opendaylight.mdsal.binding.dom.codec.impl.AugmentableCodecDataObject")) { - log.trace("Leave AugmentableCodecDataObject"); - return; - } - - Method[] methods = clazz.getDeclaredMethods(); - if (methods != null) { - for (Method method : methods) { - String methodName = method.getName(); - log.trace("Method {}", methodName); - if (methodName.startsWith("get")) { - if (!methodName.equals("getImplementedInterface")) { - handleGetterValue(method, methodName.substring(3), namePath, o, level, result); - } - } else if (methodName.startsWith("is")) { - handleGetterValue(method, methodName.substring(2), namePath, o, level, result); - } else if (methodName.equals("key")) { - handleGetterValue(method, methodName, namePath, o, level, result); - } - } - } - Class<?> sc = clazz.getSuperclass(); //Sodium - log.trace("Superclass is - {}", sc); - if (sc != null && !(sc.getName().contains("java.lang.reflect.Proxy")) && !Proxy.isProxyClass(sc)) { - handleInterface(sc, o, namePath, level + 1, result); - } - } - - private void handleGetterValue(Method method, String name, String namePath, Object o, int level, - HashMap<String, String> result) - throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - log.debug("Begin: {}-{}-{}-{}", method.getName(), name, namePath, level); - if (!method.isAccessible()) { - method.setAccessible(true); - } - Object value = method.invoke(o); - namePath += "/" + convertCamelToKebabCase(name); - log.trace("Namepath {}", namePath); - if (value != null) { - Class<?> type = value.getClass(); - log.trace("Class {}", type.getSimpleName()); - if (List.class.isAssignableFrom(type)) { - int idx = 0; - String keyString; - for (Object listObject : (List<?>) value) { - if (listObject != null) { - if (Identifiable.class.isAssignableFrom(listObject.getClass())) { - keyString = getKeyString((Identifiable<?>) listObject); - } else { - keyString = String.valueOf(idx); - } - recurseExtractData(listObject, namePath + "[" + keyString + "]", level + 1, result); - } else { - log.warn("Null value received {} {} {}", namePath, idx, name); - } - idx++; - } - } else if (DataObject.class.isAssignableFrom(type)) { - recurseExtractData(value, namePath, level + 1, result); - } else if (Proxy.isProxyClass(type)) { - recurseExtractData(value, namePath, level + 1, result); - } else if (Identifier.class.isAssignableFrom(type)) { - //don't put the key - } else { - result.put(namePath, value.toString()); - } - } else { - log.trace("Null value"); - } - } - - private String getExtendedInterfaceName(Class<?> assignableClazz, Object o) { - Class<?> interfaces[] = o.getClass().getInterfaces(); - for (Class<?> oneInterface : interfaces) { - log.trace("In getExtendedInterfaceName, oneInterface = {}", oneInterface.getClass().getName()); - if (assignableClazz.isAssignableFrom(oneInterface)) { - return oneInterface.getSimpleName().contains("eventInstantAware")?oneInterface.getSimpleName().substring(0, oneInterface.getSimpleName().indexOf("$")):oneInterface.getSimpleName(); - } - } - log.trace("In getExtendedInterfaceName, o.getClass().getName() = {}", o.getClass().getName()); - return o.getClass().getSimpleName().contains("eventInstantAware")?o.getClass().getSimpleName().substring(0, o.getClass().getSimpleName().indexOf("$")):o.getClass().getSimpleName(); - } - - private String getXmlNameSpace(Object o) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field f = o.getClass().getField("QNAME"); - Object couldQName = f.get(o); - if (couldQName instanceof QName) { - QName qname = (QName) couldQName; - return "[@xmlns=" + qname.getNamespace().toString() + "]"; - } - return ""; - } - - /*private String convertCamelToKebabCase(String camel) { - KebabCaseStrategy kbCase = new KebabCaseStrategy(); - return kbCase.translate(camel); - //return camel.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(); - } */ - - /** - * @param input string in Camel Case - * @return String in Kebab case - * Inspiration from KebabCaseStrategy class of com.fasterxml.jackson.databind with an additional condition to handle numbers as well - * Using QNAME would have been a more fool proof solution, however it can lead to performance problems due to usage of Java reflection - */ - public String convertCamelToKebabCase(String input) - { - if (input == null) return input; // garbage in, garbage out - int length = input.length(); - if (length == 0) { - return input; - } - - StringBuilder result = new StringBuilder(length + (length >> 1)); - - int upperCount = 0; - - for (int i = 0; i < length; ++i) { - char ch = input.charAt(i); - char lc = Character.toLowerCase(ch); - - if (lc == ch) { // lower-case letter means we can get new word - // but need to check for multi-letter upper-case (acronym), where assumption - // is that the last upper-case char is start of a new word - if ((upperCount > 1) ){ - // so insert hyphen before the last character now - result.insert(result.length() - 1, '-'); - } else if ((upperCount == 1) && Character.isDigit(ch) && i != length-1) { - result.append('-'); - } - upperCount = 0; - } else { - // Otherwise starts new word, unless beginning of string - if ((upperCount == 0) && (i > 0)) { - result.append('-'); - } - ++upperCount; - } - result.append(lc); - } - return result.toString(); - } - - /** - * Key format like this: "FapServiceKey{_index=2}" - * - * @return - */ - private String getKeyString(Identifiable<?> indentifiableObject) { - String keyString = (indentifiableObject.key()).toString(); - int start = keyString.indexOf("=") + 1; - int end = keyString.length() - 1; - if (start > 0 && start < end) - return keyString.substring(keyString.indexOf("=") + 1, keyString.length() - 1); - else - throw new IllegalArgumentException("indentifiable object without key"); - } - - public Instant getTime(Notification notification2) { - @NonNull - Instant time; - if (notification instanceof EventInstantAware) { // If notification class extends/implements the EventInstantAware - time = ((EventInstantAware) notification).eventInstant(); - log.info("Event time {}", time); - } else { - time = Instant.now(); - log.info("Defaulting to actual time of processing the notification - {}", time); - } - return time; - } -} diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java index ca44e63f2..1f84db41c 100644 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java +++ b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ORanToInternalDataModel.java @@ -18,59 +18,186 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; 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.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.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.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; /** - * @author herbert + * Convert data to data-provider model and perform consistency checks.<br> + * <b>Component list characteristics:</b><br> + * <ul> + * <li>component list is a flat list tree structure specified + * <li>via "component.getParent()": + * <ul> + * <li>If null we have a root element + * <li>if not null it is a child element with generated child level<br> + * </ul> + * </ul> + * Example of List:<br> + * * */ public class ORanToInternalDataModel { - public Inventory getInternalEquipment(NodeId nodeId, Component component, int treeLevel) { + private static final Logger log = LoggerFactory.getLogger(ORanToInternalDataModel.class); + + public static List<Inventory> getInventoryList(NodeId nodeId, Collection<Component> componentList) { - InventoryBuilder inventoryBuilder = new InventoryBuilder(); + List<Inventory> inventoryResultList = new ArrayList<Inventory>(); + 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; + } - // General - inventoryBuilder.setNodeId(nodeId.getValue()); - inventoryBuilder.setParentUuid(component.getParent()!=null?component.getParent():component.getName()); - inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel)); + private static List<Inventory> recurseGetInventory(NodeId nodeId, Component component, + Collection<Component> componentList, int treeLevel, List<Inventory> inventoryResultList) { - inventoryBuilder.setUuid(component.getName()); - // -- String list with ids of holders - List<String> containerHolderKeyList = new ArrayList<>(); - List<String> containerHolderList = component.getContainsChild(); - if (containerHolderList != null) { - for (String containerHolder : containerHolderList) { - containerHolderKeyList.add(containerHolder); + //Add element to list, if conversion successfull + Optional<Inventory> 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); } } - inventoryBuilder.setContainedHolder(containerHolderKeyList); - // -- Manufacturer related things - inventoryBuilder.setManufacturerName(component.getMfgName()); - inventoryBuilder.setManufacturerIdentifier(component.getMfgName()); + return inventoryResultList; + } + public static List<Component> getRootComponents(Collection<Component> componentList) { + List<Component> resultList = new ArrayList<>(); + for (Component c : componentList) { + if (c.getParent() == null) { // Root elements do not have a parent + resultList.add(c); + } + } + return resultList; + } - // Equipment type - inventoryBuilder.setDescription(component.getDescription()); - inventoryBuilder.setModelIdentifier(component.getModelName()); - if (component.getXmlClass() != null) { - inventoryBuilder.setPartTypeId(component.getXmlClass().getName()); + private static List<Component> getComponentsByName(String name, Collection<Component> componentList) { + List<Component> 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); + } } - inventoryBuilder.setTypeName(component.getName()); - inventoryBuilder.setVersion(component.getHardwareRev()); + 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<Inventory> 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 - // Equipment instance - if (component.getMfgDate() != null) { - inventoryBuilder.setDate(component.getMfgDate().getValue()); + // 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<? extends HardwareClass> 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(); + } + + public static Optional<Guicutthrough> 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"); } - inventoryBuilder.setSerial(component.getSerialNum()); - return inventoryBuilder.build(); + log.warn("Retrieving augmented System details failed. Gui cut through information not available"); + return Optional.empty(); } } diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESCommonEventHeaderPOJO.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESCommonEventHeaderPOJO.java deleted file mode 100644 index 730c63b0f..000000000 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESCommonEventHeaderPOJO.java +++ /dev/null @@ -1,196 +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 com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -@JsonPropertyOrder({"domain", "eventId", "eventName", "eventType", "lastEpochMicrosec", "nfcNamingCode", "nfNamingCode", - "nfVendorName", "priority", "reportingEntityId", "reportingEntityName", "sequence", "sourceId", "sourceName", - "startEpochMicrosec", "timeZoneOffset", "version", "vesEventListenerVersion"}) - -public class VESCommonEventHeaderPOJO { - - private String domain = ""; - private String eventId = ""; - private String eventName = ""; - private String eventType = ""; - private long sequence = 0L; - private String priority = ""; - @JsonIgnore - private String reportingEntityId = ""; - private String reportingEntityName = ""; - private String sourceId = ""; - private String sourceName = ""; - private long startEpochMicrosec = 0L; - private long lastEpochMicrosec = 0L; - private String nfcNamingCode = ""; - private String nfNamingCode = ""; - private String nfVendorName = ""; - private String timeZoneOffset = "+00:00"; - private String version = "4.1"; - private String vesEventListenerVersion = "7.1.1"; - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public String getEventId() { - return eventId; - } - - public void setEventId(String eventId) { - this.eventId = eventId; - } - - public String getEventName() { - return eventName; - } - - public void setEventName(String eventName) { - this.eventName = eventName; - } - - public String getEventType() { - return eventType; - } - - public void setEventType(String eventType) { - this.eventType = eventType; - } - - public Long getSequence() { - return sequence; - } - - public void setSequence(long sequenceNo) { - this.sequence = sequenceNo; - } - - public String getPriority() { - return priority; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public String getReportingEntityId() { - return reportingEntityId; - } - - public void setReportingEntityId(String reportingEntityId) { - this.reportingEntityId = reportingEntityId; - } - - public String getReportingEntityName() { - return reportingEntityName; - } - - public void setReportingEntityName(String reportingEntityName) { - this.reportingEntityName = reportingEntityName; - } - - public String getSourceId() { - return sourceId; - } - - public void setSourceId(String sourceId) { - this.sourceId = sourceId; - } - - public String getSourceName() { - return sourceName; - } - - public void setSourceName(String sourceName) { - this.sourceName = sourceName; - } - - public long getStartEpochMicrosec() { - return startEpochMicrosec; - } - - public void setStartEpochMicrosec(long startEpochMicrosec) { - this.startEpochMicrosec = startEpochMicrosec; - } - - public long getLastEpochMicrosec() { - return lastEpochMicrosec; - } - - public void setLastEpochMicrosec(long lastEpochMicrosec) { - this.lastEpochMicrosec = lastEpochMicrosec; - } - - public String getNfcNamingCode() { - return nfcNamingCode; - } - - public void setNfcNamingCode(String nfcNamingCode) { - this.nfcNamingCode = nfcNamingCode; - } - - public String getNfNamingCode() { - return nfNamingCode; - } - - public void setNfNamingCode(String nfNamingCode) { - this.nfNamingCode = nfNamingCode; - } - - public String getNfVendorName() { - return nfVendorName; - } - - public void setNfVendorName(String nfVendorName) { - this.nfVendorName = nfVendorName; - } - - public String getTimeZoneOffset() { - return timeZoneOffset; - } - - public void setTimeZoneOffset(String timeZoneOffset) { - this.timeZoneOffset = timeZoneOffset; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getVesEventListenerVersion() { - return vesEventListenerVersion; - } - - public void setVesEventListenerVersion(String vesEventListenerVersion) { - this.vesEventListenerVersion = vesEventListenerVersion; - } -} diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESEvent.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESEvent.java deleted file mode 100644 index 1117565e6..000000000 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESEvent.java +++ /dev/null @@ -1,44 +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.HashMap; -import java.util.Map; - -public class VESEvent { - - public Map<String, Object> event = new HashMap<String, Object>(); - - public void addEventObjects(Object eventObject) { - if (eventObject instanceof VESCommonEventHeaderPOJO) - event.put("commonEventHeader", eventObject); - else if (eventObject instanceof VESNotificationFieldsPOJO) - event.put("notificationFields", eventObject); - - } - - public Map<String, Object> getEvent() { - return event; - } -} - - diff --git a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESNotificationFieldsPOJO.java b/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESNotificationFieldsPOJO.java deleted file mode 100644 index 09aa6dd0a..000000000 --- a/sdnr/wt/devicemanager-oran/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/VESNotificationFieldsPOJO.java +++ /dev/null @@ -1,116 +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 com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import java.util.ArrayList; -import java.util.HashMap; - -@JsonPropertyOrder({"arrayOfNamedHashMap", "changeContact", "changeIdentifier", "changeType", "newState", "oldState", - "notificationFieldsVersion"}) - -public class VESNotificationFieldsPOJO { - - private ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>(); - @JsonIgnore - private HashMap<String, Object> namedHashMap = new HashMap<String, Object>(); - @JsonIgnore - private HashMap<String, String> hashMap = new HashMap<String, String>(); - @JsonIgnore - private String changeContact = ""; - private String changeIdentifier = ""; - private String changeType = ""; - @JsonIgnore - private String newState = ""; - @JsonIgnore - private String oldState = ""; - @JsonIgnore - private String stateInterface = ""; - private String notificationFieldsVersion = "2.0"; - - public ArrayList<HashMap<String, Object>> getArrayOfNamedHashMap() { - return arrayOfNamedHashMap; - } - - public void setArrayOfNamedHashMap(ArrayList<HashMap<String, Object>> arrayOfNamedHashMap) { - this.arrayOfNamedHashMap = arrayOfNamedHashMap; - } - - public String getChangeContact() { - return changeContact; - } - - public void setChangeContact(String changeContact) { - this.changeContact = changeContact; - } - - public String getChangeIdentifier() { - return changeIdentifier; - } - - public void setChangeIdentifier(String changeIdentifier) { - this.changeIdentifier = changeIdentifier; - } - - public String getChangeType() { - return changeType; - } - - public void setChangeType(String changeType) { - this.changeType = changeType; - } - - public String getNewState() { - return newState; - } - - public void setNewState(String newState) { - this.newState = newState; - } - - public String getOldState() { - return oldState; - } - - public void setOldState(String oldState) { - this.oldState = oldState; - } - - public String getStateInterface() { - return stateInterface; - } - - public void setStateInterface(String stateInterface) { - this.stateInterface = stateInterface; - } - - public String getNotificationFieldsVersion() { - return notificationFieldsVersion; - } - - public void setNotificationFieldsVersion(String notificationFieldsVersion) { - this.notificationFieldsVersion = notificationFieldsVersion; - } - - -} |