2 * Copyright © 2016 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.inventory;
11 import java.sql.Connection;
12 import java.sql.PreparedStatement;
13 import java.sql.ResultSet;
14 import java.sql.SQLException;
15 import javax.sql.DataSource;
17 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 private static final Logger LOG = LoggerFactory.getLogger(INode.class);
24 private final DataSource dataSource;
25 private final DeviceTransactionManager deviceTransactionManager;
26 //private final INode221 inode221;
27 private final INode121 inode121;
29 public INode(DataSource dataSource, DeviceTransactionManager deviceTransactionManager,
33 this.dataSource = dataSource;
34 this.deviceTransactionManager = deviceTransactionManager;
35 this.inode121 = inode121;
36 //this.inode221 = inode221;
39 public boolean addNode(String deviceId, String openROADMversion) {
40 boolean sqlResult = false;
41 return inode121.addNode(deviceId);
45 public boolean nodeExists(String nodeId) {
46 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
48 LOG.info("Checking if {} exists in DB", nodeId);
49 try (Connection connection = dataSource.getConnection();
50 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
51 preparedStmt.setString(1, nodeId);
52 try (ResultSet rs = preparedStmt.executeQuery()) {
54 nodeExists = rs.getInt("node_exists");
55 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
58 } catch (SQLException e) {
59 LOG.error(e.getMessage(), e);
61 return nodeExists == 0 ? false : true;
64 public boolean dataExists(String tableName, String searchKeys) {
65 String selectTableSQL = "select count(*) data_exists from " + tableName + " where " + searchKeys;
67 LOG.info("Checking if {} exists in DB", searchKeys);
68 try (Connection connection = dataSource.getConnection();
69 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
71 try (ResultSet rs = preparedStmt.executeQuery()) {
73 dataExists = rs.getInt("data_exists");
74 LOG.debug("Found {} devices matching {}", dataExists, searchKeys);
77 } catch (SQLException e) {
78 LOG.error(e.getMessage(), e);
80 return dataExists == 0 ? false : true;
83 /* public void getRoadmShelves(String nodeId, String openRoadmVersion)
84 throws InterruptedException, ExecutionException {
86 LOG.info("ROADMSHELVES");
87 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
88 inode121.getRoadmShelves(nodeId);
90 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
91 inode22.getRoadmShelves(nodeId);
96 public void getCircuitPacks(String nodeId, String openRoadmVersion)
97 throws InterruptedException, ExecutionException {
99 LOG.info("ROADMCircuitPacks");
100 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
101 inode121.getCircuitPacks(nodeId);
103 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
104 inode22.getCircuitPacks(nodeId);