use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by cdapio.
the class DatasetMetadataStorage method removeScope.
private MetadataDataset.Change removeScope(MetadataDatasetContext context, MetadataScope scope, MetadataEntity entity, Set<MetadataScope> scopesToRemoves, Set<MetadataKind> kindsToRemove) {
MetadataDataset dataset = context.getDataset(scope);
if (scopesToRemoves.contains(scope)) {
if (MetadataKind.ALL.equals(kindsToRemove)) {
return dataset.removeMetadata(entity);
}
if (kindsToRemove.contains(PROPERTY)) {
return dataset.removeProperties(entity);
}
if (kindsToRemove.contains(TAG)) {
return dataset.removeTags(entity);
}
}
// nothing to remove - return identity change
MetadataDataset.Record existing = dataset.getMetadata(entity);
return new MetadataDataset.Change(existing, existing);
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by cdapio.
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);
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by cdapio.
the class DatasetMetadataStorage method removeInScope.
private MetadataDataset.Change removeInScope(MetadataDatasetContext context, MetadataScope scope, MetadataEntity entity, Set<String> tagsToRemove, Set<String> propertiesToRemove) {
MetadataDataset dataset = context.getDataset(scope);
MetadataDataset.Record before = null;
MetadataDataset.Record after = null;
if (tagsToRemove.isEmpty() && propertiesToRemove.isEmpty()) {
before = dataset.getMetadata(entity);
after = before;
} else {
if (!tagsToRemove.isEmpty()) {
MetadataDataset.Change change = dataset.removeTags(entity, tagsToRemove);
before = change.getExisting();
after = change.getLatest();
}
if (!propertiesToRemove.isEmpty()) {
MetadataDataset.Change change = dataset.removeProperties(entity, propertiesToRemove);
before = before != null ? before : change.getExisting();
after = change.getLatest();
}
}
return new MetadataDataset.Change(before, after);
}
use of io.cdap.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 io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DefaultMetadataStore method execute.
private <T> T execute(TransactionExecutor.Function<MetadataDataset, T> func, MetadataScope scope) {
MetadataDataset metadataDataset = newMetadataDataset(scope);
TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, metadataDataset);
return txExecutor.executeUnchecked(func, metadataDataset);
}
Aggregations