use of org.commonjava.maven.galley.model.ListingResult 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.maven.galley.model.ListingResult in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
@Measure
public List<StoreResource> list(final ArtifactStore store, final String path, final EventMetadata eventMetadata) 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)), eventMetadata);
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 TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} 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 {
if (!PathMaskChecker.checkListingMask(store, path)) {
// if list not permitted for the path, return empty list
return result;
}
final KeyedLocation loc = LocationUtils.toLocation(store);
final StoreResource res = new StoreResource(loc, path);
if (store instanceof RemoteRepository) {
try {
final ListingResult lr = transfers.list(res, eventMetadata);
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource(loc, path, file));
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} 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, eventMetadata);
if (listing != null && listing.getListing() != null) {
for (final String child : listing.getListing()) {
result.add(new StoreResource(loc, path, child));
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Timeout / bad gateway: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} 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.maven.galley.model.ListingResult 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.maven.galley.model.ListingResult in project galley by Commonjava.
the class TransferManagerImpl method doList.
private ListingResult doList(final ConcreteResource resource, final boolean suppressFailures, EventMetadata metadata) throws TransferException {
final Transfer cachedListing = getCacheReference(resource.getChild(".listing.txt"));
Set<String> filenames = new HashSet<>();
if (cachedListing.exists()) {
InputStream stream = null;
try {
stream = cachedListing.openInputStream();
filenames.addAll(IOUtils.readLines(stream, "UTF-8"));
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Got cached listing:\n\n{}\n\n", filenames);
} catch (final IOException e) {
throw new TransferException("Failed to read listing from cached file: %s. Reason: %s", e, cachedListing, e.getMessage());
} finally {
closeQuietly(stream);
}
} else {
final Transfer cached = getCacheReference(resource);
if (cached.exists()) {
if (cached.isFile()) {
throw new TransferException("Cannot list: {}. It does not appear to be a directory.", resource);
} else {
try {
// This is fairly stupid, but we need to append '/' to the end of directories in the listing so content processors can figure
// out what to do with them.
String[] fnames = cached.list();
if (fnames != null && fnames.length > 0) {
for (String fname : fnames) {
// this will avoid some package.json redirect path empty errors, especially for the group.
if (metadata.get(STORAGE_PATH) != null) {
filenames.add(fname);
continue;
}
final ConcreteResource child = resource.getChild(fname);
final Transfer childRef = getCacheReference(child);
if (childRef.isFile()) {
filenames.add(fname);
} else {
filenames.add(fname + "/");
}
}
}
} catch (final IOException e) {
throw new TransferException("Listing failed: {}. Reason: {}", e, resource, e.getMessage());
}
}
}
if (resource.getLocation().allowsDownloading()) {
final int timeoutSeconds = getTimeoutSeconds(resource);
Transport transport = getTransport(resource);
final ListingResult remoteResult = lister.list(resource, cachedListing, timeoutSeconds, transport, suppressFailures);
if (remoteResult != null) {
String[] remoteListing = remoteResult.getListing();
if (remoteListing != null && remoteListing.length > 0) {
final TransferDecorator decorator = cachedListing.getDecorator();
if (decorator != null) {
try {
Logger logger = LoggerFactory.getLogger(getClass());
// noinspection ConfusingArgumentToVarargsMethod
logger.debug("Un-decorated listing:\n\n{}\n\n", remoteListing);
remoteListing = decorator.decorateListing(cachedListing.getParent(), remoteListing, metadata);
} catch (final IOException e) {
logger.error("Failed to decorate directory listing for: {}. Reason: {}", e, resource, e.getMessage());
remoteListing = null;
}
}
}
if (remoteListing != null && remoteListing.length > 0) {
if (transport != null && transport.allowsCaching()) {
OutputStream stream = null;
try {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Writing listing:\n\n{}\n\nto: {}", remoteListing, cachedListing);
stream = cachedListing.openOutputStream(TransferOperation.DOWNLOAD);
stream.write(join(remoteListing, "\n").getBytes("UTF-8"));
} catch (final IOException e) {
logger.debug("Failed to store directory listing for: {}. Reason: {}", e, resource, e.getMessage());
} finally {
closeQuietly(stream);
}
}
filenames.addAll(Arrays.asList(remoteListing));
}
}
}
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Listing before non-listable file removal:\n\n{}\n\n", filenames);
List<String> resultingNames = new ArrayList<>(filenames.size());
for (String fname : filenames) {
ConcreteResource child = resource.getChild(fname);
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(child, metadata.getPackageType());
if (specialPathInfo != null && !specialPathInfo.isListable()) {
continue;
}
resultingNames.add(fname);
}
logger.debug("Final listing result:\n\n{}\n\n", resultingNames);
return new ListingResult(resource, resultingNames.toArray(new String[resultingNames.size()]));
}
use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.
the class ListingHandler method list.
public ListingResult list(final ConcreteResource resource, final Transfer target, final int timeoutSeconds, final Transport transport, final boolean suppressFailures) throws TransferException {
if (nfc.isMissing(resource)) {
logger.debug("NFC: Already marked as missing: {}", resource);
return null;
}
if (transport == null) {
logger.warn("No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
return null;
}
logger.debug("LIST {}", resource);
final ListingJob job = transport.createListingJob(resource, target, timeoutSeconds);
// TODO: execute this stuff in a thread just like downloads/publishes. Requires cache storage...
try {
final ListingResult result = job.call();
if (job.getError() != null) {
logger.debug("NFC: Download error. Marking as missing: {}", resource);
nfc.addMissing(resource);
if (!suppressFailures) {
throw job.getError();
}
} else if (result == null) {
logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
nfc.addMissing(resource);
}
return result;
} catch (final TimeoutException e) {
if (!suppressFailures) {
throw new TransferTimeoutException(target, "Timed-out download: {}. Reason: {}", e, resource, e.getMessage());
}
} catch (final TransferException e) {
if (!suppressFailures) {
throw e;
}
} catch (final Exception e) {
if (!suppressFailures) {
throw new TransferException("Failed listing: {}. Reason: {}", e, resource, e.getMessage());
}
}
return null;
}
Aggregations