use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method removeTags.
/**
* Removes the specified tags from the {@link NamespacedEntityId}
*/
@Override
public void removeTags(final MetadataScope scope, final NamespacedEntityId namespacedEntityId, final String... tagsToRemove) {
final AtomicReference<MetadataRecord> previousRef = new AtomicReference<>();
execute(new TransactionExecutor.Procedure<MetadataDataset>() {
@Override
public void apply(MetadataDataset input) throws Exception {
previousRef.set(new MetadataRecord(namespacedEntityId, scope, input.getProperties(namespacedEntityId), input.getTags(namespacedEntityId)));
input.removeTags(namespacedEntityId, tagsToRemove);
}
}, scope);
publishAudit(previousRef.get(), new MetadataRecord(namespacedEntityId, scope), new MetadataRecord(namespacedEntityId, scope, EMPTY_PROPERTIES, Sets.newHashSet(tagsToRemove)));
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method removeProperties.
/**
* Removes all properties for the specified {@link NamespacedEntityId}.
*/
@Override
public void removeProperties(final MetadataScope scope, final NamespacedEntityId namespacedEntityId) {
final AtomicReference<MetadataRecord> previousRef = new AtomicReference<>();
execute(new TransactionExecutor.Procedure<MetadataDataset>() {
@Override
public void apply(MetadataDataset input) throws Exception {
previousRef.set(new MetadataRecord(namespacedEntityId, scope, input.getProperties(namespacedEntityId), input.getTags(namespacedEntityId)));
input.removeProperties(namespacedEntityId);
}
}, scope);
publishAudit(previousRef.get(), new MetadataRecord(namespacedEntityId, scope), new MetadataRecord(namespacedEntityId, scope, previousRef.get().getProperties(), EMPTY_TAGS));
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method setProperties.
/**
* Adds/updates metadata for the specified {@link NamespacedEntityId}.
*/
@Override
public void setProperties(final MetadataScope scope, final NamespacedEntityId namespacedEntityId, final Map<String, String> properties) {
final AtomicReference<MetadataRecord> previousRef = new AtomicReference<>();
execute(new TransactionExecutor.Procedure<MetadataDataset>() {
@Override
public void apply(MetadataDataset input) throws Exception {
Map<String, String> existingProperties = input.getProperties(namespacedEntityId);
Set<String> existingTags = input.getTags(namespacedEntityId);
previousRef.set(new MetadataRecord(namespacedEntityId, scope, existingProperties, existingTags));
for (Map.Entry<String, String> entry : properties.entrySet()) {
input.setProperty(namespacedEntityId, entry.getKey(), entry.getValue());
}
}
}, scope);
final ImmutableMap.Builder<String, String> propAdditions = ImmutableMap.builder();
final ImmutableMap.Builder<String, String> propDeletions = ImmutableMap.builder();
MetadataRecord previousRecord = previousRef.get();
// Iterating over properties all over again, because we want to move the diff calculation outside the transaction.
for (Map.Entry<String, String> entry : properties.entrySet()) {
String existingValue = previousRecord.getProperties().get(entry.getKey());
if (existingValue != null && existingValue.equals(entry.getValue())) {
// Value already exists and is the same as the value being passed. No update necessary.
continue;
}
// If it is an update, then mark a single deletion.
if (existingValue != null) {
propDeletions.put(entry.getKey(), existingValue);
}
// In both update or new cases, mark a single addition.
propAdditions.put(entry.getKey(), entry.getValue());
}
publishAudit(previousRecord, new MetadataRecord(namespacedEntityId, scope, propAdditions.build(), EMPTY_TAGS), new MetadataRecord(namespacedEntityId, scope, propDeletions.build(), EMPTY_TAGS));
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method removeMetadata.
/**
* Removes all metadata (including properties and tags) for the specified {@link NamespacedEntityId}.
*/
@Override
public void removeMetadata(final MetadataScope scope, final NamespacedEntityId namespacedEntityId) {
final AtomicReference<MetadataRecord> previousRef = new AtomicReference<>();
execute(new TransactionExecutor.Procedure<MetadataDataset>() {
@Override
public void apply(MetadataDataset input) throws Exception {
previousRef.set(new MetadataRecord(namespacedEntityId, scope, input.getProperties(namespacedEntityId), input.getTags(namespacedEntityId)));
input.removeProperties(namespacedEntityId);
input.removeTags(namespacedEntityId);
}
}, scope);
MetadataRecord previous = previousRef.get();
publishAudit(previous, new MetadataRecord(namespacedEntityId, scope), new MetadataRecord(previous));
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DatasetMetadataStorage method addInScope.
private MetadataDataset.Change addInScope(MetadataDatasetContext context, MetadataScope scope, MetadataEntity entity, Set<String> tagsToAdd, Map<String, String> propertiesToAdd) {
MetadataDataset dataset = context.getDataset(scope);
MetadataDataset.Record before = null, after = null;
if (tagsToAdd.isEmpty() && propertiesToAdd.isEmpty()) {
before = dataset.getMetadata(entity);
after = before;
} else {
if (!tagsToAdd.isEmpty()) {
MetadataDataset.Change change = dataset.addTags(entity, tagsToAdd);
before = change.getExisting();
after = change.getLatest();
}
if (!propertiesToAdd.isEmpty()) {
MetadataDataset.Change change = dataset.addProperties(entity, propertiesToAdd);
before = before != null ? before : change.getExisting();
after = change.getLatest();
}
}
return new MetadataDataset.Change(before, after);
}
Aggregations