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;
}
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);
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations