X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=inventory%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Finventory%2FINode221.java;h=24c6d45a9283207f0e4d4d902b2c1b96ef97055c;hb=f7d49a4792d6151b374dfe31ba50791289b5f740;hp=4c5ed86e5177a9fffe7f5209e3ceb1f9c220289b;hpb=5a2402f2aece5b66276aaaabf4201a06d8f3aa08;p=transportpce.git diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java index 4c5ed86e5..24c6d45a9 100644 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java @@ -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 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 shelvesMap = deviceObject.get().nonnullShelves(); + LOG.info("Shelves size {}", shelvesMap.size()); + try (Connection connection = requireNonNull(dataSource.getConnection())) { + for (Map.Entry 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 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 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 slotsMap = shelves.nonnullSlots(); + for (Map.Entry 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 cpSlotsMap = circuitPacks.nonnullCpSlots(); + for (Map.Entry 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 interfaceMap = deviceObject.get().nonnullInterface(); + for (Map.Entry 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 portConfigMap = protocolObject.get() + .augmentation(Protocols1.class).getLldp().nonnullPortConfig(); + for (Map.Entry 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 ifNameMap = protocolObject.get() + .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName(); + for (Map.Entry 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 protocolsIID = - InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class); - Optional 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 deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); Optional 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 internalLinkMap = deviceObject.get().nonnullInternalLink(); + for (Map.Entry 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 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 externalLinkMap = deviceObject.get().nonnullExternalLink(); + for (Map.Entry 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 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 physicalLinkMap = deviceObject.get().nonnullPhysicalLink(); + for (Map.Entry 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 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 degreeMap = deviceObject.get().nonnullDegree(); + for (Map.Entry 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 + circuitPacksMap = degree.nonnullCircuitPacks(); + for (Map.Entry 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 connectionPortsMap = degree.nonnullConnectionPorts(); + for (Map.Entry 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 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 sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup(); + for (Map.Entry 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 + circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks(); + for (Map.Entry 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 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 roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections(); + for (Map.Entry 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 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 connectionMapMap = deviceObject.get().nonnullConnectionMap(); + for (Map.Entry 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 tcmMap = oduBuilder.getTcm(); + for (Map.Entry 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 txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi(); + if (txMsi2Map == null) { + LOG.error("Null txMsi2Map for node {}", nodeId); + return; + } + for (Map.Entry 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 rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi(); + if (rxMsi2Map == null) { + LOG.error("Null rxMsi2Map for node {}", nodeId); + return; + } + for (Map.Entry 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 expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi(); + if (expMsi2Map == null) { + LOG.error("Null expMsi2Map for node {}", nodeId); + return; + } + for (Map.Entry 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); } } }