@Override public Provisioner getProvisioner(String id) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT provisioner FROM provisioners WHERE id=?"); statement.setString(1, id); try { return dbQueryExecutor.getQueryItem(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting provisioner " + id, e); } }
@Override public Node getNode(String nodeId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT node FROM nodes WHERE id=? "); statement.setString(1, nodeId); try { return dbQueryExecutor.getQueryItem(statement, Node.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public Cluster getCluster(String clusterId) throws IOException { long clusterNum = Long.parseLong(clusterId); try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectClusterStatement(conn, clusterNum); try { return dbQueryExecutor.getQueryItem(statement, Cluster.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting cluster " + clusterId, e); } }
@Override public Tenant getTenantByID(String id) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT tenant FROM tenants WHERE id=? AND deleted=false"); statement.setString(1, id); try { return dbQueryExecutor.getQueryItem(statement, Tenant.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting tenant with id {}", id, e); throw new IOException(e); } }
@Override public Tenant getTenantByName(String name) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT tenant FROM tenants WHERE name=? AND deleted=false"); statement.setString(1, name); try { return dbQueryExecutor.getQueryItem(statement, Tenant.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting tenant with name {}", name, e); throw new IOException(e); } }
@Override public Map<String, Object> getProfile(Account account) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT profile FROM users WHERE user_id=? AND tenant_id=?"); try { statement.setString(1, account.getUserId()); statement.setString(2, account.getTenantId()); return dbQueryExecutor.getQueryItem(statement, Map.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting profile for account {}.", account, e); throw new IOException(e); } }
@Override public Node getNode(final String nodeId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectNodeStatement(conn, nodeId); try { return dbQueryExecutor.getQueryItem(statement, Node.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting nodes " + nodeId, e); } }
@Override public ClusterJob getClusterJob(JobId jobId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT job FROM jobs WHERE job_num=? AND cluster_id=?"); try { statement.setLong(1, jobId.getJobNum()); statement.setLong(2, Long.parseLong(jobId.getClusterId())); return dbQueryExecutor.getQueryItem(statement, ClusterJob.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting cluster job {}", jobId, e); throw new IOException("Exception getting cluster job " + jobId, e); } }
@Override public ClusterTask getClusterTask(TaskId taskId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT task FROM tasks WHERE task_num=? AND cluster_id=? AND job_num=?"); try { statement.setLong(1, taskId.getTaskNum()); statement.setLong(2, Long.parseLong(taskId.getClusterId())); statement.setLong(3, taskId.getJobNum()); return dbQueryExecutor.getQueryItem(statement, ClusterTask.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting cluster task {}", taskId, e); throw new IOException("Exception getting cluster task " + taskId, e); } }