use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getCompletedRun.
private RunRecordMeta getCompletedRun(MDSKey completedKey, final String runid) {
// Get start time from RunId
long programStartSecs = RunIds.getTime(RunIds.fromString(runid), TimeUnit.SECONDS);
if (programStartSecs > -1) {
// If start time is found, run a get
MDSKey key = new MDSKey.Builder(completedKey).add(getInvertedTsKeyPart(programStartSecs)).add(runid).build();
return get(key, RunRecordMeta.class);
} else {
// If start time is not found, scan the table (backwards compatibility when run ids were random UUIDs)
MDSKey startKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(Long.MAX_VALUE)).build();
MDSKey stopKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(0)).build();
List<RunRecordMeta> runRecords = list(// Should have only one record for this runid
startKey, // Should have only one record for this runid
stopKey, // Should have only one record for this runid
RunRecordMeta.class, // Should have only one record for this runid
1, new Predicate<RunRecordMeta>() {
@Override
public boolean apply(RunRecordMeta input) {
return input.getPid().equals(runid);
}
});
return Iterables.getFirst(runRecords, null);
}
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method recordProgramStart.
private void recordProgramStart(ProgramId programId, String pid, long startTs, String twillRunId, Map<String, String> runtimeArgs, Map<String, String> systemArgs, MDSKey.Builder keyBuilder) {
String workflowrunId = null;
if (systemArgs != null && systemArgs.containsKey(ProgramOptionConstants.WORKFLOW_NAME)) {
// Program is started by Workflow. Add row corresponding to its node state.
addWorkflowNodeState(programId, pid, systemArgs, ProgramRunStatus.RUNNING, null);
workflowrunId = systemArgs.get(ProgramOptionConstants.WORKFLOW_RUN_ID);
}
MDSKey key = keyBuilder.add(pid).build();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("runtimeArgs", GSON.toJson(runtimeArgs, MAP_STRING_STRING_TYPE));
if (workflowrunId != null) {
builder.put("workflowrunid", workflowrunId);
}
RunRecordMeta meta = new RunRecordMeta(pid, startTs, null, ProgramRunStatus.RUNNING, builder.build(), systemArgs, twillRunId);
write(key, meta);
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getProgramRunIdMap.
/** Converts MDSkeys in the map to ProgramIDs
*
* @param keymap map with keys as MDSkeys
* @return map with keys as program IDs
*/
private Map<ProgramRunId, RunRecordMeta> getProgramRunIdMap(Map<MDSKey, RunRecordMeta> keymap) {
Map<ProgramRunId, RunRecordMeta> programRunIdMap = new LinkedHashMap<>();
for (Map.Entry<MDSKey, RunRecordMeta> entry : keymap.entrySet()) {
ProgramId programId = getProgramID(entry.getKey());
programRunIdMap.put(programId.run(entry.getValue().getPid()), entry.getValue());
}
return programRunIdMap;
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getUnfinishedRun.
/**
* @return run records for runs that do not have start time in mds key for the run record.
*/
private RunRecordMeta getUnfinishedRun(ProgramId programId, String recordType, String runid) {
MDSKey runningKey = getProgramKeyBuilder(recordType, programId).add(runid).build();
RunRecordMeta runRecordMeta = get(runningKey, RunRecordMeta.class);
if (!upgradeComplete.get() && runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
runningKey = getVersionLessProgramKeyBuilder(recordType, programId).add(runid).build();
return get(runningKey, RunRecordMeta.class);
}
return runRecordMeta;
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method addWorkflowNodeState.
/**
* This method is called to associate node state of custom action with the Workflow run.
*
* @param workflowRunId the run for which node state is to be added
* @param nodeStateDetail node state details to be added
*/
public void addWorkflowNodeState(ProgramRunId workflowRunId, WorkflowNodeStateDetail nodeStateDetail) {
// Node states will be stored with following key:
// workflowNodeState.namespace.app.WORKFLOW.workflowName.workflowRun.workflowNodeId
MDSKey key = getProgramKeyBuilder(TYPE_WORKFLOW_NODE_STATE, workflowRunId.getParent()).add(workflowRunId.getRun()).add(nodeStateDetail.getNodeId()).build();
write(key, nodeStateDetail);
}
Aggregations