diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-05-31 09:25:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-31 09:25:12 +0200 |
commit | 41fafa8edf8c7dda56b30050d5233b17f03babe1 (patch) | |
tree | 60faf59681b094102012432898051f9dfaa086a9 | |
parent | 6dc529715011f82ad25bab0521dcde275f328f49 (diff) | |
parent | ae8946f58ce027703ae383e573cb6e308d8fa02b (diff) |
Merge pull request #5999 from vespa-engine/hmusum/delete-unused-file-references
Add maintainer for deleting unused file references
34 files changed, 346 insertions, 165 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/FileDistribution.java b/config-model-api/src/main/java/com/yahoo/config/model/api/FileDistribution.java index ac1bcfa542a..9b457f49bd2 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/FileDistribution.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/FileDistribution.java @@ -23,12 +23,18 @@ public interface FileDistribution { */ void startDownload(String hostName, int port, Set<FileReference> fileReferences); + // TODO: Remove when 6.244 is oldest version in use + @Deprecated static String getDefaultFileDBRoot() { return Defaults.getDefaults().underVespaHome("var/db/vespa/filedistribution"); } + // TODO: Remove when 6.244 is oldest version in use + @Deprecated static File getDefaultFileDBPath() { return new File(getDefaultFileDBRoot()); } + File getFileReferencesDir(); + } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java index eabd0e5a7e0..131a5344116 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java @@ -7,10 +7,10 @@ import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.model.test.MockHosts; import org.junit.Test; +import java.io.File; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -48,5 +48,10 @@ public class FileDistributorTestCase { public void startDownload(String hostName, int port, Set<FileReference> fileReferences) { filesToDownloadCalled++; } + + @Override + public File getFileReferencesDir() { + return null; + } } } diff --git a/configdefinitions/src/vespa/configserver.def b/configdefinitions/src/vespa/configserver.def index 5e81526dc53..bf4c9599f4a 100644 --- a/configdefinitions/src/vespa/configserver.def +++ b/configdefinitions/src/vespa/configserver.def @@ -13,10 +13,13 @@ zookeeperserver[].port int default=2181 zookeeper.barrierTimeout long default=120 # in seconds zookeeperLocalhostAffinity bool default=true -# Misc +# Directories configModelPluginDir[] string configServerDBDir string default="var/db/vespa/config_server/serverdb/" configDefinitionsDir string default="share/vespa/configdefinitions/" +fileReferencesDir string default="var/db/vespa/filedistribution/" + +# Misc sessionLifetime long default=3600 # in seconds masterGeneration long default=0 multitenant bool default=false diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index 102a36e833f..c174464c3e6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -7,6 +7,7 @@ import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; import com.yahoo.component.Vtag; import com.yahoo.concurrent.DaemonThreadFactory; +import com.yahoo.config.FileReference; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.application.api.DeployLogger; @@ -54,7 +55,9 @@ import java.net.URI; import java.time.Clock; import java.time.Duration; import java.time.Instant; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -269,29 +272,61 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return true; } - public HttpResponse clusterControllerStatusPage(Tenant tenant, ApplicationId applicationId, String hostName, String pathSuffix) { - Application application = getApplication(tenant, applicationId); - + public HttpResponse clusterControllerStatusPage(ApplicationId applicationId, String hostName, String pathSuffix) { // WARNING: pathSuffix may be given by the external user. Make sure no security issues arise... // We should be OK here, because at most, pathSuffix may change the parent path, but cannot otherwise // change the hostname and port. Exposing other paths on the cluster controller should be fine. // TODO: It would be nice to have a simple check to verify pathSuffix doesn't contain /../ components. String relativePath = "clustercontroller-status/" + pathSuffix; - return httpProxy.get(application, hostName, "container-clustercontroller", relativePath); + return httpProxy.get(getApplication(applicationId), hostName, "container-clustercontroller", relativePath); } - public Long getApplicationGeneration(Tenant tenant, ApplicationId applicationId) { - return getApplication(tenant, applicationId).getApplicationGeneration(); + public Long getApplicationGeneration(ApplicationId applicationId) { + return getApplication(applicationId).getApplicationGeneration(); } public void restart(ApplicationId applicationId, HostFilter hostFilter) { hostProvisioner.ifPresent(provisioner -> provisioner.restart(applicationId, hostFilter)); } - public HttpResponse filedistributionStatus(Tenant tenant, ApplicationId applicationId, Duration timeout) { - Application application = getApplication(tenant, applicationId); - return fileDistributionStatus.status(application, timeout); + public HttpResponse filedistributionStatus(ApplicationId applicationId, Duration timeout) { + return fileDistributionStatus.status(getApplication(applicationId), timeout); + } + + public Set<String> deleteUnusedFiledistributionReferences(File fileReferencesPath, boolean deleteFromDisk) { + if (!fileReferencesPath.isDirectory()) throw new RuntimeException(fileReferencesPath + " is not a directory"); + + // Find all file references in use + Set<String> fileReferencesInUse = new HashSet<>(); + Set<ApplicationId> applicationIds = listApplications(); + applicationIds.forEach(applicationId -> fileReferencesInUse.addAll(getApplication(applicationId).getModel().fileReferences() + .stream() + .map(FileReference::value) + .collect(Collectors.toSet()))); + log.log(LogLevel.INFO, "File references in use : " + fileReferencesInUse); + + // Find those on disk that are not in use + Set<String> fileReferencesOnDisk = new HashSet<>(); + File[] filesOnDisk = fileReferencesPath.listFiles(); + if (filesOnDisk != null) + fileReferencesOnDisk.addAll(Arrays.stream(filesOnDisk).map(File::getName).collect(Collectors.toSet())); + log.log(LogLevel.INFO, "File references on disk (in " + fileReferencesPath + "): " + fileReferencesOnDisk); + + // TODO: Only consider the ones modified more than some time (14 days?) ago + Set<String> fileReferencesToDelete = fileReferencesOnDisk + .stream() + .filter(fileReference -> ! fileReferencesInUse.contains(fileReference)) + .collect(Collectors.toSet()); + if (deleteFromDisk) { + log.log(LogLevel.INFO, "Will delete file references not in use: " + fileReferencesToDelete); + fileReferencesToDelete.forEach(fileReference -> { + File file = new File(fileReferencesPath, fileReference); + if ( ! IOUtils.recursiveDeleteDir(file)) + log.log(LogLevel.WARNING, "Could not delete " + file.getAbsolutePath()); + }); + } + return fileReferencesToDelete; } public ApplicationFile getApplicationFileFromSession(TenantName tenantName, long sessionId, String path, LocalSession.Mode mode) { @@ -299,22 +334,27 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return getLocalSession(tenant, sessionId).getApplicationFile(Path.fromString(path), mode); } - private Application getApplication(Tenant tenant, ApplicationId applicationId) { + private Application getApplication(ApplicationId applicationId) { + Tenant tenant = tenantRepository.getTenant(applicationId.tenant()); long sessionId = getSessionIdForApplication(tenant, applicationId); RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId, 0); return session.ensureApplicationLoaded().getForVersionOrLatest(Optional.empty(), clock.instant()); } + private Set<ApplicationId> listApplications() { + return tenantRepository.getAllTenants().stream() + .flatMap(tenant -> tenant.getApplicationRepo().listApplications().stream()) + .collect(Collectors.toSet()); + } + // ---------------- Convergence ---------------------------------------------------------------- - public HttpResponse serviceConvergenceCheck(Tenant tenant, ApplicationId applicationId, String hostname, URI uri) { - Application application = getApplication(tenant, applicationId); - return convergeChecker.serviceConvergenceCheck(application, hostname, uri); + public HttpResponse serviceConvergenceCheck(ApplicationId applicationId, String hostname, URI uri) { + return convergeChecker.serviceConvergenceCheck(getApplication(applicationId), hostname, uri); } - public HttpResponse serviceListToCheckForConfigConvergence(Tenant tenant, ApplicationId applicationId, URI uri) { - Application application = getApplication(tenant, applicationId); - return convergeChecker.serviceListToCheckForConfigConvergence(application, uri); + public HttpResponse serviceListToCheckForConfigConvergence(ApplicationId applicationId, URI uri) { + return convergeChecker.serviceListToCheckForConfigConvergence(getApplication(applicationId), uri); } // ---------------- Session operations ---------------------------------------------------------------- diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerDB.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerDB.java index 33718774228..72a470cf937 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerDB.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ConfigServerDB.java @@ -17,8 +17,7 @@ import java.util.List; * Config server db is the maintainer of the serverdb directory containing def files and the file system sessions. * See also {@link com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs} which maintains directories per tenant. * - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class ConfigServerDB { private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(ConfigServerDB.class.getName()); @@ -41,17 +40,13 @@ public class ConfigServerDB { } } - public static ConfigServerDB createTestConfigServerDb(String dbDir, String definitionsDir) { - return new ConfigServerDB(new ConfigserverConfig(new ConfigserverConfig.Builder() - .configServerDBDir(dbDir) - .configDefinitionsDir(definitionsDir))); - } - // The config definitions shipped with Vespa public File classes() { return new File(Defaults.getDefaults().underVespaHome(configserverConfig.configDefinitionsDir()));} public File serverdefs() { return new File(serverDB, "serverdefs"); } + public File path() { return serverDB; } + public static void createDirectory(File d) { if (d.exists()) { if (!d.isDirectory()) { @@ -81,7 +76,4 @@ public class ConfigServerDB { } } - public ConfigserverConfig getConfigserverConfig() { - return configserverConfig; - } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java index b6e8f013fd1..6828204b17c 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/GlobalComponentRegistry.java @@ -27,7 +27,6 @@ public interface GlobalComponentRegistry { Curator getCurator(); ConfigCurator getConfigCurator(); Metrics getMetrics(); - ConfigServerDB getServerDB(); SessionPreparer getSessionPreparer(); ConfigserverConfig getConfigserverConfig(); TenantListener getTenantListener(); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java index d0b830aceaa..88f54e569df 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java @@ -31,7 +31,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry private final ConfigCurator configCurator; private final Metrics metrics; private final ModelFactoryRegistry modelFactoryRegistry; - private final ConfigServerDB serverDB; private final SessionPreparer sessionPreparer; private final RpcServer rpcServer; private final ConfigserverConfig configserverConfig; @@ -47,7 +46,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry ConfigCurator configCurator, Metrics metrics, ModelFactoryRegistry modelFactoryRegistry, - ConfigServerDB serverDB, SessionPreparer sessionPreparer, RpcServer rpcServer, ConfigserverConfig configserverConfig, @@ -61,7 +59,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry this.configCurator = configCurator; this.metrics = metrics; this.modelFactoryRegistry = modelFactoryRegistry; - this.serverDB = serverDB; this.sessionPreparer = sessionPreparer; this.rpcServer = rpcServer; this.configserverConfig = configserverConfig; @@ -80,8 +77,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry @Override public Metrics getMetrics() { return metrics; } @Override - public ConfigServerDB getServerDB() { return serverDB; } - @Override public SessionPreparer getSessionPreparer() { return sessionPreparer; } @Override public ConfigserverConfig getConfigserverConfig() { return configserverConfig; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/TenantFileSystemDirs.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/TenantFileSystemDirs.java index 93cd68f6dd6..293f35558cb 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/TenantFileSystemDirs.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/TenantFileSystemDirs.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.deploy; -import com.google.common.io.Files; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.provision.TenantName; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; @@ -12,23 +12,24 @@ import java.io.File; /* * Holds file system directories for a tenant * - * @author tonytv + * @author Tony Vaagenes */ public class TenantFileSystemDirs { private final File serverDB; private final TenantName tenant; + public TenantFileSystemDirs(ConfigserverConfig configserverConfig, TenantName tenant) { + this(new ConfigServerDB(configserverConfig).path(), tenant); + } + + // For testing public TenantFileSystemDirs(File dir, TenantName tenant) { this.serverDB = dir; this.tenant = tenant; ConfigServerDB.createDirectory(sessionsPath()); } - public static TenantFileSystemDirs createTestDirs(TenantName tenantName) { - return new TenantFileSystemDirs(Files.createTempDir(), tenantName); - } - public File sessionsPath() { return new File(serverDB, Path.fromString("tenants").append(tenant.value()).append("sessions").getRelative()); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java index 1c2c24cc7bb..df2287c64cb 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java @@ -26,10 +26,6 @@ public class FileDirectory { private static final Logger log = Logger.getLogger(FileDirectory.class.getName()); private final File root; - public FileDirectory() { - this(FileDistribution.getDefaultFileDBPath()); - } - public FileDirectory(File rootDir) { root = rootDir; try { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionImpl.java index 544451b8e10..2db89c2e8ed 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionImpl.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionImpl.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.filedistribution; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.FileReference; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.jrt.ErrorCode; @@ -11,7 +12,9 @@ import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Target; import com.yahoo.jrt.Transport; import com.yahoo.log.LogLevel; +import com.yahoo.vespa.defaults.Defaults; +import java.io.File; import java.util.Set; import java.util.logging.Logger; @@ -22,12 +25,22 @@ public class FileDistributionImpl implements FileDistribution { private final static Logger log = Logger.getLogger(FileDistributionImpl.class.getName()); private final Supervisor supervisor = new Supervisor(new Transport()); + private final File fileReferencesDir; + + public FileDistributionImpl(ConfigserverConfig configserverConfig) { + this.fileReferencesDir = new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir())); + } @Override public void startDownload(String hostName, int port, Set<FileReference> fileReferences) { startDownloadingFileReferences(hostName, port, fileReferences); } + @Override + public File getFileReferencesDir() { + return fileReferencesDir; + } + // Notifies config proxy which file references it should start downloading. It's OK if the call does not succeed, // as downloading will then start synchronously when a service requests a file reference instead private void startDownloadingFileReferences(String hostName, int port, Set<FileReference> fileReferences) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionProvider.java index d6751987424..b3f3214793c 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionProvider.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionProvider.java @@ -17,8 +17,8 @@ public class FileDistributionProvider { private final FileDistribution fileDistribution; public FileDistributionProvider(File applicationDir, FileDistribution fileDistribution) { - this(new FileDBRegistry(new ApplicationFileManager(applicationDir, new FileDirectory())), fileDistribution); - ensureDirExists(FileDistribution.getDefaultFileDBPath()); + this(new FileDBRegistry(new ApplicationFileManager(applicationDir, new FileDirectory(fileDistribution.getFileReferencesDir()))), fileDistribution); + ensureDirExists(fileDistribution.getFileReferencesDir()); } FileDistributionProvider(FileRegistry fileRegistry, FileDistribution fileDistribution) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java index 001ef751e69..42bf269e9d2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.config.server.filedistribution; import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.FileReference; -import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.jrt.Int32Value; import com.yahoo.jrt.Request; @@ -17,6 +16,7 @@ import com.yahoo.vespa.config.Connection; import com.yahoo.vespa.config.ConnectionPool; import com.yahoo.vespa.config.JRTConnectionPool; import com.yahoo.vespa.config.server.ConfigServerSpec; +import com.yahoo.vespa.defaults.Defaults; import com.yahoo.vespa.filedistribution.CompressedFileReference; import com.yahoo.vespa.filedistribution.FileDownloader; import com.yahoo.vespa.filedistribution.FileReferenceData; @@ -72,7 +72,7 @@ public class FileServer { @Inject public FileServer(ConfigserverConfig configserverConfig) { - this(createConnectionPool(configserverConfig), FileDistribution.getDefaultFileDBPath()); + this(createConnectionPool(configserverConfig), new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir()))); } // For testing only diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDBHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistribution.java index 728f327c829..40d75d9dbac 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDBHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistribution.java @@ -4,14 +4,23 @@ package com.yahoo.vespa.config.server.filedistribution; import com.yahoo.config.FileReference; import com.yahoo.config.model.api.FileDistribution; +import java.io.File; import java.util.Set; /** * @author Ulf Lilleengen */ -public class MockFileDBHandler implements FileDistribution { +public class MockFileDistribution implements FileDistribution { + private final File fileReferencesDir; + + MockFileDistribution(File fileReferencesDir) { + this.fileReferencesDir = fileReferencesDir; + } @Override public void startDownload(String hostName, int port, Set<FileReference> fileReferences) {} + @Override + public File getFileReferencesDir() { return fileReferencesDir; } + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java index b4ed2352d00..db70a51b2b4 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java @@ -4,14 +4,16 @@ package com.yahoo.vespa.config.server.filedistribution; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.model.application.provider.MockFileRegistry; +import java.io.File; + /** * @author Ulf Lilleengen */ public class MockFileDistributionProvider extends FileDistributionProvider { public int timesCalled = 0; - public MockFileDistributionProvider() { - super(new MockFileRegistry(), new MockFileDBHandler()); + public MockFileDistributionProvider(File fileReferencesDir) { + super(new MockFileRegistry(), new MockFileDistribution(fileReferencesDir)); } public FileDistribution getFileDistribution() { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index 42fdb16c7ca..6bca8b1c562 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -59,13 +59,13 @@ public class ApplicationHandler extends HttpHandler { Tenant tenant = verifyTenantAndApplication(applicationId); if (isServiceConvergeRequest(request)) { - return applicationRepository.serviceConvergenceCheck(tenant, applicationId, getHostNameFromRequest(request), request.getUri()); + return applicationRepository.serviceConvergenceCheck(applicationId, getHostNameFromRequest(request), request.getUri()); } if (isClusterControllerStatusRequest(request)) { String hostName = getHostNameFromRequest(request); String pathSuffix = getPathSuffix(request); - return applicationRepository.clusterControllerStatusPage(tenant, applicationId, hostName, pathSuffix); + return applicationRepository.clusterControllerStatusPage(applicationId, hostName, pathSuffix); } if (isContentRequest(request)) { @@ -86,15 +86,15 @@ public class ApplicationHandler extends HttpHandler { } if (isServiceConvergeListRequest(request)) { - return applicationRepository.serviceListToCheckForConfigConvergence(tenant, applicationId, request.getUri()); + return applicationRepository.serviceListToCheckForConfigConvergence(applicationId, request.getUri()); } if (isFiledistributionStatusRequest(request)) { Duration timeout = HttpHandler.getRequestTimeout(request, Duration.ofSeconds(5)); - return applicationRepository.filedistributionStatus(tenant, applicationId, timeout); + return applicationRepository.filedistributionStatus(applicationId, timeout); } - return new GetApplicationResponse(Response.Status.OK, applicationRepository.getApplicationGeneration(tenant, applicationId)); + return new GetApplicationResponse(Response.Status.OK, applicationRepository.getApplicationGeneration(applicationId)); } @Override diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java index 2c46f2968ce..a08b077699c 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java @@ -3,8 +3,10 @@ package com.yahoo.vespa.config.server.maintenance; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.AbstractComponent; +import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.session.FileDistributionFactory; import com.yahoo.vespa.curator.Curator; import java.time.Duration; @@ -13,20 +15,24 @@ public class ConfigServerMaintenance extends AbstractComponent { private final TenantsMaintainer tenantsMaintainer; private final ZooKeeperDataMaintainer zooKeeperDataMaintainer; + private final FileDistributionMaintainer fileDistributionMaintainer; @SuppressWarnings("unused") // instantiated by Dependency Injection public ConfigServerMaintenance(ConfigserverConfig configserverConfig, ApplicationRepository applicationRepository, - Curator curator) { + Curator curator, + FileDistributionFactory fileDistributionFactory) { DefaultTimes defaults = new DefaultTimes(configserverConfig); tenantsMaintainer = new TenantsMaintainer(applicationRepository, curator, defaults.tenantsMaintainerInterval); - zooKeeperDataMaintainer = new ZooKeeperDataMaintainer(applicationRepository, curator, defaults.zookeeperDataMaintainerInterval); + zooKeeperDataMaintainer = new ZooKeeperDataMaintainer(applicationRepository, curator, defaults.defaultInterval); + fileDistributionMaintainer = new FileDistributionMaintainer(applicationRepository, curator, defaults.defaultInterval, configserverConfig); } @Override public void deconstruct() { tenantsMaintainer.deconstruct(); zooKeeperDataMaintainer.deconstruct(); + fileDistributionMaintainer.deconstruct(); } /* @@ -37,7 +43,6 @@ public class ConfigServerMaintenance extends AbstractComponent { private final Duration defaultInterval; private final Duration tenantsMaintainerInterval; - private final Duration zookeeperDataMaintainerInterval; DefaultTimes(ConfigserverConfig configserverConfig) { boolean isCd = configserverConfig.system().equals(SystemName.cd.name()); @@ -45,7 +50,6 @@ public class ConfigServerMaintenance extends AbstractComponent { this.defaultInterval = Duration.ofMinutes(configserverConfig.maintainerIntervalMinutes()); // TODO: Want job control or feature flag to control when to run this, for now use a very long interval unless in CD this.tenantsMaintainerInterval = isCd ? defaultInterval : Duration.ofMinutes(configserverConfig.tenantsMaintainerIntervalMinutes()); - this.zookeeperDataMaintainerInterval = defaultInterval; } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/FileDistributionMaintainer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/FileDistributionMaintainer.java new file mode 100644 index 00000000000..58141a3a045 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/FileDistributionMaintainer.java @@ -0,0 +1,33 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.maintenance; + +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.FileDistribution; +import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.defaults.Defaults; + +import java.io.File; +import java.time.Duration; + +public class FileDistributionMaintainer extends Maintainer { + + private final ApplicationRepository applicationRepository; + private final File fileReferencesDir; + + public FileDistributionMaintainer(ApplicationRepository applicationRepository, + Curator curator, + Duration interval, + ConfigserverConfig configserverConfig) { + super(applicationRepository, curator, interval); + this.applicationRepository = applicationRepository; + this.fileReferencesDir = new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir()));; + } + + + @Override + protected void maintain() { + // TODO: Does not delete, for now just outputs what should be deleted + applicationRepository.deleteUnusedFiledistributionReferences(fileReferencesDir, false); + } +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java index d3a74486d12..8394494adca 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.session; +import com.google.inject.Inject; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.vespa.config.server.filedistribution.FileDistributionImpl; import com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider; @@ -14,8 +16,15 @@ import java.io.File; @SuppressWarnings("WeakerAccess") public class FileDistributionFactory { + private final ConfigserverConfig configserverConfig; + + @Inject + public FileDistributionFactory(ConfigserverConfig configserverConfig) { + this.configserverConfig = configserverConfig; + } + public FileDistributionProvider createProvider(File applicationPackage) { - return new FileDistributionProvider(applicationPackage, new FileDistributionImpl()); + return new FileDistributionProvider(applicationPackage, new FileDistributionImpl(configserverConfig)); } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java index 69721ed01d4..ad967f49964 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java @@ -14,9 +14,7 @@ import com.yahoo.vespa.config.server.application.ZKTenantApplications; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.session.*; -import com.yahoo.vespa.defaults.Defaults; -import java.io.File; import java.time.Clock; import java.util.Collections; @@ -162,12 +160,7 @@ public class TenantBuilder { private void createServerDbDirs() { if (tenantFileSystemDirs == null) { - tenantFileSystemDirs = new TenantFileSystemDirs(new File( - Defaults.getDefaults().underVespaHome(componentRegistry - .getServerDB() - .getConfigserverConfig() - .configServerDBDir())), - tenant); + tenantFileSystemDirs = new TenantFileSystemDirs(componentRegistry.getConfigserverConfig(), tenant); } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index 058e39eea9b..ecbeb5d7d20 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -10,10 +10,9 @@ import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.TenantName; -import com.yahoo.vespa.config.server.http.CompressedApplicationInputStream; -import com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest; +import com.yahoo.io.IOUtils; +import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.http.SessionHandlerTest; -import com.yahoo.vespa.config.server.http.v2.ApplicationApiHandler; import com.yahoo.vespa.config.server.http.v2.PrepareResult; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.Tenant; @@ -21,14 +20,17 @@ import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.time.Clock; import java.time.Duration; import java.time.Instant; +import java.util.Collections; +import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -48,18 +50,22 @@ public class ApplicationRepositoryTest { private Tenant tenant; private ApplicationRepository applicationRepository; + private TenantRepository tenantRepository; private TimeoutBudget timeoutBudget; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before public void setup() { Curator curator = new MockCurator(); - TenantRepository tenants = new TenantRepository(new TestComponentRegistry.Builder() + tenantRepository = new TenantRepository(new TestComponentRegistry.Builder() .curator(curator) .build()); - tenants.addTenant(tenantName); - tenant = tenants.getTenant(tenantName); + tenantRepository.addTenant(tenantName); + tenant = tenantRepository.getTenant(tenantName); Provisioner provisioner = new SessionHandlerTest.MockProvisioner(); - applicationRepository = new ApplicationRepository(tenants, provisioner, clock); + applicationRepository = new ApplicationRepository(tenantRepository, provisioner, clock); timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60)); } @@ -79,15 +85,15 @@ public class ApplicationRepositoryTest { } @Test - public void createAndPrepareAndActivate() throws IOException { - PrepareResult result = deployApp(); + public void createAndPrepareAndActivate() { + PrepareResult result = deployApp(testApp); assertTrue(result.configChangeActions().getRefeedActions().isEmpty()); assertTrue(result.configChangeActions().getRestartActions().isEmpty()); } @Test - public void deleteUnusedTenants() throws IOException { - deployApp(); + public void deleteUnusedTenants() { + deployApp(testApp); assertTrue(applicationRepository.removeUnusedTenants().isEmpty()); applicationRepository.remove(applicationId()); assertEquals(tenantName, applicationRepository.removeUnusedTenants().iterator().next()); @@ -110,17 +116,48 @@ public class ApplicationRepositoryTest { assertEquals(Vtag.currentVersion, ApplicationRepository.decideVersion(regularApp, Environment.perf, targetVersion)); } + @Test + public void deleteUnusedFileReferences() throws IOException { + File fileReferencesDir = temporaryFolder.newFolder(); + + // Add file reference that is not in use and should be deleted + File filereferenceDir = new File(fileReferencesDir, "foo"); + assertTrue(filereferenceDir.mkdir()); + IOUtils.writeFile(new File(filereferenceDir, "bar"), Utf8.toBytes("test")); + + tenantRepository.addTenant(tenantName); + tenant = tenantRepository.getTenant(tenantName); + Provisioner provisioner = new SessionHandlerTest.MockProvisioner(); + applicationRepository = new ApplicationRepository(tenantRepository, provisioner, clock); + timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60)); + + // TODO: Deploy an app with a bundle or file that will be a file reference, too much missing in test setup to get this working now + PrepareParams prepareParams = new PrepareParams.Builder().applicationId(applicationId()).ignoreValidationErrors(true).build(); + deployApp(new File("src/test/apps/app"), prepareParams); + + boolean deleteFiles = false; + Set<String> toBeDeleted = applicationRepository.deleteUnusedFiledistributionReferences(fileReferencesDir, deleteFiles); + assertEquals(Collections.singleton("foo"), toBeDeleted); + assertTrue(filereferenceDir.exists()); + + deleteFiles = true; + toBeDeleted = applicationRepository.deleteUnusedFiledistributionReferences(fileReferencesDir, deleteFiles); + assertEquals(Collections.singleton("foo"), toBeDeleted); + assertFalse(filereferenceDir.exists()); + } + private PrepareResult prepareAndActivateApp(File application) throws IOException { FilesApplicationPackage appDir = FilesApplicationPackage.fromFile(application); long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, appDir.getAppDir()); return applicationRepository.prepareAndActivate(tenant, sessionId, prepareParams(), false, false, Instant.now()); } - private PrepareResult deployApp() throws IOException { - File file = CompressedApplicationInputStreamTest.createTarFile(); - return applicationRepository.deploy(CompressedApplicationInputStream.createFromCompressedStream( - new FileInputStream(file), ApplicationApiHandler.APPLICATION_X_GZIP), - prepareParams(), false, false, Instant.now()); + private PrepareResult deployApp(File applicationPackage) { + return deployApp(applicationPackage, prepareParams()); + } + + private PrepareResult deployApp(File applicationPackage, PrepareParams prepareParams) { + return applicationRepository.deploy(applicationPackage, prepareParams); } private PrepareParams prepareParams() { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java index 77550b3cd35..67cc87ae223 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerBootstrapTest.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server; -import com.google.common.io.Files; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.container.jdisc.config.HealthMonitorConfig; import com.yahoo.container.jdisc.state.StateMonitor; @@ -9,12 +8,12 @@ import com.yahoo.jdisc.core.SystemTimer; import com.yahoo.vespa.config.server.deploy.DeployTester; import com.yahoo.vespa.config.server.rpc.RpcServer; import com.yahoo.vespa.config.server.version.VersionState; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import java.io.File; +import java.io.IOException; import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; @@ -35,7 +34,7 @@ public class ConfigServerBootstrapTest { @Test public void testBootStrap() throws Exception { - ConfigserverConfig configserverConfig = createConfigserverConfig(); + ConfigserverConfig configserverConfig = createConfigserverConfig(temporaryFolder); DeployTester tester = new DeployTester("src/test/apps/hosted/", configserverConfig); tester.deployApp("myApp", "4.5.6", Instant.now()); @@ -55,7 +54,7 @@ public class ConfigServerBootstrapTest { @Test public void testBootStrapWhenRedeploymentFails() throws Exception { - ConfigserverConfig configserverConfig = createConfigserverConfig(); + ConfigserverConfig configserverConfig = createConfigserverConfig(temporaryFolder); DeployTester tester = new DeployTester("src/test/apps/hosted/", configserverConfig); tester.deployApp("myApp", "4.5.6", Instant.now()); @@ -90,8 +89,8 @@ public class ConfigServerBootstrapTest { throw new RuntimeException(messageIfWaitingFails); } - private MockRpc createRpcServer(ConfigserverConfig configserverConfig) { - return new MockRpc(configserverConfig.rpcport()); + private MockRpc createRpcServer(ConfigserverConfig configserverConfig) throws IOException { + return new MockRpc(configserverConfig.rpcport(), temporaryFolder.newFolder()); } private StateMonitor createStateMonitor() { @@ -99,10 +98,10 @@ public class ConfigServerBootstrapTest { new SystemTimer()); } - private static ConfigserverConfig createConfigserverConfig() { + private static ConfigserverConfig createConfigserverConfig(TemporaryFolder temporaryFolder) throws IOException { return new ConfigserverConfig(new ConfigserverConfig.Builder() - .configServerDBDir(Files.createTempDir().getAbsolutePath()) - .configDefinitionsDir(Files.createTempDir().getAbsolutePath()) + .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) + .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath()) .hostedVespa(true) .multitenant(true)); } @@ -111,8 +110,8 @@ public class ConfigServerBootstrapTest { volatile boolean isRunning = false; - MockRpc(int port) { - super(port); + MockRpc(int port, File tempDir) { + super(port, tempDir); } @Override diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerDBTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerDBTest.java index c34f6512f29..0c8a9e5c3d8 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerDBTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ConfigServerDBTest.java @@ -1,10 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server; -import com.google.common.io.Files; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.io.IOUtils; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; @@ -13,25 +15,28 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class ConfigServerDBTest { private ConfigServerDB serverDB; - private File dbDir; - private File definitionsDir; + private ConfigserverConfig configserverConfig; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before - public void setup() { - dbDir = Files.createTempDir(); - definitionsDir = Files.createTempDir(); - serverDB = ConfigServerDB.createTestConfigServerDb(dbDir.getAbsolutePath(), definitionsDir.getAbsolutePath()); + public void setup() throws IOException { + configserverConfig = new ConfigserverConfig( + new ConfigserverConfig.Builder() + .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) + .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath())); + serverDB = new ConfigServerDB(configserverConfig); } private void createInitializer() throws IOException { File existingDef = new File(serverDB.classes(), "test.def"); IOUtils.writeFile(existingDef, "hello", false); - ConfigServerDB.createTestConfigServerDb(dbDir.getAbsolutePath(), definitionsDir.getAbsolutePath()); + new ConfigServerDB(configserverConfig); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java index dec9dd991de..5ca3deab1fe 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java @@ -1,11 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server; -import com.google.common.io.Files; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; -import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.filedistribution.FileServer; @@ -22,8 +20,11 @@ import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.model.VespaModelFactory; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import java.io.IOException; import java.util.Collections; import static org.hamcrest.Matchers.is; @@ -31,14 +32,12 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class InjectedGlobalComponentRegistryTest { private Curator curator; private Metrics metrics; - private ConfigServerDB serverDB; private SessionPreparer sessionPreparer; private ConfigserverConfig configserverConfig; private RpcServer rpcServer; @@ -50,33 +49,36 @@ public class InjectedGlobalComponentRegistryTest { private ModelFactoryRegistry modelFactoryRegistry; private Zone zone; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before - public void setupRegistry() { + public void setupRegistry() throws IOException { curator = new MockCurator(); ConfigCurator configCurator = ConfigCurator.create(curator); metrics = Metrics.createTestMetrics(); modelFactoryRegistry = new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))); configserverConfig = new ConfigserverConfig( new ConfigserverConfig.Builder() - .configServerDBDir(Files.createTempDir().getAbsolutePath()) - .configDefinitionsDir(Files.createTempDir().getAbsolutePath())); - serverDB = new ConfigServerDB(configserverConfig); + .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) + .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath())); sessionPreparer = new SessionTest.MockSessionPreparer(); - rpcServer = new RpcServer(configserverConfig, null, Metrics.createTestMetrics(), - new HostRegistries(), new ConfigRequestHostLivenessTracker(), new FileServer(FileDistribution.getDefaultFileDBPath())); + rpcServer = new RpcServer(configserverConfig, null, Metrics.createTestMetrics(), + new HostRegistries(), new ConfigRequestHostLivenessTracker(), new FileServer(temporaryFolder.newFolder("filereferences"))); generationCounter = new SuperModelGenerationCounter(curator); defRepo = new StaticConfigDefinitionRepo(); permanentApplicationPackage = new PermanentApplicationPackage(configserverConfig); hostRegistries = new HostRegistries(); HostProvisionerProvider hostProvisionerProvider = HostProvisionerProvider.withProvisioner(new SessionHandlerTest.MockProvisioner()); zone = Zone.defaultZone(); - globalComponentRegistry = new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, serverDB, sessionPreparer, rpcServer, configserverConfig, generationCounter, defRepo, permanentApplicationPackage, hostRegistries, hostProvisionerProvider, zone); + globalComponentRegistry = + new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, sessionPreparer, rpcServer, configserverConfig, + generationCounter, defRepo, permanentApplicationPackage, hostRegistries, hostProvisionerProvider, zone); } @Test public void testThatAllComponentsAreSetup() { assertThat(globalComponentRegistry.getModelFactoryRegistry(), is(modelFactoryRegistry)); - assertThat(globalComponentRegistry.getServerDB(), is(serverDB)); assertThat(globalComponentRegistry.getSessionPreparer(), is(sessionPreparer)); assertThat(globalComponentRegistry.getMetrics(), is(metrics)); assertThat(globalComponentRegistry.getCurator(), is(curator)); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java index d026989a43e..e4e45d3a014 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java @@ -23,6 +23,7 @@ import com.yahoo.vespa.curator.mock.MockCurator; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.model.VespaModelFactory; +import java.io.File; import java.time.Clock; import java.util.Collections; import java.util.Optional; @@ -37,7 +38,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { private final Curator curator; private final ConfigCurator configCurator; private final Metrics metrics; - private final ConfigServerDB serverDB; private final SessionPreparer sessionPreparer; private final ConfigserverConfig configserverConfig; private final SuperModelGenerationCounter superModelGenerationCounter; @@ -57,7 +57,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { PermanentApplicationPackage permanentApplicationPackage, FileDistributionFactory fileDistributionFactory, SuperModelGenerationCounter superModelGenerationCounter, - ConfigServerDB configServerDB, HostRegistries hostRegistries, ConfigserverConfig configserverConfig, SessionPreparer sessionPreparer, @@ -71,7 +70,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { this.configCurator = configCurator; this.metrics = metrics; this.configserverConfig = configserverConfig; - this.serverDB = configServerDB; this.reloadListener = reloadListener; this.tenantListener = tenantListener; this.superModelGenerationCounter = superModelGenerationCounter; @@ -155,7 +153,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { final PermanentApplicationPackage permApp = this.permanentApplicationPackage .orElse(new PermanentApplicationPackage(configserverConfig)); FileDistributionFactory fileDistributionFactory = this.fileDistributionFactory - .orElse(new MockFileDistributionFactory()); + .orElse(new MockFileDistributionFactory(new File(configserverConfig.fileReferencesDir()))); HostProvisionerProvider hostProvisionerProvider = hostProvisioner.isPresent() ? HostProvisionerProvider.withProvisioner(hostProvisioner.get()) : HostProvisionerProvider.empty(); @@ -168,7 +166,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { permApp, fileDistributionFactory, new SuperModelGenerationCounter(curator), - new ConfigServerDB(configserverConfig), hostRegistries, configserverConfig, sessionPreparer, hostProvisioner, defRepo, reloadListener, tenantListener, zone, clock); @@ -182,8 +179,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { @Override public Metrics getMetrics() { return metrics; } @Override - public ConfigServerDB getServerDB() { return serverDB; } - @Override public SessionPreparer getSessionPreparer() { return sessionPreparer; } @Override public ConfigserverConfig getConfigserverConfig() { return configserverConfig; } 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 157c36d7aef..9ba8adf0aa4 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 @@ -6,7 +6,9 @@ import com.yahoo.io.IOUtils; import com.yahoo.net.HostName; import com.yahoo.vespa.filedistribution.FileReferenceData; import org.junit.After; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; @@ -35,6 +37,9 @@ public class FileServerTest { created.add(dir); } + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Test public void requireThatExistingFileCanBeFound() throws IOException { createCleanDir("123"); @@ -71,10 +76,12 @@ public class FileServerTest { } @Test - public void requireThatDifferentNumberOfConfigServersWork() { + public void requireThatDifferentNumberOfConfigServersWork() throws IOException { // Empty connection pool in tests etc. - ConfigserverConfig.Builder builder = new ConfigserverConfig.Builder(); - FileServer fileServer = new FileServer(new ConfigserverConfig(builder)); + ConfigserverConfig.Builder builder = new ConfigserverConfig.Builder() + .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) + .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath()); + FileServer fileServer = createFileServer(builder); assertEquals(0, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize()); // Empty connection pool when only one server, no use in downloading from yourself @@ -84,7 +91,7 @@ public class FileServerTest { serverBuilder.port(123456); servers.add(serverBuilder); builder.zookeeperserver(servers); - fileServer = new FileServer(new ConfigserverConfig(builder)); + fileServer = createFileServer(builder); assertEquals(0, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize()); // connection pool of size 1 when 2 servers @@ -93,10 +100,16 @@ public class FileServerTest { serverBuilder2.port(123456); servers.add(serverBuilder2); builder.zookeeperserver(servers); - fileServer = new FileServer(new ConfigserverConfig(builder)); + fileServer = createFileServer(builder); assertEquals(1, fileServer.downloader().fileReferenceDownloader().connectionPool().getSize()); } + private FileServer createFileServer(ConfigserverConfig.Builder configBuilder) throws IOException { + File fileReferencesDir = temporaryFolder.newFolder(); + configBuilder.fileReferencesDir(fileReferencesDir.getAbsolutePath()); + return new FileServer(new ConfigserverConfig(configBuilder)); + } + private static class FileReceiver implements FileServer.Receiver { CompletableFuture<byte []> content; FileReceiver(CompletableFuture<byte []> content) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java index e14e59b9fe7..030963aa9a1 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java @@ -50,7 +50,9 @@ import com.yahoo.vespa.model.VespaModelFactory; import org.hamcrest.core.Is; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.ByteArrayOutputStream; import java.io.File; @@ -89,6 +91,9 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { private TenantRepository tenantRepository; private SessionActiveHandler handler; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before public void setup() { remoteSessionRepo = new RemoteSessionRepo(tenantName); @@ -221,9 +226,9 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { return session; } - private void addLocalSession(long sessionId, DeployData deployData, SessionZooKeeperClient zkc) { + private void addLocalSession(long sessionId, DeployData deployData, SessionZooKeeperClient zkc) throws IOException { writeApplicationId(zkc, deployData.getApplicationName()); - TenantFileSystemDirs tenantFileSystemDirs = TenantFileSystemDirs.createTestDirs(tenantName); + TenantFileSystemDirs tenantFileSystemDirs = new TenantFileSystemDirs(temporaryFolder.newFolder(), tenantName); ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(testApp, deployData); localRepo.addSession(new LocalSession(tenantName, sessionId, new SessionTest.MockSessionPreparer(), new SessionContext(app, zkc, new File(tenantFileSystemDirs.sessionsPath(), String.valueOf(sessionId)), diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/DelayedConfigResponseTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/DelayedConfigResponseTest.java index 0126a9e2f29..9455798c4ea 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/DelayedConfigResponseTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/DelayedConfigResponseTest.java @@ -12,8 +12,11 @@ import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; import com.yahoo.vespa.config.protocol.JRTServerConfigRequestV3; import com.yahoo.vespa.config.protocol.Trace; import com.yahoo.vespa.config.server.GetConfigContext; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -28,10 +31,13 @@ import static org.junit.Assert.assertTrue; */ public class DelayedConfigResponseTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Test - public void testDelayedConfigResponses() { + public void testDelayedConfigResponses() throws IOException { - MockRpc rpc = new MockRpc(13337); + MockRpc rpc = new MockRpc(13337, temporaryFolder.newFolder()); DelayedConfigResponses responses = new DelayedConfigResponses(rpc, 1, false); assertThat(responses.size(), is(0)); JRTServerConfigRequest req = createRequest("foo", "md5", "myid", "mymd5", 3, 1000000, "bar"); @@ -50,9 +56,9 @@ public class DelayedConfigResponseTest { } @Test - public void testDelayResponseRemove() { + public void testDelayResponseRemove() throws IOException { GetConfigContext context = GetConfigContext.testContext(ApplicationId.defaultId()); - MockRpc rpc = new MockRpc(13337); + MockRpc rpc = new MockRpc(13337, temporaryFolder.newFolder()); DelayedConfigResponses responses = new DelayedConfigResponses(rpc, 1, false); responses.delayResponse(createRequest("foolio", "md5", "myid", "mymd5", 3, 100000, "bar"), context); assertThat(responses.size(), is(1)); @@ -61,8 +67,8 @@ public class DelayedConfigResponseTest { } @Test - public void testDelayedConfigResponse() { - MockRpc rpc = new MockRpc(13337); + public void testDelayedConfigResponse() throws IOException { + MockRpc rpc = new MockRpc(13337, temporaryFolder.newFolder()); DelayedConfigResponses responses = new DelayedConfigResponses(rpc, 1, false); assertThat(responses.size(), is(0)); assertThat(responses.toString(), is("DelayedConfigResponses. Average Size=0")); @@ -72,7 +78,7 @@ public class DelayedConfigResponseTest { assertThat(rpc.latestRequest, is(req)); } - public JRTServerConfigRequest createRequest(String configName, String defMd5, String configId, String md5, long generation, long timeout, String namespace) { + private JRTServerConfigRequest createRequest(String configName, String defMd5, String configId, String md5, long generation, long timeout, String namespace) { Request request = JRTClientConfigRequestV3. createWithParams(new ConfigKey<>(configName, configId, namespace, defMd5, null), DefContent.fromList(Collections.emptyList()), "fromHost", md5, generation, timeout, Trace.createDummy(), CompressionType.UNCOMPRESSED, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessorTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessorTest.java index 578224833a1..aa4678fb01b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessorTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessorTest.java @@ -16,10 +16,11 @@ import com.yahoo.vespa.config.protocol.JRTClientConfigRequestV3; import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; import com.yahoo.vespa.config.protocol.JRTServerConfigRequestV3; import com.yahoo.vespa.config.protocol.Trace; -import com.yahoo.vespa.config.server.rpc.GetConfigProcessor; -import com.yahoo.vespa.config.server.rpc.MockRpc; import com.yahoo.vespa.config.server.tenant.MockTenantProvider; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; + import static org.junit.Assert.assertFalse; import java.io.IOException; @@ -39,9 +40,12 @@ import static org.junit.Assert.assertTrue; */ public class GetConfigProcessorTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Test - public void testSentinelConfig() { - MockRpc rpc = new MockRpc(13337, false); + public void testSentinelConfig() throws IOException { + MockRpc rpc = new MockRpc(13337, false, temporaryFolder.newFolder()); rpc.response = new MockConfigResponse("foo"); // should be a sentinel config, but it does not matter for this test // one tenant, which has host1 assigned diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpc.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpc.java index 5a9735f774a..b4de201bd0b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpc.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRpc.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.config.server.rpc; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Version; import com.yahoo.vespa.config.protocol.ConfigResponse; @@ -14,6 +13,7 @@ import com.yahoo.vespa.config.server.host.HostRegistries; import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.tenant.MockTenantProvider; +import java.io.File; import java.util.Optional; import java.util.concurrent.CompletionService; @@ -36,20 +36,20 @@ public class MockRpc extends RpcServer { public volatile JRTServerConfigRequest latestRequest = null; - public MockRpc(int port, boolean createDefaultTenant, boolean pretendToHaveLoadedAnyApplication) { + public MockRpc(int port, boolean createDefaultTenant, boolean pretendToHaveLoadedAnyApplication, File tempDir) { super(createConfig(port), null, Metrics.createTestMetrics(), - new HostRegistries(), new ConfigRequestHostLivenessTracker(), new FileServer(FileDistribution.getDefaultFileDBPath())); + new HostRegistries(), new ConfigRequestHostLivenessTracker(), new FileServer(tempDir)); if (createDefaultTenant) { onTenantCreate(TenantName.from("default"), new MockTenantProvider(pretendToHaveLoadedAnyApplication)); } } - public MockRpc(int port, boolean createDefaultTenant) { - this(port, createDefaultTenant, true); + public MockRpc(int port, boolean createDefaultTenant, File tempDir) { + this(port, createDefaultTenant, true, tempDir); } - public MockRpc(int port) { - this(port, true); + public MockRpc(int port, File tempDir) { + this(port, true, tempDir); } /** Reset fields used to assert on the calls made to this */ diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java index ef742ae3d38..3cfe6aa7c6d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcServerTest.java @@ -48,7 +48,7 @@ public class RpcServerTest extends TestWithRpc { testEmptyConfigHostedVespa(); } - private void testEmptyConfigHostedVespa() throws InterruptedException { + private void testEmptyConfigHostedVespa() throws InterruptedException, IOException { rpcServer.onTenantDelete(TenantName.defaultName()); rpcServer.onTenantsLoaded(); JRTClientConfigRequest clientReq = createSimpleRequest(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java index e022b622fb0..845e7c0f914 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.config.server.rpc; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.provision.HostLivenessTracker; import com.yahoo.config.provision.TenantName; import com.yahoo.jrt.Request; @@ -20,7 +19,10 @@ import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.tenant.MockTenantProvider; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; +import java.io.IOException; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -36,8 +38,7 @@ import static org.junit.Assert.assertTrue; /** * Test running rpc server. * - * @author lulf - * @since 5.17 + * @author Ulf Lilleengen */ // TODO: Make this a Tester instead of a superclass public class TestWithRpc { @@ -56,8 +57,11 @@ public class TestWithRpc { private List<Integer> allocatedPorts; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before - public void setupRpc() throws InterruptedException { + public void setupRpc() throws InterruptedException, IOException { allocatedPorts = new ArrayList<>(); port = allocatePort(); spec = createSpec(port); @@ -80,7 +84,7 @@ public class TestWithRpc { return port; } - protected void createAndStartRpcServer(boolean hostedVespa) { + protected void createAndStartRpcServer(boolean hostedVespa) throws IOException { ConfigserverConfig configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder()); rpcServer = new RpcServer(new ConfigserverConfig(new ConfigserverConfig.Builder() .rpcport(port) @@ -94,7 +98,7 @@ public class TestWithRpc { emptyNodeFlavors(), generationCounter)), Metrics.createTestMetrics(), new HostRegistries(), - hostLivenessTracker, new FileServer(FileDistribution.getDefaultFileDBPath())); + hostLivenessTracker, new FileServer(temporaryFolder.newFolder())); rpcServer.onTenantCreate(TenantName.from("default"), tenantProvider); t = new Thread(rpcServer); t.start(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java index 73caf770512..987dd8a6c4d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java @@ -14,7 +14,9 @@ import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.io.File; import java.time.Duration; @@ -34,6 +36,9 @@ public class LocalSessionRepoTest extends TestWithCurator { private ManualClock clock; private static final TenantName tenantName = TenantName.defaultName(); + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before public void setupSessions() throws Exception { setupSessions(tenantName, true); @@ -41,7 +46,7 @@ public class LocalSessionRepoTest extends TestWithCurator { private void setupSessions(TenantName tenantName, boolean createInitialSessions) throws Exception { GlobalComponentRegistry globalComponentRegistry = new TestComponentRegistry.Builder().curator(curator).build(); - TenantFileSystemDirs tenantFileSystemDirs = TenantFileSystemDirs.createTestDirs(tenantName); + TenantFileSystemDirs tenantFileSystemDirs = new TenantFileSystemDirs(temporaryFolder.newFolder(), tenantName); if (createInitialSessions) { IOUtils.copyDirectory(testApp, new File(tenantFileSystemDirs.sessionsPath(), "1")); IOUtils.copyDirectory(testApp, new File(tenantFileSystemDirs.sessionsPath(), "2")); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java index bd5cfdf3a0e..316c439a3cd 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.config.server.session; import com.google.common.io.Files; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.provision.*; import com.yahoo.path.Path; @@ -29,8 +30,7 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class LocalSessionTest { @@ -41,7 +41,7 @@ public class LocalSessionTest { private SuperModelGenerationCounter superModelGenerationCounter; @Before - public void setupTest() throws Exception { + public void setupTest() { curator = new MockCurator(); configCurator = ConfigCurator.create(curator); superModelGenerationCounter = new SuperModelGenerationCounter(curator); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockFileDistributionFactory.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockFileDistributionFactory.java index 9d8b7c5cc00..2c05017d449 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockFileDistributionFactory.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockFileDistributionFactory.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.session; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider; import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionProvider; @@ -11,7 +12,12 @@ import java.io.File; */ public class MockFileDistributionFactory extends FileDistributionFactory { - public final MockFileDistributionProvider mockFileDistributionProvider = new MockFileDistributionProvider(); + public final MockFileDistributionProvider mockFileDistributionProvider; + + public MockFileDistributionFactory(File fileReferencesDir) { + super(new ConfigserverConfig(new ConfigserverConfig.Builder())); + mockFileDistributionProvider = new MockFileDistributionProvider(fileReferencesDir); + } @Override public FileDistributionProvider createProvider(File applicationFile) { |