Search in sources :

Example 76 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class MetadataHttpHandlerTest method testMakeBackwardCompatible.

@Test
public void testMakeBackwardCompatible() {
    MetadataEntity.Builder entity = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").append(MetadataEntity.APPLICATION, "app").append(MetadataEntity.VERSION, "ver");
    MetadataEntity.Builder actual = MetadataHttpHandler.makeBackwardCompatible(entity);
    MetadataEntity expected = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").appendAsType(MetadataEntity.APPLICATION, "app").append(MetadataEntity.VERSION, "ver").build();
    Assert.assertEquals(expected, actual.build());
    entity = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").append(MetadataEntity.ARTIFACT, "art").append(MetadataEntity.VERSION, "ver");
    actual = MetadataHttpHandler.makeBackwardCompatible(entity);
    expected = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").appendAsType(MetadataEntity.ARTIFACT, "art").append(MetadataEntity.VERSION, "ver").build();
    Assert.assertEquals(expected, actual.build());
    // apps can have no version information
    entity = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").append(MetadataEntity.APPLICATION, "app");
    actual = MetadataHttpHandler.makeBackwardCompatible(entity);
    expected = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "ns").appendAsType(MetadataEntity.APPLICATION, "app").build();
    Assert.assertEquals(expected, actual.build());
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Test(org.junit.Test)

Example 77 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class AddMetadataPropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    Map<String, String> properties = parseMap(arguments.get("properties"), "<properties>");
    client.addProperties(metadataEntity, properties);
    output.println("Successfully added metadata properties");
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity)

Example 78 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class AddMetadataTagsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    Set<String> tags = ImmutableSet.copyOf(parseList(arguments.get("tags")));
    client.addTags(metadataEntity, tags);
    output.println("Successfully added metadata tags");
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity)

Example 79 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class MetadataDatasetTest method testCrossNamespaceCustomSearch.

@Test
public void testCrossNamespaceCustomSearch() throws Exception {
    String appName = "app";
    MetadataEntity ns1App = new NamespaceId("ns1").app(appName).toMetadataEntity();
    MetadataEntity ns2App = new NamespaceId("ns2").app(appName).toMetadataEntity();
    txnl.execute(() -> {
        dataset.addProperty(ns2App, MetadataConstants.ENTITY_NAME_KEY, appName);
        dataset.addProperty(ns1App, MetadataConstants.ENTITY_NAME_KEY, appName);
    });
    SortInfo nameAsc = new SortInfo(MetadataConstants.ENTITY_NAME_KEY, SortInfo.SortOrder.ASC);
    SearchRequest request = new SearchRequest(null, "*", ALL_TYPES, nameAsc, 0, 10, 0, null, false, EnumSet.allOf(EntityScope.class));
    SearchResults results = txnl.execute(() -> dataset.search(request));
    List<MetadataEntry> actual = results.getResults();
    List<MetadataEntry> expected = new ArrayList<>();
    expected.add(new MetadataEntry(ns1App, MetadataConstants.ENTITY_NAME_KEY, appName));
    expected.add(new MetadataEntry(ns2App, MetadataConstants.ENTITY_NAME_KEY, appName));
    Assert.assertEquals(expected, actual);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) EntityScope(io.cdap.cdap.proto.EntityScope) Test(org.junit.Test)

Example 80 with MetadataEntity

use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by cdapio.

the class MetadataDatasetTest method testSearchIncludesSystemEntities.

@Test
public void testSearchIncludesSystemEntities() throws InterruptedException, TransactionFailureException {
    // Use the same artifact in two different namespaces - system and ns2
    final MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity();
    final MetadataEntity ns2Artifact = new ArtifactId("ns2", "artifact", "1.0").toMetadataEntity();
    final String multiWordKey = "multiword";
    final String multiWordValue = "aV1 av2 ,  -  ,  av3 - av4_av5 av6";
    txnl.execute(() -> {
        dataset.addProperty(program1, multiWordKey, multiWordValue);
        dataset.addProperty(sysArtifact, multiWordKey, multiWordValue);
        dataset.addProperty(ns2Artifact, multiWordKey, multiWordValue);
    });
    // perform the exact same multiword search in the 'ns1' namespace. It should return the system artifact along with
    // matched entities in the 'ns1' namespace
    final MetadataEntry flowMultiWordEntry = new MetadataEntry(program1, multiWordKey, multiWordValue);
    final MetadataEntry systemArtifactEntry = new MetadataEntry(sysArtifact, multiWordKey, multiWordValue);
    final MetadataEntry ns2ArtifactEntry = new MetadataEntry(ns2Artifact, multiWordKey, multiWordValue);
    txnl.execute(() -> {
        List<MetadataEntry> results = searchByDefaultIndex("ns1", "aV5", ALL_TYPES);
        Assert.assertEquals(Sets.newHashSet(flowMultiWordEntry, systemArtifactEntry), Sets.newHashSet(results));
        // search only programs - should only return flow
        results = searchByDefaultIndex("ns1", multiWordKey + MetadataConstants.KEYVALUE_SEPARATOR + "aV5", ImmutableSet.of(MetadataEntity.PROGRAM));
        Assert.assertEquals(ImmutableList.of(flowMultiWordEntry), results);
        // search only artifacts - should only return system artifact
        results = searchByDefaultIndex("ns1", multiWordKey + MetadataConstants.KEYVALUE_SEPARATOR + multiWordValue, ImmutableSet.of(MetadataEntity.ARTIFACT));
        // this query returns the system artifact 4 times, since the dataset returns a list with duplicates for scoring
        // purposes. Convert to a Set for comparison.
        Assert.assertEquals(Sets.newHashSet(systemArtifactEntry), Sets.newHashSet(results));
        // search all entities in namespace 'ns2' - should return the system artifact and the same artifact in ns2
        results = searchByDefaultIndex("ns2", multiWordKey + MetadataConstants.KEYVALUE_SEPARATOR + "aV4", ALL_TYPES);
        Assert.assertEquals(Sets.newHashSet(systemArtifactEntry, ns2ArtifactEntry), Sets.newHashSet(results));
        // search only programs in a namespace 'ns2'. Should return empty
        results = searchByDefaultIndex("ns2", "aV*", ImmutableSet.of(MetadataEntity.PROGRAM));
        Assert.assertTrue(results.isEmpty());
        // search all entities in namespace 'ns3'. Should return only the system artifact
        results = searchByDefaultIndex("ns3", "av*", ALL_TYPES);
        Assert.assertEquals(Sets.newHashSet(systemArtifactEntry), Sets.newHashSet(results));
        // search the system namespace for all entities. Should return only the system artifact
        results = searchByDefaultIndex(NamespaceId.SYSTEM.getEntityName(), "av*", ALL_TYPES);
        Assert.assertEquals(Sets.newHashSet(systemArtifactEntry), Sets.newHashSet(results));
    });
    // clean up
    txnl.execute(() -> {
        dataset.removeProperties(program1);
        dataset.removeProperties(sysArtifact);
    });
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) Test(org.junit.Test)

Aggregations

MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)192 Test (org.junit.Test)114 Drop (io.cdap.cdap.spi.metadata.MetadataMutation.Drop)58 Update (io.cdap.cdap.spi.metadata.MetadataMutation.Update)56 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)34 HashMap (java.util.HashMap)30 HashSet (java.util.HashSet)30 Map (java.util.Map)28 ImmutableMap (com.google.common.collect.ImmutableMap)26 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 Remove (io.cdap.cdap.spi.metadata.MetadataMutation.Remove)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)22 List (java.util.List)22 Metadata (io.cdap.cdap.spi.metadata.Metadata)20 Create (io.cdap.cdap.spi.metadata.MetadataMutation.Create)20 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)20 Nullable (javax.annotation.Nullable)20 Path (javax.ws.rs.Path)20