Search in sources :

Example 1 with STORE

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

the class AbstractStoreDataManager method store.

protected boolean store(final ArtifactStore store, final ChangeSummary summary, final boolean skipIfExists, final boolean fireEvents, final EventMetadata eventMetadata) throws IndyDataException {
    if (store == null) {
        logger.warn("Tried to store null ArtifactStore!");
        return false;
    }
    AtomicReference<IndyDataException> error = new AtomicReference<>();
    logger.trace("Storing {} using operation lock: {}", store, opLocks);
    final StoreKey storeKey = store.getKey();
    logger.warn("Storing {} using operation lock: {}", store, opLocks);
    if (internalFeatureConfig != null && internalFeatureConfig.getStoreValidation() && store.getType() != group) {
        ArtifactStoreValidateData validateData = storeValidator.validate(store);
        if (!validateData.isValid()) {
            logger.warn("=> [AbstractStoreDataManager] Adding Validation Metadata to Remote Store: " + store.getKey() + " - not Valid! ");
            if (store.getMetadata() != null) {
                store.getMetadata().putAll(validateData.getErrors());
            } else {
                store.setMetadata(validateData.getErrors());
            }
        }
    }
    Function<StoreKey, Boolean> lockHandler = k -> doStore(k, store, summary, error, skipIfExists, fireEvents, eventMetadata);
    BiFunction<StoreKey, ReentrantLock, Boolean> lockFailedHandler = (k, lock) -> {
        error.set(new IndyDataException("Failed to lock: %s for STORE after %d seconds.", k, LOCK_TIMEOUT_SECONDS));
        return false;
    };
    Boolean result = opLocks.lockAnd(storeKey, LOCK_TIMEOUT_SECONDS, lockHandler, lockFailedHandler);
    if (result == null) {
        throw new IndyDataException("Store failed due to tryLock timeout.");
    }
    IndyDataException ex = error.get();
    if (ex != null) {
        throw ex;
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) 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) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with STORE

use of org.commonjava.indy.db.common.StoreUpdateAction.STORE 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)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptySet (java.util.Collections.emptySet)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang3.StringUtils)2 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)2 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)2