use of io.cdap.cdap.proto.RunRecord in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method historyStatusWithRetry.
private void historyStatusWithRetry(ProgramId program, ProgramRunStatus status, int size) throws Exception {
String urlAppVersionPart = ApplicationId.DEFAULT_VERSION.equals(program.getVersion()) ? "" : "/versions/" + program.getVersion();
String basePath = String.format("apps/%s%s/%s/%s/runs", program.getApplication(), urlAppVersionPart, program.getType().getCategoryName(), program.getProgram());
String runsUrl = getVersionedAPIPath(basePath + "?status=" + status.name(), Constants.Gateway.API_VERSION_3_TOKEN, program.getNamespace());
int trials = 0;
while (trials++ < 5) {
HttpResponse response = doGet(runsUrl);
List<RunRecord> result = GSON.fromJson(response.getResponseBodyAsString(), LIST_OF_RUN_RECORD);
if (result != null && result.size() >= size) {
for (RunRecord m : result) {
String runUrl = getVersionedAPIPath(basePath + "/" + m.getPid(), Constants.Gateway.API_VERSION_3_TOKEN, program.getNamespace());
response = doGet(runUrl);
RunRecord actualRunRecord = GSON.fromJson(response.getResponseBodyAsString(), RunRecord.class);
Assert.assertEquals(m.getStatus(), actualRunRecord.getStatus());
}
break;
}
TimeUnit.SECONDS.sleep(1);
}
Assert.assertTrue(trials < 5);
}
use of io.cdap.cdap.proto.RunRecord in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method testStopProgramRunWhilePending.
@Test
public void testStopProgramRunWhilePending() throws Exception {
deploy(SleepingWorkflowApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
Id.Program workflowId = Id.Program.from(TEST_NAMESPACE1, SLEEP_WORKFLOW_APP_ID, ProgramType.WORKFLOW, SLEEP_WORKFLOW_NAME);
int numKilledRuns = getProgramRuns(workflowId, ProgramRunStatus.KILLED).size();
// this tells the provisioner to wait for 60s before trying to create the cluster for the run
Map<String, String> args = new HashMap<>();
args.put(SystemArguments.PROFILE_PROPERTIES_PREFIX + MockProvisioner.WAIT_CREATE_MS, Integer.toString(120000));
startProgram(workflowId, args);
// should be safe to wait for starting since the provisioner is configure to sleep while creating a cluster
waitState(workflowId, io.cdap.cdap.proto.ProgramStatus.STARTING.name());
List<RunRecord> runRecords = getProgramRuns(workflowId, ProgramRunStatus.PENDING);
Assert.assertEquals(1, runRecords.size());
String runId = runRecords.iterator().next().getPid();
stopProgram(workflowId, runId, 200);
waitState(workflowId, STOPPED);
verifyProgramRuns(workflowId, ProgramRunStatus.KILLED, numKilledRuns);
deleteApp(workflowId.getApplication(), 200);
}
use of io.cdap.cdap.proto.RunRecord in project cdap by caskdata.
the class GetProgramRunsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
String appId = programIdParts[0];
long currentTime = System.currentTimeMillis();
long startTime = getTimestamp(arguments.getOptional(ArgumentName.START_TIME.toString(), "min"), currentTime);
long endTime = getTimestamp(arguments.getOptional(ArgumentName.END_TIME.toString(), "max"), currentTime);
int limit = arguments.getIntOptional(ArgumentName.LIMIT.toString(), Integer.MAX_VALUE);
List<RunRecord> records;
if (elementType.getProgramType() != null) {
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String programName = programIdParts[1];
ProgramId programId = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
if (arguments.hasArgument(ArgumentName.RUN_STATUS.toString())) {
records = programClient.getProgramRuns(programId, arguments.get(ArgumentName.RUN_STATUS.toString()), startTime, endTime, limit);
} else {
records = programClient.getAllProgramRuns(programId, startTime, endTime, limit);
}
} else {
throw new IllegalArgumentException("Unrecognized program element type for history: " + elementType);
}
Table table = Table.builder().setHeader("pid", "end status", "init time", "start time", "stop time").setRows(records, new RowMaker<RunRecord>() {
@Override
public List<?> makeRow(RunRecord object) {
return Lists.newArrayList(object.getPid(), object.getStatus(), object.getStartTs(), object.getRunTs() == null ? "" : object.getRunTs(), object.getStopTs() == null ? "" : object.getStopTs());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.proto.RunRecord in project cdap by caskdata.
the class LogHttpHandlerTest method testFilterWithEmptyResult.
@Test
public void testFilterWithEmptyResult() throws Exception {
String appId = "testTemplate1";
String entityType = "workflows";
String entityId = "testWorkflow1";
String namespace = NamespaceId.DEFAULT.getEntityName();
ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
RunRecord runRecord = mockLogReader.getRunRecord(programId);
String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs?format=json&filter=MDC:asdf=nothing", appId, entityType, entityId, runRecord.getPid());
HttpResponse response = doGet(getVersionedAPIPath(logsUrl, namespace));
verifyLogs(response, entityId, "json", true, true, true, 0, 0);
}
use of io.cdap.cdap.proto.RunRecord in project cdap by caskdata.
the class LogHttpHandlerTest method testNativeMethodField.
// Verify the Json returned for logs has isNativeMethod set correctly
@Test
public void testNativeMethodField() throws Exception {
ProgramId programId = new NamespaceId(MockLogReader.TEST_NAMESPACE).app("testTemplate1").program(ProgramType.valueOfCategoryName("workflows"), "testWorkflow1");
RunRecord runRecord = mockLogReader.getRunRecord(programId);
String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=json", "testTemplate1", "workflows", "testWorkflow1", runRecord.getPid());
HttpResponse response = doGet(getVersionedAPIPath(logsUrl, MockLogReader.TEST_NAMESPACE));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
List<LogDataOffset> logDataOffsetList = GSON.fromJson(response.getResponseBodyAsString(), LIST_LOGDATA_OFFSET_TYPE);
Assert.assertEquals(logDataOffsetList.size(), 15);
Assert.assertTrue(logDataOffsetList.get(0).getLog().getNativeMethod());
Assert.assertFalse(logDataOffsetList.get(1).getLog().getNativeMethod());
Assert.assertFalse(logDataOffsetList.get(2).getLog().getNativeMethod());
}
Aggregations