Search in sources :

Example 16 with StoreResource

use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.

the class DefaultDirectContentAccess method listRaw.

@Override
public Map<String, List<StoreResource>> listRaw(ArtifactStore store, List<String> parentPathList) throws IndyWorkflowException {
    CompletionService<List<StoreResource>> executor = new ExecutorCompletionService<>(executorService);
    Map<String, Future<List<StoreResource>>> futures = new HashMap<>();
    Logger logger = LoggerFactory.getLogger(getClass());
    for (final String path : parentPathList) {
        logger.debug("Requesting listing of {} in {}", path, store);
        Future<List<StoreResource>> future = executor.submit(() -> {
            logger.trace("Starting listing of {} in {}", path, store);
            List<StoreResource> listRaw = listRaw(store, path);
            logger.trace("Listing of {} in {} finished", path, store);
            return listRaw;
        });
        futures.put(path, future);
    }
    final Map<String, List<StoreResource>> result = new HashMap<>();
    for (String path : parentPathList) {
        try {
            logger.trace("Waiting for listing of {} in {}", path, store);
            Future<List<StoreResource>> future = futures.get(path);
            List<StoreResource> listing = future.get();
            logger.debug("Listing of {} in {} received", path, store);
            if (listing != null) {
                result.put(path, listing);
            }
        } catch (InterruptedException ex) {
            throw new IndyWorkflowException("Listing retrieval of %s in %s was interrupted", ex, path, store);
        } catch (ExecutionException ex) {
            throw new IndyWorkflowException("There was an error in listing retrieval of %s in %s: %s", ex, path, store, ex);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Logger(org.slf4j.Logger) StoreResource(org.commonjava.indy.content.StoreResource) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with StoreResource

use of org.commonjava.indy.content.StoreResource 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 18 with StoreResource

use of org.commonjava.indy.content.StoreResource 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 19 with StoreResource

use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.

the class MavenMetadataGeneratorTest method generateDirContent_SnapshotMetadataWith2Versions.

@Test
public void generateDirContent_SnapshotMetadataWith2Versions() throws Exception {
    final StoreResource resource = setupSnapshotDirWith2Snapshots();
    final EventMetadata emd = new EventMetadata();
    final List<StoreResource> result = generator.generateDirectoryContent(stores.getArtifactStore(resource.getStoreKey()), resource.getPath(), Collections.<StoreResource>emptyList(), emd);
    System.out.println(StringUtils.join(result, "\n"));
    assertThat(result.size(), equalTo(3));
    for (final StoreResource res : result) {
        if (!(res.getPath().endsWith(MavenMetadataMerger.METADATA_MD5_NAME) || res.getPath().endsWith(MavenMetadataMerger.METADATA_NAME) || res.getPath().endsWith(MavenMetadataMerger.METADATA_SHA_NAME))) {
            fail("Invalid generated content: " + res);
        }
    }
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 20 with StoreResource

use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.

the class MavenMetadataGeneratorTest method generateDirContent_VersionsMetadataWith2Versions.

@Test
public void generateDirContent_VersionsMetadataWith2Versions() throws Exception {
    final StoreResource resource = setupVersionsStructureWith2Versions();
    final List<StoreResource> result = generator.generateDirectoryContent(stores.getArtifactStore(resource.getStoreKey()), resource.getPath(), Collections.<StoreResource>emptyList(), new EventMetadata());
    System.out.println(StringUtils.join(result, "\n"));
    assertThat(result.size(), equalTo(3));
    for (final StoreResource res : result) {
        if (!(res.getPath().endsWith(MavenMetadataMerger.METADATA_MD5_NAME) || res.getPath().endsWith(MavenMetadataMerger.METADATA_NAME) || res.getPath().endsWith(MavenMetadataMerger.METADATA_SHA_NAME))) {
            fail("Invalid generated content: " + res);
        }
    }
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

StoreResource (org.commonjava.indy.content.StoreResource)24 ArrayList (java.util.ArrayList)16 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)13 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)10 HashMap (java.util.HashMap)9 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)8 List (java.util.List)7 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)7 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)7 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 Set (java.util.Set)6 HashSet (java.util.HashSet)5 TransferException (org.commonjava.maven.galley.TransferException)5 ArtifactPathInfo (org.commonjava.atlas.maven.ident.util.ArtifactPathInfo)4 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)4 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3