summaryrefslogtreecommitdiffstats
path: root/configserver/src/main
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2017-11-15 19:15:27 +0100
committerHarald Musum <musum@oath.com>2017-11-15 19:15:27 +0100
commitfd0541930ea6bf04b5188000eff95bcb0e36b64f (patch)
tree3e07701f972ba57cd78a063bb4c76d600d1e71e9 /configserver/src/main
parentc7c7f25a47b9debfc07a6ebbe7702d3d8ed8c476 (diff)
Cleanup and simplify code related to zk paths for tenants
No functional changes
Diffstat (limited to 'configserver/src/main')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java5
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionFactory.java8
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionRepo.java20
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionFactoryImpl.java4
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java20
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java23
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java9
7 files changed, 57 insertions, 32 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java
index 648e6bb7180..9d22f7ee08b 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ZKTenantApplications.java
@@ -47,6 +47,7 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac
private ZKTenantApplications(Curator curator, Path applicationsPath, ReloadHandler reloadHandler, TenantName tenant) {
this.curator = curator;
this.applicationsPath = applicationsPath;
+ curator.create(applicationsPath);
this.reloadHandler = reloadHandler;
this.tenant = tenant;
this.directoryCache = curator.createDirectoryCache(applicationsPath.getAbsolute(), false, false, pathChildrenExecutor);
@@ -54,9 +55,9 @@ public class ZKTenantApplications implements TenantApplications, PathChildrenCac
this.directoryCache.addListener(this);
}
- public static TenantApplications create(Curator curator, Path applicationsPath, ReloadHandler reloadHandler, TenantName tenant) {
+ public static TenantApplications create(Curator curator, ReloadHandler reloadHandler, TenantName tenant) {
try {
- return new ZKTenantApplications(curator, applicationsPath, reloadHandler, tenant);
+ return new ZKTenantApplications(curator, Tenants.getApplicationsPath(tenant), reloadHandler, tenant);
} catch (Exception e) {
throw new RuntimeException(Tenants.logPre(tenant) + "Error creating application repo", e);
}
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
index 298acaca901..9aea683a83f 100644
--- 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
@@ -6,6 +6,7 @@ import com.yahoo.path.Path;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
+import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
@@ -19,20 +20,19 @@ public class RemoteSessionFactory {
private final GlobalComponentRegistry componentRegistry;
private final Curator curator;
private final ConfigCurator configCurator;
- private final Path sessionDirPath;
+ private final Path sessionPath;
private final ConfigDefinitionRepo defRepo;
private final TenantName tenant;
private final ConfigserverConfig configserverConfig;
private final Clock clock;
public RemoteSessionFactory(GlobalComponentRegistry componentRegistry,
- Path sessionsPath,
TenantName tenant,
Clock clock) {
this.componentRegistry = componentRegistry;
this.curator = componentRegistry.getCurator();
this.configCurator = componentRegistry.getConfigCurator();
- this.sessionDirPath = sessionsPath;
+ this.sessionPath = Tenants.getSessionsPath(tenant);
this.tenant = tenant;
this.defRepo = componentRegistry.getConfigDefinitionRepo();
this.configserverConfig = componentRegistry.getConfigserverConfig();
@@ -40,7 +40,7 @@ public class RemoteSessionFactory {
}
public RemoteSession createSession(long sessionId) {
- Path sessionPath = sessionDirPath.append(String.valueOf(sessionId));
+ Path sessionPath = this.sessionPath.append(String.valueOf(sessionId));
SessionZooKeeperClient sessionZKClient = new SessionZooKeeperClient(curator,
configCurator,
sessionPath,
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 659a44bb339..2269a7ed997 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
@@ -8,10 +8,12 @@ import java.util.logging.Logger;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
+import com.yahoo.config.provision.TenantName;
import com.yahoo.log.LogLevel;
import com.yahoo.path.Path;
import com.yahoo.transaction.NestedTransaction;
import com.yahoo.vespa.config.server.application.ApplicationSet;
+import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.yolean.Exceptions;
import com.yahoo.vespa.config.server.ReloadHandler;
@@ -49,19 +51,19 @@ public class RemoteSessionRepo extends SessionRepo<RemoteSession> implements Nod
* @param curator a {@link Curator} instance.
* @param remoteSessionFactory a {@link com.yahoo.vespa.config.server.session.RemoteSessionFactory}
* @param reloadHandler a {@link com.yahoo.vespa.config.server.ReloadHandler}
- * @param sessionsPath a {@link com.yahoo.path.Path} to the sessions dir.
- * @param applicationRepo an {@link TenantApplications} object.
+ * @param tenant a {@link TenantName} instance.
+ * @param applicationRepo a {@link TenantApplications} instance.
* @param executorService an {@link ExecutorService} to run callbacks from ZooKeeper.
*/
public RemoteSessionRepo(Curator curator,
- RemoteSessionFactory remoteSessionFactory,
- ReloadHandler reloadHandler,
- Path sessionsPath,
- TenantApplications applicationRepo,
- MetricUpdater metricUpdater,
- ExecutorService executorService) {
+ RemoteSessionFactory remoteSessionFactory,
+ ReloadHandler reloadHandler,
+ TenantName tenant,
+ TenantApplications applicationRepo,
+ MetricUpdater metricUpdater,
+ ExecutorService executorService) {
this.curator = curator;
- this.sessionsPath = sessionsPath;
+ this.sessionsPath = Tenants.getSessionsPath(tenant);
this.applicationRepo = applicationRepo;
this.remoteSessionFactory = remoteSessionFactory;
this.reloadHandler = reloadHandler;
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 1d5025f2e61..fdc681b5fb6 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
@@ -16,6 +16,7 @@ import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.config.server.application.TenantApplications;
import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs;
import com.yahoo.vespa.config.server.host.HostValidator;
+import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.config.server.zookeeper.SessionCounter;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
@@ -57,7 +58,6 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader {
public SessionFactoryImpl(GlobalComponentRegistry globalComponentRegistry,
SessionCounter sessionCounter,
- Path sessionsPath,
TenantApplications applicationRepo,
TenantFileSystemDirs tenantFileSystemDirs,
HostValidator<ApplicationId> hostRegistry,
@@ -68,7 +68,7 @@ public class SessionFactoryImpl implements SessionFactory, LocalSessionLoader {
this.curator = globalComponentRegistry.getCurator();
this.configCurator = globalComponentRegistry.getConfigCurator();
this.sessionCounter = sessionCounter;
- this.sessionsPath = sessionsPath;
+ this.sessionsPath = Tenants.getSessionsPath(tenant);
this.applicationRepo = applicationRepo;
this.tenantFileSystemDirs = tenantFileSystemDirs;
this.superModelGenerationCounter = globalComponentRegistry.getSuperModelGenerationCounter();
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java
index 084d35a42d4..61145c2a138 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java
@@ -34,7 +34,6 @@ public class TenantBuilder {
private final Path tenantPath;
private final GlobalComponentRegistry componentRegistry;
private final TenantName tenant;
- private final Path sessionsPath;
private RemoteSessionRepo remoteSessionRepo;
private LocalSessionRepo localSessionRepo;
private SessionFactory sessionFactory;
@@ -47,15 +46,14 @@ public class TenantBuilder {
private TenantFileSystemDirs tenantFileSystemDirs;
private HostValidator<ApplicationId> hostValidator;
- private TenantBuilder(GlobalComponentRegistry componentRegistry, TenantName tenant, Path zkPath) {
+ private TenantBuilder(GlobalComponentRegistry componentRegistry, TenantName tenant) {
this.componentRegistry = componentRegistry;
- this.tenantPath = zkPath;
+ this.tenantPath = Tenants.getTenantPath(tenant);
this.tenant = tenant;
- this.sessionsPath = tenantPath.append(Tenant.SESSIONS);
}
- public static TenantBuilder create(GlobalComponentRegistry componentRegistry, TenantName tenant, Path zkPath) {
- return new TenantBuilder(componentRegistry, tenant, zkPath);
+ public static TenantBuilder create(GlobalComponentRegistry componentRegistry, TenantName tenant) {
+ return new TenantBuilder(componentRegistry, tenant);
}
public TenantBuilder withSessionFactory(SessionFactory sessionFactory) {
@@ -123,7 +121,7 @@ public class TenantBuilder {
private void createSessionFactory() {
if (sessionFactory == null || localSessionLoader == null) {
- SessionFactoryImpl impl = new SessionFactoryImpl(componentRegistry, sessionCounter, sessionsPath,
+ SessionFactoryImpl impl = new SessionFactoryImpl(componentRegistry, sessionCounter,
applicationRepo, tenantFileSystemDirs, hostValidator, tenant);
if (sessionFactory == null) {
sessionFactory = impl;
@@ -136,13 +134,13 @@ public class TenantBuilder {
private void createApplicationRepo() {
if (applicationRepo == null) {
- applicationRepo = ZKTenantApplications.create(componentRegistry.getCurator(), tenantPath.append(Tenant.APPLICATIONS), reloadHandler, tenant);
+ applicationRepo = ZKTenantApplications.create(componentRegistry.getCurator(), reloadHandler, tenant);
}
}
private void createSessionCounter() {
if (sessionCounter == null) {
- sessionCounter = new SessionCounter(componentRegistry.getCurator(), tenantPath, sessionsPath);
+ sessionCounter = new SessionCounter(componentRegistry.getCurator(), tenant);
}
}
@@ -167,7 +165,7 @@ public class TenantBuilder {
private void createRemoteSessionFactory(Clock clock) {
if (remoteSessionFactory == null) {
- remoteSessionFactory = new RemoteSessionFactory(componentRegistry, sessionsPath, tenant, clock);
+ remoteSessionFactory = new RemoteSessionFactory(componentRegistry, tenant, clock);
}
}
@@ -176,7 +174,7 @@ public class TenantBuilder {
remoteSessionRepo = new RemoteSessionRepo(componentRegistry.getCurator(),
remoteSessionFactory,
reloadHandler,
- sessionsPath,
+ tenant,
applicationRepo,
componentRegistry.getMetrics().getOrCreateMetricUpdater(Metrics.createDimensions(tenant)),
createSingleThreadedExecutorService(RemoteSessionRepo.class.getName()));
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java
index 528a30e0191..d2cf17a38d4 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java
@@ -189,7 +189,7 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
if (tenants.containsKey(tenantName)) return;
try {
- Tenant tenant = TenantBuilder.create(globalComponentRegistry, tenantName, getTenantPath(tenantName)).build();
+ Tenant tenant = TenantBuilder.create(globalComponentRegistry, tenantName).build();
notifyNewTenant(tenant);
tenants.put(tenantName, tenant);
} catch (Exception e) {
@@ -351,6 +351,7 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
/**
* Gets zookeeper path for tenant data
+ *
* @param tenantName tenant name
* @return a {@link com.yahoo.path.Path} to the zookeeper data for a tenant
*/
@@ -358,4 +359,24 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
return tenantsPath.append(tenantName.value());
}
+ /**
+ * Gets zookeeper path for session data for a tenant
+ *
+ * @param tenantName tenant name
+ * @return a {@link com.yahoo.path.Path} to the zookeeper sessions data for a tenant
+ */
+ public static Path getSessionsPath(TenantName tenantName) {
+ return getTenantPath(tenantName).append(Tenant.SESSIONS);
+ }
+
+ /**
+ * Gets zookeeper path for application data for a tenant
+ *
+ * @param tenantName tenant name
+ * @return a {@link com.yahoo.path.Path} to the zookeeper application data for a tenant
+ */
+ public static Path getApplicationsPath(TenantName tenantName) {
+ return getTenantPath(tenantName).append(Tenant.APPLICATIONS);
+ }
+
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
index 2d95a013da9..4df292dd204 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/SessionCounter.java
@@ -1,7 +1,8 @@
// 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.zookeeper;
-import com.yahoo.path.Path;
+import com.yahoo.config.provision.TenantName;
+import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.curator.Curator;
/**
@@ -12,8 +13,10 @@ import com.yahoo.vespa.curator.Curator;
*/
public class SessionCounter extends InitializedCounter {
- public SessionCounter(Curator curator, Path rootPath, Path sessionsDir) {
- super(curator, rootPath.append("sessionCounter").getAbsolute(), sessionsDir.getAbsolute());
+ public SessionCounter(Curator curator, TenantName tenantName) {
+ super(curator,
+ Tenants.getTenantPath(tenantName).append("sessionCounter").getAbsolute(),
+ Tenants.getSessionsPath(tenantName).getAbsolute());
}
/**