Search in sources :

Example 6 with CoprocessorDescriptor

use of co.cask.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(co.cask.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 7 with CoprocessorDescriptor

use of co.cask.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class CoprocessorManager method getCoprocessorDescriptor.

/**
   * Get the descriptor for a single coprocessor that uses the pre-built coprocessor jar.
   */
public CoprocessorDescriptor getCoprocessorDescriptor(Class<? extends Coprocessor> coprocessor, @Nullable Integer priority) throws IOException {
    if (priority == null) {
        priority = Coprocessor.PRIORITY_USER;
    }
    Location jarFile = ensureCoprocessorExists();
    String jarPath = manageCoprocessors ? jarFile.toURI().getPath() : null;
    return new CoprocessorDescriptor(coprocessor.getName(), jarPath, priority, null);
}
Also used : CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) Location(org.apache.twill.filesystem.Location)

Example 8 with CoprocessorDescriptor

use of co.cask.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase11TableDescriptorUtil 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(co.cask.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 9 with CoprocessorDescriptor

use of co.cask.cdap.spi.hbase.CoprocessorDescriptor in project cdap by caskdata.

the class HBase11TableDescriptorUtil 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(co.cask.cdap.spi.hbase.ColumnFamilyDescriptor) CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableDescriptor(co.cask.cdap.spi.hbase.TableDescriptor) HashSet(java.util.HashSet)

Example 10 with CoprocessorDescriptor

use of co.cask.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);
        if (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 '{}'", tableId, version, ProjectInfo.getVersion());
            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.setTablePrefix(newDescriptor, cConf);
        // 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(co.cask.cdap.spi.hbase.HBaseDDLExecutor) Path(org.apache.hadoop.fs.Path) HTableDescriptorBuilder(co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ProjectInfo(co.cask.cdap.common.utils.ProjectInfo) CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

CoprocessorDescriptor (co.cask.cdap.spi.hbase.CoprocessorDescriptor)18 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)15 ColumnFamilyDescriptor (co.cask.cdap.spi.hbase.ColumnFamilyDescriptor)14 Path (org.apache.hadoop.fs.Path)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 TableDescriptor (co.cask.cdap.spi.hbase.TableDescriptor)7 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)7 TableName (org.apache.hadoop.hbase.TableName)7 ProjectInfo (co.cask.cdap.common.utils.ProjectInfo)1 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)1 HBaseDDLExecutor (co.cask.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