Search in sources :

Example 1 with GROUP_METADATA_GENERATED

use of org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED in project indy by Commonjava.

the class IndexingContentManagerDecorator method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (!indexCfg.isEnabled()) {
        return delegate.retrieve(store, path, eventMetadata);
    }
    if (store == null) {
        return null;
    }
    logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD, eventMetadata);
    if (transfer != null) {
        logger.debug("Found indexed transfer: {}. Returning.", transfer);
        return transfer;
    } else if (isAuthoritativelyMissing(store)) {
        logger.debug("Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null.", transfer);
        return null;
    }
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        if (nfc.isMissing(resource)) {
            logger.debug("{} is marked as missing. Returning null.", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (specialPathInfo == null || !specialPathInfo.isMergable()) {
            if (PathMaskChecker.checkMask(store, path)) {
                transfer = getTransferFromConstituents(((Group) store).getConstituents(), resource, path, store, memberKey -> {
                    try {
                        ArtifactStore member = storeDataManager.getArtifactStore(memberKey);
                        if (member == null) {
                            logger.trace("Cannot find store for key: {}", memberKey);
                        } else {
                            return retrieve(member, path, eventMetadata);
                        }
                    } catch (IndyDataException e) {
                        logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", memberKey, store.getKey(), e.getMessage()), e);
                    }
                    return null;
                });
                nfcForGroup(store, transfer, resource);
                return transfer;
            } else {
                return null;
            }
        } else {
            logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
            transfer = delegate.retrieve(store, path, eventMetadata);
            if (!exists(transfer)) {
                Boolean metadataGenerated = (Boolean) eventMetadata.get(GROUP_METADATA_GENERATED);
                Boolean metadataExists = (Boolean) eventMetadata.get(GROUP_METADATA_EXISTS);
                if (Boolean.TRUE.equals(metadataGenerated) || Boolean.TRUE.equals(metadataExists)) {
                    // metadata generated/exists but missing due to membership change, not add to nfc so next req can retry
                    ;
                } else // don't track NFC for hosted repos
                {
                    nfc.addMissing(resource);
                }
            }
            return transfer;
        }
    }
    logger.trace("Delegating retrieve call for concrete repository: {}/{}", store, path);
    transfer = delegate.retrieve(store, path, eventMetadata);
    if (exists(transfer) && indexCfg.isEnabled()) {
        logger.debug("Got transfer from delegate: {} (will index)", transfer);
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) Arrays(java.util.Arrays) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) GROUP_METADATA_GENERATED(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) GROUP_METADATA_EXISTS(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Executor(java.util.concurrent.Executor) PathMaskChecker(org.commonjava.indy.core.content.PathMaskChecker) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ContentIndexConfig(org.commonjava.indy.content.index.conf.ContentIndexConfig) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Aggregations

InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Executor (java.util.concurrent.Executor)1 Decorator (javax.decorator.Decorator)1 Delegate (javax.decorator.Delegate)1 Any (javax.enterprise.inject.Any)1 Inject (javax.inject.Inject)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 ContentManager (org.commonjava.indy.content.ContentManager)1 ContentIndexConfig (org.commonjava.indy.content.index.conf.ContentIndexConfig)1 PathMaskChecker (org.commonjava.indy.core.content.PathMaskChecker)1 GROUP_METADATA_EXISTS (org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS)1 GROUP_METADATA_GENERATED (org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1