diff options
Diffstat (limited to 'configserver')
10 files changed, 30 insertions, 66 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionFactory.java deleted file mode 100644 index 0707260dffd..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionFactory.java +++ /dev/null @@ -1,43 +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.session; - -import com.yahoo.config.provision.TenantName; -import com.yahoo.path.Path; -import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.vespa.config.server.GlobalComponentRegistry; -import com.yahoo.vespa.config.server.tenant.TenantRepository; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; -import com.yahoo.vespa.curator.Curator; - -/** - * @author Ulf Lilleengen - */ -public class RemoteSessionFactory { - - private final GlobalComponentRegistry componentRegistry; - private final Curator curator; - private final ConfigCurator configCurator; - private final Path sessionsPath; - private final TenantName tenant; - private final ConfigserverConfig configserverConfig; - - public RemoteSessionFactory(GlobalComponentRegistry componentRegistry, TenantName tenant) { - this.componentRegistry = componentRegistry; - this.curator = componentRegistry.getCurator(); - this.configCurator = componentRegistry.getConfigCurator(); - this.sessionsPath = TenantRepository.getSessionsPath(tenant); - this.tenant = tenant; - this.configserverConfig = componentRegistry.getConfigserverConfig(); - } - - public RemoteSession createSession(long sessionId) { - Path sessionPath = this.sessionsPath.append(String.valueOf(sessionId)); - SessionZooKeeperClient sessionZKClient = new SessionZooKeeperClient(curator, - configCurator, - sessionPath, - configserverConfig.serverId(), - componentRegistry.getZone().nodeFlavors()); - return new RemoteSession(tenant, sessionId, componentRegistry, sessionZKClient); - } - -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java index de5af7994ec..316f7f7778d 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java @@ -48,7 +48,7 @@ public class RemoteSessionRepo { private final Curator curator; private final Path sessionsPath; - private final RemoteSessionFactory remoteSessionFactory; + private final SessionFactory sessionFactory; private final Map<Long, RemoteSessionStateWatcher> sessionStateWatchers = new HashMap<>(); private final ReloadHandler reloadHandler; private final TenantName tenantName; @@ -59,7 +59,7 @@ public class RemoteSessionRepo { private final SessionCache<RemoteSession> sessionCache; public RemoteSessionRepo(GlobalComponentRegistry componentRegistry, - RemoteSessionFactory remoteSessionFactory, + SessionFactory sessionFactory, ReloadHandler reloadHandler, TenantName tenantName, TenantApplications applicationRepo) { @@ -67,7 +67,7 @@ public class RemoteSessionRepo { this.curator = componentRegistry.getCurator(); this.sessionsPath = TenantRepository.getSessionsPath(tenantName); this.applicationRepo = applicationRepo; - this.remoteSessionFactory = remoteSessionFactory; + this.sessionFactory = sessionFactory; this.reloadHandler = reloadHandler; this.tenantName = tenantName; this.metrics = componentRegistry.getMetrics().getOrCreateMetricUpdater(Metrics.createDimensions(tenantName)); @@ -149,7 +149,7 @@ public class RemoteSessionRepo { */ private void sessionAdded(long sessionId) { log.log(Level.FINE, () -> "Adding session to RemoteSessionRepo: " + sessionId); - RemoteSession session = remoteSessionFactory.createSession(sessionId); + RemoteSession session = sessionFactory.createRemoteSession(sessionId); Path sessionPath = sessionsPath.append(String.valueOf(sessionId)); Curator.FileCache fileCache = curator.createFileCache(sessionPath.append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH).getAbsolute(), false); fileCache.addListener(this::nodeChanged); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java index 6b51abb7cca..c880019e0c8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactory.java @@ -36,4 +36,6 @@ public interface SessionFactory { LocalSession createSessionFromExisting(Session existingSession, DeployLogger logger, boolean internalRedeploy, TimeoutBudget timeoutBudget); + RemoteSession createRemoteSession(long sessionId); + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java index 558b17131a3..bc930916ba8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java @@ -77,6 +77,12 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader { return create(applicationFile, applicationId, nonExistingActiveSession, false, timeoutBudget); } + public RemoteSession createRemoteSession(long sessionId) { + Path sessionPath = sessionsPath.append(String.valueOf(sessionId)); + SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionPath); + return new RemoteSession(tenant, sessionId, componentRegistry, sessionZKClient); + } + private void ensureSessionPathDoesNotExist(long sessionId) { Path sessionPath = getSessionPath(sessionId); if (configCurator.exists(sessionPath.getAbsolute())) { @@ -140,8 +146,7 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader { long sessionId = getNextSessionId(); try { ensureSessionPathDoesNotExist(sessionId); - SessionZooKeeperClient sessionZooKeeperClient = - new SessionZooKeeperClient(curator, configCurator, getSessionPath(sessionId), serverId, nodeFlavors); + SessionZooKeeperClient sessionZooKeeperClient = createSessionZooKeeperClient(getSessionPath(sessionId)); File userApplicationDir = getSessionAppDir(sessionId); IOUtils.copyDirectory(applicationFile, userApplicationDir); ApplicationPackage applicationPackage = createApplication(applicationFile, @@ -157,6 +162,10 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader { } } + private SessionZooKeeperClient createSessionZooKeeperClient(Path sessionPath) { + return new SessionZooKeeperClient(curator, configCurator, sessionPath, serverId, nodeFlavors); + } + private File getAndValidateExistingSessionAppDir(long sessionId) { File appDir = getSessionAppDir(sessionId); if (!appDir.exists() || !appDir.isDirectory()) { @@ -174,11 +183,7 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader { File sessionDir = getAndValidateExistingSessionAppDir(sessionId); ApplicationPackage applicationPackage = FilesApplicationPackage.fromFile(sessionDir); Path sessionIdPath = sessionsPath.append(String.valueOf(sessionId)); - SessionZooKeeperClient sessionZKClient = new SessionZooKeeperClient(curator, - configCurator, - sessionIdPath, - serverId, - nodeFlavors); + SessionZooKeeperClient sessionZKClient = createSessionZooKeeperClient(sessionIdPath); return new LocalSession(tenant, sessionId, sessionPreparer, applicationPackage, sessionZKClient, getSessionAppDir(sessionId), applicationRepo, hostRegistry); } 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 457d5538d5c..3ddfdf412c9 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 @@ -17,7 +17,6 @@ import com.yahoo.vespa.config.server.monitoring.MetricUpdater; import com.yahoo.vespa.config.server.rpc.ConfigResponseFactory; import com.yahoo.vespa.config.server.session.LocalSessionLoader; import com.yahoo.vespa.config.server.session.LocalSessionRepo; -import com.yahoo.vespa.config.server.session.RemoteSessionFactory; import com.yahoo.vespa.config.server.session.RemoteSessionRepo; import com.yahoo.vespa.config.server.session.SessionFactory; import com.yahoo.vespa.config.server.session.SessionFactoryImpl; @@ -235,7 +234,7 @@ public class TenantRepository { // TODO: Fix the casting LocalSessionRepo localSessionRepo = new LocalSessionRepo(tenantName, globalComponentRegistry, (LocalSessionLoader) sessionFactory); RemoteSessionRepo remoteSessionRepo = new RemoteSessionRepo(globalComponentRegistry, - new RemoteSessionFactory(globalComponentRegistry, tenantName), + sessionFactory, reloadHandler, tenantName, applicationRepo); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java index b939f1ab4c5..91a40bd6083 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/SessionHandlerTest.java @@ -25,6 +25,7 @@ import com.yahoo.vespa.config.server.session.DummyTransaction; import com.yahoo.vespa.config.server.session.LocalSession; import com.yahoo.vespa.config.server.session.MockSessionZKClient; import com.yahoo.vespa.config.server.session.PrepareParams; +import com.yahoo.vespa.config.server.session.RemoteSession; import com.yahoo.vespa.config.server.session.Session; import java.io.ByteArrayOutputStream; @@ -86,7 +87,7 @@ public class SessionHandlerTest { return baos.toString(StandardCharsets.UTF_8); } - public static class MockSession extends LocalSession { + public static class MockLocalSession extends LocalSession { public Session.Status status; private ConfigChangeActions actions = new ConfigChangeActions(); @@ -94,11 +95,11 @@ public class SessionHandlerTest { private ApplicationId applicationId; private Optional<DockerImage> dockerImageRepository; - public MockSession(long sessionId, ApplicationPackage app) { + public MockLocalSession(long sessionId, ApplicationPackage app) { super(TenantName.defaultName(), sessionId, null, app, new MockSessionZKClient(app), null, null, new HostRegistry<>()); } - public MockSession(long sessionId, ApplicationPackage app, ApplicationId applicationId) { + public MockLocalSession(long sessionId, ApplicationPackage app, ApplicationId applicationId) { this(sessionId, app); this.applicationId = applicationId; } 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 09e84deb1a5..078dc47af51 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 @@ -44,7 +44,7 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { private ApplicationId idTenant2 = new ApplicationId.Builder() .tenant(tenantName2) .applicationName("foo").instanceName("quux").build(); - private MockSession session2; + private MockLocalSession session2; @Before public void setupHandler() { @@ -52,13 +52,13 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { tenantRepository.addTenant(tenantName1); tenantRepository.addTenant(tenantName2); - session2 = new MockSession(2, FilesApplicationPackage.fromFile(new File("src/test/apps/content"))); + session2 = new MockLocalSession(2, FilesApplicationPackage.fromFile(new File("src/test/apps/content"))); Tenant tenant1 = tenantRepository.getTenant(tenantName1); tenant1.getLocalSessionRepo().addSession(session2); tenant1.getApplicationRepo().createApplication(idTenant1); tenant1.getApplicationRepo().createPutTransaction(idTenant1, 2).commit(); - MockSession session3 = new MockSession(3, FilesApplicationPackage.fromFile(new File("src/test/apps/content2"))); + MockLocalSession session3 = new MockLocalSession(3, FilesApplicationPackage.fromFile(new File("src/test/apps/content2"))); Tenant tenant2 = tenantRepository.getTenant(tenantName2); tenant2.getLocalSessionRepo().addSession(session3); tenant2.getApplicationRepo().createApplication(idTenant2); 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 28fe4a7aa2c..2eaa5d75ba7 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 @@ -52,7 +52,7 @@ public class HostHandlerTest { tenant.getApplicationRepo().createApplication(applicationId); tenant.getApplicationRepo().createPutTransaction(applicationId, sessionId).commit(); ApplicationPackage app = FilesApplicationPackage.fromFile(testApp); - tenant.getLocalSessionRepo().addSession(new SessionHandlerTest.MockSession(sessionId, app, applicationId)); + tenant.getLocalSessionRepo().addSession(new SessionHandlerTest.MockLocalSession(sessionId, app, applicationId)); TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder() .modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())))) .build(); 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 bc1650ce923..88bf6fb7172 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 @@ -43,7 +43,7 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { public void setupHandler() throws Exception { tenantRepository = new TenantRepository(componentRegistry, false); tenantRepository.addTenant(tenant); - tenantRepository.getTenant(tenant).getLocalSessionRepo().addSession(new MockSession(1L, FilesApplicationPackage.fromFile(createTestApp()))); + tenantRepository.getTenant(tenant).getLocalSessionRepo().addSession(new MockLocalSession(1L, FilesApplicationPackage.fromFile(createTestApp()))); handler = createHandler(); pathPrefix = "/application/v2/tenant/" + tenant + "/session/"; baseUrl = "http://foo:1337/application/v2/tenant/" + tenant + "/session/1/content/"; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java index 69132186abc..002308ea298 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionRepoTest.java @@ -97,8 +97,8 @@ public class LocalSessionRepoTest { } assertNull(repo.getSession(1L)); - repo.addSession(new SessionHandlerTest.MockSession(1L, FilesApplicationPackage.fromFile(testApp))); - repo.addSession(new SessionHandlerTest.MockSession(2L, FilesApplicationPackage.fromFile(testApp))); + repo.addSession(new SessionHandlerTest.MockLocalSession(1L, FilesApplicationPackage.fromFile(testApp))); + repo.addSession(new SessionHandlerTest.MockLocalSession(2L, FilesApplicationPackage.fromFile(testApp))); assertNotNull(repo.getSession(1L)); assertNotNull(repo.getSession(2L)); assertNull(repo.getSession(3L)); |