Search in sources :

Example 6 with CoprocessorDescriptor

use of io.cdap.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase10CDH550TableDescriptorUtil method getTableDescriptor.

public static TableDescriptor getTableDescriptor(HTableDescriptor descriptor) {
    Set<ColumnFamilyDescriptor> families = new HashSet<>();
    for (HColumnDescriptor family : descriptor.getColumnFamilies()) {
        families.add(getColumnFamilyDescriptor(family));
    }
    Set<CoprocessorDescriptor> coprocessors = new HashSet<>();
    coprocessors.addAll(CoprocessorUtil.getCoprocessors(descriptor).values());
    Map<String, String> properties = CoprocessorUtil.getNonCoprocessorProperties(descriptor);
    // TODO: should add configurations as well
    return new TableDescriptor(descriptor.getTableName().getNamespaceAsString(), descriptor.getTableName().getQualifierAsString(), families, coprocessors, properties);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ColumnFamilyDescriptor(io.cdap.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) TableDescriptor(io.cdap.cdap.spi.hbase.TableDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HashSet(java.util.HashSet)

Example 7 with CoprocessorDescriptor

use of io.cdap.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase10CDH550TableDescriptorUtil method getHTableDescriptor.

public static HTableDescriptor getHTableDescriptor(TableDescriptor descriptor) {
    TableName tableName = TableName.valueOf(descriptor.getNamespace(), descriptor.getName());
    HTableDescriptor htd = new HTableDescriptor(tableName);
    for (Map.Entry<String, ColumnFamilyDescriptor> family : descriptor.getFamilies().entrySet()) {
        htd.addFamily(getHColumnDesciptor(family.getValue()));
    }
    for (Map.Entry<String, CoprocessorDescriptor> coprocessor : descriptor.getCoprocessors().entrySet()) {
        CoprocessorDescriptor cpd = coprocessor.getValue();
        try {
            Path path = cpd.getPath() == null ? null : new Path(cpd.getPath());
            htd.addCoprocessor(cpd.getClassName(), path, cpd.getPriority(), cpd.getProperties());
        } catch (IOException e) {
            LOG.error("Error adding coprocessor.", e);
        }
    }
    for (Map.Entry<String, String> property : descriptor.getProperties().entrySet()) {
        htd.setValue(property.getKey(), property.getValue());
    }
    return htd;
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) IOException(java.io.IOException) ColumnFamilyDescriptor(io.cdap.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 8 with CoprocessorDescriptor

use of io.cdap.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase10TableDescriptorUtil method getHTableDescriptor.

public static HTableDescriptor getHTableDescriptor(TableDescriptor descriptor) {
    TableName tableName = TableName.valueOf(descriptor.getNamespace(), descriptor.getName());
    HTableDescriptor htd = new HTableDescriptor(tableName);
    for (Map.Entry<String, ColumnFamilyDescriptor> family : descriptor.getFamilies().entrySet()) {
        htd.addFamily(getHColumnDesciptor(family.getValue()));
    }
    for (Map.Entry<String, CoprocessorDescriptor> coprocessor : descriptor.getCoprocessors().entrySet()) {
        CoprocessorDescriptor cpd = coprocessor.getValue();
        try {
            Path path = cpd.getPath() == null ? null : new Path(cpd.getPath());
            htd.addCoprocessor(cpd.getClassName(), path, cpd.getPriority(), cpd.getProperties());
        } catch (IOException e) {
            LOG.error("Error adding coprocessor.", e);
        }
    }
    for (Map.Entry<String, String> property : descriptor.getProperties().entrySet()) {
        htd.setValue(property.getKey(), property.getValue());
    }
    return htd;
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) IOException(java.io.IOException) ColumnFamilyDescriptor(io.cdap.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 9 with CoprocessorDescriptor

use of io.cdap.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBaseTableFactory method upgradeCoProcessor.

private void upgradeCoProcessor(TableId tableId, Class<? extends Coprocessor> coprocessor) throws IOException {
    try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
        HTableDescriptor tableDescriptor;
        try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
            // If table doesn't exist, then skip upgrading coprocessor
            if (!tableUtil.tableExists(admin, tableId)) {
                LOG.debug("TMS Table {} was not found. Skip upgrading coprocessor.", tableId);
                return;
            }
            tableDescriptor = tableUtil.getHTableDescriptor(admin, tableId);
        }
        // Get cdap version from the table
        ProjectInfo.Version version = HBaseTableUtil.getVersion(tableDescriptor);
        String hbaseVersion = HBaseTableUtil.getHBaseVersion(tableDescriptor);
        if (hbaseVersion != null && hbaseVersion.equals(HBaseVersion.getVersionString()) && version.compareTo(ProjectInfo.getVersion()) >= 0) {
            // If cdap has version has not changed or is greater, no need to update. Just enable it, in case
            // it has been disabled by the upgrade tool, and return
            LOG.info("Table '{}' has not changed and its version '{}' is same or greater than current CDAP version '{}'." + " The underlying HBase version {} has also not changed.", tableId, version, ProjectInfo.getVersion(), hbaseVersion);
            enableTable(ddlExecutor, tableId);
            return;
        }
        // create a new descriptor for the table update
        HTableDescriptorBuilder newDescriptor = tableUtil.buildHTableDescriptor(tableDescriptor);
        // Remove old coprocessor
        Map<String, HBaseTableUtil.CoprocessorInfo> coprocessorInfo = HBaseTableUtil.getCoprocessorInfo(tableDescriptor);
        for (Map.Entry<String, HBaseTableUtil.CoprocessorInfo> coprocessorEntry : coprocessorInfo.entrySet()) {
            newDescriptor.removeCoprocessor(coprocessorEntry.getValue().getClassName());
        }
        // Add new coprocessor
        CoprocessorDescriptor coprocessorDescriptor = coprocessorManager.getCoprocessorDescriptor(coprocessor, Coprocessor.PRIORITY_USER);
        Path path = coprocessorDescriptor.getPath() == null ? null : new Path(coprocessorDescriptor.getPath());
        newDescriptor.addCoprocessor(coprocessorDescriptor.getClassName(), path, coprocessorDescriptor.getPriority(), coprocessorDescriptor.getProperties());
        // Update CDAP version, table prefix
        HBaseTableUtil.setVersion(newDescriptor);
        HBaseTableUtil.setHBaseVersion(newDescriptor);
        HBaseTableUtil.setTablePrefix(newDescriptor, cConf);
        // Disable auto-splitting
        newDescriptor.setValue(HTableDescriptor.SPLIT_POLICY, cConf.get(Constants.MessagingSystem.TABLE_HBASE_SPLIT_POLICY));
        // Disable Table
        disableTable(ddlExecutor, tableId);
        tableUtil.modifyTable(ddlExecutor, newDescriptor.build());
        LOG.debug("Enabling table '{}'...", tableId);
        enableTable(ddlExecutor, tableId);
    }
    LOG.info("Table '{}' update completed.", tableId);
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) Path(org.apache.hadoop.fs.Path) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ProjectInfo(io.cdap.cdap.common.utils.ProjectInfo) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 10 with CoprocessorDescriptor

use of io.cdap.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase10TableDescriptorUtil method getTableDescriptor.

public static TableDescriptor getTableDescriptor(HTableDescriptor descriptor) {
    Set<ColumnFamilyDescriptor> families = new HashSet<>();
    for (HColumnDescriptor family : descriptor.getColumnFamilies()) {
        families.add(getColumnFamilyDescriptor(family));
    }
    Set<CoprocessorDescriptor> coprocessors = new HashSet<>();
    coprocessors.addAll(CoprocessorUtil.getCoprocessors(descriptor).values());
    Map<String, String> properties = CoprocessorUtil.getNonCoprocessorProperties(descriptor);
    // TODO: should add configurations as well
    return new TableDescriptor(descriptor.getTableName().getNamespaceAsString(), descriptor.getTableName().getQualifierAsString(), families, coprocessors, properties);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ColumnFamilyDescriptor(io.cdap.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) TableDescriptor(io.cdap.cdap.spi.hbase.TableDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HashSet(java.util.HashSet)

Aggregations

CoprocessorDescriptor (io.cdap.cdap.spi.hbase.CoprocessorDescriptor)14 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)11 ColumnFamilyDescriptor (io.cdap.cdap.spi.hbase.ColumnFamilyDescriptor)10 Path (org.apache.hadoop.fs.Path)8 Map (java.util.Map)7 HashMap (java.util.HashMap)6 TableDescriptor (io.cdap.cdap.spi.hbase.TableDescriptor)5 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)5 TableName (org.apache.hadoop.hbase.TableName)5 ProjectInfo (io.cdap.cdap.common.utils.ProjectInfo)1 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)1 HBaseDDLExecutor (io.cdap.cdap.spi.hbase.HBaseDDLExecutor)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Matcher (java.util.regex.Matcher)1 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 Location (org.apache.twill.filesystem.Location)1