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);
}
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;
}
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));
}
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));
}
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());
}
Aggregations