@Override public int getFreeCapacity() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT SUM(capacity_free) FROM provisioners"); try { return dbQueryExecutor.getNum(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting amount of free capacity", e); } }
@Override public int getNumAssignedWorkers(String tenantID) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT SUM(num_assigned) FROM provisionerWorkers WHERE tenant_id=?"); try { statement.setString(1, tenantID); return dbQueryExecutor.getNum(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception getting number of assigned workers for tenant " + tenantID, e); } }
@Override public int numResources() throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT COUNT(*) FROM pluginMeta WHERE tenant_id=? AND deleted=false"); try { statement.setString(1, tenantId); return dbQueryExecutor.getNum(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting number of resources in the metadata store.", e); throw new IOException(e); } }
@Override public int getHighestVersion(String name) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement( "SELECT MAX(version) FROM pluginMeta WHERE " + "tenant_id=? AND plugin_type=? AND plugin_name=? AND resource_type=? AND name=?"); try { setConstantFields(statement); statement.setString(5, name); return dbQueryExecutor.getNum(statement); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception getting highest version of resource {} for tenant {}.", name, tenant, e); throw new IOException(e); } }