Fix deprecated warnings caused by YangTools update
[transportpce.git] / inventory / src / main / java / org / opendaylight / transportpce / inventory / INode221.java
index 4c5ed86e5177a9fffe7f5209e3ceb1f9c220289b..24c6d45a9283207f0e4d4d902b2c1b96ef97055c 100644 (file)
@@ -7,60 +7,80 @@
  */
 package org.opendaylight.transportpce.inventory;
 
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp;
 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareDashString;
 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareEmptyString;
 
-import com.google.common.base.Preconditions;
-
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import javax.sql.DataSource;
-
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.inventory.query.Queries;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlots;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlotsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.attr.RstpBridgePortTable;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.container.rstp.RstpBridgeInstance;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
+@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
+    justification = "TODO review the SQL statement generation process")
 public class INode221 {
     private static final Logger LOG = LoggerFactory.getLogger(INode221.class);
 
@@ -89,7 +109,7 @@ public class INode221 {
         String query = Queries.getQuery().deviceInfoInsert().get();
         LOG.info("Running {} query ", query);
         try (Connection connection = dataSource.getConnection();
-             PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+                PreparedStatement preparedStatement = connection.prepareStatement(query)) {
             Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
             for (int i = 0; i < prepareParameters.length; i++) {
                 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
@@ -150,12 +170,8 @@ public class INode221 {
             persistDevConnectionMap(deviceId, connection);
             LOG.debug("iNode persist Connection Map call complete");
 
-        } catch (SQLException e) {
-            LOG.error(e.getMessage(), e);
-        } catch (InterruptedException e) {
-            LOG.error(e.getMessage(), e);
-        } catch (ExecutionException e) {
-            LOG.error(e.getMessage(), e);
+        } catch (SQLException | InterruptedException | ExecutionException e) {
+            LOG.error("Something wrong when storing node into DB", e);
         }
         return sqlResult;
     }
@@ -174,7 +190,7 @@ public class INode221 {
                 }
             }
         } catch (SQLException e) {
-            LOG.error(e.getMessage(), e);
+            LOG.error("Something wrong when fetching node in DB", e);
         }
         return nodeExists == 0 ? false : true;
     }
@@ -184,12 +200,16 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
-        LOG.info("Shelves size {}", deviceObject.get().getShelves().size());
-        try (Connection connection = dataSource.getConnection()) {
-            Preconditions.checkNotNull(connection);
-            for (int i = 0; i < deviceObject.get().getShelves().size(); i++) {
-                Shelves shelve = deviceObject.get().getShelves().get(i);
+        if (!deviceObject.isPresent()) {
+            LOG.error("No device found in operational datastore for nodeId {}", nodeId);
+            return;
+        }
+        @NonNull
+        Map<ShelvesKey, Shelves> shelvesMap = deviceObject.get().nonnullShelves();
+        LOG.info("Shelves size {}", shelvesMap.size());
+        try (Connection connection = requireNonNull(dataSource.getConnection())) {
+            for (Map.Entry<ShelvesKey, Shelves> entry : shelvesMap.entrySet()) {
+                Shelves shelve = entry.getValue();
                 String shelfName = shelve.getShelfName();
 
                 LOG.info("Getting Shelve Details of {}", shelfName);
@@ -204,7 +224,7 @@ public class INode221 {
                 persistShelves(nodeId, connection, shelve);
             }
         } catch (SQLException e1) {
-            LOG.error(e1.getMessage(), e1);
+            LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
         }
     }
 
@@ -217,12 +237,14 @@ public class INode221 {
             LOG.warn("Device object {} was not found", nodeId);
             return;
         }
-        LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().size());
+        @NonNull
+        Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.get().nonnullCircuitPacks();
+        LOG.info("Circuit pack size {}", circuitPacksMap.size());
 
-        try (Connection connection = dataSource.getConnection()) {
-            Preconditions.checkNotNull(connection);
-            for (int i = 0; i < deviceObject.get().getCircuitPacks().size(); i++) {
-                CircuitPacks cp = deviceObject.get().getCircuitPacks().get(i);
+        try (Connection connection = requireNonNull(dataSource.getConnection())) {
+
+            for (Map.Entry<CircuitPacksKey, CircuitPacks> entry : circuitPacksMap.entrySet()) {
+                CircuitPacks cp = entry.getValue();
 
                 if (cp.getCpSlots() != null) {
                     persistCircuitPacksSlots(nodeId, cp, connection);
@@ -235,7 +257,7 @@ public class INode221 {
                 persistCircuitPacks(nodeId, connection, cp);
             }
         } catch (SQLException e1) {
-            LOG.error(e1.getMessage(), e1);
+            LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
         }
     }
 
@@ -250,7 +272,7 @@ public class INode221 {
             stmt.execute();
             stmt.clearParameters();
         } catch (SQLException e) {
-            LOG.error(e.getMessage(), e);
+            LOG.error("Something wrong when storing Circuit Packs in DB", e);
         }
     }
 
@@ -265,14 +287,16 @@ public class INode221 {
             preparedStmt.execute();
             preparedStmt.clearParameters();
         } catch (SQLException e) {
-            LOG.error(e.getMessage(), e);
+            LOG.error("Something wrong when storing shelves in DB", e);
         }
     }
 
     private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
         String startTimetampStr = getCurrentTimestamp();
-        for (int i = 0; i < shelves.getSlots().size(); i++) {
-            Slots slot = shelves.getSlots().get(i);
+        @NonNull
+        Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
+        for (Map.Entry<SlotsKey, Slots> entry : slotsMap.entrySet()) {
+            Slots slot = entry.getValue();
             LOG.info("Getting Slot Details of {}", slot.getSlotName());
             Object[] parameters = new Object[]{nodeId,
                 shelves.getShelfName(),
@@ -291,7 +315,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing shelves slots in DB", e);
             }
         }
     }
@@ -299,8 +323,10 @@ public class INode221 {
 
     private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
         String startTimetampStr = getCurrentTimestamp();
-        for (int i = 0; i < circuitPacks.getCpSlots().size(); i++) {
-            CpSlots cpSlot = circuitPacks.getCpSlots().get(i);
+        @NonNull
+        Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
+        for (Map.Entry<CpSlotsKey, CpSlots> entry : cpSlotsMap.entrySet()) {
+            CpSlots cpSlot = entry.getValue();
 
             Object[] parameters = new Object[]{nodeId,
                 circuitPacks.getCircuitPackName(),
@@ -319,7 +345,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
             }
         }
     }
@@ -342,7 +368,7 @@ public class INode221 {
         //String serialId = "";
 
         String nodeId = prepareDashString(deviceInfo.getNodeId());
-        Long nodeNumber = deviceInfo.getNodeNumber();
+        Long nodeNumber = deviceInfo.getNodeNumber().toJava();
         Integer nodeTypeEnu = deviceInfo.getNodeType().getIntValue();
         String clli = prepareDashString(deviceInfo.getClli());
         String vendor = prepareDashString(deviceInfo.getVendor());
@@ -459,95 +485,6 @@ public class INode221 {
             startTimestamp};
     }
 
-
-    private static Object[] prepareCPPortsParameters(String nodeId, CircuitPacks circuitPacks, Ports cpPort) {
-
-        String circuitPackName = circuitPacks.getCircuitPackName();
-        String portName = cpPort.getPortName();
-        String portType = cpPort.getPortType();
-        String portQualEnu = String.valueOf(cpPort.getPortQual().getIntValue());
-        String portWavelengthTypeEnu = String.valueOf(cpPort.getPortWavelengthType().getIntValue());
-        String portDirectionEnu = String.valueOf(cpPort.getPortDirection().getIntValue());
-        String label = cpPort.getLabel();
-        String circuitId = cpPort.getCircuitId();
-        String administrativeStateEnu =
-            (cpPort.getAdministrativeState() == null ? "" :
-                String.valueOf(cpPort.getAdministrativeState().getIntValue()));
-        String operationalStateEnu =
-            (cpPort.getOperationalState() == null ? "" : String.valueOf(cpPort.getOperationalState().getIntValue()));
-        String logicalConnectionPoint = cpPort.getLogicalConnectionPoint();
-        String partnerPortCircuitPackName = cpPort.getPartnerPort().getCircuitPackName();
-        String partnerPortPortName = cpPort.getPartnerPort().getPortName().toString();
-        String parentPortCircuitPackName = cpPort.getParentPort().getCircuitPackName();
-        String parentPortPortName = cpPort.getParentPort().getPortName().toString();
-        String roadmPortPortPowerCapabilityMinRx = cpPort.getRoadmPort().getPortPowerCapabilityMinRx().toString();
-        String roadmPortPortPowerCapabilityMinTx = cpPort.getRoadmPort().getPortPowerCapabilityMinTx().toString();
-        String roadmPortPortPowerCapabilityMaxRx = cpPort.getRoadmPort().getPortPowerCapabilityMaxRx().toString();
-        String roadmPortPortPowerCapabilityMaxTx = cpPort.getRoadmPort().getPortPowerCapabilityMaxTx().toString();
-        //String roadmPortCapableWavelengths = "";
-        //String roadmPortAvailableWavelengths = "";
-        //String roadmPortUsedWavelengths = "";
-        String transponderPortPortPowerCapabilityMinRx =
-            cpPort.getTransponderPort().getPortPowerCapabilityMinRx().toString();
-        String transponderPortPortPowerCapabilityMinTx =
-            cpPort.getTransponderPort().getPortPowerCapabilityMinTx().toString();
-        String transponderPortPortPowerCapabilityMaxRx =
-            cpPort.getTransponderPort().getPortPowerCapabilityMaxRx().toString();
-        String transponderPortPortPowerCapabilityMaxTx =
-            cpPort.getTransponderPort().getPortPowerCapabilityMaxTx().toString();
-        //String transponderPortCapableWavelengths = "";
-        String otdrPortLaunchCableLength = cpPort.getOtdrPort().getLaunchCableLength().toString();
-        String otdrPortPortDirection = String.valueOf(cpPort.getOtdrPort().getPortDirection().getIntValue());
-        //String ilaPortPortPowerCapabilityMixRx = "";
-        //String ilaPortPortPowerCapabilityMixTx = "";
-        //String ilaPortPortPowerCapabilityMaxRx = "";
-        //String ilaPortPortPowerCapabilityMaxTx = "";
-
-        String startTimestamp = getCurrentTimestamp();
-
-        return new Object[]{nodeId,
-            circuitPackName,
-            portName,
-            portType,
-            portQualEnu,
-            portWavelengthTypeEnu,
-            portDirectionEnu,
-            label,
-            circuitId,
-            administrativeStateEnu,
-            operationalStateEnu,
-            logicalConnectionPoint,
-            partnerPortCircuitPackName,
-            partnerPortPortName,
-            parentPortCircuitPackName,
-            parentPortPortName,
-            roadmPortPortPowerCapabilityMinRx,
-            roadmPortPortPowerCapabilityMinTx,
-            roadmPortPortPowerCapabilityMaxRx,
-            roadmPortPortPowerCapabilityMaxTx,
-            //roadmPortCapableWavelengths,
-            //roadmPortAvailableWavelengths,
-            //roadmPortUsedWavelengths,
-            "", "", "",
-            transponderPortPortPowerCapabilityMinRx,
-            transponderPortPortPowerCapabilityMinTx,
-            transponderPortPortPowerCapabilityMaxRx,
-            transponderPortPortPowerCapabilityMaxTx,
-            //transponderPortCapableWavelengths,
-            "",
-            otdrPortLaunchCableLength,
-            otdrPortPortDirection,
-            //ilaPortPortPowerCapabilityMixRx,
-            //ilaPortPortPowerCapabilityMixTx,
-            //ilaPortPortPowerCapabilityMaxRx,
-            //ilaPortPortPowerCapabilityMaxTx,
-            "", "", "", "",
-            startTimestamp,
-            startTimestamp
-        };
-    }
-
-
     private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
         String startTimestamp = getCurrentTimestamp();
         return new Object[]{nodeId,
@@ -584,25 +521,6 @@ public class INode221 {
             startTimestamp};
     }
 
-
-    private void persistCPPorts(String nodeId, Connection connection, CircuitPacks circuitPacks) {
-        for (int i = 0; i < circuitPacks.getPorts().size(); i++) {
-            Object[] cpPortsParameters = prepareCPPortsParameters(nodeId, circuitPacks, circuitPacks.getPorts().get(i));
-            String query = Queries.getQuery().deviceCPPortInsert().get();
-            LOG.info("Running {} query ", query);
-            try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
-                for (int j = 0; j < cpPortsParameters.length; j++) {
-                    preparedStmt.setObject(j + 1, cpPortsParameters[j]);
-                }
-                preparedStmt.execute();
-                preparedStmt.clearParameters();
-            } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
-            }
-        }
-    }
-
-
     private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
 
         int administrativeStateEnu = deviceInterface.getAdministrativeState().getIntValue();
@@ -720,7 +638,7 @@ public class INode221 {
                     org.opendaylight.yang.gen.v1
                         .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
                     .getOts());
-                int otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue();
+                //otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue();
                 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
                 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
                 break;
@@ -731,21 +649,21 @@ public class INode221 {
                     .getOdu());
                 oduRate = String.valueOf(oduIfBuilder.getRate());
                 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
-                oduProactiveDelayMeasurementEnabled = oduIfBuilder.isProactiveDelayMeasurementEnabled().toString();
+                oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
 
                 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
                 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
                 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
                 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
 
-                opuPayloadType = oduIfBuilder.getOpu().getPayloadType().toString();
-                opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType().toString();
-                opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType().toString();
+                opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
+                opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
+                opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
                 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
                         /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
                         persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
                         persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
-                maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().isEnabled().toString();
+                maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
                 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getIntValue();
                 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getIntValue();
                 maintTestsignalBiterrors = oduIfBuilder.getMaintTestsignal().getBitErrors().toString();
@@ -760,7 +678,7 @@ public class INode221 {
                     .getOtu());
                 otuRate = otuIfBuilder.getRate().getName();
                 otuFecEnu = otuIfBuilder.getFec().getIntValue();
-                otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().isEnabled().toString();
+                otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
                 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getIntValue();
                 break;
 
@@ -874,8 +792,8 @@ public class INode221 {
 
         String layer = tcm.getLayer().toString();
         int monitoringModeEnu = tcm.getMonitoringMode().getIntValue();
-        String ltcActEnabled = tcm.isLtcActEnabled().toString();
-        String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().toString();
+        String ltcActEnabled = tcm.getLtcActEnabled().toString();
+        String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
         //int tcmDirectionEnu = -1;
         //int timDetectModeEnu = -1;
         //String txSapi = "";
@@ -998,10 +916,12 @@ public class INode221 {
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfaceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); */
 
-        for (int i = 0; i < deviceObject.get().getInterface().size(); i++) {
+        @NonNull
+        Map<InterfaceKey, Interface> interfaceMap = deviceObject.get().nonnullInterface();
+        for (Map.Entry<InterfaceKey, Interface> entry : interfaceMap.entrySet()) {
             Interface deviceInterface;
 
-            deviceInterface = deviceObject.get().getInterface().get(i);
+            deviceInterface = entry.getValue();
         /*if (interfaceOpt.isPresent()) {
             deviceInterface = interfaceOpt.get();
         } else {
@@ -1019,7 +939,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices interfaces in DB", e);
             }
         }
     }
@@ -1033,7 +953,7 @@ public class INode221 {
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
             LOG.error("LLDP subtree is missing");
-
+            return;
         }
         int adminstatusEnu =
             protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getAdminStatus()
@@ -1065,7 +985,7 @@ public class INode221 {
             stmt.execute();
             stmt.clearParameters();
         } catch (SQLException e) {
-            LOG.error(e.getMessage(), e);
+            LOG.error("Something wrong when storing devices protocols in DB", e);
         }
 
     }
@@ -1080,13 +1000,15 @@ public class INode221 {
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
             LOG.error("LLDP subtree is missing");
-
+            return;
         }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().size(); i++) {
+        @NonNull
+        Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.get()
+            .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
+        for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
 
-            PortConfig portConfig =
-                protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().get(i);
+            PortConfig portConfig = entry.getValue();
             String ifName = portConfig.getIfName();
             int adminStatusEnu = portConfig.getAdminStatus().getIntValue();
 
@@ -1106,7 +1028,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
             }
 
         }
@@ -1122,14 +1044,15 @@ public class INode221 {
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
             LOG.error("LLDP subtree is missing");
-
+            return;
         }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList().getIfName()
-            .size(); i++) {
+        @NonNull
+        Map<IfNameKey, IfName> ifNameMap = protocolObject.get()
+            .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
+        for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
 
-            IfName ifNameObj =
-                protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList().getIfName().get(i);
+            IfName ifNameObj = entry.getValue();
             String ifName = ifNameObj.getIfName();
             String remotesysname = ifNameObj.getRemoteSysName();
             String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
@@ -1161,192 +1084,27 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
-            }
-
-        }
-    }
-
-    private void persistDevProtocolRstp(String nodeId, Connection connection) {
-
-        InstanceIdentifier<Protocols> protocolsIID =
-                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
-        Optional<Protocols> protocolObject =
-                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
-            LOG.error("LLDP subtree is missing");
-
-        }
-        String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < protocolObject.get()
-            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
-            .getRstp().getRstpBridgeInstance().size(); i++) {
-
-            RstpBridgeInstance rstpBridgeInstance = protocolObject.get()
-                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
-                .getRstp().getRstpBridgeInstance().get(i);
-            String bridgeName = rstpBridgeInstance.getBridgeName();
-            String bridgePriority = rstpBridgeInstance.getRstpConfig().getBridgePriority().toString();
-            String shutdown = rstpBridgeInstance.getRstpConfig().getShutdown().toString();
-            String holdTime = rstpBridgeInstance.getRstpConfig().getHoldTime().toString();
-            String helloTime = rstpBridgeInstance.getRstpConfig().getHelloTime().toString();
-            String maxAge = rstpBridgeInstance.getRstpConfig().getMaxAge().toString();
-            String forwardDelay = rstpBridgeInstance.getRstpConfig().getForwardDelay().toString();
-            String transmitHoldCount = rstpBridgeInstance.getRstpConfig().getTransmitHoldCount().toString();
-            String rootBridgePort =
-                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePort().toString();
-            String rootPathCost = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootPathCost().toString();
-            String rootBridgePriority =
-                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePriority().toString();
-            String rootBridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgeId().toString();
-            String rootHoldTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHoldTime().toString();
-            String rootHelloTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHelloTime().toString();
-            String rootMaxAge = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootMaxAge().toString();
-            String rootForwardDelay =
-                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootForwardDelay().toString();
-            String bridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getBridgeId().toString();
-            String topoChangeCount =
-                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTopoChangeCount().toString();
-            String timeSinceTopoChange =
-                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTimeSinceTopoChange().toString();
-
-            persistDevProtocolRstpBridgePort(nodeId, bridgeName, rstpBridgeInstance, connection);
-            persistDevProtocolRstpBridgePortAttr(nodeId, bridgeName, rstpBridgeInstance, connection);
-
-            Object[] parameters = {nodeId,
-                bridgeName,
-                bridgePriority,
-                shutdown,
-                holdTime,
-                helloTime,
-                maxAge,
-                forwardDelay,
-                transmitHoldCount,
-                rootBridgePort,
-                rootPathCost,
-                rootBridgePriority,
-                rootBridgeId,
-                rootHoldTime,
-                rootHelloTime,
-                rootMaxAge,
-                rootForwardDelay,
-                bridgeId,
-                topoChangeCount,
-                timeSinceTopoChange,
-                startTimestamp,
-                startTimestamp
-            };
-
-            String query = Queries.getQuery().deviceProtocolRstpInsert().get();
-            LOG.info("Running {} query ", query);
-            try (PreparedStatement stmt = connection.prepareStatement(query)) {
-                for (int j = 0; j < parameters.length; j++) {
-                    stmt.setObject(j + 1, parameters[j]);
-                }
-                stmt.execute();
-                stmt.clearParameters();
-            } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
             }
 
         }
     }
 
-    private void persistDevProtocolRstpBridgePort(String nodeId, String bridgeName,
-        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
-
-        String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().size(); i++) {
-            RstpBridgePortTable rstpBridgePortTable =
-                rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().get(i);
-
-            String ifName = rstpBridgePortTable.getIfname();
-            String cost = rstpBridgePortTable.getCost().toString();
-            String priority = rstpBridgePortTable.getPriority().toString();
-
-            Object[] parameters = {nodeId,
-                bridgeName,
-                ifName,
-                cost,
-                priority,
-                startTimestamp,
-                startTimestamp
-            };
-
-            String query = Queries.getQuery().deviceProtocolRstpBridgePortInsert().get();
-            LOG.info("Running {} query ", query);
-            try (PreparedStatement stmt = connection.prepareStatement(query)) {
-                for (int j = 0; j < parameters.length; j++) {
-                    stmt.setObject(j + 1, parameters[j]);
-                }
-                stmt.execute();
-                stmt.clearParameters();
-            } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
-            }
-
-        }
-    }
-
-    private void persistDevProtocolRstpBridgePortAttr(String nodeId, String bridgeName,
-        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
-
-        String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().size();
-            i++) {
-
-            org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.state.attr
-                .RstpBridgePortTable rstpBridgePortTableAttr =
-                    rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().get(i);
-
-            String ifName = rstpBridgePortTableAttr.getIfname();
-            String bridgePortState = rstpBridgePortTableAttr.getBridgePortState().getName();
-            String bridgePortRole = rstpBridgePortTableAttr.getBridgePortRole().getName();
-            String bridgePortId = rstpBridgePortTableAttr.getBridgePortId().toString();
-            String openEdgeBridgePort = rstpBridgePortTableAttr.getOperEdgeBridgePort().toString();
-            String designatedBridgePort = rstpBridgePortTableAttr.getDesignatedBridgePort().toString();
-            String designatedBridgeId = rstpBridgePortTableAttr.getDesignatedBridgeid().toString();
-
-            Object[] parameters = {nodeId,
-                bridgeName,
-                ifName,
-                bridgePortState,
-                bridgePortRole,
-                bridgePortId,
-                openEdgeBridgePort,
-                designatedBridgePort,
-                designatedBridgeId,
-                startTimestamp,
-                startTimestamp
-            };
-
-            String query = Queries.getQuery().deviceProtocolRstpBridgePortAttrInsert().get();
-            LOG.info("Running {} query ", query);
-            try (PreparedStatement stmt = connection.prepareStatement(query)) {
-                for (int j = 0; j < parameters.length; j++) {
-                    stmt.setObject(j + 1, parameters[j]);
-                }
-                stmt.execute();
-                stmt.clearParameters();
-            } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
-            }
-
-        }
-    }
-
-
     private void persistDevInternalLinks(String nodeId, Connection connection) {
 
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getInternalLink().size(); i++) {
-            InternalLink internalLink = deviceObject.get().getInternalLink().get(i);
+        @NonNull
+        Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
+        for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
+            InternalLink internalLink = entry.getValue();
             String internalLinkName = internalLink.getInternalLinkName();
             String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
             String sourcePortName = internalLink.getSource().getPortName().toString();
@@ -1372,7 +1130,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices internal links", e);
             }
 
         }
@@ -1385,17 +1143,22 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getExternalLink().size(); i++) {
-            ExternalLink externalLink = deviceObject.get().getExternalLink().get(i);
+        @NonNull
+        Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
+        for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
+            ExternalLink externalLink = entry.getValue();
             String externalLinkName = externalLink.getExternalLinkName();
-            String sourceNodeId = externalLink.getSource().getNodeId().toString();
+            String sourceNodeId = externalLink.getSource().getNodeId();
             String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
-            String sourcePortName = externalLink.getSource().getPortName().toString();
-            String destinationNodeId = externalLink.getDestination().getNodeId().toString();
+            String sourcePortName = externalLink.getSource().getPortName();
+            String destinationNodeId = externalLink.getDestination().getNodeId();
             String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
-            String destinationPortName = externalLink.getDestination().getPortName().toString();
+            String destinationPortName = externalLink.getDestination().getPortName();
 
             Object[] parameters = {nodeId,
                 externalLinkName,
@@ -1418,7 +1181,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices external links", e);
             }
 
         }
@@ -1430,10 +1193,16 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
 
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getPhysicalLink().size(); i++) {
-            PhysicalLink physicalLink = deviceObject.get().getPhysicalLink().get(i);
+        @NonNull
+        Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
+        for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
+            PhysicalLink physicalLink = entry.getValue();
             String physicalLinkName = physicalLink.getPhysicalLinkName();
             String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
             String sourcePortName = physicalLink.getSource().getPortName().toString();
@@ -1459,7 +1228,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices physical links", e);
             }
 
         }
@@ -1471,10 +1240,15 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getDegree().size(); i++) {
-            Degree degree = deviceObject.get().getDegree().get(i);
+        @NonNull
+        Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
+        for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
+            Degree degree = entry.getValue();
             String degreeNumber = degree.getDegreeNumber().toString();
             String maxWavelengths = degree.getMaxWavelengths().toString();
             String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
@@ -1509,7 +1283,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices degrees", e);
             }
 
         }
@@ -1519,10 +1293,17 @@ public class INode221 {
     private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
 
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < degree.getCircuitPacks().size(); i++) {
+        @NonNull
+        Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
+                org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
+            circuitPacksMap = degree.nonnullCircuitPacks();
+        for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
+                org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
+                    circuitPacksMap.entrySet()) {
+
 
-            String circuitPackIndex = degree.getCircuitPacks().get(i).getIndex().toString();
-            String circuitPackName = degree.getCircuitPacks().get(i).getCircuitPackName();
+            String circuitPackIndex = entry.getValue().getIndex().toString();
+            String circuitPackName = entry.getValue().getCircuitPackName();
 
             Object[] parameters = {nodeId,
                 degreeNumber,
@@ -1541,7 +1322,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices degrees circuit packs", e);
             }
 
         }
@@ -1551,11 +1332,14 @@ public class INode221 {
         Connection connection) {
 
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < degree.getConnectionPorts().size(); i++) {
+        @NonNull
+        Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
+        for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
 
-            String connectionPortIndex = degree.getConnectionPorts().get(i).getIndex().toString();
-            String circuitPackName = degree.getConnectionPorts().get(i).getCircuitPackName();
-            String portName = degree.getConnectionPorts().get(i).getPortName().toString();
+            ConnectionPorts connectionPorts = entry.getValue();
+            String connectionPortIndex = connectionPorts.getIndex().toString();
+            String circuitPackName = connectionPorts.getCircuitPackName();
+            String portName = connectionPorts.getPortName().toString();
 
             Object[] parameters = {nodeId,
                 degreeNumber,
@@ -1575,7 +1359,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices degrees connection ports", e);
             }
 
         }
@@ -1588,13 +1372,19 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
 
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getSharedRiskGroup().size(); i++) {
-            SharedRiskGroup sharedRiskGroup = deviceObject.get().getSharedRiskGroup().get(i);
+        @NonNull
+        Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
+        for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
+            SharedRiskGroup sharedRiskGroup = entry.getValue();
             String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
             String srgNumber = sharedRiskGroup.getSrgNumber().toString();
-            int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
+            //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
             persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
             //String currentProvisionedAddDropPorts = "";
             //String mcCapSlotWidthGranularity = "";
@@ -1625,7 +1415,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices SRG", e);
             }
 
         }
@@ -1635,10 +1425,18 @@ public class INode221 {
         Connection connection) {
 
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < sharedRiskGroup.getCircuitPacks().size(); i++) {
-
-            String circuitPackindex = sharedRiskGroup.getCircuitPacks().get(i).getIndex().toString();
-            String circuitPackName = sharedRiskGroup.getCircuitPacks().get(i).getCircuitPackName();
+        @NonNull
+        Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
+                org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
+                circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
+        for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
+                org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
+                    circuitPacksMap.entrySet()) {
+
+            org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
+                                entry.getValue();
+            String circuitPackindex = circuitPack.getIndex().toString();
+            String circuitPackName = circuitPack.getCircuitPackName();
 
             Object[] parameters = {nodeId,
                 srgNumber,
@@ -1657,7 +1455,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices SRG circuit packs", e);
             }
 
         }
@@ -1669,10 +1467,15 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getRoadmConnections().size(); i++) {
-            RoadmConnections roadmConnections = deviceObject.get().getRoadmConnections().get(i);
+        @NonNull
+        Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections();
+        for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
+            RoadmConnections roadmConnections = entry.getValue();
             int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
             //String connectionName = "";
             //String connectionNumber = "";
@@ -1694,6 +1497,7 @@ public class INode221 {
                 startTimestamp
             };
 
+
             String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
             LOG.info("Running {} query ", query);
             try (PreparedStatement stmt = connection.prepareStatement(query)) {
@@ -1703,7 +1507,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices ROADM connection ", e);
             }
 
         }
@@ -1716,10 +1520,15 @@ public class INode221 {
         Optional<OrgOpenroadmDevice> deviceObject =
                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+        if (!deviceObject.isPresent()) {
+            LOG.error("Device with node id {} not found", nodeId);
+            return;
+        }
         String startTimestamp = getCurrentTimestamp();
-        for (int i = 0; i < deviceObject.get().getConnectionMap().size(); i++) {
-            ConnectionMap connectionMap = deviceObject.get().getConnectionMap().get(i);
+        @NonNull
+        Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.get().nonnullConnectionMap();
+        for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
+            ConnectionMap connectionMap = entry.getValue();
             String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
             String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
             String sourcePortName = connectionMap.getSource().getCircuitPackName();
@@ -1742,7 +1551,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices connection map", e);
             }
 
         }
@@ -1784,7 +1593,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices wavelength map", e);
             }
 
         }
@@ -1795,10 +1604,9 @@ public class INode221 {
     private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
         Connection connection) {
 
-        for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
-            Tcm tcm;
-
-            tcm = oduBuilder.getTcm().get(i);
+        Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
+        for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
+            Tcm tcm = entry.getValue();
 
             Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
 
@@ -1811,19 +1619,21 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices interface tcm", e);
             }
         }
     }
 
     private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
         Connection connection) {
-
-        for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
-            TxMsi txMsi;
-
-            txMsi = oduBuilder.getOpu().getMsi().getTxMsi().get(i);
-
+        @Nullable
+        Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
+        if (txMsi2Map == null) {
+            LOG.error("Null txMsi2Map for node {}", nodeId);
+            return;
+        }
+        for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
+            TxMsi txMsi = entry.getValue();
             Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
 
             String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
@@ -1835,7 +1645,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
             }
         }
     }
@@ -1843,11 +1653,14 @@ public class INode221 {
 
     private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
         Connection connection) {
-
-        for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
-            RxMsi rxMsi;
-
-            rxMsi = oduBuilder.getOpu().getMsi().getRxMsi().get(i);
+        @Nullable
+        Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
+        if (rxMsi2Map == null) {
+            LOG.error("Null rxMsi2Map for node {}", nodeId);
+            return;
+        }
+        for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
+            RxMsi rxMsi = entry.getValue();
 
             Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
 
@@ -1860,7 +1673,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
             }
         }
     }
@@ -1868,11 +1681,14 @@ public class INode221 {
 
     private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
         Connection connection) {
-
-        for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
-            ExpMsi expMsi;
-
-            expMsi = oduBuilder.getOpu().getMsi().getExpMsi().get(i);
+        @Nullable
+        Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
+        if (expMsi2Map == null) {
+            LOG.error("Null expMsi2Map for node {}", nodeId);
+            return;
+        }
+        for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
+            ExpMsi expMsi = entry.getValue();
 
             Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
 
@@ -1885,7 +1701,7 @@ public class INode221 {
                 stmt.execute();
                 stmt.clearParameters();
             } catch (SQLException e) {
-                LOG.error(e.getMessage(), e);
+                LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);
             }
         }
     }