use of co.cask.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 co.cask.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 co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class EntityTableTest method testGetName.
@Test
public void testGetName() throws Exception {
InMemoryTableService.create("testGetName");
MetricsTable table = new InMemoryMetricsTable("testGetName");
EntityTable entityTable = new EntityTable(table);
// Create some entities.
for (int i = 1; i <= 10; i++) {
Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
}
// Reverse lookup
for (int i = 1; i <= 10; i++) {
Assert.assertEquals("app" + i, entityTable.getName(i, "app"));
}
}
use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class FactTableTest method testPreSplits.
@Test
public void testPreSplits() throws Exception {
InMemoryTableService.create("presplitEntityTable");
InMemoryTableService.create("presplitDataTable");
int resolution = 10;
int rollTimebaseInterval = 2;
InMemoryMetricsTable metricsTable = new InMemoryMetricsTable("presplitDataTable");
FactTable table = new FactTable(metricsTable, new EntityTable(new InMemoryMetricsTable("presplitEntityTable")), resolution, rollTimebaseInterval);
byte[][] splits = FactTable.getSplits(3);
long ts = System.currentTimeMillis() / 1000;
DimensionValue dimVal1 = new DimensionValue("dim1", "value1");
DimensionValue dimVal2 = new DimensionValue("dim2", "value2");
DimensionValue dimVal3 = new DimensionValue("dim3", "value3");
// first agg view: dim1
table.add(ImmutableList.of(new Fact(ts, ImmutableList.of(dimVal1), new Measurement("metric1", MeasureType.COUNTER, 1))));
// second agg view: dim1 & dim2
table.add(ImmutableList.of(new Fact(ts, ImmutableList.of(dimVal1, dimVal2), new Measurement("metric1", MeasureType.COUNTER, 1))));
// third agg view: dim3
table.add(ImmutableList.of(new Fact(ts, ImmutableList.of(dimVal3), new Measurement("metric1", MeasureType.COUNTER, 1))));
// Verify all written records are spread across splits
Scanner scanner = metricsTable.scan(null, null, null);
Row row;
Set<Integer> splitsWithRows = Sets.newHashSet();
while ((row = scanner.next()) != null) {
boolean added = false;
for (int i = 0; i < splits.length; i++) {
if (Bytes.compareTo(row.getRow(), splits[i]) < 0) {
splitsWithRows.add(i);
added = true;
break;
}
}
if (!added) {
// falls into last split
splitsWithRows.add(splits.length);
}
}
Assert.assertEquals(3, splitsWithRows.size());
}
use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class CubeDatasetDefinition method getDataset.
@Override
public CubeDataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map<String, String> arguments, ClassLoader classLoader) throws IOException {
MetricsTable entityTable = metricsTableDef.getDataset(datasetContext, spec.getSpecification("entity"), arguments, classLoader);
int[] resolutions = getResolutions(spec.getProperties());
Map<Integer, Table> resolutionTables = Maps.newHashMap();
for (int resolution : resolutions) {
resolutionTables.put(resolution, tableDef.getDataset(datasetContext, spec.getSpecification(String.valueOf(resolution)), arguments, classLoader));
}
Map<String, Aggregation> aggregations = getAggregations(spec.getProperties());
return new CubeDataset(spec.getName(), entityTable, resolutionTables, aggregations);
}
Aggregations