use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method removeProperties.
/**
* Removes the specified properties of the {@link NamespacedEntityId}.
*/
@Override
public void removeProperties(final MetadataScope scope, final NamespacedEntityId namespacedEntityId, final String... keys) {
final AtomicReference<MetadataRecord> previousRef = new AtomicReference<>();
final ImmutableMap.Builder<String, String> deletesBuilder = ImmutableMap.builder();
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)));
for (String key : keys) {
MetadataEntry record = input.getProperty(namespacedEntityId, key);
if (record == null) {
continue;
}
deletesBuilder.put(record.getKey(), record.getValue());
}
input.removeProperties(namespacedEntityId, keys);
}
}, scope);
publishAudit(previousRef.get(), new MetadataRecord(namespacedEntityId, scope), new MetadataRecord(namespacedEntityId, scope, deletesBuilder.build(), EMPTY_TAGS));
}
use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method execute.
private void execute(TransactionExecutor.Procedure<MetadataDataset> func, MetadataScope scope) {
MetadataDataset metadataDataset = newMetadataDataset(scope);
TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, metadataDataset);
txExecutor.executeUnchecked(func, metadataDataset);
}
use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method addTags.
/**
* Adds tags for the specified {@link NamespacedEntityId}.
*/
@Override
public void addTags(final MetadataScope scope, final NamespacedEntityId namespacedEntityId, final String... tagsToAdd) {
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));
input.addTags(namespacedEntityId, tagsToAdd);
}
}, scope);
publishAudit(previousRef.get(), new MetadataRecord(namespacedEntityId, scope, EMPTY_PROPERTIES, Sets.newHashSet(tagsToAdd)), new MetadataRecord(namespacedEntityId, scope));
}
use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method setProperty.
@Override
public void setProperty(final MetadataScope scope, final NamespacedEntityId namespacedEntityId, final String key, final String value) {
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));
input.setProperty(namespacedEntityId, key, value);
}
}, scope);
publishAudit(previousRef.get(), new MetadataRecord(namespacedEntityId, scope, ImmutableMap.of(key, value), EMPTY_TAGS), new MetadataRecord(namespacedEntityId, scope));
}
use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method getSnapshotBeforeTime.
@Override
public Set<MetadataRecord> getSnapshotBeforeTime(MetadataScope scope, final Set<NamespacedEntityId> namespacedEntityIds, final long timeMillis) {
Set<Metadata> metadataHistoryEntries = execute(new TransactionExecutor.Function<MetadataDataset, Set<Metadata>>() {
@Override
public Set<Metadata> apply(MetadataDataset input) throws Exception {
return input.getSnapshotBeforeTime(namespacedEntityIds, timeMillis);
}
}, scope);
ImmutableSet.Builder<MetadataRecord> builder = ImmutableSet.builder();
for (Metadata metadata : metadataHistoryEntries) {
builder.add(new MetadataRecord(metadata.getEntityId(), scope, metadata.getProperties(), metadata.getTags()));
}
return builder.build();
}
Aggregations