Search in sources :

Example 6 with TransferTimeoutException

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

the class ExistenceHandler method exists.

public boolean exists(final ConcreteResource resource, final Transfer transfer, final int timeoutSeconds, final Transport transport, final boolean suppressFailures) throws TransferException {
    if (nfc.isMissing(resource)) {
        logger.debug("NFC: Already marked as missing: {}", resource);
        return false;
    }
    if (transport == null) {
        logger.warn("No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
        return false;
    }
    logger.debug("EXISTS {}", resource);
    final ExistenceJob job = transport.createExistenceJob(resource, transfer, timeoutSeconds);
    // TODO: execute this stuff in a thread just like downloads/publishes. Requires cache storage...
    try {
        final Boolean result = job.call();
        if (job.getError() != null) {
            logger.debug("NFC: Download error. Marking as missing: {}", resource);
            nfc.addMissing(resource);
            if (!suppressFailures) {
                throw job.getError();
            }
        } else if (result == null) {
            logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
            nfc.addMissing(resource);
        } else if (!result) {
            logger.debug("NFC: Existence check returned false. Marking as missing: {}", resource);
            nfc.addMissing(resource);
        }
        return result;
    } catch (final TimeoutException e) {
        if (!suppressFailures) {
            throw new TransferTimeoutException(transfer, "Timed-out existence check: {}. Reason: {}", e, resource, e.getMessage());
        }
    } catch (final TransferException e) {
        if (!suppressFailures) {
            throw e;
        }
    } catch (final Exception e) {
        if (!suppressFailures) {
            throw new TransferException("Failed existence check: {}. Reason: {}", e, resource, e.getMessage());
        }
    }
    return false;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferException(org.commonjava.maven.galley.TransferException) ExistenceJob(org.commonjava.maven.galley.spi.transport.ExistenceJob) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) TransferException(org.commonjava.maven.galley.TransferException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with TransferTimeoutException

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

the class ListingHandler method list.

public ListingResult list(final ConcreteResource resource, final Transfer target, final int timeoutSeconds, final Transport transport, final boolean suppressFailures) throws TransferException {
    if (nfc.isMissing(resource)) {
        logger.debug("NFC: Already marked as missing: {}", resource);
        return null;
    }
    if (transport == null) {
        logger.warn("No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
        return null;
    }
    logger.debug("LIST {}", resource);
    final ListingJob job = transport.createListingJob(resource, target, timeoutSeconds);
    // TODO: execute this stuff in a thread just like downloads/publishes. Requires cache storage...
    try {
        final ListingResult result = job.call();
        if (job.getError() != null) {
            logger.debug("NFC: Download error. Marking as missing: {}", resource);
            nfc.addMissing(resource);
            if (!suppressFailures) {
                throw job.getError();
            }
        } else if (result == null) {
            logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
            nfc.addMissing(resource);
        }
        return result;
    } catch (final TimeoutException e) {
        if (!suppressFailures) {
            throw new TransferTimeoutException(target, "Timed-out download: {}. Reason: {}", e, resource, e.getMessage());
        }
    } catch (final TransferException e) {
        if (!suppressFailures) {
            throw e;
        }
    } catch (final Exception e) {
        if (!suppressFailures) {
            throw new TransferException("Failed listing: {}. Reason: {}", e, resource, e.getMessage());
        }
    }
    return null;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferException(org.commonjava.maven.galley.TransferException) ListingResult(org.commonjava.maven.galley.model.ListingResult) ListingJob(org.commonjava.maven.galley.spi.transport.ListingJob) TimeoutException(java.util.concurrent.TimeoutException) 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 8 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 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

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