in s3-artifact-storage-agent/src/main/java/jetbrains/buildServer/artifacts/s3/download/parallel/strategy/impl/AbstractParallelDownloadStrategy.java [32:85]
public void download(@NotNull String srcUrl,
@NotNull Path targetFile,
long fileSize,
@NotNull FileProgress downloadProgress,
@NotNull ParallelDownloadContext downloadContext) throws IOException {
if (fileSize <= 0) throw new IllegalArgumentException(String.format("File size is not positive (%s)", fileSize));
S3DownloadConfiguration configuration = downloadContext.getConfiguration();
FileSplitter fileSplitter = downloadContext.getFileSplitter();
List<FilePart> fileParts = fileSplitter.split(fileSize);
if (fileParts.size() == 1) {
LOGGER.warn(String.format("File %s of size %s should be downloaded in parallel, but was split into only 1 part %s. S3 artifact transport misconfigured?",
targetFile, fileSize, fileParts.get(0).getDescription()));
}
LOGGER.debug(String.format(
"Start downloading file %s of size %s from %s in %s parts of min %s MB each (except, possibly, the last) by max %s threads", // MB in logs because not less than 1 MB
targetFile, fileSize, srcUrl, fileParts.size(), configuration.getMinPartSizeBytes() / (1024 * 1024), Math.min(configuration.getMaxThreads(), fileParts.size())
));
ParallelDownloadState downloadState = new ParallelDownloadState(downloadProgress, downloadContext.getInterruptedFlag());
try {
try {
checkDownloadInterrupted(downloadState);
beforeDownloadingParts(targetFile, fileParts, fileSize, downloadState, downloadContext);
LOGGER.debug("Finished preparations before downloading parts of file " + targetFile);
} catch (Exception e) {
throw new IOException("Preparations before downloading parts failed", e);
}
try {
checkDownloadInterrupted(downloadState);
downloadParts(srcUrl, fileParts, targetFile, fileSize, downloadState, downloadContext);
LOGGER.debug("Finished downloading parts of file " + targetFile);
} catch (Exception e) {
throw new IOException("Failed to download file parts", e);
}
try {
checkDownloadInterrupted(downloadState);
afterDownloadingParts(targetFile, fileParts, fileSize, downloadState, downloadContext);
LOGGER.debug("Finished post-processing after downloading parts of file " + targetFile);
} catch (Exception e) {
throw new IOException("Post-processing after downloading parts failed", e);
}
} catch (IOException downloadException) {
try {
cleanupUnfinishedDownload(targetFile, fileParts, downloadState, downloadContext);
} catch (Exception cleanupException) {
LOGGER.warnAndDebugDetails(String.format("Failed to cleanup unfinished download of file %s: %s", targetFile, cleanupException.getMessage()), cleanupException);
}
throw downloadException;
}
}