Slight refactor of common PortMappingVersion221 79/104079/3
authorGuillaume Lambert <guillaume.lambert@orange.com>
Fri, 28 Oct 2022 12:52:36 +0000 (14:52 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Sat, 4 Mar 2023 07:32:42 +0000 (08:32 +0100)
JIRA: TRNSPRTPCE-713
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I2c3d62077e1df3519e0c70d31e50b67d98499cad

common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java

index 056c092defc7fa4d65aa9de886f23a3e17a03137..afd966befe42b5173deb43817b36a19e2e22ec6c 100644 (file)
@@ -191,26 +191,39 @@ public class PortMappingVersion221 {
             LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value");
             return false;
         }
-        InstanceIdentifier<Ports> portId = InstanceIdentifier
-            .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
-            .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
-            .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()))
-            .build();
         try {
-            Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
-                portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
-            Interface otsInterface = null;
-            if (oldMapping.getSupportingOts() != null) {
-                InstanceIdentifier<Interface> interfId = InstanceIdentifier
-                    .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
-                    .child(Interface.class, new InterfaceKey(oldMapping.getSupportingOts()))
-                    .build();
-                otsInterface = deviceTransactionManager
-                    .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfId, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT)
-                    .get();
-            }
-            Mapping newMapping = updateMappingObject(nodeId, port, oldMapping, otsInterface);
+            Mapping newMapping = updateMappingObject(
+                nodeId,
+                //port
+                deviceTransactionManager
+                    .getDataFromDevice(
+                        nodeId,
+                        LogicalDatastoreType.OPERATIONAL,
+                        // port Identifier
+                        InstanceIdentifier
+                            .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+                            .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
+                            .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()))
+                            .build(),
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT)
+                    .get(),
+                oldMapping,
+                //otsInterface
+                oldMapping.getSupportingOts() == null
+                    ? null
+                    : deviceTransactionManager
+                        .getDataFromDevice(
+                            nodeId,
+                            LogicalDatastoreType.OPERATIONAL,
+                            //interface Identifier
+                            InstanceIdentifier
+                                .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+                                .child(Interface.class, new InterfaceKey(oldMapping.getSupportingOts()))
+                                .build(),
+                            Timeouts.DEVICE_READ_TIMEOUT,
+                            Timeouts.DEVICE_READ_TIMEOUT_UNIT)
+                        .get()
+                );
             LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG,
                 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
             final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();