[ONOS-7917] Improving device description query in Netconf Device provider
Change-Id: I10ac650e09083fa81e1a54cc8f8e39537dc16cbb
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
index cb61636..98d135f 100644
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -489,11 +489,35 @@
driver.createBehaviour(handler, DeviceDescriptionDiscovery.class);
return getDeviceRepresentation(deviceId, config, deviceDescriptionDiscovery);
} else {
- return emptyDescription(deviceId, config);
+ return existingOrEmptyDescription(deviceId, config);
}
}
- private DeviceDescription emptyDescription(DeviceId deviceId, NetconfDeviceConfig config) {
+ private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config,
+ DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
+
+ DeviceDescription existingOrEmptyDescription = existingOrEmptyDescription(deviceId, config);
+ DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
+ if (newDescription == null) {
+ return existingOrEmptyDescription;
+ }
+ //merging and returning
+ return new DefaultDeviceDescription(newDescription, true,
+ DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(),
+ existingOrEmptyDescription.annotations()));
+ }
+
+ private DeviceDescription existingOrEmptyDescription(DeviceId deviceId, NetconfDeviceConfig config) {
+ Device device = deviceService.getDevice(deviceId);
+
+ if (deviceService.getDevice(deviceId) != null) {
+ //getting the previous description
+ return new DefaultDeviceDescription(device.id().uri(), device.type(),
+ device.manufacturer(), device.hwVersion(),
+ device.swVersion(), device.serialNumber(),
+ device.chassisId(), (SparseAnnotations) device.annotations());
+ }
+
ChassisId cid = new ChassisId();
String ipAddress = config.ip().toString();
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
@@ -507,29 +531,6 @@
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, true, annotations.build());
}
- private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config,
- DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
- Device device = deviceService.getDevice(deviceId);
- //handling first time description creation
- if (deviceService.getDevice(deviceId) == null) {
- return emptyDescription(deviceId, config);
- }
- //getting the old description
- DeviceDescription oldDescription = new DefaultDeviceDescription(device.id().uri(), device.type(),
- device.manufacturer(), device.hwVersion(),
- device.swVersion(), device.serialNumber(),
- device.chassisId(), (SparseAnnotations) device.annotations());
-
- DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
- if (newDescription == null) {
- newDescription = oldDescription;
- }
- //merging and returning
- return new DefaultDeviceDescription(newDescription, true,
- DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(),
- oldDescription.annotations()));
- }
-
private void discoverOrUpdatePorts(DeviceId deviceId) {
retriedPortDiscoveryMap.put(deviceId, new AtomicInteger(0));