Search in sources :

Example 1 with IndyStoreErrorEvent

use of org.commonjava.indy.change.event.IndyStoreErrorEvent 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 IndyStoreErrorEvent

use of org.commonjava.indy.change.event.IndyStoreErrorEvent 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)

Example 3 with IndyStoreErrorEvent

use of org.commonjava.indy.change.event.IndyStoreErrorEvent in project indy by Commonjava.

the class DefaultDownloadManager method fireIndyStoreErrorEvent.

private void fireIndyStoreErrorEvent(TransferLocationException e) {
    Location location = e.getLocation();
    KeyedLocation kl = (KeyedLocation) location;
    fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation)

Example 4 with IndyStoreErrorEvent

use of org.commonjava.indy.change.event.IndyStoreErrorEvent 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)

Aggregations

IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 TransferException (org.commonjava.maven.galley.TransferException)3 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)3 Location (org.commonjava.maven.galley.model.Location)3 ArrayList (java.util.ArrayList)2 StoreResource (org.commonjava.indy.content.StoreResource)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)2 ListingResult (org.commonjava.maven.galley.model.ListingResult)2 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)2 CacheOnlyLocation (org.commonjava.indy.model.galley.CacheOnlyLocation)1 TransferContentException (org.commonjava.maven.galley.TransferContentException)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Transfer (org.commonjava.maven.galley.model.Transfer)1