Search in sources :

Example 1 with FileErrorEvent

use of org.commonjava.maven.galley.event.FileErrorEvent 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 2 with FileErrorEvent

use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.

the class Transfer method openOutputStream.

public OutputStream openOutputStream(final TransferOperation accessType, final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForWriteUnlock(resource);
    try {
        provider.lockWrite(resource);
        OutputStream stream = provider.openOutputStream(resource);
        if (stream == null) {
            return null;
        }
        final TransferUnlocker unlocker = new TransferUnlocker(resource, provider);
        if (fireEvents) {
            logger.info("Wrapping output stream to: {} using event metadata: {}", this, eventMetadata);
            stream = new TransferOutputStream(stream, unlocker, new FileStorageEvent(accessType, this, eventMetadata), fileEventManager);
        } else {
            logger.info("Wrapping output stream to: {} WITHOUT event metadata", this);
            stream = new TransferOutputStream(stream, unlocker);
        }
        stream = decorator == null ? stream : decorator.decorateWrite(stream, this, accessType, eventMetadata);
        return stream;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : FileStorageEvent(org.commonjava.maven.galley.event.FileStorageEvent) OutputStream(java.io.OutputStream) TransferOutputStream(org.commonjava.maven.galley.util.TransferOutputStream) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) IOException(java.io.IOException) TransferOutputStream(org.commonjava.maven.galley.util.TransferOutputStream)

Example 3 with FileErrorEvent

use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.

the class Transfer method delete.

public boolean delete(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForWriteUnlock(resource);
    try {
        if (decorator != null) {
            decorator.decorateDelete(this, eventMetadata);
        }
        Logger contentLogger = LoggerFactory.getLogger(DELETE_CONTENT_LOG);
        if (contentLogger.isTraceEnabled()) {
            contentLogger.trace("Starting delete of: {} ({}) from:\n    ", resource, eventMetadata, join(Thread.currentThread().getStackTrace(), "\n    "));
        } else {
            contentLogger.info("Starting delete of: {} ({})", resource, eventMetadata);
        }
        final boolean deleted = provider.delete(resource);
        if (deleted) {
            contentLogger.info("Finished delete of: {}", resource);
            if (fireEvents) {
                fileEventManager.fire(new FileDeletionEvent(this, eventMetadata));
            }
        } else {
            contentLogger.info("Failed to delete: {}", resource);
        }
        return deleted;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) FileDeletionEvent(org.commonjava.maven.galley.event.FileDeletionEvent) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Example 4 with FileErrorEvent

use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.

the class Transfer method openInputStream.

public InputStream openInputStream(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForReadUnlock(resource);
    try {
        InputStream stream = provider.openInputStream(resource);
        if (stream == null) {
            return null;
        }
        if (fireEvents) {
            stream = new TransferInputStream(stream, new FileAccessEvent(this, eventMetadata), fileEventManager);
        }
        stream = decorator == null ? stream : decorator.decorateRead(stream, this, eventMetadata);
        logger.trace("Returning stream: {} for transfer: {}", stream.getClass().getName(), this);
        return stream;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : TransferInputStream(org.commonjava.maven.galley.util.TransferInputStream) InputStream(java.io.InputStream) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) IOException(java.io.IOException) FileAccessEvent(org.commonjava.maven.galley.event.FileAccessEvent) TransferInputStream(org.commonjava.maven.galley.util.TransferInputStream)

Aggregations

IOException (java.io.IOException)4 FileErrorEvent (org.commonjava.maven.galley.event.FileErrorEvent)4 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 TransferException (org.commonjava.maven.galley.TransferException)1 FileAccessEvent (org.commonjava.maven.galley.event.FileAccessEvent)1 FileDeletionEvent (org.commonjava.maven.galley.event.FileDeletionEvent)1 FileStorageEvent (org.commonjava.maven.galley.event.FileStorageEvent)1 SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 TransferInputStream (org.commonjava.maven.galley.util.TransferInputStream)1 TransferOutputStream (org.commonjava.maven.galley.util.TransferOutputStream)1 Logger (org.slf4j.Logger)1