use of co.cask.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 co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class WorkflowDataset method write.
void write(WorkflowId id, RunRecordMeta runRecordMeta, List<ProgramRun> programRunList) {
long startTs = runRecordMeta.getStartTs();
MDSKey mdsKey = getRowKeyBuilder(id, startTs).build();
byte[] rowKey = mdsKey.getKey();
Long stopTs = runRecordMeta.getStopTs();
Preconditions.checkState(stopTs != null, "Workflow Stats are written when the workflow has completed. Hence, " + "expected workflow stop time to be non-null. Workflow = %s, Run = %s, Stop time = %s", id, runRecordMeta, stopTs);
long timeTaken = stopTs - startTs;
String value = GSON.toJson(programRunList, PROGRAM_RUNS_TYPE);
table.put(rowKey, RUNID, Bytes.toBytes(runRecordMeta.getPid()));
table.put(rowKey, TIME_TAKEN, Bytes.toBytes(timeTaken));
table.put(rowKey, NODES, Bytes.toBytes(value));
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getWorkflowToken.
public WorkflowToken getWorkflowToken(ProgramId workflowId, String workflowRunId) {
Preconditions.checkArgument(ProgramType.WORKFLOW == workflowId.getType());
// Workflow token is stored with following key:
// [wft][namespace][app][version][WORKFLOW][workflowName][workflowRun]
MDSKey key = getProgramKeyBuilder(TYPE_WORKFLOW_TOKEN, workflowId).add(workflowRunId).build();
BasicWorkflowToken workflowToken = get(key, BasicWorkflowToken.class);
// Check without the version string only for default version
if (!upgradeComplete.get() && workflowToken == null && workflowId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
key = getVersionLessProgramKeyBuilder(TYPE_WORKFLOW_TOKEN, workflowId).add(workflowRunId).build();
workflowToken = get(key, BasicWorkflowToken.class);
}
if (workflowToken == null) {
LOG.debug("No workflow token available for workflow: {}, runId: {}", workflowId, workflowRunId);
// Its ok to not allow any updates by returning a 0 size token.
return new BasicWorkflowToken(0);
}
return workflowToken;
}
use of co.cask.cdap.data2.dataset2.lib.table.MDSKey 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.MDSKey in project cdap by caskdata.
the class AppMetadataStore method updateWorkflowToken.
public void updateWorkflowToken(ProgramRunId workflowRunId, WorkflowToken workflowToken) {
// Workflow token will be stored with following key:
// [wft][namespace][app][WORKFLOW][workflowName][workflowRun]
MDSKey key = getProgramKeyBuilder(TYPE_WORKFLOW_TOKEN, workflowRunId.getParent()).add(workflowRunId.getRun()).build();
write(key, workflowToken);
}
Aggregations