use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class MetricsDataMigrator method getOrCreateMetricsTable.
private MetricsTable getOrCreateMetricsTable(String tableName, DatasetProperties empty) throws DataMigrationException {
MetricsTable table = null;
// for default namespace, we have to provide the complete table name.
tableName = "system." + tableName;
// metrics tables are in the system namespace
DatasetId metricsDatasetInstanceId = NamespaceId.DEFAULT.dataset(tableName);
try {
table = DatasetsUtil.getOrCreateDataset(dsFramework, metricsDatasetInstanceId, MetricsTable.class.getName(), empty, null);
} catch (DatasetManagementException | ServiceUnavailableException e) {
String msg = String.format("Cannot access or create table %s.", tableName) + " " + e.getMessage();
LOG.warn(msg);
throw new DataMigrationException(msg);
} catch (IOException e) {
String msg = String.format("Exception while creating table %s", tableName);
LOG.error(msg, e);
throw new DataMigrationException(msg);
}
return table;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class MetricsDataMigrator method migrateMetricsTableFromVersion26.
private void migrateMetricsTableFromVersion26(Version version) throws DataMigrationException {
for (String scope : scopes) {
EntityTable entityTable = new EntityTable(getOrCreateMetricsTable(String.format("%s.%s", scope, entityTableName), DatasetProperties.EMPTY));
String scopedMetricsTableName = String.format("%s.%s", scope, metricsTableName);
MetricsTable metricsTable = getOrCreateMetricsTable(scopedMetricsTableName, DatasetProperties.EMPTY);
System.out.println("Migrating Metrics Data from table : " + scopedMetricsTableName);
migrateMetricsData(entityTable, metricsTable, scope, version);
}
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class HBaseMetricsTableTest method testCombinedScan.
@Test
public void testCombinedScan() throws Exception {
MetricsTable v2Table = getTable("v2Table");
MetricsTable v3Table = getTable("v3Table");
v2Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(A, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(B, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).build());
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v2Table.get(A, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v2Table.get(A, B)));
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v2Table.get(B, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v2Table.get(B, B)));
v3Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(B, mapOf(B, Bytes.toLong(B), C, Bytes.toLong(C))).put(C, mapOf(P, Bytes.toLong(P), X, Bytes.toLong(X))).build());
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(B, B)));
Assert.assertEquals(Bytes.toLong(C), Bytes.toLong(v3Table.get(B, C)));
Assert.assertEquals(Bytes.toLong(X), Bytes.toLong(v3Table.get(C, X)));
Assert.assertEquals(Bytes.toLong(P), Bytes.toLong(v3Table.get(C, P)));
Scanner v2Scanner = v2Table.scan(null, null, null);
Scanner v3Scanner = v3Table.scan(null, null, null);
CombinedMetricsScanner combinedScanner = new CombinedMetricsScanner(v2Scanner, v3Scanner, getDatasetId("v2Table"), dsFramework);
Row firstRow = combinedScanner.next();
Assert.assertEquals(1L, Bytes.toLong(firstRow.getRow()));
Iterator<Map.Entry<byte[], byte[]>> colIterator = firstRow.getColumns().entrySet().iterator();
Map.Entry<byte[], byte[]> column = colIterator.next();
Assert.assertEquals(1L, Bytes.toLong(column.getKey()));
Assert.assertEquals(1L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(2L, Bytes.toLong(column.getKey()));
Assert.assertEquals(2L, Bytes.toLong(column.getValue()));
Row secondRow = combinedScanner.next();
Assert.assertEquals(2L, Bytes.toLong(secondRow.getRow()));
colIterator = secondRow.getColumns().entrySet().iterator();
column = colIterator.next();
Assert.assertEquals(1L, Bytes.toLong(column.getKey()));
Assert.assertEquals(1L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(2L, Bytes.toLong(column.getKey()));
Assert.assertEquals(4L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(3L, Bytes.toLong(column.getKey()));
Assert.assertEquals(3L, Bytes.toLong(column.getValue()));
Row thirdRow = combinedScanner.next();
Assert.assertEquals(3L, Bytes.toLong(thirdRow.getRow()));
colIterator = thirdRow.getColumns().entrySet().iterator();
column = colIterator.next();
Assert.assertEquals(4L, Bytes.toLong(column.getKey()));
Assert.assertEquals(4L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(7L, Bytes.toLong(column.getKey()));
Assert.assertEquals(7L, Bytes.toLong(column.getValue()));
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class SystemDatasetRuntimeModule method getDistributedModules.
@Override
public Module getDistributedModules() {
return new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, DatasetModule> mapBinder = MapBinder.newMapBinder(binder(), String.class, DatasetModule.class, Constants.Dataset.Manager.DefaultDatasetModules.class);
// NOTE: order is important due to dependencies between modules
mapBinder.addBinding("orderedTable-hbase").toProvider(OrderedTableModuleProvider.class).in(Singleton.class);
mapBinder.addBinding("metricsTable-hbase").toInstance(new HBaseMetricsTableModule());
bindDefaultModules(mapBinder);
mapBinder.addBinding("queueDataset").toInstance(new HBaseQueueDatasetModule());
}
};
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class SystemDatasetRuntimeModule method getStandaloneModules.
@Override
public Module getStandaloneModules() {
return new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, DatasetModule> mapBinder = MapBinder.newMapBinder(binder(), String.class, DatasetModule.class, Constants.Dataset.Manager.DefaultDatasetModules.class);
// NOTE: order is important due to dependencies between modules
mapBinder.addBinding("orderedTable-leveldb").toInstance(new LevelDBTableModule());
mapBinder.addBinding("metricsTable-leveldb").toInstance(new LevelDBMetricsTableModule());
bindDefaultModules(mapBinder);
}
};
}
Aggregations