use of io.cdap.cdap.AllProgramsApp in project cdap by cdapio.
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.AllProgramsApp in project cdap by cdapio.
the class DefaultStoreTest method testHistoryDeletion.
@Test
public void testHistoryDeletion() {
// Deploy two apps, write some history for programs
// Remove application using accountId, AppId and verify
// Remove all from accountId and verify
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
NamespaceId namespaceId = new NamespaceId("testDeleteAll");
ApplicationId appId1 = namespaceId.app(spec.getName());
store.addApplication(appId1, spec);
spec = Specifications.from(new AppWithServices());
ApplicationId appId2 = namespaceId.app(spec.getName());
store.addApplication(appId2, spec);
ProgramId mapreduceProgramId1 = appId1.mr("NoOpMR");
ProgramId workflowProgramId1 = appId1.workflow("NoOpWorkflow");
ArtifactId artifactId = appId1.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId();
ProgramId serviceId = appId2.service(AppWithServices.SERVICE_NAME);
Assert.assertNotNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
long now = System.currentTimeMillis();
ProgramRunId mapreduceProgramRunId1 = mapreduceProgramId1.run(RunIds.generate(now - 1000));
setStartAndRunning(mapreduceProgramRunId1, artifactId);
store.setStop(mapreduceProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
RunId runId = RunIds.generate(now - 1000);
setStartAndRunning(workflowProgramId1.run(runId.getId()), artifactId);
store.setStop(workflowProgramId1.run(runId.getId()), now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
ProgramRunId serviceRunId = serviceId.run(RunIds.generate(now - 1000));
setStartAndRunning(serviceRunId, artifactId);
store.setStop(serviceRunId, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
verifyRunHistory(mapreduceProgramId1, 1);
verifyRunHistory(workflowProgramId1, 1);
verifyRunHistory(serviceId, 1);
// removing application
store.removeApplication(appId1);
Assert.assertNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
verifyRunHistory(mapreduceProgramId1, 0);
verifyRunHistory(workflowProgramId1, 0);
// Check to see if the history of second app is not deleted
verifyRunHistory(serviceId, 1);
// remove all
store.removeAll(namespaceId);
verifyRunHistory(serviceId, 0);
}
use of io.cdap.cdap.AllProgramsApp in project cdap by cdapio.
the class PreferencesHttpHandlerInternalTest method testApplication.
@Test
public void testApplication() throws Exception {
String appName = AllProgramsApp.NAME;
String namespace1 = TEST_NAMESPACE1;
String uriInstance = getPreferenceURI();
String uriNamespace1 = getPreferenceURI(namespace1);
String uriApp = getPreferenceURI(namespace1, appName);
PreferencesDetail detail;
Map<String, String> combinedProperties = Maps.newHashMap();
// Application not created yet. Get preferences should succeed and get back one with empty properties.
detail = getPreferencesInternal(getPreferenceURI(namespace1, "some_non_existing_app"), false, HttpResponseStatus.OK);
Assert.assertTrue(detail.getProperties().isEmpty());
Assert.assertFalse(detail.getResolved());
Assert.assertEquals(0, detail.getSeqId());
// Create the app.
addApplication(namespace1, new AllProgramsApp());
Map<String, String> propMap = Maps.newHashMap();
Assert.assertEquals(propMap, getPreferences(uriApp, false, 200));
Assert.assertEquals(propMap, getPreferences(uriApp, true, 200));
getPreferences(getPreferenceURI(namespace1, "InvalidAppName"), false, 404);
// Application created but no preferences created yet. API call still succeeds but result is empty.
detail = getPreferencesInternal(uriApp, false, HttpResponseStatus.OK);
Assert.assertEquals(Collections.emptyMap(), detail.getProperties());
// For entity without any references, seqId is set to default 0, otherwise it should be always > 0.
Assert.assertEquals(0, detail.getSeqId());
// Set the preference
Map<String, String> instanceProperties = ImmutableMap.of("key0", "instance-val0", "instance-key1", "instance-val1");
Map<String, String> namespace1Properties = ImmutableMap.of("key0", "namespace-val0", "namespace1-key1", "namespace1-val1");
Map<String, String> appProperties = ImmutableMap.of("key0", "app-val0", "app-key1", "app-val1");
setPreferences(uriInstance, instanceProperties, 200);
setPreferences(uriNamespace1, namespace1Properties, 200);
setPreferences(uriApp, appProperties, 200);
// Get and verify preferences on the application
detail = getPreferencesInternal(uriApp, false, HttpResponseStatus.OK);
Assert.assertEquals(appProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertFalse(detail.getResolved());
// Get and verify resolved preferences on the application
detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
combinedProperties.clear();
combinedProperties.putAll(instanceProperties);
combinedProperties.putAll(namespace1Properties);
combinedProperties.putAll(appProperties);
Assert.assertEquals(combinedProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
// Delete preferences on the application and verify resolved
deletePreferences(uriApp, 200);
detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
combinedProperties.clear();
combinedProperties.putAll(instanceProperties);
combinedProperties.putAll(namespace1Properties);
Assert.assertEquals(combinedProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
// Delete preferences on the namespace and verify.
deletePreferences(uriNamespace1, 200);
detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
combinedProperties.clear();
combinedProperties.putAll(instanceProperties);
Assert.assertEquals(combinedProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
// Delete preferences on the instance and verify.
deletePreferences(uriInstance, 200);
detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
combinedProperties.clear();
Assert.assertEquals(combinedProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by cdapio.
the class PreferencesHttpHandlerTest method testApplication.
@Test
public void testApplication() throws Exception {
String appName = AllProgramsApp.NAME;
addApplication(TEST_NAMESPACE1, new AllProgramsApp());
Map<String, String> propMap = Maps.newHashMap();
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), false, 200));
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), true, 200));
getPreferences(getPreferenceURI(TEST_NAMESPACE1, "InvalidAppName"), false, 404);
setPreferences(getPreferenceURI(), ImmutableMap.of("k1", "instance"), 200);
setPreferences(getPreferenceURI(TEST_NAMESPACE1), ImmutableMap.of("k1", "namespace"), 200);
setPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), ImmutableMap.of("k1", "application"), 200);
Assert.assertEquals("application", getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), false, 200).get("k1"));
Assert.assertEquals("application", getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), true, 200).get("k1"));
Assert.assertEquals("namespace", getPreferences(getPreferenceURI(TEST_NAMESPACE1), false, 200).get("k1"));
Assert.assertEquals("namespace", getPreferences(getPreferenceURI(TEST_NAMESPACE1), true, 200).get("k1"));
Assert.assertEquals("instance", getPreferences(getPreferenceURI(), true, 200).get("k1"));
Assert.assertEquals("instance", getPreferences(getPreferenceURI(), false, 200).get("k1"));
deletePreferences(getPreferenceURI(TEST_NAMESPACE1, appName), 200);
Assert.assertEquals("namespace", getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), true, 200).get("k1"));
Assert.assertNull(getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), false, 200).get("k1"));
deletePreferences(getPreferenceURI(TEST_NAMESPACE1), 200);
Assert.assertEquals("instance", getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), true, 200).get("k1"));
Assert.assertEquals("instance", getPreferences(getPreferenceURI(TEST_NAMESPACE1), true, 200).get("k1"));
Assert.assertNull(getPreferences(getPreferenceURI(TEST_NAMESPACE1), false, 200).get("k1"));
deletePreferences(getPreferenceURI(), 200);
Assert.assertNull(getPreferences(getPreferenceURI(), true, 200).get("k1"));
Assert.assertNull(getPreferences(getPreferenceURI(TEST_NAMESPACE1), true, 200).get("k1"));
Assert.assertNull(getPreferences(getPreferenceURI(TEST_NAMESPACE1, appName), true, 200).get("k1"));
}
use of io.cdap.cdap.AllProgramsApp in project cdap by cdapio.
the class PreferencesHttpHandlerTest method testProgram.
@Test
public void testProgram() throws Exception {
String appName = AllProgramsApp.NAME;
String serviceName = AllProgramsApp.NoOpService.NAME;
addApplication(TEST_NAMESPACE2, new AllProgramsApp());
Map<String, String> propMap = Maps.newHashMap();
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), false, 200));
getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "invalidType", "somename"), false, 400);
getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", "somename"), false, 404);
propMap.put("k1", "k349*&#$");
setPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), propMap, 200);
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), false, 200));
propMap.put("k1", "instance");
setPreferences(getPreferenceURI(), propMap, 200);
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(), true, 200));
propMap.put("k1", "k349*&#$");
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), false, 200));
deletePreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), 200);
propMap.put("k1", "instance");
Assert.assertEquals(0, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), false, 200).size());
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), true, 200));
deletePreferences(getPreferenceURI(), 200);
propMap.clear();
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(TEST_NAMESPACE2, appName, "services", serviceName), false, 200));
Assert.assertEquals(propMap, getPreferences(getPreferenceURI(), false, 200));
}
Aggregations