summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHÃ¥kon Hallingstad <hakon@verizonmedia.com>2020-07-29 12:09:08 +0200
committerGitHub <noreply@github.com>2020-07-29 12:09:08 +0200
commitfb30d3667ab506976c776817aa3451f97ceed83a (patch)
treea9deeba3dccc74a29e98214c16c6708b667d8412
parentfe73d203f2ec9510d90fdf360601fb921e29d738 (diff)
parentc38e1725c1eecb8589438b13c66d460fd2e85fe6 (diff)
Merge pull request #13944 from vespa-engine/hmusum/configserver-refactoring-24
Config server refactoring, use new file distribution mocks
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistry.java22
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java21
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java18
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionFactory.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java24
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ConfigServerMaintenance.java17
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/FileDistributionMaintainer.java5
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java14
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java19
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/TestComponentRegistry.java8
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java8
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionFactory.java5
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java22
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileRegistry.java49
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java41
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionTest.java15
23 files changed, 167 insertions, 141 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistry.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistry.java
index 957531b9f7f..6888626633b 100644
--- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistry.java
+++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/PreGeneratedFileRegistry.java
@@ -20,31 +20,28 @@ public class PreGeneratedFileRegistry implements FileRegistry {
private final String fileSourceHost;
private final Map<String, String> path2Hash = new LinkedHashMap<>();
- private static String entryDelimiter = "\t";
- private static Pattern entryDelimiterPattern = Pattern.compile(entryDelimiter, Pattern.LITERAL);
+ private static final String entryDelimiter = "\t";
+ private static final Pattern entryDelimiterPattern = Pattern.compile(entryDelimiter, Pattern.LITERAL);
private PreGeneratedFileRegistry(Reader readerArg) {
- BufferedReader reader = new BufferedReader(readerArg);
- try {
+ try (BufferedReader reader = new BufferedReader(readerArg)) {
fileSourceHost = reader.readLine();
if (fileSourceHost == null)
- throw new RuntimeException("Error while reading pre generated file registry");
+ throw new RuntimeException("Error while reading pre-generated file registry");
String line;
while ((line = reader.readLine()) != null) {
addFromLine(line);
}
- } catch(IOException e) {
- throw new RuntimeException("Error while reading pre generated file registry", e);
- } finally {
- try {
- reader.close();
- } catch(IOException e) {}
+ } catch (IOException e) {
+ throw new RuntimeException("Error while reading pre-generated file registry", e);
}
}
private void addFromLine(String line) {
String[] parts = entryDelimiterPattern.split(line);
+ if (parts.length < 2)
+ throw new IllegalArgumentException("Cannot split '" + line + "' into two parts");
addEntry(parts[0], parts[1]);
}
@@ -58,8 +55,7 @@ public class PreGeneratedFileRegistry implements FileRegistry {
builder.append(registry.fileSourceHost()).append('\n');
for (FileRegistry.Entry entry : entries) {
- builder.append(entry.relativePath).append(entryDelimiter).append(entry.reference.value()).
- append('\n');
+ builder.append(entry.relativePath).append(entryDelimiter).append(entry.reference.value()).append('\n');
}
return builder.toString();
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java
index 3d2918e0ee1..0192e9d42c6 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java
@@ -9,6 +9,7 @@ import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.HostSpec;
import com.yahoo.config.provision.ProvisionLogger;
+import com.yahoo.net.HostName;
import java.net.UnknownHostException;
import java.util.LinkedHashMap;
@@ -31,7 +32,7 @@ import static java.util.logging.Level.FINE;
*/
public class HostSystem extends AbstractConfigProducer<Host> {
- private static Logger log = Logger.getLogger(HostSystem.class.getName());
+ private static final Logger log = Logger.getLogger(HostSystem.class.getName());
private final Map<String, HostResource> hostname2host = new LinkedHashMap<>();
private final HostProvisioner provisioner;
@@ -65,15 +66,19 @@ public class HostSystem extends AbstractConfigProducer<Host> {
* @return the host with the given hostname, or null if no such host
*/
public HostResource getHostByHostname(String name) {
- // TODO: please eliminate the following ugly hack
- if ("localhost.fortestingpurposesonly".equals(name)) {
- String localhost = "localhost";
- if ( ! getChildren().containsKey(localhost)) {
- new Host(this, localhost);
+ String localhost = "localhost";
+ HostResource hostResource = hostname2host.get(name);
+ if (hostResource == null) {
+ // Create a new HostResource if this is the host this code is running on (as it is when running tests)
+ // TODO: please eliminate the ugly hack using "localhost.fortestingpurposesonly"
+ if (HostName.getLocalhost().equals(name) || "localhost.fortestingpurposesonly".equals(name)) {
+ if (! getChildren().containsKey(localhost)) {
+ new Host(this, localhost);
+ }
+ hostResource = new HostResource(getChildren().get(localhost));
}
- return new HostResource(getChildren().get(localhost));
}
- return hostname2host.get(name);
+ return hostResource;
}
@Override
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java
index 7484e0cd9a0..1b5be1c2f97 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/Admin.java
@@ -264,7 +264,8 @@ public class Admin extends AbstractConfigProducer implements Serializable {
FileDistributor fileDistributor = fileDistribution.getFileDistributor();
HostResource hostResource = hostSystem().getHostByHostname(fileDistributor.fileSourceHost());
if (hostResource == null && ! multitenant)
- throw new IllegalArgumentException("Could not find " + host + " in the application's " + hostSystem());
+ throw new IllegalArgumentException("Could not find " + fileDistributor.fileSourceHost() +
+ " in the application's " + hostSystem());
FileDistributionConfigProvider configProvider =
new FileDistributionConfigProvider(fileDistribution,
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java
index 7e83d7013e0..c634d82010e 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java
@@ -36,16 +36,14 @@ public class ZooKeeperClient {
private final ConfigCurator configCurator;
private final DeployLogger logger;
- private final boolean logFine;
/* This is the generation that will be used for reading and writing application data. (1 more than last deployed application) */
private final Path rootPath;
private static final ApplicationFile.PathFilter xmlFilter = path -> path.getName().endsWith(".xml");
- public ZooKeeperClient(ConfigCurator configCurator, DeployLogger logger, boolean logFine, Path rootPath) {
+ public ZooKeeperClient(ConfigCurator configCurator, DeployLogger logger, Path rootPath) {
this.configCurator = configCurator;
this.logger = logger;
- this.logFine = logFine;
this.rootPath = rootPath;
}
@@ -62,7 +60,6 @@ public class ZooKeeperClient {
try {
while (retries > 0) {
try {
- logFine("Setting up ZooKeeper nodes for this application");
createZooKeeperNodes();
break;
} catch (RuntimeException e) {
@@ -105,16 +102,11 @@ public class ZooKeeperClient {
* @param app the application package to feed to zookeeper
*/
void write(ApplicationPackage app) {
- logFine("Feeding application config into ZooKeeper");
try {
- logFine("Feeding user def files into ZooKeeper");
writeUserDefs(app);
- logFine("Feeding application package into ZooKeeper");
writeSomeOf(app);
writeSearchDefinitions(app);
writeUserIncludeDirs(app, app.getUserIncludeDirs());
- logFine("Feeding sd from docproc bundle into ZooKeeper");
- logFine("Write application metadata into ZooKeeper");
write(app.getMetaData());
} catch (Exception e) {
throw new IllegalStateException("Unable to write vespa model to config server(s) " + System.getProperty("configsources") + "\n" +
@@ -269,7 +261,6 @@ public class ZooKeeperClient {
}
private void write(Version vespaVersion, FileRegistry fileRegistry) {
- logFine("Feeding file registry data into ZooKeeper");
String exportedRegistry = PreGeneratedFileRegistry.exportRegistry(fileRegistry);
configCurator.putData(getZooKeeperAppPath(null).append(ZKApplicationPackage.fileRegistryNode).getAbsolute(),
@@ -288,7 +279,6 @@ public class ZooKeeperClient {
}
void cleanupZooKeeper() {
- logFine("Exception occurred. Cleaning up ZooKeeper");
try {
for (String subPath : Arrays.asList(
ConfigCurator.DEFCONFIGS_ZK_SUBPATH,
@@ -317,12 +307,6 @@ public class ZooKeeperClient {
}
}
- private void logFine(String msg) {
- if (logFine) {
- logger.log(Level.FINE, msg);
- }
- }
-
public void write(AllocatedHosts hosts) throws IOException {
configCurator.putData(rootPath.append(ZKApplicationPackage.allocatedHostsNode).getAbsolute(),
AllocatedHostsSerializer.toJson(hosts));
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionFactory.java
index 1cfe30270c3..ae18c3e6e95 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionFactory.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionFactory.java
@@ -16,7 +16,7 @@ import java.io.File;
@SuppressWarnings("WeakerAccess")
public class FileDistributionFactory {
- private final ConfigserverConfig configserverConfig;
+ protected final ConfigserverConfig configserverConfig;
private final Supervisor supervisor = new Supervisor(new Transport());
@Inject
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
deleted file mode 100644
index db70a51b2b4..00000000000
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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.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(File fileReferencesDir) {
- super(new MockFileRegistry(), new MockFileDistribution(fileReferencesDir));
- }
-
- public FileDistribution getFileDistribution() {
- timesCalled++;
- return super.getFileDistribution();
- }
-
-}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java
index 92044eab5fe..e539acba916 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ApplicationPackageMaintainer.java
@@ -39,11 +39,10 @@ public class ApplicationPackageMaintainer extends ConfigServerMaintainer {
ApplicationPackageMaintainer(ApplicationRepository applicationRepository,
Curator curator,
Duration interval,
- ConfigserverConfig configserverConfig,
FlagSource flagSource) {
super(applicationRepository, curator, flagSource, interval, interval);
this.applicationRepository = applicationRepository;
- this.configserverConfig = configserverConfig;
+ this.configserverConfig = applicationRepository.configserverConfig();
distributeApplicationPackage = Flags.CONFIGSERVER_DISTRIBUTE_APPLICATION_PACKAGE.bindTo(flagSource);
downloadDirectory = new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir()));
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 adcaa3bb0e4..ecdca39dc72 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
@@ -4,10 +4,8 @@ package com.yahoo.vespa.config.server.maintenance;
import com.google.inject.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.AbstractComponent;
-import com.yahoo.config.provision.SystemName;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.config.server.ApplicationRepository;
-import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.flags.FlagSource;
@@ -31,20 +29,18 @@ public class ConfigServerMaintenance extends AbstractComponent {
public ConfigServerMaintenance(ConfigserverConfig configserverConfig,
ApplicationRepository applicationRepository,
Curator curator,
- FileDistributionFactory fileDistributionFactory,
FlagSource flagSource,
Metric metric) {
DefaultTimes defaults = new DefaultTimes(configserverConfig);
- // TODO: Disabled until we have application metadata
+ // TODO: Disabled until we have application metadata per tenant
//tenantsMaintainer = new TenantsMaintainer(applicationRepository, curator, defaults.tenantsMaintainerInterval);
- fileDistributionMaintainer = new FileDistributionMaintainer(applicationRepository, curator, defaults.defaultInterval, configserverConfig, flagSource);
+ fileDistributionMaintainer = new FileDistributionMaintainer(applicationRepository, curator, defaults.defaultInterval, flagSource);
sessionsMaintainer = new SessionsMaintainer(applicationRepository, curator, Duration.ofMinutes(1), flagSource);
- applicationPackageMaintainer = new ApplicationPackageMaintainer(applicationRepository, curator, Duration.ofMinutes(1), configserverConfig, flagSource);
+ applicationPackageMaintainer = new ApplicationPackageMaintainer(applicationRepository, curator, Duration.ofMinutes(1), flagSource);
}
@Override
public void deconstruct() {
- //tenantsMaintainer.close();
fileDistributionMaintainer.close();
sessionsMaintainer.close();
applicationPackageMaintainer.close();
@@ -57,16 +53,9 @@ public class ConfigServerMaintenance extends AbstractComponent {
private static class DefaultTimes {
private final Duration defaultInterval;
- private final Duration tenantsMaintainerInterval;
DefaultTimes(ConfigserverConfig configserverConfig) {
this.defaultInterval = Duration.ofMinutes(configserverConfig.maintainerIntervalMinutes());
- boolean isCd = configserverConfig.system().equals(SystemName.cd.value());
- // TODO: Want job control or feature flag to control when to run this, for now use a very
- // long interval to avoid running the maintainer except in CD
- this.tenantsMaintainerInterval = isCd
- ? defaultInterval
- : Duration.ofMinutes(configserverConfig.tenantsMaintainerIntervalMinutes());
}
}
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
index 835122c043c..3980ae9d980 100644
--- 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
@@ -26,12 +26,11 @@ public class FileDistributionMaintainer extends ConfigServerMaintainer {
FileDistributionMaintainer(ApplicationRepository applicationRepository,
Curator curator,
Duration interval,
- ConfigserverConfig configserverConfig,
FlagSource flagSource) {
super(applicationRepository, curator, flagSource, interval, interval);
this.applicationRepository = applicationRepository;
- this.maxUnusedFileReferenceAge = Duration.ofHours(configserverConfig.keepUnusedFileReferencesHours());
- this.fileReferencesDir = new File(Defaults.getDefaults().underVespaHome(configserverConfig.fileReferencesDir()));
+ this.maxUnusedFileReferenceAge = Duration.ofHours(applicationRepository.configserverConfig().keepUnusedFileReferencesHours());
+ this.fileReferencesDir = new File(Defaults.getDefaults().underVespaHome(applicationRepository.configserverConfig().fileReferencesDir()));
}
@Override
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java
index b6b0ac45bb5..35bbc1a8233 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java
@@ -120,10 +120,10 @@ public class SessionPreparer {
* @param tenantPath Zookeeper path for the tenant for this session
* @return the config change actions that must be done to handle the activation of the models prepared.
*/
- public ConfigChangeActions prepare(HostValidator<ApplicationId> hostValidator, DeployLogger logger, PrepareParams params,
- Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath,
- Instant now, File serverDbSessionDir, ApplicationPackage applicationPackage,
- SessionZooKeeperClient sessionZooKeeperClient) {
+ public PrepareResult prepare(HostValidator<ApplicationId> hostValidator, DeployLogger logger, PrepareParams params,
+ Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath,
+ Instant now, File serverDbSessionDir, ApplicationPackage applicationPackage,
+ SessionZooKeeperClient sessionZooKeeperClient) {
Preparation preparation = new Preparation(hostValidator, logger, params, currentActiveApplicationSet,
tenantPath, serverDbSessionDir, applicationPackage, sessionZooKeeperClient);
@@ -313,8 +313,8 @@ public class SessionPreparer {
checkTimeout("distribute files");
}
- ConfigChangeActions result() {
- return prepareResult.getConfigChangeActions();
+ PrepareResult result() {
+ return prepareResult;
}
private List<ContainerEndpoint> readEndpointsIfNull(List<ContainerEndpoint> endpoints) {
@@ -352,7 +352,7 @@ public class SessionPreparer {
}
/** The result of preparation over all model versions */
- private static class PrepareResult {
+ static class PrepareResult {
private final AllocatedHosts allocatedHosts;
private final ImmutableList<PreparedModelsBuilder.PreparedModelResult> results;
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
index 00e4005e771..98620877b1f 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
@@ -164,7 +164,8 @@ public class SessionRepository {
ConfigChangeActions actions = sessionPreparer.prepare(applicationRepo.getHostValidator(), logger, params,
currentActiveApplicationSet, tenantPath, now,
getSessionAppDir(sessionId),
- session.getApplicationPackage(), sessionZooKeeperClient);
+ session.getApplicationPackage(), sessionZooKeeperClient)
+ .getConfigChangeActions();
session.setPrepared();
waiter.awaitCompletion(params.getTimeoutBudget().timeLeft());
return actions;
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
index 906490ad8ba..1b9527f4376 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java
@@ -214,7 +214,7 @@ public class SessionZooKeeperClient {
}
public ZooKeeperDeployer createDeployer(DeployLogger logger) {
- ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, logger, true, sessionPath);
+ ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, logger, sessionPath);
return new ZooKeeperDeployer(zkClient);
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java
index 685856d5cf8..11cec9efd95 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java
@@ -93,8 +93,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
try {
return PreGeneratedFileRegistry.importRegistry(zkApplication.getDataReader(fileRegistryNode));
} catch (Exception e) {
- throw new RuntimeException("Could not determine which files to distribute. " +
- "Please try redeploying the application", e);
+ throw new RuntimeException("Could not determine which files to distribute", e);
}
}
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 e20fef0909c..f74378b32a9 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
@@ -121,14 +121,15 @@ public class ApplicationRepositoryTest {
public void setup(FlagSource flagSource) throws IOException {
Curator curator = new MockCurator();
configCurator = ConfigCurator.create(curator);
+ ConfigserverConfig configserverConfig = new ConfigserverConfig.Builder()
+ .payloadCompressionType(ConfigserverConfig.PayloadCompressionType.Enum.UNCOMPRESSED)
+ .configServerDBDir(temporaryFolder.newFolder().getAbsolutePath())
+ .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath())
+ .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath())
+ .build();
TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
.curator(curator)
- .configServerConfig(new ConfigserverConfig.Builder()
- .payloadCompressionType(ConfigserverConfig.PayloadCompressionType.Enum.UNCOMPRESSED)
- .configServerDBDir(temporaryFolder.newFolder().getAbsolutePath())
- .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath())
- .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath())
- .build())
+ .configServerConfig(configserverConfig)
.flagSource(flagSource)
.clock(clock)
.build();
@@ -142,7 +143,11 @@ public class ApplicationRepositoryTest {
applicationRepository = new ApplicationRepository(tenantRepository,
provisioner,
orchestrator,
- clock);
+ configserverConfig,
+ new MockLogRetriever(),
+ clock,
+ new MockTesterClient(),
+ new NullMetric());
timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60));
}
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 f03550c0a80..68dd5396cf1 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
@@ -51,7 +51,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry {
private final TenantListener tenantListener;
private final PermanentApplicationPackage permanentApplicationPackage;
private final HostRegistries hostRegistries;
- private final FileDistributionFactory fileDistributionProvider;
+ private final FileDistributionFactory fileDistributionFactory;
private final ModelFactoryRegistry modelFactoryRegistry;
private final Optional<Provisioner> hostProvisioner;
private final Zone zone;
@@ -65,7 +65,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry {
private TestComponentRegistry(Curator curator, ConfigCurator configCurator, Metrics metrics,
ModelFactoryRegistry modelFactoryRegistry,
PermanentApplicationPackage permanentApplicationPackage,
- FileDistributionFactory fileDistributionProvider,
+ FileDistributionFactory fileDistributionFactory,
HostRegistries hostRegistries,
ConfigserverConfig configserverConfig,
SessionPreparer sessionPreparer,
@@ -86,7 +86,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry {
this.defRepo = defRepo;
this.permanentApplicationPackage = permanentApplicationPackage;
this.hostRegistries = hostRegistries;
- this.fileDistributionProvider = fileDistributionProvider;
+ this.fileDistributionFactory = fileDistributionFactory;
this.modelFactoryRegistry = modelFactoryRegistry;
this.hostProvisioner = hostProvisioner;
this.sessionPreparer = sessionPreparer;
@@ -247,6 +247,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry {
return secretStore;
}
- public FileDistributionFactory getFileDistributionProvider() { return fileDistributionProvider; }
+ public FileDistributionFactory getFileDistributionFactory() { return fileDistributionFactory; }
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java
index 8394611737e..a4fce5e37ba 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java
@@ -53,7 +53,7 @@ public class ZooKeeperClientTest {
@Before
public void setupZK() throws IOException {
zk = ConfigCurator.create(new MockCurator());
- ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), true, Path.fromString(appPath));
+ ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), Path.fromString(appPath));
ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(new File("src/test/apps/zkfeed"),
new DeployData("foo",
"/bar/baz",
@@ -85,7 +85,7 @@ public class ZooKeeperClientTest {
ConfigCurator zk = ConfigCurator.create(new MockCurator());
BaseDeployLogger logger = new BaseDeployLogger();
long generation = 1L;
- ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, true, Path.fromString("/1"));
+ ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, Path.fromString("/1"));
zooKeeperClient.setupZooKeeper();
String appPath = "/";
assertThat(zk.getChildren(appPath).size(), is(1));
@@ -120,7 +120,7 @@ public class ZooKeeperClientTest {
ConfigCurator zk = ConfigCurator.create(new MockCurator());
BaseDeployLogger logger = new BaseDeployLogger();
Path app = Path.fromString("/1");
- ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, true, app);
+ ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, app);
zooKeeperClient.setupZooKeeper();
String currentAppPath = app.getAbsolute();
@@ -191,7 +191,7 @@ public class ZooKeeperClientTest {
ConfigCurator zk = ConfigCurator.create(new MockCurator());
BaseDeployLogger logger = new BaseDeployLogger();
Path app = Path.fromString("/1");
- ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, true, app);
+ ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, app);
zooKeeperClient.setupZooKeeper();
HostSpec host1 = new HostSpec("host1.yahoo.com", Collections.emptyList(), Optional.empty());
HostSpec host2 = new HostSpec("host2.yahoo.com", Collections.emptyList(), Optional.empty());
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java
index 4825ccc1328..641fbe5bf41 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java
@@ -48,7 +48,7 @@ public class ZooKeeperDeployerTest {
public void deploy(ApplicationPackage applicationPackage, ConfigCurator configCurator, Path appPath) throws IOException {
MockDeployLogger logger = new MockDeployLogger();
- ZooKeeperClient client = new ZooKeeperClient(configCurator, logger, true, appPath);
+ ZooKeeperClient client = new ZooKeeperClient(configCurator, logger, appPath);
ZooKeeperDeployer deployer = new ZooKeeperDeployer(client);
deployer.deploy(applicationPackage, Collections.singletonMap(new Version(1, 0, 0), new MockFileRegistry()), AllocatedHosts.withHosts(Collections.emptySet()));
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionFactory.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionFactory.java
index 78729156b93..af55dc6a90e 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionFactory.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionFactory.java
@@ -10,16 +10,13 @@ import java.io.File;
*/
public class MockFileDistributionFactory extends FileDistributionFactory {
- public final MockFileDistributionProvider mockFileDistributionProvider;
-
public MockFileDistributionFactory(ConfigserverConfig configserverConfig) {
super(configserverConfig);
- mockFileDistributionProvider = new MockFileDistributionProvider(new File(configserverConfig.fileReferencesDir()));
}
@Override
public com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider createProvider(File applicationFile) {
- return mockFileDistributionProvider;
+ return new MockFileDistributionProvider(applicationFile, new File(configserverConfig.fileReferencesDir()));
}
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java
new file mode 100644
index 00000000000..45e00e2ece8
--- /dev/null
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileDistributionProvider.java
@@ -0,0 +1,22 @@
+// Copyright Verizon Media. 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.config.model.api.FileDistribution;
+
+import java.io.File;
+
+/**
+ * @author hmusum
+ */
+public class MockFileDistributionProvider extends FileDistributionProvider {
+
+ public MockFileDistributionProvider(File applicationDir, File fileReferencesDir) {
+ super(new MockFileRegistry(applicationDir, fileReferencesDir.toPath()),
+ new MockFileDistribution(fileReferencesDir));
+ }
+
+ public FileDistribution getFileDistribution() {
+ return super.getFileDistribution();
+ }
+
+}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileRegistry.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileRegistry.java
new file mode 100644
index 00000000000..343e0c50520
--- /dev/null
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/MockFileRegistry.java
@@ -0,0 +1,49 @@
+// Copyright Verizon Media. 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.config.FileReference;
+import com.yahoo.config.application.api.FileRegistry;
+import com.yahoo.net.HostName;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A file registry for config server tests
+ *
+ * @author hmusum
+ */
+public class MockFileRegistry implements FileRegistry {
+
+ private final List<Entry> entries = new ArrayList<>();
+ private final AddFileInterface addFileInterface;
+
+ public MockFileRegistry(File applicationDir, Path rootPath) {
+ FileDirectory fileDirectory = new FileDirectory(rootPath.toFile());
+ this.addFileInterface = new ApplicationFileManager(applicationDir, fileDirectory);
+ }
+
+ public FileReference addFile(String relativePath) {
+ if (relativePath.isEmpty())
+ relativePath = "./";
+ addFileInterface.addFile(relativePath);
+
+ FileReference fileReference = new FileReference(relativePath);
+ entries.add(new Entry(relativePath, fileReference));
+ return fileReference;
+ }
+
+ @Override
+ public String fileSourceHost() { return HostName.getLocalhost(); }
+
+ public List<Entry> export() { return entries; }
+
+ @Override
+ public FileReference addUri(String uri) {
+ throw new IllegalArgumentException("FileReference addUri(String uri) is not implemented for " + getClass().getCanonicalName());
+ }
+
+}
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 496ded249fa..a2ef6aeb578 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
@@ -119,7 +119,7 @@ public class LocalSessionTest {
Optional<AllocatedHosts> allocatedHosts) throws Exception {
SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenant, sessionId, allocatedHosts);
zkc.createWriteStatusTransaction(Session.Status.NEW).commit();
- ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, new BaseDeployLogger(), false,
+ ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, new BaseDeployLogger(),
TenantRepository.getSessionsPath(tenant).append(String.valueOf(sessionId)));
if (allocatedHosts.isPresent()) {
zkClient.write(allocatedHosts.get());
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java
index 46b8754ebe0..7d1554c3e19 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.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.component.Version;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.model.api.ContainerEndpoint;
@@ -33,7 +34,6 @@ import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.TimeoutBudgetTest;
import com.yahoo.vespa.config.server.application.PermanentApplicationPackage;
import com.yahoo.vespa.config.server.deploy.DeployHandlerLogger;
-import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory;
import com.yahoo.vespa.config.server.host.HostRegistry;
import com.yahoo.vespa.config.server.http.InvalidApplicationException;
import com.yahoo.vespa.config.server.model.TestModelFactory;
@@ -59,7 +59,6 @@ import java.security.KeyPair;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -68,6 +67,7 @@ import java.util.Set;
import java.util.logging.Level;
import static com.yahoo.vespa.config.server.session.SessionZooKeeperClient.APPLICATION_PACKAGE_REFERENCE_PATH;
+import static com.yahoo.vespa.config.server.session.SessionPreparer.PrepareResult;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -85,27 +85,31 @@ public class SessionPreparerTest {
private static final File invalidTestApp = new File("src/test/apps/illegalApp");
private static final Version version123 = new Version(1, 2, 3);
private static final Version version321 = new Version(3, 2, 1);
- private KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
- private X509Certificate certificate = X509CertificateBuilder.fromKeypair(keyPair, new X500Principal("CN=subject"),
+ private final KeyPair keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
+ private final X509Certificate certificate = X509CertificateBuilder.fromKeypair(keyPair, new X500Principal("CN=subject"),
Instant.now(), Instant.now().plus(1, ChronoUnit.DAYS), SignatureAlgorithm.SHA512_WITH_ECDSA, BigInteger.valueOf(12345)).build();
-
private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
private MockCurator curator;
private ConfigCurator configCurator;
private SessionPreparer preparer;
private TestComponentRegistry componentRegistry;
- private MockFileDistributionFactory fileDistributionFactory;
- private MockSecretStore secretStore = new MockSecretStore();
+ private final MockSecretStore secretStore = new MockSecretStore();
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Before
- public void setUp() {
+ public void setUp() throws IOException {
curator = new MockCurator();
configCurator = ConfigCurator.create(curator);
- componentRegistry = new TestComponentRegistry.Builder().curator(curator).build();
- fileDistributionFactory = (MockFileDistributionFactory)componentRegistry.getFileDistributionProvider();
+ componentRegistry = new TestComponentRegistry.Builder()
+ .curator(curator)
+ .configServerConfig(new ConfigserverConfig.Builder()
+ .fileReferencesDir(folder.newFolder().getAbsolutePath())
+ .configServerDBDir(folder.newFolder().getAbsolutePath())
+ .configDefinitionsDir(folder.newFolder().getAbsolutePath())
+ .build())
+ .build();
preparer = createPreparer();
}
@@ -115,7 +119,7 @@ public class SessionPreparerTest {
private SessionPreparer createPreparer(HostProvisionerProvider hostProvisionerProvider) {
ModelFactoryRegistry modelFactoryRegistry =
- new ModelFactoryRegistry(Arrays.asList(new TestModelFactory(version123), new TestModelFactory(version321)));
+ new ModelFactoryRegistry(List.of(new TestModelFactory(version123), new TestModelFactory(version321)));
return createPreparer(modelFactoryRegistry, hostProvisionerProvider);
}
@@ -123,7 +127,7 @@ public class SessionPreparerTest {
HostProvisionerProvider hostProvisionerProvider) {
return new SessionPreparer(
modelFactoryRegistry,
- componentRegistry.getFileDistributionProvider(),
+ componentRegistry.getFileDistributionFactory(),
hostProvisionerProvider,
new PermanentApplicationPackage(componentRegistry.getConfigserverConfig()),
componentRegistry.getConfigserverConfig(),
@@ -152,14 +156,13 @@ public class SessionPreparerTest {
@Test
public void require_that_filedistribution_is_ignored_on_dryrun() throws IOException {
- prepare(testApp, new PrepareParams.Builder().dryRun(true).timeoutBudget(TimeoutBudgetTest.day()).build());
- assertThat(fileDistributionFactory.mockFileDistributionProvider.timesCalled, is(0));
+ PrepareResult result = prepare(testApp, new PrepareParams.Builder().dryRun(true).build());
+ assertTrue(result.getFileRegistries().get(version321).export().isEmpty());
}
@Test
public void require_that_application_is_prepared() throws Exception {
prepare(testApp);
- assertThat(fileDistributionFactory.mockFileDistributionProvider.timesCalled, is(1)); // Only builds the newest version
assertTrue(configCurator.exists(sessionsPath.append(ConfigCurator.USERAPP_ZK_SUBPATH).append("services.xml").getAbsolute()));
}
@@ -327,11 +330,11 @@ public class SessionPreparerTest {
prepare(app, new PrepareParams.Builder().build());
}
- private void prepare(File app, PrepareParams params) throws IOException {
+ private PrepareResult prepare(File app, PrepareParams params) throws IOException {
FilesApplicationPackage applicationPackage = getApplicationPackage(app);
- preparer.prepare(new HostRegistry<>(), getLogger(), params,
- Optional.empty(), tenantPath, Instant.now(), applicationPackage.getAppDir(),
- applicationPackage, new SessionZooKeeperClient(curator, sessionsPath));
+ return preparer.prepare(new HostRegistry<>(), getLogger(), params,
+ Optional.empty(), tenantPath, Instant.now(), applicationPackage.getAppDir(),
+ applicationPackage, new SessionZooKeeperClient(curator, sessionsPath));
}
private FilesApplicationPackage getApplicationPackage(File testFile) throws IOException {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionTest.java
index 5ae5910d827..7f38083797e 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionTest.java
@@ -3,17 +3,18 @@ package com.yahoo.vespa.config.server.session;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.config.provision.AllocatedHosts;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.path.Path;
import com.yahoo.vespa.config.server.application.ApplicationSet;
-import com.yahoo.vespa.config.server.configchange.ConfigChangeActions;
import com.yahoo.vespa.config.server.host.HostValidator;
import com.yahoo.vespa.curator.mock.MockCurator;
import java.io.File;
import java.time.Instant;
-import java.util.ArrayList;
+import java.util.List;
import java.util.Optional;
+import java.util.Set;
/**
* @author Ulf Lilleengen
@@ -28,12 +29,12 @@ public class SessionTest {
}
@Override
- public ConfigChangeActions prepare(HostValidator<ApplicationId> hostValidator, DeployLogger logger, PrepareParams params,
- Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath,
- Instant now, File serverDbSessionDir, ApplicationPackage applicationPackage,
- SessionZooKeeperClient sessionZooKeeperClient) {
+ public PrepareResult prepare(HostValidator<ApplicationId> hostValidator, DeployLogger logger, PrepareParams params,
+ Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath,
+ Instant now, File serverDbSessionDir, ApplicationPackage applicationPackage,
+ SessionZooKeeperClient sessionZooKeeperClient) {
isPrepared = true;
- return new ConfigChangeActions(new ArrayList<>());
+ return new PrepareResult(AllocatedHosts.withHosts(Set.of()), List.of());
}
}