use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class WorkflowDataset method getRecord.
@Nullable
WorkflowRunRecord getRecord(WorkflowId id, String pid) {
RunId runId = RunIds.fromString(pid);
long startTime = RunIds.getTime(runId, TimeUnit.SECONDS);
MDSKey mdsKey = getRowKeyBuilder(id, startTime).build();
byte[] startRowKey = mdsKey.getKey();
Row indexRow = table.get(startRowKey);
if (indexRow.isEmpty()) {
return null;
}
Map<byte[], byte[]> columns = indexRow.getColumns();
String workflowRunId = Bytes.toString(columns.get(RUNID));
long timeTaken = Bytes.toLong(columns.get(TIME_TAKEN));
List<ProgramRun> actionRunsList = GSON.fromJson(Bytes.toString(columns.get(NODES)), PROGRAM_RUNS_TYPE);
return new WorkflowRunRecord(workflowRunId, timeTaken, actionRunsList);
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class WorkflowDataset method delete.
public void delete(ApplicationId id) {
MDSKey mdsKey = new MDSKey.Builder().add(id.getNamespace()).add(id.getApplication()).build();
Scanner scanner = table.scan(mdsKey.getKey(), Bytes.stopKeyForPrefix(mdsKey.getKey()));
Row row;
try {
while ((row = scanner.next()) != null) {
table.delete(row.getRow());
}
} finally {
scanner.close();
}
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class DefaultPreviewStore method put.
@Override
public void put(ApplicationId applicationId, String tracerName, String propertyName, Object value) {
// PreviewStore is a singleton and we have to create gson for each operation since gson is not thread safe.
Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).create();
MDSKey mdsKey = new MDSKey.Builder().add(applicationId.getNamespace()).add(applicationId.getApplication()).add(tracerName).add(counter.getAndIncrement()).build();
try {
table.put(mdsKey.getKey(), TRACER, Bytes.toBytes(tracerName), 1L);
table.put(mdsKey.getKey(), PROPERTY, Bytes.toBytes(propertyName), 1L);
table.put(mdsKey.getKey(), VALUE, Bytes.toBytes(gson.toJson(value)), 1L);
} catch (IOException e) {
String message = String.format("Error while putting property '%s' for application '%s' and tracer '%s' in" + " preview table.", propertyName, applicationId, tracerName);
throw new RuntimeException(message, e);
}
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class DefaultPreviewStore method remove.
@Override
public void remove(ApplicationId applicationId) {
byte[] startRowKey = new MDSKey.Builder().add(applicationId.getNamespace()).add(applicationId.getApplication()).build().getKey();
byte[] stopRowKey = new MDSKey(Bytes.stopKeyForPrefix(startRowKey)).getKey();
try {
table.deleteRange(startRowKey, stopRowKey, null, null);
} catch (IOException e) {
String message = String.format("Error while removing preview data for application '%s'.", applicationId);
throw new RuntimeException(message, e);
}
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MdsKey method getTargetType.
static String getTargetType(byte[] rowKey) {
MDSKey.Splitter keySplitter = new MDSKey(rowKey).split();
// The rowkey is
// [rowPrefix][targetType][targetId][key] for value rows and
// [rowPrefix][targetType][targetId][key][index] for value index rows
keySplitter.getBytes();
return keySplitter.getString();
}
Aggregations