use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getCompletedRun.
private RunRecordMeta getCompletedRun(ProgramId programId, final String runid) {
MDSKey completedKey = getProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
RunRecordMeta runRecordMeta = getCompletedRun(completedKey, runid);
if (!upgradeComplete.get() && runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
completedKey = getVersionLessProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
return getCompletedRun(completedKey, runid);
}
return runRecordMeta;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getActiveRuns.
public Map<ProgramRunId, RunRecordMeta> getActiveRuns(ProgramId programId) {
Predicate<RunRecordMeta> timePredicate = getTimeRangePredicate(0, Long.MAX_VALUE);
MDSKey key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTING, programId).build();
Map<ProgramRunId, RunRecordMeta> activeRuns = getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate));
key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTED, programId).build();
activeRuns.putAll(getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate)));
key = getProgramKeyBuilder(TYPE_RUN_RECORD_SUSPENDED, programId).build();
activeRuns.putAll(getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate)));
return activeRuns;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method recordProgramResumed.
/**
* Logs resume of a program run and sets the run status to {@link ProgramRunStatus#RUNNING}.
* @param programRunId run id of the program
* @param sourceId unique id representing the source of program run status, such as the message id of the program
* run status notification in TMS. The source id must increase as the recording time of the program
* run status increases, so that the attempt to persist program run status older than the existing
* program run status will be ignored
* @return {@link ProgramRunStatus#RUNNING} if it is successfully persisted, {@code null} otherwise.
*/
@Nullable
public ProgramRunStatus recordProgramResumed(ProgramRunId programRunId, byte[] sourceId) {
RunRecordMeta existing = getRun(programRunId);
if (existing == null) {
LOG.warn("Ignoring unexpected transition of program run {} to program state {} with no existing run record.", programRunId, ProgramRunStatus.RUNNING);
return null;
}
if (!isValid(existing, sourceId, "resume")) {
// Skip recording resumed if the existing records are not valid
return null;
}
// also try to get the record without the version string
if (existing == null) {
if (!upgradeComplete.get() && programRunId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
MDSKey key = getVersionLessProgramKeyBuilder(TYPE_RUN_RECORD_SUSPENDED, programRunId.getParent()).add(programRunId.getRun()).build();
existing = get(key, RunRecordMeta.class);
}
if (existing == null) {
LOG.error("No run record meta for program '{}' pid '{}' exists. Skip recording program suspend.", programRunId.getParent(), programRunId.getRun());
return null;
}
}
recordProgramSuspendResume(programRunId, sourceId, existing, "resume");
return ProgramRunStatus.RUNNING;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getHistoricalRuns.
private Map<ProgramRunId, RunRecordMeta> getHistoricalRuns(MDSKey historyKey, ProgramRunStatus status, final long startTime, final long endTime, int limit, @Nullable Predicate<MDSKey> keyFiter, @Nullable Predicate<RunRecordMeta> valueFilter) {
MDSKey start = new MDSKey.Builder(historyKey).add(getInvertedTsScanKeyPart(endTime)).build();
MDSKey stop = new MDSKey.Builder(historyKey).add(getInvertedTsScanKeyPart(startTime)).build();
if (status.equals(ProgramRunStatus.ALL)) {
// return all records (successful and failed)
return getProgramRunIdMap(listKV(start, stop, RunRecordMeta.class, limit, keyFiter, valueFilter == null ? x -> true : valueFilter));
}
if (status.equals(ProgramRunStatus.COMPLETED)) {
return getProgramRunIdMap(listKV(start, stop, RunRecordMeta.class, limit, keyFiter, andPredicate(getPredicate(ProgramController.State.COMPLETED), valueFilter)));
}
if (status.equals(ProgramRunStatus.KILLED)) {
return getProgramRunIdMap(listKV(start, stop, RunRecordMeta.class, limit, keyFiter, andPredicate(getPredicate(ProgramController.State.KILLED), valueFilter)));
}
return getProgramRunIdMap(listKV(start, stop, RunRecordMeta.class, limit, keyFiter, andPredicate(getPredicate(ProgramController.State.ERROR), valueFilter)));
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method addWorkflowNodeState.
private void addWorkflowNodeState(ProgramRunId programRunId, Map<String, String> systemArgs, ProgramRunStatus status, @Nullable BasicThrowable failureCause, byte[] sourceId) {
String workflowNodeId = systemArgs.get(ProgramOptionConstants.WORKFLOW_NODE_ID);
String workflowName = systemArgs.get(ProgramOptionConstants.WORKFLOW_NAME);
String workflowRun = systemArgs.get(ProgramOptionConstants.WORKFLOW_RUN_ID);
ApplicationId appId = programRunId.getParent().getParent();
ProgramRunId workflowRunId = appId.workflow(workflowName).run(workflowRun);
// Node states will be stored with following key:
// workflowNodeState.namespace.app.WORKFLOW.workflowName.workflowRun.workflowNodeId
MDSKey key = getProgramKeyBuilder(TYPE_WORKFLOW_NODE_STATE, workflowRunId).add(workflowNodeId).build();
WorkflowNodeStateDetail nodeStateDetail = new WorkflowNodeStateDetail(workflowNodeId, ProgramRunStatus.toNodeStatus(status), programRunId.getRun(), failureCause);
write(key, nodeStateDetail);
// Get the run record of the Workflow which started this program
key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTED, workflowRunId).build();
RunRecordMeta record = get(key, RunRecordMeta.class);
if (record != null) {
// Update the parent Workflow run record by adding node id and program run id in the properties
Map<String, String> properties = new HashMap<>(record.getProperties());
properties.put(workflowNodeId, programRunId.getRun());
write(key, RunRecordMeta.builder(record).setProperties(properties).setSourceId(sourceId).build());
}
}
Aggregations