Search in sources :

Example 51 with Location

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

the class ExpiringMemoryNotFoundCache method addMissing.

@Override
public void addMissing(final ConcreteResource resource) {
    long timeout = Long.MAX_VALUE;
    if (config.getNotFoundCacheTimeoutSeconds() > 0) {
        timeout = System.currentTimeMillis() + config.getNotFoundCacheTimeoutSeconds() * 1000;
    }
    final Location loc = resource.getLocation();
    final Integer to = loc.getAttribute(RepositoryLocation.ATTR_NFC_TIMEOUT_SECONDS, Integer.class);
    if (to != null && to > 0) {
        timeout = System.currentTimeMillis() + (to * 1000);
    }
    final long tstamp = timeout;
    logger.info("[NFC] '{}' will not be checked again until: {}", new Object() {

        @Override
        public String toString() {
            return normalize(resource.getLocationUri(), resource.getPath());
        }
    }, new Object() {

        @Override
        public String toString() {
            return new SimpleDateFormat(TIMEOUT_FORMAT).format(new Date(tstamp));
        }
    });
    missingWithTimeout.put(resource, timeout);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) Location(org.commonjava.maven.galley.model.Location)

Example 52 with Location

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

the class ExpiringMemoryNotFoundCache method getAllMissing.

@Override
public Map<Location, Set<String>> getAllMissing() {
    clearAllExpiredMissing();
    final Map<Location, Set<String>> result = new HashMap<Location, Set<String>>();
    for (final ConcreteResource resource : missingWithTimeout.keySet()) {
        final Location loc = resource.getLocation();
        Set<String> paths = result.get(loc);
        if (paths == null) {
            paths = new HashSet<String>();
            result.put(loc, paths);
        }
        paths.add(resource.getPath());
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) Location(org.commonjava.maven.galley.model.Location)

Example 53 with Location

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

the class ExpiringMemoryNotFoundCache method getMissing.

@Override
public Set<String> getMissing(final Location location) {
    clearAllExpiredMissing();
    final Set<String> paths = new HashSet<String>();
    for (final ConcreteResource resource : missingWithTimeout.keySet()) {
        final Location loc = resource.getLocation();
        if (loc.equals(location)) {
            paths.add(resource.getPath());
        }
    }
    return paths;
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HashSet(java.util.HashSet) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) Location(org.commonjava.maven.galley.model.Location)

Example 54 with Location

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

the class NfcController method getAllMissing.

public NotFoundCacheDTO getAllMissing() {
    final NotFoundCacheDTO dto = new NotFoundCacheDTO();
    final Map<Location, Set<String>> allMissing = cache.getAllMissing();
    for (final Location loc : allMissing.keySet()) {
        if (loc instanceof KeyedLocation) {
            final List<String> paths = new ArrayList<String>(allMissing.get(loc));
            Collections.sort(paths);
            dto.addSection(((KeyedLocation) loc).getKey(), paths);
        }
    }
    return dto;
}
Also used : Set(java.util.Set) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LocationUtils.toLocation(org.commonjava.indy.util.LocationUtils.toLocation) Location(org.commonjava.maven.galley.model.Location)

Example 55 with Location

use of org.commonjava.maven.galley.model.Location 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

Location (org.commonjava.maven.galley.model.Location)58 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)28 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)26 Test (org.junit.Test)25 Transfer (org.commonjava.maven.galley.model.Transfer)14 ArrayList (java.util.ArrayList)13 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)11 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)11 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 OutputStream (java.io.OutputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 URI (java.net.URI)6 RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)6 TransferException (org.commonjava.maven.galley.TransferException)6 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)6 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)5