Search in sources :

Example 1 with DELETE

use of org.commonjava.indy.db.common.StoreUpdateAction.DELETE in project indy by Commonjava.

the class AbstractStoreDataManager method refreshAffectedBy.

@Measure
protected void refreshAffectedBy(final ArtifactStore store, final ArtifactStore original, StoreUpdateAction action) {
    if (store == null) {
        return;
    }
    if (store instanceof Group && isExcludedGroup((Group) store)) {
        logger.info("Skip affectedBy calculation of group: {}", store.getName());
        return;
    }
    if (action == DELETE) {
        if (store instanceof Group) {
            Group grp = (Group) store;
            new HashSet<>(grp.getConstituents()).forEach((key) -> removeAffectedBy(key, store.getKey()));
            logger.info("Removed affected-by reverse mapping for: {} in {} member stores", store.getKey(), grp.getConstituents().size());
        } else {
            removeAffectedStore(store.getKey());
        }
    } else if (action == STORE) {
        // NOTE: Only group membership changes can affect our affectedBy, unless the update is a store deletion.
        if (store instanceof Group) {
            final Set<StoreKey> updatedConstituents = new HashSet<>(((Group) store).getConstituents());
            final Set<StoreKey> originalConstituents;
            if (original != null) {
                originalConstituents = new HashSet<>(((Group) original).getConstituents());
            } else {
                originalConstituents = new HashSet<>();
            }
            final Set<StoreKey> added = new HashSet<>();
            final Set<StoreKey> removed = new HashSet<>();
            for (StoreKey updKey : updatedConstituents) {
                if (!originalConstituents.contains(updKey)) {
                    added.add(updKey);
                }
            }
            for (StoreKey oriKey : originalConstituents) {
                if (!updatedConstituents.contains(oriKey)) {
                    removed.add(oriKey);
                }
            }
            removed.forEach((key) -> removeAffectedBy(key, store.getKey()));
            logger.info("Removed affected-by reverse mapping for: {} in {} member stores", store.getKey(), removed.size());
            added.forEach((key) -> addAffectedBy(key, store.getKey()));
            logger.info("Added affected-by reverse mapping for: {} in {} member stores", store.getKey(), added.size());
        }
    }
}
Also used : BiFunction(java.util.function.BiFunction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) LoggerFactory(org.slf4j.LoggerFactory) STORE(org.commonjava.indy.db.common.StoreUpdateAction.STORE) StringUtils(org.apache.commons.lang3.StringUtils) SslValidationConfig(org.commonjava.indy.conf.SslValidationConfig) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) Map(java.util.Map) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreEventDispatcher(org.commonjava.indy.data.StoreEventDispatcher) ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreValidator(org.commonjava.indy.data.StoreValidator) Locker(org.commonjava.cdi.util.weft.Locker) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) DELETE(org.commonjava.indy.db.common.StoreUpdateAction.DELETE) InternalFeatureConfig(org.commonjava.indy.conf.InternalFeatureConfig) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Collections.emptySet(java.util.Collections.emptySet) ValuePipe(org.commonjava.indy.util.ValuePipe) HostedRepository(org.commonjava.indy.model.core.HostedRepository) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) MDC(org.slf4j.MDC) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Group(org.commonjava.indy.model.core.Group) Set(java.util.Set) HashSet(java.util.HashSet) Collections.emptySet(java.util.Collections.emptySet) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1