use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class ArtifactMetadataManagerImpl method store.
/* (non-Javadoc)
* @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, java.lang.String, java.lang.String, java.io.InputStream)
*/
@Override
public Transfer store(final Location location, final String groupId, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(groupId, filename));
final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
if (selected == null) {
logger.warn("Cannot deploy. No valid deploy points in group.");
throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
}
return transferManager.store(selected, stream, eventMetadata);
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class ArtifactMetadataManagerImpl method store.
/* (non-Javadoc)
* @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, org.commonjava.maven.atlas.ident.ref.ProjectRef, java.lang.String, java.io.InputStream)
*/
@Override
public Transfer store(final Location location, final ProjectRef ref, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(ref, filename));
final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
if (selected == null) {
logger.warn("Cannot deploy. No valid deploy points in group.");
throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
}
return transferManager.store(selected, stream, eventMetadata);
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class DownloadHandler method joinOrStart.
private Transfer joinOrStart(final ConcreteResource resource, final Transfer target, final int timeoutSeconds, final Transport transport, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
// if the target file already exists, skip joining.
if (target.exists()) {
return target;
}
Future<DownloadJob> future;
synchronized (pending) {
future = pending.get(target);
if (future == null) {
if (transport == null) {
return null;
}
final DownloadJob job = transport.createDownloadJob(resource, target, transferSizes, timeoutSeconds, eventMetadata);
future = executor.submit(job);
pending.put(target, future);
}
}
int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
int tries = 1;
try {
while (tries > 0) {
tries--;
try {
final DownloadJob job = future.get(waitSeconds, TimeUnit.SECONDS);
synchronized (pending) {
pending.remove(target);
}
final Transfer downloaded = job.getTransfer();
if (job.getError() != null) {
logger.debug("NFC: Download error. Marking as missing: {}\nError was: {}", job.getError(), resource, job.getError().getMessage());
nfc.addMissing(resource);
if (!suppressFailures) {
throw job.getError();
}
} else if (downloaded == null || !downloaded.exists()) {
logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
nfc.addMissing(resource);
}
return downloaded;
} catch (final InterruptedException e) {
if (!suppressFailures) {
throw new TransferException("Download interrupted: {}", e, target);
}
} catch (final ExecutionException e) {
if (!suppressFailures) {
throw new TransferException("Download failed: {}", e, target);
}
} catch (final TimeoutException e) {
Long size = transferSizes.get(target);
if (tries > 0) {
continue;
} else if (size != null && size > config.getThresholdWaitRetrySize()) {
logger.debug("Downloading a large file: {}. Retrying Future.get() up to {} times.", size, tries);
tries = (int) (size / config.getWaitRetryScalingIncrement());
continue;
} else if (!suppressFailures) {
throw new TransferTimeoutException(target, "Timed out waiting for execution of: {}", e, target);
}
} catch (final TransferException e) {
if (!suppressFailures) {
throw e;
}
} catch (final Exception e) {
if (!suppressFailures) {
throw new TransferException("Download failed: {}. Reason: {}", e, resource, e.getMessage());
}
}
}
} finally {
transferSizes.remove(target);
}
return null;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class ExistenceHandler method exists.
public boolean exists(final ConcreteResource resource, final Transfer transfer, final int timeoutSeconds, final Transport transport, final boolean suppressFailures) throws TransferException {
if (nfc.isMissing(resource)) {
logger.debug("NFC: Already marked as missing: {}", resource);
return false;
}
if (transport == null) {
logger.warn("No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
return false;
}
logger.debug("EXISTS {}", resource);
final ExistenceJob job = transport.createExistenceJob(resource, transfer, timeoutSeconds);
// TODO: execute this stuff in a thread just like downloads/publishes. Requires cache storage...
try {
final Boolean 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);
} else if (!result) {
logger.debug("NFC: Existence check returned false. Marking as missing: {}", resource);
nfc.addMissing(resource);
}
return result;
} catch (final TimeoutException e) {
if (!suppressFailures) {
throw new TransferTimeoutException(transfer, "Timed-out existence check: {}. Reason: {}", e, resource, e.getMessage());
}
} catch (final TransferException e) {
if (!suppressFailures) {
throw e;
}
} catch (final Exception e) {
if (!suppressFailures) {
throw new TransferException("Failed existence check: {}. Reason: {}", e, resource, e.getMessage());
}
}
return false;
}
use of org.commonjava.maven.galley.TransferException 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