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 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.TxMsi;
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.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.Wavelengths;
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 INode121 {
private static final Logger LOG = LoggerFactory.getLogger(INode121.class);
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]);
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;
}
}
}
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when fetching node in DB", e);
}
return nodeExists == 0 ? false : true;
}
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
LOG.info("Shelves size {}", deviceObject.get().getShelves().size());
- try (Connection connection = dataSource.getConnection()) {
- Preconditions.checkNotNull(connection);
+ try (Connection connection = requireNonNull(dataSource.getConnection())) {
for (int i = 0; i < deviceObject.get().getShelves().size(); i++) {
Shelves shelve = deviceObject.get().getShelves().get(i);
String shelfName = shelve.getShelfName();
persistShelves(nodeId, connection, shelve);
}
} catch (SQLException e1) {
- LOG.error(e1.getMessage(), e1);
+ LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
}
}
}
LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().size());
- try (Connection connection = dataSource.getConnection()) {
- Preconditions.checkNotNull(connection);
+ try (Connection connection = requireNonNull(dataSource.getConnection())) {
for (int i = 0; i < deviceObject.get().getCircuitPacks().size(); i++) {
CircuitPacks cp = deviceObject.get().getCircuitPacks().get(i);
persistCircuitPacks(nodeId, connection, cp);
}
} catch (SQLException e1) {
- LOG.error(e1.getMessage(), e1);
+ LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing Circuit Packs in DB", e);
}
}
preparedStmt.execute();
preparedStmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing shelves in DB", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing shelves slots in DB", e);
}
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
}
}
}
- private void persistPorts(CircuitPacks circuitPacks, Connection connection) {
- LOG.warn("Ports are not persisted yet");
- }
-
-
/**
* Prepares parameters for device insert query.
*
cpPort.getOtdrPort().getLaunchCableLength().toString()));
String otdrPortPortDirection = (cpPort.getOtdrPort() == null ? "-1" :
(cpPort.getOtdrPort().getPortDirection() == null ? "-1" :
- Integer.valueOf(cpPort.getOtdrPort().getPortDirection().getIntValue()).toString()));
+ Integer.toString(cpPort.getOtdrPort().getPortDirection().getIntValue())));
//String ilaPortPortPowerCapabilityMixRx = "";
//String ilaPortPortPowerCapabilityMixTx = "";
//String ilaPortPortPowerCapabilityMaxRx = "";
preparedStmt.execute();
preparedStmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing Cirtcuits Packs Ports in DB", e);
}
}
}
String maintTestsignalTypeEnu = "";
String otuFecEnu = "";
String otuMaintTypeEnu = "";
- String otsFiberTypeEnu = "";
+ //String otsFiberTypeEnu = "";
String ethernetSpeed = "-1";
String ethernetFec = "";
String ethernetMtu = "-1";
EthernetBuilder ethIfBuilder = new EthernetBuilder(deviceInterface.augmentation(Interface1.class)
.getEthernet());
ethernetSpeed = (ethIfBuilder.getSpeed() == null ? "-1" :
- Integer.valueOf(ethIfBuilder.getSpeed().intValue()).toString());
+ Integer.toString(ethIfBuilder.getSpeed().intValue()));
ethernetFec = ethIfBuilder.getFec().getName();
ethernetDuplexEnu = (ethIfBuilder.getDuplex() == null ? "" : ethIfBuilder.getDuplex().getName());
ethernetMtu = ethIfBuilder.getMtu().toString();
org.opendaylight.yang.gen.v1
.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
.getOts());
- otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue());
+ //otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue());
otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
break;
maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().isEnabled().toString();
maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getName();
maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getName();
- maintTestsignalBiterrors = Integer.valueOf(oduIfBuilder.getMaintTestsignal().getBitErrors().intValue())
- .toString();
+ maintTestsignalBiterrors = Integer.toString(
+ oduIfBuilder.getMaintTestsignal().getBitErrors().intValue());
maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices interfaces in DB", e);
}
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices protocols in DB", e);
}
}
}
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);
}
}
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);
- }
-
- }
- }
-
- 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]);
+ LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
}
- 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);
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices internal links", e);
}
}
String externalLinkName = externalLink.getExternalLinkName();
String sourceNodeId = externalLink.getSource().getNodeId();
String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
- String sourcePortName = externalLink.getSource().getPortName().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,
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices external links", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices physical links", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices degrees", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices degrees circuit packs", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices degrees connection ports", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices SRG", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices SRG circuit packs", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices ROADM connection ", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices connection map", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices wavelength map", e);
}
}
stmt.execute();
stmt.clearParameters();
} catch (SQLException e) {
- LOG.error(e.getMessage(), e);
+ LOG.error("Something wrong when storing devices interface tcm", e);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}