From 335c9cbe5ef2c593b201420583ca528df9dda77a Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 14 Jun 2021 20:18:44 +0200 Subject: Move some methods from FileReferenceDownloader to FileDownloader --- .../vespa/filedistribution/FileDownloader.java | 24 ++++++++++++---------- .../filedistribution/FileReferenceDownloader.java | 8 -------- .../vespa/filedistribution/FileDownloaderTest.java | 8 ++++---- 3 files changed, 17 insertions(+), 23 deletions(-) (limited to 'filedistribution') diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java index 9d2ee96340d..1a964fa2d71 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java @@ -30,6 +30,7 @@ public class FileDownloader implements AutoCloseable { private final static Logger log = Logger.getLogger(FileDownloader.class.getName()); public static File defaultDownloadDirectory = new File(Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution")); + private final ConnectionPool connectionPool; private final File downloadDirectory; private final Duration timeout; private final FileReferenceDownloader fileReferenceDownloader; @@ -46,6 +47,7 @@ public class FileDownloader implements AutoCloseable { public FileDownloader(ConnectionPool connectionPool, File downloadDirectory, Downloads downloads, Duration timeout, Duration sleepBetweenRetries) { + this.connectionPool = connectionPool; this.downloadDirectory = downloadDirectory; this.timeout = timeout; // Needed to receive RPC calls receiveFile* from server after asking for files @@ -79,9 +81,9 @@ public class FileDownloader implements AutoCloseable { : download(fileReferenceDownload); } - public Map downloadStatus() { - return downloads.downloadStatus(); - } + public Map downloadStatus() { return downloads.downloadStatus(); } + + public ConnectionPool connectionPool() { return connectionPool; } File downloadDirectory() { return downloadDirectory; @@ -105,9 +107,13 @@ public class FileDownloader implements AutoCloseable { return Optional.empty(); } - private boolean alreadyDownloaded(FileReference fileReference) { + boolean isDownloading(FileReference fileReference) { + return downloads.get(fileReference).isPresent(); + } + + private boolean alreadyDownloaded(FileReferenceDownload fileReferenceDownload) { try { - return getFileFromFileSystem(fileReference).isPresent(); + return getFileFromFileSystem(fileReferenceDownload.fileReference()).isPresent(); } catch (RuntimeException e) { return false; } @@ -115,8 +121,7 @@ public class FileDownloader implements AutoCloseable { /** Start a download, don't wait for result */ public void downloadIfNeeded(FileReferenceDownload fileReferenceDownload) { - FileReference fileReference = fileReferenceDownload.fileReference(); - if (alreadyDownloaded(fileReference)) return; + if (alreadyDownloaded(fileReferenceDownload)) return; download(fileReferenceDownload); } @@ -126,11 +131,8 @@ public class FileDownloader implements AutoCloseable { return fileReferenceDownloader.download(fileReferenceDownload); } - public FileReferenceDownloader fileReferenceDownloader() { - return fileReferenceDownloader; - } - public void close() { fileReferenceDownloader.close(); } + } diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java index 3fcf2c56088..01240357fbe 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java @@ -118,10 +118,6 @@ public class FileReferenceDownloader { } } - boolean isDownloading(FileReference fileReference) { - return downloads.get(fileReference).isPresent(); - } - private boolean validateResponse(Request request) { if (request.isError()) { return false; @@ -134,10 +130,6 @@ public class FileReferenceDownloader { return true; } - public ConnectionPool connectionPool() { - return connectionPool; - } - public void close() { downloadExecutor.shutdown(); try { diff --git a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java index 1d11b358540..d7700467494 100644 --- a/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java +++ b/filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java @@ -175,7 +175,7 @@ public class FileDownloaderTest { // Getting file failed, verify download status and since there was an error is not downloading ATM assertDownloadStatus(fileReference, 0.0); - assertFalse(fileDownloader.fileReferenceDownloader().isDownloading(fileReference)); + assertFalse(fileDownloader.isDownloading(fileReference)); // Receives fileReference, should return and make it available to caller String filename = "abc.jar"; @@ -209,8 +209,8 @@ public class FileDownloaderTest { Future>> future1 = executor.submit(() -> fileDownloader.getFutureFile(fileReferenceDownload)); do { Thread.sleep(10); - } while (! fileDownloader.fileReferenceDownloader().isDownloading(fileReference)); - assertTrue(fileDownloader.fileReferenceDownloader().isDownloading(fileReference)); + } while (! fileDownloader.isDownloading(fileReference)); + assertTrue(fileDownloader.isDownloading(fileReference)); // Request file while download is in progress Future>> future2 = executor.submit(() -> fileDownloader.getFutureFile(fileReferenceDownload)); @@ -240,7 +240,7 @@ public class FileDownloaderTest { FileReference foo = new FileReference("foo"); // Should download since we do not have the file on disk fileDownloader.downloadIfNeeded(new FileReferenceDownload(foo)); - assertTrue(fileDownloader.fileReferenceDownloader().isDownloading(foo)); + assertTrue(fileDownloader.isDownloading(foo)); assertFalse(fileDownloader.getFile(foo).isPresent()); // Receive files to simulate download receiveFile(); -- cgit v1.2.3