use of co.cask.cdap.proto.metadata.MetadataRecord 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.proto.metadata.MetadataRecord 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.proto.metadata.MetadataRecord 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();
}
use of co.cask.cdap.proto.metadata.MetadataRecord 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.proto.metadata.MetadataRecord in project cdap by caskdata.
the class ArtifactHttpHandlerTest method testDeletePropertiesAndArtifacts.
@Test
public void testDeletePropertiesAndArtifacts() throws Exception {
// add 2 versions of the same app that doesn't use config
Id.Artifact wordcountId1 = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcount", "1.0.0");
Assert.assertEquals(HttpResponseStatus.OK.getCode(), addAppArtifact(wordcountId1, WordCountApp.class).getStatusLine().getStatusCode());
// test get /artifacts endpoint
Set<ArtifactSummary> expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"));
Set<ArtifactSummary> actualArtifacts = getArtifacts(Id.Namespace.DEFAULT);
Assert.assertEquals(expectedArtifacts, actualArtifacts);
addArtifactProperties(wordcountId1, ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));
Assert.assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"), getArtifactProperties(wordcountId1));
// delete a single property
deleteArtifact(wordcountId1, false, "key1", 200);
Assert.assertEquals(ImmutableMap.of("key2", "value2", "key3", "value3"), getArtifactProperties(wordcountId1));
// delete all properties
deleteArtifact(wordcountId1, false, null, 200);
Assert.assertEquals(ImmutableMap.of(), getArtifactProperties(wordcountId1));
Set<MetadataRecord> metadataRecords = metadataClient.getMetadata(wordcountId1, MetadataScope.USER);
Assert.assertEquals(1, metadataRecords.size());
Assert.assertEquals(new MetadataRecord(wordcountId1.toEntityId(), MetadataScope.USER), metadataRecords.iterator().next());
// delete artifact
deleteArtifact(wordcountId1, true, null, 200);
try {
metadataClient.getMetadata(wordcountId1, MetadataScope.USER);
Assert.fail("Should not reach here");
} catch (NotFoundException e) {
// no-op
}
actualArtifacts = getArtifacts(Id.Namespace.DEFAULT);
Assert.assertTrue(actualArtifacts.isEmpty());
}
Aggregations