@Override public void addTags(MetadataEntity metadataEntity, Iterable<String> tags) { Set<String> tagsToAdd = new HashSet<>(); tags.forEach(tagsToAdd::add); metadataPublisher.publish(programRunId, new MetadataOperation(metadataEntity, MetadataOperation.Type.PUT, new Metadata(Collections.emptyMap(), tagsToAdd))); }
@Override public void removeProperties(MetadataEntity metadataEntity, String... keys) { Map<String, String> props = new HashMap<>(); for (String key : keys) { props.put(key, ""); } MetadataOperation metadataOperation = new MetadataOperation(metadataEntity, MetadataOperation.Type.DELETE, new Metadata(props, Collections.emptySet())); metadataPublisher.publish(programRunId, metadataOperation); }
@Override public void removeTags(MetadataEntity metadataEntity, String... tags) { MetadataOperation metadataOperation = new MetadataOperation(metadataEntity, MetadataOperation.Type.DELETE, new Metadata(Collections.emptyMap(), new HashSet<>(Arrays.asList(tags)))); metadataPublisher.publish(programRunId, metadataOperation); }
@Override public void addProperties(MetadataEntity metadataEntity, Map<String, String> properties) { metadataPublisher.publish(programRunId, new MetadataOperation(metadataEntity, MetadataOperation.Type.PUT, new Metadata(properties, Collections.emptySet()))); }
@Override public Map<MetadataScope, Metadata> getMetadata(MetadataEntity metadataEntity) { Map<MetadataScope, Metadata> scopeMetadata = new HashMap<>(); Set<MetadataRecord> metadata = metadataAdmin.getMetadata(metadataEntity); metadata.forEach(record -> scopeMetadata.put(record.getScope(), new Metadata(record.getProperties(), record.getTags()))); return scopeMetadata; }
@Override public Map<MetadataScope, Metadata> getMetadata(MetadataEntity metadataEntity) { Map<MetadataScope, Metadata> scopeMetadata = new HashMap<>(); Set<MetadataRecordV2> metadata = metadataAdmin.getMetadata(metadataEntity); metadata.forEach(record -> scopeMetadata.put(record.getScope(), new Metadata(record.getProperties(), record.getTags()))); return scopeMetadata; }
private Set<MetadataSearchResultRecord> addMetadataToEntities(Set<MetadataEntity> entities, Map<MetadataEntity, MetadataDataset.Record> systemMetadata, Map<MetadataEntity, MetadataDataset.Record> userMetadata) { Set<MetadataSearchResultRecord> result = new LinkedHashSet<>(); for (MetadataEntity entity : entities) { ImmutableMap.Builder<MetadataScope, Metadata> builder = ImmutableMap.builder(); // Add system metadata MetadataDataset.Record metadata = systemMetadata.get(entity); if (metadata != null) { builder.put(SYSTEM, new Metadata(metadata.getProperties(), metadata.getTags())); } // Add user metadata metadata = userMetadata.get(entity); if (metadata != null) { builder.put(MetadataScope.USER, new Metadata(metadata.getProperties(), metadata.getTags())); } // Create result result.add(new MetadataSearchResultRecord(entity, builder.build())); } return result; } }
private Set<MetadataSearchResultRecord> addMetadataToEntities(Set<MetadataEntity> entities, Map<MetadataEntity, MetadataDataset.Record> systemMetadata, Map<MetadataEntity, MetadataDataset.Record> userMetadata) { Set<MetadataSearchResultRecord> result = new LinkedHashSet<>(); for (MetadataEntity entity : entities) { ImmutableMap.Builder<MetadataScope, Metadata> builder = ImmutableMap.builder(); // Add system metadata MetadataDataset.Record metadata = systemMetadata.get(entity); if (metadata != null) { builder.put(SYSTEM, new Metadata(metadata.getProperties(), metadata.getTags())); } // Add user metadata metadata = userMetadata.get(entity); if (metadata != null) { builder.put(MetadataScope.USER, new Metadata(metadata.getProperties(), metadata.getTags())); } // Create result result.add(new MetadataSearchResultRecord(entity, builder.build())); } return result; }
/** * Add the deletions to the previous value of metadata to get the current value of metadata. * * @param record deletions to metadata * @return the builder object */ public MetadataPayloadBuilder addDeletions(MetadataRecord record) { deletions.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
/** * Add the previous value of metadata. * * @param record previous value of metadata record * @return the builder object */ public MetadataPayloadBuilder addPrevious(MetadataRecord record) { previous.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
/** * Add the additions to the previous value of metadata to get the current value of metadata. * * @param record additions to the metadata * @return the builder object */ public MetadataPayloadBuilder addAdditions(MetadataRecord record) { additions.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
private Set<MetadataSearchResultRecordV2> addMetadataToEntities(Set<MetadataEntity> entities, Map<MetadataEntity, Metadata> systemMetadata, Map<MetadataEntity, Metadata> userMetadata) { Set<MetadataSearchResultRecordV2> result = new LinkedHashSet<>(); for (MetadataEntity entity : entities) { ImmutableMap.Builder<MetadataScope, co.cask.cdap.api.metadata.Metadata> builder = ImmutableMap.builder(); // Add system metadata Metadata metadata = systemMetadata.get(entity); if (metadata != null) { builder.put(MetadataScope.SYSTEM, new co.cask.cdap.api.metadata.Metadata(metadata.getProperties(), metadata.getTags())); } // Add user metadata metadata = userMetadata.get(entity); if (metadata != null) { builder.put(MetadataScope.USER, new co.cask.cdap.api.metadata.Metadata(metadata.getProperties(), metadata.getTags())); } // Create result result.add(new MetadataSearchResultRecordV2(entity, builder.build())); } return result; }
/** * Add the previous value of metadata. * * @param record previous value of metadata record * @return the builder object */ public MetadataPayloadBuilder addPrevious(MetadataRecordV2 record) { previous.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
/** * Add the additions to the previous value of metadata to get the current value of metadata. * * @param record additions to the metadata * @return the builder object */ public MetadataPayloadBuilder addAdditions(MetadataRecordV2 record) { additions.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
/** * Add the deletions to the previous value of metadata to get the current value of metadata. * * @param record deletions to metadata * @return the builder object */ public MetadataPayloadBuilder addDeletions(MetadataRecordV2 record) { deletions.put(record.getScope(), new Metadata(record.getProperties(), record.getTags())); return this; }
@Override public Map<MetadataScope, Metadata> getMetadata(MetadataEntity metadataEntity) throws MetadataException { Map<MetadataScope, Metadata> scopeMetadata = new HashMap<>(); Set<MetadataRecord> metadata; try { metadata = metadataClient.getMetadata(metadataEntity); } catch (Exception e) { throw new MetadataException(e); } metadata.forEach(record -> scopeMetadata.put(record.getScope(), new Metadata(record.getProperties(), record.getTags()))); LOG.trace("Returning metadata record {} for {}", scopeMetadata, metadataEntity); return scopeMetadata; }
@Override public Map<MetadataScope, Metadata> getMetadata(MetadataEntity metadataEntity) throws MetadataException { Map<MetadataScope, Metadata> scopeMetadata = new HashMap<>(); Set<MetadataRecordV2> metadata; try { metadata = metadataClient.getMetadata(metadataEntity); } catch (Exception e) { throw new MetadataException(e); } metadata.forEach(record -> scopeMetadata.put(record.getScope(), new Metadata(record.getProperties(), record.getTags()))); LOG.trace("Returning metadata record {} for {}", scopeMetadata, metadataEntity); return scopeMetadata; }
@Override public Metadata getMetadata(MetadataScope scope, MetadataEntity metadataEntity) { final Metadata[] metadata = new Metadata[1]; metadataAdmin.getMetadata(scope, metadataEntity).forEach(record -> { if (record.getScope() == scope) { metadata[0] = new Metadata(record.getProperties(), record.getTags()); } }); return metadata[0]; } }
@Override public Metadata getMetadata(MetadataScope scope, MetadataEntity metadataEntity) { final Metadata[] metadata = new Metadata[1]; metadataAdmin.getMetadata(scope, metadataEntity).forEach(record -> { if (record.getScope() == scope) { metadata[0] = new Metadata(record.getProperties(), record.getTags()); } }); return metadata[0]; } }
Set<String> tags = record.getMetadata().getTags(scope); if (!props.isEmpty() || !tags.isEmpty()) { metaMap.put(scope, new co.cask.cdap.api.metadata.Metadata(props, tags));