use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method recordProgramProvisioned.
/**
* Record that the program run has completed provisioning compute resources for the run. If the current status has
* a higher source id, this call will be ignored.
*
* @param programRunId program run
* @param numNodes number of cluster nodes provisioned
* @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 ProgramRunClusterStatus#PROVISIONED} if it is successfully persisted, {@code null} otherwise.
*/
@Nullable
public ProgramRunClusterStatus recordProgramProvisioned(ProgramRunId programRunId, int numNodes, byte[] sourceId) {
MDSKey key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTING, programRunId).build();
RunRecordMeta existing = getRun(programRunId);
if (existing == null) {
LOG.warn("Ignoring unexpected request to transition program run {} from non-existent state to cluster state {}.", programRunId, ProgramRunClusterStatus.PROVISIONED);
return null;
} else if (!isValid(existing, sourceId, "provisioned")) {
return null;
}
ProgramRunClusterStatus clusterState = existing.getCluster().getStatus();
if (clusterState != ProgramRunClusterStatus.PROVISIONING) {
LOG.warn("Ignoring unexpected request to transition program run {} from cluster state {} to cluster state {}.", programRunId, existing.getCluster().getStatus(), ProgramRunClusterStatus.PROVISIONED);
return null;
}
ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.PROVISIONED, null, numNodes);
RunRecordMeta meta = RunRecordMeta.builder(existing).setStatus(ProgramRunStatus.STARTING).setCluster(cluster).setSourceId(sourceId).build();
write(key, meta);
return ProgramRunClusterStatus.PROVISIONED;
}
use of io.cdap.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 io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method recordProgramSuspendResume.
private void recordProgramSuspendResume(ProgramRunId programRunId, byte[] sourceId, RunRecordMeta existing, String action) {
String toType = TYPE_RUN_RECORD_SUSPENDED;
ProgramRunStatus toStatus = ProgramRunStatus.SUSPENDED;
if (action.equals("resume")) {
toType = TYPE_RUN_RECORD_STARTED;
toStatus = ProgramRunStatus.RUNNING;
}
// Delete the old run record
delete(existing);
MDSKey key = getProgramKeyBuilder(toType, programRunId).build();
write(key, RunRecordMeta.builder(existing).setStatus(toStatus).setSourceId(sourceId).build());
}
use of io.cdap.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.run(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 io.cdap.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).build();
write(key, workflowToken);
}
Aggregations