@Override public HTableDescriptor getHTableDescriptor(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableDescriptor(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<TableId> listTablesInNamespace(HBaseAdmin admin, String namespaceId) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTableDescriptorsByNamespace(HTableNameConverter.encodeHBaseEntity(namespaceId)); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
/** * Construct and return the HBase tableName from {@link TableId} and tablePrefix. */ public static TableName toTableName(String tablePrefix, TableId tableId) { return TableName.valueOf(tableId.getNamespace(), toHBaseTableName(tablePrefix, tableId)); }
/** * @return Backward compatible, ASCII encoded table name */ public static String toHBaseTableName(String tablePrefix, TableId tableId) { Preconditions.checkArgument(tablePrefix != null, "Table prefix should not be null."); return encodeHBaseEntity(getBackwardCompatibleTableName(tablePrefix, tableId)); }
@Override public List<TableId> listTables(HBaseAdmin admin) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTables(); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
@Override public boolean hasNamespace(HBaseAdmin admin, String namespace) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(namespace != null, "Namespace should not be null."); try { admin.getNamespaceDescriptor(HTableNameConverter.encodeHBaseEntity(namespace)); return true; } catch (NamespaceNotFoundException e) { return false; } }
/** * Use this constructor when not inside a coprocessor. This should only happen in: * <ul> * <li>the Master, for writing the configuration</li> * <li>test cases, for writing and reading/verifying</li> * </ul> */ public ConfigurationReader(final Configuration hbaseConf, final CConfiguration cConf) { this(new ConfigurationTableProvider() { private final String tableName = HTableNameConverter.getSysConfigTablePrefix(cConf.get(Constants.Dataset.TABLE_PREFIX)) + TABLE_NAME; @Override public HTableInterface get() throws IOException { return new HTable(hbaseConf, tableName); } @Override public String getTableName() { return tableName; } }); }
@Override public List<TableId> listTables(HBaseAdmin admin) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTables(); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
@Override public boolean hasNamespace(HBaseAdmin admin, String namespace) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(namespace != null, "Namespace should not be null."); try { admin.getNamespaceDescriptor(HTableNameConverter.encodeHBaseEntity(namespace)); return true; } catch (NamespaceNotFoundException e) { return false; } }
/** * @return Backward compatible, ASCII encoded table name */ public static String toHBaseTableName(String tablePrefix, TableId tableId) { Preconditions.checkArgument(tablePrefix != null, "Table prefix should not be null."); return encodeHBaseEntity(getBackwardCompatibleTableName(tablePrefix, tableId)); }
/** * Use this constructor when not inside a coprocessor. This should only happen in: * <ul> * <li>the Master, for writing the configuration</li> * <li>test cases, for writing and reading/verifying</li> * </ul> */ public ConfigurationReader(final Configuration hbaseConf, final CConfiguration cConf) { this(new ConfigurationTableProvider() { private final String tableName = HTableNameConverter.getSysConfigTablePrefix(cConf.get(Constants.Dataset.TABLE_PREFIX)) + TABLE_NAME; @Override public HTableInterface get() throws IOException { return new HTable(hbaseConf, tableName); } @Override public String getTableName() { return tableName; } }); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<TableId> listTablesInNamespace(HBaseAdmin admin, String namespaceId) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTableDescriptorsByNamespace(HTableNameConverter.encodeHBaseEntity(namespaceId)); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
@Override public List<TableId> listTables(HBaseAdmin admin) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTables(); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
/** * Construct and return the HBase tableName from {@link TableId} and tablePrefix. */ public static TableName toTableName(String tablePrefix, TableId tableId) { return TableName.valueOf(tableId.getNamespace(), toHBaseTableName(tablePrefix, tableId)); }
@Override public boolean hasNamespace(HBaseAdmin admin, String namespace) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(namespace != null, "Namespace should not be null."); try { admin.getNamespaceDescriptor(HTableNameConverter.encodeHBaseEntity(namespace)); return true; } catch (NamespaceNotFoundException e) { return false; } }
@Test public void testGetSysConfigTablePrefix() throws Exception { CConfiguration cConf = CConfiguration.create(); String tablePrefix = cConf.get(Constants.Dataset.TABLE_PREFIX); Assert.assertEquals(tablePrefix + "_system:", HTableNameConverter.getSysConfigTablePrefix(tablePrefix)); } }
@Override public HTableDescriptor getHTableDescriptor(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableDescriptor(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<TableId> listTablesInNamespace(HBaseAdmin admin, String namespaceId) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTableDescriptorsByNamespace(HTableNameConverter.encodeHBaseEntity(namespaceId)); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }
@Override public List<TableId> listTables(HBaseAdmin admin) throws IOException { List<TableId> tableIds = Lists.newArrayList(); HTableDescriptor[] hTableDescriptors = admin.listTables(); for (HTableDescriptor hTableDescriptor : hTableDescriptors) { if (isCDAPTable(hTableDescriptor)) { tableIds.add(HTableNameConverter.from(hTableDescriptor)); } } return tableIds; }