Search in sources :

Example 31 with MDSKey

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

Example 32 with MDSKey

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

Example 33 with MDSKey

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;
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ProgramId(co.cask.cdap.proto.id.ProgramId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 34 with MDSKey

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

Example 35 with MDSKey

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

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)48 GsonBuilder (com.google.gson.GsonBuilder)11 Row (co.cask.cdap.api.dataset.table.Row)8 ProgramId (co.cask.cdap.proto.id.ProgramId)7 Scanner (co.cask.cdap.api.dataset.table.Scanner)6 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)6 HashMap (java.util.HashMap)6 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RunId (org.apache.twill.api.RunId)3 Schema (co.cask.cdap.api.data.schema.Schema)2 Put (co.cask.cdap.api.dataset.table.Put)2 SchemaTypeAdapter (co.cask.cdap.internal.io.SchemaTypeAdapter)2 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 NamespacedEntityId (co.cask.cdap.proto.id.NamespacedEntityId)2 StreamId (co.cask.cdap.proto.id.StreamId)2