use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class PreferencesHttpHandlerInternalTest method testProgram.
@Test
public void testProgram() throws Exception {
String uriInstance = getPreferenceURI();
String namespace2 = TEST_NAMESPACE2;
String appName = AllProgramsApp.NAME;
String uriNamespace2Service = getPreferenceURI(namespace2, appName, "services", AllProgramsApp.NoOpService.NAME);
PreferencesDetail detail;
Map<String, String> programProperties = Maps.newHashMap();
// Create application.
addApplication(namespace2, new AllProgramsApp());
// Get preferences on invalid program type
getPreferencesInternal(getPreferenceURI(namespace2, appName, "invalidType", "somename"), false, HttpResponseStatus.BAD_REQUEST);
// Get preferences on non-existing program id. Should succeed and get back a PreferencesDetail with empty properites
detail = getPreferencesInternal(getPreferenceURI(namespace2, appName, "services", "somename"), false, HttpResponseStatus.OK);
Assert.assertTrue(detail.getProperties().isEmpty());
Assert.assertFalse(detail.getResolved());
Assert.assertEquals(0, detail.getSeqId());
// Set preferences on the program
programProperties.clear();
programProperties.put("key0", "program-val0");
programProperties.put("program-key1", "program-val1");
setPreferences(uriNamespace2Service, programProperties, 200);
// Get and verify preferences
detail = getPreferencesInternal(uriNamespace2Service, false, HttpResponseStatus.OK);
Assert.assertEquals(programProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertFalse(detail.getResolved());
// Set preferences on the instance and verify.
Map<String, String> instanceProperties = ImmutableMap.of("key0", "instance-key0", "instance-key1", "instance-val1");
setPreferences(uriInstance, instanceProperties, 200);
// Get resolved preferences on the program
detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
Map<String, String> combinedProperties = Maps.newHashMap();
combinedProperties.putAll(instanceProperties);
combinedProperties.putAll(programProperties);
Assert.assertEquals(combinedProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
// Delete preferences on the program
deletePreferences(uriNamespace2Service, 200);
detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
Assert.assertEquals(instanceProperties, detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
// Delete preferences on the instance
deletePreferences(uriInstance, 200);
detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
Assert.assertEquals(Collections.emptyMap(), detail.getProperties());
Assert.assertTrue(detail.getSeqId() > 0);
Assert.assertTrue(detail.getResolved());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
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 caskdata.
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));
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
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 caskdata.
the class ProgramLifecycleHttpHandlerTest method testProgramList.
/**
* Tests for program list calls
*/
@Test
public void testProgramList() throws Exception {
// test initial state
testListInitialState(TEST_NAMESPACE2, ProgramType.MAPREDUCE);
testListInitialState(TEST_NAMESPACE1, ProgramType.WORKFLOW);
testListInitialState(TEST_NAMESPACE2, ProgramType.SPARK);
testListInitialState(TEST_NAMESPACE1, ProgramType.SERVICE);
// deploy AllProgramsApp in namespace1 and verify
deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
// deploy AppWithServices in namespace2 and verify
deploy(AppWithServices.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
ApplicationSpecification allProgramSpec = Specifications.from(new AllProgramsApp());
// verify list by namespace
for (io.cdap.cdap.api.app.ProgramType type : io.cdap.cdap.api.app.ProgramType.values()) {
Set<String> programsByType = allProgramSpec.getProgramsByType(type);
verifyProgramList(TEST_NAMESPACE1, ProgramType.valueOf(type.name()), programsByType.size());
}
verifyProgramList(TEST_NAMESPACE2, ProgramType.SERVICE, 1);
// verify list by app
for (io.cdap.cdap.api.app.ProgramType type : io.cdap.cdap.api.app.ProgramType.values()) {
Set<String> programsByType = allProgramSpec.getProgramsByType(type);
verifyProgramList(TEST_NAMESPACE1, AllProgramsApp.NAME, ProgramType.valueOf(type.name()), programsByType.size());
}
verifyProgramList(TEST_NAMESPACE2, AppWithServices.NAME, ProgramType.SERVICE, 1);
// verify invalid namespace
Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, AppWithServices.SERVICE_NAME));
// verify invalid app
Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, "random"));
}
Aggregations