Inventory init 77/82577/25
authorNarayan Padi <np2698@att.com>
Thu, 28 Mar 2019 17:34:18 +0000 (13:34 -0400)
committerguillaume.lambert <guillaume.lambert@orange.com>
Wed, 20 Nov 2019 10:58:17 +0000 (11:58 +0100)
- 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 <malick.sylla@orange.com>
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
25 files changed:
common/src/main/java/org/opendaylight/transportpce/common/StringConstants.java
features/features-transportpce/pom.xml
features/odl-transportpce-inventory/pom.xml [new file with mode: 0644]
features/odl-transportpce-inventory/src/main/feature/feature.xml [new file with mode: 0644]
features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg [new file with mode: 0644]
features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg [new file with mode: 0644]
features/pom.xml
inventory/pom.xml [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceConfigListener.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/JsonStringBuilder.java [new file with mode: 0644]
inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java [new file with mode: 0644]
inventory/src/main/resources/OSGI-INF/blueprint/inventory-blueprint.xml [new file with mode: 0644]
pom.xml

index 052c02e16ca013d4bb1cf349c14d21d7cd0ab922..bb95bddc37da6247b9b9ce0fda14a940f4138efb 100644 (file)
@@ -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";
 
index 66df3622490cd30c8e73237bd9f848aa5176c2a8..685844e594875321fac8c7469e624de8badcb2ba 100644 (file)
@@ -43,6 +43,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <classifier>features</classifier>
       <type>xml</type>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>odl-transportpce-inventory</artifactId>
+      <version>${project.version}</version>
+      <classifier>features</classifier>
+      <type>xml</type>
+    </dependency>
     <!--dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>odl-transportpce-stubmodels</artifactId>
diff --git a/features/odl-transportpce-inventory/pom.xml b/features/odl-transportpce-inventory/pom.xml
new file mode 100644 (file)
index 0000000..6f2a75b
--- /dev/null
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright © 2016 Orange 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 INTERNAL -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.opendaylight.odlparent</groupId>
+        <artifactId>single-feature-parent</artifactId>
+        <version>5.0.3</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>org.opendaylight.transportpce</groupId>
+    <artifactId>odl-transportpce-inventory</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+    <packaging>feature</packaging>
+
+    <properties>
+        <transportpce.db.host>localhost:3306</transportpce.db.host>
+        <transportpce.db.database>transportpce</transportpce.db.database>
+        <transportpce.db.username>root</transportpce.db.username>
+        <transportpce.db.password>root</transportpce.db.password>
+        <transporpce.device.backup.folder>data/transportpce/devicebackup</transporpce.device.backup.folder>
+        <transporpce.device.backup.prefix></transporpce.device.backup.prefix>
+        <transporpce.device.backup.period>600</transporpce.device.backup.period>
+        <!-- skipping single feature test because DataSource is not available in Pax4j (H2 possible workaround) -->
+        <skip.karaf.featureTest>true</skip.karaf.featureTest>
+    </properties>
+
+    <name>OpenDaylight :: transportpce :: Inventory</name>
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.transportpce</groupId>
+            <artifactId>transportpce-inventory</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.transportpce</groupId>
+            <artifactId>odl-transportpce</artifactId>
+            <version>${project.version}</version>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-resources</id>
+                        <phase>validate</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${basedir}/target/resources</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>
+                                        src/main/resources
+                                    </directory>
+                                    <filtering>true</filtering>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>attach-db-artifact</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>target/resources/org.ops4j.datasource-transporpce.cfg</file>
+                                    <type>cfg</type>
+                                    <classifier>datasource</classifier>
+                                </artifact>
+                                <artifact>
+                                    <file>target/resources/org.opendaylight.transportpce.job.cfg</file>
+                                    <type>cfg</type>
+                                    <classifier>config</classifier>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
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 (file)
index 0000000..f95a755
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-transportpce-inventory">
+    <feature name="odl-transportpce-inventory">
+        <feature>scheduler</feature>
+        <feature>pax-jdbc-mysql</feature>
+        <feature>pax-jdbc-pool-dbcp2</feature>
+        <configfile finalname="etc/org.ops4j.datasource-transportpce.cfg" override="false">
+            mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/datasource
+        </configfile>
+        <configfile finalname="etc/org.opendaylight.transportpce.job.cfg" override="false">
+            mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/config
+        </configfile>
+    </feature>
+</features>
\ 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 (file)
index 0000000..c350584
--- /dev/null
@@ -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 (file)
index 0000000..c10ae34
--- /dev/null
@@ -0,0 +1,6 @@
+osgi.jdbc.driver.name=mysql
+url=jdbc:mysql://${transportpce.db.host}/${transportpce.db.database}?useUnicode=true&amp;characterEncoding=utf8
+pool=dbcp2
+user=${transportpce.db.username}
+password=${transportpce.db.password}
+dataSourceName=transportpce
index 1055e4cbdf124e6c2180c995dea809ab75022a2e..a870f14e485be11ccb48aa35a75c15c87ac866c7 100644 (file)
@@ -28,6 +28,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
     <module>odl-transportpce-ordmodels</module>
     <!--module>odl-transportpce-stubmodels</module-->
     <module>odl-transportpce</module>
+    <module>odl-transportpce-inventory</module>
   </modules>
 
 </project>
diff --git a/inventory/pom.xml b/inventory/pom.xml
new file mode 100644 (file)
index 0000000..62996eb
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!-- Copyright © 2016 Orange 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 -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>4.0.7</version>
+        <relativePath />
+    </parent>
+
+    <groupId>org.opendaylight.transportpce</groupId>
+    <artifactId>transportpce-inventory</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.opendaylight.controller</groupId>
+                <artifactId>mdsal-artifacts</artifactId>
+                <version>1.10.2-SNAPSHOT</version>
+                <scope>import</scope>
+                <type>pom</type>
+            </dependency>
+            <dependency>
+                <groupId>org.opendaylight.netconf</groupId>
+                <artifactId>netconf-artifacts</artifactId>
+                <version>1.7.2-SNAPSHOT</version>
+                <scope>import</scope>
+                <type>pom</type>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>transportpce-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}.ordmodels</groupId>
+            <artifactId>transportpce-ordmodels-device</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>transportpce-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>transportpce-renderer</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller.model</groupId>
+            <artifactId>model-topology</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.netconf</groupId>
+            <artifactId>sal-netconf-connector</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <!--<dependency>
+            <groupId>org.apache.karaf.scheduler</groupId>
+            <artifactId>org.apache.karaf.scheduler.core</artifactId>
+            <version>4.0.9</version>
+            <scope>provided</scope>
+        </dependency> -->
+    </dependencies>
+
+</project>
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 (file)
index 0000000..6f749cf
--- /dev/null
@@ -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 (file)
index 0000000..f31f89d
--- /dev/null
@@ -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 (file)
index 0000000..1ed0e11
--- /dev/null
@@ -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<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
+        Optional<Info> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
+                LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        LOG.info("Shelves size {}", deviceObject.get().getShelves().size());
+        try (Connection connection = dataSource.getConnection()) {
+            Preconditions.checkNotNull(connection);
+            for (int i = 0; i < deviceObject.get().getShelves().size(); i++) {
+                Shelves shelve = deviceObject.get().getShelves().get(i);
+                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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!deviceObject.isPresent()) {
+            LOG.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+           .child(Interface.class);
+        Optional<Interface> 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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        } 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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < protocolObject.get().augmentation(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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (protocolObject.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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < protocolObject.get()
+            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
+            .getRstp().getRstpBridgeInstance().size(); i++) {
+
+            RstpBridgeInstance rstpBridgeInstance = protocolObject.get()
+                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
+                .getRstp().getRstpBridgeInstance().get(i);
+            String bridgeName = rstpBridgeInstance.getBridgeName();
+            String bridgePriority = rstpBridgeInstance.getRstpConfig().getBridgePriority().toString();
+            String shutdown = rstpBridgeInstance.getRstpConfig().getShutdown().toString();
+            String holdTime = rstpBridgeInstance.getRstpConfig().getHoldTime().toString();
+            String helloTime = rstpBridgeInstance.getRstpConfig().getHelloTime().toString();
+            String maxAge = rstpBridgeInstance.getRstpConfig().getMaxAge().toString();
+            String forwardDelay = rstpBridgeInstance.getRstpConfig().getForwardDelay().toString();
+            String transmitHoldCount = rstpBridgeInstance.getRstpConfig().getTransmitHoldCount().toString();
+            String rootBridgePort =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePort().toString();
+            String rootPathCost = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootPathCost().toString();
+            String rootBridgePriority =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePriority().toString();
+            String rootBridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgeId().toString();
+            String rootHoldTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHoldTime().toString();
+            String rootHelloTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHelloTime().toString();
+            String rootMaxAge = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootMaxAge().toString();
+            String rootForwardDelay =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootForwardDelay().toString();
+            String bridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getBridgeId().toString();
+            String topoChangeCount =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTopoChangeCount().toString();
+            String timeSinceTopoChange =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTimeSinceTopoChange().toString();
+
+            persistDevProtocolRstpBridgePort(nodeId, bridgeName, rstpBridgeInstance, connection);
+            persistDevProtocolRstpBridgePortAttr(nodeId, bridgeName, rstpBridgeInstance, connection);
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                bridgePriority,
+                shutdown,
+                holdTime,
+                helloTime,
+                maxAge,
+                forwardDelay,
+                transmitHoldCount,
+                rootBridgePort,
+                rootPathCost,
+                rootBridgePriority,
+                rootBridgeId,
+                rootHoldTime,
+                rootHelloTime,
+                rootMaxAge,
+                rootForwardDelay,
+                bridgeId,
+                topoChangeCount,
+                timeSinceTopoChange,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+    private void persistDevProtocolRstpBridgePort(String nodeId, String bridgeName,
+        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
+
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().size(); i++) {
+            RstpBridgePortTable rstpBridgePortTable =
+                rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().get(i);
+
+            String ifName = rstpBridgePortTable.getIfname();
+            String cost = rstpBridgePortTable.getCost().toString();
+            String priority = rstpBridgePortTable.getPriority().toString();
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                ifName,
+                cost,
+                priority,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpBridgePortInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+    private void persistDevProtocolRstpBridgePortAttr(String nodeId, String bridgeName,
+        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
+
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().size();
+            i++) {
+
+            org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.state.attr
+                .RstpBridgePortTable rstpBridgePortTableAttr =
+                    rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().get(i);
+
+            String ifName = rstpBridgePortTableAttr.getIfname();
+            String bridgePortState = rstpBridgePortTableAttr.getBridgePortState().getName();
+            String bridgePortRole = rstpBridgePortTableAttr.getBridgePortRole().getName();
+            String bridgePortId = rstpBridgePortTableAttr.getBridgePortId().toString();
+            String openEdgeBridgePort = rstpBridgePortTableAttr.getOperEdgeBridgePort().toString();
+            String designatedBridgePort = rstpBridgePortTableAttr.getDesignatedBridgePort().toString();
+            String designatedBridgeId = rstpBridgePortTableAttr.getDesignatedBridgeid().toString();
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                ifName,
+                bridgePortState,
+                bridgePortRole,
+                bridgePortId,
+                openEdgeBridgePort,
+                designatedBridgePort,
+                designatedBridgeId,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpBridgePortAttrInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+
+    private void persistDevInternalLinks(String nodeId, Connection connection) {
+
+        InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+
+        /*if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        if (deviceObject.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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 (file)
index 0000000..4c5ed86
--- /dev/null
@@ -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<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
+        Optional<Info> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
+                LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        LOG.info("Shelves size {}", deviceObject.get().getShelves().size());
+        try (Connection connection = dataSource.getConnection()) {
+            Preconditions.checkNotNull(connection);
+            for (int i = 0; i < deviceObject.get().getShelves().size(); i++) {
+                Shelves shelve = deviceObject.get().getShelves().get(i);
+                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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!deviceObject.isPresent()) {
+            LOG.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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+           .child(Interface.class);
+        Optional<Interface> 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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < protocolObject.get().augmentation(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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < protocolObject.get().augmentation(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<Protocols> protocolsIID =
+                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
+        Optional<Protocols> protocolObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
+            LOG.error("LLDP subtree is missing");
+
+        }
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < protocolObject.get()
+            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
+            .getRstp().getRstpBridgeInstance().size(); i++) {
+
+            RstpBridgeInstance rstpBridgeInstance = protocolObject.get()
+                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
+                .getRstp().getRstpBridgeInstance().get(i);
+            String bridgeName = rstpBridgeInstance.getBridgeName();
+            String bridgePriority = rstpBridgeInstance.getRstpConfig().getBridgePriority().toString();
+            String shutdown = rstpBridgeInstance.getRstpConfig().getShutdown().toString();
+            String holdTime = rstpBridgeInstance.getRstpConfig().getHoldTime().toString();
+            String helloTime = rstpBridgeInstance.getRstpConfig().getHelloTime().toString();
+            String maxAge = rstpBridgeInstance.getRstpConfig().getMaxAge().toString();
+            String forwardDelay = rstpBridgeInstance.getRstpConfig().getForwardDelay().toString();
+            String transmitHoldCount = rstpBridgeInstance.getRstpConfig().getTransmitHoldCount().toString();
+            String rootBridgePort =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePort().toString();
+            String rootPathCost = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootPathCost().toString();
+            String rootBridgePriority =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePriority().toString();
+            String rootBridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgeId().toString();
+            String rootHoldTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHoldTime().toString();
+            String rootHelloTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHelloTime().toString();
+            String rootMaxAge = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootMaxAge().toString();
+            String rootForwardDelay =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootForwardDelay().toString();
+            String bridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getBridgeId().toString();
+            String topoChangeCount =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTopoChangeCount().toString();
+            String timeSinceTopoChange =
+                rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTimeSinceTopoChange().toString();
+
+            persistDevProtocolRstpBridgePort(nodeId, bridgeName, rstpBridgeInstance, connection);
+            persistDevProtocolRstpBridgePortAttr(nodeId, bridgeName, rstpBridgeInstance, connection);
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                bridgePriority,
+                shutdown,
+                holdTime,
+                helloTime,
+                maxAge,
+                forwardDelay,
+                transmitHoldCount,
+                rootBridgePort,
+                rootPathCost,
+                rootBridgePriority,
+                rootBridgeId,
+                rootHoldTime,
+                rootHelloTime,
+                rootMaxAge,
+                rootForwardDelay,
+                bridgeId,
+                topoChangeCount,
+                timeSinceTopoChange,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+    private void persistDevProtocolRstpBridgePort(String nodeId, String bridgeName,
+        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
+
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().size(); i++) {
+            RstpBridgePortTable rstpBridgePortTable =
+                rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().get(i);
+
+            String ifName = rstpBridgePortTable.getIfname();
+            String cost = rstpBridgePortTable.getCost().toString();
+            String priority = rstpBridgePortTable.getPriority().toString();
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                ifName,
+                cost,
+                priority,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpBridgePortInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+    private void persistDevProtocolRstpBridgePortAttr(String nodeId, String bridgeName,
+        RstpBridgeInstance rstpBridgeInstance, Connection connection) {
+
+        String startTimestamp = getCurrentTimestamp();
+        for (int i = 0; i < rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().size();
+            i++) {
+
+            org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.state.attr
+                .RstpBridgePortTable rstpBridgePortTableAttr =
+                    rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().get(i);
+
+            String ifName = rstpBridgePortTableAttr.getIfname();
+            String bridgePortState = rstpBridgePortTableAttr.getBridgePortState().getName();
+            String bridgePortRole = rstpBridgePortTableAttr.getBridgePortRole().getName();
+            String bridgePortId = rstpBridgePortTableAttr.getBridgePortId().toString();
+            String openEdgeBridgePort = rstpBridgePortTableAttr.getOperEdgeBridgePort().toString();
+            String designatedBridgePort = rstpBridgePortTableAttr.getDesignatedBridgePort().toString();
+            String designatedBridgeId = rstpBridgePortTableAttr.getDesignatedBridgeid().toString();
+
+            Object[] parameters = {nodeId,
+                bridgeName,
+                ifName,
+                bridgePortState,
+                bridgePortRole,
+                bridgePortId,
+                openEdgeBridgePort,
+                designatedBridgePort,
+                designatedBridgeId,
+                startTimestamp,
+                startTimestamp
+            };
+
+            String query = Queries.getQuery().deviceProtocolRstpBridgePortAttrInsert().get();
+            LOG.info("Running {} query ", query);
+            try (PreparedStatement stmt = connection.prepareStatement(query)) {
+                for (int j = 0; j < parameters.length; j++) {
+                    stmt.setObject(j + 1, parameters[j]);
+                }
+                stmt.execute();
+                stmt.clearParameters();
+            } catch (SQLException e) {
+                LOG.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+
+    private void persistDevInternalLinks(String nodeId, Connection connection) {
+
+        InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> deviceObject =
+                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+        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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+        Optional<OrgOpenroadmDevice> 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);
+            wavelengthNumber=wavelengths.getWavelengthNumber().toString();
+            centerFrequency=wavelengths.getCenterFrequency().toString();
+            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/ListenerProvider.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java
new file mode 100644 (file)
index 0000000..0e1227d
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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 org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.InstanceIdentifiers;
+import org.opendaylight.transportpce.inventory.listener.ClliNetworkChangeListener;
+import org.opendaylight.transportpce.inventory.listener.DeviceConfigListener;
+import org.opendaylight.transportpce.inventory.listener.DeviceListener;
+import org.opendaylight.transportpce.inventory.listener.OverlayNetworkChangeListener;
+import org.opendaylight.transportpce.inventory.listener.UnderlayNetworkChangeListener;
+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;
+
+/**
+ * {@link ListenerProvider} registers {@link DataTreeChangeListener} for each network layer.
+ */
+public class ListenerProvider {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ListenerProvider.class);
+
+    private final DataBroker dataBroker;
+    private final OverlayNetworkChangeListener overlayNetworkListener;
+    private final UnderlayNetworkChangeListener underlayNetworkListener;
+    private final ClliNetworkChangeListener clliNetworkChangeListener;
+    private final DeviceListener deviceListener;
+    private final DeviceConfigListener deviceConfigListener;
+
+    /**
+     * Constructor invoked by blueprint injects all dependencies.
+     *
+     * @param dataBroker dataBroker
+     * @param overlayNetworkListener  overlay-network Listener
+     * @param underlayNetworkListener underlay-network Listener
+     * @param clliNetworkChangeListener clli Network change Listener
+     * @param deviceListener device listener
+     * @param deviceConfigListener device config listener
+     */
+    public ListenerProvider(DataBroker dataBroker, OverlayNetworkChangeListener overlayNetworkListener,
+        UnderlayNetworkChangeListener underlayNetworkListener, ClliNetworkChangeListener clliNetworkChangeListener,
+        DeviceListener deviceListener, DeviceConfigListener deviceConfigListener) {
+
+        this.dataBroker = dataBroker;
+        this.overlayNetworkListener = overlayNetworkListener;
+        this.underlayNetworkListener = underlayNetworkListener;
+        this.clliNetworkChangeListener = clliNetworkChangeListener;
+        this.deviceListener = deviceListener;
+        this.deviceConfigListener = deviceConfigListener;
+    }
+
+    /**
+     * Invoked by blueprint, registers the listeners.
+     */
+    public void initialize() {
+        LOG.debug("Registering listeners...");
+        dataBroker.registerDataTreeChangeListener(
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II),
+                overlayNetworkListener);
+        LOG.info("Overlay network change listener was successfully registered");
+        dataBroker.registerDataTreeChangeListener(
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.UNDERLAY_NETWORK_II),
+                underlayNetworkListener);
+        LOG.info("Underlay network change listener was successfully registered");
+        dataBroker.registerDataTreeChangeListener(
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.CLLI_NETWORK_II),
+                clliNetworkChangeListener);
+        LOG.info("CLLI network change listener was successfully registered");
+        dataBroker.registerDataTreeChangeListener(
+                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), deviceListener);
+        LOG.info("Device change listener was successfully registered");
+        dataBroker.registerDataTreeChangeListener(
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), deviceConfigListener);
+        LOG.info("Device config change listener was successfully registered");
+    }
+
+}
diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java
new file mode 100644 (file)
index 0000000..2c341d4
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * 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.dto;
+
+@SuppressWarnings({"checkstyle:ParameterName","checkstyle:MemberName"})
+public class InvDevInfo {
+    private String node_id;
+    private String node_number;
+    private String node_type;
+    private String clli;
+    private String vendor;
+    private String model;
+    private String serial_id;
+    private String ipAddress;
+    private String prefix_length;
+    private String default_gateway;
+    private String source;
+    private String current_ipAddress;
+    private String current_prefix_length;
+    private String current_default_gateway;
+    private String macAddress;
+    private String software_version;
+    private String template;
+    private String current_datetime;
+    private String latitude;
+    private String longitude;
+    private String max_degrees;
+    private String max_srgs;
+    private String sw_version;
+    private String sw_validation_timer;
+    private String activation_date_time;
+    private String create_date;
+    private String update_date;
+
+
+    public String getNode_id() {
+        return node_id;
+    }
+
+    public void setNode_id(String node_id) {
+        this.node_id = node_id;
+    }
+
+    public String getNode_number() {
+        return node_number;
+    }
+
+    public void setNode_number(String node_number) {
+        this.node_number = node_number;
+    }
+
+    public String getNode_type() {
+        return node_type;
+    }
+
+    public void setNode_type(String node_type) {
+        this.node_type = node_type;
+    }
+
+    public String getClli() {
+        return clli;
+    }
+
+    public void setClli(String clli) {
+        this.clli = clli;
+    }
+
+    public String getVendor() {
+        return vendor;
+    }
+
+    public void setVendor(String vendor) {
+        this.vendor = vendor;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getSerial_id() {
+        return serial_id;
+    }
+
+    public void setSerial_id(String serial_id) {
+        this.serial_id = serial_id;
+    }
+
+    public String getIpAddress() {
+        return ipAddress;
+    }
+
+    public void setIpAddress(String ipAddress) {
+        this.ipAddress = ipAddress;
+    }
+
+    public String getPrefix_length() {
+        return prefix_length;
+    }
+
+    public void setPrefix_length(String prefix_length) {
+        this.prefix_length = prefix_length;
+    }
+
+    public String getDefault_gateway() {
+        return default_gateway;
+    }
+
+    public void setDefault_gateway(String default_gateway) {
+        this.default_gateway = default_gateway;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
+
+    public String getCurrent_ipAddress() {
+        return current_ipAddress;
+    }
+
+    public void setCurrent_ipAddress(String current_ipAddress) {
+        this.current_ipAddress = current_ipAddress;
+    }
+
+    public String getCurrent_prefix_length() {
+        return current_prefix_length;
+    }
+
+    public void setCurrent_prefix_length(String current_prefix_length) {
+        this.current_prefix_length = current_prefix_length;
+    }
+
+    public String getCurrent_default_gateway() {
+        return current_default_gateway;
+    }
+
+    public void setCurrent_default_gateway(String current_default_gateway) {
+        this.current_default_gateway = current_default_gateway;
+    }
+
+    public String getMacAddress() {
+        return macAddress;
+    }
+
+    public void setMacAddress(String macAddress) {
+        this.macAddress = macAddress;
+    }
+
+    public String getSoftware_version() {
+        return software_version;
+    }
+
+    public void setSoftware_version(String software_version) {
+        this.software_version = software_version;
+    }
+
+    public String getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(String template) {
+        this.template = template;
+    }
+
+    public String getCurrent_datetime() {
+        return current_datetime;
+    }
+
+    public void setCurrent_datetime(String current_datetime) {
+        this.current_datetime = current_datetime;
+    }
+
+    public String getLatitude() {
+        return latitude;
+    }
+
+    public void setLatitude(String latitude) {
+        this.latitude = latitude;
+    }
+
+    public String getLongitude() {
+        return longitude;
+    }
+
+    public void setLongitude(String longitude) {
+        this.longitude = longitude;
+    }
+
+    public String getMax_degrees() {
+        return max_degrees;
+    }
+
+    public void setMax_degrees(String max_degrees) {
+        this.max_degrees = max_degrees;
+    }
+
+    public String getMax_srgs() {
+        return max_srgs;
+    }
+
+    public void setMax_srgs(String max_srgs) {
+        this.max_srgs = max_srgs;
+    }
+
+    public String getSw_version() {
+        return sw_version;
+    }
+
+    public void setSw_version(String sw_version) {
+        this.sw_version = sw_version;
+    }
+
+    public String getSw_validation_timer() {
+        return sw_validation_timer;
+    }
+
+    public void setSw_validation_timer(String sw_validation_timer) {
+        this.sw_validation_timer = sw_validation_timer;
+    }
+
+    public String getActivation_date_time() {
+        return activation_date_time;
+    }
+
+    public void setActivation_date_time(String activation_date_time) {
+        this.activation_date_time = activation_date_time;
+    }
+
+    public String getCreate_date() {
+        return create_date;
+    }
+
+    public void setCreate_date(String create_date) {
+        this.create_date = create_date;
+    }
+
+    public String getUpdate_date() {
+        return update_date;
+    }
+
+    public void setUpdate_date(String update_date) {
+        this.update_date = update_date;
+    }
+}
diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java
new file mode 100644 (file)
index 0000000..4cf13e8
--- /dev/null
@@ -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 ClliNetworkChangeListener implements DataTreeChangeListener<Network> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClliNetworkChangeListener.class);
+
+    @Override
+    public void onDataTreeChanged(Collection<DataTreeModification<Network>> 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 (file)
index 0000000..5e132da
--- /dev/null
@@ -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<Node> {
+
+    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<DataTreeModification<Node>> changes) {
+
+        //LOG.info("################testing np1:"+changes.toString());
+        String openROADMversion = "";
+        List<DataTreeModification<Node>> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes);
+        for (DataTreeModification<Node> device : changesWithoutDefaultNetconfNode) {
+            DataObjectModification<Node> 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<DataTreeModification<Node>> getRealDevicesOnly(Collection<DataTreeModification<Node>> 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<Node> 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<Node> change) {
+        return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType());
+    }
+
+    /**
+     * In the filtered collection checks if the node was deleted.
+     *
+     */
+    private static boolean isDelete(DataTreeModification<Node> 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 (file)
index 0000000..70f5822
--- /dev/null
@@ -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<Node> {
+
+    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<DataTreeModification<Node>> changes) {
+        //LOG.debug("testing np1:"+changes.toString());
+        String openROADMversion = "";
+        List<DataTreeModification<Node>> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes);
+        for (DataTreeModification<Node> 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<DataTreeModification<Node>> getRealDevicesOnly(Collection<DataTreeModification<Node>> 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<Node> change) {
+        return change.getRootNode().getModificationType().toString().equalsIgnoreCase("WRITE");
+    }
+
+    /**
+     * In the filtered collection checks if the modification is update.
+     *
+     */
+    private static boolean isUpdate(DataTreeModification<Node> change) {
+        return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType());
+    }
+
+    /**
+     * In the filtered collection checks if the node was deleted.
+     *
+     */
+    private static boolean isDelete(DataTreeModification<Node> 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 (file)
index 0000000..26fd56d
--- /dev/null
@@ -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<Network> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(OverlayNetworkChangeListener.class);
+
+    @Override
+    public void onDataTreeChanged(Collection<DataTreeModification<Network>> 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 (file)
index 0000000..19b87fa
--- /dev/null
@@ -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<Network> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(UnderlayNetworkChangeListener.class);
+
+    @Override
+    public void onDataTreeChanged(Collection<DataTreeModification<Network>> 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 (file)
index 0000000..c0b2e34
--- /dev/null
@@ -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 (file)
index 0000000..d34ca54
--- /dev/null
@@ -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 (file)
index 0000000..6fadc93
--- /dev/null
@@ -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 (file)
index 0000000..7f2031a
--- /dev/null
@@ -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 (file)
index 0000000..1210020
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!-- Copyright © 2016 Orange 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 -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+           odl:use-default-for-reference-types="true">
+
+    <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"
+               odl:type="default"/>
+    <reference id="dataSource" interface="javax.sql.DataSource"/>
+    <reference id="deviceTransactionManager"
+               interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager"/>
+
+    <bean id="deviceInventory" class="org.opendaylight.transportpce.inventory.DeviceInventory">
+        <argument ref="dataSource"/>
+        <argument ref="iNodeImpl"/>
+        <argument ref="deviceTransactionManager"/>
+    </bean>
+
+    <bean id="iNode22" class="org.opendaylight.transportpce.inventory.INode22">
+        <argument ref="dataSource"/>
+        <argument ref="deviceTransactionManager"/>
+    </bean>
+
+    <bean id="iNode121" class="org.opendaylight.transportpce.inventory.INode121">
+        <argument ref="dataSource"/>
+        <argument ref="deviceTransactionManager"/>
+    </bean>
+
+    <bean id="iNodeImpl" class="org.opendaylight.transportpce.inventory.INode">
+        <argument ref="dataSource"/>
+        <argument ref="deviceTransactionManager"/>
+        <argument ref="iNode121"/>
+        <argument ref="iNode22"/>
+    </bean>
+
+    <bean id="overlayNetworkChangeListener"
+          class="org.opendaylight.transportpce.inventory.listener.OverlayNetworkChangeListener"/>
+    <bean id="underlayNetworkChangeListener"
+          class="org.opendaylight.transportpce.inventory.listener.UnderlayNetworkChangeListener"/>
+    <bean id="clliNetworkChangeListener"
+          class="org.opendaylight.transportpce.inventory.listener.ClliNetworkChangeListener"/>
+
+    <bean id="deviceListener" class="org.opendaylight.transportpce.inventory.listener.DeviceListener">
+        <argument ref="deviceInventory"/>
+    </bean>
+
+    <bean id="deviceConfigListener" class="org.opendaylight.transportpce.inventory.listener.DeviceConfigListener">
+        <argument ref="deviceInventory"/>
+    </bean>
+
+    <bean id="listenerProvider" class="org.opendaylight.transportpce.inventory.ListenerProvider"
+          init-method="initialize">
+        <argument ref="dataBroker"/>
+        <argument ref="overlayNetworkChangeListener"/>
+        <argument ref="underlayNetworkChangeListener"/>
+        <argument ref="clliNetworkChangeListener"/>
+        <argument ref="deviceListener"/>
+        <argument ref="deviceConfigListener"/>
+    </bean>
+
+</blueprint>
diff --git a/pom.xml b/pom.xml
index 1139963ba6560f250573107f72f49eeec900aa2d..aae2c2d3a94f50259960385e13e6caf3627f2dca 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
     <module>common</module>
     <module>renderer</module>
     <module>networkmodel</module>
+    <module>inventory</module>
     <module>olm</module>
     <!--module>tests</module-->
     <module>pce</module>