From a0d7822978d83bebb173887da4bf30319f37f216 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Wed, 20 Jan 2021 09:21:45 +0100 Subject: Move secret store out of GlobalComponentRegistry --- .../vespa/config/server/GlobalComponentRegistry.java | 3 --- .../server/InjectedGlobalComponentRegistry.java | 11 +---------- .../server/modelfactory/ActivatedModelsBuilder.java | 5 +++-- .../config/server/session/SessionRepository.java | 11 +++++++---- .../vespa/config/server/tenant/TenantRepository.java | 17 ++++++++++++----- .../server/InjectedGlobalComponentRegistryTest.java | 3 +-- .../vespa/config/server/TestComponentRegistry.java | 14 ++------------ .../server/application/TenantApplicationsTest.java | 19 +++++-------------- .../vespa/config/server/deploy/DeployTester.java | 19 +++++++------------ .../config/server/tenant/TenantRepositoryTest.java | 4 +++- .../config/server/tenant/TestTenantRepository.java | 9 ++++++++- 11 files changed, 49 insertions(+), 66 deletions(-) (limited to 'configserver') 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 093898edc23..00fc346397d 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 @@ -5,13 +5,11 @@ import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.tenant.TenantListener; import java.time.Clock; import java.util.Optional; -import java.util.concurrent.ExecutorService; /** * Interface representing all global config server components used within the config server. @@ -29,5 +27,4 @@ public interface GlobalComponentRegistry { Zone getZone(); Clock getClock(); ConfigServerDB getConfigServerDB(); - 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 de681a32818..0b95c29249a 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 @@ -6,7 +6,6 @@ import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; import com.yahoo.vespa.config.server.rpc.RpcServer; @@ -29,7 +28,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry private final Optional hostProvisioner; private final Zone zone; private final ConfigServerDB configServerDB; - private final SecretStore secretStore; @SuppressWarnings("WeakerAccess") @Inject @@ -39,8 +37,7 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry ConfigDefinitionRepo staticConfigDefinitionRepo, HostProvisionerProvider hostProvisionerProvider, Zone zone, - ConfigServerDB configServerDB, - SecretStore secretStore) { + ConfigServerDB configServerDB) { this.modelFactoryRegistry = modelFactoryRegistry; this.rpcServer = rpcServer; this.configserverConfig = configserverConfig; @@ -48,7 +45,6 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry this.hostProvisioner = hostProvisionerProvider.getHostProvisioner(); this.zone = zone; this.configServerDB = configServerDB; - this.secretStore = secretStore; } @Override @@ -78,9 +74,4 @@ public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry @Override public ConfigServerDB getConfigServerDB() { return configServerDB; } - @Override - public SecretStore getSecretStore() { - return secretStore; - } - } 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 5682a9277f6..943f5658773 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 @@ -69,7 +69,8 @@ public class ActivatedModelsBuilder extends ModelsBuilder { Curator curator, Metrics metrics, PermanentApplicationPackage permanentApplicationPackage, - FlagSource flagSource) { + FlagSource flagSource, + SecretStore secretStore) { super(globalComponentRegistry.getModelFactoryRegistry(), globalComponentRegistry.getConfigserverConfig(), globalComponentRegistry.getZone(), @@ -83,7 +84,7 @@ public class ActivatedModelsBuilder extends ModelsBuilder { this.metrics = metrics; this.curator = curator; this.flagSource = flagSource; - this.secretStore = globalComponentRegistry.getSecretStore(); + this.secretStore = secretStore; } @Override 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 9a4a67b7750..e40a557a156 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 @@ -12,6 +12,7 @@ import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.io.IOUtils; import com.yahoo.lang.SettableOptional; import com.yahoo.path.Path; @@ -98,7 +99,7 @@ public class SessionRepository { private final GlobalComponentRegistry componentRegistry; private final ConfigCurator configCurator; private final SessionCounter sessionCounter; - private final ExecutorService zkCacheExecutor; + private final SecretStore secretStore; public SessionRepository(TenantName tenantName, GlobalComponentRegistry componentRegistry, @@ -109,7 +110,8 @@ public class SessionRepository { StripedExecutor zkWatcherExecutor, PermanentApplicationPackage permanentApplicationPackage, FlagSource flagSource, - ExecutorService zkCacheExecutor) { + ExecutorService zkCacheExecutor, + SecretStore secretStore) { this.tenantName = tenantName; this.componentRegistry = componentRegistry; this.configCurator = ConfigCurator.create(curator); @@ -126,7 +128,7 @@ public class SessionRepository { this.sessionPreparer = sessionPreparer; this.metrics = metrics; this.metricUpdater = metrics.getOrCreateMetricUpdater(Metrics.createDimensions(tenantName)); - this.zkCacheExecutor = zkCacheExecutor; + this.secretStore = secretStore; loadSessions(); // Needs to be done before creating cache below this.directoryCache = curator.createDirectoryCache(sessionsPath.getAbsolute(), false, false, zkCacheExecutor); @@ -450,7 +452,8 @@ public class SessionRepository { curator, metrics, permanentApplicationPackage, - flagSource); + flagSource, + secretStore); // Read hosts allocated on the config server instance which created this SettableOptional allocatedHosts = new SettableOptional<>(applicationPackage.getAllocatedHosts()); 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 edfd78f63b7..97320698200 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 @@ -9,6 +9,7 @@ import com.yahoo.concurrent.StripedExecutor; import com.yahoo.concurrent.ThreadFactoryFactory; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; +import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.path.Path; import com.yahoo.text.Utf8; import com.yahoo.transaction.Transaction; @@ -95,6 +96,7 @@ public class TenantRepository { private final StripedExecutor zkWatcherExecutor; private final FileDistributionFactory fileDistributionFactory; private final FlagSource flagSource; + private final SecretStore secretStore; private final ExecutorService bootstrapExecutor; private final ScheduledExecutorService checkForRemovedApplicationsService = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("check for removed applications")); @@ -110,7 +112,8 @@ public class TenantRepository { HostRegistry hostRegistry, Curator curator, Metrics metrics, - FlagSource flagSource) { + FlagSource flagSource, + SecretStore secretStore) { this(componentRegistry, hostRegistry, curator, @@ -118,7 +121,8 @@ public class TenantRepository { new StripedExecutor<>(), new FileDistributionFactory(componentRegistry.getConfigserverConfig()), flagSource, - Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName()))); + Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName())), + secretStore); } public TenantRepository(GlobalComponentRegistry componentRegistry, @@ -128,7 +132,8 @@ public class TenantRepository { StripedExecutor zkWatcherExecutor, FileDistributionFactory fileDistributionFactory, FlagSource flagSource, - ExecutorService zkCacheExecutor) { + ExecutorService zkCacheExecutor, + SecretStore secretStore) { this.componentRegistry = componentRegistry; this.hostRegistry = hostRegistry; ConfigserverConfig configserverConfig = componentRegistry.getConfigserverConfig(); @@ -142,6 +147,7 @@ public class TenantRepository { this.zkWatcherExecutor = zkWatcherExecutor; this.fileDistributionFactory = fileDistributionFactory; this.flagSource = flagSource; + this.secretStore = secretStore; curator.framework().getConnectionStateListenable().addListener(this::stateChanged); @@ -279,7 +285,7 @@ public class TenantRepository { curator, componentRegistry.getZone(), flagSource, - componentRegistry.getSecretStore()); + secretStore); SessionRepository sessionRepository = new SessionRepository(tenantName, componentRegistry, applicationRepo, @@ -289,7 +295,8 @@ public class TenantRepository { zkWatcherExecutor, permanentApplicationPackage, flagSource, - zkCacheExecutor); + zkCacheExecutor, + secretStore); 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/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistryTest.java index 9f59a059f9f..a651f947136 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 @@ -64,8 +64,7 @@ public class InjectedGlobalComponentRegistryTest { defRepo, hostProvisionerProvider, zone, - new ConfigServerDB(configserverConfig), - new MockSecretStore()); + new ConfigServerDB(configserverConfig)); } @Test 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 3681444b719..c2571fbf224 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 @@ -6,7 +6,6 @@ import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.Zone; -import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.vespa.config.server.application.TenantApplicationsTest; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.tenant.MockTenantListener; @@ -34,7 +33,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { private final Zone zone; private final Clock clock; private final ConfigServerDB configServerDB; - private final SecretStore secretStore; private TestComponentRegistry(ModelFactoryRegistry modelFactoryRegistry, ConfigserverConfig configserverConfig, @@ -43,8 +41,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { ReloadListener reloadListener, TenantListener tenantListener, Zone zone, - Clock clock, - SecretStore secretStore) { + Clock clock) { this.configserverConfig = configserverConfig; this.reloadListener = reloadListener; this.tenantListener = tenantListener; @@ -54,7 +51,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { this.zone = zone; this.clock = clock; this.configServerDB = new ConfigServerDB(configserverConfig); - this.secretStore = secretStore; } public static class Builder { @@ -107,7 +103,6 @@ public class TestComponentRegistry implements GlobalComponentRegistry { } public TestComponentRegistry build() { - SecretStore secretStore = new MockSecretStore(); return new TestComponentRegistry(modelFactoryRegistry, configserverConfig, hostProvisioner, @@ -115,8 +110,7 @@ public class TestComponentRegistry implements GlobalComponentRegistry { reloadListener, tenantListener, zone, - clock, - secretStore); + clock); } } @@ -142,9 +136,5 @@ public class TestComponentRegistry implements GlobalComponentRegistry { public Clock getClock() { return clock;} @Override public ConfigServerDB getConfigServerDB() { return configServerDB;} - @Override - public SecretStore getSecretStore() { - return secretStore; - } } 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 c385dcd37ef..732c9385608 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 @@ -3,8 +3,6 @@ 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; @@ -14,16 +12,14 @@ 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.config.server.tenant.TestTenantRepository; 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; @@ -83,15 +79,10 @@ public class TenantApplicationsTest { .reloadListener(listener) .build(); HostRegistry hostRegistry = new HostRegistry(); - InThreadExecutorService zkCacheExecutor = new InThreadExecutorService(); - TenantRepository tenantRepository = new TenantRepository(componentRegistry, - hostRegistry, - curator, - Metrics.createTestMetrics(), - new StripedExecutor<>(new InThreadExecutorService()), - new MockFileDistributionFactory(configserverConfig), - new InMemoryFlagSource(), - zkCacheExecutor); + TenantRepository tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(componentRegistry) + .withCurator(curator) + .build(); tenantRepository.addTenant(TenantRepository.HOSTED_VESPA_TENANT); tenantRepository.addTenant(tenantName); applications = TenantApplications.create(componentRegistry, hostRegistry, tenantName, curator); 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 19552d3e2d0..9e21bcc315d 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,8 +3,6 @@ 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; @@ -29,7 +27,6 @@ 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; import com.yahoo.vespa.config.server.monitoring.Metrics; @@ -37,9 +34,9 @@ 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 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; @@ -292,14 +289,12 @@ public class DeployTester { .zone(zone); if (configserverConfig.hostedVespa()) testComponentRegistryBuilder.provisioner(provisioner); - TenantRepository tenantRepository = new TenantRepository(testComponentRegistryBuilder.build(), - new HostRegistry(), - curator, - Optional.ofNullable(metrics).orElseGet(Metrics::createTestMetrics), - new StripedExecutor<>(new InThreadExecutorService()), - new MockFileDistributionFactory(configserverConfig), - new InMemoryFlagSource(), - new InThreadExecutorService()); + TenantRepository tenantRepository = new TestTenantRepository.Builder() + .withComponentRegistry(testComponentRegistryBuilder.build()) + .withCurator(curator) + .withMetrics(Optional.ofNullable(metrics).orElse(Metrics.createTestMetrics())) + .withFileDistributionFactory(new MockFileDistributionFactory(configserverConfig)) + .build(); tenantRepository.addTenant(tenantName); ApplicationRepository applicationRepository = new ApplicationRepository.Builder() 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 8d2c37e98c0..ab6b50dce2b 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 @@ -15,6 +15,7 @@ import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.server.GlobalComponentRegistry; +import com.yahoo.vespa.config.server.MockSecretStore; import com.yahoo.vespa.config.server.ServerCache; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.Application; @@ -213,7 +214,8 @@ public class TenantRepositoryTest { new StripedExecutor<>(new InThreadExecutorService()), new FileDistributionFactory(new ConfigserverConfig.Builder().build()), new InMemoryFlagSource(), - new InThreadExecutorService()); + new InThreadExecutorService(), + new MockSecretStore()); } @Override 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 index 2a3e2dad265..0faae9762fa 100644 --- 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 @@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server.tenant; import com.yahoo.concurrent.InThreadExecutorService; import com.yahoo.concurrent.StripedExecutor; import com.yahoo.vespa.config.server.GlobalComponentRegistry; +import com.yahoo.vespa.config.server.MockSecretStore; import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.monitoring.Metrics; @@ -31,7 +32,8 @@ public class TestTenantRepository extends TenantRepository { new StripedExecutor<>(new InThreadExecutorService()), fileDistributionFactory, flagSource, - new InThreadExecutorService()); + new InThreadExecutorService(), + new MockSecretStore()); } public static class Builder { @@ -64,6 +66,11 @@ public class TestTenantRepository extends TenantRepository { return this; } + public Builder withMetrics(Metrics metrics) { + this.metrics = metrics; + return this; + } + public Builder withFileDistributionFactory(FileDistributionFactory fileDistributionFactory) { this.fileDistributionFactory = fileDistributionFactory; return this; -- cgit v1.2.3