Search in sources :

Example 6 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class AppMetadataStore method updateAppSpec.

// todo: do we need appId? may be use from appSpec?
public void updateAppSpec(String namespaceId, String appId, String versionId, ApplicationSpecification spec) {
    LOG.trace("App spec to be updated: id: {}: spec: {}", appId, GSON.toJson(spec));
    MDSKey key = new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId, versionId).build();
    MDSKey versionLessKey = null;
    ApplicationMeta existing = getFirst(key, ApplicationMeta.class);
    ApplicationMeta updated;
    // Check again without the version to account for old data format if might not have been upgraded yet
    if (!upgradeComplete.get() && existing == null && (versionId.equals(ApplicationId.DEFAULT_VERSION))) {
        versionLessKey = new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId).build();
        existing = get(versionLessKey, ApplicationMeta.class);
    }
    if (existing == null) {
        String msg = String.format("No meta for namespace %s app %s exists", namespaceId, appId);
        LOG.error(msg);
        throw new IllegalArgumentException(msg);
    }
    updated = ApplicationMeta.updateSpec(existing, spec);
    LOG.trace("Application exists in mds: id: {}, spec: {}", existing);
    // Delete the old spec since the old spec has been replaced with this one.
    if (versionLessKey != null) {
        delete(versionLessKey);
    }
    write(key, updated);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 7 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class InMemoryTableService method increment.

// todo: remove it from here: only used by "system" metrics table, which should be revised
@Deprecated
public static synchronized Map<byte[], Long> increment(String tableName, byte[] row, Map<byte[], Long> increments) {
    Map<byte[], Long> resultMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    ConcurrentNavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, Update>>> table = tables.get(tableName);
    // get the correct row from the table, create it if it doesn't exist
    NavigableMap<byte[], NavigableMap<Long, Update>> rowMap = table.get(row);
    if (rowMap == null) {
        rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        table.put(row, rowMap);
    }
    // now increment each column, one by one
    long versionForWrite = System.currentTimeMillis();
    for (Map.Entry<byte[], Long> inc : increments.entrySet()) {
        IncrementValue increment = new IncrementValue(inc.getValue());
        // create the column in the row if it does not exist
        NavigableMap<Long, Update> colMap = rowMap.get(inc.getKey());
        Update last = null;
        if (colMap == null) {
            colMap = Maps.newTreeMap();
            rowMap.put(inc.getKey(), colMap);
        } else {
            last = colMap.lastEntry().getValue();
        }
        Update merged = Updates.mergeUpdates(last, increment);
        // put into the column with given version
        long newValue = Bytes.toLong(merged.getBytes());
        resultMap.put(inc.getKey(), newValue);
        colMap.put(versionForWrite, merged);
    }
    return resultMap;
}
Also used : IncrementValue(co.cask.cdap.data2.dataset2.lib.table.IncrementValue) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) Update(co.cask.cdap.data2.dataset2.lib.table.Update) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 8 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version 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));
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) TableName(org.apache.hadoop.hbase.TableName) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 9 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class AppMetadataStore method writeApplication.

public void writeApplication(String namespaceId, String appId, String versionId, ApplicationSpecification spec) {
    if (!upgradeComplete.get() && versionId.equals(ApplicationId.DEFAULT_VERSION)) {
        MDSKey mdsKey = new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId).build();
        ApplicationMeta appMeta = get(mdsKey, ApplicationMeta.class);
        // If app meta exists for the application without a version, delete that key.
        if (appMeta != null) {
            delete(mdsKey);
        }
    }
    write(new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId, versionId).build(), new ApplicationMeta(appId, spec));
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 10 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class AppMetadataStore method deleteApplication.

public void deleteApplication(String namespaceId, String appId, String versionId) {
    if (!upgradeComplete.get() && versionId.equals(ApplicationId.DEFAULT_VERSION)) {
        MDSKey mdsKey = new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId).build();
        ApplicationMeta appMeta = get(mdsKey, ApplicationMeta.class);
        // If app meta exists for the application without a version, delete only that key.
        if (appMeta != null) {
            delete(mdsKey);
        }
    }
    deleteAll(new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId, versionId).build());
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)8 Map (java.util.Map)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)4 Update (co.cask.cdap.data2.dataset2.lib.table.Update)3 GsonBuilder (com.google.gson.GsonBuilder)3 NavigableMap (java.util.NavigableMap)3 ProjectInfo (co.cask.cdap.common.utils.ProjectInfo)2 MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)2 Version (co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version)2 EntityTable (co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable)2 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)2 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)2 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)2 IOException (java.io.IOException)2 SortedMap (java.util.SortedMap)2 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 TableName (org.apache.hadoop.hbase.TableName)2 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)1