Search in sources :

Example 11 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class RemoteRuntimeStoreTest method testSimpleCase.

@Test
public void testSimpleCase() {
    ProgramId flowId = new ProgramId(Id.Namespace.DEFAULT.getId(), "test_app", ProgramType.FLOW, "test_flow");
    long stopTime = System.currentTimeMillis() / 2000;
    long startTime = stopTime - 20;
    String pid = RunIds.generate(startTime * 1000).getId();
    // to test null serialization (setStart can take in nullable)
    String twillRunId = null;
    Map<String, String> runtimeArgs = ImmutableMap.of();
    Map<String, String> properties = ImmutableMap.of("runtimeArgs", GSON.toJson(runtimeArgs));
    Map<String, String> systemArgs = ImmutableMap.of("a", "b");
    RunRecordMeta initialRunRecord = new RunRecordMeta(pid, startTime, null, ProgramRunStatus.RUNNING, properties, systemArgs, twillRunId);
    runtimeStore.setStart(flowId, pid, startTime, twillRunId, runtimeArgs, systemArgs);
    RunRecordMeta runMeta = store.getRun(flowId, pid);
    Assert.assertEquals(initialRunRecord, runMeta);
    runtimeStore.setSuspend(flowId, pid);
    Assert.assertEquals(new RunRecordMeta(initialRunRecord, null, ProgramRunStatus.SUSPENDED), store.getRun(flowId, pid));
    runtimeStore.setResume(flowId, pid);
    Assert.assertEquals(initialRunRecord, store.getRun(flowId, pid));
    runtimeStore.setStop(flowId, pid, stopTime, ProgramRunStatus.COMPLETED);
    RunRecordMeta runRecordMeta = store.getRun(flowId, pid);
    RunRecordMeta finalRunRecord = new RunRecordMeta(initialRunRecord, stopTime, ProgramRunStatus.COMPLETED);
    Assert.assertEquals(finalRunRecord, runRecordMeta);
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 12 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta 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 13 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta 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 14 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta 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 15 with RunRecordMeta

use of co.cask.cdap.internal.app.store.RunRecordMeta in project cdap by caskdata.

the class LogHandler method runIdNext.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs/next")
public void runIdNext(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @PathParam("run-id") String runId, @QueryParam("max") @DefaultValue("50") int maxEvents, @QueryParam("fromOffset") @DefaultValue("") String fromOffsetStr, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr, @QueryParam("format") @DefaultValue("text") String format, @QueryParam("suppress") List<String> suppress) throws NotFoundException {
    ProgramType type = ProgramType.valueOfCategoryName(programType);
    RunRecordMeta runRecord = getRunRecordMeta(namespaceId, appId, type, programId, runId);
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(namespaceId, appId, programId, type, runId, runRecord.getSystemArgs());
    doNext(responder, loggingContext, maxEvents, fromOffsetStr, escape, filterStr, runRecord, format, suppress);
}
Also used : LoggingContext(co.cask.cdap.common.logging.LoggingContext) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramType(co.cask.cdap.proto.ProgramType) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)25 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11 ProgramId (co.cask.cdap.proto.id.ProgramId)9 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 LoggingContext (co.cask.cdap.common.logging.LoggingContext)6 RuntimeInfo (co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 ProgramType (co.cask.cdap.proto.ProgramType)4 MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)3 RunId (org.apache.twill.api.RunId)3 Test (org.junit.Test)3 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 Relation (co.cask.cdap.data2.metadata.lineage.Relation)2 SimpleRuntimeInfo (co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo)2 RunRecord (co.cask.cdap.proto.RunRecord)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 TwillController (org.apache.twill.api.TwillController)2