Search in sources :

Example 1 with SpecialPathInfo

use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.

the class SpecialPathManagerImpl method getPathInfo.

private SpecialPathInfo getPathInfo(Location location, String path, Collection<SpecialPathInfo> from) {
    SpecialPathInfo firstHit = null;
    // Location is not used in current SpecialPathMatcher impl classes, so removed the null check.
    if (path != null) {
        for (SpecialPathInfo info : from) {
            if (info.getMatcher().matches(location, path)) {
                if (firstHit != null) {
                    Logger logger = LoggerFactory.getLogger(getClass());
                    logger.error("Duplicate special-path registration for: {}:{}. Using: {}", location, path, firstHit);
                } else {
                    firstHit = info;
                }
            }
        }
    }
    // TODO: Return SpecialPathConstants.DEFAULT_FILE or SpecialPathConstants.DEFAULT_DIR based on path if firstHit is null!
    return firstHit;
}
Also used : SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Logger(org.slf4j.Logger)

Example 2 with SpecialPathInfo

use of org.commonjava.maven.galley.model.SpecialPathInfo in project indy by Commonjava.

the class InfinispanGalleyStorageProvider method setup.

@PostConstruct
public void setup() {
    SpecialPathInfo infoSpi = SpecialPathInfo.from(new FilePatternMatcher(".+\\.info")).setDecoratable(false).setDeletable(false).setListable(false).setPublishable(false).setRetrievable(false).setStorable(false).build();
    specialPathManager.registerSpecialPathInfo(infoSpi);
    transferDecorator = new ChecksummingTransferDecorator(Collections.singleton(TransferOperation.GENERATE), specialPathManager, new Md5GeneratorFactory(), new Sha1GeneratorFactory());
    this.cacheProvider = new GridFileSystemCacheProvider(pathGenerator, fileEventManager, transferDecorator, cacheFs);
}
Also used : Sha1GeneratorFactory(org.commonjava.maven.galley.io.checksum.Sha1GeneratorFactory) GridFileSystemCacheProvider(org.commonjava.maven.galley.cache.infinispan.GridFileSystemCacheProvider) FilePatternMatcher(org.commonjava.maven.galley.model.FilePatternMatcher) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) Md5GeneratorFactory(org.commonjava.maven.galley.io.checksum.Md5GeneratorFactory) PostConstruct(javax.annotation.PostConstruct)

Example 3 with SpecialPathInfo

use of org.commonjava.maven.galley.model.SpecialPathInfo in project indy by Commonjava.

the class ScheduleManager method setProxyTimeouts.

public synchronized void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    RemoteRepository repo = null;
    try {
        repo = (RemoteRepository) dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (repo == null) {
        return;
    }
    int timeout = config.getPassthroughTimeoutSeconds();
    final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
    final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource);
    if (!repo.isPassthrough()) {
        if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() > 0) {
            logger.debug("Using metadata timeout for: {}", resource);
            timeout = repo.getMetadataTimeoutSeconds();
        } else {
            if (info == null) {
                logger.debug("No special path info for: {}", resource);
            } else {
                logger.debug("{} is a special path, but not metadata.", resource);
            }
            timeout = repo.getCacheTimeoutSeconds();
        }
    }
    if (timeout > 0) {
        //            logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
        //                + timeout ) );
        cancel(new StoreKeyMatcher(key, CONTENT_JOB_TYPE), path);
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 4 with SpecialPathInfo

use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.

the class TransferManagerImpl method retrieve.

@Override
public Transfer retrieve(final ConcreteResource resource, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    // logger.info( "Attempting to resolve: {}", resource );
    // TODO: Handle the case where storage isn't allowed?
    // NOTE: This would expand the notion out from simply:
    // "don't allow storing new stuff"
    // to:
    // "don't ever cache this stuff"
    Transfer target = null;
    try {
        // TODO: (see above re:storing) Handle things like local archives that really don't need to be cached...
        target = getCacheReference(resource);
        if (target.exists()) {
            logger.debug("Using cached copy of: {}", target);
            return target;
        }
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
        if (!resource.allowsDownloading() || (specialPathInfo != null && !specialPathInfo.isRetrievable())) {
            logger.debug("Download not allowed for: {}. Returning null transfer.", resource);
            return null;
        }
        final Transfer retrieved = downloader.download(resource, target, getTimeoutSeconds(resource), getTransport(resource), suppressFailures, eventMetadata);
        if (retrieved != null && retrieved.exists() && !target.equals(retrieved)) {
            if (specialPathInfo == null || specialPathInfo.isCachable()) {
                cacheProvider.createAlias(retrieved.getResource(), target.getResource());
            }
        }
        if (target.exists()) {
            logger.debug("DOWNLOADED: {}", resource);
            return target;
        } else {
            logger.debug("NOT DOWNLOADED: {}", resource);
            return null;
        }
    } catch (final TransferException e) {
        fileEventManager.fire(new FileErrorEvent(target, e, eventMetadata));
        throw e;
    } catch (final IOException e) {
        final TransferException error = new TransferException("Failed to download: {}. Reason: {}", e, resource, e.getMessage());
        fileEventManager.fire(new FileErrorEvent(target, error, eventMetadata));
        throw error;
    }
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 5 with SpecialPathInfo

use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.

the class ChecksummingTransferDecorator method decorateWrite.

public OutputStream decorateWrite(final OutputStream stream, final Transfer transfer, final TransferOperation op, final EventMetadata eventMetadata) throws IOException {
    Object forceObj = eventMetadata.get(FORCE_CHECKSUM);
    boolean force = Boolean.TRUE.equals(forceObj) || Boolean.parseBoolean(String.valueOf(forceObj));
    SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, eventMetadata.getPackageType());
    logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null || specialPathInfo.isDecoratable()));
    if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
        ChecksummingDecoratorAdvisor.ChecksumAdvice advice = writerFilter.getDecorationAdvice(transfer, op, eventMetadata);
        if (force && advice == NO_DECORATE) {
            advice = CALCULATE_NO_WRITE;
        }
        boolean consumerNeedsIt = (consumer == null || consumer.needsMetadataFor(transfer));
        logger.trace("Advice is: {} for {} of: {} (and consumer is missing or needs it? {})", advice, op, transfer, consumerNeedsIt);
        // 2. if we have a metadata consumer AND the consumer needs metadata for this transfer
        if (advice != NO_DECORATE && (consumer == null || consumer.needsMetadataFor(transfer))) {
            logger.trace("Wrapping output stream to: {} for checksum generation.", transfer);
            return new ChecksummingOutputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
        }
    }
    logger.trace("NOT decorating write with ChecksummingTransferDecorator for: {}", transfer);
    return stream;
}
Also used : ChecksummingOutputStream(org.commonjava.maven.galley.io.checksum.ChecksummingOutputStream) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo)

Aggregations

SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)30 Transfer (org.commonjava.maven.galley.model.Transfer)10 IOException (java.io.IOException)7 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 TransferException (org.commonjava.maven.galley.TransferException)5 Logger (org.slf4j.Logger)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 IndyDataException (org.commonjava.indy.data.IndyDataException)4 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 StoreType (org.commonjava.indy.model.core.StoreType)4 List (java.util.List)3 Map (java.util.Map)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)3 OutputStream (java.io.OutputStream)2 HashSet (java.util.HashSet)2 PostConstruct (javax.annotation.PostConstruct)2