diff options
Diffstat (limited to 'configserver')
36 files changed, 364 insertions, 336 deletions
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 49a61eb8dee..da114e89f00 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 @@ -2,21 +2,12 @@ package com.yahoo.vespa.config.server; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; -import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; -import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; -import com.yahoo.vespa.config.server.monitoring.Metrics; -import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.tenant.TenantListener; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; -import com.yahoo.vespa.curator.Curator; -import com.yahoo.vespa.flags.FlagSource; import java.time.Clock; import java.util.Optional; @@ -29,22 +20,15 @@ import java.util.concurrent.ExecutorService; */ public interface GlobalComponentRegistry { - Curator getCurator(); - ConfigCurator getConfigCurator(); - Metrics getMetrics(); - SessionPreparer getSessionPreparer(); ConfigserverConfig getConfigserverConfig(); TenantListener getTenantListener(); ReloadListener getReloadListener(); ConfigDefinitionRepo getStaticConfigDefinitionRepo(); - PermanentApplicationPackage getPermanentApplicationPackage(); ModelFactoryRegistry getModelFactoryRegistry(); Optional<Provisioner> getHostProvisioner(); Zone getZone(); Clock getClock(); ConfigServerDB getConfigServerDB(); - StripedExecutor<TenantName> getZkWatcherExecutor(); - FlagSource getFlagSource(); ExecutorService getZkCacheExecutor(); SecretStore getSecretStore(); } 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 5760eae866c..dbd477c0b93 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 @@ -3,25 +3,16 @@ package com.yahoo.vespa.config.server; import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.concurrent.StripedExecutor; import com.yahoo.concurrent.ThreadFactoryFactory; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; -import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; -import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; -import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.rpc.RpcServer; -import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.tenant.TenantListener; import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; -import com.yahoo.vespa.curator.Curator; -import com.yahoo.vespa.flags.FlagSource; import java.time.Clock; import java.util.Optional; @@ -35,69 +26,38 @@ import java.util.concurrent.Executors; */ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry { - private final Curator curator; - private final ConfigCurator configCurator; - private final Metrics metrics; private final ModelFactoryRegistry modelFactoryRegistry; - private final SessionPreparer sessionPreparer; private final RpcServer rpcServer; private final ConfigserverConfig configserverConfig; private final ConfigDefinitionRepo staticConfigDefinitionRepo; - private final PermanentApplicationPackage permanentApplicationPackage; private final Optional<Provisioner> hostProvisioner; private final Zone zone; private final ConfigServerDB configServerDB; - private final FlagSource flagSource; private final SecretStore secretStore; - private final StripedExecutor<TenantName> zkWatcherExecutor; private final ExecutorService zkCacheExecutor; - private final HostRegistry hostRegistry; @SuppressWarnings("WeakerAccess") @Inject - public InjectedGlobalComponentRegistry(Curator curator, - ConfigCurator configCurator, - Metrics metrics, - ModelFactoryRegistry modelFactoryRegistry, - SessionPreparer sessionPreparer, + public InjectedGlobalComponentRegistry(ModelFactoryRegistry modelFactoryRegistry, RpcServer rpcServer, ConfigserverConfig configserverConfig, ConfigDefinitionRepo staticConfigDefinitionRepo, - PermanentApplicationPackage permanentApplicationPackage, HostProvisionerProvider hostProvisionerProvider, Zone zone, ConfigServerDB configServerDB, - FlagSource flagSource, - SecretStore secretStore, - HostRegistry hostRegistry) { - this.curator = curator; - this.configCurator = configCurator; - this.metrics = metrics; + SecretStore secretStore) { this.modelFactoryRegistry = modelFactoryRegistry; - this.sessionPreparer = sessionPreparer; this.rpcServer = rpcServer; this.configserverConfig = configserverConfig; this.staticConfigDefinitionRepo = staticConfigDefinitionRepo; - this.permanentApplicationPackage = permanentApplicationPackage; this.hostProvisioner = hostProvisionerProvider.getHostProvisioner(); this.zone = zone; this.configServerDB = configServerDB; - this.flagSource = flagSource; this.secretStore = secretStore; - this.zkWatcherExecutor = new StripedExecutor<>(); this.zkCacheExecutor = Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName())); - this.hostRegistry = hostRegistry; } @Override - public Curator getCurator() { return curator; } - @Override - public ConfigCurator getConfigCurator() { return configCurator; } - @Override - public Metrics getMetrics() { return metrics; } - @Override - public SessionPreparer getSessionPreparer() { return sessionPreparer; } - @Override public ConfigserverConfig getConfigserverConfig() { return configserverConfig; } @Override public TenantListener getTenantListener() { return rpcServer; } @@ -106,8 +66,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry @Override public ConfigDefinitionRepo getStaticConfigDefinitionRepo() { return staticConfigDefinitionRepo; } @Override - public PermanentApplicationPackage getPermanentApplicationPackage() { return permanentApplicationPackage; } - @Override public ModelFactoryRegistry getModelFactoryRegistry() { return modelFactoryRegistry; } @Override @@ -127,14 +85,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry public ConfigServerDB getConfigServerDB() { return configServerDB; } @Override - public StripedExecutor<TenantName> getZkWatcherExecutor() { - return zkWatcherExecutor; - } - - @Override - public FlagSource getFlagSource() { return flagSource; } - - @Override public ExecutorService getZkCacheExecutor() { return zkCacheExecutor; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java index c4908b8827b..3d979ebd3b8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.config.server.application; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; +import com.yahoo.concurrent.InThreadExecutorService; import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.FileReference; import com.yahoo.config.provision.ApplicationId; @@ -87,12 +88,15 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica } // For testing only - public static TenantApplications create(GlobalComponentRegistry componentRegistry, HostRegistry hostRegistry, TenantName tenantName) { + public static TenantApplications create(GlobalComponentRegistry componentRegistry, + HostRegistry hostRegistry, + TenantName tenantName, + Curator curator) { return new TenantApplications(tenantName, - componentRegistry.getCurator(), - componentRegistry.getZkWatcherExecutor(), + curator, + new StripedExecutor<>(new InThreadExecutorService()), componentRegistry.getZkCacheExecutor(), - componentRegistry.getMetrics(), + Metrics.createTestMetrics(), componentRegistry.getReloadListener(), componentRegistry.getConfigserverConfig(), hostRegistry, diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java index 997ea32ff0b..8eb9c66150f 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java @@ -230,7 +230,7 @@ public class ModelContextImpl implements ModelContext { private final Optional<ApplicationRoles> applicationRoles; private final Quota quota; - private final String jvmGCOPtions; + private final String jvmGcOptions; public Properties(ApplicationId applicationId, ConfigserverConfig configserverConfig, @@ -260,7 +260,7 @@ public class ModelContextImpl implements ModelContext { this.applicationRoles = applicationRoles; this.quota = maybeQuota.orElseGet(Quota::unlimited); - jvmGCOPtions = flagValue(flagSource, applicationId, PermanentFlags.JVM_GC_OPTIONS); + jvmGcOptions = flagValue(flagSource, applicationId, PermanentFlags.JVM_GC_OPTIONS); } @Override public ModelContext.FeatureFlags featureFlags() { return featureFlags; } @@ -315,7 +315,7 @@ public class ModelContextImpl implements ModelContext { @Override public Quota quota() { return quota; } - @Override public String jvmGCOptions() { return jvmGCOPtions; } + @Override public String jvmGCOptions() { return jvmGcOptions; } private static <V> V flagValue(FlagSource source, ApplicationId appId, UnboundFlag<? extends V, ?, ?> flag) { return flag.bindTo(source) diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java index fa058514d17..5682a9277f6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java @@ -65,7 +65,11 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { long applicationGeneration, SessionZooKeeperClient zkClient, Optional<ApplicationSet> currentActiveApplicationSet, - GlobalComponentRegistry globalComponentRegistry) { + GlobalComponentRegistry globalComponentRegistry, + Curator curator, + Metrics metrics, + PermanentApplicationPackage permanentApplicationPackage, + FlagSource flagSource) { super(globalComponentRegistry.getModelFactoryRegistry(), globalComponentRegistry.getConfigserverConfig(), globalComponentRegistry.getZone(), @@ -74,11 +78,11 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { this.applicationGeneration = applicationGeneration; this.zkClient = zkClient; this.currentActiveApplicationSet = currentActiveApplicationSet; - this.permanentApplicationPackage = globalComponentRegistry.getPermanentApplicationPackage(); + this.permanentApplicationPackage = permanentApplicationPackage; this.configDefinitionRepo = globalComponentRegistry.getStaticConfigDefinitionRepo(); - this.metrics = globalComponentRegistry.getMetrics(); - this.curator = globalComponentRegistry.getCurator(); - this.flagSource = globalComponentRegistry.getFlagSource(); + this.metrics = metrics; + this.curator = curator; + this.flagSource = flagSource; this.secretStore = globalComponentRegistry.getSecretStore(); } 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 5609de68391..c244274c49f 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 @@ -2,7 +2,6 @@ package com.yahoo.vespa.config.server.session; import com.google.common.util.concurrent.UncheckedTimeoutException; -import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; import com.yahoo.component.Vtag; @@ -80,7 +79,6 @@ public class SessionPreparer { private final SecretStore secretStore; private final FlagSource flagSource; - @Inject public SessionPreparer(ModelFactoryRegistry modelFactoryRegistry, FileDistributionFactory fileDistributionFactory, HostProvisionerProvider hostProvisionerProvider, 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 592198cbbef..51a1b6f9d57 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 @@ -3,6 +3,7 @@ package com.yahoo.vespa.config.server.session; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; +import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.FileReference; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; @@ -20,6 +21,7 @@ import com.yahoo.transaction.Transaction; import com.yahoo.vespa.config.server.GlobalComponentRegistry; import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.application.ApplicationSet; +import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.configchange.ConfigChangeActions; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; @@ -32,6 +34,7 @@ import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.config.server.zookeeper.SessionCounter; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.defaults.Defaults; +import com.yahoo.vespa.flags.FlagSource; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; @@ -81,32 +84,45 @@ public class SessionRepository { private final Clock clock; private final Curator curator; private final Executor zkWatcherExecutor; + private final PermanentApplicationPackage permanentApplicationPackage; + private final FlagSource flagSource; private final TenantFileSystemDirs tenantFileSystemDirs; - private final MetricUpdater metrics; + private final Metrics metrics; + private final MetricUpdater metricUpdater; private final Curator.DirectoryCache directoryCache; private final TenantApplications applicationRepo; private final SessionPreparer sessionPreparer; private final Path sessionsPath; private final TenantName tenantName; private final GlobalComponentRegistry componentRegistry; + private final ConfigCurator configCurator; private final SessionCounter sessionCounter; public SessionRepository(TenantName tenantName, GlobalComponentRegistry componentRegistry, TenantApplications applicationRepo, - SessionPreparer sessionPreparer) { + SessionPreparer sessionPreparer, + Curator curator, + Metrics metrics, + StripedExecutor<TenantName> zkWatcherExecutor, + PermanentApplicationPackage permanentApplicationPackage, + FlagSource flagSource) { this.tenantName = tenantName; this.componentRegistry = componentRegistry; - sessionCounter = new SessionCounter(componentRegistry.getConfigCurator(), tenantName); + this.configCurator = ConfigCurator.create(curator); + sessionCounter = new SessionCounter(configCurator, tenantName); this.sessionsPath = TenantRepository.getSessionsPath(tenantName); this.clock = componentRegistry.getClock(); - this.curator = componentRegistry.getCurator(); + this.curator = curator; this.sessionLifetime = Duration.ofSeconds(componentRegistry.getConfigserverConfig().sessionLifetime()); - this.zkWatcherExecutor = command -> componentRegistry.getZkWatcherExecutor().execute(tenantName, command); + this.zkWatcherExecutor = command -> zkWatcherExecutor.execute(tenantName, command); + this.permanentApplicationPackage = permanentApplicationPackage; + this.flagSource = flagSource; this.tenantFileSystemDirs = new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName); this.applicationRepo = applicationRepo; this.sessionPreparer = sessionPreparer; - this.metrics = componentRegistry.getMetrics().getOrCreateMetricUpdater(Metrics.createDimensions(tenantName)); + this.metrics = metrics; + this.metricUpdater = metrics.getOrCreateMetricUpdater(Metrics.createDimensions(tenantName)); loadSessions(); // Needs to be done before creating cache below this.directoryCache = curator.createDirectoryCache(sessionsPath.getAbsolute(), false, false, componentRegistry.getZkCacheExecutor()); this.directoryCache.addListener(this::childEvent); @@ -348,7 +364,7 @@ public class SessionRepository { SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId); if (watcher != null) watcher.close(); remoteSessionCache.remove(sessionId); - metrics.incRemovedSessions(); + metricUpdater.incRemovedSessions(); } private void loadSessionIfActive(RemoteSession session) { @@ -425,7 +441,11 @@ public class SessionRepository { session.getSessionId(), sessionZooKeeperClient, previousApplicationSet, - componentRegistry); + componentRegistry, + curator, + metrics, + permanentApplicationPackage, + flagSource); // Read hosts allocated on the config server instance which created this SettableOptional<AllocatedHosts> allocatedHosts = new SettableOptional<>(applicationPackage.getAllocatedHosts()); @@ -443,10 +463,10 @@ public class SessionRepository { for (Session session : remoteSessionCache.values()) { sessionMetrics.add(session.getStatus()); } - metrics.setNewSessions(sessionMetrics.count(Session.Status.NEW)); - metrics.setPreparedSessions(sessionMetrics.count(Session.Status.PREPARE)); - metrics.setActivatedSessions(sessionMetrics.count(Session.Status.ACTIVATE)); - metrics.setDeactivatedSessions(sessionMetrics.count(Session.Status.DEACTIVATE)); + metricUpdater.setNewSessions(sessionMetrics.count(Session.Status.NEW)); + metricUpdater.setPreparedSessions(sessionMetrics.count(Session.Status.PREPARE)); + metricUpdater.setActivatedSessions(sessionMetrics.count(Session.Status.ACTIVATE)); + metricUpdater.setDeactivatedSessions(sessionMetrics.count(Session.Status.DEACTIVATE)); }); } @@ -507,7 +527,7 @@ public class SessionRepository { private void ensureSessionPathDoesNotExist(long sessionId) { Path sessionPath = getSessionPath(sessionId); - if (componentRegistry.getConfigCurator().exists(sessionPath.getAbsolute())) { + if (configCurator.exists(sessionPath.getAbsolute())) { throw new IllegalArgumentException("Path " + sessionPath.getAbsolute() + " already exists in ZooKeeper"); } } @@ -677,7 +697,7 @@ public class SessionRepository { private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) { String serverId = componentRegistry.getConfigserverConfig().serverId(); - return new SessionZooKeeperClient(curator, componentRegistry.getConfigCurator(), tenantName, sessionId, serverId); + return new SessionZooKeeperClient(curator, configCurator, tenantName, sessionId, serverId); } private File getAndValidateExistingSessionAppDir(long sessionId) { @@ -697,7 +717,7 @@ public class SessionRepository { if (sessionStateWatcher == null) { Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false); fileCache.addListener(this::nodeChanged); - sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metrics, zkWatcherExecutor, this)); + sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metricUpdater, zkWatcherExecutor, this)); } else { sessionStateWatcher.updateRemoteSession(remoteSession); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java index ce382e8698e..76fb7d29a43 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java @@ -12,14 +12,20 @@ import com.yahoo.path.Path; import com.yahoo.text.Utf8; import com.yahoo.transaction.Transaction; import com.yahoo.vespa.config.server.GlobalComponentRegistry; +import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; +import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; +import com.yahoo.vespa.config.server.monitoring.Metrics; +import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; +import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.session.SessionRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.transaction.CuratorOperations; import com.yahoo.vespa.curator.transaction.CuratorTransaction; +import com.yahoo.vespa.flags.FlagSource; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; import org.apache.curator.framework.state.ConnectionState; @@ -82,10 +88,12 @@ public class TenantRepository { private final HostRegistry hostRegistry; private final List<TenantListener> tenantListeners = Collections.synchronizedList(new ArrayList<>()); private final Curator curator; - + private final Metrics metrics; private final MetricUpdater metricUpdater; private final ExecutorService zkCacheExecutor; private final StripedExecutor<TenantName> zkWatcherExecutor; + private final FileDistributionFactory fileDistributionFactory; + private final FlagSource flagSource; private final ExecutorService bootstrapExecutor; private final ScheduledExecutorService checkForRemovedApplicationsService = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("check for removed applications")); @@ -97,17 +105,41 @@ public class TenantRepository { * @param componentRegistry a {@link com.yahoo.vespa.config.server.GlobalComponentRegistry} */ @Inject - public TenantRepository(GlobalComponentRegistry componentRegistry, HostRegistry hostRegistry) { + public TenantRepository(GlobalComponentRegistry componentRegistry, + HostRegistry hostRegistry, + Curator curator, + Metrics metrics, + FlagSource flagSource) { + this(componentRegistry, + hostRegistry, + curator, + metrics, + new StripedExecutor<>(), + new FileDistributionFactory(componentRegistry.getConfigserverConfig()), + flagSource); + } + + public TenantRepository(GlobalComponentRegistry componentRegistry, + HostRegistry hostRegistry, + Curator curator, + Metrics metrics, + StripedExecutor<TenantName> zkWatcherExecutor, + FileDistributionFactory fileDistributionFactory, + FlagSource flagSource) { this.componentRegistry = componentRegistry; this.hostRegistry = hostRegistry; ConfigserverConfig configserverConfig = componentRegistry.getConfigserverConfig(); this.bootstrapExecutor = Executors.newFixedThreadPool(configserverConfig.numParallelTenantLoaders(), new DaemonThreadFactory("bootstrap tenants")); - this.curator = componentRegistry.getCurator(); - metricUpdater = componentRegistry.getMetrics().getOrCreateMetricUpdater(Collections.emptyMap()); + this.curator = curator; + this.metrics = metrics; + metricUpdater = metrics.getOrCreateMetricUpdater(Collections.emptyMap()); this.tenantListeners.add(componentRegistry.getTenantListener()); this.zkCacheExecutor = componentRegistry.getZkCacheExecutor(); - this.zkWatcherExecutor = componentRegistry.getZkWatcherExecutor(); + this.zkWatcherExecutor = zkWatcherExecutor; + this.fileDistributionFactory = fileDistributionFactory; + this.flagSource = flagSource; + curator.framework().getConnectionStateListenable().addListener(this::stateChanged); curator.create(tenantsPath); @@ -226,18 +258,34 @@ public class TenantRepository { TenantApplications applicationRepo = new TenantApplications(tenantName, curator, - componentRegistry.getZkWatcherExecutor(), + zkWatcherExecutor, componentRegistry.getZkCacheExecutor(), - componentRegistry.getMetrics(), + metrics, componentRegistry.getReloadListener(), componentRegistry.getConfigserverConfig(), hostRegistry, new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName), componentRegistry.getClock()); + PermanentApplicationPackage permanentApplicationPackage = new PermanentApplicationPackage(componentRegistry.getConfigserverConfig()); + SessionPreparer sessionPreparer = new SessionPreparer(componentRegistry.getModelFactoryRegistry(), + fileDistributionFactory, + HostProvisionerProvider.from(componentRegistry.getHostProvisioner()), + permanentApplicationPackage, + componentRegistry.getConfigserverConfig(), + componentRegistry.getStaticConfigDefinitionRepo(), + curator, + componentRegistry.getZone(), + flagSource, + componentRegistry.getSecretStore()); SessionRepository sessionRepository = new SessionRepository(tenantName, componentRegistry, applicationRepo, - componentRegistry.getSessionPreparer()); + sessionPreparer, + curator, + metrics, + zkWatcherExecutor, + permanentApplicationPackage, + flagSource); log.log(Level.INFO, "Adding tenant '" + tenantName + "'" + ", created " + created); Tenant tenant = new Tenant(tenantName, sessionRepository, applicationRepo, applicationRepo, created); notifyNewTenant(tenant); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java index 20ac4b65c64..24553704862 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java @@ -239,11 +239,11 @@ public class ConfigCurator { curator.framework().checkExists().forPath("/dummy"); } catch (Exception e) { - log.log(Level.SEVERE, "Unable to contact ZooKeeper on " + curator.connectionSpec() + - ". Please verify for all configserver nodes that " + - "VESPA_CONFIGSERVERS points to the correct configserver(s), " + - "the same configserver(s) as in services.xml, and that they are started. " + - "Check the log(s) for configserver errors. Aborting.", e); + log.log(Level.SEVERE, "Unable to connect to ZooKeeper on " + curator.connectionSpec() + + ". Please verify that VESPA_CONFIGSERVERS points to the correct configserver(s) " + + "on all config server nodes and are the same config server(s) as in services.xml, " + + "and that they are started. " + + "Check the log(s) for config server errors. Aborting.", e); } } diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml index 00c65644e47..d301dffdf40 100644 --- a/configserver/src/main/resources/configserver-app/services.xml +++ b/configserver/src/main/resources/configserver-app/services.xml @@ -18,7 +18,6 @@ <component id="com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.SuperModelGenerationCounter" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.SuperModelManager" bundle="configserver" /> - <component id="com.yahoo.vespa.config.server.session.SessionPreparer" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.SuperModelRequestHandler" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.StaticConfigDefinitionRepo" bundle="configserver" /> <component id="com.yahoo.vespa.config.server.provision.HostProvisionerProvider" bundle="configserver" /> 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 b45569c95b8..36e1698d69f 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 @@ -32,7 +32,7 @@ import com.yahoo.vespa.config.protocol.VespaVersion; import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.deploy.DeployTester; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; -import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; import com.yahoo.vespa.config.server.http.v2.PrepareResult; import com.yahoo.vespa.config.server.session.LocalSession; import com.yahoo.vespa.config.server.session.PrepareParams; @@ -42,6 +42,7 @@ import com.yahoo.vespa.config.server.session.SessionZooKeeperClient; import com.yahoo.vespa.config.server.tenant.ApplicationRolesStore; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.config.util.ConfigUtils; import com.yahoo.vespa.curator.Curator; @@ -121,14 +122,17 @@ public class ApplicationRepositoryTest { .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath()) .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) .build(); - InMemoryFlagSource flagSource = new InMemoryFlagSource(); TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder() - .curator(curator) .configServerConfig(configserverConfig) - .flagSource(flagSource) .clock(clock) .build(); - tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + InMemoryFlagSource flagSource = new InMemoryFlagSource(); + tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(componentRegistry) + .withCurator(curator) + .withFileDistributionFactory(new MockFileDistributionFactory(configserverConfig)) + .withFlagSource(flagSource) + .build(); tenantRepository.addTenant(TenantRepository.HOSTED_VESPA_TENANT); tenantRepository.addTenant(tenant1); tenantRepository.addTenant(tenant2); 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 4f6642610dd..9f59a059f9f 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 @@ -5,7 +5,6 @@ import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Zone; -import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.filedistribution.FileServer; import com.yahoo.vespa.config.server.host.ConfigRequestHostLivenessTracker; import com.yahoo.vespa.config.server.host.HostRegistry; @@ -15,12 +14,6 @@ import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.rpc.RpcRequestHandlerProvider; import com.yahoo.vespa.config.server.rpc.RpcServer; import com.yahoo.vespa.config.server.rpc.security.NoopRpcAuthorizer; -import com.yahoo.vespa.config.server.session.SessionPreparer; -import com.yahoo.vespa.config.server.session.SessionTest; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; -import com.yahoo.vespa.curator.Curator; -import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.model.VespaModelFactory; import org.junit.Before; import org.junit.Rule; @@ -28,7 +21,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import java.io.IOException; -import java.util.Collections; +import java.util.List; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -39,13 +32,9 @@ import static org.junit.Assert.assertTrue; */ public class InjectedGlobalComponentRegistryTest { - private Curator curator; - private Metrics metrics; - private SessionPreparer sessionPreparer; private ConfigserverConfig configserverConfig; private RpcServer rpcServer; private ConfigDefinitionRepo defRepo; - private PermanentApplicationPackage permanentApplicationPackage; private GlobalComponentRegistry globalComponentRegistry; private ModelFactoryRegistry modelFactoryRegistry; private Zone zone; @@ -55,44 +44,38 @@ public class InjectedGlobalComponentRegistryTest { @Before 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()))); + modelFactoryRegistry = new ModelFactoryRegistry(List.of(new VespaModelFactory(new NullConfigModelRegistry()))); configserverConfig = new ConfigserverConfig( new ConfigserverConfig.Builder() .configServerDBDir(temporaryFolder.newFolder("serverdb").getAbsolutePath()) .configDefinitionsDir(temporaryFolder.newFolder("configdefinitions").getAbsolutePath())); - sessionPreparer = new SessionTest.MockSessionPreparer(); HostRegistry hostRegistry = new HostRegistry(); rpcServer = new RpcServer(configserverConfig, null, Metrics.createTestMetrics(), hostRegistry, new ConfigRequestHostLivenessTracker(), new FileServer(temporaryFolder.newFolder("filereferences")), new NoopRpcAuthorizer(), new RpcRequestHandlerProvider()); defRepo = new StaticConfigDefinitionRepo(); - permanentApplicationPackage = new PermanentApplicationPackage(configserverConfig); HostProvisionerProvider hostProvisionerProvider = HostProvisionerProvider.withProvisioner(new MockProvisioner()); zone = Zone.defaultZone(); globalComponentRegistry = - new InjectedGlobalComponentRegistry(curator, configCurator, metrics, modelFactoryRegistry, sessionPreparer, - rpcServer, configserverConfig, defRepo, permanentApplicationPackage, - hostProvisionerProvider, zone, - new ConfigServerDB(configserverConfig), new InMemoryFlagSource(), - new MockSecretStore(), hostRegistry); + new InjectedGlobalComponentRegistry(modelFactoryRegistry, + rpcServer, + configserverConfig, + defRepo, + hostProvisionerProvider, + zone, + new ConfigServerDB(configserverConfig), + new MockSecretStore()); } @Test public void testThatAllComponentsAreSetup() { assertThat(globalComponentRegistry.getModelFactoryRegistry(), is(modelFactoryRegistry)); - assertThat(globalComponentRegistry.getSessionPreparer(), is(sessionPreparer)); - assertThat(globalComponentRegistry.getMetrics(), is(metrics)); - assertThat(globalComponentRegistry.getCurator(), is(curator)); assertThat(globalComponentRegistry.getConfigserverConfig(), is(configserverConfig)); assertThat(globalComponentRegistry.getReloadListener().hashCode(), is(rpcServer.hashCode())); assertThat(globalComponentRegistry.getTenantListener().hashCode(), is(rpcServer.hashCode())); assertThat(globalComponentRegistry.getStaticConfigDefinitionRepo(), is(defRepo)); - assertThat(globalComponentRegistry.getPermanentApplicationPackage(), is(permanentApplicationPackage)); - assertThat(globalComponentRegistry.getZone(), is (zone)); + assertThat(globalComponentRegistry.getZone(), is(zone)); assertTrue(globalComponentRegistry.getHostProvisioner().isPresent()); } 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 0221cf9abfc..38310e5b20d 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 @@ -3,29 +3,15 @@ package com.yahoo.vespa.config.server; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.concurrent.InThreadExecutorService; -import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; -import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; -import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.config.server.application.TenantApplicationsTest; -import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; -import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; -import com.yahoo.vespa.config.server.monitoring.Metrics; -import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; -import com.yahoo.vespa.config.server.session.SessionPreparer; import com.yahoo.vespa.config.server.tenant.MockTenantListener; import com.yahoo.vespa.config.server.tenant.TenantListener; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; -import com.yahoo.vespa.curator.Curator; -import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.flags.FlagSource; -import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.model.VespaModelFactory; import java.nio.file.Files; @@ -41,65 +27,41 @@ import static com.yahoo.yolean.Exceptions.uncheck; */ public class TestComponentRegistry implements GlobalComponentRegistry { - private final Curator curator; - private final ConfigCurator configCurator; - private final Metrics metrics; - private final SessionPreparer sessionPreparer; private final ConfigserverConfig configserverConfig; private final ConfigDefinitionRepo defRepo; private final ReloadListener reloadListener; private final TenantListener tenantListener; - private final PermanentApplicationPackage permanentApplicationPackage; - private final FileDistributionFactory fileDistributionFactory; private final ModelFactoryRegistry modelFactoryRegistry; private final Optional<Provisioner> hostProvisioner; private final Zone zone; private final Clock clock; private final ConfigServerDB configServerDB; - private final StripedExecutor<TenantName> zkWatcherExecutor; private final ExecutorService zkCacheExecutor; private final SecretStore secretStore; - private final FlagSource flagSource; - private TestComponentRegistry(Curator curator, ConfigCurator configCurator, Metrics metrics, - ModelFactoryRegistry modelFactoryRegistry, - PermanentApplicationPackage permanentApplicationPackage, - FileDistributionFactory fileDistributionFactory, + private TestComponentRegistry(ModelFactoryRegistry modelFactoryRegistry, ConfigserverConfig configserverConfig, - SessionPreparer sessionPreparer, Optional<Provisioner> hostProvisioner, ConfigDefinitionRepo defRepo, ReloadListener reloadListener, TenantListener tenantListener, Zone zone, Clock clock, - SecretStore secretStore, - FlagSource flagSource) { - this.curator = curator; - this.configCurator = configCurator; - this.metrics = metrics; + SecretStore secretStore) { this.configserverConfig = configserverConfig; this.reloadListener = reloadListener; this.tenantListener = tenantListener; this.defRepo = defRepo; - this.permanentApplicationPackage = permanentApplicationPackage; - this.fileDistributionFactory = fileDistributionFactory; this.modelFactoryRegistry = modelFactoryRegistry; this.hostProvisioner = hostProvisioner; - this.sessionPreparer = sessionPreparer; this.zone = zone; this.clock = clock; this.configServerDB = new ConfigServerDB(configserverConfig); - this.zkWatcherExecutor = new StripedExecutor<>(new InThreadExecutorService()); this.zkCacheExecutor = new InThreadExecutorService(); this.secretStore = secretStore; - this.flagSource = flagSource; } public static class Builder { - - private Curator curator = new MockCurator(); - private Metrics metrics = Metrics.createTestMetrics(); private ConfigserverConfig configserverConfig = new ConfigserverConfig( new ConfigserverConfig.Builder() .configServerDBDir(uncheck(() -> Files.createTempDirectory("serverdb")).toString()) @@ -108,39 +70,21 @@ public class TestComponentRegistry implements GlobalComponentRegistry { private ConfigDefinitionRepo defRepo = new StaticConfigDefinitionRepo(); private ReloadListener reloadListener = new TenantApplicationsTest.MockReloadListener(); private final MockTenantListener tenantListener = new MockTenantListener(); - private Optional<PermanentApplicationPackage> permanentApplicationPackage = Optional.empty(); - private final Optional<FileDistributionFactory> fileDistributionFactory = Optional.empty(); private ModelFactoryRegistry modelFactoryRegistry = new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))); private Optional<Provisioner> hostProvisioner = Optional.empty(); private Zone zone = Zone.defaultZone(); private Clock clock = Clock.systemUTC(); - private FlagSource flagSource = new InMemoryFlagSource(); public Builder configServerConfig(ConfigserverConfig configserverConfig) { this.configserverConfig = configserverConfig; return this; } - public Builder curator(Curator curator) { - this.curator = curator; - return this; - } - - public Builder metrics(Metrics metrics) { - this.metrics = metrics; - return this; - } - public Builder modelFactoryRegistry(ModelFactoryRegistry modelFactoryRegistry) { this.modelFactoryRegistry = modelFactoryRegistry; return this; } - public Builder permanentApplicationPackage(PermanentApplicationPackage permanentApplicationPackage) { - this.permanentApplicationPackage = Optional.ofNullable(permanentApplicationPackage); - return this; - } - public Builder provisioner(Provisioner provisioner) { this.hostProvisioner = Optional.ofNullable(provisioner); return this; @@ -161,44 +105,26 @@ public class TestComponentRegistry implements GlobalComponentRegistry { return this; } - public Builder flagSource(FlagSource flagSource) { - this.flagSource = flagSource; - return this; - } - public Builder configDefinitionRepo(ConfigDefinitionRepo configDefinitionRepo) { this.defRepo = configDefinitionRepo; return this; } public TestComponentRegistry build() { - final PermanentApplicationPackage permApp = this.permanentApplicationPackage - .orElse(new PermanentApplicationPackage(configserverConfig)); - FileDistributionFactory fileDistributionProvider = this.fileDistributionFactory - .orElse(new MockFileDistributionFactory(configserverConfig)); - HostProvisionerProvider hostProvisionerProvider = hostProvisioner. - map(HostProvisionerProvider::withProvisioner).orElseGet(HostProvisionerProvider::empty); SecretStore secretStore = new MockSecretStore(); - SessionPreparer sessionPreparer = new SessionPreparer(modelFactoryRegistry, fileDistributionProvider, - hostProvisionerProvider, permApp, - configserverConfig, defRepo, curator, - zone, flagSource, secretStore); - return new TestComponentRegistry(curator, ConfigCurator.create(curator), metrics, modelFactoryRegistry, - permApp, fileDistributionProvider, configserverConfig, - sessionPreparer, hostProvisioner, defRepo, reloadListener, tenantListener, - zone, clock, secretStore, flagSource); + return new TestComponentRegistry(modelFactoryRegistry, + configserverConfig, + hostProvisioner, + defRepo, + reloadListener, + tenantListener, + zone, + clock, + secretStore); } } @Override - public Curator getCurator() { return curator; } - @Override - public ConfigCurator getConfigCurator() { return configCurator; } - @Override - public Metrics getMetrics() { return metrics; } - @Override - public SessionPreparer getSessionPreparer() { return sessionPreparer; } - @Override public ConfigserverConfig getConfigserverConfig() { return configserverConfig; } @Override public TenantListener getTenantListener() { return tenantListener; } @@ -207,8 +133,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { @Override public ConfigDefinitionRepo getStaticConfigDefinitionRepo() { return defRepo; } @Override - public PermanentApplicationPackage getPermanentApplicationPackage() { return permanentApplicationPackage; } - @Override public ModelFactoryRegistry getModelFactoryRegistry() { return modelFactoryRegistry; } @Override public Optional<Provisioner> getHostProvisioner() { @@ -222,25 +146,13 @@ public class TestComponentRegistry implements GlobalComponentRegistry { public Clock getClock() { return clock;} @Override public ConfigServerDB getConfigServerDB() { return configServerDB;} - - @Override - public StripedExecutor<TenantName> getZkWatcherExecutor() { - return zkWatcherExecutor; - } - - @Override - public FlagSource getFlagSource() { return flagSource; } - @Override public ExecutorService getZkCacheExecutor() { return zkCacheExecutor; } - @Override public SecretStore getSecretStore() { return secretStore; } - public FileDistributionFactory getFileDistributionFactory() { return fileDistributionFactory; } - } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java index 4543d3b5673..61db4e96c92 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/TenantApplicationsTest.java @@ -1,8 +1,10 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// 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.application; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; +import com.yahoo.concurrent.InThreadExecutorService; +import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.ApplicationId; @@ -12,13 +14,16 @@ import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.server.ReloadListener; import com.yahoo.vespa.config.server.ServerCache; import com.yahoo.vespa.config.server.TestComponentRegistry; +import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.model.TestModelFactory; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; +import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.VespaModelFactory; import org.apache.curator.framework.CuratorFramework; @@ -55,6 +60,7 @@ public class TenantApplicationsTest { private static final Version vespaVersion = new VespaModelFactory(new NullConfigModelRegistry()).version(); private final MockReloadListener listener = new MockReloadListener(); + private Curator curator; private CuratorFramework curatorFramework; private TestComponentRegistry componentRegistry; private TenantApplications applications; @@ -64,23 +70,29 @@ public class TenantApplicationsTest { @Before public void setup() throws IOException { - Curator curator = new MockCurator(); + curator = new MockCurator(); curatorFramework = curator.framework(); + ConfigserverConfig configserverConfig = new ConfigserverConfig.Builder() + .payloadCompressionType(ConfigserverConfig.PayloadCompressionType.Enum.UNCOMPRESSED) + .configServerDBDir(tempFolder.newFolder("configserverdb").getAbsolutePath()) + .configDefinitionsDir(tempFolder.newFolder("configdefinitions").getAbsolutePath()) + .build(); componentRegistry = new TestComponentRegistry.Builder() - .curator(curator) - .configServerConfig(new ConfigserverConfig.Builder() - .payloadCompressionType(ConfigserverConfig.PayloadCompressionType.Enum.UNCOMPRESSED) - .configServerDBDir(tempFolder.newFolder("configserverdb").getAbsolutePath()) - .configDefinitionsDir(tempFolder.newFolder("configdefinitions").getAbsolutePath()) - .build()) + .configServerConfig(configserverConfig) .modelFactoryRegistry(createRegistry()) .reloadListener(listener) .build(); HostRegistry hostRegistry = new HostRegistry(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, hostRegistry); + TenantRepository tenantRepository = new TenantRepository(componentRegistry, + hostRegistry, + curator, + Metrics.createTestMetrics(), + new StripedExecutor<>(new InThreadExecutorService()), + new MockFileDistributionFactory(configserverConfig), + new InMemoryFlagSource()); tenantRepository.addTenant(TenantRepository.HOSTED_VESPA_TENANT); tenantRepository.addTenant(tenantName); - applications = TenantApplications.create(componentRegistry, hostRegistry, tenantName); + applications = TenantApplications.create(componentRegistry, hostRegistry, tenantName, curator); } @Test @@ -173,7 +185,7 @@ public class TenantApplicationsTest { @Test public void testListConfigs() throws IOException, SAXException { - applications = TenantApplications.create(componentRegistry, new HostRegistry(), TenantName.defaultName()); + applications = TenantApplications.create(componentRegistry, new HostRegistry(), TenantName.defaultName(), new MockCurator()); assertdefaultAppNotFound(); VespaModel model = new VespaModel(FilesApplicationPackage.fromFile(new File("src/test/apps/app"))); @@ -208,7 +220,7 @@ public class TenantApplicationsTest { } private TenantApplications createZKAppRepo() { - return TenantApplications.create(componentRegistry, new HostRegistry(), tenantName); + return TenantApplications.create(componentRegistry, new HostRegistry(), tenantName, curator); } private static ApplicationId createApplicationId(String name) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java index 54d23652349..bc668f8f1a1 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java @@ -3,6 +3,8 @@ package com.yahoo.vespa.config.server.deploy; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; +import com.yahoo.concurrent.InThreadExecutorService; +import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.ConfigModelRegistry; import com.yahoo.config.model.NullConfigModelRegistry; @@ -26,6 +28,7 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.application.OrchestratorMock; +import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.v2.PrepareResult; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; @@ -36,6 +39,7 @@ import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.VespaModelFactory; import com.yahoo.vespa.orchestrator.Orchestrator; @@ -263,7 +267,7 @@ public class DeployTester { private Provisioner provisioner; private ConfigserverConfig configserverConfig; private Zone zone; - private Curator curator; + private Curator curator = new MockCurator(); private Metrics metrics; private List<ModelFactory> modelFactories; private Orchestrator orchestrator; @@ -284,13 +288,17 @@ public class DeployTester { TestComponentRegistry.Builder testComponentRegistryBuilder = new TestComponentRegistry.Builder() .clock(clock) .configServerConfig(configserverConfig) - .curator(Optional.ofNullable(curator).orElseGet(MockCurator::new)) .modelFactoryRegistry(new ModelFactoryRegistry(modelFactories)) - .metrics(Optional.ofNullable(metrics).orElseGet(Metrics::createTestMetrics)) .zone(zone); if (configserverConfig.hostedVespa()) testComponentRegistryBuilder.provisioner(provisioner); - TenantRepository tenantRepository = new TenantRepository(testComponentRegistryBuilder.build(), new HostRegistry()); + TenantRepository tenantRepository = new TenantRepository(testComponentRegistryBuilder.build(), + new HostRegistry(), + curator, + Optional.ofNullable(metrics).orElseGet(Metrics::createTestMetrics), + new StripedExecutor<>(new InThreadExecutorService()), + new MockFileDistributionFactory(configserverConfig), + new InMemoryFlagSource()); tenantRepository.addTenant(tenantName); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java index 6c5e25d0503..3631922f844 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java @@ -11,9 +11,9 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TestConfigDefinitionRepo; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -59,7 +59,7 @@ public class HttpGetConfigHandlerTest { .configDefinitionRepo(new TestConfigDefinitionRepo()) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenant); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpListConfigsHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpListConfigsHandlerTest.java index b55b250fc1c..cdf89eda367 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpListConfigsHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpListConfigsHandlerTest.java @@ -12,10 +12,10 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TestConfigDefinitionRepo; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HttpListConfigsHandler.ListConfigsResponse; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -64,7 +64,7 @@ public class HttpListConfigsHandlerTest { .configDefinitionRepo(new TestConfigDefinitionRepo()) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenant); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java index 06bac6497a2..02129a1b5cd 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java @@ -12,12 +12,12 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.Session; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -63,7 +63,7 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { .build(); Clock clock = componentRegistry.getClock(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenantName1); tenantRepository.addTenant(tenantName2); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index 293219eade3..05b09fb4204 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -26,7 +26,7 @@ import com.yahoo.vespa.config.server.application.ClusterReindexing.Status; import com.yahoo.vespa.config.server.application.HttpProxy; import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.deploy.DeployTester; -import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SessionHandlerTest; @@ -37,6 +37,7 @@ import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -114,7 +115,10 @@ public class ApplicationHandlerTest { .configServerConfig(configserverConfig) .clock(clock) .build(); - tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(componentRegistry) + .withFileDistributionFactory(new MockFileDistributionFactory(configserverConfig)) + .build(); tenantRepository.addTenant(mytenantName); provisioner = new MockProvisioner(); orchestrator = new OrchestratorMock(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java index 6ef1a0b63cd..671faa42f7b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java @@ -14,11 +14,11 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -57,7 +57,7 @@ public class HostHandlerTest { .zone(zone) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(mytenant); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java index 68cd474412f..80ff70120c1 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java @@ -13,13 +13,13 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TestConfigDefinitionRepo; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpConfigRequest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -67,7 +67,7 @@ public class HttpGetConfigHandlerTest { .configDefinitionRepo(new TestConfigDefinitionRepo()) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenant); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java index 985a88ceed2..cf04c8df56c 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java @@ -21,6 +21,7 @@ import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.v2.HttpListConfigsHandler.ListConfigsResponse; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -71,7 +72,7 @@ public class HttpListConfigsHandlerTest { .configDefinitionRepo(new TestConfigDefinitionRepo()) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenant); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java index 232243c2b74..e3930c2784d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java @@ -12,9 +12,9 @@ import com.yahoo.jdisc.Response; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.TenantApplications; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Test; @@ -42,7 +42,7 @@ public class ListApplicationsHandlerTest { @Before public void setup() { - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(mytenant); tenantRepository.addTenant(foobar); applicationRepo = tenantRepository.getTenant(mytenant).getApplicationRepo(); 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 8e9ef42352c..24176d17c38 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 @@ -15,7 +15,6 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.model.TestModelFactory; @@ -24,7 +23,7 @@ import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.session.Session; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.model.VespaModelFactory; import org.hamcrest.core.Is; import org.junit.Before; @@ -76,11 +75,10 @@ public class SessionActiveHandlerTest { .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) .build(); componentRegistry = new TestComponentRegistry.Builder() - .curator(new MockCurator()) .modelFactoryRegistry(new ModelFactoryRegistry(List.of((modelFactory)))) .configServerConfig(configserverConfig) .build(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenantName); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java index ce086cbfb15..867dbdfe65a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java @@ -14,12 +14,12 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; @@ -61,7 +61,7 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { .configServerConfig(configserverConfig) .build(); - tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); tenantRepository.addTenant(tenantName); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java index 7efd448c3ed..56afe1e4a08 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java @@ -11,11 +11,11 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.CompressedApplicationInputStreamTest; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.session.Session; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -63,7 +63,7 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { @Before public void setupRepo() { - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) .withProvisioner(new MockProvisioner()) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java index ed65d8294b8..b87f24cf06d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java @@ -19,11 +19,11 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SessionHandler; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; @@ -77,12 +77,14 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) .build(); componentRegistry = new TestComponentRegistry.Builder() - .curator(curator) .configServerConfig(configserverConfig) .build(); Clock clock = componentRegistry.getClock(); timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(10)); - tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(componentRegistry) + .withCurator(curator) + .build(); tenantRepository.addTenant(tenant); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java index a8cc989c802..d9f5f094023 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java @@ -1,40 +1,41 @@ // 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.http.v2; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; +import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.http.BadRequestException; +import com.yahoo.vespa.config.server.http.NotFoundException; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.jdisc.http.HttpRequest.Method; -import com.yahoo.vespa.config.server.http.BadRequestException; -import com.yahoo.vespa.config.server.http.NotFoundException; import org.junit.rules.TemporaryFolder; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + public class TenantHandlerTest { private static final File testApp = new File("src/test/apps/app"); @@ -54,12 +55,10 @@ public class TenantHandlerTest { .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath()) .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) .build(); - tenantRepository = new TenantRepository(new TestComponentRegistry.Builder() - .curator(new MockCurator()) - .configServerConfig(configserverConfig) - .build(), - new HostRegistry()); - + TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder() + .configServerConfig(configserverConfig) + .build(); + tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) .withProvisioner(new MockProvisioner()) diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/MaintainerTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/MaintainerTester.java index 1d8f60bb683..2803747bb59 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/MaintainerTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/MaintainerTester.java @@ -11,10 +11,10 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.OrchestratorMock; import com.yahoo.vespa.config.server.deploy.DeployTester; -import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.session.PrepareParams; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.rules.TemporaryFolder; @@ -41,13 +41,12 @@ class MaintainerTester { .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) .build(); GlobalComponentRegistry componentRegistry = new TestComponentRegistry.Builder() - .curator(curator) .clock(clock) .configServerConfig(configserverConfig) .provisioner(provisioner) .modelFactoryRegistry(new ModelFactoryRegistry(List.of(new DeployTester.CountingModelFactory(clock)))) .build(); - tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) .withProvisioner(provisioner) 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 5a41eff3cc9..55a6572ce3b 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 @@ -25,10 +25,8 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.ServerCache; import com.yahoo.vespa.config.server.application.Application; import com.yahoo.vespa.config.server.application.ApplicationSet; -import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; import com.yahoo.vespa.config.server.session.PrepareParams; -import com.yahoo.vespa.config.server.session.RemoteSession; import com.yahoo.vespa.model.VespaModel; import org.junit.Rule; import org.junit.Test; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java index 06c224b5a09..ffc60d01732 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/RpcTester.java @@ -28,6 +28,7 @@ import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.config.server.rpc.security.NoopRpcAuthorizer; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.flags.InMemoryFlagSource; import org.junit.After; import org.junit.rules.TemporaryFolder; @@ -90,7 +91,10 @@ public class RpcTester implements AutoCloseable { .configServerConfig(configserverConfig) .reloadListener(rpcServer) .build(); - tenantRepository = new TenantRepository(componentRegistry, hostRegistry); + tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(componentRegistry) + .withHostRegistry(hostRegistry) + .build(); tenantRepository.addTenant(tenantName); startRpcServer(); applicationRepository = new ApplicationRepository.Builder() 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 90d3bddc88d..3c44d304de5 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 @@ -27,6 +27,7 @@ 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; @@ -100,7 +101,6 @@ public class SessionPreparerTest { curator = new MockCurator(); configCurator = ConfigCurator.create(curator); componentRegistry = new TestComponentRegistry.Builder() - .curator(curator) .configServerConfig(new ConfigserverConfig.Builder() .fileReferencesDir(folder.newFolder().getAbsolutePath()) .configServerDBDir(folder.newFolder().getAbsolutePath()) @@ -124,7 +124,7 @@ public class SessionPreparerTest { HostProvisionerProvider hostProvisionerProvider) { return new SessionPreparer( modelFactoryRegistry, - componentRegistry.getFileDistributionFactory(), + new MockFileDistributionFactory(componentRegistry.getConfigserverConfig()), hostProvisionerProvider, new PermanentApplicationPackage(componentRegistry.getConfigserverConfig()), componentRegistry.getConfigserverConfig(), diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java index b2cfd7015ba..0ca04d51107 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java @@ -20,10 +20,11 @@ import com.yahoo.vespa.config.server.MockProvisioner; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.application.OrchestratorMock; -import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.filedistribution.MockFileDistributionFactory; import com.yahoo.vespa.config.server.http.InvalidApplicationException; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.config.server.tenant.TestTenantRepository; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.config.util.ConfigUtils; import com.yahoo.vespa.curator.Curator; @@ -82,22 +83,26 @@ public class SessionRepositoryTest { private void setup(FlagSource flagSource, TestComponentRegistry.Builder componentRegistryBuilder) throws Exception { curator = new MockCurator(); File configserverDbDir = temporaryFolder.newFolder().getAbsoluteFile(); + ConfigserverConfig configserverConfig = new ConfigserverConfig.Builder() + .configServerDBDir(configserverDbDir.getAbsolutePath()) + .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath()) + .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) + .sessionLifetime(5) + .build(); GlobalComponentRegistry globalComponentRegistry = componentRegistryBuilder - .curator(curator) - .configServerConfig(new ConfigserverConfig.Builder() - .configServerDBDir(configserverDbDir.getAbsolutePath()) - .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath()) - .fileReferencesDir(temporaryFolder.newFolder().getAbsolutePath()) - .sessionLifetime(5) - .build()) - .flagSource(flagSource) + .configServerConfig(configserverConfig) + .build(); + tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(globalComponentRegistry) + .withCurator(curator) + .withFileDistributionFactory(new MockFileDistributionFactory(configserverConfig)) .build(); - tenantRepository = new TenantRepository(globalComponentRegistry, new HostRegistry()); tenantRepository.addTenant(SessionRepositoryTest.tenantName); applicationRepository = new ApplicationRepository.Builder() .withTenantRepository(tenantRepository) .withProvisioner(new MockProvisioner()) .withOrchestrator(new OrchestratorMock()) + .withFlagSource(flagSource) .build(); sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository(); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java index dbc352128f5..6c5415416e7 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java @@ -1,8 +1,10 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// 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.tenant; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; +import com.yahoo.concurrent.InThreadExecutorService; +import com.yahoo.concurrent.StripedExecutor; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationName; @@ -19,10 +21,13 @@ import com.yahoo.vespa.config.server.application.Application; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.application.TenantApplicationsTest; +import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; +import com.yahoo.vespa.config.server.monitoring.Metrics; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.model.VespaModel; import org.junit.After; import org.junit.Before; @@ -49,7 +54,6 @@ public class TenantRepositoryTest { private static final TenantName tenant3 = TenantName.from("tenant3"); private TenantRepository tenantRepository; - private TestComponentRegistry globalComponentRegistry; private TenantApplicationsTest.MockReloadListener listener; private MockTenantListener tenantListener; private Curator curator; @@ -63,11 +67,13 @@ public class TenantRepositoryTest { @Before public void setupSessions() { curator = new MockCurator(); - globalComponentRegistry = new TestComponentRegistry.Builder().curator(curator).build(); - listener = (TenantApplicationsTest.MockReloadListener)globalComponentRegistry.getReloadListener(); - tenantListener = (MockTenantListener)globalComponentRegistry.getTenantListener(); + TestComponentRegistry globalComponentRegistry = new TestComponentRegistry.Builder().build(); + listener = (TenantApplicationsTest.MockReloadListener) globalComponentRegistry.getReloadListener(); + tenantListener = (MockTenantListener) globalComponentRegistry.getTenantListener(); assertFalse(tenantListener.tenantsLoaded); - tenantRepository = new TenantRepository(globalComponentRegistry, new HostRegistry()); + tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(globalComponentRegistry) + .withCurator(curator) + .build(); assertTrue(tenantListener.tenantsLoaded); tenantRepository.addTenant(tenant1); tenantRepository.addTenant(tenant2); @@ -185,13 +191,11 @@ public class TenantRepositoryTest { } private void assertZooKeeperTenantPathExists(TenantName tenantName) throws Exception { - assertNotNull(globalComponentRegistry.getCurator().framework() - .checkExists().forPath(TenantRepository.getTenantPath(tenantName).getAbsolute())); + assertNotNull(curator.framework().checkExists().forPath(TenantRepository.getTenantPath(tenantName).getAbsolute())); } private GlobalComponentRegistry createComponentRegistry() throws IOException { return new TestComponentRegistry.Builder() - .curator(new MockCurator()) .configServerConfig(new ConfigserverConfig(new ConfigserverConfig.Builder() .configDefinitionsDir(temporaryFolder.newFolder("configdefs").getAbsolutePath()) .configServerDBDir(temporaryFolder.newFolder("configserverdb").getAbsolutePath()))) @@ -201,8 +205,14 @@ public class TenantRepositoryTest { private static class FailingDuringBootstrapTenantRepository extends TenantRepository { - public FailingDuringBootstrapTenantRepository(GlobalComponentRegistry globalComponentRegistry) { - super(globalComponentRegistry, new HostRegistry()); + public FailingDuringBootstrapTenantRepository(GlobalComponentRegistry componentRegistry) { + super(componentRegistry, + new HostRegistry(), + new MockCurator(), + Metrics.createTestMetrics(), + new StripedExecutor<>(new InThreadExecutorService()), + new FileDistributionFactory(new ConfigserverConfig.Builder().build()), + new InMemoryFlagSource()); } @Override diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java index 1b754ca6695..75d1b848f50 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java @@ -33,7 +33,7 @@ public class TenantTest { } private Tenant createTenant(String name) { - TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry()); + TenantRepository tenantRepository = new TestTenantRepository.Builder().withComponentRegistry(componentRegistry).build(); TenantName tenantName = TenantName.from(name); tenantRepository.addTenant(tenantName); return tenantRepository.getTenant(tenantName); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java new file mode 100644 index 00000000000..2c9c35f65e1 --- /dev/null +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TestTenantRepository.java @@ -0,0 +1,82 @@ +// 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.tenant; + +import com.yahoo.concurrent.InThreadExecutorService; +import com.yahoo.concurrent.StripedExecutor; +import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.config.server.GlobalComponentRegistry; +import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; +import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.monitoring.Metrics; +import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.curator.mock.MockCurator; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.InMemoryFlagSource; + +/** + * + * @author hmusum + */ +public class TestTenantRepository extends TenantRepository { + + public TestTenantRepository(GlobalComponentRegistry componentRegistry, + HostRegistry hostRegistry, + Curator curator, + Metrics metrics, + StripedExecutor<TenantName> zkWatcherExecutor, + FileDistributionFactory fileDistributionFactory, + FlagSource flagSource) { + super(componentRegistry, hostRegistry, curator, metrics, zkWatcherExecutor, fileDistributionFactory, flagSource); + } + + public static class Builder { + + GlobalComponentRegistry componentRegistry; + HostRegistry hostRegistry = new HostRegistry(); + Curator curator = new MockCurator(); + Metrics metrics = Metrics.createTestMetrics(); + StripedExecutor<TenantName> zkWatcherExecutor = new StripedExecutor<>(new InThreadExecutorService()); + FileDistributionFactory fileDistributionFactory = null; + FlagSource flagSource = new InMemoryFlagSource(); + + + public Builder withFlagSource(FlagSource flagSource) { + this.flagSource = flagSource; + return this; + } + + public Builder withComponentRegistry(GlobalComponentRegistry componentRegistry) { + this.componentRegistry = componentRegistry; + return this; + } + + public Builder withHostRegistry(HostRegistry hostRegistry) { + this.hostRegistry = hostRegistry; + return this; + } + + public Builder withCurator(Curator curator) { + this.curator = curator; + return this; + } + + public Builder withFileDistributionFactory(FileDistributionFactory fileDistributionFactory) { + this.fileDistributionFactory = fileDistributionFactory; + return this; + } + + public TenantRepository build() { + if (fileDistributionFactory == null) + fileDistributionFactory = new FileDistributionFactory(componentRegistry.getConfigserverConfig()); + return new TestTenantRepository(componentRegistry, + hostRegistry, + curator, + metrics, + zkWatcherExecutor, + fileDistributionFactory, + flagSource); + } + + } + +} |