Search in sources :

Example 6 with MDSKey

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;
}
Also used : ProgramRunClusterStatus(co.cask.cdap.proto.ProgramRunClusterStatus) ProgramRunCluster(co.cask.cdap.proto.ProgramRunCluster) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Nullable(javax.annotation.Nullable)

Example 7 with MDSKey

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);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 8 with MDSKey

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());
}
Also used : ProgramRunStatus(co.cask.cdap.proto.ProgramRunStatus) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 9 with MDSKey

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;
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) BasicWorkflowToken(co.cask.cdap.internal.app.runtime.workflow.BasicWorkflowToken)

Example 10 with MDSKey

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);
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)66 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)31 GsonBuilder (com.google.gson.GsonBuilder)22 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)14 HashMap (java.util.HashMap)12 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)9 Row (co.cask.cdap.api.dataset.table.Row)8 ProgramId (co.cask.cdap.proto.id.ProgramId)8 Nullable (javax.annotation.Nullable)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Test (org.junit.Test)7 Scanner (co.cask.cdap.api.dataset.table.Scanner)6 MetadataStoreDataset (co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset)6 ArrayList (java.util.ArrayList)6 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 Row (io.cdap.cdap.api.dataset.table.Row)5 Scanner (io.cdap.cdap.api.dataset.table.Scanner)5