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, INode121 inode121,
31 this.dataSource = dataSource;
32 this.deviceTransactionManager = deviceTransactionManager;
33 this.inode121 = inode121;
34 this.inode221 = inode221;
37 public boolean addNode(String deviceId, String openROADMversion) {
38 boolean sqlResult = false;
39 return inode121.addNode(deviceId);
43 public boolean nodeExists(String nodeId) {
44 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
46 LOG.info("Checking if {} exists in DB", nodeId);
47 try (Connection connection = dataSource.getConnection();
48 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
49 preparedStmt.setString(1, nodeId);
50 try (ResultSet rs = preparedStmt.executeQuery()) {
52 nodeExists = rs.getInt("node_exists");
53 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
56 } catch (SQLException e) {
57 LOG.error(e.getMessage(), e);
59 return nodeExists == 0 ? false : true;
62 public boolean dataExists(String tableName, String searchKeys) {
63 String selectTableSQL = "select count(*) data_exists from " + tableName + " where " + searchKeys;
65 LOG.info("Checking if {} exists in DB", searchKeys);
66 try (Connection connection = dataSource.getConnection();
67 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
69 try (ResultSet rs = preparedStmt.executeQuery()) {
71 dataExists = rs.getInt("data_exists");
72 LOG.debug("Found {} devices matching {}", dataExists, searchKeys);
75 } catch (SQLException e) {
76 LOG.error(e.getMessage(), e);
78 return dataExists == 0 ? false : true;
81 /* public void getRoadmShelves(String nodeId, String openRoadmVersion)
82 throws InterruptedException, ExecutionException {
84 LOG.info("ROADMSHELVES");
85 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
86 inode121.getRoadmShelves(nodeId);
88 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
89 inode22.getRoadmShelves(nodeId);
94 public void getCircuitPacks(String nodeId, String openRoadmVersion)
95 throws InterruptedException, ExecutionException {
97 LOG.info("ROADMCircuitPacks");
98 if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
99 inode121.getCircuitPacks(nodeId);
101 else if (openRoadmVersion.equalsIgnoreCase(StringConstants.OPENROADM_DEVICE_VERSION_2_2)) {
102 inode22.getCircuitPacks(nodeId);