use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil in project cdap by caskdata.
the class MetricHBaseTableUtilTest method testGetVersion.
@Test
public void testGetVersion() throws Exception {
// Verify new metric datasets are properly recognized as 2.8+ version from now on
HBaseMetricsTableDefinition definition = new HBaseMetricsTableDefinition("foo", TEST_HBASE.getConfiguration(), hBaseTableUtil, new LocalLocationFactory(TMP_FOLDER.newFolder()), cConf);
DatasetSpecification spec = definition.configure("metricV2.8", DatasetProperties.EMPTY);
DatasetAdmin admin = definition.getAdmin(DatasetContext.from(NamespaceId.SYSTEM.getNamespace()), spec, null);
admin.create();
MetricHBaseTableUtil util = new MetricHBaseTableUtil(hBaseTableUtil);
HBaseAdmin hAdmin = TEST_HBASE.getHBaseAdmin();
TableId hTableId = hBaseTableUtil.createHTableId(NamespaceId.SYSTEM, spec.getName());
HTableDescriptor desc = hBaseTableUtil.getHTableDescriptor(hAdmin, hTableId);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_8_OR_HIGHER, util.getVersion(desc));
// Verify HBase table without coprocessor is properly recognized as 2.6- version
TableName table26 = TableName.valueOf("metricV2.6");
hAdmin.createTable(new HTableDescriptor(table26));
desc = hAdmin.getTableDescriptor(table26);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_6_OR_LOWER, util.getVersion(desc));
// Verify HBase table with IncrementHandler coprocessor but without cdap.version on it is properly recognized as
// 2.7 version
TableName table27 = TableName.valueOf("metricV2.7");
desc = new HTableDescriptor(table27);
desc.addCoprocessor(hBaseTableUtil.getIncrementHandlerClassForVersion().getName());
hAdmin.createTable(desc);
desc = hAdmin.getTableDescriptor(table27);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_7, util.getVersion(desc));
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil in project cdap by caskdata.
the class MetricsDataMigrator method findMetricsTableVersion.
@Nullable
private Version findMetricsTableVersion(MetricHBaseTableUtil metricHBaseTableUtil) {
// Figure out what is the latest working version of CDAP
// 1) if latest is 2.8.x - nothing to do, if "pre-2.8", proceed to next step.
// 2) find a most recent metrics table: start by looking for 2.7, then 2.6
// 3) if we find 2.7 - we will migrate data from 2.7 table, if not - migrate data from 2.6 metrics table
// todo - use UpgradeTool to figure out if version is 2.8.x, return if it is 2.8.x
String tableName27 = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, UpgradeMetricsConstants.DEFAULT_METRICS_TABLE_PREFIX) + ".agg";
// versions older than 2.7, has two metrics table, identified by system and user prefix
String tableName26 = "system." + tableName27;
DefaultDatasetNamespace defaultDatasetNamespace = new DefaultDatasetNamespace(cConf);
String metricsEntityTable26 = defaultDatasetNamespace.namespace(NamespaceId.SYSTEM, tableName26);
String metricsEntityTable27 = defaultDatasetNamespace.namespace(NamespaceId.SYSTEM, tableName27);
Version version = null;
try (HBaseAdmin hAdmin = new HBaseAdmin(hConf)) {
for (HTableDescriptor desc : hAdmin.listTables()) {
if (desc.getNameAsString().equals(metricsEntityTable27)) {
System.out.println("Matched HBase Table Name For Migration " + desc.getNameAsString());
version = metricHBaseTableUtil.getVersion(desc);
version = verifyVersion(Version.VERSION_2_7, version);
if (version == null) {
return null;
}
break;
}
if (desc.getNameAsString().equals(metricsEntityTable26)) {
System.out.println("Matched HBase Table Name For Migration " + desc.getNameAsString());
version = metricHBaseTableUtil.getVersion(desc);
version = verifyVersion(Version.VERSION_2_6_OR_LOWER, version);
if (version == null) {
return null;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return version;
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil in project cdap by caskdata.
the class MetricsDataMigrator method migrateMetricsTables.
public void migrateMetricsTables(HBaseTableUtil hBaseTableUtil, boolean keepOldData) throws DataMigrationException {
Version cdapVersion = findMetricsTableVersion(new MetricHBaseTableUtil(hBaseTableUtil));
if (cdapVersion == Version.VERSION_2_6_OR_LOWER) {
migrateMetricsTableFromVersion26(cdapVersion);
} else if (cdapVersion == Version.VERSION_2_7) {
migrateMetricsTableFromVersion27(cdapVersion);
} else {
System.out.println("Unsupported version" + cdapVersion);
return;
}
if (!keepOldData) {
System.out.println("Performing cleanup of old metrics tables");
cleanUpOldTables(cdapVersion);
}
}
Aggregations