Search in sources :

Example 91 with MetadataEntity

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

the class GetMetadataTagsCommand 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());
    Set<String> tags = scope == null ? client.getTags(metadataEntity) : client.getTags(metadataEntity, MetadataScope.valueOf(scope.toUpperCase()));
    Table table = Table.builder().setHeader("tags").setRows(Iterables.transform(tags, new Function<String, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(@Nullable String tag) {
            return Lists.newArrayList(tag);
        }
    })).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) Nullable(javax.annotation.Nullable)

Example 92 with MetadataEntity

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

the class RemoveMetadataPropertiesCommand method perform.

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

Example 93 with MetadataEntity

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

the class RemoveMetadataTagCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    String tag = arguments.get("tag");
    client.removeTag(metadataEntity, tag);
    output.println("Successfully removed metadata tag");
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity)

Example 94 with MetadataEntity

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

the class RemoveMetadataTagsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    client.removeTags(metadataEntity);
    output.println("Successfully removed metadata tags");
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity)

Example 95 with MetadataEntity

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

the class MetadataHttpHandlerTestRun method testSystemScopeArtifacts.

@Test
public void testSystemScopeArtifacts() throws Exception {
    // add a system artifact. currently can't do this through the rest api (by design)
    // so bypass it and use the repository directly
    ArtifactId systemId = NamespaceId.SYSTEM.artifact("app", "1.0.0");
    File systemArtifact = createArtifactJarFile(AllProgramsApp.class, "app", "1.0.0", new Manifest());
    StandaloneTester tester = STANDALONE.get();
    tester.addSystemArtifact(systemId.getArtifact(), Id.Artifact.fromEntityId(systemId).getVersion(), systemArtifact, null);
    // wait until the system metadata has been processed
    Tasks.waitFor(false, () -> getProperties(systemId, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
    // verify that user metadata can be added for system-scope artifacts
    Map<String, String> userProperties = ImmutableMap.of("systemArtifactKey", "systemArtifactValue");
    Set<String> userTags = ImmutableSet.of();
    addProperties(systemId, userProperties);
    addTags(systemId, userTags);
    // verify that user and system metadata can be retrieved for system-scope artifacts
    Assert.assertEquals(ImmutableSet.of(new MetadataRecord(systemId, MetadataScope.USER, userProperties, userTags), new MetadataRecord(systemId, MetadataScope.SYSTEM, ImmutableMap.of(MetadataConstants.ENTITY_NAME_KEY, systemId.getEntityName()), ImmutableSet.of())), removeCreationTime(getMetadata(systemId.toMetadataEntity())));
    // verify that system scope artifacts can be returned by a search in the default namespace
    // with no target type
    MetadataSearchResponse response = searchMetadata(ImmutableList.of(NamespaceId.DEFAULT, NamespaceId.SYSTEM), "system*");
    MetadataEntity expectedEntity = systemId.toMetadataEntity();
    Set<MetadataEntity> actualEntities = new HashSet<>(extractMetadataEntities(response.getResults()));
    Assert.assertTrue(actualEntities.contains(expectedEntity));
    // with target type as artifact
    assertSearch(searchMetadata(ImmutableList.of(NamespaceId.DEFAULT, NamespaceId.SYSTEM), "system*", MetadataEntity.ARTIFACT), systemId);
    // verify that user metadata can be deleted for system-scope artifacts
    removeMetadata(systemId);
    Assert.assertEquals(ImmutableSet.of(new MetadataRecord(systemId, MetadataScope.USER, ImmutableMap.of(), ImmutableSet.of()), new MetadataRecord(systemId, MetadataScope.SYSTEM, ImmutableMap.of(MetadataConstants.ENTITY_NAME_KEY, systemId.getEntityName()), ImmutableSet.of())), removeCreationTime(getMetadata(systemId.toMetadataEntity())));
    artifactClient.delete(systemId);
}
Also used : StandaloneTester(io.cdap.cdap.StandaloneTester) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) MetadataSearchResponse(io.cdap.cdap.proto.metadata.MetadataSearchResponse) Manifest(java.util.jar.Manifest) MetadataRecord(io.cdap.cdap.common.metadata.MetadataRecord) File(java.io.File) HashSet(java.util.HashSet) 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