Search in sources :

Example 21 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class DataMigration method createRegisteredDatasetFramework.

/**
   * Sets up a {@link DatasetFramework} instance for standalone usage.  NOTE: should NOT be used by applications!!!
   */
public static DatasetFramework createRegisteredDatasetFramework(Injector injector) throws DatasetManagementException, IOException {
    DatasetDefinitionRegistryFactory registryFactory = injector.getInstance(DatasetDefinitionRegistryFactory.class);
    DatasetFramework datasetFramework = new InMemoryDatasetFramework(registryFactory);
    // TODO: this doesn't sound right. find out why its needed.
    datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("table"), new HBaseTableModule());
    datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("metricsTable"), new HBaseMetricsTableModule());
    datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("core"), new CoreDatasetsModule());
    datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("fileSet"), new FileSetModule());
    return datasetFramework;
}
Also used : DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework) DatasetDefinitionRegistryFactory(co.cask.cdap.data2.dataset2.DatasetDefinitionRegistryFactory) CoreDatasetsModule(co.cask.cdap.data2.dataset2.lib.table.CoreDatasetsModule) HBaseMetricsTableModule(co.cask.cdap.data2.dataset2.module.lib.hbase.HBaseMetricsTableModule) HBaseTableModule(co.cask.cdap.data2.dataset2.module.lib.hbase.HBaseTableModule) FileSetModule(co.cask.cdap.data2.dataset2.lib.file.FileSetModule) InMemoryDatasetFramework(co.cask.cdap.data2.dataset2.InMemoryDatasetFramework)

Example 22 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class MetricsDataMigrator method migrateMetricsTableFromVersion27.

private void migrateMetricsTableFromVersion27(Version version) throws DataMigrationException {
    EntityTable entityTable = new EntityTable(getOrCreateMetricsTable(entityTableName, DatasetProperties.EMPTY));
    MetricsTable metricsTable = getOrCreateMetricsTable(metricsTableName, DatasetProperties.EMPTY);
    System.out.println("Migrating Metrics Data from table : " + metricsTableName);
    migrateMetricsData(entityTable, metricsTable, null, version);
}
Also used : EntityTable(co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable)

Example 23 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class MetricsTableOnTableTest method getTable.

@Override
protected MetricsTable getTable(String name) throws Exception {
    DatasetId id = DatasetFrameworkTestUtil.NAMESPACE_ID.dataset(name);
    if (dsFrameworkUtil.getInstance(id) == null) {
        dsFrameworkUtil.createInstance(Table.class.getName(), id, DatasetProperties.EMPTY);
    }
    Table table = dsFrameworkUtil.getInstance(id);
    return new MetricsTableTxnlWrapper(new MetricsTableOnTable(table), table);
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 24 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class EntityTableTest method testRecycleAfterMaxId.

@Test
public void testRecycleAfterMaxId() throws Exception {
    InMemoryTableService.create("testRecycleId");
    MetricsTable table = new InMemoryMetricsTable("testRecycleId");
    EntityTable entityTable = new EntityTable(table, 101);
    // only have 100 entries as maxId.
    for (long i = 1; i <= 500; i++) {
        entityTable.getId("app", "app" + i);
    }
    // we call getName for the 100 entries, it will be the latest entries 401-500
    for (long i = 1; i <= 100; i++) {
        Assert.assertEquals("app" + String.valueOf(400 + i), entityTable.getName(i, "app"));
    }
}
Also used : InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Example 25 with MetricsTable

use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class FactCodecTest method test.

@Test
public void test() {
    InMemoryTableService.create("FactCodecTest");
    MetricsTable table = new InMemoryMetricsTable("FactCodecTest");
    int resolution = 10;
    int rollTimebaseInterval = 2;
    FactCodec codec = new FactCodec(new EntityTable(table), resolution, rollTimebaseInterval);
    // testing encoding with multiple dimensions
    List<DimensionValue> dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    // note: we use seconds everywhere and rely on this
    long ts = 1422312915;
    byte[] rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    byte[] column = codec.createColumn(ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("myMetric", codec.getMeasureName(rowKey));
    // testing encoding without one dimension
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, "mySingleTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("mySingleTagMetric", codec.getMeasureName(rowKey));
    // testing encoding without empty dimensions
    rowKey = codec.createRowKey(new ArrayList<DimensionValue>(), "myNoTagsMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(new ArrayList<DimensionValue>(), codec.getDimensionValues(rowKey));
    Assert.assertEquals("myNoTagsMetric", codec.getMeasureName(rowKey));
    // testing null metric
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, "mySingleTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("mySingleTagMetric", codec.getMeasureName(rowKey));
    // testing null value
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myNullTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("myNullTagMetric", codec.getMeasureName(rowKey));
    // testing fuzzy mask for fuzzy stuff in row key
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), // any value is accepted
    new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    byte[] mask = codec.createFuzzyRowMask(dimensionValues, "myMetric");
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    FuzzyRowFilter filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask)));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "annnnnnnnnny"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value12"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value13"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    // fuzzy in value should match the "null" value
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric2", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    rowKey = codec.createRowKey(dimensionValues, null, ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    rowKey = codec.createRowKey(new ArrayList<DimensionValue>(), "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    // testing fuzzy mask for fuzzy metric
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, null, ts);
    mask = codec.createFuzzyRowMask(dimensionValues, null);
    filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask)));
    rowKey = codec.createRowKey(dimensionValues, "annyyy", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    rowKey = codec.createRowKey(dimensionValues, "zzzzzzzzzzzz", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue2"));
    rowKey = codec.createRowKey(dimensionValues, "metric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
// todo: test prefix of multi dimension valued row key is not same one dimension valued row key
// todo: test that rollTimebaseInterval applies well
}
Also used : ArrayList(java.util.ArrayList) FuzzyRowFilter(co.cask.cdap.data2.dataset2.lib.table.FuzzyRowFilter) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue) ImmutablePair(co.cask.cdap.common.utils.ImmutablePair) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Aggregations

MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)19 Test (org.junit.Test)16 MetricsTable (io.cdap.cdap.data2.dataset2.lib.table.MetricsTable)15 DatasetId (co.cask.cdap.proto.id.DatasetId)6 AbstractModule (com.google.inject.AbstractModule)6 InMemoryMetricsTable (io.cdap.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)6 InMemoryMetricsTable (co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)5 MetricsTableTest (co.cask.cdap.data2.dataset2.lib.table.MetricsTableTest)4 CombinedHBaseMetricsTable (co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetModule (co.cask.cdap.api.dataset.module.DatasetModule)3 Row (co.cask.cdap.api.dataset.table.Row)3 Scanner (co.cask.cdap.api.dataset.table.Scanner)3 Table (co.cask.cdap.api.dataset.table.Table)3 Constants (co.cask.cdap.common.conf.Constants)3 ExternalDatasetModule (co.cask.cdap.data2.dataset2.lib.external.ExternalDatasetModule)3 MetadataDatasetModule (co.cask.cdap.data2.metadata.dataset.MetadataDatasetModule)3 LineageDatasetModule (co.cask.cdap.data2.metadata.lineage.LineageDatasetModule)3 UsageDatasetModule (co.cask.cdap.data2.registry.UsageDatasetModule)3 HBaseQueueDatasetModule (co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule)3