Search in sources :

Example 1 with MetricsTable

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;
}
Also used : DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) IOException(java.io.IOException) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 2 with MetricsTable

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);
    }
}
Also used : EntityTable(co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable)

Example 3 with MetricsTable

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()));
}
Also used : Scanner(co.cask.cdap.api.dataset.table.Scanner) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Row(co.cask.cdap.api.dataset.table.Row) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MetricsTableTest(co.cask.cdap.data2.dataset2.lib.table.MetricsTableTest) Test(org.junit.Test)

Example 4 with MetricsTable

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());
        }
    };
}
Also used : HBaseMetricsTableModule(co.cask.cdap.data2.dataset2.module.lib.hbase.HBaseMetricsTableModule) Constants(co.cask.cdap.common.conf.Constants) HBaseQueueDatasetModule(co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule) HBaseQueueDatasetModule(co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule) LineageDatasetModule(co.cask.cdap.data2.metadata.lineage.LineageDatasetModule) ExternalDatasetModule(co.cask.cdap.data2.dataset2.lib.external.ExternalDatasetModule) UsageDatasetModule(co.cask.cdap.data2.registry.UsageDatasetModule) MetadataDatasetModule(co.cask.cdap.data2.metadata.dataset.MetadataDatasetModule) DatasetModule(co.cask.cdap.api.dataset.module.DatasetModule) AbstractModule(com.google.inject.AbstractModule)

Example 5 with MetricsTable

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);
        }
    };
}
Also used : LevelDBMetricsTableModule(co.cask.cdap.data2.dataset2.module.lib.leveldb.LevelDBMetricsTableModule) Constants(co.cask.cdap.common.conf.Constants) LevelDBTableModule(co.cask.cdap.data2.dataset2.module.lib.leveldb.LevelDBTableModule) HBaseQueueDatasetModule(co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule) LineageDatasetModule(co.cask.cdap.data2.metadata.lineage.LineageDatasetModule) ExternalDatasetModule(co.cask.cdap.data2.dataset2.lib.external.ExternalDatasetModule) UsageDatasetModule(co.cask.cdap.data2.registry.UsageDatasetModule) MetadataDatasetModule(co.cask.cdap.data2.metadata.dataset.MetadataDatasetModule) DatasetModule(co.cask.cdap.api.dataset.module.DatasetModule) AbstractModule(com.google.inject.AbstractModule)

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