Search in sources :

Example 1 with WorkflowTokenNodeDetail

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

the class TestFrameworkTestRun method testDeployWorkflowApp.

@Category(XSlowTests.class)
@Test
public void testDeployWorkflowApp() throws Exception {
    ApplicationManager applicationManager = deployApplication(testSpace, AppWithSchedule.class);
    final WorkflowManager wfmanager = applicationManager.getWorkflowManager("SampleWorkflow");
    List<ScheduleDetail> schedules = wfmanager.getProgramSchedules();
    Assert.assertEquals(1, schedules.size());
    String scheduleName = schedules.get(0).getName();
    Assert.assertNotNull(scheduleName);
    Assert.assertFalse(scheduleName.isEmpty());
    final int initialRuns = wfmanager.getHistory().size();
    LOG.info("initialRuns = {}", initialRuns);
    wfmanager.getSchedule(scheduleName).resume();
    String status = wfmanager.getSchedule(scheduleName).status(200);
    Assert.assertEquals("SCHEDULED", status);
    // Make sure something ran before suspending
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return wfmanager.getHistory().size() > initialRuns;
        }
    }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    wfmanager.getSchedule(scheduleName).suspend();
    waitForScheduleState(scheduleName, wfmanager, ProgramScheduleStatus.SUSPENDED);
    // Sleep for three seconds to make sure scheduled workflows are pending to run
    TimeUnit.SECONDS.sleep(3);
    // All runs should be completed
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            for (RunRecord record : wfmanager.getHistory()) {
                if (record.getStatus() != ProgramRunStatus.COMPLETED) {
                    return false;
                }
            }
            return true;
        }
    }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    List<RunRecord> history = wfmanager.getHistory();
    int workflowRuns = history.size();
    LOG.info("workflowRuns = {}", workflowRuns);
    Assert.assertTrue(workflowRuns > 0);
    //Sleep for some time and verify there are no more scheduled jobs after the suspend.
    TimeUnit.SECONDS.sleep(5);
    final int workflowRunsAfterSuspend = wfmanager.getHistory().size();
    Assert.assertEquals(workflowRuns, workflowRunsAfterSuspend);
    wfmanager.getSchedule(scheduleName).resume();
    //Check that after resume it goes to "SCHEDULED" state
    waitForScheduleState(scheduleName, wfmanager, ProgramScheduleStatus.SCHEDULED);
    // Make sure new runs happens after resume
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return wfmanager.getHistory().size() > workflowRunsAfterSuspend;
        }
    }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    // Check scheduled state
    Assert.assertEquals("SCHEDULED", wfmanager.getSchedule(scheduleName).status(200));
    // Check status of non-existent schedule
    Assert.assertEquals("NOT_FOUND", wfmanager.getSchedule("doesnt exist").status(404));
    // Suspend the schedule
    wfmanager.getSchedule(scheduleName).suspend();
    // Check that after suspend it goes to "SUSPENDED" state
    waitForScheduleState(scheduleName, wfmanager, ProgramScheduleStatus.SUSPENDED);
    // Test workflow token while suspended
    String pid = history.get(0).getPid();
    WorkflowTokenDetail workflowToken = wfmanager.getToken(pid, WorkflowToken.Scope.SYSTEM, null);
    Assert.assertEquals(0, workflowToken.getTokenData().size());
    workflowToken = wfmanager.getToken(pid, null, null);
    Assert.assertEquals(2, workflowToken.getTokenData().size());
    // Wait until workflow finishes execution
    waitForWorkflowStatus(wfmanager, ProgramRunStatus.COMPLETED);
    // Verify workflow token after workflow completion
    WorkflowTokenNodeDetail workflowTokenAtNode = wfmanager.getTokenAtNode(pid, AppWithSchedule.DummyAction.class.getSimpleName(), WorkflowToken.Scope.USER, "finished");
    Assert.assertEquals(true, Boolean.parseBoolean(workflowTokenAtNode.getTokenDataAtNode().get("finished")));
    workflowToken = wfmanager.getToken(pid, null, null);
    Assert.assertEquals(false, Boolean.parseBoolean(workflowToken.getTokenData().get("running").get(0).getValue()));
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) WorkflowTokenNodeDetail(co.cask.cdap.proto.WorkflowTokenNodeDetail) WorkflowManager(co.cask.cdap.test.WorkflowManager) ConflictException(co.cask.cdap.common.ConflictException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) RunRecord(co.cask.cdap.proto.RunRecord) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) WorkflowTokenDetail(co.cask.cdap.proto.WorkflowTokenDetail) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with WorkflowTokenNodeDetail

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

the class WikipediaPipelineAppTest method testWorkflow.

private void testWorkflow(WorkflowManager workflowManager, WikipediaPipelineApp.WikipediaAppConfig config, int expectedRuns, @Nullable Integer threshold) throws Exception {
    if (threshold == null) {
        workflowManager.start();
    } else {
        workflowManager.start(ImmutableMap.of(WikipediaPipelineWorkflow.MIN_PAGES_THRESHOLD_KEY, String.valueOf(threshold), WikipediaPipelineWorkflow.MODE_KEY, WikipediaPipelineWorkflow.ONLINE_MODE));
    }
    workflowManager.waitForRuns(ProgramRunStatus.COMPLETED, expectedRuns, 5, TimeUnit.MINUTES);
    String pid = getLatestPid(workflowManager.getHistory());
    WorkflowTokenNodeDetail tokenAtCondition = workflowManager.getTokenAtNode(pid, WikipediaPipelineWorkflow.EnoughDataToProceed.class.getSimpleName(), WorkflowToken.Scope.USER, "result");
    boolean conditionResult = Boolean.parseBoolean(tokenAtCondition.getTokenDataAtNode().get("result"));
    if (threshold == null) {
        Assert.assertFalse(conditionResult);
        assertWorkflowToken(workflowManager, config, pid, false);
    } else {
        Assert.assertTrue(conditionResult);
        assertWorkflowToken(workflowManager, config, pid, true);
    }
}
Also used : WorkflowTokenNodeDetail(co.cask.cdap.proto.WorkflowTokenNodeDetail)

Example 3 with WorkflowTokenNodeDetail

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

the class WikipediaPipelineAppTest method assertTokenAtRawDataMRNode.

private void assertTokenAtRawDataMRNode(WorkflowManager workflowManager, String pid, boolean continueConditionSucceeded) throws NotFoundException {
    if (!continueConditionSucceeded) {
        return;
    }
    WorkflowTokenNodeDetail rawWikiDataUserTokens = workflowManager.getTokenAtNode(pid, WikipediaDataDownloader.NAME, null, null);
    Assert.assertTrue(Boolean.parseBoolean(rawWikiDataUserTokens.getTokenDataAtNode().get("result")));
    WorkflowTokenNodeDetail rawWikiDataSystemTokens = workflowManager.getTokenAtNode(pid, WikipediaDataDownloader.NAME, WorkflowToken.Scope.SYSTEM, null);
    Assert.assertEquals(2, Integer.parseInt(rawWikiDataSystemTokens.getTokenDataAtNode().get("custom.num.records")));
}
Also used : WorkflowTokenNodeDetail(co.cask.cdap.proto.WorkflowTokenNodeDetail)

Example 4 with WorkflowTokenNodeDetail

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

the class WikipediaPipelineAppTest method assertTokenAtPageTitlesMRNode.

private void assertTokenAtPageTitlesMRNode(WorkflowManager workflowManager, String pid) throws NotFoundException {
    WorkflowTokenNodeDetail pageTitlesUserTokens = workflowManager.getTokenAtNode(pid, WikipediaPipelineApp.LIKES_TO_DATASET_MR_NAME, null, null);
    Assert.assertTrue(Boolean.parseBoolean(pageTitlesUserTokens.getTokenDataAtNode().get("result")));
    WorkflowTokenNodeDetail pageTitlesSystemTokens = workflowManager.getTokenAtNode(pid, WikipediaPipelineApp.LIKES_TO_DATASET_MR_NAME, WorkflowToken.Scope.SYSTEM, null);
    Assert.assertEquals(2, Integer.parseInt(pageTitlesSystemTokens.getTokenDataAtNode().get("custom.num.records")));
}
Also used : WorkflowTokenNodeDetail(co.cask.cdap.proto.WorkflowTokenNodeDetail)

Example 5 with WorkflowTokenNodeDetail

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

the class WikipediaPipelineAppTest method assertTokenAtSparkClusteringNode.

private void assertTokenAtSparkClusteringNode(WorkflowManager workflowManager, WikipediaPipelineApp.WikipediaAppConfig config, String pid, boolean continueConditionSucceeded) throws NotFoundException {
    if (!continueConditionSucceeded) {
        return;
    }
    @SuppressWarnings("ConstantConditions") String sparkProgramName = SparkWikipediaClustering.NAME + "-" + config.clusteringAlgorithm.toUpperCase();
    WorkflowTokenNodeDetail clusteringUserTokens = workflowManager.getTokenAtNode(pid, sparkProgramName, null, null);
    Assert.assertEquals(10, Integer.parseInt(clusteringUserTokens.getTokenDataAtNode().get("num.records")));
    Assert.assertTrue(clusteringUserTokens.getTokenDataAtNode().containsKey("highest.score.term"));
    Assert.assertTrue(clusteringUserTokens.getTokenDataAtNode().containsKey("highest.score.value"));
    WorkflowTokenNodeDetail ldaSystemTokens = workflowManager.getTokenAtNode(pid, sparkProgramName, WorkflowToken.Scope.SYSTEM, null);
    Assert.assertTrue(ldaSystemTokens.getTokenDataAtNode().isEmpty());
}
Also used : WorkflowTokenNodeDetail(co.cask.cdap.proto.WorkflowTokenNodeDetail)

Aggregations

WorkflowTokenNodeDetail (co.cask.cdap.proto.WorkflowTokenNodeDetail)10 RunRecord (co.cask.cdap.proto.RunRecord)3 WorkflowTokenDetail (co.cask.cdap.proto.WorkflowTokenDetail)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 NotFoundException (co.cask.cdap.common.NotFoundException)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 File (java.io.File)2 AppWithWorkflow (co.cask.cdap.AppWithWorkflow)1 ConflictException (co.cask.cdap.common.ConflictException)1 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)1 Id (co.cask.cdap.proto.Id)1 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)1 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)1 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)1 WorkflowId (co.cask.cdap.proto.id.WorkflowId)1 ApplicationManager (co.cask.cdap.test.ApplicationManager)1 WorkflowManager (co.cask.cdap.test.WorkflowManager)1 HttpResponse (co.cask.common.http.HttpResponse)1 URL (java.net.URL)1