Search in sources :

Example 1 with MetadataRecord

use of co.cask.cdap.common.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));
}
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 MetadataRecord

use of co.cask.cdap.common.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));
}
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 3 with MetadataRecord

use of co.cask.cdap.common.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));
}
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 MetadataRecord

use of co.cask.cdap.common.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();
}
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)

Example 5 with MetadataRecord

use of co.cask.cdap.common.metadata.MetadataRecord in project cdap by caskdata.

the class DefaultMetadataStore method removeTags.

/**
 * Removes all the tags from the {@link NamespacedEntityId}
 */
@Override
public void removeTags(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.removeTags(namespacedEntityId);
        }
    }, scope);
    MetadataRecord previous = previousRef.get();
    publishAudit(previous, new MetadataRecord(namespacedEntityId, scope), new MetadataRecord(namespacedEntityId, scope, EMPTY_PROPERTIES, previous.getTags()));
}
Also used : MetadataDataset(co.cask.cdap.data2.metadata.dataset.MetadataDataset) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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

MetadataRecord (co.cask.cdap.common.metadata.MetadataRecord)22 Test (org.junit.Test)10 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)9 BadRequestException (co.cask.cdap.common.BadRequestException)9 MetadataDataset (co.cask.cdap.data2.metadata.dataset.MetadataDataset)9 IOException (java.io.IOException)9 TransactionExecutor (org.apache.tephra.TransactionExecutor)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DatasetId (co.cask.cdap.proto.id.DatasetId)6 Lineage (co.cask.cdap.data2.metadata.lineage.Lineage)4 Relation (co.cask.cdap.data2.metadata.lineage.Relation)4 NamespaceId (co.cask.cdap.proto.id.NamespaceId)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 EnumSet (java.util.EnumSet)4 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 AllProgramsApp (co.cask.cdap.client.app.AllProgramsApp)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3