use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testInvalidParams.
@Test
public void testInvalidParams() throws Exception {
NamespaceId namespace = new NamespaceId("testInvalidParams");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
try {
Set<String> targets = Collections.emptySet();
searchMetadata(namespace, "text", targets, MetadataConstants.CREATION_TIME_KEY + " desc");
Assert.fail("Expected not to be able to specify 'query' and 'sort' parameters.");
} catch (BadRequestException expected) {
// expected
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchMetadataDelete.
@Test
public void testSearchMetadataDelete() throws Exception {
NamespaceId namespace = new NamespaceId("ns1");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
// Deploy app
appClient.deploy(namespace, createAppJarFile(AllProgramsApp.class, AllProgramsApp.class.getSimpleName(), "1.0"));
ArtifactId artifact = namespace.artifact(AllProgramsApp.class.getSimpleName(), "1.0");
ApplicationId app = namespace.app(AllProgramsApp.NAME);
ProgramId service = app.service(AllProgramsApp.NoOpService.NAME);
DatasetId datasetInstance = namespace.dataset(AllProgramsApp.DATASET_NAME);
// wait for metadata to be processed
Tasks.waitFor(false, () -> getProperties(app, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(service, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(datasetInstance, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Set<String> tags = ImmutableSet.of("tag1", "tag2");
// Add metadata
addTags(app, tags);
addTags(datasetInstance, tags);
// Assert metadata
assertSearch(searchMetadata(namespace, AllProgramsApp.DATASET_NAME), datasetInstance);
assertSearch(searchMetadata(namespace, "all*"), app, artifact);
assertSearch(searchMetadata(namespace, "tag1"), app, datasetInstance);
// Delete entities
appClient.delete(app);
datasetClient.delete(datasetInstance);
artifactClient.delete(artifact);
// Assert no metadata
waitForSearch(() -> searchMetadata(namespace, AllProgramsApp.DATASET_NAME));
waitForSearch(() -> searchMetadata(namespace, "all*"));
waitForSearch(() -> searchMetadata(namespace, "tag1"));
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreferencesClientTestRun method testInvalidApplication.
@Test(expected = NotFoundException.class)
public void testInvalidApplication() throws Exception {
ApplicationId someapp = new NamespaceId("somespace").app("someapp");
client.getApplicationPreferences(someapp, true);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreferencesClientTestRun method testPreferences.
@Test
public void testPreferences() throws Exception {
NamespaceId invalidNamespace = new NamespaceId("invalid");
namespaceClient.create(new NamespaceMeta.Builder().setName(invalidNamespace).build());
Map<String, String> propMap = client.getInstancePreferences();
Assert.assertEquals(ImmutableMap.<String, String>of(), propMap);
propMap.put("k1", "instance");
client.setInstancePreferences(propMap);
Assert.assertEquals(propMap, client.getInstancePreferences());
File jarFile = createAppJarFile(FakeApp.class);
appClient.deploy(NamespaceId.DEFAULT, jarFile);
try {
propMap.put("k1", "namespace");
client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
Assert.assertTrue(client.getNamespacePreferences(invalidNamespace, false).isEmpty());
Assert.assertEquals("instance", client.getNamespacePreferences(invalidNamespace, true).get("k1"));
client.deleteNamespacePreferences(NamespaceId.DEFAULT);
propMap.put("k1", "instance");
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(ImmutableMap.<String, String>of(), client.getNamespacePreferences(NamespaceId.DEFAULT, false));
propMap.put("k1", "namespace");
client.setNamespacePreferences(NamespaceId.DEFAULT, propMap);
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, false));
propMap.put("k1", "application");
client.setApplicationPreferences(FAKE_APP_ID, propMap);
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
propMap.put("k1", "program");
ServiceId service = FAKE_APP_ID.service(FakeApp.SERVICES.get(0));
client.setProgramPreferences(service, propMap);
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
client.deleteProgramPreferences(service);
propMap.put("k1", "application");
Assert.assertTrue(client.getProgramPreferences(service, false).isEmpty());
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteApplicationPreferences(FAKE_APP_ID);
propMap.put("k1", "namespace");
Assert.assertTrue(client.getApplicationPreferences(FAKE_APP_ID, false).isEmpty());
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteNamespacePreferences(NamespaceId.DEFAULT);
propMap.put("k1", "instance");
Assert.assertTrue(client.getNamespacePreferences(NamespaceId.DEFAULT, false).isEmpty());
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
client.deleteInstancePreferences();
propMap.clear();
Assert.assertEquals(propMap, client.getInstancePreferences());
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getNamespacePreferences(NamespaceId.DEFAULT, true));
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, true));
Assert.assertEquals(propMap, client.getProgramPreferences(service, true));
// Test Deleting Application
propMap.put("k1", "application");
client.setApplicationPreferences(FAKE_APP_ID, propMap);
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
propMap.put("k1", "program");
client.setProgramPreferences(service, propMap);
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
appClient.delete(FAKE_APP_ID);
// deleting the app should have deleted the preferences that were stored. so deploy the app and check
// if the preferences are empty. we need to deploy the app again since getting preferences of non-existent apps
// is not allowed by the API.
appClient.deploy(NamespaceId.DEFAULT, jarFile);
propMap.clear();
Assert.assertEquals(propMap, client.getApplicationPreferences(FAKE_APP_ID, false));
Assert.assertEquals(propMap, client.getProgramPreferences(service, false));
} finally {
try {
appClient.delete(FAKE_APP_ID);
} catch (ApplicationNotFoundException e) {
// ok if this happens, means its already deleted.
}
namespaceClient.delete(invalidNamespace);
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreferencesClientTestRun method testInvalidProgram.
@Test(expected = ProgramNotFoundException.class)
public void testInvalidProgram() throws Exception {
ApplicationId someapp = new NamespaceId("somespace").app("someapp");
client.deleteProgramPreferences(someapp.worker("myworker"));
}
Aggregations