Search in sources :

Example 66 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by cdapio.

the class HBaseMetadataTableTestRun method setupBeforeClass.

@BeforeClass
public static void setupBeforeClass() throws Exception {
    hConf = HBASE_TEST_BASE.getConfiguration();
    hConf.set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
    tableUtil = new HBaseTableUtilFactory(cConf).get();
    ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get();
    ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
    LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class);
    tableFactory = new HBaseTableFactory(cConf, hConf, tableUtil, locationFactory);
}
Also used : HBaseDDLExecutorFactory(io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) BeforeClass(org.junit.BeforeClass)

Example 67 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by cdapio.

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.");
}
Also used : ProvisionException(com.google.inject.ProvisionException) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) IOException(java.io.IOException) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) HConnection(org.apache.hadoop.hbase.client.HConnection)

Example 68 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by cdapio.

the class CoprocessorBuildTool method main.

public static void main(final String[] args) throws ParseException {
    Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message.")).addOption(new Option("f", "force", false, "Overwrites any coprocessors that already exist."));
    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);
    String[] commandArgs = commandLine.getArgs();
    // if help is an option, or if there isn't a single 'ensure' command, print usage and exit.
    if (commandLine.hasOption("h") || commandArgs.length != 1 || !"check".equalsIgnoreCase(commandArgs[0])) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(CoprocessorBuildTool.class.getName() + " check", "Checks that HBase coprocessors required by CDAP are loaded onto HDFS. " + "If not, the coprocessors are built and placed on HDFS.", options, "");
        System.exit(0);
    }
    boolean overwrite = commandLine.hasOption("f");
    CConfiguration cConf = CConfiguration.create();
    Configuration hConf = HBaseConfiguration.create();
    Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), new DFSLocationModule());
    try {
        SecurityUtil.loginForMasterService(cConf);
    } catch (Exception e) {
        LOG.error("Failed to login as CDAP user", e);
        System.exit(1);
    }
    LocationFactory locationFactory = injector.getInstance(LocationFactory.class);
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    CoprocessorManager coprocessorManager = new CoprocessorManager(cConf, locationFactory, tableUtil);
    try {
        Location location = coprocessorManager.ensureCoprocessorExists(overwrite);
        LOG.info("coprocessor exists at {}.", location);
    } catch (IOException e) {
        LOG.error("Unable to build and upload coprocessor jars.", e);
        System.exit(1);
    }
}
Also used : Options(org.apache.commons.cli.Options) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) IOException(java.io.IOException) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) LocationFactory(org.apache.twill.filesystem.LocationFactory) HelpFormatter(org.apache.commons.cli.HelpFormatter) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) CoprocessorManager(io.cdap.cdap.data2.util.hbase.CoprocessorManager) Injector(com.google.inject.Injector) Option(org.apache.commons.cli.Option) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) CommandLineParser(org.apache.commons.cli.CommandLineParser) Location(org.apache.twill.filesystem.Location)

Example 69 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by cdapio.

the class ReplicationStatusTool method getMapFromTable.

private static Map<String, Long> getMapFromTable(String rowType) throws IOException {
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    // Scan the table to scan for all regions.
    ScanBuilder scan = getScanBuilder(tableUtil, rowType);
    Result result;
    HashMap<String, Long> timeMap = new HashMap<>();
    try (Table table = tableUtil.createTable(hConf, getReplicationStateTableId(tableUtil));
        ResultScanner resultScanner = table.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);
    }
    return timeMap;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) ReplicationStatusKey(io.cdap.cdap.replication.ReplicationStatusKey) ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

HBaseTableUtilFactory (io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory)42 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)28 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)25 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)20 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)18 BeforeClass (org.junit.BeforeClass)18 FileSystem (org.apache.hadoop.fs.FileSystem)17 Path (org.apache.hadoop.fs.Path)17 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)17 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)17 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)17 HRegionFileSystem (org.apache.hadoop.hbase.regionserver.HRegionFileSystem)17 WAL (org.apache.hadoop.hbase.wal.WAL)15 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)15 LocationFactory (org.apache.twill.filesystem.LocationFactory)15 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)14 HBaseDDLExecutorFactory (io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory)12 IOException (java.io.IOException)9 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)6