use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testInvalidSearchParams.
@Test
public void testInvalidSearchParams() throws Exception {
NamespaceId namespace = new NamespaceId("invalid");
Set<EntityTypeSimpleName> targets = EnumSet.allOf(EntityTypeSimpleName.class);
try {
searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY);
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with bad sort field
try {
searchMetadata(namespace, "*", targets, "name asc");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with bad sort order
try {
searchMetadata(namespace, "*", targets, AbstractSystemMetadataWriter.ENTITY_NAME_KEY + " unknown");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with numCursors for relevance sort
try {
searchMetadata(NamespaceId.DEFAULT, "search*", targets, null, 0, Integer.MAX_VALUE, 1, null);
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with cursor for relevance sort
try {
searchMetadata(NamespaceId.DEFAULT, "search*", targets, null, 0, Integer.MAX_VALUE, 0, "cursor");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// search with invalid query
try {
searchMetadata(NamespaceId.DEFAULT, "");
Assert.fail();
} catch (BadRequestException e) {
// expected
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ApplicationClientTestRun method testDeleteAll.
@Test
public void testDeleteAll() throws Exception {
NamespaceId namespace = NamespaceId.DEFAULT;
ApplicationId app = namespace.app(FakeApp.NAME);
ApplicationId app2 = namespace.app(AppReturnsArgs.NAME);
Assert.assertEquals(0, appClient.list(namespace).size());
try {
// deploy first app
LOG.info("Deploying first app");
appClient.deploy(namespace, createAppJarFile(FakeApp.class));
appClient.waitForDeployed(app, 30, TimeUnit.SECONDS);
Assert.assertEquals(1, appClient.list(namespace).size());
// deploy second app
LOG.info("Deploying second app");
appClient.deploy(namespace, createAppJarFile(AppReturnsArgs.class));
appClient.waitForDeployed(app2, 30, TimeUnit.SECONDS);
Assert.assertEquals(2, appClient.list(namespace).size());
} finally {
appClient.deleteAll(namespace);
appClient.waitForDeleted(app, 30, TimeUnit.SECONDS);
appClient.waitForDeleted(app2, 30, TimeUnit.SECONDS);
Assert.assertEquals(0, appClient.list(namespace).size());
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchResultPaginationWithTargetType.
@Test
public void testSearchResultPaginationWithTargetType() throws Exception {
// note that the ordering of the entity creations and the sort param used in this test case matter, in order to
// reproduce the scenario that caused the issue CDAP-7881
NamespaceId namespace = new NamespaceId("pagination_with_target_type");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
StreamId stream1 = namespace.stream("text1");
StreamId stream2 = namespace.stream("text2");
DatasetId trackerDataset = namespace.dataset("_auditLog");
DatasetId mydataset = namespace.dataset("mydataset");
// the creation order below will determine how we see the entities in search result sorted by entity creation time
// in ascending order
datasetClient.create(trackerDataset, new DatasetInstanceConfiguration(Table.class.getName(), Collections.<String, String>emptyMap()));
datasetClient.create(mydataset, new DatasetInstanceConfiguration(Table.class.getName(), Collections.<String, String>emptyMap()));
// create entities so system metadata is annotated
streamClient.create(stream1);
streamClient.create(stream2);
// do sorting with creation time here since the testSearchResultPagination does with entity name
// the sorted result order _auditLog mydataset text2 text1 (ascending: creation from earliest time)
String sort = AbstractSystemMetadataWriter.CREATION_TIME_KEY + " " + SortInfo.SortOrder.ASC;
// offset 1, limit 2, 2 cursors, should return 2nd result, with 0 cursors since we don't have enough data
// set showHidden to true which will show the trackerDataset but will not be in search response since its not stream
MetadataSearchResponse searchResponse = searchMetadata(namespace, "*", ImmutableSet.of(EntityTypeSimpleName.STREAM), sort, 1, 2, 2, null, true);
List<MetadataSearchResultRecord> expectedResults = ImmutableList.of(new MetadataSearchResultRecord(stream2));
List<String> expectedCursors = ImmutableList.of();
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
// offset 1, limit 2, 2 cursors, should return just the dataset created above other than trackerDataset even
// though it was created before since showHidden is false and it should not affect pagination
searchResponse = searchMetadata(namespace, "*", ImmutableSet.of(EntityTypeSimpleName.DATASET), sort, 0, 2, 2, null);
expectedResults = ImmutableList.of(new MetadataSearchResultRecord(mydataset));
expectedCursors = ImmutableList.of();
Assert.assertEquals(expectedResults, new ArrayList<>(searchResponse.getResults()));
Assert.assertEquals(expectedCursors, searchResponse.getCursors());
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LineageTestRun method testLineageInNonExistingNamespace.
@Test
public void testLineageInNonExistingNamespace() throws Exception {
NamespaceId namespace = new NamespaceId("nonExistent");
ApplicationId app = namespace.app(AllProgramsApp.NAME);
ProgramId flow = app.flow(AllProgramsApp.NoOpFlow.NAME);
assertRunMetadataNotFound(flow.run(RunIds.generate(1000).getId()));
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testProperties.
@Test
public void testProperties() throws Exception {
// should fail because we haven't provided any metadata in the request
addProperties(application, null, BadRequestException.class);
String multiWordValue = "wow1 WoW2 - WOW3 - wow4_woW5 wow6";
Map<String, String> appProperties = ImmutableMap.of("aKey", "aValue", "multiword", multiWordValue);
addProperties(application, appProperties);
// should fail because we haven't provided any metadata in the request
addProperties(pingService, null, BadRequestException.class);
Map<String, String> serviceProperties = ImmutableMap.of("sKey", "sValue", "sK", "sV");
addProperties(pingService, serviceProperties);
// should fail because we haven't provided any metadata in the request
addProperties(myds, null, BadRequestException.class);
Map<String, String> datasetProperties = ImmutableMap.of("dKey", "dValue", "dK", "dV");
addProperties(myds, datasetProperties);
// should fail because we haven't provided any metadata in the request
addProperties(mystream, null, BadRequestException.class);
Map<String, String> streamProperties = ImmutableMap.of("stKey", "stValue", "stK", "stV", "multiword", multiWordValue);
addProperties(mystream, streamProperties);
addProperties(myview, null, BadRequestException.class);
Map<String, String> viewProperties = ImmutableMap.of("viewKey", "viewValue", "viewK", "viewV");
addProperties(myview, viewProperties);
// should fail because we haven't provided any metadata in the request
addProperties(artifactId, null, BadRequestException.class);
Map<String, String> artifactProperties = ImmutableMap.of("rKey", "rValue", "rK", "rV");
addProperties(artifactId, artifactProperties);
// retrieve properties and verify
Map<String, String> properties = getProperties(application, MetadataScope.USER);
Assert.assertEquals(appProperties, properties);
properties = getProperties(pingService, MetadataScope.USER);
Assert.assertEquals(serviceProperties, properties);
properties = getProperties(myds, MetadataScope.USER);
Assert.assertEquals(datasetProperties, properties);
properties = getProperties(mystream, MetadataScope.USER);
Assert.assertEquals(streamProperties, properties);
properties = getProperties(myview, MetadataScope.USER);
Assert.assertEquals(viewProperties, properties);
properties = getProperties(artifactId, MetadataScope.USER);
Assert.assertEquals(artifactProperties, properties);
// test search for application
Set<MetadataSearchResultRecord> expected = ImmutableSet.of(new MetadataSearchResultRecord(application));
Set<MetadataSearchResultRecord> searchProperties = searchMetadata(NamespaceId.DEFAULT, "aKey:aValue", EntityTypeSimpleName.APP);
Assert.assertEquals(expected, searchProperties);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "multiword:wow1", EntityTypeSimpleName.APP);
Assert.assertEquals(expected, searchProperties);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "multiword:woW5", EntityTypeSimpleName.APP);
Assert.assertEquals(expected, searchProperties);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "WOW3", EntityTypeSimpleName.APP);
Assert.assertEquals(expected, searchProperties);
// test search for stream
searchProperties = searchMetadata(NamespaceId.DEFAULT, "stKey:stValue", EntityTypeSimpleName.STREAM);
expected = ImmutableSet.of(new MetadataSearchResultRecord(mystream));
Assert.assertEquals(expected, searchProperties);
// test search for view with lowercase key value when metadata was stored in mixed case
searchProperties = searchMetadata(NamespaceId.DEFAULT, "viewkey:viewvalue", EntityTypeSimpleName.VIEW);
expected = ImmutableSet.of(new MetadataSearchResultRecord(myview));
Assert.assertEquals(expected, searchProperties);
// test search for view with lowercase value when metadata was stored in mixed case
searchProperties = searchMetadata(NamespaceId.DEFAULT, "viewvalue", EntityTypeSimpleName.VIEW);
expected = ImmutableSet.of(new MetadataSearchResultRecord(myview));
Assert.assertEquals(expected, searchProperties);
// test search for artifact
searchProperties = searchMetadata(NamespaceId.DEFAULT, "rKey:rValue", EntityTypeSimpleName.ARTIFACT);
expected = ImmutableSet.of(new MetadataSearchResultRecord(artifactId));
Assert.assertEquals(expected, searchProperties);
expected = ImmutableSet.of(new MetadataSearchResultRecord(application), new MetadataSearchResultRecord(mystream));
searchProperties = searchMetadata(NamespaceId.DEFAULT, "multiword:w*", EntityTypeSimpleName.ALL);
Assert.assertEquals(2, searchProperties.size());
Assert.assertEquals(expected, searchProperties);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "multiword:*", EntityTypeSimpleName.ALL);
Assert.assertEquals(2, searchProperties.size());
Assert.assertEquals(expected, searchProperties);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "wo*", EntityTypeSimpleName.ALL);
Assert.assertEquals(2, searchProperties.size());
Assert.assertEquals(expected, searchProperties);
// test prefix search for service
searchProperties = searchMetadata(NamespaceId.DEFAULT, "sKey:s*", EntityTypeSimpleName.ALL);
expected = ImmutableSet.of(new MetadataSearchResultRecord(pingService));
Assert.assertEquals(expected, searchProperties);
// search without any target param
searchProperties = searchMetadata(NamespaceId.DEFAULT, "sKey:s*");
Assert.assertEquals(expected, searchProperties);
// Should get empty
searchProperties = searchMetadata(NamespaceId.DEFAULT, "sKey:s");
Assert.assertTrue(searchProperties.size() == 0);
searchProperties = searchMetadata(NamespaceId.DEFAULT, "s");
Assert.assertTrue(searchProperties.size() == 0);
// search non-existent property should return empty set
searchProperties = searchMetadata(NamespaceId.DEFAULT, "NullKey:s*");
Assert.assertEquals(ImmutableSet.<MetadataSearchResultRecord>of(), searchProperties);
// search invalid ns should return empty set
searchProperties = searchMetadata(new NamespaceId("invalidnamespace"), "sKey:s*");
Assert.assertEquals(ImmutableSet.of(), searchProperties);
// test removal
removeProperties(application);
Assert.assertTrue(getProperties(application, MetadataScope.USER).isEmpty());
removeProperty(pingService, "sKey");
removeProperty(pingService, "sK");
Assert.assertTrue(getProperties(pingService, MetadataScope.USER).isEmpty());
removeProperty(myds, "dKey");
Assert.assertEquals(ImmutableMap.of("dK", "dV"), getProperties(myds, MetadataScope.USER));
removeProperty(mystream, "stK");
removeProperty(mystream, "stKey");
Assert.assertEquals(ImmutableMap.of("multiword", multiWordValue), getProperties(mystream, MetadataScope.USER));
removeProperty(myview, "viewK");
Assert.assertEquals(ImmutableMap.of("viewKey", "viewValue"), getProperties(myview, MetadataScope.USER));
// cleanup
removeProperties(myview);
removeProperties(application);
removeProperties(pingService);
removeProperties(myds);
removeProperties(mystream);
removeProperties(artifactId);
Assert.assertTrue(getProperties(application, MetadataScope.USER).isEmpty());
Assert.assertTrue(getProperties(pingService, MetadataScope.USER).isEmpty());
Assert.assertTrue(getProperties(myds, MetadataScope.USER).isEmpty());
Assert.assertTrue(getProperties(mystream, MetadataScope.USER).isEmpty());
Assert.assertTrue(getProperties(myview, MetadataScope.USER).isEmpty());
Assert.assertTrue(getProperties(artifactId, MetadataScope.USER).isEmpty());
// non-existing namespace
addProperties(nonExistingApp, appProperties, NotFoundException.class);
addProperties(nonExistingService, serviceProperties, NotFoundException.class);
addProperties(nonExistingDataset, datasetProperties, NotFoundException.class);
addProperties(nonExistingStream, streamProperties, NotFoundException.class);
addProperties(nonExistingView, streamProperties, NotFoundException.class);
addProperties(nonExistingArtifact, artifactProperties, NotFoundException.class);
}
Aggregations