use of org.commonjava.indy.IndyWorkflowException 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.IndyWorkflowException in project indy by Commonjava.
the class DefaultDownloadManager method recurseListing.
private void recurseListing(final Transfer transfer, final List<Transfer> result) throws IndyWorkflowException {
if (transfer.isDirectory()) {
try {
final String[] children = transfer.list();
for (final String child : children) {
final Transfer childTransfer = transfer.getChild(child);
recurseListing(childTransfer, result);
}
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to list children of: %s. Reason: %s", e, transfer, e.getMessage());
}
} else if (transfer.exists()) {
result.add(transfer);
}
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultContentDigester method digest.
public TransferMetadata digest(final StoreKey key, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final Transfer transfer = directContentAccess.getTransfer(key, path);
if (transfer == null || !transfer.exists()) {
return new TransferMetadata(Collections.emptyMap(), 0L);
}
TransferMetadata meta = getContentMetadata(transfer);
if (meta != null) {
return meta;
}
String cacheKey = generateCacheKey(transfer);
logger.debug("TransferMetadata missing for: {}. Re-reading with FORCE_CHECKSUM now to calculate it.", cacheKey);
// FIXME: This IS NOT WORKING! It results in NPE for callers assuming a non-null TransferMetadata response.
EventMetadata forcedEventMetadata = new EventMetadata(eventMetadata).set(FORCE_CHECKSUM, Boolean.TRUE);
try (InputStream stream = transfer.openInputStream(false, forcedEventMetadata)) {
// depend on ChecksummingTransferDecorator to calculate / store metadata as this gets read, using
// the FORCE_CHECKSUM metadata key to control its generation.
IOUtils.toByteArray(stream);
} catch (IOException e) {
throw new IndyWorkflowException("Failed to calculate checksums (MD5, SHA-256, etc.) for: %s. Reason: %s", e, transfer, e.getMessage());
}
logger.debug("Retrying TransferMetadata retrieval from cache for: {} after recalculating", cacheKey);
return getContentMetadata(transfer);
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultContentManager method retrieveAll.
@Override
public List<Transfer> retrieveAll(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final List<Transfer> txfrs = new ArrayList<>();
for (final ArtifactStore store : stores) {
if (group == store.getKey().getType()) {
List<ArtifactStore> members;
try {
members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
final List<Transfer> storeTransfers = new ArrayList<>();
for (final ContentGenerator generator : contentGenerators) {
final Transfer txfr = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
if (txfr != null) {
storeTransfers.add(txfr);
}
}
// ...if it's generated, it's merged in this case.
if (storeTransfers.isEmpty()) {
for (final ArtifactStore member : members) {
// NOTE: This is only safe to call because we're concrete ordered stores, so anything passing through here is concrete.
final Transfer txfr = doRetrieve(member, path, eventMetadata);
if (txfr != null) {
storeTransfers.add(txfr);
}
}
}
txfrs.addAll(storeTransfers);
} else {
// NOTE: This is only safe to call because we're doing the group check up front, so anything passing through here is concrete.
final Transfer txfr = doRetrieve(store, path, eventMetadata);
if (txfr != null) {
txfrs.add(txfr);
}
}
}
return txfrs;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultContentManager method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
logger.debug("Getting transfer for: {}/{} (op: {})", store.getKey(), path, op);
if (group == store.getKey().getType()) {
KeyedLocation location = LocationUtils.toLocation(store);
SpecialPathInfo spInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
if (spInfo == null || !spInfo.isMergable()) {
try {
final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
logger.debug("Trying to retrieve suitable transfer for: {} in group: {} members:\n{}", path, store.getName(), allMembers);
return getTransfer(allMembers, path, op);
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
} else {
logger.debug("Detected mergable special path: {}/{}.", store.getKey(), path);
}
}
logger.debug("Retrieving storage reference (Transfer) directly for: {}/{}", store.getKey(), path);
return downloadManager.getStorageReference(store, path, op);
}
Aggregations