use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class HBaseCheck method run.
@Override
public void run() {
LOG.info("Checking HBase version.");
HBaseTableUtil hBaseTableUtil;
try {
hBaseTableUtil = new HBaseTableUtilFactory(cConf).get();
} catch (ProvisionException e) {
throw new RuntimeException("Unsupported Hbase version " + HBaseVersion.getVersionString());
}
LOG.info(" HBase version successfully verified.");
LOG.info("Checking HBase availability.");
try (HConnection hbaseConnection = HConnectionManager.createConnection(hConf)) {
hbaseConnection.listTables();
LOG.info(" HBase availability successfully verified.");
} catch (IOException e) {
throw new RuntimeException("Unable to connect to HBase. " + "Please check that HBase is running and that the correct HBase configuration (hbase-site.xml) " + "and libraries are included in the CDAP master classpath.", e);
}
if (hConf.getBoolean("hbase.security.authorization", false)) {
if (cConf.getBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE)) {
LOG.info("HBase authorization and transaction pruning are enabled. Checking global admin privileges for cdap.");
try {
boolean isGlobalAdmin = hBaseTableUtil.isGlobalAdmin(hConf);
LOG.info("Global admin privileges check status: {}", isGlobalAdmin);
if (isGlobalAdmin) {
return;
}
// if global admin was false then depend on the TX_PRUNE_ACL_CHECK value
if (cConf.getBoolean(Constants.Startup.TX_PRUNE_ACL_CHECK, false)) {
LOG.info("Found {} to be set to true. Continuing with cdap master startup even though global admin check " + "returned false", Constants.Startup.TX_PRUNE_ACL_CHECK);
return;
}
StringBuilder builder = new StringBuilder("Transaction pruning is enabled and cdap does not have global " + "admin privileges in HBase. Global admin privileges for cdap " + "are required for transaction pruning. " + "Either disable transaction pruning or grant global admin " + "privilege to cdap in HBase or can override this " + "check by setting ");
builder.append(Constants.Startup.TX_PRUNE_ACL_CHECK);
builder.append(" in cdap-site.xml.");
if (HBaseVersion.get().equals(HBaseVersion.Version.HBASE_96) || HBaseVersion.get().equals(HBaseVersion.Version.HBASE_98)) {
builder.append(" Detected HBase version ");
builder.append(HBaseVersion.get());
builder.append(" CDAP will not be able determine if it has global admin privilege in HBase.");
builder.append(" After granting global admin privilege please set ");
builder.append(Constants.Startup.TX_PRUNE_ACL_CHECK);
}
throw new RuntimeException(builder.toString());
} catch (IOException e) {
throw new RuntimeException("Unable to determines cdap privileges as global admin in HBase.");
}
}
}
LOG.info("Hbase authorization is disabled. Skipping global admin check for transaction pruning.");
}
use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class IncrementHandlerTest method createTable.
@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);
}
use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class IncrementHandlerTest method createTable.
@Override
public Table 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.createTable(conf, tableId);
}
use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class ConfigurationWriter method createTableIfNecessary.
/**
* 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);
}
}
use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.
the class IncrementHandlerTest method createTable.
@Override
public Table 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.createTable(conf, tableId);
}
Aggregations