use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by caskdata.
the class GetMetadataPropertiesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
Map<String, String> properties = scope == null ? client.getProperties(metadataEntity) : client.getProperties(metadataEntity, MetadataScope.valueOf(scope.toUpperCase()));
Table table = Table.builder().setHeader("key", "value").setRows(Iterables.transform(properties.entrySet(), new Function<Map.Entry<String, String>, List<String>>() {
@Nullable
@Override
public List<String> apply(@Nullable Map.Entry<String, String> entry) {
return Lists.newArrayList(entry.getKey(), entry.getValue());
}
})).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by caskdata.
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 caskdata.
the class DefaultMetadataServiceClientTest method testCreate.
@Test
public void testCreate() throws Exception {
final MetadataEntity createEntity = MetadataEntity.builder().append("create", "test").build();
createMetadataMutation(new MetadataMutation.Create(createEntity, testMetadata, CREATE_DIRECTIVES));
Assert.assertEquals(testMetadata.getProperties(MetadataScope.SYSTEM), getMetadataProperties(createEntity, MetadataScope.SYSTEM));
Assert.assertEquals(testMetadata.getTags(MetadataScope.SYSTEM), getMetadataTags(createEntity, MetadataScope.SYSTEM));
Assert.assertEquals(testMetadata.getProperties(MetadataScope.USER), getMetadataProperties(createEntity, MetadataScope.USER));
Assert.assertEquals(testMetadata.getTags(MetadataScope.USER), getMetadataTags(createEntity, MetadataScope.USER));
// confirm that KEEP/PRESERVE work by trying to re-create the entity
final Metadata recreate = new Metadata(Collections.EMPTY_SET, ImmutableMap.of(new ScopedName(MetadataScope.SYSTEM, "x"), "10", new ScopedName(MetadataScope.SYSTEM, "y"), "20", new ScopedName(MetadataScope.USER, "z"), "40"));
createMetadataMutation(new MetadataMutation.Create(createEntity, recreate, CREATE_DIRECTIVES));
Assert.assertEquals(recreate.getProperties(MetadataScope.SYSTEM), getMetadataProperties(createEntity, MetadataScope.SYSTEM));
Assert.assertEquals(recreate.getTags(MetadataScope.SYSTEM), getMetadataTags(createEntity, MetadataScope.SYSTEM));
Assert.assertEquals(testMetadata.getProperties(MetadataScope.USER), getMetadataProperties(createEntity, MetadataScope.USER));
Assert.assertEquals(testMetadata.getTags(MetadataScope.USER), getMetadataTags(createEntity, MetadataScope.USER));
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by caskdata.
the class DefaultMetadataServiceClientTest method testDrop.
@Test
public void testDrop() throws Exception {
final MetadataEntity dropEntity = MetadataEntity.builder().append("drop", "test").build();
createMetadataMutation(new MetadataMutation.Create(dropEntity, testMetadata, CREATE_DIRECTIVES));
// confirm that the create was successful
Assert.assertEquals(testMetadata.getProperties(MetadataScope.SYSTEM), getMetadataProperties(dropEntity, MetadataScope.SYSTEM));
Assert.assertEquals(testMetadata.getTags(MetadataScope.SYSTEM), getMetadataTags(dropEntity, MetadataScope.SYSTEM));
Assert.assertEquals(testMetadata.getProperties(MetadataScope.USER), getMetadataProperties(dropEntity, MetadataScope.USER));
Assert.assertEquals(testMetadata.getTags(MetadataScope.USER), getMetadataTags(dropEntity, MetadataScope.USER));
dropMetadataMutation(new MetadataMutation.Drop(dropEntity));
Assert.assertEquals(Collections.EMPTY_MAP, getMetadataProperties(dropEntity, MetadataScope.SYSTEM));
Assert.assertEquals(Collections.EMPTY_SET, getMetadataTags(dropEntity, MetadataScope.SYSTEM));
Assert.assertEquals(Collections.EMPTY_MAP, getMetadataProperties(dropEntity, MetadataScope.USER));
Assert.assertEquals(Collections.EMPTY_SET, getMetadataTags(dropEntity, MetadataScope.USER));
}
use of io.cdap.cdap.api.metadata.MetadataEntity in project cdap by caskdata.
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());
}
Aggregations