Search in sources :

Example 21 with RunRecord

use of co.cask.cdap.proto.RunRecord in project cdap by caskdata.

the class ProgramClientTestRun method testWorkflowCommand.

private void testWorkflowCommand(final WorkflowId workflow) throws Exception {
    // File is used to synchronized between the test case and the FakeWorkflow
    File doneFile = TMP_FOLDER.newFile();
    Assert.assertTrue(doneFile.delete());
    LOG.info("Starting workflow");
    programClient.start(workflow, false, ImmutableMap.of("done.file", doneFile.getAbsolutePath()));
    assertProgramRunning(programClient, workflow);
    Tasks.waitFor(1, new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return programClient.getProgramRuns(workflow, "running", Long.MIN_VALUE, Long.MAX_VALUE, 100).size();
        }
    }, 5, TimeUnit.SECONDS);
    List<RunRecord> runRecords = programClient.getProgramRuns(workflow, "running", Long.MIN_VALUE, Long.MAX_VALUE, 100);
    Assert.assertEquals(1, runRecords.size());
    final String pid = runRecords.get(0).getPid();
    Tasks.waitFor(1, new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            try {
                return programClient.getWorkflowCurrent(workflow, pid).size();
            } catch (NotFoundException e) {
                // try again if the 'current' endpoint is not discoverable yet
                return 0;
            }
        }
    }, 20, TimeUnit.SECONDS);
    // Signal the FakeWorkflow that execution can be continued by creating temp file
    Assert.assertTrue(doneFile.createNewFile());
    assertProgramStopped(programClient, workflow);
    LOG.info("Workflow stopped");
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) NotFoundException(co.cask.cdap.common.NotFoundException) File(java.io.File) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 22 with RunRecord

use of co.cask.cdap.proto.RunRecord in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testProgramStartStopStatus.

@Category(XSlowTests.class)
@Test
public void testProgramStartStopStatus() throws Exception {
    // deploy, check the status
    HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Id.Flow wordcountFlow1 = Id.Flow.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, WORDCOUNT_FLOW_NAME);
    Id.Flow wordcountFlow2 = Id.Flow.from(TEST_NAMESPACE2, WORDCOUNT_APP_NAME, WORDCOUNT_FLOW_NAME);
    // flow is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(wordcountFlow1));
    // start flow in the wrong namespace and verify that it does not start
    startProgram(wordcountFlow2, 404);
    Assert.assertEquals(STOPPED, getProgramStatus(wordcountFlow1));
    // start a flow and check the status
    startProgram(wordcountFlow1);
    waitState(wordcountFlow1, ProgramRunStatus.RUNNING.toString());
    // stop the flow and check the status
    stopProgram(wordcountFlow1);
    waitState(wordcountFlow1, STOPPED);
    // deploy another app in a different namespace and verify
    response = deploy(DummyAppWithTrackingTable.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Id.Program dummyMR1 = Id.Program.from(TEST_NAMESPACE1, DUMMY_APP_ID, ProgramType.MAPREDUCE, DUMMY_MR_NAME);
    Id.Program dummyMR2 = Id.Program.from(TEST_NAMESPACE2, DUMMY_APP_ID, ProgramType.MAPREDUCE, DUMMY_MR_NAME);
    // mapreduce is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(dummyMR2));
    // start mapreduce in the wrong namespace and verify it does not start
    startProgram(dummyMR1, 404);
    Assert.assertEquals(STOPPED, getProgramStatus(dummyMR2));
    // start map-reduce and verify status
    startProgram(dummyMR2);
    waitState(dummyMR2, ProgramRunStatus.RUNNING.toString());
    // stop the mapreduce program and check the status
    stopProgram(dummyMR2);
    waitState(dummyMR2, STOPPED);
    // start multiple runs of the map-reduce program
    startProgram(dummyMR2);
    startProgram(dummyMR2);
    // verify that more than one map-reduce program runs are running
    verifyProgramRuns(dummyMR2, "running", 1);
    // get run records corresponding to the program runs
    List<RunRecord> historyRuns = getProgramRuns(dummyMR2, "running");
    Assert.assertEquals(2, historyRuns.size());
    // stop individual runs of the map-reduce program
    String runId = historyRuns.get(0).getPid();
    stopProgram(dummyMR2, runId, 200);
    runId = historyRuns.get(1).getPid();
    stopProgram(dummyMR2, runId, 200);
    waitState(dummyMR2, STOPPED);
    // start multiple runs of the map-reduce program
    startProgram(dummyMR2);
    startProgram(dummyMR2);
    verifyProgramRuns(dummyMR2, "running", 1);
    historyRuns = getProgramRuns(dummyMR2, "running");
    Assert.assertEquals(2, historyRuns.size());
    // stop all runs of the map-reduce program
    stopProgram(dummyMR2, 200);
    waitState(dummyMR2, STOPPED);
    // get run records, all runs should be stopped
    historyRuns = getProgramRuns(dummyMR2, "running");
    Assert.assertTrue(historyRuns.isEmpty());
    // deploy an app containing a workflow
    response = deploy(SleepingWorkflowApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Id.Program sleepWorkflow1 = Id.Program.from(TEST_NAMESPACE1, SLEEP_WORKFLOW_APP_ID, ProgramType.WORKFLOW, SLEEP_WORKFLOW_NAME);
    Id.Program sleepWorkflow2 = Id.Program.from(TEST_NAMESPACE2, SLEEP_WORKFLOW_APP_ID, ProgramType.WORKFLOW, SLEEP_WORKFLOW_NAME);
    // workflow is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(sleepWorkflow2));
    // start workflow in the wrong namespace and verify that it does not start
    startProgram(sleepWorkflow1, 404);
    Assert.assertEquals(STOPPED, getProgramStatus(sleepWorkflow2));
    // start workflow and check status
    startProgram(sleepWorkflow2);
    waitState(sleepWorkflow2, ProgramRunStatus.RUNNING.toString());
    // workflow will stop itself
    waitState(sleepWorkflow2, STOPPED);
    // cleanup
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) DummyAppWithTrackingTable(co.cask.cdap.DummyAppWithTrackingTable) HttpResponse(org.apache.http.HttpResponse) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) StreamId(co.cask.cdap.proto.id.StreamId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) SleepingWorkflowApp(co.cask.cdap.SleepingWorkflowApp) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 23 with RunRecord

use of co.cask.cdap.proto.RunRecord in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testProgramStartStopStatusErrors.

@Category(XSlowTests.class)
@Test
public void testProgramStartStopStatusErrors() throws Exception {
    // deploy, check the status
    HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // start unknown program
    startProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, "noexist"), 404);
    // start program in unknonw app
    startProgram(Id.Program.from(TEST_NAMESPACE1, "noexist", ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // start program in unknown namespace
    startProgram(Id.Program.from("noexist", WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // debug unknown program
    debugProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, "noexist"), 404);
    // debug a program that does not support it
    debugProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.MAPREDUCE, WORDCOUNT_MAPREDUCE_NAME), // not implemented
    501);
    // status for unknown program
    programStatus(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, "noexist"), 404);
    // status for program in unknonw app
    programStatus(Id.Program.from(TEST_NAMESPACE1, "noexist", ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // status for program in unknown namespace
    programStatus(Id.Program.from("noexist", WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // stop unknown program
    stopProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, "noexist"), 404);
    // stop program in unknonw app
    stopProgram(Id.Program.from(TEST_NAMESPACE1, "noexist", ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // stop program in unknown namespace
    stopProgram(Id.Program.from("noexist", WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 404);
    // stop program that is not running
    stopProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 400);
    // stop run of a program with ill-formed run id
    stopProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), "norunid", 400);
    // start program twice
    startProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME));
    waitState(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), RUNNING);
    startProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), // conflict
    409);
    // get run records for later use
    List<RunRecord> runs = getProgramRuns(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), "running");
    Assert.assertEquals(1, runs.size());
    String runId = runs.get(0).getPid();
    // stop program
    stopProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), 200);
    waitState(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), "STOPPED");
    // get run records again, should be empty now
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            Id.Program id = Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME);
            return getProgramRuns(id, "running").isEmpty();
        }
    }, 10, TimeUnit.SECONDS);
    // stop run of the program that is not running
    stopProgram(Id.Program.from(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, WORDCOUNT_FLOW_NAME), runId, // active run not found
    404);
    // cleanup
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 24 with RunRecord

use of co.cask.cdap.proto.RunRecord in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method assertRunRecord.

private void assertRunRecord(String url, RunRecord expectedRunRecord) throws Exception {
    HttpResponse response = doGet(url);
    RunRecord actualRunRecord = GSON.fromJson(EntityUtils.toString(response.getEntity()), RunRecord.class);
    Assert.assertEquals(expectedRunRecord, actualRunRecord);
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) HttpResponse(org.apache.http.HttpResponse)

Example 25 with RunRecord

use of co.cask.cdap.proto.RunRecord in project cdap by caskdata.

the class WikipediaPipelineAppTest method getLatestPid.

@Nullable
private String getLatestPid(List<RunRecord> history) {
    String pid = null;
    long latestStartTime = 0;
    for (RunRecord runRecord : history) {
        // OK to use start ts, since we ensure that the next run begins after the previous run finishes in the test
        if (runRecord.getStartTs() > latestStartTime) {
            latestStartTime = runRecord.getStartTs();
            pid = runRecord.getPid();
        }
    }
    return pid;
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) Nullable(javax.annotation.Nullable)

Aggregations

RunRecord (co.cask.cdap.proto.RunRecord)36 Test (org.junit.Test)19 ProgramId (co.cask.cdap.proto.id.ProgramId)16 HttpResponse (org.apache.http.HttpResponse)13 File (java.io.File)10 IOException (java.io.IOException)10 Id (co.cask.cdap.proto.Id)8 ApplicationManager (co.cask.cdap.test.ApplicationManager)8 WorkflowManager (co.cask.cdap.test.WorkflowManager)7 Category (org.junit.experimental.categories.Category)6 WorkflowTokenDetail (co.cask.cdap.proto.WorkflowTokenDetail)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 NamespaceId (co.cask.cdap.proto.id.NamespaceId)5 TimeoutException (java.util.concurrent.TimeoutException)5 ConflictException (co.cask.cdap.common.ConflictException)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)3 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)3 AppRequest (co.cask.cdap.proto.artifact.AppRequest)3 Table (co.cask.cdap.api.dataset.table.Table)2