Search in sources :

Example 6 with TransferLocationException

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

the class TransferManagerImpl method doBatch.

private <T extends TransferBatch> T doBatch(final Set<Resource> resources, final T batch, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    logger.info("Attempting to batch-retrieve {} resources:\n  {}", resources.size(), new JoinString("\n  ", resources));
    final Set<BatchRetriever> retrievers = new HashSet<BatchRetriever>(resources.size());
    for (final Resource resource : resources) {
        retrievers.add(new BatchRetriever(this, resource, suppressFailures, eventMetadata));
    }
    final Map<ConcreteResource, TransferException> errors = new HashMap<ConcreteResource, TransferException>();
    final Map<ConcreteResource, Transfer> transfers = new HashMap<ConcreteResource, Transfer>();
    do {
        for (final BatchRetriever retriever : retrievers) {
            batchExecutor.submit(retriever);
        }
        int count = retrievers.size();
        for (int i = 0; i < count; i++) {
            try {
                Future<BatchRetriever> pending = batchExecutor.take();
                BatchRetriever retriever = pending.get();
                final ConcreteResource resource = retriever.getLastTry();
                final TransferException error = retriever.getError();
                if (error != null) {
                    logger.warn("ERROR: {}...{}", error, resource, error.getMessage());
                    retrievers.remove(retriever);
                    if (!(error instanceof TransferLocationException)) {
                        errors.put(resource, error);
                    }
                    continue;
                }
                final Transfer transfer = retriever.getTransfer();
                if (transfer != null && transfer.exists()) {
                    transfers.put(resource, transfer);
                    retrievers.remove(retriever);
                    logger.debug("Completed: {}", resource);
                    continue;
                }
                if (!retriever.hasMoreTries()) {
                    logger.debug("Not completed, but out of tries: {}", resource);
                    retrievers.remove(retriever);
                }
            } catch (final InterruptedException e) {
                logger.error(String.format("Failed to wait for batch retrieval attempts to complete: %s", e.getMessage()), e);
                break;
            } catch (ExecutionException e) {
                logger.error(String.format("Failed to retrieve next completed retrieval: %s", e.getMessage()), e);
            }
        }
    } while (!retrievers.isEmpty());
    batch.setErrors(errors);
    batch.setTransfers(transfers);
    return batch;
}
Also used : HashMap(java.util.HashMap) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Resource(org.commonjava.maven.galley.model.Resource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) BatchRetriever(org.commonjava.maven.galley.internal.xfer.BatchRetriever) TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 7 with TransferLocationException

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

the class DownloadHandler method download.

// FIXME: download batch
public Transfer download(final ConcreteResource resource, final Transfer target, final int timeoutSeconds, final Transport transport, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    if (!resource.allowsDownloading()) {
        return null;
    }
    if (transport == null) {
        throw new TransferLocationException(resource.getLocation(), "No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
    }
    if (nfc.isMissing(resource)) {
        logger.debug("NFC: Already marked as missing: {}", resource);
        return null;
    }
    logger.debug("RETRIEVE {}", resource);
    final Transfer result = joinOrStart(resource, target, timeoutSeconds, transport, suppressFailures, eventMetadata);
    return result;
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) TransferLocationException(org.commonjava.maven.galley.TransferLocationException)

Example 8 with TransferLocationException

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

the class DefaultDownloadManager method list.

@Override
public List<StoreResource> list(final ArtifactStore store, final String path) throws IndyWorkflowException {
    final List<StoreResource> result = new ArrayList<>();
    if (store.getKey().getType() == StoreType.group) {
        try {
            final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(store), 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(), path, 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, store.getKey(), e.getMessage());
        }
    } else {
        final KeyedLocation loc = LocationUtils.toLocation(store);
        final StoreResource res = new StoreResource(loc, path);
        if (store instanceof RemoteRepository) {
            try {
                final ListingResult lr = transfers.list(res);
                if (lr != null && lr.getListing() != null) {
                    for (final String file : lr.getListing()) {
                        result.add(new StoreResource(loc, path, 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 path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
            }
        } else {
            try {
                final ListingResult listing = transfers.list(res);
                if (listing != null && listing.getListing() != null) {
                    for (final String child : listing.getListing()) {
                        result.add(new StoreResource(loc, path, child));
                    }
                }
            } catch (final TransferLocationException e) {
                Location location = res.getLocation();
                KeyedLocation kl = (KeyedLocation) location;
                logger.warn("Timeout  / bad gateway: " + e.getMessage(), e);
                fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
            } catch (final TransferException e) {
                logger.error(e.getMessage(), e);
                throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
            }
        }
    }
    return dedupeListing(result);
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) 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)

Aggregations

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