use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testLoadingProgram.
@Test
public void testLoadingProgram() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new FooApp());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
ProgramDescriptor descriptor = store.loadProgram(appId.mr("mrJob1"));
Assert.assertNotNull(descriptor);
MapReduceSpecification mrSpec = descriptor.getSpecification();
Assert.assertEquals("mrJob1", mrSpec.getName());
Assert.assertEquals(FooMapReduceJob.class.getName(), mrSpec.getClassName());
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testProgramRunCount.
@Test
public void testProgramRunCount() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
ArtifactId testArtifact = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
ProgramId serviceId = appId.service(AllProgramsApp.NoOpService.NAME);
ProgramId nonExistingAppProgramId = NamespaceId.DEFAULT.app("nonExisting").workflow("test");
ProgramId nonExistingProgramId = appId.workflow("nonExisting");
// add the application
store.addApplication(appId, spec);
// add some run records to workflow and service
for (int i = 0; i < 5; i++) {
setStart(workflowId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
setStart(serviceId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
}
List<RunCountResult> result = store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId, nonExistingAppProgramId, nonExistingProgramId));
// compare the result
Assert.assertEquals(4, result.size());
for (RunCountResult runCountResult : result) {
ProgramId programId = runCountResult.getProgramId();
Long count = runCountResult.getCount();
if (programId.equals(nonExistingAppProgramId) || programId.equals(nonExistingProgramId)) {
Assert.assertNull(count);
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
} else {
Assert.assertNotNull(count);
Assert.assertEquals(5L, count.longValue());
}
}
// remove the app should remove all run count
store.removeApplication(appId);
for (RunCountResult runCountResult : store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId))) {
Assert.assertNull(runCountResult.getCount());
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
}
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testCheckDeletedWorkflow.
@Test
public void testCheckDeletedWorkflow() {
// Deploy program with all types of programs.
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
store.addApplication(appId, spec);
Set<String> specsToBeDeleted = Sets.newHashSet();
specsToBeDeleted.addAll(spec.getWorkflows().keySet());
Assert.assertEquals(1, specsToBeDeleted.size());
// Get the spec for app that contains only flow and mapreduce - removing workflows.
spec = Specifications.from(new DefaultStoreTestApp());
// Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
Assert.assertEquals(2, deletedSpecs.size());
for (ProgramSpecification specification : deletedSpecs) {
// Remove the spec that is verified, to check the count later.
specsToBeDeleted.remove(specification.getName());
}
// 2 specs should have been deleted and 0 should be remaining.
Assert.assertEquals(0, specsToBeDeleted.size());
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testScanApplicationsWithNamespace.
public void testScanApplicationsWithNamespace(Store store) {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
int count = 100;
for (int i = 0; i < count / 2; i++) {
String appName = "test" + (2 * i);
store.addApplication(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appName), appSpec);
appName = "test" + (2 * i + 1);
store.addApplication(new ApplicationId(NamespaceId.CDAP.getNamespace(), appName), appSpec);
}
List<ApplicationId> apps = new ArrayList<ApplicationId>();
ScanApplicationsRequest request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).build();
store.scanApplications(request, 20, (appId, spec) -> {
apps.add(appId);
});
Assert.assertEquals(count / 2, apps.size());
// Reverse
List<ApplicationId> reverseApps = new ArrayList<>();
request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setSortOrder(SortOrder.DESC).build();
store.scanApplications(request, 20, (appId, spec) -> reverseApps.add(appId));
Assert.assertEquals(Lists.reverse(apps), reverseApps);
// Second page
int firstPageSize = 10;
List<ApplicationId> restartApps = new ArrayList<>();
request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setScanFrom(apps.get(firstPageSize - 1)).build();
store.scanApplications(request, 20, (appId, spec) -> restartApps.add(appId));
Assert.assertEquals(apps.subList(firstPageSize, apps.size()), restartApps);
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testServiceDeletion.
@Test
public void testServiceDeletion() {
// Store the application specification
AbstractApplication app = new AppWithServices();
ApplicationSpecification appSpec = Specifications.from(app);
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
AbstractApplication newApp = new AppWithNoServices();
// get the delete program specs after deploying AppWithNoServices
List<ProgramSpecification> programSpecs = store.getDeletedProgramSpecifications(appId, Specifications.from(newApp));
// verify the result.
Assert.assertEquals(1, programSpecs.size());
Assert.assertEquals("NoOpService", programSpecs.get(0).getName());
}
Aggregations