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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations