aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java6
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java24
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReferenceDownloader.java8
-rw-r--r--filedistribution/src/test/java/com/yahoo/vespa/filedistribution/FileDownloaderTest.java8
4 files changed, 20 insertions, 26 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java
index 17faa3f093d..2b595992cdb 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java
@@ -86,7 +86,7 @@ public class FileServerTest {
.configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath())
.configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath());
FileServer fileServer = createFileServer(builder);
- assertEquals(0, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize());
+ assertEquals(0, fileServer.downloader().connectionPool().getSize());
// Empty connection pool when only one server, no use in downloading from yourself
List<ConfigserverConfig.Zookeeperserver.Builder> servers = new ArrayList<>();
@@ -96,7 +96,7 @@ public class FileServerTest {
servers.add(serverBuilder);
builder.zookeeperserver(servers);
fileServer = createFileServer(builder);
- assertEquals(0, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize());
+ assertEquals(0, fileServer.downloader().connectionPool().getSize());
// connection pool of size 1 when 2 servers
ConfigserverConfig.Zookeeperserver.Builder serverBuilder2 = new ConfigserverConfig.Zookeeperserver.Builder();
@@ -105,7 +105,7 @@ public class FileServerTest {
servers.add(serverBuilder2);
builder.zookeeperserver(servers);
fileServer = createFileServer(builder);
- assertEquals(1, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize());
+ assertEquals(1, fileServer.downloader().connectionPool().getSize());
}
private void writeFile(String dir) throws IOException {
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<FileReference, Double> downloadStatus() {
- return downloads.downloadStatus();
- }
+ public Map<FileReference, Double> 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<Future<Optional<File>>> 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<Future<Optional<File>>> 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();