Search in sources :

Example 1 with TransferContentException

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

the class DefaultDownloadManager method retrieve.

private Transfer retrieve(final ArtifactStore store, final String path, final boolean suppressFailures, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (store.getKey().getType() == StoreType.group) {
        return null;
    }
    if (!PathMaskChecker.checkMask(store, path)) {
        return null;
    }
    final ConcreteResource res = new ConcreteResource(LocationUtils.toLocation(store), path);
    if (store.getType() != hosted && nfc.isMissing(res)) {
        return null;
    }
    Transfer target;
    try {
        if (store instanceof RemoteRepository) {
            target = transfers.retrieve(res, suppressFailures, eventMetadata);
        } else {
            target = transfers.getCacheReference(res);
            if (target == null || !target.exists()) {
                target = null;
            }
        }
    } catch (final TransferLocationException e) {
        fileEventManager.fire(new IndyStoreErrorEvent(store.getKey(), e));
        logger.warn("Timeout / bad gateway: " + res + ". Reason: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to retrieve path: {} from: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferContentException e) {
        logger.warn("Content-Length mismatch: " + res + ". Reason: " + e.getMessage() + "\nNOTE: This may be a network error; will retry download on next request.", e);
        throw new IndyWorkflowException("Failed to retrieve path: {} from: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferException e) {
        logger.error(e.getMessage(), e);
        throw new IndyWorkflowException("Failed to retrieve path: {} from: {}. Reason: {}", e, path, store, e.getMessage());
    }
    return target;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) TransferContentException(org.commonjava.maven.galley.TransferContentException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent)

Example 2 with TransferContentException

use of org.commonjava.maven.galley.TransferContentException in project galley by Commonjava.

the class DownloadHandler method joinOrStart.

private Transfer joinOrStart(final ConcreteResource resource, final Transfer target, final int timeoutSeconds, final Transport transport, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    Future<DownloadJob> future;
    boolean created = false;
    synchronized (DOWNLOAD_MUTEX) {
        // if the target file already exists, skip joining.
        if (target.exists()) {
            return target;
        }
        future = pending.get(target);
        if (future == null) {
            if (transport == null) {
                return null;
            }
            final DownloadJob job = transport.createDownloadJob(resource, target, transferSizes, timeoutSeconds, eventMetadata);
            created = true;
            future = executor.submit(job);
            logger.debug("Created download job for path {}: {}", resource, future);
            pending.put(target, future);
        }
    }
    int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
    int tries = 1;
    try {
        while (tries > 0) {
            tries--;
            try {
                logger.debug("Waiting for download job of path: {}: {}", resource, future);
                final DownloadJob job = future.get(waitSeconds, TimeUnit.SECONDS);
                if (created) {
                    synchronized (DOWNLOAD_MUTEX) {
                        logger.debug("Removing download job of path: {}: {}", resource, future);
                        pending.remove(target);
                    }
                }
                final Transfer downloaded = job.getTransfer();
                if (job.getError() != null) {
                    logger.debug("NFC: Download error. Marking as missing: {}\nError was: {}", job.getError(), resource, job.getError().getMessage());
                    if (!(job.getError() instanceof TransferContentException)) {
                        nfc.addMissing(resource);
                    }
                    if (!suppressFailures) {
                        throw job.getError();
                    }
                } else if (downloaded == null || !downloaded.exists()) {
                    logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
                    nfc.addMissing(resource);
                }
                return downloaded;
            } catch (final InterruptedException e) {
                if (!suppressFailures) {
                    throw new TransferException("Download interrupted: {}", e, target);
                }
            } catch (final ExecutionException e) {
                if (!suppressFailures) {
                    throw new TransferException("Download failed: {}", e, target);
                }
            } catch (final TimeoutException e) {
                Long size = transferSizes.get(target);
                if (tries > 0) {
                    continue;
                } else if (size != null && size > config.getThresholdWaitRetrySize()) {
                    logger.debug("Downloading a large file: {}. Retrying Future.get() up to {} times.", size, tries);
                    tries = (int) (size / config.getWaitRetryScalingIncrement());
                    continue;
                } else if (!suppressFailures) {
                    throw new TransferTimeoutException(target, "Timed out waiting for execution of: {}", e, target);
                }
            } catch (final TransferException e) {
                // noinspection ConstantConditions
                if (!suppressFailures) {
                    throw e;
                }
            } catch (final Exception e) {
                if (!suppressFailures) {
                    throw new TransferException("Download failed: {}. Reason: {}", e, resource, e.getMessage());
                }
            }
        }
    } finally {
        transferSizes.remove(target);
    }
    return null;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferContentException(org.commonjava.maven.galley.TransferContentException) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) TimeoutException(java.util.concurrent.TimeoutException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferContentException(org.commonjava.maven.galley.TransferContentException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ExecutionException(java.util.concurrent.ExecutionException) TransferException(org.commonjava.maven.galley.TransferException) TransferException(org.commonjava.maven.galley.TransferException) Transfer(org.commonjava.maven.galley.model.Transfer) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException)

Example 3 with TransferContentException

use of org.commonjava.maven.galley.TransferContentException in project galley by Commonjava.

the class HttpDownload method writeTarget.

private void writeTarget() throws TransferException {
    OutputStream out = null;
    if (response != null) {
        InputStream in = null;
        try {
            final HttpEntity entity = response.getEntity();
            in = entity.getContent();
            out = target.openOutputStream(TransferOperation.DOWNLOAD, true, eventMetadata, deleteFilesOnPath);
            doCopy(in, out);
            logger.info("Ensuring all HTTP data is consumed...");
        } catch (final IOException eOrig) {
            closeAllQuietly(in, out);
            ConcreteResource resource = target.getResource();
            try {
                logger.debug("Failed to write to local proxy store:{}. Deleting partial target file:{}", eOrig, target.getPath());
                target.delete();
            } catch (IOException eDel) {
                logger.error(String.format("Failed to delete target file: %s\nOriginal URL: %s. Reason: %s", target, url, eDel.getMessage()), eDel);
            }
            logger.error(String.format("Failed to write to local proxy store: %s\nOriginal URL: %s. Reason: %s", target, url, eOrig.getMessage()), eOrig);
            throw new TransferContentException(resource, "Failed to write to local proxy store: %s\nOriginal URL: %s. Reason: %s", eOrig, target, url, eOrig.getMessage());
        } finally {
            closeAllQuietly(in, out);
        }
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStream(java.io.InputStream) TransferContentException(org.commonjava.maven.galley.TransferContentException) OutputStream(java.io.OutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) IOException(java.io.IOException)

Aggregations

TransferContentException (org.commonjava.maven.galley.TransferContentException)3 TransferException (org.commonjava.maven.galley.TransferException)2 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)2 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)2 Transfer (org.commonjava.maven.galley.model.Transfer)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 HttpEntity (org.apache.http.HttpEntity)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)1 DownloadJob (org.commonjava.maven.galley.spi.transport.DownloadJob)1