Search in sources :

Example 6 with MDSKey

use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class DefaultOwnerStore method createRowKey.

private static byte[] createRowKey(NamespacedEntityId targetId) {
    String targetType = EntityIdKeyHelper.getTargetType(targetId);
    MDSKey.Builder builder = new MDSKey.Builder();
    builder.add(OWNER_PREFIX);
    builder.add(targetType);
    EntityIdKeyHelper.addTargetIdToKey(builder, targetId);
    MDSKey build = builder.build();
    return build.getKey();
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 7 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(ProgramId programId, final String runid) {
    MDSKey completedKey = getProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
    RunRecordMeta runRecordMeta = getCompletedRun(completedKey, runid);
    if (runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
        completedKey = getVersionLessProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
        return getCompletedRun(completedKey, runid);
    }
    return runRecordMeta;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 8 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 : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 9 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 (runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
        runningKey = getVersionLessProgramKeyBuilder(recordType, programId).add(runid).build();
        return get(runningKey, RunRecordMeta.class);
    }
    return runRecordMeta;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 10 with MDSKey

use of co.cask.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class OrderedPair method getSecond.

public Set<SECOND> getSecond(Set<MDSKey> mdsKeys) {
    Set<SECOND> secondSet = Sets.newHashSetWithExpectedSize(mdsKeys.size());
    for (MDSKey mdsKey : mdsKeys) {
        MDSKey.Splitter splitter = mdsKey.split();
        // prefix
        splitter.skipString();
        keyMaker1.skipKey(splitter);
        secondSet.add(this.keyMaker2.getElement(splitter));
    }
    return secondSet;
}
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