Search in sources :

Example 11 with KeyedLocation

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

the class MavenMetadataGeneratorTest method setupSnapshotDirWith2Snapshots.

private StoreResource setupSnapshotDirWith2Snapshots() throws Exception {
    final RemoteRepository store = new RemoteRepository(MAVEN_PKG_KEY, "testrepo", "http://foo.bar");
    stores.storeArtifactStore(store, summary, false, true, new EventMetadata());
    final String path = "org/group/artifact/1.0-SNAPSHOT";
    final KeyedLocation location = LocationUtils.toLocation(store);
    final StoreResource resource = new StoreResource(location, path);
    final TestListing listing = new TestListing(new ListingResult(resource, new String[] { "artifact-1.0-20140828.221400-1.pom", "artifact-1.0-20140828.221400-1.jar", "artifact-1.0-20140828.225800-1.pom", "artifact-1.0-20140828.225800-1.jar" }));
    fixture.getTransport().registerListing(resource, listing);
    return resource;
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) TestListing(org.commonjava.maven.galley.testing.core.transport.job.TestListing) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ListingResult(org.commonjava.maven.galley.model.ListingResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 12 with KeyedLocation

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

the class ImpliedRepositoryDetector method initJob.

private boolean initJob(final ImplicationsJob job) {
    switch(job.event.getType()) {
        case DOWNLOAD:
        case UPLOAD:
            break;
        default:
            // we're not interested in these.
            return false;
    }
    final Transfer transfer = job.transfer;
    if (!transfer.getPath().endsWith(".pom")) {
        return false;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        return false;
    }
    final StoreKey key = ((KeyedLocation) location).getKey();
    try {
        job.store = storeManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Cannot retrieve artifact store for: %s. Failed to process implied repositories.", key), e);
    }
    if (job.store == null) {
        return false;
    }
    job.pathInfo = ArtifactPathInfo.parse(transfer.getPath());
    if (job.pathInfo == null) {
        return false;
    }
    try {
        logger.debug("Parsing: {}", transfer);
        job.pomView = pomReader.readLocalPom(job.pathInfo.getProjectId(), transfer, MavenPomView.ALL_PROFILES);
    } catch (final GalleyMavenException e) {
        logger.error(String.format("Cannot parse: %s from: %s. Failed to process implied repositories.", job.pathInfo.getProjectId(), transfer), e);
    }
    return job.pomView != null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 13 with KeyedLocation

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

the class IndyLocationExpander method expand.

/**
     * For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are 
     * specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
     * {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
     */
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
    final List<Location> result = new ArrayList<Location>();
    for (final Location location : locations) {
        if (location instanceof GroupLocation) {
            final GroupLocation gl = (GroupLocation) location;
            try {
                logger.debug("Expanding group: {}", gl.getKey());
                final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
                if (members != null) {
                    for (final ArtifactStore member : members) {
                        if (!result.contains(member)) {
                            logger.debug("expansion += {}", member.getKey());
                            result.add(LocationUtils.toLocation(member));
                        }
                    }
                    logger.debug("Expanded group: {} to:\n  {}", gl.getKey(), new JoinString("\n  ", result));
                }
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
            }
        } else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
            final StoreKey key = ((KeyedLocation) location).getKey();
            try {
                final ArtifactStore store = data.getArtifactStore(key);
                if (store == null) {
                    throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
                }
                logger.debug("Adding single store: {} for location: {}", store, location);
                result.add(LocationUtils.toLocation(store));
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
            }
        } else {
            logger.debug("No expansion available for location: {}", location);
            result.add(location);
        }
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TransferException(org.commonjava.maven.galley.TransferException) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Example 14 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation 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 15 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation 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

KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)11 Location (org.commonjava.maven.galley.model.Location)10 ArrayList (java.util.ArrayList)7 IndyDataException (org.commonjava.indy.data.IndyDataException)7 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)6 Transfer (org.commonjava.maven.galley.model.Transfer)6 StoreResource (org.commonjava.indy.content.StoreResource)5 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 TransferException (org.commonjava.maven.galley.TransferException)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 ListingResult (org.commonjava.maven.galley.model.ListingResult)4 Set (java.util.Set)3 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)3 File (java.io.File)2 HashSet (java.util.HashSet)2 Inject (javax.inject.Inject)2 ContentGenerator (org.commonjava.indy.content.ContentGenerator)2