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());
}
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");
}
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");
}
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);
}
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);
});
}
Aggregations