public static Class<? extends HBaseTableUtil> getHBaseTableUtilClass(CConfiguration cConf) { // Since we only need the class name, it is fine to have a null namespaceQueryAdmin, // since we do not use the tableUtil instance return new HBaseTableUtilFactory(cConf).get().getClass(); }
/** * Adds extra dependency classes based on the given configuration. */ private Set<Class<?>> addExtraDependencies(CConfiguration cConf, Set<Class<?>> dependencies) { // Only support HBase and KMS when running on premise if (clusterMode == ClusterMode.ON_PREMISE) { dependencies.add(HBaseTableUtilFactory.getHBaseTableUtilClass(cConf)); if (SecureStoreUtils.isKMSBacked(cConf) && SecureStoreUtils.isKMSCapable()) { dependencies.add(SecureStoreUtils.getKMSSecureStore()); } } return dependencies; } }
@Override public HBaseTableUtil get() { return hBaseTableUtilFactory.get(); } }
@Inject HBaseTableUtilProvider(CConfiguration cConf) { this.hBaseTableUtilFactory = new HBaseTableUtilFactory(cConf); }
@Override public HBaseTableUtil get() { return hBaseTableUtilFactory.get(); } }
@Inject HBaseTableUtilProvider(CConfiguration cConf) { this.hBaseTableUtilFactory = new HBaseTableUtilFactory(cConf); }
public static Class<? extends HBaseTableUtil> getHBaseTableUtilClass(CConfiguration cConf) { // Since we only need the class name, it is fine to have a null namespaceQueryAdmin, // since we do not use the tableUtil instance return new HBaseTableUtilFactory(cConf).get().getClass(); }
/** * Adds extra dependency classes based on the given configuration. */ private Set<Class<?>> addExtraDependencies(CConfiguration cConf, Set<Class<?>> dependencies) { // Only support HBase and KMS when running on premise if (clusterMode == ClusterMode.ON_PREMISE) { dependencies.add(HBaseTableUtilFactory.getHBaseTableUtilClass(cConf)); if (SecureStoreUtils.isKMSBacked(cConf) && SecureStoreUtils.isKMSCapable()) { dependencies.add(SecureStoreUtils.getKMSSecureStore()); } } return dependencies; } }
/** * Creates HBase namespace for the cdap system namespace. */ private void createSystemHBaseNamespace() { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) { ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM)); } catch (IOException e) { throw Throwables.propagate(e); } }
Class<?> hbaseTableUtilClass = HBaseTableUtilFactory.getHBaseTableUtilClass(cConf); classes.add(hbaseTableUtilClass); } catch (ProvisionException e) {
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); CoprocessorManager coprocessorManager = new CoprocessorManager(cConf, locationFactory, tableUtil);
Class<?> hbaseTableUtilClass = HBaseTableUtilFactory.getHBaseTableUtilClass(cConf); classes.add(hbaseTableUtilClass); } catch (ProvisionException e) {
private static Map<String, Long> getMapFromTable(String rowType) throws IOException { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); HTable hTable = tableUtil.createHTable(hConf, getReplicationStateTableId(tableUtil)); // Scan the table to scan for all regions. ScanBuilder scan = getScanBuilder(tableUtil, rowType); Result result; HashMap<String, Long> timeMap = new HashMap<>(); try (ResultScanner resultScanner = hTable.getScanner(scan.build())) { while ((result = resultScanner.next()) != null) { ReplicationStatusKey key = new ReplicationStatusKey(result.getRow()); String region = key.getRegionName(); Long timestamp = getTimeFromResult(result, rowType); if (timeMap.get(region) == null || timestamp > timeMap.get(region)) { timeMap.put(region, timestamp); } } } catch (Exception e) { LOG.error("Error while reading table.", e); throw Throwables.propagate(e); } finally { hTable.close(); } return timeMap; }
HBaseTableUtil hBaseTableUtil; try { hBaseTableUtil = new HBaseTableUtilFactory(cConf).get(); } catch (ProvisionException e) { throw new RuntimeException("Unsupported Hbase version " + HBaseVersion.getVersionString());
@BeforeClass public static void setup() throws Exception { conf = TEST_HBASE.getConfiguration(); cConf = CConfiguration.create(); tableUtil = new HBaseTableUtilFactory(cConf).get(); }
/** * Creates the configuration HBase table if it does not exist. */ @VisibleForTesting void createTableIfNecessary() throws IOException { try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, TABLE_NAME); ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(FAMILY), hConf); TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build()); ddlExecutor.createTableIfNotExists(tdBuilder.build(), null); } } }
/** * Creates the configuration HBase table if it does not exist. */ @VisibleForTesting void createTableIfNecessary() throws IOException { try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, TABLE_NAME); ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(FAMILY), hConf); TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build()); ddlExecutor.createTableIfNotExists(tdBuilder.build(), null); } } }
private static void dumpReplicationStateTable() throws Exception { System.out.println("\nThis is all the HBase regions on the Cluster:"); HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); HTable hTable = tableUtil.createHTable(hConf, getReplicationStateTableId(tableUtil)); ScanBuilder scan = tableUtil.buildScan(); scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE)); scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE)); Result result; try (ResultScanner resultScanner = hTable.getScanner(scan.build())) { while ((result = resultScanner.next()) != null) { ReplicationStatusKey key = new ReplicationStatusKey(result.getRow()); String rowType = key.getRowType(); String region = key.getRegionName(); UUID rsID = key.getRsID(); Long writeTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE); Long replicateTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE); System.out.println("Key=>rowType:" + rowType + ":region:" + region + ":RSID:" + rsID + " writeTime:" + writeTime + ":replicateTime:" + replicateTime); } } finally { hTable.close(); } }
@Override public HTable createTable(TableId tableId) throws Exception { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); HTableDescriptorBuilder tableDesc = tableUtil.buildHTableDescriptor(tableId); HColumnDescriptor columnDesc = new HColumnDescriptor(FAMILY); columnDesc.setMaxVersions(Integer.MAX_VALUE); columnDesc.setValue(IncrementHandlerState.PROPERTY_TRANSACTIONAL, "false"); tableDesc.addFamily(columnDesc); tableDesc.addCoprocessor(IncrementHandler.class.getName()); HTableDescriptor htd = tableDesc.build(); TEST_HBASE.getHBaseAdmin().createTable(htd); TEST_HBASE.waitUntilTableAvailable(htd.getName(), 5000); return tableUtil.createHTable(conf, tableId); }
@Override public HTable createTable(TableId tableId) throws Exception { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); HTableDescriptorBuilder tableDesc = tableUtil.buildHTableDescriptor(tableId); HColumnDescriptor columnDesc = new HColumnDescriptor(FAMILY); columnDesc.setMaxVersions(Integer.MAX_VALUE); columnDesc.setValue(IncrementHandlerState.PROPERTY_TRANSACTIONAL, "false"); tableDesc.addFamily(columnDesc); tableDesc.addCoprocessor(IncrementHandler.class.getName()); HTableDescriptor htd = tableDesc.build(); TEST_HBASE.getHBaseAdmin().createTable(htd); TEST_HBASE.waitUntilTableAvailable(htd.getName(), 5000); return tableUtil.createHTable(conf, tableId); }