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