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);
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations