Search in sources :

Example 16 with MetadataEntity

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);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Table(io.cdap.cdap.cli.util.table.Table) List(java.util.List) Map(java.util.Map) Nullable(javax.annotation.Nullable)

Example 17 with MetadataEntity

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");
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity)

Example 18 with MetadataEntity

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));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) Metadata(io.cdap.cdap.spi.metadata.Metadata) ScopedName(io.cdap.cdap.spi.metadata.ScopedName) Test(org.junit.Test)

Example 19 with MetadataEntity

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));
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) Test(org.junit.Test)

Example 20 with MetadataEntity

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());
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) 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