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