summaryrefslogtreecommitdiffstats
path: root/configserver/src/main
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2017-11-27 18:03:54 +0100
committerHarald Musum <musum@oath.com>2017-11-27 18:03:54 +0100
commit679f19d137c5c19ae3f0d4845e63b06e1fc34112 (patch)
treed34aac8a32c2cd27ce2557e30c0206e54fe8901d /configserver/src/main
parent775cbe184dcf306b38091e07d04f798d77f8873d (diff)
Do not create system tenants in constructor. Do not put into map of tenants unless absent
Diffstat (limited to 'configserver/src/main')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java17
1 files changed, 8 insertions, 9 deletions
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 d2cf17a38d4..5fb62a68e3e 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
@@ -96,18 +96,17 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
}
/**
- * New instance containing the given tenants. This will not create Zookeeper watches. For testing only
+ * New instance containing the given tenants. Creates no system tenants and noZookeeper watches. For testing only.
* @param globalComponentRegistry a {@link com.yahoo.vespa.config.server.GlobalComponentRegistry} instance
* @param tenants a collection of {@link Tenant}s
*/
+ // TODO: Get rid of the second argument and let callers use addTenant() instead
public Tenants(GlobalComponentRegistry globalComponentRegistry, Collection<Tenant> tenants) {
this.globalComponentRegistry = globalComponentRegistry;
this.curator = globalComponentRegistry.getCurator();
metricUpdater = globalComponentRegistry.getMetrics().getOrCreateMetricUpdater(Collections.emptyMap());
this.tenantListeners.add(globalComponentRegistry.getTenantListener());
curator.create(tenantsPath);
- createSystemTenants(globalComponentRegistry.getConfigserverConfig());
- createTenants();
this.directoryCache = curator.createDirectoryCache(tenantsPath.getAbsolute(), false, false, pathChildrenExecutor);
this.tenants.putAll(addTenants(tenants));
}
@@ -120,13 +119,13 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
// Pre-condition: tenants path needs to exist in zk
private LinkedHashMap<TenantName, Tenant> addTenants(Collection<Tenant> newTenants) {
- LinkedHashMap<TenantName, Tenant> sessionTenants = new LinkedHashMap<>();
+ LinkedHashMap<TenantName, Tenant> tenants = new LinkedHashMap<>();
for (Tenant t : newTenants) {
- sessionTenants.put(t.getName(), t);
+ tenants.put(t.getName(), t);
}
- log.log(LogLevel.DEBUG, "Tenants at startup: " + sessionTenants);
- metricUpdater.setTenants(tenants.size());
- return sessionTenants;
+ log.log(LogLevel.DEBUG, "Tenants at startup: " + tenants);
+ metricUpdater.setTenants(this.tenants.size());
+ return tenants;
}
public synchronized void addTenant(TenantName tenantName) throws Exception {
@@ -191,7 +190,7 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen
try {
Tenant tenant = TenantBuilder.create(globalComponentRegistry, tenantName).build();
notifyNewTenant(tenant);
- tenants.put(tenantName, tenant);
+ tenants.putIfAbsent(tenantName, tenant);
} catch (Exception e) {
log.log(LogLevel.WARNING, "Error loading tenant '" + tenantName + "', skipping.", e);
}