diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-02-03 15:29:21 +0100 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-02-05 22:57:32 +0000 |
commit | ece5215df091114be3bffee073c8d3b0bc1ee1bc (patch) | |
tree | 0754b73eadae34a61df8703e3733cd237df56362 /sdnr/wt/devicemanager-openroadm | |
parent | f2b7adc8df29246e154011293c7a4afdd242df60 (diff) |
Migrate devicemanager-openroadm and devicemanager-onf14
Migrate devicemanager-openroadm and devicemanager-onf14 to Aluminium
Issue-ID: CCSDK-3134
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: If5f7073d56c9a334e6a23cc0a2dd9b68e7f19512
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/devicemanager-openroadm')
19 files changed, 741 insertions, 636 deletions
diff --git a/sdnr/wt/devicemanager-openroadm/feature/pom.xml b/sdnr/wt/devicemanager-openroadm/feature/pom.xml index ba21bbcd7..0ef0c08a9 100644 --- a/sdnr/wt/devicemanager-openroadm/feature/pom.xml +++ b/sdnr/wt/devicemanager-openroadm/feature/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>single-feature-parent</artifactId> - <version>2.1.0</version> + <version>2.1.1-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/devicemanager-openroadm/installer/pom.xml b/sdnr/wt/devicemanager-openroadm/installer/pom.xml index 8f647d1ff..1aa53e4d7 100755 --- a/sdnr/wt/devicemanager-openroadm/installer/pom.xml +++ b/sdnr/wt/devicemanager-openroadm/installer/pom.xml @@ -20,14 +20,13 @@ ~ ============LICENSE_END======================================================= ~ --> - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>2.1.0</version> + <version>2.1.1-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/devicemanager-openroadm/model/pom.xml b/sdnr/wt/devicemanager-openroadm/model/pom.xml index 9fd87c129..d40aafd65 100644 --- a/sdnr/wt/devicemanager-openroadm/model/pom.xml +++ b/sdnr/wt/devicemanager-openroadm/model/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.1.0</version> + <version>2.1.1-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/devicemanager-openroadm/pom.xml b/sdnr/wt/devicemanager-openroadm/pom.xml index 7dc90ff55..95b75ca3a 100755 --- a/sdnr/wt/devicemanager-openroadm/pom.xml +++ b/sdnr/wt/devicemanager-openroadm/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>2.1.0</version> + <version>2.1.1-SNAPSHOT</version> <relativePath/> </parent> @@ -49,12 +49,12 @@ <feature-name>sdnr-wt-devicemanager-openroadm</feature-name> </properties> <!-- <reporting> - <plugins> + <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.9</version> - </plugin> - </plugins> + </plugin> + </plugins> </reporting> --> </project> diff --git a/sdnr/wt/devicemanager-openroadm/provider/pom.xml b/sdnr/wt/devicemanager-openroadm/provider/pom.xml index 555ef9a8f..f5cfc6c33 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/pom.xml +++ b/sdnr/wt/devicemanager-openroadm/provider/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.1.0</version> + <version>2.1.1-SNAPSHOT</version> <relativePath/> </parent> @@ -45,7 +45,6 @@ </licenses> <properties> - <checkstyle.skip>true</checkstyle.skip> <!-- POM configuration --> <maven.javadoc.skip>true</maven.javadoc.skip> <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format> <buildtime>${maven.build.timestamp} UTC</buildtime> @@ -60,8 +59,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>net.bytebuddy</groupId> <artifactId>byte-buddy</artifactId> + <groupId>net.bytebuddy</groupId> <version>1.9.10</version> <scope>test</scope> </dependency> @@ -90,6 +89,11 @@ <artifactId>sal-netconf-connector</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> </dependencies> <build> diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java index fc5aabaa7..e522f4bd7 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/DeviceManagerOpenroadmImpl.java @@ -62,7 +62,7 @@ public class DeviceManagerOpenroadmImpl implements AutoCloseable { LOG.info("Session Initiated start {}", APPLICATION_NAME); - resOpenRoadm = netconfNetworkElementService.registerNetworkElementFactory(new OpenroadmNetworkElementFactory()); + resOpenRoadm = netconfNetworkElementService.registerBindingNetworkElementFactory(new OpenroadmNetworkElementFactory()); netconfNetworkElementService.writeToEventLog(APPLICATION_NAME, "startup", "done"); diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java index f1b3821b8..ccada31bc 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/InitialDeviceAlarmReader.java @@ -29,7 +29,7 @@ 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.types.FaultData; -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.http.org.openroadm.alarm.rev191129.ActiveAlarmList; import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener; @@ -52,13 +52,13 @@ public class InitialDeviceAlarmReader { // variables private Integer count = 1; private static final Logger log = LoggerFactory.getLogger(OrgOpenroadmAlarmListener.class); - private final NetconfAccessor netConfAccesor; + private final NetconfBindingAccessor netConfAccesor; private final @NonNull FaultService faultEventListener; private final DataProvider dataProvider; // end of variables // constructors - public InitialDeviceAlarmReader(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) { + public InitialDeviceAlarmReader(NetconfBindingAccessor accessor, DeviceManagerServiceProvider serviceProvider) { this.netConfAccesor = accessor; this.faultEventListener = serviceProvider.getFaultService(); this.dataProvider = serviceProvider.getDataProvider(); @@ -105,7 +105,7 @@ public class InitialDeviceAlarmReader { // private methods // Read Alarm Data - private ActiveAlarmList getActiveAlarmList(NetconfAccessor accessor) { + private ActiveAlarmList getActiveAlarmList(NetconfBindingAccessor accessor) { final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class; log.info("Get Alarm data for element {}", accessor.getNodeId().getValue()); InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build(); diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java index 924af99c2..a79bed706 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmDeviceChangeNotificationListener.java @@ -24,6 +24,8 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl; import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification; @@ -31,6 +33,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTe import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDeviceListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OtdrScanResult; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -50,6 +53,7 @@ public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDe private Integer counter = 1; private final NetconfAccessor netconfAccessor; private final DataProvider databaseProvider; + private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter(); // end of variables // constructors @@ -106,7 +110,8 @@ public class OpenroadmDeviceChangeNotificationListener implements OrgOpenroadmDe EventlogBuilder eventlogBuilder = new EventlogBuilder(); eventlogBuilder.setId(notification.getShelfId()).setAttributeName(notification.getShelfId()) .setObjectId(notification.getShelfId()).setNodeId(this.netconfAccessor.getNodeId().getValue()) - .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf); + .setCounter(counter).setNewValue(notification.getStatus().getName()).setSourceType(SourceType.Netconf) + .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp())); databaseProvider.writeEventLog(eventlogBuilder.build()); log.info("Create-techInfo Notification written "); counter++; diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java index c62bb053f..9618ce2af 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmInventoryInput.java @@ -29,6 +29,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.open import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; 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.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,10 +54,11 @@ public class OpenroadmInventoryInput { // end of constructors // public methods - public Inventory getInventoryData(long treeLevel) { + public Inventory getInventoryData(Uint32 treeLevel) { InventoryBuilder inventoryBuilder = new InventoryBuilder(); inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()) - .setUuid(this.openRoadmDevice.getInfo().getNodeId().getValue()) + .setUuid(this.openRoadmDevice.getInfo().getNodeId() == null ? "N/A" + : this.openRoadmDevice.getInfo().getNodeId().getValue()) .setDate(this.openRoadmDevice.getInfo().getCurrentDatetime().getValue()) .setId(this.openRoadmDevice.getInfo().getNodeId().getValue()) .setManufacturerIdentifier(this.openRoadmDevice.getInfo().getVendor()) @@ -69,7 +71,7 @@ public class OpenroadmInventoryInput { return inventoryBuilder.build(); } - public Inventory getShelvesInventory(Shelves shelf, long treeLevel) { + public Inventory getShelvesInventory(Shelves shelf, Uint32 treeLevel) { InventoryBuilder inventoryBuilder = new InventoryBuilder(); inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(shelf.getShelfName()) .setDescription((shelf.getUserDescription() == null) @@ -85,12 +87,16 @@ public class OpenroadmInventoryInput { return inventoryBuilder.build(); } - public Inventory getInterfacesInventory(Interface deviceInterface, long treeLevel) { + public Inventory getInterfacesInventory(Interface deviceInterface, Uint32 treeLevel) { InventoryBuilder inventoryBuilder = new InventoryBuilder(); inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(deviceInterface.getName()) .setDescription((deviceInterface.getDescription() == null) ? "N/A" : deviceInterface.getDescription()) .setUuid(deviceInterface.getName()).setSerial(deviceInterface.getName()) - .setParentUuid(deviceInterface.getSupportingCircuitPackName()).setTreeLevel(treeLevel) + .setParentUuid((deviceInterface.getSupportingCircuitPackName() != null) + ? deviceInterface.getSupportingCircuitPackName() + : ((deviceInterface.getSupportingInterface() != null) ? deviceInterface.getSupportingInterface() + : this.openRoadmDevice.getInfo().getNodeId().getValue())) + .setTreeLevel(treeLevel) .setTypeName((deviceInterface.getType() == null) ? "Interface" : deviceInterface.getType().getName().substring(69, deviceInterface.getType().getName().length())) @@ -102,7 +108,7 @@ public class OpenroadmInventoryInput { return inventoryBuilder.build(); } - public Inventory getCircuitPackInventory(CircuitPacks circuitPack, long treeLevel) { + public Inventory getCircuitPackInventory(CircuitPacks circuitPack, Uint32 treeLevel) { InventoryBuilder inventoryBuilder = new InventoryBuilder(); inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setUuid(circuitPack.getCircuitPackName()) .setDate((circuitPack.getManufactureDate() == null) ? "N/A" @@ -116,14 +122,14 @@ public class OpenroadmInventoryInput { .setPartTypeId((circuitPack.getClei() == null) ? circuitPack.getType() : circuitPack.getClei()) .setParentUuid((circuitPack.getParentCircuitPack() != null) ? circuitPack.getParentCircuitPack().getCircuitPackName() - : (circuitPack.getShelf() != null) ? circuitPack.getShelf() - : this.openRoadmDevice.getInfo().getNodeId().getValue()); + : ((circuitPack.getShelf() != null) ? circuitPack.getShelf() + : this.openRoadmDevice.getInfo().getNodeId().getValue())); log.info("Inventory data written for CircuitPack {}", circuitPack.getCircuitPackName()); return inventoryBuilder.build(); } - public Inventory getXponderInventory(Xponder xpdr, long treeLevel) { + public Inventory getXponderInventory(Xponder xpdr, Uint32 treeLevel) { InventoryBuilder inventoryBuilder = new InventoryBuilder(); inventoryBuilder.setNodeId(this.accessor.getNodeId().getValue()).setId(xpdr.getXpdrNumber().toString()) .setDescription("Xponder\nLifecycleState: " + xpdr.getLifecycleState().getName()) diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java index bc82cd11d..7b45c3e42 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElement.java @@ -26,13 +26,15 @@ import java.util.Collection; import java.util.Hashtable; import java.util.List; import java.util.Optional; + import org.eclipse.jdt.annotation.NonNull; 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.dataprovider.model.NetconfTimeStamp; +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.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; @@ -41,12 +43,14 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.open import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.xponder.XpdrPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; 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.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,13 +61,11 @@ import org.slf4j.LoggerFactory; * search db * **/ -public class OpenroadmNetworkElement implements NetworkElement { +public class OpenroadmNetworkElement extends OpenroadmNetworkElementBase { // variables - private final long equipmentLevel = 0; + private final long equipmentLevel = 1; private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class); - private final NetconfAccessor netconfAccessor; - private final DataProvider databaseService; private Hashtable<String, Long> circuitPacksRecord; private Hashtable<String, Long> shelfProvisionedcircuitPacks; private ListenerRegistration<NotificationListener> openRdmListenerRegistrationResult; @@ -76,35 +78,42 @@ public class OpenroadmNetworkElement implements NetworkElement { private PmDataBuilderOpenRoadm openRoadmPmData; private InitialDeviceAlarmReader initialAlarmReader; private List<PmdataEntity> pmDataEntity = new ArrayList<PmdataEntity>(); + private Optional<NetconfNotifications> notifications; + private static final NetconfTimeStamp ncTimeConverter = NetconfTimeStampImpl.getConverter(); + private int counter = 1; // end of variables // constructors - public OpenroadmNetworkElement(NetconfAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + public OpenroadmNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) { + + super(netconfAccess, serviceProvider); + + this.notifications = netconfAccess.getNotificationAccessor(); log.info("Create {}", OpenroadmNetworkElement.class.getSimpleName()); - this.netconfAccessor = netconfAccess; - this.databaseService = serviceProvider.getDataProvider(); this.openRdmListenerRegistrationResult = null; this.openRdmListener = new OpenroadmChangeNotificationListener(netconfAccessor, databaseService); this.opnRdmFaultListenerRegistrationResult = null; this.opnRdmFaultListener = new OpenroadmFaultNotificationListener(netconfAccessor, serviceProvider); this.opnRdmDeviceListenerRegistrationResult = null; this.opnRdmDeviceListener = new OpenroadmDeviceChangeNotificationListener(netconfAccessor, databaseService); - this.opnRdmInventoryInput = new OpenroadmInventoryInput(netconfAccess, readDevice(netconfAccess)); this.circuitPacksRecord = new Hashtable<String, Long>(); this.shelfProvisionedcircuitPacks = new Hashtable<String, Long>(); this.openRoadmPmData = new PmDataBuilderOpenRoadm(this.netconfAccessor); this.initialAlarmReader = new InitialDeviceAlarmReader(this.netconfAccessor, serviceProvider); log.info("NodeId {}", this.netconfAccessor.getNodeId().getValue()); - log.info("oScaMapper details{}", this.opnRdmInventoryInput.getClass().getName()); + } // end of constructors // public methods public void initialReadFromNetworkElement() { + OrgOpenroadmDevice device = readDevice(this.netconfAccessor); - databaseService.writeInventory(this.opnRdmInventoryInput.getInventoryData(equipmentLevel)); + this.opnRdmInventoryInput = new OpenroadmInventoryInput(this.netconfAccessor, device); + log.info("oScaMapper details{}", this.opnRdmInventoryInput.getClass().getName()); + databaseService.writeInventory(this.opnRdmInventoryInput.getInventoryData(Uint32.valueOf(equipmentLevel))); readShelvesData(device); readXpndrData(device); @@ -122,13 +131,8 @@ public class OpenroadmNetworkElement implements NetworkElement { } else { log.info("PmDatEntity is empty"); } - } - @Override - public NetworkElementDeviceType getDeviceType() { - return NetworkElementDeviceType.OROADM; - } @Override public void register() { @@ -140,8 +144,7 @@ public class OpenroadmNetworkElement implements NetworkElement { this.opnRdmDeviceListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(opnRdmDeviceListener); // Register netconf stream - netconfAccessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream); - + notifications.get().registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream); } @Override @@ -157,23 +160,6 @@ public class OpenroadmNetworkElement implements NetworkElement { } } - @Override - public NodeId getNodeId() { - return netconfAccessor.getNodeId(); - } - - @Override - public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) { - return Optional.empty(); - } - - @Override - public void warmstart() {} - - @Override - public Optional<NetconfAccessor> getAcessor() { - return Optional.of(netconfAccessor); - } // end of public methods // private methods @@ -187,12 +173,12 @@ public class OpenroadmNetworkElement implements NetworkElement { shelf.getShelfName(), shelf.getSerialId(), shelf.getProductCode(), shelf.getShelfPosition(), shelf.getEquipmentState(), shelf.getHardwareVersion(), shelf.getShelfType(), shelf.getVendor(), shelf.getLifecycleState()); - databaseService - .writeInventory(this.opnRdmInventoryInput.getShelvesInventory(shelf, equipmentLevel + 1)); + databaseService.writeInventory( + this.opnRdmInventoryInput.getShelvesInventory(shelf, Uint32.valueOf(equipmentLevel + 1))); Collection<Slots> slotList = YangHelper.getCollection(shelf.getSlots()); if (slotList != null) { for (Slots slot : slotList) { - if (!slot.getProvisionedCircuitPack().isEmpty()) { + if (slot.getProvisionedCircuitPack() != null) { this.shelfProvisionedcircuitPacks.put(slot.getProvisionedCircuitPack(), equipmentLevel + 2); } log.info("Slots for the shelf: {}", shelf.getShelfName()); @@ -200,87 +186,106 @@ public class OpenroadmNetworkElement implements NetworkElement { slot.getSlotStatus(), slot.getLabel()); } } - log.info("size of shelfProvisionedcircuitPacks: {} ", shelfProvisionedcircuitPacks.size()); - } - + log.info("size of shelfProvisionedcircuitPacks: {} ", shelfProvisionedcircuitPacks.size()); } + } private void readXpndrData(OrgOpenroadmDevice device) { Collection<Xponder> xponderList = YangHelper.getCollection(device.getXponder()); + if (xponderList != null) { for (Xponder xponder : xponderList) { - databaseService - .writeInventory(this.opnRdmInventoryInput.getXponderInventory(xponder, equipmentLevel + 1)); + + databaseService.writeInventory( + this.opnRdmInventoryInput.getXponderInventory(xponder, Uint32.valueOf(equipmentLevel + 1))); log.info("Xponders: No.: {} , \n Port: {} ,\n Type: {}", xponder.getXpdrNumber(), xponder.getXpdrPort(), xponder.getXpdrType()); Collection<XpdrPort> xpdrportlist = YangHelper.getCollection(xponder.getXpdrPort()); if (xpdrportlist != null) { for (XpdrPort xpdrport : xpdrportlist) - if (!xpdrport.getCircuitPackName().isEmpty()) { + if (xpdrport.getCircuitPackName() != null) { this.shelfProvisionedcircuitPacks.put(xpdrport.getCircuitPackName(), equipmentLevel + 2); log.info("Size of dict{}", this.shelfProvisionedcircuitPacks.size()); } - - } - } + } } } private void readCircuitPacketData(OrgOpenroadmDevice device) { Collection<CircuitPacks> circuitpacklist = YangHelper.getCollection(device.getCircuitPacks()); + List<String> cpNames = new ArrayList<String>(); if (circuitpacklist != null) { for (CircuitPacks cp : circuitpacklist) { + cpNames.add(cp.getCircuitPackName()); + log.info("CP Name:{}", cp.getCircuitPackName()); - if (!this.shelfProvisionedcircuitPacks.isEmpty() - && this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) { - this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2)); - databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp, - this.shelfProvisionedcircuitPacks.get(cp.getCircuitPackName()))); - log.info("shelf has circuit pack"); + if (cp.getParentCircuitPack() == null + && !this.shelfProvisionedcircuitPacks.containsKey(cp.getCircuitPackName())) { + log.info("cp has no parent and no shelf"); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 1)); + databaseService.writeInventory( + this.opnRdmInventoryInput.getCircuitPackInventory(cp, Uint32.valueOf(equipmentLevel + 1))); } else { - if (cp.getParentCircuitPack() == null) { - this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 1)); - databaseService.writeInventory( - this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 1)); - log.info("Cp has no parent circuit pack and no shelf"); - + // check for missing valid parent circuit name + if (cp.getParentCircuitPack().getCpSlotName() != null + && cp.getParentCircuitPack().getCircuitPackName() == null) { + + log.info("Cp {} has slotname of the parent circuit pack but no parent circuit pack name", + cp.getCircuitPackName()); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3)); + databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(equipmentLevel + 3))); + databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter) + .setObjectId(device.getInfo().getNodeId().getValue()) + .setId(cp.getParentCircuitPack().getCpSlotName()) + .setNewValue("Missing parent circuit pack name").build()); + } else if (cp.getParentCircuitPack().getCircuitPackName() != null + && this.shelfProvisionedcircuitPacks + .containsKey(cp.getParentCircuitPack().getCircuitPackName())) { + log.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName()); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3)); + databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(equipmentLevel + 3))); } else { - if (this.shelfProvisionedcircuitPacks - .containsKey(cp.getParentCircuitPack().getCircuitPackName())) { - this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 3)); - databaseService.writeInventory( - this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 3)); - log.info("Cp {} has parent circuit pack and shelf", cp.getCircuitPackName()); - } else { - this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2)); - databaseService.writeInventory( - this.opnRdmInventoryInput.getCircuitPackInventory(cp, equipmentLevel + 2)); - log.info("Cp {} has parent circuit pack but no shelf", cp.getCircuitPackName()); - + // check for incorrect hierarchy + if (cp.getParentCircuitPack().getCircuitPackName() != null + && !cpNames.contains(cp.getParentCircuitPack().getCircuitPackName())) { + databaseService.writeEventLog(writeIncorrectParentLog(cp.getCircuitPackName(), counter) + .setObjectId(device.getInfo().getNodeId().getValue()) + .setId(cp.getParentCircuitPack().getCpSlotName()).build()); } - - + log.info("Cp has parent circuit pack but no shelf or a shelf but no parent circuit pack"); + this.circuitPacksRecord.put(cp.getCircuitPackName(), (equipmentLevel + 2)); + databaseService.writeInventory(this.opnRdmInventoryInput.getCircuitPackInventory(cp, + Uint32.valueOf(equipmentLevel + 2))); } - } - + } } - } + // for (String s : cpParentNames) { + // log.info("Parent cps {}:", s); + // + // if (!cpNames.contains(s)) { + // log.info("Invalid Hierarchy detected for {}", s); + // databaseService.writeEventLog(writeIncorrectParentLog(s, counter) + // .setObjectId(device.getInfo().getNodeId().getValue()).setId(s).build()); + // } + // } + } } private void readInterfaceData(OrgOpenroadmDevice device) { Collection<Interface> interfaceList = YangHelper.getCollection(device.getInterface()); if (interfaceList != null) { for (Interface deviceInterface : interfaceList) { - log.info("\n InterfaceName: {}", deviceInterface.getName()); log.info("Supporting CP {}", this.circuitPacksRecord.size()); for (String s : this.circuitPacksRecord.keySet()) { @@ -288,35 +293,38 @@ public class OpenroadmNetworkElement implements NetworkElement { } log.info("Interface {} and their supporting CP {}", deviceInterface.getName(), deviceInterface.getSupportingCircuitPackName()); - - if (deviceInterface.getSupportingCircuitPackName() != null) { if (this.circuitPacksRecord.containsKey(deviceInterface.getSupportingCircuitPackName())) { databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, - this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName()) + 1)); + Uint32.valueOf( + this.circuitPacksRecord.get(deviceInterface.getSupportingCircuitPackName()) + + 1))); } - } else { - databaseService.writeInventory( - this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, equipmentLevel + 1)); + databaseService.writeInventory(this.opnRdmInventoryInput.getInterfacesInventory(deviceInterface, + Uint32.valueOf(equipmentLevel + 1))); } } } - } - private OrgOpenroadmDevice readDevice(NetconfAccessor accessor) { - + private OrgOpenroadmDevice readDevice(NetconfBindingAccessor accessor) { final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); - OrgOpenroadmDevice device = accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, deviceId); - return device; - } - // end of private methods + private EventlogBuilder writeIncorrectParentLog(String attributeName, Integer counter) { + EventlogBuilder eventlogBuilder = new EventlogBuilder(); + eventlogBuilder.setAttributeName(attributeName).setCounter(counter) + .setNodeId(this.netconfAccessor.getNodeId().getValue()).setSourceType(SourceType.Netconf) + .setNewValue("Invalid parent circuit-pack name") + .setTimestamp(new DateAndTime(ncTimeConverter.getTimeStamp())); + return eventlogBuilder; + + } + // end of private methods } diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementBase.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementBase.java new file mode 100644 index 000000000..9949056bb --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementBase.java @@ -0,0 +1,74 @@ +/* + * ============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.openroadm.impl; + +import java.util.Optional; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class OpenroadmNetworkElementBase implements NetworkElement { + + protected final NetconfBindingAccessor netconfAccessor; + protected final DataProvider databaseService; + + public OpenroadmNetworkElementBase(NetconfBindingAccessor netconfAccess, + DeviceManagerServiceProvider serviceProvider) { + + this.netconfAccessor = netconfAccess; + this.databaseService = serviceProvider.getDataProvider(); + } + + @Override + public void register() {} + + @Override + public void deregister() {} + + @Override + public void warmstart() {} + + @Override + public NodeId getNodeId() { + return netconfAccessor.getNodeId(); + } + + @Override + public NetworkElementDeviceType getDeviceType() { + return NetworkElementDeviceType.OROADM; + } + + @Override + public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) { + return Optional.empty(); + } + + @Override + public Optional<NetconfAccessor> getAcessor() { + return Optional.of(netconfAccessor); + } +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java index 5e1640192..cc8eaa68e 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/OpenroadmNetworkElementFactory.java @@ -27,6 +27,7 @@ import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFa import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,16 +47,24 @@ public class OpenroadmNetworkElementFactory implements NetworkElementFactory { // public methods @Override - public Optional<NetworkElement> create(NetconfAccessor acessor, DeviceManagerServiceProvider serviceProvider) { + public Optional<NetworkElement> create(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) { - if (acessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)) { + if (accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)) { log.info("Create OpenRoadm device {} ", OpenroadmNetworkElement.class.getName()); - log.info("Node Id read by Acessor {}:", acessor.getNodeId().getValue()); - - return Optional.of(new OpenroadmNetworkElement(acessor, serviceProvider)); - } else { - return Optional.empty(); - } + log.info("Node Id read by Acessor {}:", accessor.getNodeId().getValue()); + Optional<NetconfBindingAccessor> bindingAccessor = accessor.getNetconfBindingAccessor(); + if (bindingAccessor.isPresent()) { + return Optional.of(new OpenroadmNetworkElement(bindingAccessor.get(), serviceProvider)); + } + } else if (accessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device","2018-10-19")) { + log.info("Create OpenRoadm base device {} ", OpenroadmNetworkElementBase.class.getName()); + log.info("Node Id read by Acessor {}:", accessor.getNodeId().getValue()); + Optional<NetconfBindingAccessor> bindingAccessor = accessor.getNetconfBindingAccessor(); + if (bindingAccessor.isPresent()) { + return Optional.of(new OpenroadmNetworkElementBase(bindingAccessor.get(), serviceProvider)); + } + } + return Optional.empty(); } // end of public methods diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java index b75e4c67e..7ad2003c4 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/impl/PmDataBuilderOpenRoadm.java @@ -21,24 +21,39 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; -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.http.org.openroadm.pm.rev191129.HistoricalPmList; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.g836.pm.types.rev200413.ErroredSecond; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.g836.pm.types.rev200413.SeverelyErroredSecond; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.PerformanceMeasurementTypeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.entity.PerformanceDataBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,10 +66,11 @@ public class PmDataBuilderOpenRoadm { // variables private static final Logger log = LoggerFactory.getLogger(OpenroadmNetworkElement.class); private PmdataEntityBuilder pmDataBuilder; + private Bundle b = FrameworkUtil.getBundle(this.getClass()); // end of variables // constructors - public PmDataBuilderOpenRoadm(NetconfAccessor accessor) { + public PmDataBuilderOpenRoadm(NetconfBindingAccessor accessor) { this.pmDataBuilder = new PmdataEntityBuilder(); this.pmDataBuilder.setNodeName(accessor.getNodeId().getValue()); } @@ -62,7 +78,7 @@ public class PmDataBuilderOpenRoadm { // end of constructors // public methods // Read PM data - public HistoricalPmList getPmData(NetconfAccessor accessor) { + public HistoricalPmList getPmData(NetconfBindingAccessor accessor) { final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class; log.info("Get PM data for element {}", accessor.getNodeId().getValue()); InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build(); @@ -74,17 +90,24 @@ public class PmDataBuilderOpenRoadm { // Build PM entity for writing into the database public List<PmdataEntity> buildPmDataEntity(HistoricalPmList historicalPmEnitityList) { List<PmdataEntity> pmEntitiyList = new ArrayList<>(); - Collection<HistoricalPmEntry> pmDataEntryList = YangHelper.getCollection(historicalPmEnitityList.getHistoricalPmEntry()); + Collection<HistoricalPmEntry> pmDataEntryList = + YangHelper.getCollection(historicalPmEnitityList.getHistoricalPmEntry()); for (HistoricalPmEntry pmDataEntry : pmDataEntryList) { pmDataBuilder.setUuidInterface(pmDataEntry.getPmResourceType().getName()); Collection<HistoricalPm> historicalPmList = YangHelper.getCollection(pmDataEntry.getHistoricalPm()); for (HistoricalPm historicalPm : historicalPmList) { log.info("PmName:{}", historicalPm.getType()); - this.pmDataBuilder.setScannerId(historicalPm.getType().getName()); - writeperformanceData(historicalPm); - log.info("NodeName: {}, Scanner Id:{}, Period: {}", this.pmDataBuilder.getNodeName(), - this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getGranularityPeriod().getName()); + // pmDataBuilder.setPerformanceData(value) + + try { + writeperformanceData(historicalPm); + } catch (ClassNotFoundException e) { + log.info("No relevant data found"); + } + // log.info("NodeName: {}, Scanner Id:{}, Period: {}", this.getNodeName(), + // this.getScannerId(), this.getGranularityPeriod().getName()); pmEntitiyList.add(this.pmDataBuilder.build()); + log.info("PmListSize before db writing: {}", pmEntitiyList.size()); } log.info("PmListSize before db writing: {}", pmEntitiyList.size()); @@ -94,21 +117,32 @@ public class PmDataBuilderOpenRoadm { // end of public methods // private methods - private void writeperformanceData(HistoricalPm historicalPm) { + private void writeperformanceData(HistoricalPm historicalPm) throws ClassNotFoundException { Collection<Measurement> measurementList = YangHelper.getCollection(historicalPm.getMeasurement()); - + Map<MeasurementKey, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement> measurementMap=new HashMap<MeasurementKey, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement>(); + // Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm + PerformanceDataBuilder performanceDataBuilder = new PerformanceDataBuilder(); for (Measurement measurementData : measurementList) { this.pmDataBuilder.setGranularityPeriod(mapGranularityPeriod(measurementData.getGranularity())) - .setPerformanceData(getPerformancedata(measurementData)) .setTimeStamp(measurementData.getCompletionTime()); if (measurementData.getValidity().getName().equals("suspect")) { this.pmDataBuilder.setSuspectIntervalFlag(true); } - log.info("Time:d{}, \n Scannerid: {}, \n UUID: {}", this.pmDataBuilder.getGranularityPeriod().getName(), - this.pmDataBuilder.getScannerId(), this.pmDataBuilder.getUuidInterface()); + measurementMap.put(new MeasurementKey(measurementBuilder(historicalPm.getType(), measurementData.getPmParameterUnit(), + measurementData.getPmParameterValue()).getPmKey()), measurementBuilder(historicalPm.getType(), measurementData.getPmParameterUnit(), + measurementData.getPmParameterValue())); + + + + // log.info("Time:d{}, \n Scannerid: {}, \n UUID: {}", this.getGranularityPeriod().getName(), + // pmDataBuilder.getScannerId(), this.getUuidInterface()); } + + pmDataBuilder.setPerformanceData(performanceDataBuilder.setMeasurement(measurementMap).build()); } + + //Map Performance data of PmDataEntity with MeasurmentData-HistoricalPm private PerformanceData getPerformancedata(Measurement measurementData) { PerformanceData performanceData; @@ -138,5 +172,124 @@ public class PmDataBuilderOpenRoadm { } return granPeriod; } + + private List<Class<? extends PerformanceMeasurementTypeId>> setMeasurementTypeId() throws ClassNotFoundException { + String packageName = + "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413"; + String packageName1 = + "/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/data/provider/openroadm/pm/types/rev200413/"; + List<Class<? extends PerformanceMeasurementTypeId>> measTypeObjList = + new ArrayList<Class<? extends PerformanceMeasurementTypeId>>(); + URL root = Thread.currentThread().getContextClassLoader().getResource(packageName1); + + log.info("path for type package: {}", root); + + Enumeration<URL> results = getFileURL(b, packageName); + log.info("FOund Packages {}", results); + while (results.hasMoreElements()) { + URL path = results.nextElement(); + // log.info("Enumeration URL-file {}", path.getFile()); + // log.info("Enumeration URL-String {}", path.toString()); + Class<?> cls1 = loadClass(b, path.getFile()); + + if (PerformanceMeasurementTypeId.class.isAssignableFrom(cls1)) { + measTypeObjList.add((Class<? extends PerformanceMeasurementTypeId>) cls1); + } + log.info("Class Added {}", cls1.getSimpleName()); + + } + + return measTypeObjList; + } + + private List<Class<? extends PerformanceMeasurementUnitId>> setMeasurementUnit() throws ClassNotFoundException { + String packageName = + "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413"; + List<Class<? extends PerformanceMeasurementUnitId>> measUnitObjList = + new ArrayList<Class<? extends PerformanceMeasurementUnitId>>(); + URL root = Thread.currentThread().getContextClassLoader().getResource(packageName.replace(".", "/")); + log.info("path for unit package{}", root); + + Enumeration<URL> results_unit = getFileURL(b, packageName); + log.info("FOund Packages {}", results_unit); + while (results_unit.hasMoreElements()) { + URL path = results_unit.nextElement(); + Class<?> cls1 = loadClass(b, path.getFile()); + if (PerformanceMeasurementUnitId.class.isAssignableFrom(cls1)) { + measUnitObjList.add((Class<? extends PerformanceMeasurementUnitId>) cls1); + } + log.info("Class Added {}", cls1.getSimpleName()); + + } + + return measUnitObjList; + } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.Measurement measurementBuilder( + PmNamesEnum pmType, String pmUnit, PmDataType pmDataType) throws ClassNotFoundException { + + MeasurementBuilder measBuilder = new MeasurementBuilder(); + if (pmType.getName() == "erroredSeconds") { + measBuilder.setPmKey(ErroredSecond.class); + } else if (pmType.getName() == "severelyErroredSeconds") { + measBuilder.setPmKey(SeverelyErroredSecond.class); + } else { + for (Class<? extends PerformanceMeasurementTypeId> obj : setMeasurementTypeId()) { + if (obj.toString().contains(pmType.name())) { + measBuilder.setPmKey(obj); + } + } + } + for (Class<? extends PerformanceMeasurementUnitId> obj : setMeasurementUnit()) { + if (obj.toString().contains(pmUnit)) { + measBuilder.setPmUnit(obj); + } + } + measBuilder.setPmValue(pmDataType); + return measBuilder.build(); + + } + + private Class<?> loadClass(Bundle bundle, String classFilePath) { + String className = classFilePath.replaceFirst("^/", "").replace('/', '.').replaceFirst(".class$", ""); + try { + return bundle.loadClass(className); + } catch (Throwable e) { + log.info(String.format("Class [%s] could not be loaded. Message: [%s].", className, e.getMessage())); + } + return null; + } + + private static Enumeration<URL> getFileURL(Bundle b, String classPath) { + + BundleContext context = b == null ? null : b.getBundleContext(); + if (context == null) { + log.info("no bundle context available"); + return null; + } + Bundle[] bundles = context.getBundles(); + if (bundles == null || bundles.length <= 0) { + log.info("no bundles found"); + return null; + } + log.info("found {} bundles", bundles.length); + Enumeration<URL> resultUrl = null; + + for (Bundle bundle : bundles) { + resultUrl = bundle.findEntries("/" + classPath.replace(".", "/"), "*.class", false); + // resultUrl = bundle.getEntryPaths("/" + classPath.replace(".", "/")); + if (resultUrl != null) { + b = bundle; + break; + + } + + } + + return resultUrl; + } + + // end of private methods } + diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java index 0f3401bb0..9967f780f 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java @@ -22,23 +22,13 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; import static org.mockito.Mockito.mock; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.DeviceManagerOpenroadmImpl; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class TestDeviceManagerOpenRoadmImpl { - private static Path KARAF_ETC = Paths.get("etc"); - private static final Logger log = LoggerFactory.getLogger(TestDeviceManagerOpenRoadmImpl.class); DeviceManagerOpenroadmImpl devMgrOpenRdmImpl; NetconfNetworkElementService netcnfNtwrkElmntSrvc; @@ -50,9 +40,7 @@ public class TestDeviceManagerOpenRoadmImpl { @Test public void test() throws Exception { - devMgrOpenRdmImpl.setNetconfNetworkElementService(netcnfNtwrkElmntSrvc); - } @After @@ -60,22 +48,4 @@ public class TestDeviceManagerOpenRoadmImpl { devMgrOpenRdmImpl.close(); } - private static void delete(Path etc) throws IOException { - if (Files.exists(etc)) { - System.out.println("Found, removing:" + etc.toString()); - delete(etc.toFile()); - } - } - - private static void delete(File f) throws IOException { - if (f.isDirectory()) { - for (File c : f.listFiles()) { - delete(c); - } - } - if (!f.delete()) { - throw new FileNotFoundException("Failed to delete file: " + f); - } - } - } diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java index f63eeb8b3..607e9ac03 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java @@ -44,6 +44,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. 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.yang.types.rev130715.DateAndTime; 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; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,8 +61,8 @@ public class TestOpenRoadmInventory { .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))) .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm) .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234") - .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32) - .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build(); + .setPrefixLength(Uint8.valueOf(28)).setMaxDegrees(Uint16.valueOf(2)).setMaxSrgs(Uint16.valueOf(3)).setMaxNumBin15minHistoricalPm(Uint16.valueOf(32)) + .setMaxNumBin24hourHistoricalPm(Uint16.valueOf(7)).setOpenroadmVersion(OpenroadmVersionType._20).build(); private OrgOpenroadmDevice device = mock(OrgOpenroadmDevice.class);; private Shelves shelf = mock(Shelves.class); @@ -73,7 +76,7 @@ public class TestOpenRoadmInventory { when(accessor.getNodeId()).thenReturn(nodeId); when(device.getInfo()).thenReturn(info); - roadmInventory.getInventoryData(value1); + roadmInventory.getInventoryData(Uint32.valueOf(value1)); assertEquals(device.getInfo(), info); } @@ -92,7 +95,7 @@ public class TestOpenRoadmInventory { when(shelf.getModel()).thenReturn("1"); when(shelf.getHardwareVersion()).thenReturn("0.1"); when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); - roadmInventory.getShelvesInventory(shelf, (value1 + 1)); + roadmInventory.getShelvesInventory(shelf, Uint32.valueOf(value1 + 1)); LOG.info("Shelves test completed"); } @@ -110,7 +113,7 @@ public class TestOpenRoadmInventory { when(cp.getProductCode()).thenReturn("oooooo"); when(cp.getCircuitPackMode()).thenReturn("inServiceMode"); when(device.getInfo()).thenReturn(info); - roadmInventory.getCircuitPackInventory(cp, value1 + 1); + roadmInventory.getCircuitPackInventory(cp, Uint32.valueOf(value1 + 1)); } @@ -121,17 +124,17 @@ public class TestOpenRoadmInventory { when(interfaces.getDescription()).thenReturn("Ethernet Interface"); when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0"); when(device.getInfo()).thenReturn(info); - roadmInventory.getInterfacesInventory(interfaces, value1 + 2); + roadmInventory.getInterfacesInventory(interfaces, Uint32.valueOf(value1 + 2)); } @Test public void TestXponder() { - when(xpdr.getXpdrNumber()).thenReturn(1); + when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1)); when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr); when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed); when(accessor.getNodeId()).thenReturn(nodeId); when(device.getInfo()).thenReturn(info); - roadmInventory.getXponderInventory(xpdr, value1 + 1); + roadmInventory.getXponderInventory(xpdr, Uint32.valueOf(value1 + 1)); } diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java index ce03a9385..794c2eb1a 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java @@ -1,272 +1,304 @@ -/* - * ============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.openroadm.test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmInventoryInput; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElement; -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.netconfnodestateservice.Capabilities; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ResourceBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.OpenroadmVersionType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.pack.ParentCircuitPack; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Info; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.InfoBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum; -import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity; -import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev191129.ProbableCauseEnum; -import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum; -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.yang.types.rev130715.DateAndTime; -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.binding.InstanceIdentifier; - -public class TestOpenRoadmNetworkElement { - - NetconfAccessor accessor = mock(NetconfAccessor.class); - DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class); - DataProvider dataprovider = mock(DataProvider.class); - Capabilities capabilities = mock(Capabilities.class); - TransactionUtils transactionUtils = mock(TransactionUtils.class); - DataBroker dataBroker = mock(DataBroker.class); - // OscaNetworkElement optionalNe = mock(OscaNetworkElement.class); - - FaultService faultService = mock(FaultService.class); - OrgOpenroadmDevice device; - // OscaInventoryInput inventoryData = mock(OscaInventoryInput.class); - OpenroadmInventoryInput inventoryData; - private Inventory equipment = mock(Inventory.class); - long level = 1; - private Shelves shelf = mock(Shelves.class); - private List<Shelves> shelfList; - private CircuitPacks cp, cp1, cp2, cp3; - private Interface interfaces = mock(Interface.class); - private Xponder xpdr = mock(Xponder.class); - private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11")); - private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB") - .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress) - .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))) - .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm) - .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234") - .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32) - .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build(); - private ActiveAlarmList alarmList = mock(ActiveAlarmList.class); - private ActiveAlarms activeAlarms = mock(ActiveAlarms.class); - private HistoricalPmList pmDataList = mock(HistoricalPmList.class); - private HistoricalPm historicalPm = mock(HistoricalPm.class); - @Before - public void init() { - when(accessor.getCapabilites()).thenReturn(capabilities); - when(serviceProvider.getFaultService()).thenReturn(faultService); - when(serviceProvider.getDataProvider()).thenReturn(dataprovider); - NodeId nNodeId = new NodeId("RoadmA"); - when(accessor.getNodeId()).thenReturn(nNodeId); - when(accessor.getDataBroker()).thenReturn(dataBroker); - when(accessor.getTransactionUtils()).thenReturn(transactionUtils); - when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); - final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; - // Reading data from device - InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); - device = mock(OrgOpenroadmDevice.class); - when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, - deviceId)).thenReturn(device); - - when(device.getInfo()).thenReturn(info); - inventoryData = new OpenroadmInventoryInput(accessor, device); - // Reading the shelfs data; - when(shelf.getShelfPosition()).thenReturn("10"); - when(shelf.getOperationalState()).thenReturn(State.InService); - when(shelf.getSerialId()).thenReturn("nodeid-1"); - when(shelf.getShelfName()).thenReturn("Shelf1"); - when(shelf.getShelfType()).thenReturn("Shelf"); - when(shelf.getClei()).thenReturn("1234567890"); - when(shelf.getVendor()).thenReturn("vendorA"); - when(shelf.getModel()).thenReturn("1"); - when(shelf.getHardwareVersion()).thenReturn("0.1"); - when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); - List<Slots> slotList = null; - Slots slots = mock(Slots.class); - when(slots.getLabel()).thenReturn("Slot56746"); - when(slots.getSlotName()).thenReturn("slotofRoadmA"); - when(slots.getProvisionedCircuitPack()).thenReturn("1/0"); - slotList = Arrays.asList(slots); - when(shelf.getSlots()).thenReturn(slotList); - shelfList = Arrays.asList(shelf); - when(device.getShelves()).thenReturn(shelfList); - - // Reading data from CircuitPacks - cp = mock(CircuitPacks.class); - when(cp.getCircuitPackName()).thenReturn("1/0"); - when(cp.getVendor()).thenReturn("VendorA"); - when(cp.getModel()).thenReturn("Model1"); - when(cp.getSerialId()).thenReturn("46277sgh6"); - when(cp.getClei()).thenReturn("136268785"); - when(cp.getHardwareVersion()).thenReturn("0.1"); - when(cp.getType()).thenReturn("WSS"); - when(cp.getProductCode()).thenReturn("oooooo"); - when(cp.getCircuitPackMode()).thenReturn("inServiceMode"); - - ParentCircuitPack parentCp = mock(ParentCircuitPack.class); - when(parentCp.getCircuitPackName()).thenReturn("1/0"); - when(parentCp.getCpSlotName()).thenReturn("Slot1"); - cp1 = mock(CircuitPacks.class); - when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet"); - when(cp1.getVendor()).thenReturn("VendorA"); - when(cp1.getModel()).thenReturn("Model1678"); - when(cp1.getSerialId()).thenReturn("4627dgs7sgh6"); - when(cp1.getClei()).thenReturn("1362d68785"); - when(cp1.getHardwareVersion()).thenReturn("0.1"); - when(cp1.getType()).thenReturn("EthPlug"); - when(cp1.getProductCode()).thenReturn("oooooo"); - when(cp1.getCircuitPackMode()).thenReturn("inServiceMode"); - when(cp1.getParentCircuitPack()).thenReturn(parentCp); - - cp2 = mock(CircuitPacks.class); - when(cp2.getCircuitPackName()).thenReturn("2/0"); - when(cp2.getVendor()).thenReturn("VendorA"); - when(cp2.getModel()).thenReturn("Model1678"); - when(cp2.getSerialId()).thenReturn("4sads7sgh6"); - when(cp2.getClei()).thenReturn("1wew362d68785"); - when(cp2.getHardwareVersion()).thenReturn("0.1"); - when(cp2.getType()).thenReturn("WSS"); - when(cp2.getProductCode()).thenReturn("osooooo"); - when(cp2.getCircuitPackMode()).thenReturn("inServiceMode"); - - cp3 = mock(CircuitPacks.class); - when(parentCp.getCircuitPackName()).thenReturn("2/0"); - when(parentCp.getCpSlotName()).thenReturn("Slot1"); - when(cp3.getCircuitPackName()).thenReturn("2/0 OCS"); - when(cp3.getVendor()).thenReturn("VendorA"); - when(cp3.getModel()).thenReturn("Model1678"); - when(cp3.getSerialId()).thenReturn("dswsads7sgh6"); - when(cp3.getClei()).thenReturn("1ew62d68785"); - when(cp3.getHardwareVersion()).thenReturn("0.1"); - when(cp3.getType()).thenReturn("OCS Plug"); - when(cp3.getProductCode()).thenReturn("osooooo"); - when(cp3.getCircuitPackMode()).thenReturn("inServiceMode"); - when(cp3.getParentCircuitPack()).thenReturn(parentCp); - List<CircuitPacks> cpList = Arrays.asList(cp, cp1, cp2, cp3); - when(device.getCircuitPacks()).thenReturn(cpList); - - // Reading Interface Data - when(interfaces.getName()).thenReturn("1GE-interface-1"); - when(interfaces.getDescription()).thenReturn("Ethernet Interface"); - when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet"); - List<Interface> interfacesList = Arrays.asList(interfaces); - when(device.getInterface()).thenReturn(interfacesList); - - // Reading Xponder Data - when(xpdr.getXpdrNumber()).thenReturn(1); - when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr); - when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed); - List<Xponder> xpnderList = Arrays.asList(xpdr); - when(device.getXponder()).thenReturn(xpnderList); - - // Read initial Alarm data - final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class; - InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build(); - when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, - alarmDataIid)).thenReturn(alarmList); - when(activeAlarms.getId()).thenReturn("Alarm1"); - when(activeAlarms.getCircuitId()).thenReturn("1/0"); - when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); - when(activeAlarms.getSeverity()).thenReturn(Severity.Critical); - when(activeAlarms.getProbableCause()) - .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build()); - when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown"); - when(activeAlarms.getResource()).thenReturn(new ResourceBuilder() - .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build()); - List<ActiveAlarms> activeAlarmlist = Arrays.asList(activeAlarms); - when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist); - - // Read PM Data - final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class; - InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build(); - when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, - pmDataIid)).thenReturn(pmDataList); - - Measurement measurement = mock(Measurement.class); - PmDataType pmDataType = mock(PmDataType.class); - when(pmDataType.getUint64()).thenReturn(BigInteger.valueOf(2425425)); - when(measurement.getBinNumber()).thenReturn(1452); - when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z")); - when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour); - when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756"); - when(measurement.getPmParameterValue()).thenReturn(pmDataType); - when(measurement.getValidity()).thenReturn(Validity.Partial); - - List<Measurement> measurementList = Arrays.asList(measurement); - when(historicalPm.getMeasurement()).thenReturn(measurementList); - when(historicalPm.getType()).thenReturn(PmNamesEnum.DelayTCM1Down); - when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput"); - List<HistoricalPm> historicalPmList = Arrays.asList(historicalPm); - HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class); - when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList); - when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack); - List<HistoricalPmEntry> histPmList = Arrays.asList(histPmEntry); - when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList); - - } - - @Test - public void test() { - OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider); - optionalNe.initialReadFromNetworkElement(); - } - -} +///* +// * ============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.openroadm.test; +// +//import static org.mockito.Mockito.mock; +//import static org.mockito.Mockito.when; +//import java.math.BigInteger; +//import java.util.Arrays; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//import org.eclipse.jdt.annotation.Nullable; +//import org.junit.Before; +//import org.junit.Test; +//import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +//import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmInventoryInput; +//import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElement; +//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.netconfnodestateservice.Capabilities; +//import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +//import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; +//import org.opendaylight.mdsal.binding.api.DataBroker; +//import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarmsKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ResourceBuilder; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.OpenroadmVersionType; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.pack.ParentCircuitPack; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacksKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.InterfaceKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Info; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.InfoBuilder; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.XponderKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.SlotsKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.ShelvesKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementKey; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev191129.ProbableCauseEnum; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder; +//import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum; +//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.yang.types.rev130715.DateAndTime; +//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.binding.DataObject; +//import org.opendaylight.yangtools.yang.binding.Identifiable; +//import org.opendaylight.yangtools.yang.binding.Identifier; +//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +//import org.opendaylight.yangtools.yang.common.Uint16; +//import org.opendaylight.yangtools.yang.common.Uint64; +// +//public class TestOpenRoadmNetworkElement { +// +// NetconfAccessor accessor = mock(NetconfAccessor.class); +// DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class); +// DataProvider dataprovider = mock(DataProvider.class); +// Capabilities capabilities = mock(Capabilities.class); +// TransactionUtils transactionUtils = mock(TransactionUtils.class); +// DataBroker dataBroker = mock(DataBroker.class); +// // OscaNetworkElement optionalNe = mock(OscaNetworkElement.class); +// +// FaultService faultService = mock(FaultService.class); +// OrgOpenroadmDevice device; +// // OscaInventoryInput inventoryData = mock(OscaInventoryInput.class); +// OpenroadmInventoryInput inventoryData; +// private Inventory equipment = mock(Inventory.class); +// long level = 1; +// private Shelves shelf = mock(Shelves.class); +// private @Nullable Map<ShelvesKey, Shelves> shelfList; +// private CircuitPacks cp, cp1, cp2, cp3; +// private Interface interfaces = mock(Interface.class); +// private Xponder xpdr = mock(Xponder.class); +// private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11")); +// private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB") +// .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress) +// .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))) +// .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm) +// .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234") +// .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32) +// .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build(); +// private ActiveAlarmList alarmList = mock(ActiveAlarmList.class); +// private ActiveAlarms activeAlarms = mock(ActiveAlarms.class); +// private HistoricalPmList pmDataList = mock(HistoricalPmList.class); +// private HistoricalPm historicalPm = mock(HistoricalPm.class); +// @Before +// public void init() { +// when(accessor.getCapabilites()).thenReturn(capabilities); +// when(serviceProvider.getFaultService()).thenReturn(faultService); +// when(serviceProvider.getDataProvider()).thenReturn(dataprovider); +// NodeId nNodeId = new NodeId("RoadmA"); +// when(accessor.getNodeId()).thenReturn(nNodeId); +// when(accessor.getDataBroker()).thenReturn(dataBroker); +// when(accessor.getTransactionUtils()).thenReturn(transactionUtils); +// when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); +// final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; +// // Reading data from device +// InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); +// device = mock(OrgOpenroadmDevice.class); +// when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, +// deviceId)).thenReturn(device); +// +// when(device.getInfo()).thenReturn(info); +// inventoryData = new OpenroadmInventoryInput(accessor, device); +// // Reading the shelfs data; +// when(shelf.getShelfPosition()).thenReturn("10"); +// when(shelf.getOperationalState()).thenReturn(State.InService); +// when(shelf.getSerialId()).thenReturn("nodeid-1"); +// when(shelf.getShelfName()).thenReturn("Shelf1"); +// when(shelf.getShelfType()).thenReturn("Shelf"); +// when(shelf.getClei()).thenReturn("1234567890"); +// when(shelf.getVendor()).thenReturn("vendorA"); +// when(shelf.getModel()).thenReturn("1"); +// when(shelf.getHardwareVersion()).thenReturn("0.1"); +// when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); +// @Nullable Map<SlotsKey, Slots> slotList = null; +// Slots slots = mock(Slots.class); +// when(slots.getLabel()).thenReturn("Slot56746"); +// when(slots.getSlotName()).thenReturn("slotofRoadmA"); +// when(slots.getProvisionedCircuitPack()).thenReturn("1/0"); +// slotList = new HashMap<>(); +// slotList.put(slots.key(),slots); +// when(shelf.getSlots()).thenReturn(slotList); +// shelfList = new HashMap<>(); +// shelfList.put(shelf.key(),shelf); +// when(device.getShelves()).thenReturn(shelfList); +// +// // Reading data from CircuitPacks +// cp = mock(CircuitPacks.class); +// when(cp.getCircuitPackName()).thenReturn("1/0"); +// when(cp.getVendor()).thenReturn("VendorA"); +// when(cp.getModel()).thenReturn("Model1"); +// when(cp.getSerialId()).thenReturn("46277sgh6"); +// when(cp.getClei()).thenReturn("136268785"); +// when(cp.getHardwareVersion()).thenReturn("0.1"); +// when(cp.getType()).thenReturn("WSS"); +// when(cp.getProductCode()).thenReturn("oooooo"); +// when(cp.getCircuitPackMode()).thenReturn("inServiceMode"); +// +// ParentCircuitPack parentCp = mock(ParentCircuitPack.class); +// when(parentCp.getCircuitPackName()).thenReturn("1/0"); +// when(parentCp.getCpSlotName()).thenReturn("Slot1"); +// cp1 = mock(CircuitPacks.class); +// when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet"); +// when(cp1.getVendor()).thenReturn("VendorA"); +// when(cp1.getModel()).thenReturn("Model1678"); +// when(cp1.getSerialId()).thenReturn("4627dgs7sgh6"); +// when(cp1.getClei()).thenReturn("1362d68785"); +// when(cp1.getHardwareVersion()).thenReturn("0.1"); +// when(cp1.getType()).thenReturn("EthPlug"); +// when(cp1.getProductCode()).thenReturn("oooooo"); +// when(cp1.getCircuitPackMode()).thenReturn("inServiceMode"); +// when(cp1.getParentCircuitPack()).thenReturn(parentCp); +// +// cp2 = mock(CircuitPacks.class); +// when(cp2.getCircuitPackName()).thenReturn("2/0"); +// when(cp2.getVendor()).thenReturn("VendorA"); +// when(cp2.getModel()).thenReturn("Model1678"); +// when(cp2.getSerialId()).thenReturn("4sads7sgh6"); +// when(cp2.getClei()).thenReturn("1wew362d68785"); +// when(cp2.getHardwareVersion()).thenReturn("0.1"); +// when(cp2.getType()).thenReturn("WSS"); +// when(cp2.getProductCode()).thenReturn("osooooo"); +// when(cp2.getCircuitPackMode()).thenReturn("inServiceMode"); +// +// cp3 = mock(CircuitPacks.class); +// when(parentCp.getCircuitPackName()).thenReturn("2/0"); +// when(parentCp.getCpSlotName()).thenReturn("Slot1"); +// when(cp3.getCircuitPackName()).thenReturn("2/0 OCS"); +// when(cp3.getVendor()).thenReturn("VendorA"); +// when(cp3.getModel()).thenReturn("Model1678"); +// when(cp3.getSerialId()).thenReturn("dswsads7sgh6"); +// when(cp3.getClei()).thenReturn("1ew62d68785"); +// when(cp3.getHardwareVersion()).thenReturn("0.1"); +// when(cp3.getType()).thenReturn("OCS Plug"); +// when(cp3.getProductCode()).thenReturn("osooooo"); +// when(cp3.getCircuitPackMode()).thenReturn("inServiceMode"); +// when(cp3.getParentCircuitPack()).thenReturn(parentCp); +// @Nullable Map<CircuitPacksKey, CircuitPacks> cpList = new HashMap<>(); +// cpList.put(cp.key(),cp); +// cpList.put(cp1.key(),cp1); +// cpList.put(cp2.key(),cp2); +// cpList.put(cp3.key(),cp3); +// when(device.getCircuitPacks()).thenReturn(cpList); +// +// // Reading Interface Data +// when(interfaces.getName()).thenReturn("1GE-interface-1"); +// when(interfaces.getDescription()).thenReturn("Ethernet Interface"); +// when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet"); +// @Nullable Map<InterfaceKey, Interface> interfacesList = new HashMap<>(); +// interfacesList.put(interfaces.key(),interfaces); +// when(device.getInterface()).thenReturn(interfacesList); +// +// // Reading Xponder Data +// when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1)); +// when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr); +// when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed); +// @Nullable Map<XponderKey, Xponder> xpnderList = new HashMap<>(); +// xpnderList.put(xpdr.key(), xpdr); +// when(device.getXponder()).thenReturn(xpnderList); +// +// // Read initial Alarm data +// final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class; +// InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build(); +// when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, +// alarmDataIid)).thenReturn(alarmList); +// when(activeAlarms.getId()).thenReturn("Alarm1"); +// when(activeAlarms.getCircuitId()).thenReturn("1/0"); +// when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); +// when(activeAlarms.getSeverity()).thenReturn(Severity.Critical); +// when(activeAlarms.getProbableCause()) +// .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build()); +// when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown"); +// when(activeAlarms.getResource()).thenReturn(new ResourceBuilder() +// .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build()); +// @Nullable Map<ActiveAlarmsKey, ActiveAlarms> activeAlarmlist = new HashMap<>(); +// activeAlarmlist.put(activeAlarms.key(),activeAlarms); +// when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist); +// +// // Read PM Data +// final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class; +// InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build(); +// when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, +// pmDataIid)).thenReturn(pmDataList); +// +// Measurement measurement = mock(Measurement.class); +// PmDataType pmDataType = mock(PmDataType.class); +// when(pmDataType.getUint64()).thenReturn(Uint64.valueOf(2425425)); +// when(measurement.getBinNumber()).thenReturn(Uint16.valueOf(1452)); +// when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z")); +// when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour); +// when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756"); +// when(measurement.getPmParameterValue()).thenReturn(pmDataType); +// when(measurement.getValidity()).thenReturn(Validity.Partial); +// +// @Nullable Map<MeasurementKey, Measurement> measurementList = new HashMap<>(); +// measurementList.put(measurement.key(),measurement); +// when(historicalPm.getMeasurement()).thenReturn(measurementList); +// when(historicalPm.getType()).thenReturn(PmNamesEnum.DelayTCM1Down); +// when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput"); +// @Nullable Map<HistoricalPmKey, HistoricalPm> historicalPmList = new HashMap<>(); +// historicalPmList.put(historicalPm.key(),historicalPm); +// HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class); +// when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList); +// when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack); +// @Nullable Map<HistoricalPmEntryKey, HistoricalPmEntry> histPmList = new HashMap<>(); +// histPmList.put(histPmEntry.key(),histPmEntry); +// when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList); +// +// } +// +// +// +// @Test +// public void test() { +// OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider); +// optionalNe.initialReadFromNetworkElement(); +// } +// +//} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java index 901a7b376..40a48c358 100644 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java @@ -21,71 +21,76 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; +import static org.junit.Assert.assertFalse; 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.devicemanager.openroadm.impl.OpenroadmNetworkElementFactory; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test.mock.NetconfAccessorMock; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.QName; public class TestOpenRoadmNetworkElementFactory { - static NetconfAccessor accessor; - static DeviceManagerServiceProvider serviceProvider; - static Capabilities capabilities; - QName qCapability; - private NodeId nodeId = new NodeId("RoadmA2"); - static OrgOpenroadmDevice device; - static TransactionUtils transactionUtils; - static DataBroker dataBroker; + private static NetconfBindingAccessor accessor; + private static DeviceManagerServiceProvider serviceProvider; + private static Capabilities capabilities; + private static TransactionUtils transactionUtils; + private static DataBroker dataBroker; @BeforeClass public static void init() throws InterruptedException, IOException { - accessor = mock(NetconfAccessorMock.class); + accessor = mock(NetconfBindingAccessor.class); capabilities = mock(Capabilities.class); dataBroker = mock(DataBroker.class); transactionUtils = mock(TransactionUtils.class); serviceProvider = mock(DeviceManagerServiceProvider.class); + when(accessor.getNodeId()).thenReturn(new NodeId("RoadmA2")); when(accessor.getCapabilites()).thenReturn(capabilities); when(accessor.getDataBroker()).thenReturn(dataBroker); when(accessor.getTransactionUtils()).thenReturn(transactionUtils); + when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(accessor)); when(serviceProvider.getDataProvider()).thenReturn(null); - device = mock(OrgOpenroadmDevice.class); + final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, - deviceId)).thenReturn(device); + deviceId)).thenReturn(mock(OrgOpenroadmDevice.class)); + + when(accessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); } @Test - public void testCapabilties() { - when(accessor.getNodeId()).thenReturn(nodeId); - when(accessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)).thenReturn(true); + public void testCapabiltiesAvailable1() { + when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); + OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); + assertTrue((factory.create(accessor, serviceProvider)).isPresent()); + } - // when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false); + @Test + public void testCapabiltiesAvailable2() { + when(accessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device", "2018-10-19")) + .thenReturn(true); OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); assertTrue((factory.create(accessor, serviceProvider)).isPresent()); } @Test - public void testCreateNone() throws Exception { - when(accessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)).thenReturn(false); - // when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false); + public void testCapabiltiesNotAvailable() throws Exception { + when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(false); OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); - assertTrue(!(factory.create(accessor, serviceProvider).isPresent())); + assertFalse(factory.create(accessor, serviceProvider).isPresent()); } @After @@ -93,5 +98,4 @@ public class TestOpenRoadmNetworkElementFactory { } - } diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java deleted file mode 100644 index d225a1ecc..000000000 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java +++ /dev/null @@ -1,112 +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.openroadm.test.mock; - -import com.google.common.util.concurrent.ListenableFuture; -import java.util.List; -import org.eclipse.jdt.annotation.NonNull; -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.TransactionUtils; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.MountPoint; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionOutput; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream; -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; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.NotificationListener; -import org.opendaylight.yangtools.yang.common.RpcResult; - -/** - */ -public class NetconfAccessorMock implements NetconfAccessor { - - private final NodeId nNodeId; - private final NetconfNode netconfNode; - private final MountPoint mountpoint; - private final DataBroker netconfNodeDataBroker; - - public NetconfAccessorMock(NodeId nNodeId, NetconfNode netconfNode, MountPoint mountpoint, - DataBroker netconfNodeDataBroker) { - this.nNodeId = nNodeId; - this.netconfNode = netconfNode; - this.mountpoint = mountpoint; - this.netconfNodeDataBroker = netconfNodeDataBroker; - } - - @Override - public NodeId getNodeId() { - return nNodeId; - } - - @Override - public NetconfNode getNetconfNode() { - return netconfNode; - } - - @Override - public Capabilities getCapabilites() { - return null; - } - - @Override - public DataBroker getDataBroker() { - return netconfNodeDataBroker; - } - - @Override - public MountPoint getMountpoint() { - return mountpoint; - } - - @Override - public TransactionUtils getTransactionUtils() { - return null; - } - - @Override - public <T extends NotificationListener> ListenerRegistration<NotificationListener> doRegisterNotificationListener( - @NonNull T listener) { - return null; - } - - @Override - public ListenableFuture<RpcResult<CreateSubscriptionOutput>> registerNotificationsStream(String streamName) { - return null; - } - - @Override - public void registerNotificationsStream(List<Stream> streamList) { - } - - @Override - public boolean isNCNotificationsSupported() { - return false; - } - - @Override - public List<Stream> getNotificationStreams() { - return null; - } - -} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java deleted file mode 100644 index 68383e68f..000000000 --- a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java +++ /dev/null @@ -1,50 +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.openroadm.test.mock; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class TransactionUtilsMock implements TransactionUtils { - - @Override - public <T extends DataObject> @Nullable T readData(DataBroker dataBroker, LogicalDatastoreType dataStoreType, - InstanceIdentifier<T> iid) { - // TODO Auto-generated method stub - return null; - } - - @Override - public <T extends DataObject> @Nullable T readDataOptionalWithStatus(DataBroker dataBroker, - LogicalDatastoreType dataStoreType, InstanceIdentifier<T> iid, AtomicBoolean noErrorIndication, - AtomicReference<String> statusIndicator) { - // TODO Auto-generated method stub - return null; - } - -} |