From 17fd7d683b0b38a401481ae85cc5927679e20ce3 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Wed, 16 Jun 2021 10:22:36 +0530 Subject: Include missing mapping of O-RAN fault fields Refactor O-RAN devicemanager and correct VES fault fields characteristics Issue-ID: CCSDK-3309 Change-Id: I01441cb9c84660c0ee6931d6bbe3f28993cfd054 Signed-off-by: Ravi Pendurty --- .../o-ran/ru-fh/installer/pom.xml | 4 +- .../o-ran/ru-fh/provider/pom.xml | 14 +- .../oran/impl/ORanChangeNotificationListener.java | 42 +++-- .../oran/impl/ORanFaultNotificationListener.java | 168 ++++++++++++------- .../oran/impl/ORanFaultToVESFaultMapper.java | 47 ++++-- .../oran/impl/ORanNetworkElement.java | 162 +++++++++++-------- .../oran/impl/ORanNetworkElementFactory.java | 3 +- ...ORanRegistrationToVESpnfRegistrationMapper.java | 25 +-- .../oran/impl/ORanToInternalDataModel.java | 77 ++++++++- .../devicemanager/oran/impl/ComponentHelper.java | 179 +++++++++++++++++++++ .../wt/devicemanager/oran/impl/TestAlarmNotif.java | 90 +++++++++++ .../oran/impl/TestDeviceManagerORanImpl.java | 50 ++++++ .../devicemanager/oran/impl/TestHardwareClass.java | 24 +++ .../impl/TestORanChangeNotificationListener.java | 110 +++++++++++++ .../impl/TestORanFaultNotificationListener.java | 114 +++++++++++++ .../oran/impl/TestORanNetworkElement.java | 111 +++++++++++++ .../oran/impl/TestORanNetworkElementFactory.java | 94 +++++++++++ .../TestORanRegistrationToVESpnfRegistration.java | 72 +++++++++ .../oran/impl/TestORanToInternalDataModel.java | 97 +++++++++++ .../devicemanager/oran/test/ComponentHelper.java | 179 --------------------- .../wt/devicemanager/oran/test/TestAlarmNotif.java | 88 ---------- .../oran/test/TestDeviceManagerORanImpl.java | 50 ------ .../devicemanager/oran/test/TestHardwareClass.java | 24 --- .../test/TestORanChangeNotificationListener.java | 108 ------------- .../test/TestORanFaultNotificationListener.java | 65 -------- .../oran/test/TestORanNetworkElement.java | 106 ------------ .../oran/test/TestORanNetworkElementFactory.java | 78 --------- .../TestORanRegistrationToVESpnfRegistration.java | 88 ---------- .../oran/test/TestORanToInternalDataModel.java | 97 ----------- 29 files changed, 1308 insertions(+), 1058 deletions(-) create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java create mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/ComponentHelper.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestAlarmNotif.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestDeviceManagerORanImpl.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestHardwareClass.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanChangeNotificationListener.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanFaultNotificationListener.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElement.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElementFactory.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanRegistrationToVESpnfRegistration.java delete mode 100644 sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanToInternalDataModel.java (limited to 'sdnr/wt/devicemanager-o-ran-sc') diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/installer/pom.xml b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/installer/pom.xml index 91f6897bf..3f89a2a50 100755 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/installer/pom.xml +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/installer/pom.xml @@ -47,7 +47,7 @@ - org.onap.ccsdk.features.sdnr.wt + ${project.groupId} ${application.name}-feature ${project.version} xml @@ -60,7 +60,7 @@ - org.onap.ccsdk.features.sdnr.wt + ${project.groupId} ${application.name}-provider ${project.version} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/pom.xml b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/pom.xml index 3074e8031..2e816277d 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/pom.xml +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/pom.xml @@ -61,12 +61,16 @@ test - org.json - json + ${project.groupId} + sdnr-wt-devicemanager-core-provider + ${project.version} test - + + org.json + json + ${project.groupId} sdnr-wt-devicemanager-o-ran-sc-oran-model @@ -101,12 +105,12 @@ provided - org.onap.ccsdk.features.sdnr.wt + ${project.groupId} rfc7317-ietf-system ${project.version} - org.onap.ccsdk.features.sdnr.wt + ${project.groupId} onap-system ${project.version} 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 index 63d8f2787..c0aa0ac9b 100644 --- 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 @@ -20,7 +20,10 @@ 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; @@ -33,6 +36,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.not 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; @@ -47,18 +52,20 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL 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, DataProvider databaseService, - VESCollectorService vesCollectorService, NotificationProxyParser notificationProxyParser) { + public ORanChangeNotificationListener(NetconfBindingAccessor netconfAccessor, + DeviceManagerServiceProvider serviceProvider) { this.netconfAccessor = netconfAccessor; - this.databaseService = databaseService; - this.vesCollectorService = vesCollectorService; - this.notificationProxyParser = notificationProxyParser; + this.databaseService = serviceProvider.getDataProvider(); + this.notificationService = serviceProvider.getNotificationService(); + this.vesCollectorService = serviceProvider.getVESCollectorService(); + this.notificationProxyParser = vesCollectorService.getNotificationProxyParser(); } @Override @@ -83,8 +90,8 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL @Override public void onNetconfConfigChange(NetconfConfigChange notification) { - log.info("onNetconfConfigChange (1) {}", notification); - sequenceNo++; + log.info("onNetconfConfigChange (1) {}", notification.toString()); + StringBuffer sb = new StringBuffer(); List editList = notification.nonnullEdit(); for (Edit edit : editList) { @@ -93,19 +100,19 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL } sb.append(edit); - EventlogBuilder eventlogBuilder = new EventlogBuilder(); - InstanceIdentifier target = edit.getTarget(); if (target != null) { - eventlogBuilder.setObjectId(target.toString()); - log.info("TARGET: {} {} {}", target.getClass(), target.getTargetType()); + log.info("TARGET: {} {}", target.getClass(), target.getTargetType()); for (PathArgument pa : target.getPathArguments()) { - log.info("PathArgument {}", pa); + 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); } - eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue()); - eventlogBuilder.setNewValue(String.valueOf(edit.getOperation())); - databaseService.writeEventLog(eventlogBuilder.build()); } log.info("onNetconfConfigChange (2) {}", sb); @@ -113,8 +120,9 @@ public class ORanChangeNotificationListener implements IetfNetconfNotificationsL if (mapper == null) { this.mapper = new ORanNotifToVESEventAssembly(netconfAccessor, vesCollectorService); } - VESCommonEventHeaderPOJO header = mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification), - NetconfConfigChange.class.getSimpleName(), sequenceNo); + VESCommonEventHeaderPOJO header = + mapper.createVESCommonEventHeader(notificationProxyParser.getTime(notification), + NetconfConfigChange.class.getSimpleName(), sequenceNo); VESNotificationFieldsPOJO body = mapper.createVESNotificationFields(notificationProxyParser.parseNotificationProxy(notification), NetconfConfigChange.class.getSimpleName()); 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 index 6f5de9677..a17dcd726 100644 --- 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 @@ -20,91 +20,147 @@ 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 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.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.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; -/** - * @author herbert - * - */ 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; + 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.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); + LOG.debug("onAlarmNotif {}", notification.getClass().getSimpleName()); + counter++; - databaseService.updateFaultCurrent(faultCurrent.build()); + // 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()) { - if (mapper == null) { - this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService, - AlarmNotif.class.getSimpleName()); - } - VESCommonEventHeaderPOJO header = - mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); + VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(notification, eventTimeInstant, counter); VESFaultFieldsPOJO body = mapper.mapFaultFields(notification); - vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body)); + 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); + 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 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; + 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 index 1790f82c7..0d68bdbf5 100644 --- 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 @@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory; * * * 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" @@ -43,17 +44,17 @@ import org.slf4j.LoggerFactory; * 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 ??? + * 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 ????? + * 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 - * timeZoneOffset + * 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" + * vesEventListenerVersion "7.2.1" * * * alarmAdditionalInformation @@ -61,7 +62,7 @@ import org.slf4j.LoggerFactory; * 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. + * 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" @@ -71,6 +72,7 @@ import org.slf4j.LoggerFactory; 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"; @@ -82,7 +84,9 @@ public class ORanFaultToVESFaultMapper { 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) { @@ -91,6 +95,30 @@ public class ORanFaultToVESFaultMapper { 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); @@ -105,10 +133,10 @@ public class ORanFaultToVESFaultMapper { vesCEH.setEventId(eventId); vesCEH.setStartEpochMicrosec(eventTime.toEpochMilli() * 1000); vesCEH.setLastEpochMicrosec(eventTime.toEpochMilli() * 1000); - vesCEH.setNfVendorName("ORAN"); + vesCEH.setNfVendorName(getMfgName()); vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); vesCEH.setSequence(sequenceNo); - vesCEH.setSourceId("ORAN"); + vesCEH.setSourceId(getUuid()); vesCEH.setSourceName(nodeIdString); return vesCEH; @@ -121,6 +149,7 @@ public class ORanFaultToVESFaultMapper { vesFaultFields.setAlarmInterfaceA(alarmNotif.getFaultSource()); vesFaultFields.setEventCategory(VES_EVENT_CATEGORY); vesFaultFields.setEventSeverity(alarmNotif.getFaultSeverity().getName()); + vesFaultFields.setEventSourceType(getModelName()); vesFaultFields.setFaultFieldsVersion(VES_FAULT_FIELDS_VERSION); vesFaultFields.setSpecificProblem(alarmNotif.getFaultText()); vesFaultFields.setVfStatus(VES_FAULT_FIELDS_VFSTATUS); 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 index 0bb7f872b..05f1e6dd5 100644 --- 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 @@ -19,21 +19,23 @@ 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.NotificationProxyParser; +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.netmod.notification.rev080714.netconf.streams.Stream; 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; @@ -47,59 +49,67 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. 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); + private static final Logger LOG = LoggerFactory.getLogger(ORanNetworkElement.class); - private final NetconfBindingAccessor netconfAccessor; + 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; - - @SuppressWarnings("unused") + private final ORanRegistrationToVESpnfRegistrationMapper mapper; private final VESCollectorService vesCollectorService; private ListenerRegistration oRanListenerRegistrationResult; private @NonNull final ORanChangeNotificationListener oRanListener; private ListenerRegistration oRanFaultListenerRegistrationResult; private @NonNull final ORanFaultNotificationListener oRanFaultListener; - private final NotificationProxyParser notificationProxyParser; - private @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper; - private Collection componentList; - private static int sequenceNo = 0; - - ORanNetworkElement(NetconfBindingAccessor netconfAccess, DataProvider databaseService, - VESCollectorService vesCollectorService) { - log.info("Create {}", ORanNetworkElement.class.getSimpleName()); + + ORanNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + LOG.info("Create {}", ORanNetworkElement.class.getSimpleName()); + // Read parameters this.netconfAccessor = netconfAccess; - this.databaseService = databaseService; - this.vesCollectorService = vesCollectorService; - this.notificationProxyParser = vesCollectorService.getNotificationProxyParser(); + // 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, databaseService, vesCollectorService, - notificationProxyParser); + this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, serviceProvider); this.oRanFaultListenerRegistrationResult = null; - this.oRanFaultListener = - new ORanFaultNotificationListener(netconfAccessor, databaseService, vesCollectorService); + this.oRanFaultListener = new ORanFaultNotificationListener(netconfAccessor, vesCollectorService, + serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService); } - private void initialReadFromNetworkElement() { + 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 @@ -109,21 +119,18 @@ public class ORanNetworkElement implements NetworkElement { @Override public void register() { - initialReadFromNetworkElement(); + // Read data from device + Collection componentList = initialReadFromNetworkElement(); + oRanFaultListener.setComponentList(componentList); // Publish the mountpoint to VES if enabled - publishMountpointToVES(); + 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()) { - List streamList = netconfAccessor.getNotificationStreams(); - netconfAccessor.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream); // Always register first to default stream - netconfAccessor.registerNotificationsStream(streamList); - } else { - netconfAccessor.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream); - } + this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener); + this.oRanFaultListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanFaultListener); + // Register notifications stream + if (netconfAccessor.isNotificationsRFC5277Supported()) { + netconfAccessor.registerNotificationsStream(); + } } @Override @@ -136,7 +143,6 @@ public class ORanNetworkElement implements NetworkElement { } ; } - @Override public NodeId getNodeId() { return netconfAccessor.getNodeId(); @@ -155,82 +161,96 @@ public class ORanNetworkElement implements NetworkElement { return Optional.of(netconfAccessor); } + // Private functions + + private String getMountpointId() { + return getNodeId().getValue(); + } + // Read from device - private System1 getOnapSystemData() { - log.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue()); - - InstanceIdentifier 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; + /** + * 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(), + 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); + LOG.debug("Result of Hardware = {}", res); return res; } - private void publishMountpointToVES() { - log.debug("In publishMountpointToVES()"); + // 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 + /* + * 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(netconfAccessor.getNodeId().getValue())) { + 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. - this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, - vesCollectorService, component); - VESCommonEventHeaderPOJO header = - mapper.mapCommonEventHeader(sequenceNo++); - VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(); + // 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); + 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; - allowedDevices = netconfAccessor.getTransactionUtils().readData( + 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()); + 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"); + LOG.info("Mountpoint is part of allowed-devices list"); return true; } } } - log.info("Mountpoint {} is not part of allowed-devices list", mountpointName); + 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 index 55b2eea34..fff1fba79 100644 --- 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 @@ -47,8 +47,7 @@ public class ORanNetworkElementFactory implements NetworkElementFactory { log.info("Create device {} ", ORanNetworkElement.class.getName()); Optional bindingAccessor = accessor.getNetconfBindingAccessor(); if (bindingAccessor.isPresent()) { - return Optional.of(new ORanNetworkElement(bindingAccessor.get(), serviceProvider.getDataProvider(), - serviceProvider.getVESCollectorService())); + return Optional.of(new ORanNetworkElement(bindingAccessor.get(), serviceProvider)); } } } 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 index 81605e450..3524383f2 100644 --- 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 @@ -22,7 +22,6 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl; import java.time.Instant; -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.VESPNFRegistrationFieldsPOJO; @@ -33,6 +32,7 @@ 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"; @@ -40,17 +40,20 @@ public class ORanRegistrationToVESpnfRegistrationMapper { private static final String VES_EVENT_PRIORITY = "Normal"; private final VESCollectorService vesProvider; - private final @NonNull Component component; private final NetconfAccessor netconfAccessor; + private Integer sequenceNo; + + public ORanRegistrationToVESpnfRegistrationMapper(NetconfAccessor netconfAccessor, - VESCollectorService vesCollectorService, Component component) { + VESCollectorService vesCollectorService) { this.netconfAccessor = netconfAccessor; this.vesProvider = vesCollectorService; - this.component = component; + + this.sequenceNo = 0; } - public VESCommonEventHeaderPOJO mapCommonEventHeader(int sequenceNo) { + public VESCommonEventHeaderPOJO mapCommonEventHeader(Component component) { VESCommonEventHeaderPOJO vesCEH = new VESCommonEventHeaderPOJO(); vesCEH.setDomain(VES_EVENT_DOMAIN); vesCEH.setEventId(netconfAccessor.getNodeId().getValue()); @@ -62,24 +65,24 @@ public class ORanRegistrationToVESpnfRegistrationMapper { vesCEH.setLastEpochMicrosec(Instant.now().toEpochMilli() * 1000); vesCEH.setNfVendorName(component.getMfgName()); vesCEH.setReportingEntityName(vesProvider.getConfig().getReportingEntityName()); - vesCEH.setSequence(sequenceNo); - vesCEH.setSourceId(component.getUuid().toString()); + vesCEH.setSequence(sequenceNo++); + vesCEH.setSourceId(component.getUuid() != null ? component.getUuid().toString():netconfAccessor.getNodeId().getValue()); vesCEH.setSourceName(netconfAccessor.getNodeId().getValue()); return vesCEH; } - public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields() { + public VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields(Component component) { VESPNFRegistrationFieldsPOJO vesPnfFields = new VESPNFRegistrationFieldsPOJO(); vesPnfFields.setModelNumber(component.getModelName()); - vesPnfFields.setOamV4IpAddress(netconfAccessor.getNetconfNode().getHost().getIpAddress().toString()); - //vesPnfFields.setOamV6IpAddress(oamV6IpAddress); // Check if IP address in V6 format and then include it. Same with v4 address also + 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().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 index 1f84db41c..71ab613d2 100644 --- 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 @@ -17,6 +17,7 @@ */ 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; @@ -27,11 +28,17 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.re 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; @@ -111,8 +118,8 @@ public class ORanToInternalDataModel { } /** - * Convert equipment into Inventory. Decide if inventory can by created from content or not. - * Public for test case. + * 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 @@ -181,6 +188,12 @@ public class ORanToInternalDataModel { 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(); @@ -200,4 +213,64 @@ public class ORanToInternalDataModel { 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/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java new file mode 100644 index 000000000..05c825fdc --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/ComponentHelper.java @@ -0,0 +1,179 @@ +/* + * ============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.Arrays; +import java.util.List; +import java.util.Scanner; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.json.JSONArray; +import org.json.JSONObject; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.Fan; +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.iana.hardware.rev180313.Port; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.Sensor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.AdminState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.OperState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorStatus; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorValue; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorValueType; +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.hardware.rev180313.hardware.ComponentBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.SensorData; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.SensorDataBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.State; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.StateBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; + +public class ComponentHelper { + + public static Component get(String name, String dateTimeString) { + DateAndTime dateTime = new DateAndTime(dateTimeString); + Uuid uuid = new Uuid("0Aabcdef-0abc-0cfD-0abC-0123456789AB"); + + ComponentBuilder componentBuilder = new ComponentBuilder(); + componentBuilder.setParent("Shelf").setName("Slot-0").setParentRelPos(0); + componentBuilder.setUuid(uuid); + componentBuilder.setContainsChild(Arrays.asList("Card-01A", "Card-01B")); + componentBuilder.setDescription("ORAN Network Element NO-456"); + componentBuilder.setXmlClass(TestHardwareClass.class); + componentBuilder.setMfgName("Nokia"); + componentBuilder.setMfgDate(dateTime); + return componentBuilder.build(); + } + + public static List getComponentList(String resourceName) { + try (Scanner scanner = new Scanner(ComponentHelper.class.getResourceAsStream(resourceName), "UTF-8")) { + String jsonString = scanner.useDelimiter("\\A").next(); + JSONObject jsonHardware = new JSONObject(jsonString).getJSONObject("hardware"); + JSONArray jsonComponentArray = jsonHardware.getJSONArray("component"); + return IntStream.range(0, jsonComponentArray.length()) + .mapToObj(idx -> ComponentHelper.get(jsonComponentArray.getJSONObject(idx))) + .collect(Collectors.toList()); + } + } + + public static Component get(JSONObject jsonComponent) { + ComponentBuilder componentBuilder = new ComponentBuilder(); + componentBuilder.setName(getString(jsonComponent, "name")); + componentBuilder.setParent(getString(jsonComponent, "parent")); + componentBuilder.setParentRelPos(getInteger(jsonComponent, "parent-rel-pos")); + componentBuilder.setAlias(getString(jsonComponent, "alias")); + componentBuilder.setXmlClass(getXmlClass(jsonComponent, "class")); + componentBuilder.setState(getState(jsonComponent, "state")); + componentBuilder.setDescription(getString(jsonComponent, "description")); + componentBuilder.setContainsChild(getStringArray(jsonComponent, "contains-child")); + componentBuilder.setSensorData(getSensorData(jsonComponent, "sensor-data")); + componentBuilder.setFirmwareRev(getString(jsonComponent, "firmware-rev")); + componentBuilder.setSerialNum(getString(jsonComponent, "serial-num")); + componentBuilder.setSoftwareRev(getString(jsonComponent, "software-rev")); + return componentBuilder.build(); + } + + // Private + + private static State getState(JSONObject jsonComponent, String key) { + if (jsonComponent.has(key)) { + JSONObject jsonState = jsonComponent.getJSONObject(key); + StateBuilder stateBuilder = new StateBuilder(); + stateBuilder.setOperState(getString(jsonState, "oper-state", value -> OperState.forName(value)).get()); + stateBuilder.setAdminState(getString(jsonState, "admin-state", value -> AdminState.forName(value)).get()); + return stateBuilder.build(); + } + return null; + } + + private static SensorData getSensorData(JSONObject jsonComponent, String key) { + if (jsonComponent.has(key)) { + JSONObject jsonSonsor = jsonComponent.getJSONObject(key); + SensorDataBuilder sensorBuilder = new SensorDataBuilder(); + sensorBuilder.setValueTimestamp(getString(jsonSonsor, "value-timestamp", value -> new DateAndTime(value))); + sensorBuilder.setValue(getInteger(jsonSonsor, "value", value -> new SensorValue(value))); + sensorBuilder + .setValueType(getString(jsonSonsor, "value-type", value -> SensorValueType.forName(value).get())); + sensorBuilder + .setOperStatus(getString(jsonSonsor, "oper-status", value -> SensorStatus.forName(value).get())); + return sensorBuilder.build(); + } + return null; + } + + // Get data types + private static Class getXmlClass(JSONObject jsonComponent, String key) { + return getString(jsonComponent, key, value -> { + switch (value) { + case "iana-hardware:sensor": + return Sensor.class; + case "iana-hardware:port": + return Port.class; + case "iana-hardware:fan": + return Fan.class; + default: + return HardwareClass.class; + } + }); + } + + private static String getString(JSONObject jsonObject, String key) { + return getString(jsonObject, key, value -> value); + } + + private static Integer getInteger(JSONObject jsonObject, String key) { + return getInteger(jsonObject, key, value -> value); + } + + private interface ConvertString { + T convert(String value); + } + + private static T getString(JSONObject jsonObject, String key, ConvertString convert) { + if (jsonObject.has(key)) { + String value = jsonObject.getString(key); + return convert.convert(value); + } + return null; + } + + private interface ConvertInteger { + T convert(int value); + } + + private static T getInteger(JSONObject jsonObject, String key, ConvertInteger convert) { + if (jsonObject.has(key)) { + int value = jsonObject.getInt(key); + return convert.convert(value); + } + return null; + } + + private static List getStringArray(JSONObject jsonComponent, String key) { + if (jsonComponent.has(key)) { + JSONArray stringArray = jsonComponent.getJSONArray(key); + return IntStream.range(0, stringArray.length()).mapToObj(idx -> stringArray.getString(idx)) + .collect(Collectors.toList()); + } + return null; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java new file mode 100644 index 000000000..b3388114b --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestAlarmNotif.java @@ -0,0 +1,90 @@ +/* + * ============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.Map; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +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.alarm.AffectedObjects; +import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.alarm.AffectedObjectsKey; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.common.Uint16; + +public class TestAlarmNotif implements AlarmNotif { + + private static final Uint16 FAULT_ID = Uint16.valueOf(123); + + @Override + public > @Nullable A augmentation(Class augmentationType) { + return null; + } + + @Override + public @Nullable Uint16 getFaultId() { + return FAULT_ID; + } + + @Override + public @Nullable String getFaultSource() { + return "ORAN-RU-FH"; + } + + @Override + public @Nullable Map getAffectedObjects() { + return null; + } + + @Override + public @Nullable FaultSeverity getFaultSeverity() { + return FaultSeverity.CRITICAL; + } + + @Override + public @Nullable Boolean isIsCleared() { + return true; + } + + @Override + public @Nullable String getFaultText() { + return "CPRI Port Down"; + } + + @Override + public @Nullable DateAndTime getEventTime() { + return new DateAndTime("2021-03-23T18:19:42.326144Z"); + } + + @Override + public @NonNull Map>, Augmentation> augmentations() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Boolean getIsCleared() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java new file mode 100644 index 000000000..98db4bbb6 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestDeviceManagerORanImpl.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.mockito.Mockito.mock; +import java.io.IOException; +import org.junit.Before; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.DeviceManagerORanImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; + +public class TestDeviceManagerORanImpl { + DeviceManagerORanImpl devMgrOran; + + @Before + public void init() throws InterruptedException, IOException { + } + + // @Test + public void test() throws Exception { + devMgrOran = new DeviceManagerORanImpl(); + NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class); + + try { + devMgrOran.setNetconfNetworkElementService(netconfNetworkElementService); + devMgrOran.init(); + } catch (Exception e) { + throw e; + } + } + + //@After + public void cleanUp() throws Exception { + devMgrOran.close(); + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java new file mode 100644 index 000000000..64b6ac1ab --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestHardwareClass.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass; + +public interface TestHardwareClass extends HardwareClass { + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java new file mode 100644 index 000000000..da4d830d7 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanChangeNotificationListener.java @@ -0,0 +1,110 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +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.VESCollectorCfgService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType; +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.netconf.config.change.Edit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; + +@RunWith(MockitoJUnitRunner.class) +public class TestORanChangeNotificationListener { + + private static final String NODEID = "node1"; + + @Mock + DeviceManagerServiceProvider serviceProvider; + @Mock + NetconfBindingAccessor netconfAccessor; + @Mock + DataProvider databaseService; + @Mock + VESCollectorService vesCollectorService; + @Mock + VESCollectorCfgService vesCfgService; + @Mock + NotificationProxyParser notifProxyParser; + @Mock + static NetconfConfigChange change; + + @Test + public void test() { + + when(vesCollectorService.getConfig()).thenReturn(vesCfgService); + when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID)); + when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); + when(serviceProvider.getDataProvider()).thenReturn(databaseService); + when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); + when(vesCollectorService.getNotificationProxyParser()).thenReturn(notifProxyParser); + + ORanChangeNotificationListener notifListener = + new ORanChangeNotificationListener(netconfAccessor, serviceProvider); + + Iterable pathArguments = Arrays.asList(new PathArgument() { + + @Override + public int compareTo(PathArgument arg0) { + return 0; + } + + @Override + public Class getType() { + return DataObject.class; + } + }); + InstanceIdentifier target = InstanceIdentifier.create(pathArguments); + NetconfConfigChange confChangeNotification = createNotification(EditOperationType.Create, target); + when(notifProxyParser.getTime(confChangeNotification)).thenReturn(Instant.now()); + notifListener.onNetconfConfigChange(confChangeNotification); + verify(databaseService).writeEventLog(any(EventlogEntity.class)); + } + + /** + * @param type + * @return + */ + private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier target) { + @SuppressWarnings("null") + final @NonNull List edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build()); + when(change.nonnullEdit()).thenReturn(edits); + return change; + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java new file mode 100644 index 000000000..af2515c9a --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanFaultNotificationListener.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +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.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; +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.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.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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@RunWith(MockitoJUnitRunner.class) +public class TestORanFaultNotificationListener { + + private static final Logger LOG = LoggerFactory.getLogger(TestORanFaultNotificationListener.class); + private static final String TESTFILENAME = "configFile.txt"; + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[VESCollector]\n" + + "VES_COLLECTOR_ENABLED=true\n" + + "VES_COLLECTOR_TLS_ENABLED=true\n" + + "VES_COLLECTOR_TRUST_ALL_CERTS=true\n" + + "VES_COLLECTOR_USERNAME=sample1\n" + + "VES_COLLECTOR_PASSWORD=sample1\n" + + "VES_COLLECTOR_IP=[2001:db8:1:1::1]\n" + + "VES_COLLECTOR_PORT=8443\n" + + "VES_COLLECTOR_VERSION=v7\n" + + "REPORTING_ENTITY_NAME=ONAP SDN-R\n" + + "EVENTLOG_MSG_DETAIL=SHORT\n" + + ""; + // @formatter:on + + @Mock NetconfBindingAccessor bindingAccessor; + @Mock DataProvider dataProvider; + @Mock FaultService faultService; + @Mock DeviceManagerServiceProvider serviceProvider; + @Mock WebsocketManagerService websocketManagerService; + @Mock DataProvider databaseService; + VESCollectorService vesCollectorService; + + @After + @Before + public void afterAndBefore() { + File f = new File(TESTFILENAME); + if (f.exists()) { + LOG.info("Remove {}", f.getAbsolutePath()); + f.delete(); + } + } + + @Test + public void test() throws IOException { + Files.asCharSink(new File(TESTFILENAME), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + vesCollectorService = + new VESCollectorServiceImpl(new ConfigurationFileRepresentation(TESTFILENAME)); + when(bindingAccessor.getNodeId()).thenReturn(new NodeId("nSky")); + ORanFaultNotificationListener faultListener = new ORanFaultNotificationListener(bindingAccessor, + vesCollectorService, faultService, websocketManagerService, databaseService); + faultListener.onAlarmNotif(new TestAlarmNotif()); + + verify(faultService).faultNotification(getFaultLog()); + } + + private FaultlogEntity getFaultLog() { + FaultlogBuilder faultAlarm = new FaultlogBuilder(); + faultAlarm.setNodeId("nSky"); + faultAlarm.setObjectId("ORAN-RU-FH"); + faultAlarm.setProblem("CPRI Port Down"); + faultAlarm.setSeverity(SeverityType.NonAlarmed); + faultAlarm.setCounter(1); + faultAlarm.setId("123"); + faultAlarm.setSourceType(SourceType.Netconf); + faultAlarm.setTimestamp(new DateAndTime("2021-03-23T18:19:42.326144Z")); + return faultAlarm.build(); + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java new file mode 100644 index 000000000..af7664ab8 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElement.java @@ -0,0 +1,111 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.io.IOException; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +import org.junit.BeforeClass; +import org.junit.Test; +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.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; +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.TransactionUtils; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.common.QName; + +public class TestORanNetworkElement { + + private static final QName OneCell = + QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern(); + private static final @NonNull QName OnapSystem = QName.create("urn:onap:system", "2020-10-26", "onap-system").intern(); + private static String NODEIDSTRING = "nSky"; + private static NodeId nodeId = new NodeId(NODEIDSTRING); + + private static NetconfAccessor accessor; + private static DeviceManagerServiceProvider serviceProvider; + private static Capabilities capabilities; + private static TransactionUtils transactionUtils; + private static NetconfBindingAccessor bindingAccessor; + private static VESCollectorService vesCollectorService; + private static NotificationProxyParser notificationProxyParser; + private static VESCollectorCfgService vesCfgService; + private static WebsocketManagerService websocketManagerService; + + @BeforeClass + public static void init() throws InterruptedException, IOException { + capabilities = mock(Capabilities.class); + accessor = mock(NetconfAccessor.class); + serviceProvider = mock(DeviceManagerServiceProvider.class); + transactionUtils = mock(TransactionUtils.class); + bindingAccessor = mock(NetconfBindingAccessor.class); + vesCollectorService = mock(VESCollectorService.class); + notificationProxyParser = mock(NotificationProxyParser.class); + vesCfgService = mock(VESCollectorCfgService.class); + websocketManagerService = mock(WebsocketManagerService.class); + + when(accessor.getCapabilites()).thenReturn(capabilities); + when(accessor.getNodeId()).thenReturn(nodeId); + when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor)); + when(bindingAccessor.getCapabilites()).thenReturn(capabilities); + when(bindingAccessor.getTransactionUtils()).thenReturn(transactionUtils); + when(bindingAccessor.getNodeId()).thenReturn(nodeId); + when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser); + + DataProvider dataProvider = mock(DataProvider.class); + FaultService faultService = mock(FaultService.class); + when(serviceProvider.getWebsocketService()).thenReturn(websocketManagerService); + when(serviceProvider.getFaultService()).thenReturn(faultService); + when(serviceProvider.getDataProvider()).thenReturn(dataProvider); + when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); + when(vesCollectorService.getConfig()).thenReturn(vesCfgService); + when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); + + } + + @Test + public void test() { + Optional oRanNe; + when(capabilities.isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true); + when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false); + when(capabilities.isSupportingNamespace(OnapSystem)).thenReturn(false); + + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + oRanNe = factory.create(accessor, serviceProvider); + assertTrue(factory.create(accessor, serviceProvider).isPresent()); + oRanNe.get().register(); + oRanNe.get().deregister(); + oRanNe.get().getAcessor(); + oRanNe.get().getDeviceType(); + assertEquals(oRanNe.get().getNodeId().getValue(), "nSky"); + } + + } diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java new file mode 100644 index 000000000..fc382bfe2 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanNetworkElementFactory.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.io.IOException; +import java.util.Optional; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +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.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; +import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class TestORanNetworkElementFactory { + + private static String NODEIDSTRING = "nSky"; + + private static NetconfBindingAccessor accessor; + private static DeviceManagerServiceProvider serviceProvider; + private static Capabilities capabilities; + private static VESCollectorService vesCollectorService; + private static FaultService faultService; + private static WebsocketManagerService notificationService; + private static DataProvider databaseService; + + @BeforeClass + public static void init() throws InterruptedException, IOException { + NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class); + NodeId nodeId = new NodeId(NODEIDSTRING); + when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); + when(bindingAccessor.getNodeId()).thenReturn(nodeId); + + capabilities = mock(Capabilities.class); + accessor = mock(NetconfBindingAccessor.class); + serviceProvider = mock(DeviceManagerServiceProvider.class); + vesCollectorService = mock(VESCollectorService.class); + faultService = mock(FaultService.class); + notificationService = mock(WebsocketManagerService.class); + databaseService = mock(DataProvider.class); + + when(accessor.getCapabilites()).thenReturn(capabilities); + when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor)); + when(serviceProvider.getFaultService()).thenReturn(faultService); + when(serviceProvider.getWebsocketService()).thenReturn(notificationService); + when(serviceProvider.getDataProvider()).thenReturn(databaseService); + when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); + + } + + @Test + public void testCreateORANHWComponent() throws Exception { + when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true); + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + assertTrue((factory.create(accessor, serviceProvider)).isPresent()); + } + + @Test + public void testCreateNone() throws Exception { + when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(false); + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + assertTrue(!(factory.create(accessor, serviceProvider).isPresent())); + } + + @After + public void cleanUp() throws Exception { + + } +} + diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java new file mode 100644 index 000000000..115765d46 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanRegistrationToVESpnfRegistration.java @@ -0,0 +1,72 @@ +/* + * ============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 static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanRegistrationToVESpnfRegistrationMapper; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +@RunWith(MockitoJUnitRunner.class) +public class TestORanRegistrationToVESpnfRegistration { + + @Mock + NetconfAccessor netconfAccessor; + @Mock + VESCollectorService vesCollectorService; + @Mock + VESCollectorCfgService vesCfgService; + + private final int SEQUENCE_NO = 10; + + @Test + public void test() { + String dateTimeString = "2020-02-05T12:30:45.283Z"; + String name = "Slot-0"; + + NetconfNode testNetconfNode = mock(NetconfNode.class); + when(testNetconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("10.10.10.10")))); + + when(netconfAccessor.getNodeId()).thenReturn(new NodeId("nSky")); + when(netconfAccessor.getNetconfNode()).thenReturn(testNetconfNode); + when(vesCollectorService.getConfig()).thenReturn(vesCfgService); + when(vesCfgService.getReportingEntityName()).thenReturn("SDN-R"); + Component testComponent = ComponentHelper.get(name, dateTimeString); + + ORanRegistrationToVESpnfRegistrationMapper mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, vesCollectorService); + mapper.mapCommonEventHeader(testComponent); + mapper.mapPNFRegistrationFields(testComponent); + } + +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java new file mode 100644 index 000000000..e2e0eb812 --- /dev/null +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/TestORanToInternalDataModel.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.function.IntConsumer; +import java.util.stream.IntStream; +import org.eclipse.jdt.annotation.Nullable; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanToInternalDataModel; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestORanToInternalDataModel { + + private static final Logger LOG = LoggerFactory.getLogger(TestORanToInternalDataModel.class); + + NodeId nodeId = new NodeId("ORan-1000"); + + @Test + public void testInventory() { + String dateTimeString = "2020-02-05T12:30:45.283Z"; + String name = "Slot-0"; + + Component testComponent = ComponentHelper.get(name, dateTimeString); + Optional oInventory = ORanToInternalDataModel.getInternalEquipment(nodeId, testComponent, 0); + + assertTrue(oInventory.isPresent()); + Inventory inventory = oInventory.get(); + assertEquals(name, inventory.getUuid()); + assertEquals(dateTimeString, inventory.getDate()); + assertEquals(nodeId.getValue(), inventory.getNodeId()); + } + + @Test + public void testInventoryList() throws IOException, ClassNotFoundException { + List componentList = ComponentHelper.getComponentList("/Device-ietf-hardware-Output.json"); + List inventoryList = ORanToInternalDataModel.getInventoryList(nodeId, componentList); + //componentList.forEach(System.out::println); + assertEquals("All elements", 27, inventoryList.size()); + assertEquals("Fully parseable", componentList.size(), inventoryList.size()); + assertEquals("Treelevel always there", 0, + inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count()); + listAsTree(inventoryList); + } + + private void listAsTree(List inventoryList) { + //Walk through complete list and print parameters + IntConsumer action = level -> IntStream.range(0, inventoryList.size()) + .filter(idx -> inventoryList.get(idx).getTreeLevel().intValue() == level) + .forEach(idx2 -> printElements(idx2, level, inventoryList.get(idx2))); + //Walk trough 10 levels + IntStream.range(0, 10) + .forEach(action); + } + + private void printElements(int idx2, int level, Inventory inventory) { + System.out.println(level + ": " + inventory.getParentUuid() + " " + + inventory.getUuid()); + } + + @SuppressWarnings("unused") + private boolean compareLevel(int idx, List componentList, List inventoryList) { + @Nullable + Integer relPos = componentList.get(idx).getParentRelPos(); + @Nullable + Uint32 treeLevel = inventoryList.get(idx).getTreeLevel(); + LOG.warn("Treelevel relPos: {} treeLevel: {}", relPos, treeLevel); + if (relPos != null && treeLevel != null) { + return relPos == treeLevel.intValue(); + } + return false; + } +} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/ComponentHelper.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/ComponentHelper.java deleted file mode 100644 index 7b8380442..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/ComponentHelper.java +++ /dev/null @@ -1,179 +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.test; - -import java.util.Arrays; -import java.util.List; -import java.util.Scanner; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.json.JSONArray; -import org.json.JSONObject; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.Fan; -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.iana.hardware.rev180313.Port; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.Sensor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.AdminState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.OperState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorValue; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.SensorValueType; -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.hardware.rev180313.hardware.ComponentBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.SensorData; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.SensorDataBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.State; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.component.StateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; - -public class ComponentHelper { - - public static Component get(String name, String dateTimeString) { - DateAndTime dateTime = new DateAndTime(dateTimeString); - Uuid uuid = new Uuid("0Aabcdef-0abc-0cfD-0abC-0123456789AB"); - - ComponentBuilder componentBuilder = new ComponentBuilder(); - componentBuilder.setParent("Shelf").setName("Slot-0").setParentRelPos(0); - componentBuilder.setUuid(uuid); - componentBuilder.setContainsChild(Arrays.asList("Card-01A", "Card-01B")); - componentBuilder.setDescription("ORAN Network Element NO-456"); - componentBuilder.setXmlClass(TestHardwareClass.class); - componentBuilder.setMfgName("Nokia"); - componentBuilder.setMfgDate(dateTime); - return componentBuilder.build(); - } - - public static List getComponentList(String resourceName) { - try (Scanner scanner = new Scanner(ComponentHelper.class.getResourceAsStream(resourceName), "UTF-8")) { - String jsonString = scanner.useDelimiter("\\A").next(); - JSONObject jsonHardware = new JSONObject(jsonString).getJSONObject("hardware"); - JSONArray jsonComponentArray = jsonHardware.getJSONArray("component"); - return IntStream.range(0, jsonComponentArray.length()) - .mapToObj(idx -> ComponentHelper.get(jsonComponentArray.getJSONObject(idx))) - .collect(Collectors.toList()); - } - } - - public static Component get(JSONObject jsonComponent) { - ComponentBuilder componentBuilder = new ComponentBuilder(); - componentBuilder.setName(getString(jsonComponent, "name")); - componentBuilder.setParent(getString(jsonComponent, "parent")); - componentBuilder.setParentRelPos(getInteger(jsonComponent, "parent-rel-pos")); - componentBuilder.setAlias(getString(jsonComponent, "alias")); - componentBuilder.setXmlClass(getXmlClass(jsonComponent, "class")); - componentBuilder.setState(getState(jsonComponent, "state")); - componentBuilder.setDescription(getString(jsonComponent, "description")); - componentBuilder.setContainsChild(getStringArray(jsonComponent, "contains-child")); - componentBuilder.setSensorData(getSensorData(jsonComponent, "sensor-data")); - componentBuilder.setFirmwareRev(getString(jsonComponent, "firmware-rev")); - componentBuilder.setSerialNum(getString(jsonComponent, "serial-num")); - componentBuilder.setSoftwareRev(getString(jsonComponent, "software-rev")); - return componentBuilder.build(); - } - - // Private - - private static State getState(JSONObject jsonComponent, String key) { - if (jsonComponent.has(key)) { - JSONObject jsonState = jsonComponent.getJSONObject(key); - StateBuilder stateBuilder = new StateBuilder(); - stateBuilder.setOperState(getString(jsonState, "oper-state", value -> OperState.forName(value)).get()); - stateBuilder.setAdminState(getString(jsonState, "admin-state", value -> AdminState.forName(value)).get()); - return stateBuilder.build(); - } - return null; - } - - private static SensorData getSensorData(JSONObject jsonComponent, String key) { - if (jsonComponent.has(key)) { - JSONObject jsonSonsor = jsonComponent.getJSONObject(key); - SensorDataBuilder sensorBuilder = new SensorDataBuilder(); - sensorBuilder.setValueTimestamp(getString(jsonSonsor, "value-timestamp", value -> new DateAndTime(value))); - sensorBuilder.setValue(getInteger(jsonSonsor, "value", value -> new SensorValue(value))); - sensorBuilder - .setValueType(getString(jsonSonsor, "value-type", value -> SensorValueType.forName(value).get())); - sensorBuilder - .setOperStatus(getString(jsonSonsor, "oper-status", value -> SensorStatus.forName(value).get())); - return sensorBuilder.build(); - } - return null; - } - - // Get data types - private static Class getXmlClass(JSONObject jsonComponent, String key) { - return getString(jsonComponent, key, value -> { - switch (value) { - case "iana-hardware:sensor": - return Sensor.class; - case "iana-hardware:port": - return Port.class; - case "iana-hardware:fan": - return Fan.class; - default: - return HardwareClass.class; - } - }); - } - - private static String getString(JSONObject jsonObject, String key) { - return getString(jsonObject, key, value -> value); - } - - private static Integer getInteger(JSONObject jsonObject, String key) { - return getInteger(jsonObject, key, value -> value); - } - - private interface ConvertString { - T convert(String value); - } - - private static T getString(JSONObject jsonObject, String key, ConvertString convert) { - if (jsonObject.has(key)) { - String value = jsonObject.getString(key); - return convert.convert(value); - } - return null; - } - - private interface ConvertInteger { - T convert(int value); - } - - private static T getInteger(JSONObject jsonObject, String key, ConvertInteger convert) { - if (jsonObject.has(key)) { - int value = jsonObject.getInt(key); - return convert.convert(value); - } - return null; - } - - private static List getStringArray(JSONObject jsonComponent, String key) { - if (jsonComponent.has(key)) { - JSONArray stringArray = jsonComponent.getJSONArray(key); - return IntStream.range(0, stringArray.length()).mapToObj(idx -> stringArray.getString(idx)) - .collect(Collectors.toList()); - } - return null; - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestAlarmNotif.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestAlarmNotif.java deleted file mode 100644 index 76487fa17..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestAlarmNotif.java +++ /dev/null @@ -1,88 +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.test; - -import java.util.Map; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -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.alarm.AffectedObjects; -import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.alarm.AffectedObjectsKey; -import org.opendaylight.yangtools.yang.binding.Augmentation; -import org.opendaylight.yangtools.yang.common.Uint16; - -public class TestAlarmNotif implements AlarmNotif { - - private static final Uint16 FAULT_ID = Uint16.valueOf(123); - - @Override - public > @Nullable A augmentation(Class augmentationType) { - return null; - } - - @Override - public @Nullable Uint16 getFaultId() { - return FAULT_ID; - } - - @Override - public @Nullable String getFaultSource() { - return "ORAN-RU-FH"; - } - - @Override - public @Nullable Map getAffectedObjects() { - return null; - } - - @Override - public @Nullable FaultSeverity getFaultSeverity() { - return FaultSeverity.CRITICAL; - } - - @Override - public @Nullable Boolean isIsCleared() { - return true; - } - - @Override - public @Nullable String getFaultText() { - return "CPRI Port Down"; - } - - @Override - public @Nullable DateAndTime getEventTime() { - return new DateAndTime("2021-03-23T18:19:42.326144Z"); - } - - @Override - public @NonNull Map>, Augmentation> augmentations() { - return null; - } - - @Override - public Boolean getIsCleared() { - return null; - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestDeviceManagerORanImpl.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestDeviceManagerORanImpl.java deleted file mode 100644 index 7b05342c4..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestDeviceManagerORanImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.mockito.Mockito.mock; -import java.io.IOException; -import org.junit.Before; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.DeviceManagerORanImpl; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; - -public class TestDeviceManagerORanImpl { - DeviceManagerORanImpl devMgrOran; - - @Before - public void init() throws InterruptedException, IOException { - } - - // @Test - public void test() throws Exception { - devMgrOran = new DeviceManagerORanImpl(); - NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class); - - try { - devMgrOran.setNetconfNetworkElementService(netconfNetworkElementService); - devMgrOran.init(); - } catch (Exception e) { - throw e; - } - } - - //@After - public void cleanUp() throws Exception { - devMgrOran.close(); - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestHardwareClass.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestHardwareClass.java deleted file mode 100644 index c8a000bde..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestHardwareClass.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.hardware.rev180313.HardwareClass; - -public interface TestHardwareClass extends HardwareClass { - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanChangeNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanChangeNotificationListener.java deleted file mode 100644 index dd5fa7fae..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanChangeNotificationListener.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import org.eclipse.jdt.annotation.NonNull; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanChangeNotificationListener; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType; -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.netconf.config.change.Edit; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder; -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.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; - -@RunWith(MockitoJUnitRunner.class) -public class TestORanChangeNotificationListener { - - private static final String NODEID = "node1"; - - @Mock - NetconfBindingAccessor netconfAccessor; - @Mock - DataProvider databaseService; - @Mock - VESCollectorService vesCollectorService; - @Mock - VESCollectorCfgService vesCfgService; - @Mock - NotificationProxyParser notifProxyParser; - @Mock - static NetconfConfigChange change; - - @Test - public void test() { - - when(vesCollectorService.getConfig()).thenReturn(vesCfgService); - when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID)); - when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); - - ORanChangeNotificationListener notifListener = - new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService, notifProxyParser); - - Iterable pathArguments = Arrays.asList(new PathArgument() { - - @Override - public int compareTo(PathArgument arg0) { - return 0; - } - - @Override - public Class getType() { - return DataObject.class; - } - }); - InstanceIdentifier target = InstanceIdentifier.create(pathArguments); - NetconfConfigChange confChangeNotification = createNotification(EditOperationType.Create, target); - when(notifProxyParser.getTime(confChangeNotification)).thenReturn(Instant.now()); - notifListener.onNetconfConfigChange(confChangeNotification); - EventlogEntity event = new EventlogBuilder().setNodeId(NODEID) - .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build(); - verify(databaseService).writeEventLog(event); - - } - - /** - * @param type - * @return - */ - private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier target) { - @SuppressWarnings("null") - final @NonNull List edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build()); - when(change.nonnullEdit()).thenReturn(edits); - return change; - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanFaultNotificationListener.java deleted file mode 100644 index b536460a0..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanFaultNotificationListener.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanFaultNotificationListener; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -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.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.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; - -@RunWith(MockitoJUnitRunner.class) -public class TestORanFaultNotificationListener { - - @Mock - NetconfBindingAccessor bindingAccessor; - @Mock - DataProvider dataProvider; - @Mock - VESCollectorService vesCollectorService; - @Mock - VESCollectorCfgService vesCfgService; - - @Test - public void test() { - when(bindingAccessor.getNodeId()).thenReturn(new NodeId("nSky")); - when(vesCollectorService.getConfig()).thenReturn(vesCfgService); - when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); - - ORanFaultNotificationListener faultListener = new ORanFaultNotificationListener(bindingAccessor, dataProvider, vesCollectorService); - faultListener.onAlarmNotif(new TestAlarmNotif()); - verify(dataProvider).updateFaultCurrent(new FaultcurrentBuilder().setCounter(0) - .setNodeId("nSky") - .setId("123") - .setProblem("CPRI Port Down") - .setSeverity(SeverityType.Critical) - .setObjectId("ORAN-RU-FH") - .setTimestamp(new DateAndTime("2021-03-23T18:19:42.326144Z")) - .build()); - } -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElement.java deleted file mode 100644 index 2ca59d916..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElement.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.io.IOException; -import java.util.Optional; -import org.junit.BeforeClass; -import org.junit.Test; -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.oran.impl.ORanNetworkElementFactory; -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.VESCollectorCfgService; -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.TransactionUtils; -import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.common.QName; - -public class TestORanNetworkElement { - - private static final QName OneCell = - QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern(); - private static String NODEIDSTRING = "nSky"; - private static NodeId nodeId = new NodeId(NODEIDSTRING); - private static NodeId nNodeId = new NodeId("nSky"); - - private static NetconfAccessor accessor; - private static DeviceManagerServiceProvider serviceProvider; - private static Capabilities capabilities; - private static TransactionUtils transactionUtils; - private static NetconfBindingAccessor bindingCommunicator; - private static VESCollectorService vesCollectorService; - private static NotificationProxyParser notificationProxyParser; - private static VESCollectorCfgService vesCfgService; - - @BeforeClass - public static void init() throws InterruptedException, IOException { - capabilities = mock(Capabilities.class); - accessor = mock(NetconfAccessor.class); - serviceProvider = mock(DeviceManagerServiceProvider.class); - transactionUtils = mock(TransactionUtils.class); - bindingCommunicator = mock(NetconfBindingAccessor.class); - vesCollectorService = mock(VESCollectorService.class); - notificationProxyParser = mock(NotificationProxyParser.class); - vesCfgService = mock(VESCollectorCfgService.class); - - when(accessor.getCapabilites()).thenReturn(capabilities); - when(accessor.getNodeId()).thenReturn(nNodeId); - when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingCommunicator)); - when(bindingCommunicator.getTransactionUtils()).thenReturn(transactionUtils); - when(bindingCommunicator.getNodeId()).thenReturn(nodeId); - when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser); - - DataProvider dataProvider = mock(DataProvider.class); - when(serviceProvider.getDataProvider()).thenReturn(dataProvider); - when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); - when(vesCollectorService.getConfig()).thenReturn(vesCfgService); - when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); - - } - - @Test - public void test() { - - NodeId nodeId = new NodeId(NODEIDSTRING); - when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); - when(bindingCommunicator.getNodeId()).thenReturn(nodeId); - - Optional oRanNe; - when(capabilities.isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true); - when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); - oRanNe = factory.create(accessor, serviceProvider); - assertTrue(factory.create(accessor, serviceProvider).isPresent()); - oRanNe.get().register(); - oRanNe.get().deregister(); - oRanNe.get().getAcessor(); - oRanNe.get().getDeviceType(); - assertEquals(oRanNe.get().getNodeId().getValue(), "nSky"); - } - - } diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElementFactory.java deleted file mode 100644 index 0e257e345..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanNetworkElementFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.io.IOException; -import java.util.Optional; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanNetworkElementFactory; -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.NetconfBindingAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; -import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; - -public class TestORanNetworkElementFactory { - - private static String NODEIDSTRING = "nSky"; - - private static NetconfBindingAccessor accessor; - private static DeviceManagerServiceProvider serviceProvider; - private static Capabilities capabilities; - - // @BeforeClass - public static void init() throws InterruptedException, IOException { - NetconfBindingAccessor bindingCommunicator = mock(NetconfBindingAccessor.class); - NodeId nodeId = new NodeId(NODEIDSTRING); - when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); - when(bindingCommunicator.getNodeId()).thenReturn(nodeId); - - capabilities = mock(Capabilities.class); - accessor = mock(NetconfBindingAccessor.class); - serviceProvider = mock(DeviceManagerServiceProvider.class); - - when(accessor.getCapabilites()).thenReturn(capabilities); - when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingCommunicator)); - when(serviceProvider.getDataProvider()).thenReturn(null); - - - } - - //@Test - public void testCreateORANHWComponent() throws Exception { - when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); - assertTrue((factory.create(accessor, serviceProvider)).isPresent()); - } - - //@Test - public void testCreateNone() throws Exception { - when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(false); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); - assertTrue(!(factory.create(accessor, serviceProvider).isPresent())); - } - - //@After - public void cleanUp() throws Exception { - - } -} - diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanRegistrationToVESpnfRegistration.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanRegistrationToVESpnfRegistration.java deleted file mode 100644 index d2cf94807..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanRegistrationToVESpnfRegistration.java +++ /dev/null @@ -1,88 +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.test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.math.BigDecimal; -import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanRegistrationToVESpnfRegistrationMapper; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; -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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.augmented.optional.fields.IgnoreMissingSchemaSources; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.NonModuleCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.OdlHelloMessageCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.YangModuleCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.ClusteredConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.PassThrough; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.UnavailableCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.common.Uint16; -import org.opendaylight.yangtools.yang.common.Uint32; - -@RunWith(MockitoJUnitRunner.class) -public class TestORanRegistrationToVESpnfRegistration { - - @Mock - NetconfAccessor netconfAccessor; - @Mock - VESCollectorService vesCollectorService; - @Mock - VESCollectorCfgService vesCfgService; - - private final int SEQUENCE_NO = 10; - - @Test - public void test() { - String dateTimeString = "2020-02-05T12:30:45.283Z"; - String name = "Slot-0"; - - NetconfNode testNetconfNode = mock(NetconfNode.class); - when(testNetconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("10.10.10.10")))); - - when(netconfAccessor.getNodeId()).thenReturn(new NodeId("nSky")); - when(netconfAccessor.getNetconfNode()).thenReturn(testNetconfNode); - when(vesCollectorService.getConfig()).thenReturn(vesCfgService); - when(vesCfgService.getReportingEntityName()).thenReturn("SDN-R"); - Component testComponent = ComponentHelper.get(name, dateTimeString); - - ORanRegistrationToVESpnfRegistrationMapper mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor, vesCollectorService, testComponent); - mapper.mapCommonEventHeader(SEQUENCE_NO); - mapper.mapPNFRegistrationFields(); - } - -} diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanToInternalDataModel.java deleted file mode 100644 index 531b2f939..000000000 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/test/TestORanToInternalDataModel.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * 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.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.function.IntConsumer; -import java.util.stream.IntStream; -import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanToInternalDataModel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.common.Uint32; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestORanToInternalDataModel { - - private static final Logger LOG = LoggerFactory.getLogger(TestORanToInternalDataModel.class); - - NodeId nodeId = new NodeId("ORan-1000"); - - @Test - public void testInventory() { - String dateTimeString = "2020-02-05T12:30:45.283Z"; - String name = "Slot-0"; - - Component testComponent = ComponentHelper.get(name, dateTimeString); - Optional oInventory = ORanToInternalDataModel.getInternalEquipment(nodeId, testComponent, 0); - - assertTrue(oInventory.isPresent()); - Inventory inventory = oInventory.get(); - assertEquals(name, inventory.getUuid()); - assertEquals(dateTimeString, inventory.getDate()); - assertEquals(nodeId.getValue(), inventory.getNodeId()); - } - - @Test - public void testInventoryList() throws IOException, ClassNotFoundException { - List componentList = ComponentHelper.getComponentList("/Device-ietf-hardware-Output.json"); - List inventoryList = ORanToInternalDataModel.getInventoryList(nodeId, componentList); - //componentList.forEach(System.out::println); - assertEquals("All elements", 27, inventoryList.size()); - assertEquals("Fully parseable", componentList.size(), inventoryList.size()); - assertEquals("Treelevel always there", 0, - inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count()); - listAsTree(inventoryList); - } - - private void listAsTree(List inventoryList) { - //Walk through complete list and print parameters - IntConsumer action = level -> IntStream.range(0, inventoryList.size()) - .filter(idx -> inventoryList.get(idx).getTreeLevel().intValue() == level) - .forEach(idx2 -> printElements(idx2, level, inventoryList.get(idx2))); - //Walk trough 10 levels - IntStream.range(0, 10) - .forEach(action); - } - - private void printElements(int idx2, int level, Inventory inventory) { - System.out.println(level + ": " + inventory.getParentUuid() + " " - + inventory.getUuid()); - } - - @SuppressWarnings("unused") - private boolean compareLevel(int idx, List componentList, List inventoryList) { - @Nullable - Integer relPos = componentList.get(idx).getParentRelPos(); - @Nullable - Uint32 treeLevel = inventoryList.get(idx).getTreeLevel(); - LOG.warn("Treelevel relPos: {} treeLevel: {}", relPos, treeLevel); - if (relPos != null && treeLevel != null) { - return relPos == treeLevel.intValue(); - } - return false; - } -} -- cgit 1.2.3-korg