Search in sources :

Example 11 with MetadataDataset

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);
}
Also used : MetadataDataset(io.cdap.cdap.data2.metadata.dataset.MetadataDataset) MetadataChange(io.cdap.cdap.spi.metadata.MetadataChange)

Example 12 with MetadataDataset

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);
}
Also used : MetadataDataset(io.cdap.cdap.data2.metadata.dataset.MetadataDataset) MetadataChange(io.cdap.cdap.spi.metadata.MetadataChange)

Example 13 with MetadataDataset

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);
}
Also used : MetadataDataset(io.cdap.cdap.data2.metadata.dataset.MetadataDataset) MetadataChange(io.cdap.cdap.spi.metadata.MetadataChange)

Example 14 with MetadataDataset

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;
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Metadata(co.cask.cdap.data2.metadata.dataset.Metadata) TransactionExecutor(org.apache.tephra.TransactionExecutor) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Example 15 with MetadataDataset

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);
}
Also used : MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) TransactionExecutor(org.apache.tephra.TransactionExecutor)

Aggregations

IOException (java.io.IOException)14 MetadataDataset (co.cask.cdap.data2.metadata.dataset.MetadataDataset)12 TransactionExecutor (org.apache.tephra.TransactionExecutor)12 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 BadRequestException (co.cask.cdap.common.BadRequestException)10 MetadataDataset (io.cdap.cdap.data2.metadata.dataset.MetadataDataset)10 MetadataChange (io.cdap.cdap.spi.metadata.MetadataChange)10 MetadataRecord (co.cask.cdap.common.metadata.MetadataRecord)9 EnumSet (java.util.EnumSet)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 HashMap (java.util.HashMap)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Map (java.util.Map)7 ImmutableSet (com.google.common.collect.ImmutableSet)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 Inject (com.google.inject.Inject)4