/** * Queries the store for a list of items, deserializing the items and returning an immutable list of them. If no items * exist, the list will be empty. Statement passed in must be closed by the caller. * * @param statement PreparedStatement of the query, ready for execution. * @param clazz Class of the items being queried. * @param <T> Type of the items being queried. * @return Immutable list of objects that were queried for. * @throws java.sql.SQLException */ public <T> ImmutableList<T> getQueryList(PreparedStatement statement, Class<T> clazz) throws SQLException { return getQueryList(statement, clazz, Integer.MAX_VALUE); }
/** * Queries the store for a list of at most limit items, deserializing the items and performing a transform before * before placing the transformed object into the output, finally returning an immutable list of transformed items. * If no items exist, the list will be empty. Statement passed in must be closed by the caller. * * @param statement PreparedStatement of the query, ready for execution. * @param clazz Class of the items being queried in the statement. * @param transform Transform to perform to change the deserialized object in the table to the object in the output. * @param <F> Type of item being queried * @param <T> Type of item to return * @return Immutable list of transformed objects that were queried for. * @throws SQLException */ public <F, T> ImmutableList<T> getQueryList(PreparedStatement statement, Class<F> clazz, Function<F, T> transform) throws SQLException { return getQueryList(statement, clazz, transform, Integer.MAX_VALUE); }
@Override public Collection<Provisioner> getAllProvisioners() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT provisioner FROM provisioners"); try { return dbQueryExecutor.getQueryList(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all provisioners", e); } }
@Override public List<Tenant> getAllTenants() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT tenant FROM tenants WHERE deleted=false"); try { return dbQueryExecutor.getQueryList(statement, Tenant.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting all tenants", e); throw new IOException(e); } }
@Override public Collection<Provisioner> getProvisionersWithFreeCapacity() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT provisioner FROM provisioners WHERE capacity_free > 0"); try { return dbQueryExecutor.getQueryList(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all provisioners", e); } }
@Override public Collection<Provisioner> getTenantProvisioners(String tenantId) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT P.provisioner FROM provisioners P, provisionerWorkers W" + " WHERE W.tenant_id=? AND P.id=W.provisioner_id AND W.num_assigned > 0"); try { statement.setString(1, tenantId); return dbQueryExecutor.getQueryList(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all provisioners", e); } }
@Override public List<TenantSpecification> getAllTenantSpecifications() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT tenant FROM tenants WHERE deleted=false"); try { return dbQueryExecutor.getQueryList(statement, Tenant.class, new Function<Tenant, TenantSpecification>() { @Override public TenantSpecification apply(Tenant input) { return input.getSpecification(); } }); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting all tenants", e); throw new IOException(e); } }
@Override public List<ClusterJob> getClusterJobs(String clusterId, int limit) throws IOException { long clusterNum = Long.parseLong(clusterId); try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectClusterJobsStatement(conn, clusterNum); try { return dbQueryExecutor.getQueryList(statement, ClusterJob.class, limit); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting cluster jobs for cluster " + clusterId + " with limit " + limit, e); } }
@Override public Collection<Provisioner> getTimedOutProvisioners(long idleTimestamp) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT provisioner FROM provisioners WHERE last_heartbeat < ?"); try { statement.setTimestamp(1, DBHelper.getTimestamp(idleTimestamp)); return dbQueryExecutor.getQueryList(statement, Provisioner.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all provisioners", e); } }
@Override public List<Cluster> getNonTerminatedClusters() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectNonTerminatedClusters(conn); try { return dbQueryExecutor.getQueryList(statement, Cluster.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all clusters"); } }
@Override public List<Cluster> getAllClusters() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = getSelectAllClustersStatement(conn); try { return dbQueryExecutor.getQueryList(statement, Cluster.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting all clusters"); } }
index = initializeFilter(statement, filter.getClusterId(), index); initializeFilter(statement, filter.getClusterTemplate(), index); return dbQueryExecutor.getQueryList(statement, ClusterTask.class); } finally { statement.close();