Search in sources :

Example 1 with TransferTimeoutException

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

the class DefaultDownloadManager method list.

@Override
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path) throws IndyWorkflowException {
    final String dir = PathUtils.dirname(path);
    final List<StoreResource> result = new ArrayList<>();
    try {
        final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), path)));
        for (final ListingResult lr : results) {
            if (lr != null && lr.getListing() != null) {
                for (final String file : lr.getListing()) {
                    result.add(new StoreResource((KeyedLocation) lr.getLocation(), dir, file));
                }
            }
        }
    } catch (final BadGatewayException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Bad gateway: " + e.getMessage(), e);
    } catch (final TransferTimeoutException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Timeout: " + e.getMessage(), e);
    } catch (final TransferLocationException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Location Error: " + e.getMessage(), e);
    } catch (final TransferException e) {
        logger.error(e.getMessage(), e);
        throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
    }
    return dedupeListing(result);
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) ListingResult(org.commonjava.maven.galley.model.ListingResult) StoreResource(org.commonjava.indy.content.StoreResource) TransferException(org.commonjava.maven.galley.TransferException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 2 with TransferTimeoutException

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

the class DefaultDownloadManager method store.

/*
     * (non-Javadoc)
     * @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
     * java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (store.getKey().getType() == StoreType.group) {
        //FIXME: Why is this null? Investigate.
        return null;
    }
    if (store.getKey().getType() != StoreType.hosted) {
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
    }
    if (storeManager.isReadonly(store)) {
        throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
    }
    if (store instanceof HostedRepository) {
        final HostedRepository deploy = (HostedRepository) store;
        //            final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
        final ContentQuality quality = getQuality(path);
        if (quality != null && quality == ContentQuality.SNAPSHOT) {
            if (!deploy.isAllowSnapshots()) {
                logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
                throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
            }
        } else if (!deploy.isAllowReleases()) {
            logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
            throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
        }
    }
    try {
        return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
    } catch (final BadGatewayException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Bad gateway: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferTimeoutException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Timeout: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferLocationException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Location Error: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (TransferException e) {
        logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
        throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
    }
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) TransferException(org.commonjava.maven.galley.TransferException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) HostedRepository(org.commonjava.indy.model.core.HostedRepository) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 3 with TransferTimeoutException

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

the class AbstractHttpJob method executeHttp.

protected boolean executeHttp() throws TransferException {
    try {
        client = http.createClient(location);
        response = client.execute(request, http.createContext(location));
        final StatusLine line = response.getStatusLine();
        final int sc = line.getStatusCode();
        logger.debug("{} {} : {}", request.getMethod(), line, url);
        if (!successStatuses.contains(sc)) {
            logger.debug("Detected failure response: " + sc);
            success = TransferResponseUtils.handleUnsuccessfulResponse(request, response, location, url);
            logger.debug("Returning non-error failure response for code: " + sc);
            return false;
        }
    } catch (final NoHttpResponseException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final ConnectTimeoutException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final SocketTimeoutException e) {
        throw new TransferTimeoutException(location, url, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final ClientProtocolException e) {
        throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (BadGatewayException e) {
        throw e;
    } catch (final GalleyException e) {
        throw new TransferException("Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } catch (final IOException e) {
        throw new TransferLocationException(location, "Repository remote request failed for: {}. Reason: {}", e, url, e.getMessage());
    } finally {
        /*
            * we need to integrate the writeMetadata() method into the executeHttp() call in a finally block,
            * and with a condition that it only runs on HEAD or GET. This would allow us to capture metadata on failed requests too,
            * which is critical for responding consistently to the user after a failed request is cached in the NFC.
            */
        String method = request.getMethod();
        if ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)) {
            Transfer target = getTransfer();
            ObjectMapper mapper = getMetadataObjectMapper();
            if (target != null && mapper != null) {
                writeMetadata(target, mapper);
            }
        }
    }
    return true;
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) IOException(java.io.IOException) GalleyException(org.commonjava.maven.galley.GalleyException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StatusLine(org.apache.http.StatusLine) TransferException(org.commonjava.maven.galley.TransferException) SocketTimeoutException(java.net.SocketTimeoutException) Transfer(org.commonjava.maven.galley.model.Transfer) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 4 with TransferTimeoutException

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

the class UploadHandler method joinOrStart.

private boolean joinOrStart(final ConcreteResource resource, final int timeoutSeconds, final InputStream stream, final long length, final String contentType, final Transport transport) throws TransferException {
    if (transport == null) {
        return false;
    }
    Future<PublishJob> future;
    synchronized (pending) {
        future = pending.get(resource);
        if (future == null) {
            final PublishJob job = transport.createPublishJob(resource, stream, length, timeoutSeconds);
            future = executor.submit(job);
            pending.put(resource, future);
        }
    }
    int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
    int tries = 1;
    try {
        while (tries > 0) {
            tries--;
            try {
                final PublishJob job = future.get(timeoutSeconds, TimeUnit.SECONDS);
                if (job.getError() != null) {
                    throw job.getError();
                }
                nfc.clearMissing(resource);
                return job.isSuccessful();
            } catch (final InterruptedException e) {
                throw new TransferException("Interrupted publish: {}. Reason: {}", e, resource, e.getMessage());
            } catch (final ExecutionException e) {
                throw new TransferException("Failed to publish: {}. Reason: {}", e, resource, e.getMessage());
            } catch (final TimeoutException e) {
                Long size = transferSizes.get(resource);
                if (tries > 0) {
                    continue;
                } else if (size != null && size > config.getThresholdWaitRetrySize()) {
                    logger.debug("Publishing a large file: {}. Retrying Future.get() up to {} times.", size, tries);
                    tries = (int) (size / config.getWaitRetryScalingIncrement());
                    continue;
                } else {
                    throw new TransferTimeoutException(resource, "Timed out waiting for execution of: {}", e, resource);
                }
            } catch (final TransferException e) {
                throw e;
            } catch (final Exception e) {
                throw new TransferException("Failed listing: {}. Reason: {}", e, resource, e.getMessage());
            }
        }
    } finally {
        transferSizes.remove(resource);
        //            logger.info( "Marking download complete: {}", url );
        pending.remove(resource);
    }
    return false;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferException(org.commonjava.maven.galley.TransferException) ExecutionException(java.util.concurrent.ExecutionException) PublishJob(org.commonjava.maven.galley.spi.transport.PublishJob) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) TransferException(org.commonjava.maven.galley.TransferException) TimeoutException(java.util.concurrent.TimeoutException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException)

Example 5 with TransferTimeoutException

use of org.commonjava.maven.galley.TransferTimeoutException 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 {
    // if the target file already exists, skip joining.
    if (target.exists()) {
        return target;
    }
    Future<DownloadJob> future;
    synchronized (pending) {
        future = pending.get(target);
        if (future == null) {
            if (transport == null) {
                return null;
            }
            final DownloadJob job = transport.createDownloadJob(resource, target, transferSizes, timeoutSeconds, eventMetadata);
            future = executor.submit(job);
            pending.put(target, future);
        }
    }
    int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
    int tries = 1;
    try {
        while (tries > 0) {
            tries--;
            try {
                final DownloadJob job = future.get(waitSeconds, TimeUnit.SECONDS);
                synchronized (pending) {
                    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());
                    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) {
                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) TransferException(org.commonjava.maven.galley.TransferException) Transfer(org.commonjava.maven.galley.model.Transfer) ExecutionException(java.util.concurrent.ExecutionException) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) TransferException(org.commonjava.maven.galley.TransferException) TimeoutException(java.util.concurrent.TimeoutException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException)

Aggregations

TransferException (org.commonjava.maven.galley.TransferException)8 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)8 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)7 TimeoutException (java.util.concurrent.TimeoutException)4 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)3 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 ListingResult (org.commonjava.maven.galley.model.ListingResult)3 Location (org.commonjava.maven.galley.model.Location)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 StoreResource (org.commonjava.indy.content.StoreResource)2 Transfer (org.commonjava.maven.galley.model.Transfer)2 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1 StatusLine (org.apache.http.StatusLine)1