From 5a2402f2aece5b66276aaaabf4201a06d8f3aa08 Mon Sep 17 00:00:00 2001 From: Narayan Padi Date: Thu, 28 Mar 2019 13:34:18 -0400 Subject: [PATCH] Inventory init - creates a new inventory module to store information in an external MySQL/Mariadb database - currently supports OpenROADM version 1.2.1 devices - prepares the support of OpenROADM version 2.2.1 devices - uses new mdsal Databroker API JIRA: TRNSPRTPCE-81 Change-Id: I7c2df57d39964bc90dfd475efa4565d51e054822 Signed-off-by: malick Signed-off-by: guillaume.lambert --- .../transportpce/common/StringConstants.java | 3 +- features/features-transportpce/pom.xml | 7 + features/odl-transportpce-inventory/pom.xml | 103 + .../src/main/feature/feature.xml | 14 + .../org.opendaylight.transportpce.job.cfg | 6 + .../org.ops4j.datasource-transporpce.cfg | 6 + features/pom.xml | 1 + inventory/pom.xml | 82 + .../inventory/DeviceInventory.java | 90 + .../transportpce/inventory/INode.java | 109 + .../transportpce/inventory/INode121.java | 1978 +++++++++++++++++ .../transportpce/inventory/INode221.java | 1894 ++++++++++++++++ .../inventory/ListenerProvider.java | 87 + .../inventory/dto/InvDevInfo.java | 257 +++ .../listener/ClliNetworkChangeListener.java | 26 + .../listener/DeviceConfigListener.java | 156 ++ .../inventory/listener/DeviceListener.java | 158 ++ .../OverlayNetworkChangeListener.java | 26 + .../UnderlayNetworkChangeListener.java | 26 + .../transportpce/inventory/query/Queries.java | 865 +++++++ .../inventory/query/StatementBuilder.java | 48 + .../inventory/utils/JsonStringBuilder.java | 56 + .../inventory/utils/StringUtils.java | 80 + .../blueprint/inventory-blueprint.xml | 63 + pom.xml | 1 + 25 files changed, 6140 insertions(+), 2 deletions(-) create mode 100644 features/odl-transportpce-inventory/pom.xml create mode 100644 features/odl-transportpce-inventory/src/main/feature/feature.xml create mode 100644 features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg create mode 100644 features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg create mode 100644 inventory/pom.xml create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceConfigListener.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/JsonStringBuilder.java create mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java create mode 100644 inventory/src/main/resources/OSGI-INF/blueprint/inventory-blueprint.xml diff --git a/common/src/main/java/org/opendaylight/transportpce/common/StringConstants.java b/common/src/main/java/org/opendaylight/transportpce/common/StringConstants.java index 052c02e16..bb95bddc3 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/StringConstants.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/StringConstants.java @@ -13,10 +13,9 @@ public final class StringConstants { public static final String OPENROADM_DEVICE_MODEL_NAME = "org-openroadm-device"; public static final String DEFAULT_NETCONF_NODEID = "controller-config"; - + public static final String OPENROADM_DEVICE_VERSION_1_2_1 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; public static final String OPENROADM_DEVICE_VERSION_2_2_1 = "(http://org/openroadm/device?revision=2018-10-19)org-openroadm-device"; - public static final String OPENROADM_DEVICE_VERSION_1_2_1 = "(http://org/openroadm/device?revision=2017-02-06)org-openroadm-device"; public static final String NETWORK_TOKEN = "NETWORK"; diff --git a/features/features-transportpce/pom.xml b/features/features-transportpce/pom.xml index 66df36224..685844e59 100644 --- a/features/features-transportpce/pom.xml +++ b/features/features-transportpce/pom.xml @@ -43,6 +43,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL features xml + + ${project.groupId} + odl-transportpce-inventory + ${project.version} + features + xml + + + 4.0.0 + + + org.opendaylight.odlparent + single-feature-parent + 5.0.3 + + + + org.opendaylight.transportpce + odl-transportpce-inventory + 0.5.0-SNAPSHOT + feature + + + localhost:3306 + transportpce + root + root + data/transportpce/devicebackup + + 600 + + true + + + OpenDaylight :: transportpce :: Inventory + + + org.opendaylight.transportpce + transportpce-inventory + ${project.version} + + + org.opendaylight.transportpce + odl-transportpce + ${project.version} + features + xml + + + + + + + maven-resources-plugin + + + copy-resources + validate + + copy-resources + + + ${basedir}/target/resources + + + + src/main/resources + + true + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-db-artifact + package + + attach-artifact + + + + + target/resources/org.ops4j.datasource-transporpce.cfg + cfg + datasource + + + target/resources/org.opendaylight.transportpce.job.cfg + cfg + config + + + + + + + + + diff --git a/features/odl-transportpce-inventory/src/main/feature/feature.xml b/features/odl-transportpce-inventory/src/main/feature/feature.xml new file mode 100644 index 000000000..f95a75539 --- /dev/null +++ b/features/odl-transportpce-inventory/src/main/feature/feature.xml @@ -0,0 +1,14 @@ + + + + scheduler + pax-jdbc-mysql + pax-jdbc-pool-dbcp2 + + mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/datasource + + + mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/config + + + \ No newline at end of file diff --git a/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg b/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg new file mode 100644 index 000000000..c3505840d --- /dev/null +++ b/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg @@ -0,0 +1,6 @@ +#folder where backup files are stored +deviceBackupFolder=${transporpce.device.backup.folder} +#prefix for the generated files +deviceBackupPrefix=${transporpce.device.backup.prefix} +#period of storing the device info is seconds +deviceBackupPeriod=${transporpce.device.backup.period} diff --git a/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg b/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg new file mode 100644 index 000000000..c10ae34fb --- /dev/null +++ b/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg @@ -0,0 +1,6 @@ +osgi.jdbc.driver.name=mysql +url=jdbc:mysql://${transportpce.db.host}/${transportpce.db.database}?useUnicode=true&characterEncoding=utf8 +pool=dbcp2 +user=${transportpce.db.username} +password=${transportpce.db.password} +dataSourceName=transportpce diff --git a/features/pom.xml b/features/pom.xml index 1055e4cbd..a870f14e4 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -28,6 +28,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL odl-transportpce-ordmodels odl-transportpce + odl-transportpce-inventory diff --git a/inventory/pom.xml b/inventory/pom.xml new file mode 100644 index 000000000..62996eb44 --- /dev/null +++ b/inventory/pom.xml @@ -0,0 +1,82 @@ + + + + + 4.0.0 + + + org.opendaylight.mdsal + binding-parent + 4.0.7 + + + + org.opendaylight.transportpce + transportpce-inventory + 0.5.0-SNAPSHOT + bundle + + + + + org.opendaylight.controller + mdsal-artifacts + 1.10.2-SNAPSHOT + import + pom + + + org.opendaylight.netconf + netconf-artifacts + 1.7.2-SNAPSHOT + import + pom + + + + + + + ${project.groupId} + transportpce-api + ${project.version} + + + ${project.groupId}.ordmodels + transportpce-ordmodels-device + ${project.version} + + + ${project.groupId} + transportpce-common + ${project.version} + + + ${project.groupId} + transportpce-renderer + ${project.version} + + + org.opendaylight.controller.model + model-topology + + + org.opendaylight.netconf + sal-netconf-connector + + + com.fasterxml.jackson.core + jackson-databind + + + + + diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java new file mode 100644 index 000000000..6f749cf7d --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2016 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.ExecutionException; +import java.util.regex.Pattern; +import javax.sql.DataSource; + +import org.opendaylight.transportpce.common.device.DeviceTransactionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeviceInventory { + private static final String INSERT_ALARM_STRING = + "insert into inv_alarm_info(nodeid, probablecause, direction,extension,location," + + "notificationid,type,raisetime,severity,circuitid,circuitpack,connection,degree,iface," + + "internallink,physicallink,service,shelf,sharedriskgroup,port,portcircuitpack, create_date, update_date) " + + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final Logger LOG = LoggerFactory.getLogger(DeviceInventory.class); + + private final DataSource dataSource; + private final INode inode; + private final DeviceTransactionManager deviceTransactionManager; + + public DeviceInventory(DataSource dataSource, INode inode, + DeviceTransactionManager deviceTransactionManager) { + this.dataSource = dataSource; + this.inode = inode; + this.deviceTransactionManager = deviceTransactionManager; + } + + public void init() { + LOG.info("Initializing {}", DeviceInventory.class.getName()); + } + + public void initializeDevice(String deviceId, String openRoadmVersion) + throws InterruptedException, ExecutionException { + + LOG.info("Creating Device Inventory for device {} with version {}", deviceId, openRoadmVersion); + if (!inode.dataExists("inv_dev_info", " node_id = '" + deviceId + "'")) { + LOG.info("Adding node {} to inventory", deviceId); + inode.addNode(deviceId, openRoadmVersion); + } + } + + /** + * Stores the alarm into DB using {@link PreparedStatement}. + * + * @param alarmString an alarm + * @return number of rows inserted + */ + public int storeAlarm(String alarmString) { + String delimiter = "|"; + String[] splitAlarmString = alarmString.split(Pattern.quote(delimiter)); + int count = 0; + try (Connection connection = dataSource.getConnection(); + PreparedStatement statement = connection.prepareStatement(INSERT_ALARM_STRING)) { + LOG.debug("Inserting prepared stmt for {} query", INSERT_ALARM_STRING); + SimpleDateFormat myTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + Date startTimetamp = new Date(); + String startTimetampStr = myTimeStamp.format(startTimetamp); + + for (int i = 0; i < 21; i++) { + String value = (splitAlarmString.length >= i + 1) ? splitAlarmString[i] : ""; + LOG.debug("Setting parameter {}, to {} in the insert alarm query", i + 1, value); + statement.setString(i + 1, value); + } + statement.setString(22, startTimetampStr); + statement.setString(23, startTimetampStr); + LOG.debug("Setting current time and edited time to {}", startTimetampStr); + count = statement.executeUpdate(); + LOG.debug("Statment {}, returned {}", INSERT_ALARM_STRING, count); + statement.clearParameters(); + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + } + return count; + } +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java new file mode 100644 index 000000000..f31f89da7 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java @@ -0,0 +1,109 @@ +/* + * Copyright © 2016 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.inventory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import javax.sql.DataSource; + +import org.opendaylight.transportpce.common.device.DeviceTransactionManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class INode { + private static final Logger LOG = LoggerFactory.getLogger(INode.class); + + private final DataSource dataSource; + private final DeviceTransactionManager deviceTransactionManager; + private final INode221 inode221; + private final INode121 inode121; + + public INode(DataSource dataSource, DeviceTransactionManager deviceTransactionManager, INode121 inode121, + INode221 inode221) { + this.dataSource = dataSource; + this.deviceTransactionManager = deviceTransactionManager; + this.inode121 = inode121; + this.inode221 = inode221; + } + + public boolean addNode(String deviceId, String openROADMversion) { + boolean sqlResult = false; + return inode121.addNode(deviceId); + + } + + public boolean nodeExists(String nodeId) { + String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?"; + int nodeExists = 0; + LOG.info("Checking if {} exists in DB", nodeId); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) { + preparedStmt.setString(1, nodeId); + try (ResultSet rs = preparedStmt.executeQuery()) { + while (rs.next()) { + nodeExists = rs.getInt("node_exists"); + LOG.debug("Found {} devices matching {}", nodeExists, nodeId); + } + } + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + } + return nodeExists == 0 ? false : true; + } + + public boolean dataExists(String tableName, String searchKeys) { + String selectTableSQL = "select count(*) data_exists from " + tableName + " where " + searchKeys; + int dataExists = 0; + LOG.info("Checking if {} exists in DB", searchKeys); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) { + + try (ResultSet rs = preparedStmt.executeQuery()) { + while (rs.next()) { + dataExists = rs.getInt("data_exists"); + LOG.debug("Found {} devices matching {}", dataExists, searchKeys); + } + } + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + } + return dataExists == 0 ? false : true; + } + + /* public void getRoadmShelves(String nodeId, String openRoadmVersion) + throws InterruptedException, ExecutionException { + + LOG.info("ROADMSHELVES"); + if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) { + inode121.getRoadmShelves(nodeId); + } + else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) { + inode22.getRoadmShelves(nodeId); + } + return; + } + + public void getCircuitPacks(String nodeId, String openRoadmVersion) + throws InterruptedException, ExecutionException { + + LOG.info("ROADMCircuitPacks"); + if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) { + inode121.getCircuitPacks(nodeId); + } + else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) { + inode22.getCircuitPacks(nodeId); + } + return; + } +*/ + + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java new file mode 100644 index 000000000..1ed0e1115 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java @@ -0,0 +1,1978 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.inventory; + +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.Optional; +import java.util.concurrent.ExecutionException; +import javax.sql.DataSource; + +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.packs.CircuitPacks; +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.interfaces.grp.Interface; +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.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.Degree; +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.SharedRiskGroup; +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.shelf.Slots; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves; +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.nbr.list.IfName; +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.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.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; + +public class INode121 { + + private static final Logger LOG = LoggerFactory.getLogger(INode121.class); + + private final DataSource dataSource; + private final DeviceTransactionManager deviceTransactionManager; + + public INode121(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) { + this.dataSource = dataSource; + this.deviceTransactionManager = deviceTransactionManager; + } + + public boolean addNode(String deviceId) { + + InstanceIdentifier infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class); + Optional infoOpt = + deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + Info deviceInfo; + if (infoOpt.isPresent()) { + deviceInfo = infoOpt.get(); + } else { + LOG.warn("Could not get device info from DataBroker"); + return false; + } + boolean sqlResult = false; + String query = Queries.getQuery().deviceInfoInsert().get(); + LOG.info("Running {} query ", query); + try (Connection connection = dataSource.getConnection(); + 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]); + preparedStatement.setObject(i + 1, prepareParameters[i]); + + } + int executeUpdate = preparedStatement.executeUpdate(); + LOG.info("{} entries were added", executeUpdate); + sqlResult = true; + + LOG.debug("iNode AddNode call complete"); + getRoadmShelves(deviceId); + LOG.debug("iNode getRoadmShelves call complete"); + getCircuitPacks(deviceId); + LOG.debug("iNode getCircuitPacks call complete"); + + LOG.debug("iNode persist interfaces call"); + persistDevInterfaces(deviceId, connection); + LOG.debug("iNode persist interfaces call complete"); + + + LOG.debug("iNode persist protocols call"); + persistDevProtocols(deviceId, connection); + LOG.debug("iNode persist protocols call complete"); + + + LOG.debug("iNode persist wavelength map call"); + persistDevWavelengthMap(deviceId, connection); + LOG.debug("iNode persist wavelength map call complete"); + + LOG.debug("iNode persist internal links map call"); + persistDevInternalLinks(deviceId, connection); + LOG.debug("iNode persist internal links map call complete"); + + LOG.debug("iNode persist Physical links map call"); + persistDevPhysicalLinks(deviceId, connection); + LOG.debug("iNode persist Physical links map call complete"); + + LOG.debug("iNode persist External links map call"); + persistDevExternalLinks(deviceId, connection); + LOG.debug("iNode persist External links map call complete"); + + LOG.debug("iNode persist degree map call"); + persistDevDegree(deviceId, connection); + LOG.debug("iNode persist degree map call complete"); + + LOG.debug("iNode persist srg map call"); + persistDevSrg(deviceId, connection); + LOG.debug("iNode persist srg map call complete"); + + LOG.debug("iNode persist Roadm Connections call"); + persistDevRoadmConnections(deviceId, connection); + LOG.debug("iNode persist Roadm Connections call complete"); + + LOG.debug("iNode persist Connection Map call"); + 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); + } + return sqlResult; + } + + public boolean nodeExists(String nodeId) { + String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?"; + int nodeExists = 0; + LOG.info("Checking if {} exists in DB", nodeId); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) { + preparedStmt.setString(1, nodeId); + try (ResultSet rs = preparedStmt.executeQuery()) { + while (rs.next()) { + nodeExists = rs.getInt("node_exists"); + LOG.debug("Found {} devices matching {}", nodeExists, nodeId); + } + } + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + } + return nodeExists == 0 ? false : true; + } + + public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException { + InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); + 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); + String shelfName = shelve.getShelfName(); + + LOG.info("Getting Shelve Details of {}", shelfName); + if (shelve.getSlots() != null) { + LOG.info("Slot Size {} ", shelve.getSlots().size()); + persistShelveSlots(nodeId, shelve, connection); + } else { + LOG.info("No Slots for shelf {}", shelfName); + } + + persistShelves(nodeId, connection, shelve); + } + } catch (SQLException e1) { + LOG.error(e1.getMessage(), e1); + } + } + + public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException { + 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.warn("Device object {} was not found", nodeId); + return; + } + LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().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); + + if (cp.getCpSlots() != null) { + persistCircuitPacksSlots(nodeId, cp, connection); + } + LOG.info("Everything {}", cp); + LOG.info("CP is {}", cp); + + //persistPorts(cp, connection); + if (cp.getPorts() != null) { + persistCPPorts(nodeId, connection, cp); + } + persistCircuitPacks(nodeId, connection, cp); + } + } catch (SQLException e1) { + LOG.error(e1.getMessage(), e1); + } + } + + private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) { + Object[] parameters = prepareCircuitPacksParameters(nodeId, cp); + String query = Queries.getQuery().deviceCircuitPackInsert().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 persistShelves(String nodeId, Connection connection, Shelves shelve) { + Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve); + String query = Queries.getQuery().deviceShelfInsert().get(); + LOG.info("Running {} query ", query); + try (PreparedStatement preparedStmt = connection.prepareStatement(query)) { + for (int j = 0; j < shelvesParameter.length; j++) { + preparedStmt.setObject(j + 1, shelvesParameter[j]); + } + preparedStmt.execute(); + preparedStmt.clearParameters(); + } catch (SQLException e) { + LOG.error(e.getMessage(), 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); + LOG.info("Getting Slot Details of {}", slot.getSlotName()); + Object[] parameters = new Object[]{nodeId, + shelves.getShelfName(), + slot.getSlotName(), + slot.getLabel(), + slot.getProvisionedCircuitPack(), + "0", + startTimetampStr, + startTimetampStr}; + String query = Queries.getQuery().deviceShelfSlotInsert().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 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); + + Object[] parameters = new Object[]{nodeId, + circuitPacks.getCircuitPackName(), + cpSlot.getSlotName(), + cpSlot.getLabel(), + cpSlot.getProvisionedCircuitPack(), + "-1", + "-1", + startTimetampStr, + startTimetampStr}; + String query = Queries.getQuery().deviceCPSlotInsert().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 persistPorts(CircuitPacks circuitPacks, Connection connection) { + LOG.warn("Ports are not persisted yet"); + } + + + /** + * Prepares parameters for device insert query. + * + * @param deviceInfo device information + * @return Object an object + */ + private static Object[] prepareDeviceInfoParameters(Info deviceInfo) { + String startTimetampStr = getCurrentTimestamp(); + + String nodeId = prepareDashString(deviceInfo.getNodeId()); + Long nodeNumber = deviceInfo.getNodeNumber(); + String nodeTypeEnu = deviceInfo.getNodeType().getName(); + String clli = prepareDashString(deviceInfo.getClli()); + String vendor = prepareDashString(deviceInfo.getVendor()); + String model = prepareDashString(deviceInfo.getModel()); + String serialId = prepareDashString(deviceInfo.getSerialId()); + String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue()); + String prefixLength = prepareDashString(deviceInfo.getPrefixLength()); + String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue()); + String sourceEnum = deviceInfo.getSource().getName(); + String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue()); + String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength()); + String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue()); + String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue()); + String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion()); + //String openroadmVersion = "1.2.1"; + String template = prepareDashString(deviceInfo.getTemplate()); + String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue()); + String geoLatitude = (deviceInfo.getGeoLocation() != null + ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : ""); + String geoLongitude = (deviceInfo.getGeoLocation() != null + ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : ""); + String maxDegrees = (deviceInfo.getMaxDegrees() == null ? "-1" : prepareDashString(deviceInfo.getMaxDegrees())); + String maxSrgs = (deviceInfo.getMaxSrgs() == null ? "-1" : prepareDashString(deviceInfo.getMaxSrgs())); + String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version + String swValidationTimer = prepareDashString(""); //sw_validation_timer + String activationDateTime = prepareDashString(""); //activation_date_time + //Integer maxNumBin15minHistoricalPm = null; + //Integer maxNumBin24hourHistoricalPm = null; + /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId) + .replace("$$NODE-NUMBER$$", nodeNumber) + .replace("$$NODE-TYPE$$",nodeType) + .replace("$$CLLI$$",clli) + .replace("$$VENDOR$$",vendor) + .replace("$$MODEL$$",model) + .replace("$$SERIAL-ID$$",serialId) + .replace("$$IPADDRESS$$",ipAddress) + .replace("$$PREFIX-LENGTH$$",prefixLength) + .replace("$$DEFAULTGATEWAY$$",defaultGateway) + .replace("$$SOURCE$$",String.valueOf(source)) + .replace("$$CURRENT-IPADDRESS$$",currentIpAddress) + .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength) + .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway) + .replace("$$MACADDRESS$$",macAddress) + .replace("$$SOFTWAREVERSION$$",softwareVersion) + .replace("$$OPENROADM-VERSION$$",openroadmVersion) + .replace("$$TEMPLATE$$",template) + .replace("$$CURRENT-DATETIME$$",currentDatetime) + .replace("$$LATITUDE$$",latitude) + .replace("$$LONGITUDE$$",longitude) + .replace("$$MAX-DEGREES$$",maxDegrees) + .replace("$$MAX-SRGS$$",maxSrgs) + .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString("")) + .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString("")) + .replace("$$SW-VERSION$$",swVersion) + .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer) + .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/ + + + return new Object[]{ + nodeId, + nodeNumber, + nodeTypeEnu, + clli, + vendor, + model, + serialId, + ipAddress, + prefixLength, + defaultGateway, + sourceEnum, + currentIpAddress, + currentPrefixLength, + currentDefaultGateway, + macAddress, + softwareVersion, + //openroadmVersion, + "1.2.1", + template, + currentDatetime, + geoLatitude, + geoLongitude, + maxDegrees, + maxSrgs, + //maxNumBin15minHistoricalPm, + //maxNumBin24hourHistoricalPm, + null, null, + swVersion, + swValidationTimer, + activationDateTime, + startTimetampStr, + startTimetampStr + }; + } + + + private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) { + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + shelve.getShelfName(), + shelve.getShelfType(), + shelve.getRack(), + shelve.getShelfPosition(), + (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()), + shelve.getVendor(), + shelve.getModel(), + shelve.getSerialId(), + shelve.getType(), + shelve.getProductCode(), + (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()), + shelve.getClei(), + shelve.getHardwareVersion(), + (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()), + (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()), + (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()), + startTimestamp, + 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() == null ? "-1" : cpPort.getPortQual().getName())); + String portWavelengthTypeEnu = "-1"; //cpPort.getPortWavelengthType().getIntValue(); /* Check error*/ + String portDirectionEnu = String.valueOf((cpPort.getPortDirection() == null ? "" : + cpPort.getPortDirection().getName())); + String label = cpPort.getLabel(); + String circuitId = cpPort.getCircuitId(); + String administrativeStateEnu = (cpPort.getAdministrativeState() == null ? "" : + cpPort.getAdministrativeState().getName()); + String operationalStateEnu = + (cpPort.getOperationalState() == null ? "" : cpPort.getOperationalState().getName()); + String logicalConnectionPoint = cpPort.getLogicalConnectionPoint(); + String parentPortCircuitPackName = (cpPort.getPartnerPort() == null ? "" : + (cpPort.getPartnerPort().getCircuitPackName() == null ? "" : cpPort.getPartnerPort().getCircuitPackName())); + String partnerPortPortName = (cpPort.getPartnerPort() == null ? "" : + (cpPort.getPartnerPort().getPortName() == null ? "" : cpPort.getPartnerPort().getPortName().toString())); + String partnerPortCircuitPackName = (cpPort.getParentPort() == null ? "" : + (cpPort.getParentPort().getCircuitPackName() == null ? "" : cpPort.getParentPort().getCircuitPackName())); + String parentPortPortName = (cpPort.getParentPort() == null ? "" : + (cpPort.getParentPort().getPortName() == null ? "" : cpPort.getParentPort().toString())); + String roadmPortPortPowerCapabilityMinRx = (cpPort.getRoadmPort() == null ? "" : + (cpPort.getRoadmPort().getPortPowerCapabilityMinRx() == null ? "" : + cpPort.getRoadmPort().getPortPowerCapabilityMinRx().toString())); + String roadmPortPortPowerCapabilityMinTx = (cpPort.getRoadmPort() == null ? "" : + (cpPort.getRoadmPort().getPortPowerCapabilityMinTx() == null ? "" : + cpPort.getRoadmPort().getPortPowerCapabilityMinTx().toString())); + String roadmPortPortPowerCapabilityMaxRx = (cpPort.getRoadmPort() == null ? "" : + (cpPort.getRoadmPort().getPortPowerCapabilityMaxRx() == null ? "" : + cpPort.getRoadmPort().getPortPowerCapabilityMaxRx().toString())); + String roadmPortPortPowerCapabilityMaxTx = (cpPort.getRoadmPort() == null ? "" : + (cpPort.getRoadmPort().getPortPowerCapabilityMaxTx() == null ? "" : + cpPort.getRoadmPort().getPortPowerCapabilityMaxTx().toString())); + //String roadmPortCapableWavelengths = ""; + //String roadmPortAvailableWavelengths = ""; + //String roadmPortUsedWavelengths = ""; + String transponderPortPortPowerCapabilityMinRx = (cpPort.getTransponderPort() == null ? "" : + (cpPort.getTransponderPort().getPortPowerCapabilityMinRx() == null ? "" : + cpPort.getTransponderPort().getPortPowerCapabilityMinRx().toString())); + String transponderPortPortPowerCapabilityMinTx = (cpPort.getTransponderPort() == null ? "" : + (cpPort.getTransponderPort().getPortPowerCapabilityMinTx() == null ? "" : + cpPort.getTransponderPort().getPortPowerCapabilityMinTx().toString())); + String transponderPortPortPowerCapabilityMaxRx = (cpPort.getTransponderPort() == null ? "" : + (cpPort.getTransponderPort().getPortPowerCapabilityMaxRx() == null ? "" : + cpPort.getTransponderPort().getPortPowerCapabilityMaxRx().toString())); + String transponderPortPortPowerCapabilityMaxTx = (cpPort.getTransponderPort() == null ? "" : + (cpPort.getTransponderPort().getPortPowerCapabilityMaxTx() == null ? "" : + cpPort.getTransponderPort().getPortPowerCapabilityMaxTx().toString())); + //String transponderPortCapableWavelengths = ""; + String otdrPortLaunchCableLength = (cpPort.getOtdrPort() == null ? "" : + (cpPort.getOtdrPort().getLaunchCableLength() == null ? "" : + cpPort.getOtdrPort().getLaunchCableLength().toString())); + String otdrPortPortDirection = (cpPort.getOtdrPort() == null ? "-1" : + (cpPort.getOtdrPort().getPortDirection() == null ? "-1" : + Integer.valueOf(cpPort.getOtdrPort().getPortDirection().getIntValue()).toString())); + //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, + cpack.getCircuitPackName(), + cpack.getCircuitPackType(), + cpack.getCircuitPackProductCode(), + (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()), + cpack.getVendor(), + cpack.getModel(), + cpack.getSerialId(), + cpack.getType(), + cpack.getProductCode(), + (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()), + cpack.getClei(), + cpack.getHardwareVersion(), + (cpack.getOperationalState() == null ? -1 : cpack.getOperationalState().getIntValue()), + cpack.getCircuitPackCategory().getType().getIntValue(), + cpack.getCircuitPackCategory().getExtension(), + (cpack.getEquipmentState() == null ? -1 : cpack.getEquipmentState().getIntValue()), + cpack.getCircuitPackMode(), + cpack.getShelf(), + cpack.getSlot(), + cpack.getSubSlot(), + prepareEmptyString(cpack.getDueDate()), + prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" : + ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" : + cpack.getParentCircuitPack().getCircuitPackName()) + ), + prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" : + ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" : + cpack.getParentCircuitPack().getCpSlotName()) + ), + startTimestamp, + 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) { + + String ethernetDuplexEnu = ""; + String ethernetAutoNegotiationEnu = ""; + String maintTestsignalTestpatternEnu = ""; + String maintTestsignalTypeEnu = ""; + String otuFecEnu = ""; + String otuMaintTypeEnu = ""; + String otsFiberTypeEnu = ""; + String ethernetSpeed = "-1"; + String ethernetFec = ""; + String ethernetMtu = "-1"; + String ethernetCurrSpeed = ""; + String ethernetCurrDuplex = "-1"; + //String mciMcttpMinFreq = ""; + //String mciMcttpMaxFreq = ""; + //String mciMcttpCenterFreq = ""; + //String mciMcttpSlotWidth = ""; + //String mciNmcCtpFrequency = ""; + //String mciNmcCtpWidth = ""; + String ochRate = ""; + //String ochFrequency = ""; + //String ochWidth = ""; + String ochWavelengthNumber = ""; + String ochModulationFormat = ""; + String ochTransmitPower = ""; + String otsSpanLossReceive = ""; + String otsSpanLossTransmit = ""; + //String otsIngressSpanLossAgingMargin = ""; + //String otsEolMaxLoadPin = ""; + String oduRate = ""; + //String oduFunction = ""; + String oduMonitoringMode = ""; + //String oduNoOamFunction = ""; + String oduProactiveDelayMeasurementEnabled = ""; + //String oduPoaTribPortNumber = "-1"; + //String oduTxSapi = ""; + //String oduTxDapi = ""; + //String oduTxOperator = ""; + //String oduAcceptedSapi = ""; + //String oduAcceptedDapi = ""; + //String oduAcceptedOperator = ""; + //String oduExpectedSapi = ""; + //String oduExpectedDapi = ""; + //String oduTimActEnabled = ""; + //String oduTimDetectMode = ""; + //String oduDegmIntervals = "-1"; + //String oduDegthrPercentage = "-1"; + String opuPayloadType = ""; + String opuRxPayloadType = ""; + String opuExpPayloadType = ""; + String opuPayloadInterface = ""; + String maintTestsignalEnabled = ""; + String maintTestsignalBiterrors = "-1"; + String maintTestsignalBiterrorsterminal = "-1"; + String maintTestsignalSyncseconds = "-1"; + String maintTestsignalSyncsecondsterminal = "-1"; + String otuRate = ""; + //String otuTxSapi = ""; + //String otuTxDapi = ""; + //String otuTxOperator = ""; + //String otuAcceptedSapi = ""; + //String otuAcceptedDapi = ""; + //String otuAcceptedOperator = ""; + //String otuExpectedSapi = ""; + //String otuExpectedDapi = ""; + //String otuTimActEnabled = ""; + //String otuTimDetectMode = ""; + //String otuDegmIntervals = "-1"; + //String otuDegthrPercentage = "-1"; + String otuMaintLoopbackEnabled = ""; + //String mtOtuRate = ""; + //String mtOtuFec = ""; + //String mtOtuMaintLoopback = ""; + //String mtOtuEnabled = ""; + //String mtOtuType = ""; + + String name = deviceInterface.getName(); + String description = deviceInterface.getDescription(); + String type = deviceInterface.getType().getTypeName(); + String administrativeStateEnu = deviceInterface.getAdministrativeState().getName(); + int operationalState = deviceInterface.getOperationalState().getIntValue(); + String circuitId = deviceInterface.getCircuitId(); + String supportingInterface = deviceInterface.getSupportingInterface(); + String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName(); + String supportingPort = deviceInterface.getSupportingPort().toString(); + + switch (deviceInterface.getType().toString()) { + + case "ethernet": + //EthernetBuilder ethIfBuilder = new EthernetBuilder(); + EthernetBuilder ethIfBuilder = new EthernetBuilder(deviceInterface.augmentation(Interface1.class) + .getEthernet()); + ethernetSpeed = (ethIfBuilder.getSpeed() == null ? "-1" : + Integer.valueOf(ethIfBuilder.getSpeed().intValue()).toString()); + ethernetFec = ethIfBuilder.getFec().getName(); + ethernetDuplexEnu = (ethIfBuilder.getDuplex() == null ? "" : ethIfBuilder.getDuplex().getName()); + ethernetMtu = ethIfBuilder.getMtu().toString(); + ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getName(); + ethernetCurrSpeed = ethIfBuilder.getCurrSpeed(); + ethernetCurrDuplex = ethIfBuilder.getCurrDuplex(); + break; + + case "och": + OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1 + .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class) + .getOch()); + ochRate = ochIfBuilder.getRate().getName(); + ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString(); + ochModulationFormat = ochIfBuilder.getModulationFormat().getName(); + ochTransmitPower = ochIfBuilder.getTransmitPower().toString(); + break; + + case "ots": + OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1 + .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class) + .getOts()); + otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue()); + otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString(); + otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString(); + break; + + case "odu": + OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class) + .getOdu()); + oduRate = String.valueOf(oduIfBuilder.getRate()); + oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName(); + oduProactiveDelayMeasurementEnabled = oduIfBuilder.isProactiveDelayMeasurementEnabled().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(); + 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(); + maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getName(); + maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getName(); + maintTestsignalBiterrors = Integer.valueOf(oduIfBuilder.getMaintTestsignal().getBitErrors().intValue()) + .toString(); + maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString(); + maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds(); + maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal(); + break; + + case "otu": + OtuBuilder otuIfBuilder = + new OtuBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class) + .getOtu()); + otuRate = otuIfBuilder.getRate().getName(); + otuFecEnu = otuIfBuilder.getFec().getName(); + otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().isEnabled().toString(); + otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getName(); + break; + + default: + LOG.error("could not get interface type"); + + } + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + name, + description, + type, + administrativeStateEnu, + Integer.toString(operationalState), + circuitId, + supportingInterface, + supportingCircuitPackName, + supportingPort, + ethernetSpeed, + ethernetFec, + ethernetDuplexEnu, + ethernetMtu, + ethernetAutoNegotiationEnu, + ethernetCurrSpeed, + ethernetCurrDuplex, + //mciMcttpMinFreq, + //mciMcttpMaxFreq, + //mciMcttpCenterFreq, + //mciMcttpSlotWidth, + //mciNmcCtpFrequency, + //mciNmcCtpWidth, + "", "", "", "", "", "", + ochRate, + //ochFrequency, + //ochWidth, + "", "", + ochWavelengthNumber, + ochModulationFormat, + ochTransmitPower, + //otsFiberTypeEnu, + otsSpanLossReceive, + otsSpanLossTransmit, + //otsIngressSpanLossAgingMargin, + //otsEolMaxLoadPin, + "", "", + oduRate, + //oduFunction, + "", + oduMonitoringMode, + //oduNoOamFunction, + "", + oduProactiveDelayMeasurementEnabled, + //oduPoaTribPortNumber, + //oduTxSapi, + //oduTxDapi, + //oduTxOperator, + //oduAcceptedSapi, + //oduAcceptedDapi, + //oduAcceptedOperator, + //oduExpectedSapi, + //oduExpectedDapi, + //oduTimActEnabled, + //oduTimDetectMode, + //oduDegmIntervals, + //oduDegthrPercentage, + "-1", "", "", "", "", "","", "", "", "", "", "-1", "-1", + opuPayloadType, + opuRxPayloadType, + opuExpPayloadType, + opuPayloadInterface, + maintTestsignalEnabled, + maintTestsignalTestpatternEnu, + maintTestsignalTypeEnu, + maintTestsignalBiterrors, + maintTestsignalBiterrorsterminal, + maintTestsignalSyncseconds, + maintTestsignalSyncsecondsterminal, + otuRate, + otuFecEnu, + //otuTxSapi, + //otuTxDapi, + //otuTxOperator, + //otuAcceptedSapi, + //otuAcceptedDapi, + //otuAcceptedOperator, + //otuExpectedSapi, + //otuExpectedDapi, + //otuTimActEnabled, + //otuTimDetectMode, + //otuDegmIntervals, + //otuDegthrPercentage, + "", "", "", "", "", "","", "", "", "", "-1", "-1", + otuMaintLoopbackEnabled, + otuMaintTypeEnu, + //mtOtuRate, + //mtOtuFec, + //mtOtuMaintLoopback, + //mtOtuEnabled, + //mtOtuType, + "", "", "", "", "", + startTimestamp, + startTimestamp + }; + + } + + private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) { + + String layer = tcm.getLayer().toString(); + String monitoringModeEnu = tcm.getMonitoringMode().getName(); + String ltcActEnabled = tcm.isLtcActEnabled().toString(); + String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().toString(); + //String tcmDirectionEnu = ""; + //String timDetectModeEnu = ""; + //String txSapi = ""; + //String txDapi = ""; + //String txOperator = ""; + //String acceptedSapi = ""; + //String acceptedDapi = ""; + //String acceptedOperator = ""; + //String expectedSapi = ""; + //String expectedDapi = ""; + //String timActEnabled = ""; + //String degmIntervals = ""; + //String degthrPercentage = ""; + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + layer, + monitoringModeEnu, + ltcActEnabled, + proactiveDelayMeasurementEnabled, + //tcmDirectionEnu, + //txSapi, + //txDapi, + //txOperator, + //acceptedSapi, + //acceptedDapi, + //acceptedOperator, + //expectedSapi, + //expectedDapi, + //timActEnabled, + //timDetectModeEnu, + //degmIntervals, + //degthrPercentage, + "", "", "", "", "", "", "", "", "", "", "", "", "", + startTimestamp, + startTimestamp}; + + } + + private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) { + + String tribSlot = txMsi.getTribSlot().toString(); + String odtuType = txMsi.getOdtuType().getTypeName(); + String tribPort = txMsi.getTribPort().toString(); + String tribPortPayload = txMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) { + + String tribSlot = rxMsi.getTribSlot().toString(); + String odtuType = rxMsi.getOdtuType().getTypeName(); + String tribPort = rxMsi.getTribPort().toString(); + String tribPortPayload = rxMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + + private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName, + ExpMsi expMsi) { + + String tribSlot = expMsi.getTribSlot().toString(); + String odtuType = expMsi.getOdtuType().getTypeName(); + String tribPort = expMsi.getTribPort().toString(); + String tribPortPayload = expMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + private void persistDevInterfaces(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); + + /*InstanceIdentifier interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) + .child(Interface.class); + Optional interfaceOpt = + 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++) { + Interface deviceInterface; + + deviceInterface = deviceObject.get().getInterface().get(i); + /*if (interfaceOpt.isPresent()) { + deviceInterface = interfaceOpt.get(); + } else { + LOG.warn("Could not get interface info"); + return false; + }*/ + Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection); + + String query = Queries.getQuery().deviceInterfacesInsert().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 persistDevProtocols(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"); + + } else { + String adminstatusEnu = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig() + .getAdminStatus().getName(); + String msgTxtInterval = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig() + .getMsgTxInterval().toString(); + String mxgTxHoldMultiplier = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig() + .getMsgTxHoldMultiplier().toString(); + String startTimestamp = getCurrentTimestamp(); + persistDevProtocolLldpPortConfig(nodeId, connection); + persistDevProtocolLldpNbrList(nodeId, connection); + + Object[] parameters = {nodeId, + adminstatusEnu, + msgTxtInterval, + mxgTxHoldMultiplier, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolInsert().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 persistDevProtocolLldpPortConfig(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(Protocols1.class).getLldp().getPortConfig().size(); i++) { + PortConfig portConfig = + protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().get(i); + String ifName = portConfig.getIfName(); + String adminStatusEnu = portConfig.getAdminStatus().getName(); + + Object[] parameters = {nodeId, + ifName, + adminStatusEnu, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolPortConfigInsert().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 persistDevProtocolLldpNbrList(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.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) { + protocolObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, protocolsIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + + } + if (protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) { + LOG.error("LLDP nbrlist subtree is missing for {}", nodeId); + + } else { + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < protocolObject.get() + .augmentation(Protocols1.class).getLldp().getNbrList().getIfName().size(); i++) { + + IfName ifNameObj = protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() + .getIfName().get(i); + String ifName = ifNameObj.getIfName(); + String remotesysname = ifNameObj.getRemoteSysName(); + String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName(); + String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString(); + String remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getName(); + String remoteportid = ifNameObj.getRemotePortId(); + String remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getName(); + String remotechassisid = ifNameObj.getRemoteChassisId(); + + Object[] parameters = {nodeId, + ifName, + remotesysname, + remotemgmtaddresssubtype, + remotemgmtaddress, + remoteportidsubtypeEnu, + remoteportid, + remotechassisidsubtypeEnu, + remotechassisid, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().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 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); + } + + } + } + + 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.get().getInternalLink() == null) { + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } + if (deviceObject.get().getInternalLink() == null) { + LOG.info("External links not found for {}", nodeId); + } else { + + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getInternalLink().size(); i++) { + InternalLink internalLink = deviceObject.get().getInternalLink().get(i); + String internalLinkName = internalLink.getInternalLinkName(); + String sourceCircuitPackName = internalLink.getSource().getCircuitPackName(); + String sourcePortName = internalLink.getSource().getPortName().toString(); + String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName(); + String destinationPortName = internalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + internalLinkName, + sourceCircuitPackName, + sourcePortName, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceInternalLinkInsert().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 persistDevExternalLinks(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.get().getExternalLink() == null) { + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } + if (deviceObject.get().getExternalLink() == null) { + LOG.info("External links not found for {}", nodeId); + } else { + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getExternalLink().size(); i++) { + ExternalLink externalLink = deviceObject.get().getExternalLink().get(i); + String externalLinkName = externalLink.getExternalLinkName(); + String sourceNodeId = externalLink.getSource().getNodeId(); + String sourceCircuitPackName = externalLink.getSource().getCircuitPackName(); + String sourcePortName = externalLink.getSource().getPortName().toString(); + String destinationNodeId = externalLink.getDestination().getNodeId(); + String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName(); + String destinationPortName = externalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + externalLinkName, + sourceNodeId, + sourceCircuitPackName, + sourcePortName, + destinationNodeId, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceExternalLinkInsert().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 persistDevPhysicalLinks(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.get().getPhysicalLink() == null) { + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } + if (deviceObject.get().getPhysicalLink() == null) { + LOG.info("Physical links not found for {}", nodeId); + } else { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getPhysicalLink().size(); i++) { + PhysicalLink physicalLink = deviceObject.get().getPhysicalLink().get(i); + String physicalLinkName = physicalLink.getPhysicalLinkName(); + String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName(); + String sourcePortName = physicalLink.getSource().getPortName().toString(); + String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName(); + String destinationPortName = physicalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + physicalLinkName, + sourceCircuitPackName, + sourcePortName, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().devicePhysicalLinkInsert().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 persistDevDegree(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.get().getDegree()==null){ + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } */ + if (deviceObject.get().getDegree() == null) { + LOG.warn("Degree info not found for {}", nodeId); + } else { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getDegree().size(); i++) { + Degree degree = deviceObject.get().getDegree().get(i); + String degreeNumber = degree.getDegreeNumber().toString(); + String maxWavelengths = degree.getMaxWavelengths().toString(); + String otdrPortCircuitPackName = + (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getCircuitPackName()); + String otdrPortPortName = + (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getPortName().toString()); + //String mcCapabilitiesSlotWidthGranularity = ""; + //String mcCapabilitiesCenterFreqGranularity = ""; + //String mcCapabilitiesMinSlots = "-1"; + //String mcCapabilitiesMaxSlots = "-1"; + persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection); + persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection); + + Object[] parameters = {nodeId, + degreeNumber, + maxWavelengths, + otdrPortCircuitPackName, + otdrPortPortName, + //mcCapabilitiesSlotWidthGranularity, + //mcCapabilitiesCenterFreqGranularity, + //mcCapabilitiesMinSlots, + //mcCapabilitiesMaxSlots, + "", "", "-1", "-1", + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeInsert().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 persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < degree.getCircuitPacks().size(); i++) { + + String circuitPackIndex = degree.getCircuitPacks().get(i).getIndex().toString(); + String circuitPackName = degree.getCircuitPacks().get(i).getCircuitPackName(); + + Object[] parameters = {nodeId, + degreeNumber, + circuitPackIndex, + circuitPackName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeCircuitPackInsert().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 persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber, + Connection connection) { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < degree.getConnectionPorts().size(); i++) { + + String connectionPortIndex = degree.getConnectionPorts().get(i).getIndex().toString(); + String circuitPackName = degree.getConnectionPorts().get(i).getCircuitPackName(); + String portName = degree.getConnectionPorts().get(i).getPortName().toString(); + + Object[] parameters = {nodeId, + degreeNumber, + connectionPortIndex, + circuitPackName, + portName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeConnectionPortInsert().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 persistDevSrg(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.get().getSharedRiskGroup() == null) { + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } + if (deviceObject.get().getSharedRiskGroup() == null) { + LOG.info("no srg found for node {} ", nodeId); + } else { + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getSharedRiskGroup().size(); i++) { + SharedRiskGroup sharedRiskGroup = deviceObject.get().getSharedRiskGroup().get(i); + //String currentProvisionedAddDropPorts = "-1"; + //String mcCapSlotWidthGranularity = ""; + //String mcCapCenterFreqGranularity = ""; + //String mcCapMinSlots = "-1"; + //String mcCapMaxSlots = "-1"; + String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString(); + String srgNumber = sharedRiskGroup.getSrgNumber().toString(); + String wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getName(); + persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection); + + Object[] parameters = {nodeId, + maxAddDropPorts, + //currentProvisionedAddDropPorts, + "-1", + srgNumber, + wavelengthDuplicationEnu, + //mcCapSlotWidthGranularity, + //mcCapCenterFreqGranularity, + //mcCapMinSlots, + //mcCapMaxSlots, + "", "", "", "", + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceSharedRiskGroupInsert().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 persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber, + 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(); + + Object[] parameters = {nodeId, + srgNumber, + circuitPackindex, + circuitPackName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceSrgCircuitPackInsert().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 persistDevRoadmConnections(String nodeId, Connection connection) { + + //int opticalcontrolmodeEnu=-1; + + 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.get().getRoadmConnections() == null) { + deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + } + + if (deviceObject.get().getRoadmConnections() != null) { + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getRoadmConnections().size(); i++) { + RoadmConnections roadmConnections = deviceObject.get().getRoadmConnections().get(i); + String connectionNumber = roadmConnections.getConnectionNumber(); + //String connectionName = ""; + String wavelengthNumber = roadmConnections.getWavelengthNumber().toString(); + String opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getName(); + String targetOutputPower = roadmConnections.getTargetOutputPower().toString(); + String srcIf = roadmConnections.getSource().getSrcIf(); + String dstIf = roadmConnections.getDestination().getDstIf(); + + Object[] parameters = {nodeId, + //connectionName, + "", + connectionNumber, + wavelengthNumber, + opticalcontrolmodeEnu, + targetOutputPower, + srcIf, + dstIf, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceRoadmConnectionsInsert().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); + } + + } + } else { + LOG.info("ROADM Dev Connections not found!! for {}", nodeId); + } + } + + + private void persistDevConnectionMap(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getConnectionMap().size(); i++) { + ConnectionMap connectionMap = deviceObject.get().getConnectionMap().get(i); + String connectionMapNumber = connectionMap.getConnectionMapNumber().toString(); + String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName(); + String sourcePortName = connectionMap.getSource().getCircuitPackName(); + + + Object[] parameters = {nodeId, + connectionMapNumber, + sourceCircuitPackName, + sourcePortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceConnectionMapInsert().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 persistDevWavelengthMap(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) { + Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i); + String wavelengthNumber = wavelengths.getWavelengthNumber().toString(); + String centerFrequency = wavelengths.getCenterFrequency().toString(); + String wavelength = wavelengths.getWavelength().toString(); + + + Object[] parameters = {nodeId, + wavelengthNumber, + centerFrequency, + wavelength, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceWavelengthInsert().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 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); + + Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm); + + String query = Queries.getQuery().deviceInterfacesInsert().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 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); + + Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi); + + String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().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 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); + + Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi); + + String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().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 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); + + Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi); + + String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().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); + } + } + } + + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java new file mode 100644 index 000000000..4c5ed86e5 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java @@ -0,0 +1,1894 @@ +/* + * Copyright © 2016 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory; + +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.Optional; +import java.util.concurrent.ExecutionException; +import javax.sql.DataSource; + +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.packs.CircuitPacks; +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.interfaces.grp.Interface; +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.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.Degree; +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.SharedRiskGroup; +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.shelf.Slots; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves; +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.nbr.list.IfName; +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.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.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.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class INode221 { + private static final Logger LOG = LoggerFactory.getLogger(INode221.class); + + private final DataSource dataSource; + private final DeviceTransactionManager deviceTransactionManager; + + public INode221(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) { + this.dataSource = dataSource; + this.deviceTransactionManager = deviceTransactionManager; + } + + public boolean addNode(String deviceId) { + + InstanceIdentifier infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class); + Optional infoOpt = + deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + Info deviceInfo; + if (infoOpt.isPresent()) { + deviceInfo = infoOpt.get(); + } else { + LOG.warn("Could not get device info from DataBroker"); + return false; + } + boolean sqlResult = false; + String query = Queries.getQuery().deviceInfoInsert().get(); + LOG.info("Running {} query ", query); + try (Connection connection = dataSource.getConnection(); + 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]); + preparedStatement.setObject(i + 1, prepareParameters[i]); + + } + int executeUpdate = preparedStatement.executeUpdate(); + LOG.info("{} entries were added", executeUpdate); + sqlResult = true; + + LOG.info("iNode AddNode call complete"); + getRoadmShelves(deviceId); + LOG.info("iNode getRoadmShelves call complete"); + getCircuitPacks(deviceId); + LOG.debug("iNode getCircuitPacks call complete"); + + LOG.debug("iNode persist interfaces call"); + persistDevInterfaces(deviceId, connection); + LOG.debug("iNode persist interfaces call complete"); + + LOG.debug("iNode persist interfaces call"); + persistDevInterfaces(deviceId, connection); + LOG.debug("iNode persist interfaces call complete"); + + LOG.debug("iNode persist protocols call"); + persistDevProtocols(deviceId, connection); + LOG.debug("iNode persist protocols call complete"); + + // LOG.debug("iNode persist wavelength map call"); + // persistDevWavelengthMap(deviceId, connection); + // LOG.debug("iNode persist wavelength map call complete"); + + LOG.debug("iNode persist internal links map call"); + persistDevInternalLinks(deviceId, connection); + LOG.debug("iNode persist internal links map call complete"); + + LOG.debug("iNode persist Physical links map call"); + persistDevPhysicalLinks(deviceId, connection); + LOG.debug("iNode persist Physical links map call complete"); + + LOG.debug("iNode persist External links map call"); + persistDevExternalLinks(deviceId, connection); + LOG.debug("iNode persist External links map call complete"); + + LOG.debug("iNode persist degree map call"); + persistDevDegree(deviceId, connection); + LOG.debug("iNode persist degree map call complete"); + + LOG.debug("iNode persist srg map call"); + persistDevSrg(deviceId, connection); + LOG.debug("iNode persist srg map call complete"); + + LOG.debug("iNode persist Roadm Connections call"); + persistDevRoadmConnections(deviceId, connection); + LOG.debug("iNode persist Roadm Connections call complete"); + + LOG.debug("iNode persist Connection Map call"); + 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); + } + return sqlResult; + } + + public boolean nodeExists(String nodeId) { + String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?"; + int nodeExists = 0; + LOG.info("Checking if {} exists in DB", nodeId); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) { + preparedStmt.setString(1, nodeId); + try (ResultSet rs = preparedStmt.executeQuery()) { + while (rs.next()) { + nodeExists = rs.getInt("node_exists"); + LOG.debug("Found {} devices matching {}", nodeExists, nodeId); + } + } + } catch (SQLException e) { + LOG.error(e.getMessage(), e); + } + return nodeExists == 0 ? false : true; + } + + public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException { + InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); + 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); + String shelfName = shelve.getShelfName(); + + LOG.info("Getting Shelve Details of {}", shelfName); + if (shelve.getSlots() != null) { + LOG.info("Slot Size {} ", shelve.getSlots().size()); + persistShelveSlots(nodeId, shelve, connection); + } else { + LOG.info("No Slots for shelf {}", shelfName); + } + + + persistShelves(nodeId, connection, shelve); + } + } catch (SQLException e1) { + LOG.error(e1.getMessage(), e1); + } + } + + public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException { + 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.warn("Device object {} was not found", nodeId); + return; + } + LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().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); + + if (cp.getCpSlots() != null) { + persistCircuitPacksSlots(nodeId, cp, connection); + } + LOG.info("Everything {}", cp); + LOG.info("CP is {}", cp); + + persistPorts(cp, connection); + + persistCircuitPacks(nodeId, connection, cp); + } + } catch (SQLException e1) { + LOG.error(e1.getMessage(), e1); + } + } + + private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) { + Object[] parameters = prepareCircuitPacksParameters(nodeId, cp); + String query = Queries.getQuery().deviceCircuitPackInsert().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 persistShelves(String nodeId, Connection connection, Shelves shelve) { + Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve); + String query = Queries.getQuery().deviceShelfInsert().get(); + LOG.info("Running {} query ", query); + try (PreparedStatement preparedStmt = connection.prepareStatement(query)) { + for (int j = 0; j < shelvesParameter.length; j++) { + preparedStmt.setObject(j + 1, shelvesParameter[j]); + } + preparedStmt.execute(); + preparedStmt.clearParameters(); + } catch (SQLException e) { + LOG.error(e.getMessage(), 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); + LOG.info("Getting Slot Details of {}", slot.getSlotName()); + Object[] parameters = new Object[]{nodeId, + shelves.getShelfName(), + slot.getSlotName(), + slot.getLabel(), + slot.getProvisionedCircuitPack(), + "0", + startTimetampStr, + startTimetampStr}; + String query = Queries.getQuery().deviceShelfSlotInsert().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 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); + + Object[] parameters = new Object[]{nodeId, + circuitPacks.getCircuitPackName(), + cpSlot.getSlotName(), + cpSlot.getLabel(), + cpSlot.getProvisionedCircuitPack(), + null, + startTimetampStr, + startTimetampStr}; + String query = Queries.getQuery().deviceCPSlotInsert().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 persistPorts(CircuitPacks circuitPacks, Connection connection) { + LOG.warn("Ports are not persisted yet"); + } + + + /** + * Prepares parameters for device insert query. + * + * @param deviceInfo device info + * @return Object Object + */ + private static Object[] prepareDeviceInfoParameters(Info deviceInfo) { + String startTimetampStr = getCurrentTimestamp(); + //Integer maxNumBin15minHistoricalPm = null; + //Integer maxNumBin24hourHistoricalPm = null; + //String serialId = ""; + + String nodeId = prepareDashString(deviceInfo.getNodeId()); + Long nodeNumber = deviceInfo.getNodeNumber(); + Integer nodeTypeEnu = deviceInfo.getNodeType().getIntValue(); + String clli = prepareDashString(deviceInfo.getClli()); + String vendor = prepareDashString(deviceInfo.getVendor()); + String model = prepareDashString(deviceInfo.getModel()); + String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue()); + String prefixLength = prepareDashString(deviceInfo.getPrefixLength()); + String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue()); + Integer sourceEnum = deviceInfo.getSource().getIntValue(); + String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue()); + String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength()); + String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue()); + String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue()); + String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion()); + String openroadmVersion = "2.2.1"; + String template = prepareDashString(deviceInfo.getTemplate()); + String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue()); + String geoLatitude = + (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : ""); + String geoLongitude = + (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : ""); + String maxDegrees = prepareDashString(deviceInfo.getMaxDegrees()); // max_degrees + String maxSrgs = prepareDashString(deviceInfo.getMaxSrgs()); //max_srgs + String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version + String swValidationTimer = prepareDashString(""); //sw_validation_timer + String activationDateTime = prepareDashString(""); //activation_date_time + /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId) + .replace("$$NODE-NUMBER$$", nodeNumber) + .replace("$$NODE-TYPE$$",nodeType) + .replace("$$CLLI$$",clli) + .replace("$$VENDOR$$",vendor) + .replace("$$MODEL$$",model) + .replace("$$SERIAL-ID$$",serialId) + .replace("$$IPADDRESS$$",ipAddress) + .replace("$$PREFIX-LENGTH$$",prefixLength) + .replace("$$DEFAULTGATEWAY$$",defaultGateway) + .replace("$$SOURCE$$",String.valueOf(source)) + .replace("$$CURRENT-IPADDRESS$$",currentIpAddress) + .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength) + .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway) + .replace("$$MACADDRESS$$",macAddress) + .replace("$$SOFTWAREVERSION$$",softwareVersion) + .replace("$$OPENROADM-VERSION$$",openroadmVersion) + .replace("$$TEMPLATE$$",template) + .replace("$$CURRENT-DATETIME$$",currentDatetime) + .replace("$$LATITUDE$$",latitude) + .replace("$$LONGITUDE$$",longitude) + .replace("$$MAX-DEGREES$$",maxDegrees) + .replace("$$MAX-SRGS$$",maxSrgs) + .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString("")) + .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString("")) + .replace("$$SW-VERSION$$",swVersion) + .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer) + .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/ + + + return new Object[]{ + nodeId, + nodeNumber, + nodeTypeEnu, + clli, + vendor, + model, + //serialId, + "", + ipAddress, + prefixLength, + defaultGateway, + sourceEnum, + currentIpAddress, + currentPrefixLength, + currentDefaultGateway, + macAddress, + softwareVersion, + openroadmVersion, + template, + currentDatetime, + geoLatitude, + geoLongitude, + maxDegrees, + maxSrgs, + //maxNumBin15minHistoricalPm, + //maxNumBin24hourHistoricalPm, + null, null, + swVersion, + swValidationTimer, + activationDateTime, + startTimetampStr, + startTimetampStr + }; + } + + + private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) { + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + shelve.getShelfName(), + shelve.getShelfType(), + shelve.getRack(), + shelve.getShelfPosition(), + (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()), + shelve.getVendor(), + shelve.getModel(), + shelve.getSerialId(), + shelve.getType(), + shelve.getProductCode(), + (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()), + shelve.getClei(), + shelve.getHardwareVersion(), + (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()), + (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()), + (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()), + startTimestamp, + 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, + cpack.getCircuitPackName(), + cpack.getCircuitPackType(), + cpack.getCircuitPackProductCode(), + (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()), + cpack.getVendor(), + cpack.getModel(), + cpack.getSerialId(), + cpack.getType(), + cpack.getProductCode(), + (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()), + cpack.getClei(), + cpack.getHardwareVersion(), + prepareEmptyString(cpack.getOperationalState().getIntValue()), + cpack.getCircuitPackCategory().getType().getName(), + cpack.getCircuitPackCategory().getExtension(), + (cpack.getEquipmentState() == null ? "" : cpack.getEquipmentState().getIntValue()), + cpack.getCircuitPackMode(), + cpack.getShelf(), + cpack.getSlot(), + cpack.getSubSlot(), + prepareEmptyString(cpack.getDueDate()), + prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" : + ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" : + cpack.getParentCircuitPack().getCircuitPackName()) + ), + prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" : + ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" : + cpack.getParentCircuitPack().getCpSlotName()) + ), + startTimestamp, + 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(); + int operationalState = deviceInterface.getOperationalState().getIntValue(); + int ethernetDuplexEnu = -1; + int ethernetAutoNegotiationEnu = -1; + int maintTestsignalTestpatternEnu = -1; + int maintTestsignalTypeEnu = -1; + int otuFecEnu = -1; + int otuMaintTypeEnu = -1; + //int otsFiberTypeEnu = -1; + String name = deviceInterface.getName(); + String description = deviceInterface.getDescription(); + String type = deviceInterface.getType().getTypeName(); + String circuitId = deviceInterface.getCircuitId(); + String supportingInterface = deviceInterface.getSupportingInterface(); + String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName(); + String supportingPort = deviceInterface.getSupportingPort().toString(); + String ethernetSpeed = ""; + String ethernetFec = ""; + String ethernetMtu = ""; + String ethernetCurrSpeed = ""; + String ethernetCurrDuplex = ""; + //String mciMcttpMinFreq = ""; + //String mciMcttpMaxFreq = ""; + //String mciMcttpCenterFreq = ""; + //String mciMcttpSlotWidth = ""; + //String mciNmcCtpFrequency = ""; + //String mciNmcCtpWidth = ""; + String ochRate = ""; + //String ochFrequency = ""; + //String ochWidth = ""; + //String ochWavelengthNumber = ""; + String ochModulationFormat = ""; + String ochTransmitPower = ""; + String otsSpanLossReceive = ""; + String otsSpanLossTransmit = ""; + //String otsIngressSpanLossAgingMargin = ""; + //String otsEolMaxLoadPin = ""; + String oduRate = ""; //BUG in following case switch statement ??? + //String oduFunction = ""; + String oduMonitoringMode = ""; + //String oduNoOamFunction = ""; + String oduProactiveDelayMeasurementEnabled = ""; + //String oduPoaTribPortNumber = ""; + //String oduTxSapi = ""; + //String oduTxDapi = ""; + //String oduTxOperator = ""; + //String oduAcceptedSapi = ""; + //String oduAcceptedDapi = ""; + //String oduAcceptedOperator = ""; + //String oduExpectedSapi = ""; + //String oduExpectedDapi = ""; + //String oduTimActEnabled = ""; + //String oduTimDetectMode = ""; + //String oduDegmIntervals = ""; + //String oduDegthrPercentage = ""; + String opuPayloadType = ""; + String opuRxPayloadType = ""; + String opuExpPayloadType = ""; + String opuPayloadInterface = ""; + String maintTestsignalEnabled = ""; + String maintTestsignalBiterrors = ""; + String maintTestsignalBiterrorsterminal = ""; + String maintTestsignalSyncseconds = ""; + String maintTestsignalSyncsecondsterminal = ""; + String otuRate = ""; + //String otuTxSapi = ""; + //String otuTxDapi = ""; + //String otuTxOperator = ""; + //String otuAcceptedSapi = ""; + //String otuAcceptedDapi = ""; + //String otuAcceptedOperator = ""; + //String otuExpectedSapi = ""; + //String otuExpectedDapi = ""; + //String otuTimActEnabled = ""; + //String otuTimDetectMode = ""; + //String otuDegmIntervals = ""; + //String otuDegthrPercentage = ""; + String otuMaintLoopbackEnabled = ""; + //String mtOtuRate = ""; + //String mtOtuFec = ""; + //String mtOtuMaintLoopback = ""; + //String mtOtuEnabled = ""; + //String mtOtuType = ""; + + switch (deviceInterface.getType().toString()) { + + case "ethernet": + //EthernetBuilder ethIfBuilder = new EthernetBuilder(); + EthernetBuilder ethIfBuilder = + new EthernetBuilder(deviceInterface.augmentation(Interface1.class).getEthernet()); + ethernetSpeed = ethIfBuilder.getSpeed().toString(); + ethernetFec = ethIfBuilder.getFec().getName(); + ethernetDuplexEnu = ethIfBuilder.getDuplex().getIntValue(); + ethernetMtu = ethIfBuilder.getMtu().toString(); + ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getIntValue(); + ethernetCurrSpeed = ethIfBuilder.getCurrSpeed(); + ethernetCurrDuplex = ethIfBuilder.getCurrDuplex(); + break; + + case "och": + OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1 + .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class) + .getOch()); + ochRate = ochIfBuilder.getRate().getName(); + //ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString(); + ochModulationFormat = ochIfBuilder.getModulationFormat().getName(); + ochTransmitPower = ochIfBuilder.getTransmitPower().toString(); + break; + + case "ots": + OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1 + .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class) + .getOts()); + int otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue(); + otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString(); + otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString(); + break; + + case "odu": + OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class) + .getOdu()); + oduRate = String.valueOf(oduIfBuilder.getRate()); + oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName(); + oduProactiveDelayMeasurementEnabled = oduIfBuilder.isProactiveDelayMeasurementEnabled().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(); + opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface(); + /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection); + persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection); + persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */ + maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().isEnabled().toString(); + maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getIntValue(); + maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getIntValue(); + maintTestsignalBiterrors = oduIfBuilder.getMaintTestsignal().getBitErrors().toString(); + maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString(); + maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds(); + maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal(); + break; + + case "otu": + OtuBuilder otuIfBuilder = new OtuBuilder(deviceInterface.augmentation( + org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class) + .getOtu()); + otuRate = otuIfBuilder.getRate().getName(); + otuFecEnu = otuIfBuilder.getFec().getIntValue(); + otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().isEnabled().toString(); + otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getIntValue(); + break; + + default: + LOG.error("Could not get interface type"); + } + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + name, + description, + type, + Integer.toString(administrativeStateEnu), + Integer.toString(operationalState), + circuitId, + supportingInterface, + supportingCircuitPackName, + supportingPort, + ethernetSpeed, + ethernetFec, + Integer.toString(ethernetDuplexEnu), + ethernetMtu, + Integer.toString(ethernetAutoNegotiationEnu), + ethernetCurrSpeed, + ethernetCurrDuplex, + //mciMcttpMinFreq, + //mciMcttpMaxFreq, + //mciMcttpCenterFreq, + //mciMcttpSlotWidth, + //mciNmcCtpFrequency, + //mciNmcCtpWidth, + "", "", "", "", "", "", + ochRate, + //ochFrequency, + //ochWidth, + //ochWavelengthNumber, + "", "", "", + ochModulationFormat, + ochTransmitPower, + //Integer.toString(otsFiberTypeEnu), + "-1", + otsSpanLossReceive, + otsSpanLossTransmit, + //otsIngressSpanLossAgingMargin, + //otsEolMaxLoadPin, + "", "", + oduRate, + //oduFunction, + "", + oduMonitoringMode, + //oduNoOamFunction, + "", + oduProactiveDelayMeasurementEnabled, + //oduPoaTribPortNumber, + //oduTxSapi, + //oduTxDapi, + //oduTxOperator, + //oduAcceptedSapi, + //oduAcceptedDapi, + //oduAcceptedOperator, + //oduExpectedSapi, + //oduExpectedDapi, + //oduTimActEnabled, + //oduTimDetectMode, + //oduDegmIntervals, + //oduDegthrPercentage, + "", "", "", "", "", "", "", "", "", "", "", "", "", + opuPayloadType, + opuRxPayloadType, + opuExpPayloadType, + opuPayloadInterface, + maintTestsignalEnabled, + Integer.toString(maintTestsignalTestpatternEnu), + Integer.toString(maintTestsignalTypeEnu), + maintTestsignalBiterrors, + maintTestsignalBiterrorsterminal, + maintTestsignalSyncseconds, + maintTestsignalSyncsecondsterminal, + otuRate, + Integer.toString(otuFecEnu), + //otuTxSapi, + //otuTxDapi, + //otuTxOperator, + //otuAcceptedSapi, + //otuAcceptedDapi, + //otuAcceptedOperator, + //otuExpectedSapi, + //otuExpectedDapi, + //otuTimActEnabled, + //otuTimDetectMode, + //otuDegmIntervals, + //otuDegthrPercentage, + "", "", "", "", "", "", "", "", "", "", "", "", + otuMaintLoopbackEnabled, + Integer.toString(otuMaintTypeEnu), + //mtOtuRate, + //mtOtuFec, + //mtOtuMaintLoopback, + //mtOtuEnabled, + //mtOtuType, + "", "", "", "", "", + startTimestamp, + startTimestamp + }; + + } + + private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) { + + + String layer = tcm.getLayer().toString(); + int monitoringModeEnu = tcm.getMonitoringMode().getIntValue(); + String ltcActEnabled = tcm.isLtcActEnabled().toString(); + String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().toString(); + //int tcmDirectionEnu = -1; + //int timDetectModeEnu = -1; + //String txSapi = ""; + //String txDapi = ""; + //String txOperator = ""; + //String acceptedSapi = ""; + //String acceptedDapi = ""; + //String acceptedOperator = ""; + //String expectedSapi = ""; + //String expectedDapi = ""; + //String timActEnabled = ""; + //String degmIntervals = ""; + //String degthrPercentage = ""; + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + layer, + Integer.toString(monitoringModeEnu), + ltcActEnabled, + proactiveDelayMeasurementEnabled, + //Integer.toString(tcmDirectionEnu), + "-1", + //txSapi, + //txDapi, + //txOperator, + //acceptedSapi, + //acceptedDapi, + //acceptedOperator, + //expectedSapi, + //expectedDapi, + //timActEnabled, + "", "", "", "", "", "", "", "", "", + //Integer.toString(timDetectModeEnu), + "-1", + //degmIntervals, + //degthrPercentage, + "", "", + startTimestamp, + startTimestamp}; + + } + + private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) { + + String tribSlot = txMsi.getTribSlot().toString(); + String odtuType = txMsi.getOdtuType().getTypeName(); + String tribPort = txMsi.getTribPort().toString(); + String tribPortPayload = txMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) { + + String tribSlot = rxMsi.getTribSlot().toString(); + String odtuType = rxMsi.getOdtuType().getTypeName(); + String tribPort = rxMsi.getTribPort().toString(); + String tribPortPayload = rxMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + + private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName, + ExpMsi expMsi) { + + String tribSlot = expMsi.getTribSlot().toString(); + String odtuType = expMsi.getOdtuType().getTypeName(); + String tribPort = expMsi.getTribPort().toString(); + String tribPortPayload = expMsi.getTribPortPayload(); + + String startTimestamp = getCurrentTimestamp(); + + return new Object[]{nodeId, + interfaceName, + tribSlot, + odtuType, + tribPort, + tribPortPayload, + startTimestamp, + startTimestamp + }; + + } + + private void persistDevInterfaces(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); + + /*InstanceIdentifier interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) + .child(Interface.class); + Optional interfaceOpt = + 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++) { + Interface deviceInterface; + + deviceInterface = deviceObject.get().getInterface().get(i); + /*if (interfaceOpt.isPresent()) { + deviceInterface = interfaceOpt.get(); + } else { + LOG.warn("Could not get interface info"); + return false; + }*/ + Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection); + + String query = Queries.getQuery().deviceInterfacesInsert().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 persistDevProtocols(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"); + + } + int adminstatusEnu = + protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getAdminStatus() + .getIntValue(); + String msgTxtInterval = + protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxInterval() + .toString(); + String mxgTxHoldMultiplier = + protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxHoldMultiplier() + .toString(); + String startTimestamp = getCurrentTimestamp(); + persistDevProtocolLldpPortConfig(nodeId, connection); + persistDevProtocolLldpNbrList(nodeId, connection); + + Object[] parameters = {nodeId, + Integer.toString(adminstatusEnu), + msgTxtInterval, + mxgTxHoldMultiplier, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolInsert().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 persistDevProtocolLldpPortConfig(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(Protocols1.class).getLldp().getPortConfig().size(); i++) { + + PortConfig portConfig = + protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().get(i); + String ifName = portConfig.getIfName(); + int adminStatusEnu = portConfig.getAdminStatus().getIntValue(); + + Object[] parameters = {nodeId, + ifName, + Integer.toString(adminStatusEnu), + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolPortConfigInsert().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 persistDevProtocolLldpNbrList(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(Protocols1.class).getLldp().getNbrList().getIfName() + .size(); i++) { + + IfName ifNameObj = + protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList().getIfName().get(i); + String ifName = ifNameObj.getIfName(); + String remotesysname = ifNameObj.getRemoteSysName(); + String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName(); + String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString(); + int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue(); + String remoteportid = ifNameObj.getRemotePortId(); + int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue(); + String remotechassisid = ifNameObj.getRemoteChassisId(); + + Object[] parameters = {nodeId, + ifName, + remotesysname, + remotemgmtaddresssubtype, + remotemgmtaddress, + Integer.toString(remoteportidsubtypeEnu), + remoteportid, + Integer.toString(remotechassisidsubtypeEnu), + remotechassisid, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().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 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); + } + + } + } + + 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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getInternalLink().size(); i++) { + InternalLink internalLink = deviceObject.get().getInternalLink().get(i); + String internalLinkName = internalLink.getInternalLinkName(); + String sourceCircuitPackName = internalLink.getSource().getCircuitPackName(); + String sourcePortName = internalLink.getSource().getPortName().toString(); + String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName(); + String destinationPortName = internalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + internalLinkName, + sourceCircuitPackName, + sourcePortName, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceInternalLinkInsert().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 persistDevExternalLinks(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getExternalLink().size(); i++) { + ExternalLink externalLink = deviceObject.get().getExternalLink().get(i); + String externalLinkName = externalLink.getExternalLinkName(); + String sourceNodeId = externalLink.getSource().getNodeId().toString(); + String sourceCircuitPackName = externalLink.getSource().getCircuitPackName(); + String sourcePortName = externalLink.getSource().getPortName().toString(); + String destinationNodeId = externalLink.getDestination().getNodeId().toString(); + String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName(); + String destinationPortName = externalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + externalLinkName, + sourceNodeId, + sourceCircuitPackName, + sourcePortName, + destinationNodeId, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceExternalLinkInsert().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 persistDevPhysicalLinks(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getPhysicalLink().size(); i++) { + PhysicalLink physicalLink = deviceObject.get().getPhysicalLink().get(i); + String physicalLinkName = physicalLink.getPhysicalLinkName(); + String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName(); + String sourcePortName = physicalLink.getSource().getPortName().toString(); + String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName(); + String destinationPortName = physicalLink.getDestination().getPortName().toString(); + + Object[] parameters = {nodeId, + physicalLinkName, + sourceCircuitPackName, + sourcePortName, + destinationCircuitPackName, + destinationPortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().devicePhysicalLinkInsert().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 persistDevDegree(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getDegree().size(); i++) { + Degree degree = deviceObject.get().getDegree().get(i); + String degreeNumber = degree.getDegreeNumber().toString(); + String maxWavelengths = degree.getMaxWavelengths().toString(); + String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName(); + String otdrPortPortName = degree.getOtdrPort().getPortName().toString(); + persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection); + persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection); + //String mcCapabilitiesSlotWidthGranularity = ""; + //String mcCapabilitiesCenterFreqGranularity = ""; + //String mcCapabilitiesMinSlots = ""; + //String mcCapabilitiesMaxSlots = ""; + + Object[] parameters = {nodeId, + degreeNumber, + maxWavelengths, + otdrPortCircuitPackName, + otdrPortPortName, + //mcCapabilitiesSlotWidthGranularity, + //mcCapabilitiesCenterFreqGranularity, + //mcCapabilitiesMinSlots, + //mcCapabilitiesMaxSlots, + "","","","", + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeInsert().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 persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < degree.getCircuitPacks().size(); i++) { + + String circuitPackIndex = degree.getCircuitPacks().get(i).getIndex().toString(); + String circuitPackName = degree.getCircuitPacks().get(i).getCircuitPackName(); + + Object[] parameters = {nodeId, + degreeNumber, + circuitPackIndex, + circuitPackName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeCircuitPackInsert().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 persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber, + Connection connection) { + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < degree.getConnectionPorts().size(); i++) { + + String connectionPortIndex = degree.getConnectionPorts().get(i).getIndex().toString(); + String circuitPackName = degree.getConnectionPorts().get(i).getCircuitPackName(); + String portName = degree.getConnectionPorts().get(i).getPortName().toString(); + + Object[] parameters = {nodeId, + degreeNumber, + connectionPortIndex, + circuitPackName, + portName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceDegreeConnectionPortInsert().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 persistDevSrg(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getSharedRiskGroup().size(); i++) { + SharedRiskGroup sharedRiskGroup = deviceObject.get().getSharedRiskGroup().get(i); + String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString(); + String srgNumber = sharedRiskGroup.getSrgNumber().toString(); + int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue(); + persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection); + //String currentProvisionedAddDropPorts = ""; + //String mcCapSlotWidthGranularity = ""; + //String mcCapCenterFreqGranularity = ""; + //String mcCapMinSlots = ""; + //String mcCapMaxSlots = ""; + + Object[] parameters = {nodeId, + maxAddDropPorts, + //currentProvisionedAddDropPorts, + "", + srgNumber, + //mcCapSlotWidthGranularity, + //mcCapCenterFreqGranularity, + //mcCapMinSlots, + //mcCapMaxSlots, + "","","","", + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceSharedRiskGroupInsert().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 persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber, + 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(); + + Object[] parameters = {nodeId, + srgNumber, + circuitPackindex, + circuitPackName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceSrgCircuitPackInsert().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 persistDevRoadmConnections(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getRoadmConnections().size(); i++) { + RoadmConnections roadmConnections = deviceObject.get().getRoadmConnections().get(i); + int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue(); + //String connectionName = ""; + //String connectionNumber = ""; + //String wavelengthNumber = ""; + String targetOutputPower = roadmConnections.getTargetOutputPower().toString(); + String srcIf = roadmConnections.getSource().getSrcIf(); + String dstIf = roadmConnections.getDestination().getDstIf(); + + Object[] parameters = {nodeId, + //connectionName, + //connectionNumber, + //wavelengthNumber, + "","","", + Integer.toString(opticalcontrolmodeEnu), + targetOutputPower, + srcIf, + dstIf, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceRoadmConnectionsInsert().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 persistDevConnectionMap(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); + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i < deviceObject.get().getConnectionMap().size(); i++) { + ConnectionMap connectionMap = deviceObject.get().getConnectionMap().get(i); + String connectionMapNumber = connectionMap.getConnectionMapNumber().toString(); + String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName(); + String sourcePortName = connectionMap.getSource().getCircuitPackName(); + + + Object[] parameters = {nodeId, + connectionMapNumber, + sourceCircuitPackName, + sourcePortName, + startTimestamp, + startTimestamp + }; + + String query = Queries.getQuery().deviceConnectionMapInsert().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 persistDevWavelengthMap(String nodeId, Connection connection) { + + + String wavelengthNumber="", centerFrequency="", wavelength="";; + + InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); + Optional deviceObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + + + String startTimestamp = getCurrentTimestamp(); + for (int i = 0; i { + + private static final Logger LOG = LoggerFactory.getLogger(ClliNetworkChangeListener.class); + + @Override + public void onDataTreeChanged(Collection> changes) { + LOG.info("Clli network changed {}", changes); + } + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceConfigListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceConfigListener.java new file mode 100644 index 000000000..5e132da80 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceConfigListener.java @@ -0,0 +1,156 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.inventory.listener; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.transportpce.common.StringConstants; +import org.opendaylight.transportpce.inventory.DeviceInventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements the {@link DataTreeChangeListener} on a {@link Node}. + * This listener should be registered on a netconf topology node. + */ +public class DeviceConfigListener implements DataTreeChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(DeviceConfigListener.class); + private final DeviceInventory deviceInventory; + + /** + * Default constructor invoked by blueprint injects {@link DeviceInventory} as a persistence layer. + * + * @param deviceInventory reference to the {@link DeviceInventory} + */ + public DeviceConfigListener(DeviceInventory deviceInventory) { + this.deviceInventory = deviceInventory; + } + + @Override + public void onDataTreeChanged(Collection> changes) { + + //LOG.info("################testing np1:"+changes.toString()); + String openROADMversion = ""; + List> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes); + for (DataTreeModification device : changesWithoutDefaultNetconfNode) { + DataObjectModification rootNode = device.getRootNode(); + String nodeId = rootNode.getDataAfter().key().getNodeId().getValue(); + + LOG.info("################nodeId {}", nodeId); + + NetconfNode netconfNode = rootNode.getDataAfter().augmentation(NetconfNode.class); + NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = + netconfNode.getConnectionStatus(); + long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() + .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)) + .count(); + LOG.info("################## DCL Modification Type {}", + device.getRootNode().getModificationType().toString()); + LOG.info("################## DCL Capability Count {}", count); + LOG.info("################## DCL Connection Status {}", connectionStatus); + if (isCreate(device) || isUpdate(device)) { + LOG.info("Node {} was modified", nodeId); + try { + processModifiedSubtree(nodeId, netconfNode, openROADMversion); + } catch (InterruptedException | ExecutionException e) { + LOG.error(e.getMessage(), e); + } + + } else if (isDelete(device)) { + LOG.info("Node {} was deleted", nodeId); + } + } + } + + /** + * Handles the {@link ModificationType#SUBTREE_MODIFIED} case. + * If the changed node has. + * + * @param nodeId device id + * @param netconfNode netconf node + * @throws InterruptedException may be thrown if there is a problem getting the device from + * datastore + * @throws ExecutionException may be thrown if there is a problem getting the device from datastore + */ + private void processModifiedSubtree(String nodeId, NetconfNode netconfNode, String openROADMversion) + throws InterruptedException, ExecutionException { + NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = netconfNode.getConnectionStatus(); + /*long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() + .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)).count(); + if (count < 1) { + LOG.info("No {} capable device was found", StringConstants.OPENROADM_DEVICE_MODEL_NAME); + return; + } */ + if (ConnectionStatus.Connected.equals(connectionStatus)) { + LOG.info("DCL The device is in {} state", connectionStatus); + deviceInventory.initializeDevice(nodeId, openROADMversion); + } else if (ConnectionStatus.Connecting.equals(connectionStatus) + || ConnectionStatus.UnableToConnect.equals(connectionStatus)) { + LOG.info("DCL The device is in {} state", connectionStatus); + } else { + LOG.warn("DCL Invalid connection status {}", connectionStatus); + } + } + + /** + * Filters the {@link StringConstants#DEFAULT_NETCONF_NODEID} nodes from the provided {@link Collection}. + * + */ + private static List> getRealDevicesOnly(Collection> changes) { + return changes.stream() + .filter(change -> (change.getRootNode().getDataAfter() != null + && !StringConstants.DEFAULT_NETCONF_NODEID + .equalsIgnoreCase(change.getRootNode().getDataAfter().key().getNodeId().getValue()) + && change.getRootNode().getDataAfter().augmentation(NetconfNode.class) != null) + || (change.getRootNode().getDataBefore() != null + && !StringConstants.DEFAULT_NETCONF_NODEID.equalsIgnoreCase( + change.getRootNode().getDataBefore().key().getNodeId().getValue()) + && change.getRootNode().getDataBefore().augmentation(NetconfNode.class) != null + + )).collect(Collectors.toList()); + } + + /** + * In the filtered collection checks if the change is a new write. + * + */ + private static boolean isCreate(DataTreeModification change) { + return change.getRootNode().getDataBefore() == null && change.getRootNode().getDataAfter() != null + && ModificationType.WRITE.equals(change.getRootNode().getModificationType()); + } + + /** + * In the filtered collection checks if the modification is update. + * + */ + private static boolean isUpdate(DataTreeModification change) { + return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType()); + } + + /** + * In the filtered collection checks if the node was deleted. + * + */ + private static boolean isDelete(DataTreeModification change) { + return change.getRootNode().getDataBefore() != null && change.getRootNode().getDataAfter() == null + && ModificationType.DELETE.equals(change.getRootNode().getModificationType()); + } +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java new file mode 100644 index 000000000..70f582222 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java @@ -0,0 +1,158 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.inventory.listener; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.transportpce.common.StringConstants; +import org.opendaylight.transportpce.inventory.DeviceInventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements the {@link DataTreeChangeListener} on a {@link Node}. + * This listener should be registered on a netconf topology node. + */ +public class DeviceListener implements DataTreeChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(DeviceListener.class); + private final DeviceInventory deviceInventory; + + /** + * Default constructor invoked by blueprint injects {@link DeviceInventory} as a persistence layer. + * + * @param deviceInventory reference to the {@link DeviceInventory} + */ + public DeviceListener(DeviceInventory deviceInventory) { + this.deviceInventory = deviceInventory; + } + + @Override + public void onDataTreeChanged(Collection> changes) { + //LOG.debug("testing np1:"+changes.toString()); + String openROADMversion = ""; + List> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes); + for (DataTreeModification device : changesWithoutDefaultNetconfNode) { + String nodeId = device.getRootNode().getDataAfter().key().getNodeId().getValue(); + NetconfNode netconfNode = device.getRootNode().getDataAfter().augmentation(NetconfNode.class); + NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = + netconfNode.getConnectionStatus(); + long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() + .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)) + .count(); + LOG.info("DL ################## Modification Type {}", + device.getRootNode().getModificationType().toString()); + LOG.info("DL ################## Capability Count {}", count); + LOG.info("DL ################## Connection Status {}", connectionStatus); + LOG.info("DL ################## device.getRootNode().getDataBefore() {}", + device.getRootNode().getDataBefore()); + LOG.info("DL ################## device.getRootNode().getDataAfter() {}", + device.getRootNode().getDataAfter()); + + + if (isCreate(device)) { + LOG.info("Node {} was created", nodeId); + try { + processModifiedSubtree(nodeId, netconfNode, openROADMversion); + } catch (InterruptedException | ExecutionException e) { + LOG.error(e.getMessage(), e); + } + } else if (isDelete(device)) { + LOG.info("Node {} was deleted", nodeId); + } + } + } + + /** + * Handles the {@link ModificationType#SUBTREE_MODIFIED} case. + * If the changed node has. + * + * @param nodeId device id + * @param netconfNode netconf node + * @throws InterruptedException may be thrown if there is a problem getting the device from + * datastore + * @throws ExecutionException may be thrown if there is a problem getting the device from datastore + */ + private void processModifiedSubtree(String nodeId, NetconfNode netconfNode, String openROADMversion) + throws InterruptedException, ExecutionException { + NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = netconfNode.getConnectionStatus(); + + long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() + .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)) + .count(); + + if (count < 1) { + LOG.info("No {} capable device was found", StringConstants.OPENROADM_DEVICE_MODEL_NAME); + return; + } + if (ConnectionStatus.Connected.equals(connectionStatus)) { + LOG.info("DL The device is in {} state", connectionStatus); + deviceInventory.initializeDevice(nodeId, openROADMversion); + } else if (ConnectionStatus.Connecting.equals(connectionStatus) + || ConnectionStatus.UnableToConnect.equals(connectionStatus)) { + LOG.info("DL The device is in {} state", connectionStatus); + } else { + LOG.warn("DL Invalid connection status {}", connectionStatus); + } + + } + + /** + * Filters the {@link StringConstants#DEFAULT_NETCONF_NODEID} nodes from the provided {@link Collection}. + * + */ + private static List> getRealDevicesOnly(Collection> changes) { + return changes.stream() + .filter(change -> (change.getRootNode().getDataAfter() != null + && !StringConstants.DEFAULT_NETCONF_NODEID + .equalsIgnoreCase(change.getRootNode().getDataAfter().key().getNodeId().getValue()) + && change.getRootNode().getDataAfter().augmentation(NetconfNode.class) != null) + || (change.getRootNode().getDataBefore() != null + && !StringConstants.DEFAULT_NETCONF_NODEID.equalsIgnoreCase( + change.getRootNode().getDataBefore().key().getNodeId().getValue()) + && change.getRootNode().getDataBefore().augmentation(NetconfNode.class) != null + + )).collect(Collectors.toList()); + } + + /** + * In the filtered collection checks if the change is a new write. + * + */ + private static boolean isCreate(DataTreeModification change) { + return change.getRootNode().getModificationType().toString().equalsIgnoreCase("WRITE"); + } + + /** + * In the filtered collection checks if the modification is update. + * + */ + private static boolean isUpdate(DataTreeModification change) { + return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType()); + } + + /** + * In the filtered collection checks if the node was deleted. + * + */ + private static boolean isDelete(DataTreeModification change) { + return change.getRootNode().getDataBefore() != null && change.getRootNode().getDataAfter() == null + && ModificationType.DELETE.equals(change.getRootNode().getModificationType()); + } +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java new file mode 100644 index 000000000..26fd56d13 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory.listener; + +import java.util.Collection; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OverlayNetworkChangeListener implements DataTreeChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(OverlayNetworkChangeListener.class); + + @Override + public void onDataTreeChanged(Collection> changes) { + LOG.info("Overlay network changed {}", changes); + } + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java new file mode 100644 index 000000000..19b87fae1 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory.listener; + +import java.util.Collection; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UnderlayNetworkChangeListener implements DataTreeChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(UnderlayNetworkChangeListener.class); + + @Override + public void onDataTreeChanged(Collection> changes) { + LOG.info("Underlay network changed {}", changes); + } + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java new file mode 100644 index 000000000..c0b2e34a9 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java @@ -0,0 +1,865 @@ +/* + * Copyright © 2016 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.inventory.query; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + +@SuppressWarnings("checkstyle:LineLength") +public final class Queries { + + private static final String DEVICE_INFO_INSERT = + "INSERT INTO %sinv_dev_info (node_id, node_number, node_type, clli, vendor, model, serial_id, ipAddress, prefix_length, default_gateway, " + + "source, current_ipAddress, current_prefix_length, current_default_gateway, macAddress, software_version, openroadm_version, " + + "template, current_datetime, geo_latitude, geo_longitude, max_degrees, max_srgs, max_num_bin_15min_historical_pm, " + + "max_num_bin_24hour_historical_pm, sw_version, sw_validation_timer, activation_date_time, create_date, update_date) VALUES " + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_SHELF_INSERT = "INSERT INTO %sinv_dev_shelf" + + " (node_id, shelf_name, shelf_type, rack, shelf_position, administrative_state, vendor, model, serial_id, type, product_code, manufacture_date, clei, hardware_version, operational_state, equipment_state, due_date, " + + "create_date, update_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_SHELF_SLOT_INSERT = "INSERT INTO %sinv_dev_shelf_slot " + + " (node_id, shelf_name, slot_name, label, provisioned_circuit_pack, slot_status, create_date, update_date) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_CP_INSERT = "INSERT INTO %sinv_dev_circuit_pack" + + " (node_id, circuit_pack_name, circuit_pack_type, circuit_pack_product_code, administrative_state, vendor, model, serial_id, type, " + + " product_code, manufacture_date, clei, hardware_version, operational_state, cpc_type, cpc_extension, equipment_state, circuit_pack_mode, shelf, slot, " + + " subSlot, due_date, pcp_circuit_pack_name, pcp_cp_slot_name, create_date, update_date) " + + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + + private static final String DEVICE_CP_PORT_INSERT = "INSERT INTO %sinv_dev_cp_ports " + + " (node_id, circuit_pack_name, port_name, port_type, port_qual, port_wavelength_type, port_direction, label, circuit_id, " + + "administrative_state, operational_state, logical_connection_point, partner_port_circuit_pack_name, partner_port_port_name, parent_port_circuit_pack_name, " + + "parent_port_port_name, roadm_port_port_power_capability_min_rx, roadm_port_port_power_capability_min_tx, roadm_port_port_power_capability_max_rx, " + + "roadm_port_port_power_capability_max_tx, roadm_port_capable_wavelengths, roadm_port_available_wavelengths, roadm_port_used_wavelengths, " + + "transponder_port_port_power_capability_min_rx, transponder_port_port_power_capability_min_tx, transponder_port_port_power_capability_max_rx, " + + "transponder_port_port_power_capability_max_tx, transponder_port_capable_wavelengths, otdr_port_launch_cable_length, otdr_port_port_direction, " + + "ila_port_port_power_capability_mix_rx, ila_port_port_power_capability_mix_tx, ila_port_port_power_capability_max_rx, ila_port_port_power_capability_max_tx, " + + "create_date, update_date) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_CP_SLOT_INSERT = "INSERT INTO %sinv_dev_cp_slots " + + " (node_id, circuit_pack_name, slot_name, label, provisioned_circuit_pack, slot_status, slot_type, create_date, update_date) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERFACES_INSERT = "INSERT INTO %sinv_dev_interfaces " + + " (node_id, name, description, type, administrative_state, operational_state, circuit_id, supporting_interface, supporting_circuit_pack_name, " + + "supporting_port, ethernet_speed, ethernet_fec, ethernet_duplex, ethernet_mtu, ethernet_auto_negotiation, ethernet_curr_speed, " + + "ethernet_curr_duplex, mci_mcttp_min_freq, mci_mcttp_max_freq, mci_mcttp_center_freq, mci_mcttp_slot_width, mci_nmc_ctp_frequency, mci_nmc_ctp_width, " + + "och_rate, och_frequency, och_width, och_wavelength_number, och_modulation_format, och_transmit_power, ots_fiber_type, ots_span_loss_receive, " + + "ots_span_loss_transmit, ots_ingress_span_loss_aging_margin, ots_eol_max_load_pin, odu_rate, odu_function, odu_monitoring_mode, odu_no_oam_function, " + + "odu_proactive_delay_measurement_enabled, odu_poa_trib_port_number, odu_tx_sapi, odu_tx_dapi, odu_tx_operator, odu_accepted_sapi, odu_accepted_dapi, " + + "odu_accepted_operator, odu_expected_sapi, odu_expected_dapi, odu_tim_act_enabled, odu_tim_detect_mode, odu_degm_intervals, odu_degthr_percentage, " + + "opu_payload_type, opu_rx_payload_type, opu_exp_payload_type, opu_payload_interface, maint_testsignal_enabled, maint_testsignal_testpattern, " + + "maint_testsignal_type, maint_testsignal_biterrors, maint_testsignal_biterrorsterminal, maint_testsignal_syncseconds, " + + "maint_testsignal_syncsecondsterminal, otu_rate, otu_fec, otu_tx_sapi, otu_tx_dapi, otu_tx_operator, otu_accepted_sapi, otu_accepted_dapi, " + + "otu_accepted_operator, otu_expected_sapi, otu_expected_dapi, otu_tim_act_enabled, otu_tim_detect_mode, otu_degm_intervals, otu_degthr_percentage, " + + "otu_maint_loopback_enabled, otu_maint_type, mt_otu_rate, mt_otu_fec, mt_otu_maint_loopback, mt_otu_enabled, mt_otu_type, create_date, update_date) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERFACE_ODU_OPU_MIS_TX_INSERT = "INSERT INTO %sinv_dev_interface_odu_opu_tx_msi " + + " (node_id, interface_name, trib_slot, odtu_type, trib_port, trib_port_payload, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERFACE_ODU_OPU_MIS_RX_INSERT = "INSERT INTO %sinv_dev_interface_odu_opu_rx_msi " + + " (node_id, interface_name, trib_slot, odtu_type, trib_port, trib_port_payload, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERFACE_ODU_OPU_MIS_EXP_INSERT = "INSERT INTO %sinv_dev_interface_odu_opu_exp_msi " + + " (node_id, interface_name, trib_slot, odtu_type, trib_port, trib_port_payload, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERFACE_TCM_INSERT = "INSERT INTO %sinv_dev_interface_odu_tcm " + + " (node_id, interface_name, layer, monitoring_mode, ltc_act_enabled, proactive_delay_measurement_enabled, tcm_direction, tx_sapi, tx_dapi, tx_operator, accepted_sapi," + + " accepted_dapi, accepted_operator, expected_sapi, expected_dapi, tim_act_enabled, tim_detect_mode, degm_intervals, degthr_percentage, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; + + private static final String DEVICE_PROTOCOL_INSERT = + "INSERT INTO %sinv_dev_proto_lldp" + + "(node_id," + + "adminstatus," + + "msgtxinterval," + + "msgtxholdmultiplier," + + "create_date," + + "update_date )" + + "values ( ?," + + "?," + + "?," + + "?," + + "?," + + "? )"; + + private static final String DEVICE_PROTOCOL_PORT_CONFIG_INSERT = "INSERT INTO %sinv_dev_proto_lldp_port_config " + + " (node_id, ifname, adminstatus, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ? )"; + + + private static final String DEVICE_PROTOCOL_LLDP_NBR_LIST_INSERT = "INSERT INTO %sinv_dev_proto_lldp_nbr_lst " + + " (node_id, ifname, remotesysname, remotemgmtaddresssubtype, remotemgmtaddress, remoteportidsubtype, remoteportid, remotechassisidsubtype, remotechassisid, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + + private static final String DEVICE_PROTOCOL_RSTP_INSERT = "INSERT INTO %sinv_dev_proto_rstp " + + " (node_id, bridge_name, bridge_priority, shutdown, hold_time, hello_time, max_age, forward_delay, transmit_hold_count, " + + "root_bridge_port, root_path_cost, root_bridge_priority, root_bridge_id, root_hold_time, root_hello_time, root_max_age, " + + "root_forward_delay, bridge_id, topo_change_count, time_since_topo_change, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_PROTOCOL_RSTP_BRIDGEPORT_INSERT = "INSERT INTO %sinv_dev_proto_rstp_bridge_port " + + " (node_id, bridge_name, ifname, cost, priority, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_PROTOCOL_RSTP_BRIDGEPORT_ATTR_INSERT = "INSERT INTO %sinv_dev_proto_rstp_bridge_port_attr " + + " (node_id, bridge_name, ifname, bridge_port_state, bridge_port_role, bridge_port_id, open_edge_bridge_port, designated_bridge_port, designated_bridgeid, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + private static final String DEVICE_INTERNAL_LINK_INSERT = "INSERT INTO %sinv_dev_internal_link " + + " (node_id, internal_link_name, source_circuit_pack_name, source_port_name, destination_circuit_pack_name, destination_port_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_EXTERNAL_LINK_INSERT = "INSERT INTO %sinv_dev_external_link " + + " (node_id, external_link_name, source_node_id, source_circuit_pack_name, source_port_name, destination_node_id, destination_circuit_pack_name, destination_port_name, create_date, update_date) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_PHYSICAL_LINK_INSERT = "INSERT INTO %sinv_dev_physical_link " + + " (node_id, physical_link_name, source_circuit_pack_name, source_port_name, destination_circuit_pack_name, destination_port_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_DEGREE_INSERT = "INSERT INTO %sinv_dev_degree " + + " (node_id, degree_number, max_wavelengths, otdr_port_circuit_pack_name, otdr_port_port_name, mc_capabilities_slot_width_granularity, mc_capabilities_center_freq_granularity, mc_capabilities_min_slots, mc_capabilities_max_slots, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_DEGREE_CIRCUITPACK_INSERT = "INSERT INTO %sinv_dev_degree_circuit_packs " + + " (node_id, degree_number, cktpk_index, circuit_pack_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_CONNECTION_PORT_INSERT = "INSERT INTO %sinv_dev_degree_connection_ports " + + " (node_id, degree_number, conn_port_index, circuit_pack_name, port_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_SHARED_RISK_GROUP_INSERT = "INSERT INTO %sinv_dev_srg " + + " (node_id, max_add_drop_ports, current_provisioned_add_drop_ports, srg_number, wavelength_duplication, mc_cap_slot_width_granularity, mc_cap_center_freq_granularity, mc_cap_min_slots, mc_cap_max_slots, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_SRG_CIRCUITPACK_INSERT = "INSERT INTO %sinv_dev_srg_circuit_pack " + + " (node_id, srg_number, ckptk_index, circuit_pack_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_ROADM_CONNECTIONS_INSERT = "INSERT INTO %sinv_dev_roadm_connections " + + " (node_id, connection_name, connection_number, wavelength_number, opticalcontrolmode, target_output_power, src_if, dst_if, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_CONNECTION_MAP_INSERT = "INSERT INTO %sinv_dev_connection_map " + + " (node_id, connection_map_number, source_circuit_pack_name, source_port_name, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + private static final String DEVICE_WAVELENGTH_INSERT = "INSERT INTO %sinv_dev_wavelength_map " + + " (node_id, wavelength_number, center_frequency, wavelength, create_date, update_date ) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + + + private static final String SERVICE_PATH_LIST = + "INSERT INTO %sinv_ser_pathlist ( path_name ) values (?)"; + + private static final String SERVICE_UPDATE = "UPDATE %sinv_ser_main " + + "set " + + "common_id = ? " + + "sdnc_req_header_request_id = ? " + + "sdnc_req_header_rpc_action = ? " + + "sdnc_req_header_notification_url = ? " + + "sdnc_req_header_request_system_id = ? " + + "connection_type = ? " + + "lifecycle_state = ? " + + "administrative_state = ? " + + "operational_state = ? " + + "serv_condition = ? " + + "a_end_service_format = ? " + + "a_end_service_rate = ? " + + "a_end_clli = ? " + + "a_end_node_id = ? " + + "a_end_tx_port_device_name = ? " + + "a_end_tx_port_type = ? " + + "a_end_tx_port_name = ? " + + "a_end_tx_port_rack = ? " + + "a_end_tx_port_shelf = ? " + + "a_end_tx_port_slot = ? " + + "a_end_tx_port_sub_slot = ? " + + "a_end_tx_lgx_device_name = ? " + + "a_end_tx_lgx_port_name = ? " + + "a_end_tx_lgx_port_rack = ? " + + "a_end_tx_lgx_port_shelf = ? " + + "a_end_tx_tail_rnode_id = ? " + + "a_end_tx_xport_cp_name = ? " + + "a_end_tx_xport_port_name = ? " + + "a_end_tx_tail_roadm_port_aid = ? " + + "a_end_tx_tail_roadm_port_rack_loc = ? " + + "a_end_rx_port_device_name = ? " + + "a_end_rx_port_type = ? " + + "a_end_rx_port_name = ? " + + "a_end_rx_port_rack = ? " + + "a_end_rx_port_shelf = ? " + + "a_end_rx_port_slot = ? " + + "a_end_rx_port_sub_slot = ? " + + "a_end_rx_lgx_device_name = ? " + + "a_end_rx_lgx_port_name = ? " + + "a_end_rx_lgx_port_rack = ? " + + "a_end_rx_lgx_port_shelf = ? " + + "a_end_rx_tail_rnode_id = ? " + + "a_end_rx_xport_cp_name = ? " + + "a_end_rx_xport_port_name = ? " + + "a_end_rx_tail_roadm_port_aid = ? " + + "a_end_rx_tail_roadm_port_rack_loc = ? " + + "a_end_optic_type = ? " + + "a_end_router_node_id = ? " + + "a_end_router_ip_address = ? " + + "a_end_router_url = ? " + + "a_end_user_label = ? " + + "z_end_service_format = ? " + + "z_end_service_rate = ? " + + "z_end_clli = ? " + + "z_end_node_id = ? " + + "z_end_tx_port_device_name = ? " + + "z_end_tx_port_type = ? " + + "z_end_tx_port_name = ? " + + "z_end_tx_port_rack = ? " + + "z_end_tx_port_shelf = ? " + + "z_end_tx_port_slot = ? " + + "z_end_tx_port_sub_slot = ? " + + "z_end_tx_lgx_device_name = ? " + + "z_end_tx_lgx_port_name = ? " + + "z_end_tx_lgx_port_rack = ? " + + "z_end_tx_lgx_port_shelf = ? " + + "z_end_tx_tail_rnode_id = ? " + + "z_end_tx_xport_cp_name = ? " + + "z_end_tx_xport_port_name = ? " + + "z_end_tx_tail_roadm_port_aid = ? " + + "z_end_tx_tail_roadm_port_rack_loc = ? " + + "z_end_rx_port_device_name = ? " + + "z_end_rx_port_type = ? " + + "z_end_rx_port_name = ? " + + "z_end_rx_port_rack = ? " + + "z_end_rx_port_shelf = ? " + + "z_end_rx_port_slot = ? " + + "z_end_rx_port_sub_slot = ? " + + "z_end_rx_lgx_device_name = ? " + + "z_end_rx_lgx_port_name = ? " + + "z_end_rx_lgx_port_rack = ? " + + "z_end_rx_lgx_port_shelf = ? " + + "z_end_rx_tail_rnode_id = ? " + + "z_end_rx_xport_cp_name = ? " + + "z_end_rx_xport_port_name = ? " + + "z_end_rx_tail_roadm_port_aid = ? " + + "z_end_rx_tail_roadm_port_rack_loc = ? " + + "z_end_optic_type = ? " + + "z_end_router_node_id = ? " + + "z_end_router_ip_address = ? " + + "z_end_router_url = ? " + + "z_end_user_label " + + "due_date = ? " + + "end_date = ? " + + "nc_code = ? " + + "nci_code = ? " + + "secondary_nci_code = ? " + + "customer = ? " + + "customer_contact = ? " + + "operator_contact = ? " + + "latency = ? " + + "fiber_span_srlgs = ? " + + "supp_serv_name = ? " + + "update_date" + + " where service_name = ? "; + + private static final String SERVICE_EVENT_INSERT = + "INSERT INTO %sinv_ser_events" + + "(event," + + "event_key," + + "event_value," + + "change_key," + + "change_orig_val," + + "change_new_val," + + "event_date )" + + "values ( ?" + + "?" + + "?" + + "?" + + "?" + + "?" + + "? )"; + + private static final String SERVICE_INSERT = + "INSERT INTO %sinv_ser_main " + + "( service_name, " + + "common_id, " + + "sdnc_req_header_request_id, " + + "sdnc_req_header_rpc_action, " + + "sdnc_req_header_notification_url, " + + "sdnc_req_header_request_system_id, " + + "connection_type, " + + "lifecycle_state, " + + "administrative_state, " + + "operational_state, " + + "serv_condition, " + + "a_end_service_format, " + + "a_end_service_rate, " + + "a_end_clli, " + + "a_end_node_id, " + + "a_end_tx_port_device_name, " + + "a_end_tx_port_type, " + + "a_end_tx_port_name, " + + "a_end_tx_port_rack, " + + "a_end_tx_port_shelf, " + + "a_end_tx_port_slot, " + + "a_end_tx_port_sub_slot, " + + "a_end_tx_lgx_device_name, " + + "a_end_tx_lgx_port_name, " + + "a_end_tx_lgx_port_rack, " + + "a_end_tx_lgx_port_shelf, " + + "a_end_tx_tail_rnode_id, " + + "a_end_tx_xport_cp_name, " + + "a_end_tx_xport_port_name, " + + "a_end_tx_tail_roadm_port_aid, " + + "a_end_tx_tail_roadm_port_rack_loc, " + + "a_end_rx_port_device_name, " + + "a_end_rx_port_type, " + + "a_end_rx_port_name, " + + "a_end_rx_port_rack, " + + "a_end_rx_port_shelf, " + + "a_end_rx_port_slot, " + + "a_end_rx_port_sub_slot, " + + "a_end_rx_lgx_device_name, " + + "a_end_rx_lgx_port_name, " + + "a_end_rx_lgx_port_rack, " + + "a_end_rx_lgx_port_shelf, " + + "a_end_rx_tail_rnode_id, " + + "a_end_rx_xport_cp_name, " + + "a_end_rx_xport_port_name, " + + "a_end_rx_tail_roadm_port_aid, " + + "a_end_rx_tail_roadm_port_rack_loc, " + + "a_end_optic_type, " + + "a_end_router_node_id, " + + "a_end_router_ip_address, " + + "a_end_router_url, " + + "a_end_user_label, " + + "z_end_service_format, " + + "z_end_service_rate, " + + "z_end_clli, " + + "z_end_node_id, " + + "z_end_tx_port_device_name, " + + "z_end_tx_port_type, " + + "z_end_tx_port_name, " + + "z_end_tx_port_rack, " + + "z_end_tx_port_shelf, " + + "z_end_tx_port_slot, " + + "z_end_tx_port_sub_slot, " + + "z_end_tx_lgx_device_name, " + + "z_end_tx_lgx_port_name, " + + "z_end_tx_lgx_port_rack, " + + "z_end_tx_lgx_port_shelf, " + + "z_end_tx_tail_rnode_id, " + + "z_end_tx_xport_cp_name, " + + "z_end_tx_xport_port_name, " + + "z_end_tx_tail_roadm_port_aid, " + + "z_end_tx_tail_roadm_port_rack_loc, " + + "z_end_rx_port_device_name, " + + "z_end_rx_port_type, " + + "z_end_rx_port_name, " + + "z_end_rx_port_rack, " + + "z_end_rx_port_shelf, " + + "z_end_rx_port_slot, " + + "z_end_rx_port_sub_slot, " + + "z_end_rx_lgx_device_name, " + + "z_end_rx_lgx_port_name, " + + "z_end_rx_lgx_port_rack, " + + "z_end_rx_lgx_port_shelf, " + + "z_end_rx_tail_rnode_id, " + + "z_end_rx_xport_cp_name, " + + "z_end_rx_xport_port_name, " + + "z_end_rx_tail_roadm_port_aid, " + + "z_end_rx_tail_roadm_port_rack_loc, " + + "z_end_optic_type, " + + "z_end_router_node_id, " + + "z_end_router_ip_address, " + + "z_end_router_url, " + + "z_end_user_label, " + /*+ "hcon_cust_code, " + + "hcon_gen_div_existing_serv, " + + "hcon_gen_div_app_site, " + + "hcon_gen_div_app_node, " + + "hcon_gen_div_app_srlg, " + + "hcon_gen_excl_fiber_bundle, " + + "hcon_gen_excl_site, " + + "hcon_gen_excl_node_id, " + + "hcon_gen_excl_supp_serv_name, " + + "hcon_gen_incl_fiber_bundle, " + + "hcon_gen_incl_site, " + + "hcon_gen_incl_node_id, " + + "hcon_gen_incl_supp_serv_name, " + + "hcon_gen_max_latency, " + + "hcon_corout_existing_serv, " + + "scon_cust_code, " + + "scon_gen_div_existing_serv, " + + "scon_gen_div_app_site, " + + "scon_gen_div_app_node, " + + "scon_gen_div_app_srlg, " + + "scon_gen_excl_fiber_bundle, " + + "scon_gen_excl_site, " + + "scon_gen_excl_node_id, " + + "scon_gen_excl_supp_serv_name, " + + "scon_gen_incl_fiber_bundle, " + + "scon_gen_incl_site, " + + "scon_gen_incl_node_id, " + + "scon_gen_incl_supp_serv_name, " + + "scon_gen_max_latency, " + + "scon_corout_existing_serv, " */ + + "due_date, " + + "end_date, " + + "nc_code, " + + "nci_code, " + + "secondary_nci_code, " + + "customer, " + + "customer_contact, " + + "operator_contact, " + + "latency, " + + "fiber_span_srlgs, " + + "supp_serv_name, " + + "create_date, " + + "update_date) " + + "values ( " + /*+ "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " */ + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?, " + + "?) "; + + + private static final String SERVICE_HCON_CREATE = "insert into @inv_ser_hcon (service_name, customer_code, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_HCON_DIVERSITY_CREATE = "insert into @inv_ser_hcon_diversity_service (service_name, existing_service, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_HCON_DIVERSITY_CAPABILITY_CREATE = "insert into @inv_ser_hcon_diversity_service_capability (service_name, site, node, srlg, create_date, update_date)" + + "values (?, ?, ?, ?, ?) "; + + private static final String SERVICE_HCON_COMPONENT_CREATE = "insert into @inv_ser_hcon_components (service_name, application, component, value, create_date, update_date)" + + "values (?, ?, ?, ?, ?, ?) "; + + private static final String SERVICE_HCON_COROUTING_CREATE = "insert into @inv_ser_hcon_corouting (service_name, existing_service, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_SCON_CREATE = "insert into @inv_ser_scon (service_name, customer_code, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_SCON_DIVERSITY_CREATE = "insert into @inv_ser_scon_diversity_service (service_name, existing_service, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_SCON_DIVERSITY_CAPABILITY_CREATE = "insert into @inv_ser_scon_diversity_service_capability (service_name, site, node, srlg, create_date, update_date)" + + "values (?, ?, ?, ?, ?) "; + + private static final String SERVICE_SCON_COMPONENT_CREATE = "insert into @inv_ser_scon_components (service_name, application, component, value, create_date, update_date)" + + "values (?, ?, ?, ?, ?, ?) "; + + private static final String SERVICE_SCON_COROUTING_CREATE = "insert into @inv_ser_scon_corouting (service_name, existing_service, create_date, update_date)" + + "values (?, ?, ?, ?) "; + + private static final String SERVICE_FIBERSPAN_SRLG_CREATE = "insert into inv_ser_fiber_span_srlgs values (service_name, fiber_span_srlg, create_date, update_date) " + + "values(?, ?, ?, ?)"; + + private static final String SERVICE_EQUIPMENT_SRG_CREATE = "insert into inv_ser_equipment_srgs values (service_name, srg_number, create_date, update_date) " + + "values(?, ?, ?, ?)"; + + private static final String SERVICE_SUPPORTING_SVC_CREATE = "insert into inv_ser_supporting_service values (service_name, supporting_service_name, create_date, update_date) " + + "values(?, ?, ?, ?)"; + + private static final String SERVICE_DELETE = "DELETE FROM %sinv_ser_main WHERE service_name = ?"; + + + private Queries() { + // util class + } + + public static Query getQuery() { + return new Query(); + } + + public static final class Query { + private String sql; + private String schema; + + private Query() { + this.schema = ""; + } + + public Query withSchema(String schema0) { + this.schema = schema0; + return this; + } + + public Query deviceInfoInsert() { + this.sql = DEVICE_INFO_INSERT; + return this; + } + + public Query deviceShelfInsert() { + this.sql = DEVICE_SHELF_INSERT; + return this; + } + + public Query deviceShelfSlotInsert() { + this.sql = DEVICE_SHELF_SLOT_INSERT; + return this; + } + + public Query deviceCircuitPackInsert() { + this.sql = DEVICE_CP_INSERT; + return this; + } + + public Query deviceCPSlotInsert() { + this.sql = DEVICE_CP_SLOT_INSERT; + return this; + } + + public Query deviceCPPortInsert() { + this.sql = DEVICE_CP_PORT_INSERT; + return this; + } + + public Query deviceInterfacesInsert() { + this.sql = DEVICE_INTERFACES_INSERT; + return this; + } + + public Query deviceInterfaceTcmInsert() { + this.sql = DEVICE_INTERFACE_TCM_INSERT; + return this; + } + + public Query deviceInterfaceOtnOduTxMsiInsert() { + this.sql = DEVICE_INTERFACE_ODU_OPU_MIS_TX_INSERT; + return this; + } + + public Query deviceInterfaceOtnOduRxMsiInsert() { + this.sql = DEVICE_INTERFACE_ODU_OPU_MIS_RX_INSERT; + return this; + } + + public Query deviceInterfaceOtnOduExpMsiInsert() { + this.sql = DEVICE_INTERFACE_ODU_OPU_MIS_EXP_INSERT; + return this; + } + + public Query deviceProtocolInsert() { + this.sql = DEVICE_PROTOCOL_INSERT; + return this; + } + + public Query deviceProtocolPortConfigInsert() { + this.sql = DEVICE_PROTOCOL_PORT_CONFIG_INSERT; + return this; + } + + public Query deviceProtocolLldpNbrlistInsert() { + this.sql = DEVICE_PROTOCOL_LLDP_NBR_LIST_INSERT; + return this; + } + + public Query deviceProtocolRstpInsert() { + this.sql = DEVICE_PROTOCOL_RSTP_INSERT; + return this; + } + + public Query deviceProtocolRstpBridgePortInsert() { + this.sql = DEVICE_PROTOCOL_RSTP_BRIDGEPORT_INSERT; + return this; + } + + public Query deviceProtocolRstpBridgePortAttrInsert() { + this.sql = DEVICE_PROTOCOL_RSTP_BRIDGEPORT_ATTR_INSERT; + return this; + } + + public Query deviceInternalLinkInsert() { + this.sql = DEVICE_INTERNAL_LINK_INSERT; + return this; + } + + public Query deviceExternalLinkInsert() { + this.sql = DEVICE_EXTERNAL_LINK_INSERT; + return this; + } + + public Query devicePhysicalLinkInsert() { + this.sql = DEVICE_PHYSICAL_LINK_INSERT; + return this; + } + + + public Query deviceDegreeInsert() { + this.sql = DEVICE_DEGREE_INSERT; + return this; + } + + public Query deviceDegreeCircuitPackInsert() { + this.sql = DEVICE_DEGREE_CIRCUITPACK_INSERT; + return this; + } + + public Query deviceDegreeConnectionPortInsert() { + this.sql = DEVICE_CONNECTION_PORT_INSERT; + return this; + } + + + public Query deviceSharedRiskGroupInsert() { + this.sql = DEVICE_SHARED_RISK_GROUP_INSERT; + return this; + } + + + public Query deviceSrgCircuitPackInsert() { + this.sql = DEVICE_SRG_CIRCUITPACK_INSERT; + return this; + } + + + public Query deviceRoadmConnectionsInsert() { + this.sql = DEVICE_ROADM_CONNECTIONS_INSERT; + return this; + } + + + public Query deviceConnectionMapInsert() { + this.sql = DEVICE_CONNECTION_MAP_INSERT; + return this; + } + + + public Query deviceWavelengthInsert() { + this.sql = DEVICE_WAVELENGTH_INSERT; + return this; + } + + public Query serviceCreate() { + this.sql = SERVICE_INSERT; + return this; + } + + public Query serviceEventCreate() { + this.sql = SERVICE_EVENT_INSERT; + return this; + } + + public Query serviceUpdate() { + this.sql = SERVICE_UPDATE; + return this; + } + + public Query serviceDelete() { + this.sql = SERVICE_DELETE; + return this; + } + + public Query servicePathListCreate() { + this.sql = SERVICE_PATH_LIST; + return this; + } + + public Query serviceHConCreate() { + this.sql = SERVICE_HCON_CREATE; + return this; + } + + public Query serviceHConDiversityCreate() { + this.sql = SERVICE_HCON_DIVERSITY_CREATE; + return this; + } + + public Query serviceHConDiversityCapabilityCreate() { + this.sql = SERVICE_HCON_DIVERSITY_CAPABILITY_CREATE; + return this; + } + + public Query serviceHConComponentCreate() { + this.sql = SERVICE_HCON_COMPONENT_CREATE; + return this; + } + + public Query serviceHConCoroutingCreate() { + this.sql = SERVICE_HCON_COROUTING_CREATE; + return this; + } + + public Query serviceSConDiversityCreate() { + this.sql = SERVICE_SCON_DIVERSITY_CREATE; + return this; + } + + public Query serviceSConDiversityCapabilityCreate() { + this.sql = SERVICE_SCON_DIVERSITY_CAPABILITY_CREATE; + return this; + } + + public Query serviceSConComponentCreate() { + this.sql = SERVICE_SCON_COMPONENT_CREATE; + return this; + } + + public Query serviceSConCoroutingCreate() { + this.sql = SERVICE_SCON_COROUTING_CREATE; + return this; + } + + public Query serviceFiberspanSrlgCreate() { + this.sql = SERVICE_FIBERSPAN_SRLG_CREATE; + return this; + } + + public Query serviceEquipmentSrgCreate() { + this.sql = SERVICE_EQUIPMENT_SRG_CREATE; + return this; + } + + public Query serviceSupportingSvcCreate() { + this.sql = SERVICE_SUPPORTING_SVC_CREATE; + return this; + } + + public String get() { + Preconditions.checkArgument(!Strings.isNullOrEmpty(this.sql), "No query selected"); + return String.format(this.sql, this.schema.concat(".")); + } + } +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java new file mode 100644 index 000000000..d34ca5443 --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory.query; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public final class StatementBuilder { + + private final PreparedStatement statement; + private int index; + + private StatementBuilder(PreparedStatement statement) { + this.statement = statement; + this.index = 1; + } + + public StatementBuilder setParameter(String value) throws SQLException { + this.statement.setString(this.index++, value); + return this; + } + + public StatementBuilder setParameter(Long value) throws SQLException { + this.statement.setLong(this.index++, value); + return this; + } + + public StatementBuilder setParameters(String... strings) throws SQLException { + for (int i = 0; i < strings.length; i++) { + statement.setString(i + 1, strings[i]); + } + return this; + } + + public StatementBuilder reset() { + this.index = 1; + return this; + } + + public static StatementBuilder builder(PreparedStatement statement) { + return new StatementBuilder(statement); + } +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/JsonStringBuilder.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/JsonStringBuilder.java new file mode 100644 index 000000000..6fadc93ba --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/JsonStringBuilder.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2016 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory.utils; + +public final class JsonStringBuilder { + + public static String getDevInfoJson() { + + String devInfoJson = "{ \"info\" : { \n" + + "\"node-id\": \"$$NODE-ID$$\",\n" + + "\"node-number\": \"$$NODE-NUMBER$$\",\n" + + "\"node-type\":\"$$NODE-TYPE$$\",\n" + + "\"clli\":\"$$CLLI$$\",\n" + + "\"vendor\":\"$$VENDOR$$\",\n" + + "\"model\":\"$$MODEL$$\",\n" + + "\"serial-id\":\"$$SERIAL-ID$$\",\n" + + "\"ipAddress\":\"$$IPADDRESS$$\",\n" + + "\"prefix-length\":\"$$PREFIX-LENGTH$$\",\n" + + "\"defaultGateway\":\"$$DEFAULTGATEWAY$$\",\n" + + "\"source\":\"$$SOURCE$$\",\n" + + "\"current-ipAddress\":\"$$CURRENT-IPADDRESS$$\",\n" + + "\"current-prefix-length\":\"$$CURRENT-PREFIX-LENGTH$$\",\n" + + "\"current-defaultGateway\":\"$$CURRENT-DEFAULTGATEWAY$$\",\n" + + "\"macAddress\":\"$$MACADDRESS$$\",\n" + + "\"softwareVersion\":\"$$SOFTWAREVERSION$$\",\n" + + "\"openroadm-version\":\"$$OPENROADM-VERSION$$\",\n" + + "\"template\":\"$$TEMPLATE$$\",\n" + + "\"current-datetime\":\"$$CURRENT-DATETIME$$\",\n" + + "\"geoLocation\": {\n" + + "\"latitude\":\"$$LATITUDE$$\",\n" + + "\"longitude\":\"$$LONGITUDE$$\"\n" + + "},\n" + + "\"max-degrees\":\"$$MAX-DEGREES$$\",\n" + + "\"max-srgs\":\"$$MAX-SRGS$$\",\n" + + "\"max-num-bin-15min-historical-pm\":\"$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$\",\n" + + "\"max-num-bin-24hour-historical-pm\":\"$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$\",\n" + + "\"pending-sw\":{\n" + + "\"sw-version\":\"$$SW-VERSION$$\",\n" + + "\"sw-validation-timer\":\"$$SW-VALIDATION-TIMER$$\",\n" + + "\"activation-date-time\":\"$$ACTIVATION-DATE-TIME$$\"\n" + + "}\n" + + "}\n" + + "}"; + return devInfoJson; + } + + private JsonStringBuilder() { + //not called + } + +} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java new file mode 100644 index 000000000..7f2031ada --- /dev/null +++ b/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java @@ -0,0 +1,80 @@ +/* + * Copyright © 2017 AT&T and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.transportpce.inventory.utils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Utility class which handles strings in inventory project. + * + */ +public final class StringUtils { + public static final String DEFAULT_SQL_DATE = "yyyy-MM-dd HH:mm:ss"; + + private StringUtils() { + // hiding the constructor + } + + /** + * Returns the current timestamp formatted with {@link StringUtils#DEFAULT_SQL_DATE}. + * + * @see StringUtils#getTimestamp(Date) + * @return Timestamp represenation of the given date + */ + public static String getCurrentTimestamp() { + return getTimestamp(new Date()); + } + + /** + * This method will format the provided {@link Date} with the {@link StringUtils#DEFAULT_SQL_DATE} format. + * + * @param date link date + * @return string represenation of the given date + */ + public static String getTimestamp(Date date) { + SimpleDateFormat myTimeStamp = new SimpleDateFormat(DEFAULT_SQL_DATE); + return myTimeStamp.format(date); + } + + /** + * Checks the input object for null and if it's null returns a dash instead. + * + * @param object an object + * @return if object is null a dash is returned, otherwise {@link Object#toString()} + */ + public static String prepareDashString(Object object) { + return prepareString(object, ""); + } + + /** + * Checks the input object for null and if's null returns an empty string instead. + * + * @param object an object + * @return if object is null an empty string is returned, otherwise {@link Object#toString()} + */ + public static String prepareEmptyString(Object object) { + return prepareString(object, ""); + } + + /** + * Checks if the given object is null and returns its representation given by replacement. + * + */ + public static String prepareString(Object objectString, String replacement) { + return objectString == null ? replacement : objectString.toString(); + } + + /** + * Checks if the given object is null and returns -1 . + * + */ + public static String prepareEmptyInt(Object object) { + return (object == null ? "-1" : object.toString()); + } +} diff --git a/inventory/src/main/resources/OSGI-INF/blueprint/inventory-blueprint.xml b/inventory/src/main/resources/OSGI-INF/blueprint/inventory-blueprint.xml new file mode 100644 index 000000000..12100208e --- /dev/null +++ b/inventory/src/main/resources/OSGI-INF/blueprint/inventory-blueprint.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 1139963ba..aae2c2d3a 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL common renderer networkmodel + inventory olm pce -- 2.36.6