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;
16 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 private static final Logger LOG = LoggerFactory.getLogger(INode.class);
23 private final DataSource dataSource;
24 private final DeviceTransactionManager deviceTransactionManager;
25 //private final INode221 inode221;
26 private final INode121 inode121;
28 public INode(DataSource dataSource, DeviceTransactionManager deviceTransactionManager,
32 this.dataSource = dataSource;
33 this.deviceTransactionManager = deviceTransactionManager;
34 this.inode121 = inode121;
35 //this.inode221 = inode221;
38 public boolean addNode(String deviceId, String openROADMversion) {
39 boolean sqlResult = false;
40 return inode121.addNode(deviceId);
44 public boolean nodeExists(String nodeId) {
45 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
47 LOG.info("Checking if {} exists in DB", nodeId);
48 try (Connection connection = dataSource.getConnection();
49 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
50 preparedStmt.setString(1, nodeId);
51 try (ResultSet rs = preparedStmt.executeQuery()) {
53 nodeExists = rs.getInt("node_exists");
54 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
57 } catch (SQLException e) {
58 LOG.error(e.getMessage(), e);
60 return nodeExists == 0 ? false : true;
63 public boolean dataExists(String tableName, String searchKeys) {
64 String selectTableSQL = "select count(*) data_exists from " + tableName + " where " + searchKeys;
66 LOG.info("Checking if {} exists in DB", searchKeys);
67 try (Connection connection = dataSource.getConnection();
68 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
70 try (ResultSet rs = preparedStmt.executeQuery()) {
72 dataExists = rs.getInt("data_exists");
73 LOG.debug("Found {} devices matching {}", dataExists, searchKeys);
76 } catch (SQLException e) {
77 LOG.error(e.getMessage(), e);
79 return dataExists == 0 ? false : true;
82 /* public void getRoadmShelves(String nodeId, String openRoadmVersion)
83 throws InterruptedException, ExecutionException {
85 LOG.info("ROADMSHELVES");
86 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
87 inode121.getRoadmShelves(nodeId);
89 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
90 inode22.getRoadmShelves(nodeId);
95 public void getCircuitPacks(String nodeId, String openRoadmVersion)
96 throws InterruptedException, ExecutionException {
98 LOG.info("ROADMCircuitPacks");
99 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
100 inode121.getCircuitPacks(nodeId);
102 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
103 inode22.getCircuitPacks(nodeId);