use of co.cask.cdap.common.metadata.MetadataRecord 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 co.cask.cdap.common.metadata.MetadataRecord 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 co.cask.cdap.common.metadata.MetadataRecord 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 co.cask.cdap.common.metadata.MetadataRecord 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 co.cask.cdap.common.metadata.MetadataRecord in project cdap by caskdata.
the class ArtifactRepositoryTest method testDeletingArtifact.
@Test
public void testDeletingArtifact() throws Exception {
MetadataRecord record = metadataStore.getMetadata(MetadataScope.SYSTEM, APP_ARTIFACT_ID.toEntityId());
Assert.assertFalse(record.getProperties().isEmpty());
artifactRepository.deleteArtifact(APP_ARTIFACT_ID);
record = metadataStore.getMetadata(MetadataScope.SYSTEM, APP_ARTIFACT_ID.toEntityId());
Assert.assertTrue(record.getProperties().isEmpty());
}
Aggregations