use of co.cask.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 co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method fetchMetadata.
private Map<NamespacedEntityId, Metadata> fetchMetadata(final Set<NamespacedEntityId> namespacedEntityIds, MetadataScope scope) {
Set<Metadata> metadataSet = execute(new TransactionExecutor.Function<MetadataDataset, Set<Metadata>>() {
@Override
public Set<Metadata> apply(MetadataDataset input) throws Exception {
return input.getMetadata(namespacedEntityIds);
}
}, scope);
Map<NamespacedEntityId, Metadata> metadataMap = new HashMap<>();
for (Metadata m : metadataSet) {
metadataMap.put(m.getEntityId(), m);
}
return metadataMap;
}
use of co.cask.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 co.cask.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 co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class MetadataDatasetTest method testIndexRebuilding.
@Test
public void testIndexRebuilding() throws Exception {
final MetadataDataset dataset = getDataset(DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("testIndexRebuilding"));
TransactionExecutor txnl = dsFrameworkUtil.newInMemoryTransactionExecutor((TransactionAware) dataset);
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
Indexer indexer = new ReversingIndexer();
dataset.setMetadata(new MetadataEntry(flow1, "flowKey", "flowValue"), Collections.singleton(indexer));
dataset.setMetadata(new MetadataEntry(dataset1, "datasetKey", "datasetValue"), Collections.singleton(indexer));
}
});
final String namespaceId = flow1.getNamespace();
final Set<EntityTypeSimpleName> targetTypes = Collections.singleton(EntityTypeSimpleName.ALL);
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
List<MetadataEntry> searchResults = searchByDefaultIndex(dataset, namespaceId, "flowValue", targetTypes);
Assert.assertTrue(searchResults.isEmpty());
searchResults = searchByDefaultIndex(dataset, namespaceId, "flowKey:flow*", targetTypes);
Assert.assertTrue(searchResults.isEmpty());
searchResults = searchByDefaultIndex(dataset, namespaceId, "datasetValue", targetTypes);
Assert.assertTrue(searchResults.isEmpty());
searchResults = searchByDefaultIndex(dataset, namespaceId, "datasetKey:dataset*", targetTypes);
Assert.assertTrue(searchResults.isEmpty());
}
});
final AtomicReference<byte[]> startRowKeyForNextBatch = new AtomicReference<>();
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
// Re-build indexes. Now the default indexer should be used
startRowKeyForNextBatch.set(dataset.rebuildIndexes(null, 1));
Assert.assertNotNull(startRowKeyForNextBatch.get());
}
});
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
List<MetadataEntry> flowSearchResults = searchByDefaultIndex(dataset, namespaceId, "flowValue", targetTypes);
List<MetadataEntry> dsSearchResults = searchByDefaultIndex(dataset, namespaceId, "datasetValue", targetTypes);
if (!flowSearchResults.isEmpty()) {
Assert.assertEquals(1, flowSearchResults.size());
flowSearchResults = searchByDefaultIndex(dataset, namespaceId, "flowKey:flow*", targetTypes);
Assert.assertEquals(1, flowSearchResults.size());
Assert.assertTrue(dsSearchResults.isEmpty());
dsSearchResults = searchByDefaultIndex(dataset, namespaceId, "datasetKey:dataset*", targetTypes);
Assert.assertTrue(dsSearchResults.isEmpty());
} else {
flowSearchResults = searchByDefaultIndex(dataset, namespaceId, "flowKey:flow*", targetTypes);
Assert.assertTrue(flowSearchResults.isEmpty());
Assert.assertEquals(1, dsSearchResults.size());
dsSearchResults = searchByDefaultIndex(dataset, namespaceId, "datasetKey:dataset*", targetTypes);
Assert.assertEquals(1, dsSearchResults.size());
}
}
});
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
startRowKeyForNextBatch.set(dataset.rebuildIndexes(startRowKeyForNextBatch.get(), 1));
Assert.assertNull(startRowKeyForNextBatch.get());
}
});
txnl.execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
List<MetadataEntry> searchResults = searchByDefaultIndex(dataset, namespaceId, "flowValue", targetTypes);
Assert.assertEquals(1, searchResults.size());
searchResults = searchByDefaultIndex(dataset, namespaceId, "flowKey:flow*", targetTypes);
Assert.assertEquals(1, searchResults.size());
searchResults = searchByDefaultIndex(dataset, namespaceId, "datasetValue", targetTypes);
Assert.assertEquals(1, searchResults.size());
searchResults = searchByDefaultIndex(dataset, namespaceId, "datasetKey:dataset*", targetTypes);
Assert.assertEquals(1, searchResults.size());
}
});
}
Aggregations