use of io.cdap.cdap.proto.id.NamespaceId 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).getResponseCode());
Assert.assertEquals(200, deploy(app1, appRequest).getResponseCode());
Assert.assertEquals(200, deploy(app2, appRequest).getResponseCode());
// 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);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactLocalizerServiceTest method setupArtifactLocalizerService.
private ArtifactLocalizerService setupArtifactLocalizerService(CConfiguration cConf) {
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
ArtifactLocalizerService artifactLocalizerService = new ArtifactLocalizerService(cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
}));
// start the service
artifactLocalizerService.startAndWait();
return artifactLocalizerService;
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DefaultStoreTest method testDeleteSuspendedWorkflow.
@Test
public void testDeleteSuspendedWorkflow() {
NamespaceId namespaceId = new NamespaceId("namespace1");
// Test delete application
ApplicationId appId1 = namespaceId.app("app1");
ProgramId programId1 = appId1.workflow("pgm1");
ArtifactId artifactId = namespaceId.artifact("testArtifact", "1.0").toApiArtifactId();
RunId run1 = RunIds.generate();
setStartAndRunning(programId1.run(run1.getId()), artifactId);
store.setSuspend(programId1.run(run1.getId()), AppFabricTestHelper.createSourceId(++sourceId), -1);
store.removeApplication(appId1);
Assert.assertTrue(store.getRuns(programId1, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, Integer.MAX_VALUE).isEmpty());
// Test delete namespace
ProgramId programId2 = namespaceId.app("app2").workflow("pgm2");
RunId run2 = RunIds.generate();
setStartAndRunning(programId2.run(run2.getId()), artifactId);
store.setSuspend(programId2.run(run2.getId()), AppFabricTestHelper.createSourceId(++sourceId), -1);
store.removeAll(namespaceId);
nsStore.delete(namespaceId);
Assert.assertTrue(store.getRuns(programId2, ProgramRunStatus.ALL, 0, Long.MAX_VALUE, Integer.MAX_VALUE).isEmpty());
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DefaultStoreTest method testRemoveApplication.
@Test
public void testRemoveApplication() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
NamespaceId namespaceId = new NamespaceId("account1");
ApplicationId appId = namespaceId.app(spec.getName());
store.addApplication(appId, spec);
Assert.assertNotNull(store.getApplication(appId));
// removing application
store.removeApplication(appId);
Assert.assertNull(store.getApplication(appId));
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DefaultStoreTest method testRunningInRangeSimple.
@Test
public void testRunningInRangeSimple() {
NamespaceId ns = new NamespaceId("d");
ProgramRunId run1 = ns.app("a1").program(ProgramType.SERVICE, "f1").run(RunIds.generate(20000).getId());
ProgramRunId run2 = ns.app("a2").program(ProgramType.MAPREDUCE, "f2").run(RunIds.generate(10000).getId());
ProgramRunId run3 = ns.app("a3").program(ProgramType.WORKER, "f3").run(RunIds.generate(40000).getId());
ProgramRunId run4 = ns.app("a4").program(ProgramType.SERVICE, "f4").run(RunIds.generate(70000).getId());
ProgramRunId run5 = ns.app("a5").program(ProgramType.SPARK, "f5").run(RunIds.generate(30000).getId());
ProgramRunId run6 = ns.app("a6").program(ProgramType.WORKFLOW, "f6").run(RunIds.generate(60000).getId());
ArtifactId artifactId = ns.artifact("testArtifact", "1.0").toApiArtifactId();
writeStartRecord(run1, artifactId);
writeStartRecord(run2, artifactId);
writeStartRecord(run3, artifactId);
writeStartRecord(run4, artifactId);
writeStartRecord(run5, artifactId);
writeStartRecord(run6, artifactId);
Assert.assertEquals(runsToTime(run1, run2), runIdsToTime(store.getRunningInRange(1, 30)));
Assert.assertEquals(runsToTime(run1, run2, run5, run3), runIdsToTime(store.getRunningInRange(30, 50)));
Assert.assertEquals(runsToTime(run1, run2, run3, run4, run5, run6), runIdsToTime(store.getRunningInRange(1, 71)));
Assert.assertEquals(runsToTime(run1, run2, run3, run4, run5, run6), runIdsToTime(store.getRunningInRange(50, 71)));
Assert.assertEquals(ImmutableSet.of(), runIdsToTime(store.getRunningInRange(1, 10)));
writeStopRecord(run1, 45000);
writeStopRecord(run3, 55000);
writeSuspendedRecord(run5);
Assert.assertEquals(runsToTime(run2, run3, run4, run5, run6), runIdsToTime(store.getRunningInRange(50, 71)));
}
Aggregations