Search in sources :

Example 6 with MetadataSearchResultRecord

use of co.cask.cdap.proto.metadata.MetadataSearchResultRecord 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);
}
Also used : MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 7 with MetadataSearchResultRecord

use of co.cask.cdap.proto.metadata.MetadataSearchResultRecord in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method testSearchTargetType.

@Test
public void testSearchTargetType() throws Exception {
    NamespaceId namespace = Ids.namespace("testSearchTargetType");
    namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
    appClient.deploy(namespace, createAppJarFile(AllProgramsApp.class));
    // Add metadata to app
    Set<String> tags = ImmutableSet.of("utag1", "utag2");
    ApplicationId appId = Ids.namespace(namespace.getNamespace()).app(AllProgramsApp.NAME);
    addTags(appId, tags);
    // Add metadata to stream
    tags = ImmutableSet.of("utag11");
    StreamId streamId = Ids.namespace(namespace.getNamespace()).stream(AllProgramsApp.STREAM_NAME);
    addTags(streamId, tags);
    // Add metadata to dataset
    tags = ImmutableSet.of("utag21");
    DatasetId datasetId = Ids.namespace(namespace.getNamespace()).dataset(AllProgramsApp.DATASET_NAME);
    addTags(datasetId, tags);
    // Search for single target type
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(appId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.APP));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.DATASET));
    // Search for multiple target types
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.DATASET, EntityTypeSimpleName.STREAM)));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.APP, EntityTypeSimpleName.DATASET)));
    // Search for all target types
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", EntityTypeSimpleName.ALL));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetId), new MetadataSearchResultRecord(appId), new MetadataSearchResultRecord(streamId)), searchMetadata(namespace, "utag*", ImmutableSet.of(EntityTypeSimpleName.DATASET, EntityTypeSimpleName.ALL)));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) AllProgramsApp(co.cask.cdap.client.app.AllProgramsApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 8 with MetadataSearchResultRecord

use of co.cask.cdap.proto.metadata.MetadataSearchResultRecord in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method searchMetadata.

/**
   * strips metadata from search results
   */
@Override
protected MetadataSearchResponse searchMetadata(NamespaceId namespaceId, String query, Set<EntityTypeSimpleName> targets, @Nullable String sort, int offset, int limit, int numCursors, @Nullable String cursor, boolean showHidden) throws Exception {
    MetadataSearchResponse searchResponse = super.searchMetadata(namespaceId, query, targets, sort, offset, limit, numCursors, cursor, showHidden);
    Set<MetadataSearchResultRecord> transformed = new LinkedHashSet<>();
    for (MetadataSearchResultRecord result : searchResponse.getResults()) {
        transformed.add(new MetadataSearchResultRecord(result.getEntityId()));
    }
    return new MetadataSearchResponse(searchResponse.getSort(), searchResponse.getOffset(), searchResponse.getLimit(), searchResponse.getNumCursors(), searchResponse.getTotal(), transformed, searchResponse.getCursors(), searchResponse.isShowHidden(), searchResponse.getEntityScope());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) MetadataSearchResponse(co.cask.cdap.proto.metadata.MetadataSearchResponse)

Example 9 with MetadataSearchResultRecord

use of co.cask.cdap.proto.metadata.MetadataSearchResultRecord 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(WordCountApp.class, WordCountApp.class.getSimpleName(), "1.0"));
    Set<String> tags = ImmutableSet.of("tag1", "tag2");
    ArtifactId artifact = namespace.artifact("WordCountApp", "1.0");
    ApplicationId app = namespace.app("WordCountApp");
    ProgramId flow = app.flow("WordCountFlow");
    ProgramId service = app.service("WordFrequencyService");
    StreamId stream = namespace.stream("text");
    DatasetId datasetInstance = namespace.dataset("mydataset");
    StreamViewId view = stream.view("view");
    streamViewClient.createOrUpdate(view, new ViewSpecification(new FormatSpecification("csv", null, null)));
    // Add metadata
    addTags(app, tags);
    addTags(flow, tags);
    addTags(stream, tags);
    addTags(datasetInstance, tags);
    addTags(view, tags);
    // Assert metadata
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "text"));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetInstance)), searchMetadata(namespace, "mydataset"));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(artifact), new MetadataSearchResultRecord(service)), searchMetadata(namespace, "word*"));
    Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(datasetInstance), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "tag1"));
    // Delete entities
    appClient.delete(app);
    streamViewClient.delete(view);
    streamClient.delete(stream);
    datasetClient.delete(datasetInstance);
    artifactClient.delete(artifact);
    // Assert no metadata
    Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "text"));
    Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "mydataset"));
    Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "word*"));
    Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "tag1"));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) WordCountApp(co.cask.cdap.WordCountApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Example 10 with MetadataSearchResultRecord

use of co.cask.cdap.proto.metadata.MetadataSearchResultRecord in project cdap by caskdata.

the class SearchMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String searchQuery = arguments.get(ArgumentName.SEARCH_QUERY.toString());
    String type = arguments.getOptional(ArgumentName.TARGET_TYPE.toString());
    MetadataSearchResponse metadataSearchResponse = metadataClient.searchMetadata(cliConfig.getCurrentNamespace().toId(), searchQuery, parseTargetType(type));
    Set<MetadataSearchResultRecord> searchResults = metadataSearchResponse.getResults();
    Table table = Table.builder().setHeader("Entity").setRows(Lists.newArrayList(searchResults), new RowMaker<MetadataSearchResultRecord>() {

        @Override
        public List<?> makeRow(MetadataSearchResultRecord searchResult) {
            return Lists.newArrayList(searchResult.getEntityId().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) RowMaker(co.cask.cdap.cli.util.RowMaker) MetadataSearchResponse(co.cask.cdap.proto.metadata.MetadataSearchResponse)

Aggregations

MetadataSearchResultRecord (co.cask.cdap.proto.metadata.MetadataSearchResultRecord)19 Test (org.junit.Test)12 StreamId (co.cask.cdap.proto.id.StreamId)10 DatasetId (co.cask.cdap.proto.id.DatasetId)9 NamespaceId (co.cask.cdap.proto.id.NamespaceId)8 MetadataSearchResponse (co.cask.cdap.proto.metadata.MetadataSearchResponse)7 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)6 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)5 ViewSpecification (co.cask.cdap.proto.ViewSpecification)5 StreamViewId (co.cask.cdap.proto.id.StreamViewId)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 ArtifactId (co.cask.cdap.proto.id.ArtifactId)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 AllProgramsApp (co.cask.cdap.client.app.AllProgramsApp)3 DatasetInstanceConfiguration (co.cask.cdap.proto.DatasetInstanceConfiguration)3 NamespacedEntityId (co.cask.cdap.proto.id.NamespacedEntityId)3 WordCountApp (co.cask.cdap.WordCountApp)2 EntityTypeSimpleName (co.cask.cdap.proto.element.EntityTypeSimpleName)2 Metadata (co.cask.cdap.proto.metadata.Metadata)2 MetadataScope (co.cask.cdap.proto.metadata.MetadataScope)2