Search in sources :

Example 1 with RunRecord

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);
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HttpResponse(io.cdap.common.http.HttpResponse) ConcurrencyConstraint(io.cdap.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ServiceHttpEndpoint(io.cdap.cdap.api.service.http.ServiceHttpEndpoint) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint)

Example 2 with RunRecord

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);
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HashMap(java.util.HashMap) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ConcurrencyConstraint(io.cdap.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ServiceHttpEndpoint(io.cdap.cdap.api.service.http.ServiceHttpEndpoint) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint) Test(org.junit.Test)

Example 3 with RunRecord

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);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) RunRecord(io.cdap.cdap.proto.RunRecord) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 4 with RunRecord

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);
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 5 with RunRecord

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());
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

RunRecord (io.cdap.cdap.proto.RunRecord)50 ProgramId (io.cdap.cdap.proto.id.ProgramId)29 Test (org.junit.Test)25 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)19 HttpResponse (io.cdap.common.http.HttpResponse)17 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)13 File (java.io.File)13 Id (io.cdap.cdap.common.id.Id)11 ApplicationManager (io.cdap.cdap.test.ApplicationManager)10 WorkflowTokenDetail (io.cdap.cdap.proto.WorkflowTokenDetail)9 WorkflowManager (io.cdap.cdap.test.WorkflowManager)9 HashMap (java.util.HashMap)9 WorkflowId (io.cdap.cdap.proto.id.WorkflowId)8 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)7 Category (org.junit.experimental.categories.Category)7 Table (io.cdap.cdap.api.dataset.table.Table)6 NotFoundException (io.cdap.cdap.common.NotFoundException)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 List (java.util.List)6 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)5