use of co.cask.cdap.proto.ScheduleDetail in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method testMultipleWorkflowSchedules.
@Test
public void testMultipleWorkflowSchedules() throws Exception {
// Deploy the app
NamespaceId testNamespace2 = new NamespaceId(TEST_NAMESPACE2);
Id.Namespace idTestNamespace2 = Id.Namespace.fromEntityId(testNamespace2);
Id.Artifact artifactId = Id.Artifact.from(idTestNamespace2, "appwithmultiplescheduledworkflows", VERSION1);
addAppArtifact(artifactId, AppWithMultipleSchedules.class);
AppRequest<? extends Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()));
Id.Application appDefault = new Id.Application(idTestNamespace2, AppWithMultipleSchedules.NAME);
ApplicationId app1 = testNamespace2.app(AppWithMultipleSchedules.NAME, VERSION1);
ApplicationId app2 = testNamespace2.app(AppWithMultipleSchedules.NAME, VERSION2);
Assert.assertEquals(200, deploy(appDefault, appRequest).getStatusLine().getStatusCode());
Assert.assertEquals(200, deploy(app1, appRequest).getStatusLine().getStatusCode());
Assert.assertEquals(200, deploy(app2, appRequest).getStatusLine().getStatusCode());
// Schedule details from non-versioned API
List<ScheduleDetail> someSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.SOME_WORKFLOW);
Assert.assertEquals(2, someSchedules.size());
Assert.assertEquals(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules.get(0).getProgram().getProgramName());
Assert.assertEquals(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules.get(1).getProgram().getProgramName());
// Schedule details from non-versioned API
List<ScheduleDetail> anotherSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.ANOTHER_WORKFLOW);
Assert.assertEquals(3, anotherSchedules.size());
Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(0).getProgram().getProgramName());
Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(1).getProgram().getProgramName());
Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(2).getProgram().getProgramName());
// Schedule details from non-versioned API filtered by Trigger type
List<ScheduleDetail> filteredTimeSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.TIME);
Assert.assertEquals(1, filteredTimeSchedules.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, filteredTimeSchedules);
// Schedule details from non-versioned API filtered by Trigger type
List<ScheduleDetail> programStatusSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.PROGRAM_STATUS);
Assert.assertEquals(4, programStatusSchedules.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, programStatusSchedules);
deleteApp(appDefault, 200);
// Schedule of app1 from versioned API
List<ScheduleDetail> someSchedules1 = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.SOME_WORKFLOW);
Assert.assertEquals(2, someSchedules1.size());
assertProgramInSchedules(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules1);
// Schedule details from versioned API filtered by Trigger type
filteredTimeSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.TIME);
Assert.assertEquals(1, filteredTimeSchedules.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, filteredTimeSchedules);
// Schedule details from versioned API filtered by Trigger type
programStatusSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.PROGRAM_STATUS);
Assert.assertEquals(4, programStatusSchedules.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, programStatusSchedules);
// Schedules triggered by SOME_WORKFLOW's completed or failed or killed status
ProgramId someWorkflow = app1.workflow(AppWithMultipleSchedules.SOME_WORKFLOW);
List<ScheduleDetail> triggeredSchedules1 = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
Assert.assertEquals(3, triggeredSchedules1.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredSchedules1);
List<ScheduleDetail> filteredSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramScheduleStatus.SCHEDULED, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
// No schedule is enabled yet
Assert.assertEquals(0, filteredSchedules.size());
filteredSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramScheduleStatus.SUSPENDED, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
// All schedules are suspended
Assert.assertEquals(3, filteredSchedules.size());
// Schedules triggered by SOME_WORKFLOW's completed status
List<ScheduleDetail> triggeredByCompletedSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramStatus.COMPLETED);
Assert.assertEquals(2, triggeredByCompletedSchedules.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredByCompletedSchedules);
// Schedules triggered by ANOTHER_WORKFLOW regardless of program status
ProgramId anotherWorkflow = app1.workflow(AppWithMultipleSchedules.ANOTHER_WORKFLOW);
List<ScheduleDetail> triggeredSchedules2 = listSchedulesByTriggerProgram(TEST_NAMESPACE2, anotherWorkflow);
Assert.assertEquals(1, triggeredSchedules2.size());
assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredSchedules2);
deleteApp(app1, 200);
// Schedule detail of app2 from versioned API
List<ScheduleDetail> anotherSchedules2 = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION2, AppWithMultipleSchedules.ANOTHER_WORKFLOW);
Assert.assertEquals(3, anotherSchedules2.size());
assertProgramInSchedules(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules2);
deleteApp(app2, 200);
}
Aggregations