diff options
author | Harald Musum <musum@oath.com> | 2017-11-17 10:51:22 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2017-11-17 10:51:22 +0100 |
commit | 5cc31e861f6ebfcaafa25e7aa143e613dbf2856c (patch) | |
tree | db042f9a9be3c06d047b24431cd9a6ba06684d21 | |
parent | 359d3c4a6d22a0ea4aef20e7293fe808228d4b6f (diff) |
Remove PaathProvider
This is a bad neighbourhood, so try to get rid of deceptive and cheating code
8 files changed, 40 insertions, 88 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/PathProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/PathProvider.java deleted file mode 100644 index 5910c69048a..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/PathProvider.java +++ /dev/null @@ -1,42 +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.google.inject.Inject; -import com.yahoo.path.Path; - -/** - * Temporary provider of root path for components that will soon get them injected from a parent class. - * - * @author lulf - * * @since 5.1.24 - */ -public class PathProvider { - - private final Path root; - // Path for Vespa-related data stored in Zookeeper (subpaths are relative to this path) - // NOTE: This should not be exposed, as this path can be different in testing, depending on how we configure it. - private static final String APPS_ZK_NODE = "sessions"; - private static final String VESPA_ZK_PATH = "/vespa/config"; - - @Inject - public PathProvider() { - root = Path.fromString(VESPA_ZK_PATH); - } - - public PathProvider(Path root) { - this.root = root; - } - - public Path getRoot() { - return root; - } - - public Path getSessionDirs() { - return root.append(APPS_ZK_NODE); - } - - public Path getSessionDir(long sessionId) { - return getSessionDirs().append(String.valueOf(sessionId)); - } - -} 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 6b25772f85d..9d04b7e982d 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 @@ -19,10 +19,8 @@ import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.logging.AccessLog; import com.yahoo.jdisc.Response; import com.yahoo.jdisc.http.HttpRequest; -import com.yahoo.path.Path; import com.yahoo.slime.JsonFormat; import com.yahoo.vespa.config.server.ApplicationRepository; -import com.yahoo.vespa.config.server.PathProvider; import com.yahoo.vespa.config.server.SuperModelGenerationCounter; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.MemoryTenantApplications; @@ -45,6 +43,7 @@ import com.yahoo.vespa.config.server.session.SessionContext; import com.yahoo.vespa.config.server.session.SessionFactory; import com.yahoo.vespa.config.server.session.SessionTest; import com.yahoo.vespa.config.server.session.SessionZooKeeperClient; +import com.yahoo.vespa.config.server.tenant.Tenants; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; @@ -83,7 +82,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { private Curator curator; private RemoteSessionRepo remoteSessionRepo; private LocalSessionRepo localRepo; - private PathProvider pathProvider; private TenantApplications applicationRepo; private MockProvisioner hostProvisioner; @@ -95,7 +93,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { configCurator = ConfigCurator.create(curator); localRepo = new LocalSessionRepo(Clock.systemUTC()); pathPrefix = "/application/v2/tenant/" + tenant + "/session/"; - pathProvider = new PathProvider(Path.createRoot()); hostProvisioner = new MockProvisioner(); } @@ -213,7 +210,7 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { private RemoteSession createRemoteSession(long sessionId, Session.Status status, SessionZooKeeperClient zkClient, Clock clock) throws IOException { zkClient.writeStatus(status); - ZooKeeperClient zkC = new ZooKeeperClient(configCurator, new BaseDeployLogger(), false, pathProvider.getSessionDirs().append(String.valueOf(sessionId))); + ZooKeeperClient zkC = new ZooKeeperClient(configCurator, new BaseDeployLogger(), false, Tenants.getSessionsPath(tenant).append(String.valueOf(sessionId))); VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); zkC.write(Collections.singletonMap(modelFactory.getVersion(), new MockFileRegistry())); zkC.write(AllocatedHosts.withHosts(Collections.emptySet())); @@ -318,7 +315,7 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { } ActivateRequest invoke(boolean createLocalSession) throws Exception { - SessionZooKeeperClient zkClient = new MockSessionZKClient(curator, pathProvider.getSessionDirs().append(String.valueOf(sessionId)), + SessionZooKeeperClient zkClient = new MockSessionZKClient(curator, tenant, sessionId, Optional.of(AllocatedHosts.withHosts(Collections.singleton(new HostSpec("bar", Collections.emptyList()))))); session = createRemoteSession(sessionId, initialStatus, zkClient, clock); if (createLocalSession) { 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 428cd16508f..d0e60144125 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 @@ -20,7 +20,6 @@ import com.yahoo.slime.JsonDecoder; import com.yahoo.slime.Slime; import com.yahoo.transaction.Transaction; import com.yahoo.vespa.config.server.ApplicationRepository; -import com.yahoo.vespa.config.server.PathProvider; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.host.HostRegistry; @@ -149,14 +148,13 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { */ private RemoteSessionRepo fromLocalSessionRepo(LocalSessionRepo localRepo, Clock clock) { RemoteSessionRepo remoteRepo = new RemoteSessionRepo(); - PathProvider pathProvider = new PathProvider(Path.createRoot()); for (LocalSession ls : localRepo.listSessions()) { - zooKeeperClient = new MockSessionZKClient(curator, pathProvider.getSessionDirs().append(String.valueOf(ls.getSessionId()))); + zooKeeperClient = new MockSessionZKClient(curator, tenant, ls.getSessionId()); if (ls.getStatus()!=null) zooKeeperClient.writeStatus(ls.getStatus()); - RemoteSession remSess = new RemoteSession(TenantName.from("default"), ls.getSessionId(), + RemoteSession remSess = new RemoteSession(tenant, ls.getSessionId(), new TestComponentRegistry.Builder().curator(curator).build(), - zooKeeperClient, + zooKeeperClient, clock); remoteRepo.addSession(remSess); } @@ -239,8 +237,8 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { public void require_that_preparing_with_multiple_tenants_work() throws Exception { // Need different repos for 'default' tenant as opposed to the 'test' tenant LocalSessionRepo localRepoDefault = new LocalSessionRepo(Clock.systemUTC()); - final TenantName tenantName = TenantName.defaultName(); - addTenant(tenantName, localRepoDefault, new RemoteSessionRepo(), new MockSessionFactory()); + final TenantName defaultTenant = TenantName.defaultName(); + addTenant(defaultTenant, localRepoDefault, new RemoteSessionRepo(), new MockSessionFactory()); addTestTenant(); final SessionHandler handler = createHandler(builder); @@ -248,7 +246,7 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { // Deploy with default tenant MockSession session = new MockSession(sessionId, null); localRepoDefault.addSession(session); - pathPrefix = "/application/v2/tenant/default/session/"; + pathPrefix = "/application/v2/tenant/" + defaultTenant + "/session/"; HttpResponse response = handler.handle( SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, sessionId)); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java index c6099e724bc..b98fa49ac26 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/LocalSessionTest.java @@ -13,6 +13,7 @@ import com.yahoo.vespa.config.server.deploy.DeployHandlerLogger; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; import com.yahoo.vespa.config.server.deploy.ZooKeeperClient; import com.yahoo.vespa.config.server.host.HostRegistry; +import com.yahoo.vespa.config.server.tenant.Tenants; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; @@ -108,13 +109,15 @@ public class LocalSessionTest { @Test public void require_that_session_can_be_deleted() throws Exception { - LocalSession session = createSession(TenantName.defaultName(), 3); - assertTrue(configCurator.exists("/3")); + TenantName tenantName = TenantName.defaultName(); + LocalSession session = createSession(tenantName, 3); + String sessionNode = Tenants.getSessionsPath(tenantName).append(String.valueOf(3)).getAbsolute(); + assertTrue(configCurator.exists(sessionNode)); assertTrue(new File(tenantFileSystemDirs.sessionsPath(), "3").exists()); long gen = superModelGenerationCounter.get(); session.delete(); assertThat(superModelGenerationCounter.get(), is(gen + 1)); - assertFalse(configCurator.exists("/3")); + assertFalse(configCurator.exists(sessionNode)); assertFalse(new File(tenantFileSystemDirs.sessionsPath(), "3").exists()); } @@ -155,10 +158,9 @@ public class LocalSessionTest { } private LocalSession createSession(TenantName tenant, long sessionId, SessionTest.MockSessionPreparer preparer, Optional<AllocatedHosts> allocatedHosts) throws Exception { - Path sessionPath = Path.fromString("/" + sessionId); - SessionZooKeeperClient zkc = new MockSessionZKClient(curator, sessionPath, allocatedHosts); + SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenant, sessionId, allocatedHosts); zkc.createWriteStatusTransaction(Session.Status.NEW).commit(); - ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, new BaseDeployLogger(), false, sessionPath); + ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, new BaseDeployLogger(), false, Tenants.getSessionsPath(tenant).append(String.valueOf(sessionId))); if (allocatedHosts.isPresent()) { zkClient.write(allocatedHosts.get()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java index 62b0ecbada2..a4331216334 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java @@ -4,8 +4,10 @@ package com.yahoo.vespa.config.server.session; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.AllocatedHosts; +import com.yahoo.config.provision.TenantName; import com.yahoo.transaction.Transaction; import com.yahoo.path.Path; +import com.yahoo.vespa.config.server.tenant.Tenants; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; @@ -22,17 +24,17 @@ public class MockSessionZKClient extends SessionZooKeeperClient { private Optional<AllocatedHosts> info = Optional.empty(); private Session.Status sessionStatus; - public MockSessionZKClient(Curator curator, Path sessionPath) { - this(curator, sessionPath, (ApplicationPackage)null); + public MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId) { + this(curator, tenantName, sessionId, (ApplicationPackage)null); } - public MockSessionZKClient(Curator curator, Path sessionPath, Optional<AllocatedHosts> allocatedHosts) { - this(curator, sessionPath); + public MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId, Optional<AllocatedHosts> allocatedHosts) { + this(curator, tenantName, sessionId); this.info = allocatedHosts; } - public MockSessionZKClient(Curator curator, Path sessionPath, ApplicationPackage application) { - super(curator, sessionPath); + public MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId, ApplicationPackage application) { + super(curator, Tenants.getSessionsPath(tenantName).append(String.valueOf(sessionId))); this.app = application; } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionTest.java index 44f304847ba..9598a9262f0 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/RemoteSessionTest.java @@ -11,10 +11,8 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.Version; -import com.yahoo.path.Path; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; -import com.yahoo.vespa.config.server.PathProvider; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.PermanentApplicationPackage; import com.yahoo.vespa.curator.mock.MockCurator; @@ -49,13 +47,13 @@ import static org.junit.Assert.assertTrue; */ public class RemoteSessionTest { + private static final TenantName tenantName = TenantName.from("default"); + private Curator curator; - private PathProvider pathProvider; @Before public void setupTest() throws Exception { curator = new MockCurator(); - pathProvider = new PathProvider(Path.createRoot()); } @Test @@ -180,7 +178,7 @@ public class RemoteSessionTest { okFactory.vespaVersion = Version.fromIntValues(2, 0, 0); okFactory.throwOnLoad = false; - SessionZooKeeperClient zkc = new MockSessionZKClient(curator, pathProvider.getSessionDir(3), application); + SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenantName, 3, application); RemoteSession session = createSession(3, zkc, Arrays.asList(okFactory, failingFactory), failingFactory.clock()); session.loadPrepared(); @@ -189,7 +187,7 @@ public class RemoteSessionTest { @Test public void require_that_session_status_is_updated() throws IOException, SAXException { - SessionZooKeeperClient zkc = new MockSessionZKClient(curator, pathProvider.getSessionDir(3)); + SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenantName, 3); RemoteSession session = createSession(3, zkc, Clock.systemUTC()); assertThat(session.getStatus(), is(Session.Status.NEW)); zkc.writeStatus(Session.Status.PREPARE); @@ -203,7 +201,7 @@ public class RemoteSessionTest { MockModelFactory mockModelFactory = new MockModelFactory(); try { int sessionId = 3; - SessionZooKeeperClient zkc = new MockSessionZKClient(curator, pathProvider.getSessionDir(sessionId)); + SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenantName, sessionId); createSession(sessionId, zkc, Collections.singletonList(mockModelFactory), permanentApp, mockModelFactory.clock()).ensureApplicationLoaded(); } catch (Exception e) { e.printStackTrace(); @@ -220,7 +218,7 @@ public class RemoteSessionTest { return createSession(sessionId, zkc, Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())), clock); } private RemoteSession createSession(long sessionId, List<ModelFactory> modelFactories, Clock clock) { - SessionZooKeeperClient zkc = new MockSessionZKClient(curator, pathProvider.getSessionDir(sessionId)); + SessionZooKeeperClient zkc = new MockSessionZKClient(curator, tenantName, sessionId); return createSession(sessionId, zkc, modelFactories, clock); } @@ -238,7 +236,8 @@ public class RemoteSessionTest { if (permanentApplicationPackage.isPresent()) registryBuilder.permanentApplicationPackage(permanentApplicationPackage.get()); - return new RemoteSession(TenantName.from("default"), sessionId, + + return new RemoteSession(tenantName, sessionId, registryBuilder.build(), zkc, clock); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepoTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepoTest.java index 1bb25bc37db..01cb90721f3 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepoTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepoTest.java @@ -1,8 +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.session; -import com.yahoo.path.Path; -import com.yahoo.vespa.config.server.PathProvider; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Test; @@ -34,10 +32,10 @@ public class SessionRepoTest { } private class TestSession extends Session { - public TestSession(long sessionId) { - super(TenantName.from("default"), + TestSession(long sessionId) { + super(TenantName.defaultName(), sessionId, - new MockSessionZKClient(new MockCurator(), new PathProvider(Path.createRoot()).getSessionDir(sessionId))); + new MockSessionZKClient(new MockCurator(), TenantName.defaultName(), sessionId)); } } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java index 91cf6e79165..dc6268c5a25 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java @@ -11,7 +11,6 @@ import com.yahoo.config.provision.ApplicationName; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.Version; import com.yahoo.io.IOUtils; -import com.yahoo.path.Path; import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.GetConfigRequest; @@ -20,7 +19,6 @@ import com.yahoo.vespa.config.protocol.DefContent; import com.yahoo.vespa.config.protocol.VespaVersion; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.host.HostRegistries; -import com.yahoo.vespa.config.server.PathProvider; import com.yahoo.vespa.config.server.ReloadListener; import com.yahoo.vespa.config.server.ServerCache; import com.yahoo.vespa.config.server.TestComponentRegistry; @@ -88,7 +86,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { private void feedApp(File appDir, long sessionId, ApplicationId appId) throws IOException { SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, configCurator, - new PathProvider(Path.createRoot()).getSessionDir(sessionId), + Tenants.getSessionsPath(tenant).append(String.valueOf(sessionId)), new TestConfigDefinitionRepo(), "", Optional.empty()); zkc.writeApplicationId(appId); @@ -104,7 +102,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { private ApplicationSet reloadConfig(long id, String application, Clock clock) { SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, configCurator, - new PathProvider(Path.createRoot()).getSessionDir(id), + Tenants.getSessionsPath(tenant).append(String.valueOf(id)), new TestConfigDefinitionRepo(), "", Optional.empty()); zkc.writeApplicationId(new ApplicationId.Builder().tenant(tenant).applicationName(application).build()); @@ -187,7 +185,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { public void testResolveForAppId() { long id = 1l; SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, configCurator, - new PathProvider(Path.createRoot()).getSessionDir(id), + Tenants.getSessionsPath(tenant).append(String.valueOf(id)), new TestConfigDefinitionRepo(), "", Optional.empty()); ApplicationId appId = new ApplicationId.Builder() @@ -231,7 +229,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { private void feedAndReloadApp(File appDir, long sessionId, ApplicationId appId) throws IOException { feedApp(appDir, sessionId, appId); - SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, new PathProvider(Path.createRoot()).getSessionDir(sessionId)); + SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, Tenants.getSessionsPath(tenant).append(String.valueOf(sessionId))); zkc.writeApplicationId(appId); RemoteSession session = new RemoteSession(tenant, sessionId, componentRegistry, zkc, Clock.systemUTC()); server.reloadConfig(session.ensureApplicationLoaded()); |