Search in sources :

Example 1 with CoprocessorDescriptor

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

the class HBase10CDHTableDescriptorUtil 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 2 with CoprocessorDescriptor

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

the class HBase10CDHTableDescriptorUtil 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 3 with CoprocessorDescriptor

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

the class HBase12CDH570TableDescriptorUtil 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 4 with CoprocessorDescriptor

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

the class CoprocessorUtil method getCoprocessors.

/**
 * Returns information for all coprocessor configured for the table.
 *
 * @return a Map from coprocessor class name to {@link CoprocessorDescriptor}
 */
public static Map<String, CoprocessorDescriptor> getCoprocessors(HTableDescriptor tableDescriptor) {
    Map<String, CoprocessorDescriptor> info = Maps.newHashMap();
    // The following logic is copied from RegionCoprocessorHost in HBase
    for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> entry : tableDescriptor.getValues().entrySet()) {
        String key = Bytes.toString(entry.getKey().get()).trim();
        String spec = Bytes.toString(entry.getValue().get()).trim();
        if (!HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(key).matches()) {
            continue;
        }
        try {
            Matcher matcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(spec);
            if (!matcher.matches()) {
                continue;
            }
            String className = matcher.group(2).trim();
            Path path = matcher.group(1).trim().isEmpty() ? null : new Path(matcher.group(1).trim());
            int priority = matcher.group(3).trim().isEmpty() ? Coprocessor.PRIORITY_USER : Integer.valueOf(matcher.group(3));
            String cfgSpec = null;
            try {
                cfgSpec = matcher.group(4);
            } catch (IndexOutOfBoundsException ex) {
            // ignore
            }
            Map<String, String> properties = Maps.newHashMap();
            if (cfgSpec != null) {
                cfgSpec = cfgSpec.substring(cfgSpec.indexOf('|') + 1);
                // do an explicit deep copy of the passed configuration
                Matcher m = HConstants.CP_HTD_ATTR_VALUE_PARAM_PATTERN.matcher(cfgSpec);
                while (m.find()) {
                    properties.put(m.group(1), m.group(2));
                }
            }
            String pathStr = path == null ? null : path.toUri().getPath();
            info.put(className, new CoprocessorDescriptor(className, pathStr, priority, properties));
        } catch (Exception ex) {
            LOG.warn("Coprocessor attribute '{}' has invalid coprocessor specification '{}'", key, spec, ex);
        }
    }
    return info;
}
Also used : Path(org.apache.hadoop.fs.Path) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Matcher(java.util.regex.Matcher) CoprocessorDescriptor(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with CoprocessorDescriptor

use of io.cdap.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(io.cdap.cdap.spi.hbase.CoprocessorDescriptor) Location(org.apache.twill.filesystem.Location)

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