Search in sources :

Example 1 with InternalFeatureConfig

use of org.commonjava.indy.conf.InternalFeatureConfig 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)

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