Search in sources :

Example 1 with MetadataDataset

use of co.cask.cdap.data2.metadata.dataset.MetadataDataset 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));
}
Also used : MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) MetadataEntry(co.cask.cdap.data2.metadata.dataset.MetadataEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionExecutor(org.apache.tephra.TransactionExecutor) MetadataRecord(co.cask.cdap.common.metadata.MetadataRecord) ImmutableMap(com.google.common.collect.ImmutableMap) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Example 2 with MetadataDataset

use of co.cask.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.

the class DefaultMetadataStore method execute.

private void execute(TransactionExecutor.Procedure<MetadataDataset> func, MetadataScope scope) {
    MetadataDataset metadataDataset = newMetadataDataset(scope);
    TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, metadataDataset);
    txExecutor.executeUnchecked(func, metadataDataset);
}
Also used : MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) TransactionExecutor(org.apache.tephra.TransactionExecutor)

Example 3 with MetadataDataset

use of co.cask.cdap.data2.metadata.dataset.MetadataDataset 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));
}
Also used : 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) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionExecutor(org.apache.tephra.TransactionExecutor) MetadataRecord(co.cask.cdap.common.metadata.MetadataRecord) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Example 4 with MetadataDataset

use of co.cask.cdap.data2.metadata.dataset.MetadataDataset 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));
}
Also used : 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) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionExecutor(org.apache.tephra.TransactionExecutor) MetadataRecord(co.cask.cdap.common.metadata.MetadataRecord) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Example 5 with MetadataDataset

use of co.cask.cdap.data2.metadata.dataset.MetadataDataset 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();
}
Also used : 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) ImmutableSet(com.google.common.collect.ImmutableSet) Metadata(co.cask.cdap.data2.metadata.dataset.Metadata) TransactionExecutor(org.apache.tephra.TransactionExecutor) MetadataRecord(co.cask.cdap.common.metadata.MetadataRecord) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException)

Aggregations

TransactionExecutor (org.apache.tephra.TransactionExecutor)14 BadRequestException (co.cask.cdap.common.BadRequestException)13 MetadataDataset (co.cask.cdap.data2.metadata.dataset.MetadataDataset)12 IOException (java.io.IOException)11 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 MetadataRecord (co.cask.cdap.common.metadata.MetadataRecord)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 ImmutableSet (com.google.common.collect.ImmutableSet)5 EnumSet (java.util.EnumSet)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Indexer (co.cask.cdap.data2.metadata.indexer.Indexer)3 InvertedValueIndexer (co.cask.cdap.data2.metadata.indexer.InvertedValueIndexer)3 Map (java.util.Map)3 Metadata (co.cask.cdap.data2.metadata.dataset.Metadata)2 MetadataEntry (co.cask.cdap.data2.metadata.dataset.MetadataEntry)2 EntityTypeSimpleName (co.cask.cdap.proto.element.EntityTypeSimpleName)2