diff options
author | gjoranv <gv@verizonmedia.com> | 2020-07-03 13:39:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-03 13:39:19 +0200 |
commit | 566d9a7d5cf2df8e3a0746522c5f0936977a3b8f (patch) | |
tree | f129e31d5607205f09708c0b3e811e71c72a5b7c /configserver | |
parent | bff64708d76b80ec125fa44c3c70df93b97ff22a (diff) | |
parent | b29fb812be8cde17bb88dff266899eaa76535959 (diff) |
Merge pull request #13795 from vespa-engine/hmusum/configserver-refactoring-21
Config server refactoring, part 21
Diffstat (limited to 'configserver')
13 files changed, 31 insertions, 87 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadHandler.java deleted file mode 100644 index 93af4b1d593..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.config.server.application.ApplicationSet; - -import java.util.Set; - -/** - * Interface representing a reload handler. - * - * @author Ulf Lilleengen - */ -public interface ReloadHandler { - - /** - * Reload config with the one contained in the application. - * - * @param applicationSet The set of applications to set as active. - */ - void reloadConfig(ApplicationSet applicationSet); - - /** - * Remove an application and resources related to it. - * - * @param applicationId to be removed - */ - void removeApplication(ApplicationId applicationId); - - /** - * Remove all applications except those specified in argument. - * - * @param applicationIds to be kept - */ - void removeApplicationsExcept(Set<ApplicationId> applicationIds); - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelController.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelController.java index 23baac3d02e..73ee23e5c03 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelController.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelController.java @@ -3,7 +3,6 @@ package com.yahoo.vespa.config.server; import com.yahoo.config.ConfigInstance; import com.yahoo.config.codegen.DefParser; -import com.yahoo.config.codegen.InnerCNode; import com.yahoo.config.model.api.ConfigDefinitionRepo; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.ConfigDefinitionKey; @@ -47,22 +46,21 @@ public class SuperModelController { */ public ConfigResponse resolveConfig(GetConfigRequest request) { ConfigKey<?> configKey = request.getConfigKey(); - InnerCNode targetDef = getConfigDefinition(request.getConfigKey(), request.getDefContent()); + validateConfigDefinition(request.getConfigKey(), request.getDefContent()); ConfigPayload payload = model.getConfig(configKey); - return responseFactory.createResponse(payload, targetDef, generation, false); + return responseFactory.createResponse(payload, generation, false); } - private InnerCNode getConfigDefinition(ConfigKey<?> configKey, DefContent defContent) { + private void validateConfigDefinition(ConfigKey<?> configKey, DefContent defContent) { if (defContent.isEmpty()) { ConfigDefinitionKey configDefinitionKey = new ConfigDefinitionKey(configKey.getName(), configKey.getNamespace()); ConfigDefinition configDefinition = configDefinitionRepo.getConfigDefinitions().get(configDefinitionKey); if (configDefinition == null) { throw new UnknownConfigDefinitionException("Unable to find config definition for '" + configKey.getNamespace() + "." + configKey.getName()); } - return configDefinition.getCNode(); } else { DefParser dParser = new DefParser(configKey.getName(), new StringReader(defContent.asString())); - return dParser.getTree(); + dParser.getTree(); } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java index 2560badbf43..51213b173dd 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java @@ -134,7 +134,7 @@ public class Application implements ModelResult { throw new ConfigurationRuntimeException("Unable to resolve config " + configKey); } - ConfigResponse configResponse = responseFactory.createResponse(payload, def.getCNode(), appGeneration, internalRedeploy); + ConfigResponse configResponse = responseFactory.createResponse(payload, appGeneration, internalRedeploy); metricUpdater.incrementProcTime(System.currentTimeMillis() - start); if (useCache(req)) { cache.put(cacheKey, configResponse, configResponse.getConfigMd5()); 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 795c6398354..638e3565602 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 @@ -15,7 +15,6 @@ import com.yahoo.vespa.config.GetConfigRequest; import com.yahoo.vespa.config.protocol.ConfigResponse; import com.yahoo.vespa.config.server.GlobalComponentRegistry; import com.yahoo.vespa.config.server.NotFoundException; -import com.yahoo.vespa.config.server.ReloadHandler; import com.yahoo.vespa.config.server.ReloadListener; import com.yahoo.vespa.config.server.RequestHandler; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; @@ -59,7 +58,7 @@ import static java.util.stream.Collectors.toSet; * @author Ulf Lilleengen * @author jonmv */ -public class TenantApplications implements RequestHandler, ReloadHandler, HostValidator<ApplicationId> { +public class TenantApplications implements RequestHandler, HostValidator<ApplicationId> { private static final Logger log = Logger.getLogger(TenantApplications.class.getName()); @@ -258,7 +257,6 @@ public class TenantApplications implements RequestHandler, ReloadHandler, HostVa * * @param applicationSet the {@link ApplicationSet} to be reloaded */ - @Override public void reloadConfig(ApplicationSet applicationSet) { ApplicationId id = applicationSet.getId(); try (Lock lock = lock(id)) { @@ -272,7 +270,6 @@ public class TenantApplications implements RequestHandler, ReloadHandler, HostVa } } - @Override public void removeApplication(ApplicationId applicationId) { try (Lock lock = lock(applicationId)) { if (exists(applicationId)) @@ -288,7 +285,6 @@ public class TenantApplications implements RequestHandler, ReloadHandler, HostVa } } - @Override public void removeApplicationsExcept(Set<ApplicationId> applications) { for (ApplicationId activeApplication : applicationMapper.listApplicationIds()) { if ( ! applications.contains(activeApplication)) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactory.java index 54825167d15..88aa41ca735 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactory.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.config.server.rpc; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.codegen.InnerCNode; import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.protocol.ConfigResponse; @@ -26,14 +25,12 @@ public interface ConfigResponseFactory { } /** - * Create a {@link ConfigResponse} for a given payload and generation. - * - * @param payload The {@link com.yahoo.vespa.config.ConfigPayload} to put in the response. - * @param defFile The {@link com.yahoo.config.codegen.InnerCNode} def file for this config. - * @param generation The payload generation. @return A {@link ConfigResponse} that can be sent to the client. + * Creates a {@link ConfigResponse} for a given payload and generation. + * @param payload the {@link ConfigPayload} to put in the response. + * @param generation the payload generation. @return A {@link ConfigResponse} that can be sent to the client. * @param internalRedeploy whether this config generation was produced by an internal redeployment, * not a change to the application package */ - ConfigResponse createResponse(ConfigPayload payload, InnerCNode defFile, long generation, boolean internalRedeploy); + ConfigResponse createResponse(ConfigPayload payload, long generation, boolean internalRedeploy); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/LZ4ConfigResponseFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/LZ4ConfigResponseFactory.java index 5235a2bcadd..cba1316a131 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/LZ4ConfigResponseFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/LZ4ConfigResponseFactory.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.rpc; -import com.yahoo.config.codegen.InnerCNode; import com.yahoo.text.Utf8Array; import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.LZ4PayloadCompressor; @@ -18,11 +17,10 @@ import com.yahoo.vespa.config.util.ConfigUtils; */ public class LZ4ConfigResponseFactory implements ConfigResponseFactory { - private static LZ4PayloadCompressor compressor = new LZ4PayloadCompressor(); + private static final LZ4PayloadCompressor compressor = new LZ4PayloadCompressor(); @Override public ConfigResponse createResponse(ConfigPayload payload, - InnerCNode defFile, long generation, boolean internalRedeploy) { Utf8Array rawPayload = payload.toUtf8Array(true); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/UncompressedConfigResponseFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/UncompressedConfigResponseFactory.java index bd0b117c3db..2de88ab44cc 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/UncompressedConfigResponseFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/UncompressedConfigResponseFactory.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.rpc; -import com.yahoo.config.codegen.InnerCNode; import com.yahoo.text.Utf8Array; import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.protocol.CompressionInfo; @@ -19,7 +18,6 @@ public class UncompressedConfigResponseFactory implements ConfigResponseFactory @Override public ConfigResponse createResponse(ConfigPayload payload, - InnerCNode defFile, long generation, boolean internalRedeploy) { Utf8Array rawPayload = payload.toUtf8Array(true); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java index 763c77f2088..66ed721a3e1 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java @@ -8,8 +8,8 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.lang.SettableOptional; import com.yahoo.transaction.Transaction; import com.yahoo.vespa.config.server.GlobalComponentRegistry; -import com.yahoo.vespa.config.server.ReloadHandler; import com.yahoo.vespa.config.server.application.ApplicationSet; +import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.modelfactory.ActivatedModelsBuilder; import com.yahoo.vespa.curator.Curator; import org.apache.zookeeper.KeeperException; @@ -81,12 +81,12 @@ public class RemoteSession extends Session { return sessionZooKeeperClient.createWriteStatusTransaction(Status.DELETE); } - void makeActive(ReloadHandler reloadHandler) { + void makeActive(TenantApplications tenantApplications) { Curator.CompletionWaiter waiter = sessionZooKeeperClient.getActiveWaiter(); log.log(Level.FINE, () -> logPre() + "Getting session from repo: " + getSessionId()); ApplicationSet app = ensureApplicationLoaded(); log.log(Level.FINE, () -> logPre() + "Reloading config for " + getSessionId()); - reloadHandler.reloadConfig(app); + tenantApplications.reloadConfig(app); log.log(Level.FINE, () -> logPre() + "Notifying " + waiter); notifyCompletion(waiter); log.log(Level.INFO, logPre() + "Session activated: " + getSessionId()); 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 c35fcb3cf21..8a7be7ef176 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 @@ -17,7 +17,6 @@ import com.yahoo.transaction.AbstractTransaction; import com.yahoo.transaction.NestedTransaction; import com.yahoo.transaction.Transaction; import com.yahoo.vespa.config.server.GlobalComponentRegistry; -import com.yahoo.vespa.config.server.ReloadHandler; import com.yahoo.vespa.config.server.TimeoutBudget; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.application.TenantApplications; @@ -73,8 +72,6 @@ public class SessionRepository { private static final FilenameFilter sessionApplicationsFilter = (dir, name) -> name.matches("\\d+"); private static final long nonExistingActiveSession = 0; - - private final SessionCache<LocalSession> localSessionCache = new SessionCache<>(); private final SessionCache<RemoteSession> remoteSessionCache = new SessionCache<>(); private final Map<Long, SessionStateWatcher> sessionStateWatchers = new HashMap<>(); @@ -84,7 +81,6 @@ public class SessionRepository { private final Executor zkWatcherExecutor; private final TenantFileSystemDirs tenantFileSystemDirs; private final BooleanFlag distributeApplicationPackage; - private final ReloadHandler reloadHandler; private final MetricUpdater metrics; private final Curator.DirectoryCache directoryCache; private final TenantApplications applicationRepo; @@ -97,7 +93,6 @@ public class SessionRepository { public SessionRepository(TenantName tenantName, GlobalComponentRegistry componentRegistry, TenantApplications applicationRepo, - ReloadHandler reloadHandler, FlagSource flagSource, SessionPreparer sessionPreparer) { this.tenantName = tenantName; @@ -111,7 +106,6 @@ public class SessionRepository { this.applicationRepo = applicationRepo; this.sessionPreparer = sessionPreparer; this.distributeApplicationPackage = Flags.CONFIGSERVER_DISTRIBUTE_APPLICATION_PACKAGE.bindTo(flagSource); - this.reloadHandler = reloadHandler; this.metrics = componentRegistry.getMetrics().getOrCreateMetricUpdater(Metrics.createDimensions(tenantName)); this.locksPath = TenantRepository.getLocksPath(tenantName); @@ -351,7 +345,7 @@ public class SessionRepository { for (ApplicationId applicationId : applicationRepo.activeApplications()) { if (applicationRepo.requireActiveSessionOf(applicationId) == session.getSessionId()) { log.log(Level.FINE, () -> "Found active application for session " + session.getSessionId() + " , loading it"); - reloadHandler.reloadConfig(session.ensureApplicationLoaded()); + applicationRepo.reloadConfig(session.ensureApplicationLoaded()); log.log(Level.INFO, session.logPre() + "Application activated successfully: " + applicationId + " (generation " + session.getSessionId() + ")"); return; } @@ -626,7 +620,7 @@ public class SessionRepository { if (sessionStateWatchers.containsKey(sessionId)) { localSession.ifPresent(session -> sessionStateWatchers.get(sessionId).addLocalSession(session)); } else { - sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, reloadHandler, remoteSession, + sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, applicationRepo, remoteSession, localSession, metrics, zkWatcherExecutor, this)); } } @@ -636,8 +630,6 @@ public class SessionRepository { return getLocalSessions().toString(); } - public ReloadHandler getReloadHandler() { return reloadHandler; } - /** Returns the lock for session operations for the given session id. */ public Lock lock(long sessionId) { return curator.lock(lockPath(sessionId), Duration.ofMinutes(1)); // These locks shouldn't be held for very long. diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java index 1cbab9be1a8..65c62a392b7 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java @@ -2,7 +2,7 @@ package com.yahoo.vespa.config.server.session; import com.yahoo.text.Utf8; -import com.yahoo.vespa.config.server.ReloadHandler; +import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.monitoring.MetricUpdater; import com.yahoo.vespa.curator.Curator; import org.apache.curator.framework.recipes.cache.ChildData; @@ -26,7 +26,7 @@ public class SessionStateWatcher { private static final Logger log = Logger.getLogger(SessionStateWatcher.class.getName()); private final Curator.FileCache fileCache; - private final ReloadHandler reloadHandler; + private final TenantApplications tenantApplications; private final RemoteSession remoteSession; private final MetricUpdater metrics; private final Executor zkWatcherExecutor; @@ -34,14 +34,14 @@ public class SessionStateWatcher { private Optional<LocalSession> localSession; SessionStateWatcher(Curator.FileCache fileCache, - ReloadHandler reloadHandler, + TenantApplications tenantApplications, RemoteSession remoteSession, Optional<LocalSession> localSession, MetricUpdater metrics, Executor zkWatcherExecutor, SessionRepository sessionRepository) { this.fileCache = fileCache; - this.reloadHandler = reloadHandler; + this.tenantApplications = tenantApplications; this.remoteSession = remoteSession; this.localSession = localSession; this.metrics = metrics; @@ -60,7 +60,7 @@ public class SessionStateWatcher { remoteSession.loadPrepared(); } else if (newStatus.equals(Status.ACTIVATE)) { createLocalSession(sessionId); - remoteSession.makeActive(reloadHandler); + remoteSession.makeActive(tenantApplications); } else if (newStatus.equals(Status.DEACTIVATE)) { remoteSession.deactivate(); } else if (newStatus.equals(Status.DELETE)) { 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 33bbda33230..33ce8f52834 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 @@ -219,8 +219,9 @@ public class TenantRepository { componentRegistry.getConfigserverConfig(), componentRegistry.getHostRegistries().createApplicationHostRegistry(tenantName), new TenantFileSystemDirs(componentRegistry.getConfigServerDB(), tenantName)); - SessionRepository sessionRepository = new SessionRepository(tenantName, componentRegistry, - applicationRepo, applicationRepo, + SessionRepository sessionRepository = new SessionRepository(tenantName, + componentRegistry, + applicationRepo, componentRegistry.getFlagSource(), componentRegistry.getSessionPreparer()); log.log(Level.INFO, "Adding tenant '" + tenantName + "'" + ", created " + created); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactoryTest.java index 2eccf6b5643..6fa4a421d5a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/ConfigResponseFactoryTest.java @@ -32,7 +32,7 @@ public class ConfigResponseFactoryTest { @Test public void testUncompressedFactory() { UncompressedConfigResponseFactory responseFactory = new UncompressedConfigResponseFactory(); - ConfigResponse response = responseFactory.createResponse(ConfigPayload.empty(), def, 3, false); + ConfigResponse response = responseFactory.createResponse(ConfigPayload.empty(), 3, false); assertEquals(CompressionType.UNCOMPRESSED, response.getCompressionInfo().getCompressionType()); assertEquals(3L,response.getGeneration()); assertEquals(2, response.getPayload().getByteLength()); @@ -41,7 +41,7 @@ public class ConfigResponseFactoryTest { @Test public void testLZ4CompressedFactory() { LZ4ConfigResponseFactory responseFactory = new LZ4ConfigResponseFactory(); - ConfigResponse response = responseFactory.createResponse(ConfigPayload.empty(), def, 3, false); + ConfigResponse response = responseFactory.createResponse(ConfigPayload.empty(), 3, false); assertEquals(CompressionType.LZ4, response.getCompressionInfo().getCompressionType()); assertEquals(3L, response.getGeneration()); assertEquals(3, response.getPayload().getByteLength()); 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 8d0285ac12b..f372b21b065 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.vespa.config.server.ServerCache; import com.yahoo.vespa.config.server.TestComponentRegistry; 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.monitoring.MetricUpdater; import com.yahoo.vespa.curator.Curator; @@ -82,10 +83,10 @@ public class TenantRepositoryTest { @Test public void testListenersAdded() throws IOException, SAXException { - Tenant tenant = tenantRepository.getTenant(tenant1); - tenant.getApplicationRepo().createApplication(ApplicationId.defaultId()); - tenant.getApplicationRepo().createPutTransaction(ApplicationId.defaultId(), 4).commit(); - tenant.getSessionRepository().getReloadHandler().reloadConfig(ApplicationSet.fromSingle( + TenantApplications applicationRepo = tenantRepository.getTenant(tenant1).getApplicationRepo(); + applicationRepo.createApplication(ApplicationId.defaultId()); + applicationRepo.createPutTransaction(ApplicationId.defaultId(), 4).commit(); + applicationRepo.reloadConfig(ApplicationSet.fromSingle( new Application(new VespaModel(MockApplicationPackage.createEmpty()), new ServerCache(), 4L, |