@Override public Set<Node> getClusterNodes(String clusterId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); long clusterNum = Long.parseLong(clusterId); try { PreparedStatement statement = getSelectClusterNodesStatement(conn, clusterNum); try { return dbQueryExecutor.getQuerySet(statement, Node.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting nodes for cluster " + clusterId, e); } }
@Override public Set<Node> getAllNodes() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectAllNodesStatement(conn); try { return dbQueryExecutor.getQuerySet(statement, Node.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all nodes"); } }
@Override public Set<ClusterTask> getRunningTasks(long timestamp) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT task FROM tasks WHERE status = ? AND submit_time < ?"); statement.setString(1, ClusterTask.Status.IN_PROGRESS.name()); statement.setTimestamp(2, DBHelper.getTimestamp(timestamp)); try { return dbQueryExecutor.getQuerySet(statement, ClusterTask.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public Set<Cluster> getExpiringClusters(long timestamp) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT cluster FROM clusters WHERE status IN (?, ?) AND expire_time < ?"); statement.setString(1, Cluster.Status.ACTIVE.name()); statement.setString(2, Cluster.Status.INCOMPLETE.name()); statement.setTimestamp(3, DBHelper.getTimestamp(timestamp)); try { return dbQueryExecutor.getQuerySet(statement, Cluster.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }