summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java6
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSession.java14
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java12
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java141
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java55
7 files changed, 63 insertions, 170 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
index b7555ee3bfb..d90a79795cf 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/Deployment.java
@@ -185,7 +185,7 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
}
}
- private static Transaction deactivateCurrentActivateNew(RemoteSession active, LocalSession prepared, boolean ignoreStaleSessionFailure) {
+ private static Transaction deactivateCurrentActivateNew(Session active, LocalSession prepared, boolean ignoreStaleSessionFailure) {
Transaction transaction = prepared.createActivateTransaction();
if (isValidSession(active)) {
checkIfActiveHasChanged(prepared, active, ignoreStaleSessionFailure);
@@ -195,11 +195,11 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
return transaction;
}
- private static boolean isValidSession(RemoteSession session) {
+ private static boolean isValidSession(Session session) {
return session != null;
}
- private static void checkIfActiveHasChanged(LocalSession session, RemoteSession currentActiveSession, boolean ignoreStaleSessionFailure) {
+ private static void checkIfActiveHasChanged(LocalSession session, Session currentActiveSession, boolean ignoreStaleSessionFailure) {
long activeSessionAtCreate = session.getActiveSessionAtCreate();
log.log(Level.FINE, currentActiveSession.logPre() + "active session id at create time=" + activeSessionAtCreate);
if (activeSessionAtCreate == 0) return; // No active session at create
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
index e61c884cbf6..831f4ba3679 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSession.java
@@ -24,6 +24,7 @@ import com.yahoo.vespa.curator.Curator;
import java.io.File;
import java.time.Instant;
import java.util.Optional;
+import java.util.logging.Level;
/**
* A LocalSession is a session that has been created locally on this configserver. A local session can be edited and
@@ -67,6 +68,7 @@ public class LocalSession extends Session implements Comparable<LocalSession> {
Path tenantPath,
Instant now) {
applicationRepo.createApplication(params.getApplicationId()); // TODO jvenstad: This is wrong, but it has to be done now, since preparation can change the application ID of a session :(
+ logger.log(Level.FINE, "Created application " + params.getApplicationId());
Curator.CompletionWaiter waiter = zooKeeperClient.createPrepareWaiter();
ConfigChangeActions actions = sessionPreparer.prepare(hostValidator, logger, params,
currentActiveApplicationSet, tenantPath, now,
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 a1d767b0d1c..d0082d34114 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
@@ -140,22 +140,8 @@ public class RemoteSession extends Session {
return zooKeeperClient.getAllocatedHosts();
}
- // Note: Assumes monotonically increasing session ids
- public boolean isNewerThan(long sessionId) {
- return getSessionId() > sessionId;
- }
-
- public Transaction createDeactivateTransaction() {
- return createSetStatusTransaction(Status.DEACTIVATE);
- }
-
- private Transaction createSetStatusTransaction(Status status) {
- return zooKeeperClient.createWriteStatusTransaction(status);
- }
-
public ApplicationMetaData getMetaData() {
return zooKeeperClient.loadApplicationPackage().getMetaData();
}
-
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java
index a57bfeda12e..7803bd05e0a 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java
@@ -8,6 +8,7 @@ import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.AthenzDomain;
import com.yahoo.config.provision.DockerImage;
import com.yahoo.config.provision.TenantName;
+import com.yahoo.transaction.Transaction;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import java.time.Instant;
@@ -116,4 +117,15 @@ public abstract class Session {
return zooKeeperClient.getAllocatedHosts();
}
+ public Transaction createDeactivateTransaction() {
+ return createSetStatusTransaction(Status.DEACTIVATE);
+ }
+
+ private Transaction createSetStatusTransaction(Status status) {
+ return zooKeeperClient.createWriteStatusTransaction(status);
+ }
+
+ // Note: Assumes monotonically increasing session ids
+ public boolean isNewerThan(long sessionId) { return getSessionId() > sessionId; }
+
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java
index bbd3ae55f10..f0aab8b2312 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java
@@ -38,7 +38,6 @@ public class Tenant implements TenantHandlerProvider {
private final Curator curator;
Tenant(TenantName name,
- Path path,
SessionFactory sessionFactory,
LocalSessionRepo localSessionRepo,
RemoteSessionRepo remoteSessionRepo,
@@ -47,7 +46,7 @@ public class Tenant implements TenantHandlerProvider {
TenantApplications applicationRepo,
Curator curator) {
this.name = name;
- this.path = path;
+ this.path = TenantRepository.getTenantPath(name);
this.requestHandler = requestHandler;
this.reloadHandler = reloadHandler;
this.remoteSessionRepo = remoteSessionRepo;
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
deleted file mode 100644
index 108892803c1..00000000000
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java
+++ /dev/null
@@ -1,141 +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.tenant;
-
-import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.config.provision.TenantName;
-import com.yahoo.vespa.config.server.rpc.ConfigResponseFactory;
-import com.yahoo.vespa.config.server.GlobalComponentRegistry;
-import com.yahoo.vespa.config.server.host.HostValidator;
-import com.yahoo.vespa.config.server.RequestHandler;
-import com.yahoo.vespa.config.server.application.TenantApplications;
-import com.yahoo.vespa.config.server.session.*;
-
-import java.util.Collections;
-
-/**
- * Builder for helping out with tenant creation. Each of a tenants dependencies may be overridden for testing.
- *
- * @author Ulf Lilleengen
- */
-public class TenantBuilder {
-
- private final GlobalComponentRegistry componentRegistry;
- private final TenantName tenant;
- private RemoteSessionRepo remoteSessionRepo;
- private LocalSessionRepo localSessionRepo;
- private SessionFactory sessionFactory;
- private LocalSessionLoader localSessionLoader;
- private TenantApplications applicationRepo;
- private TenantRequestHandler reloadHandler;
- private RequestHandler requestHandler;
- private RemoteSessionFactory remoteSessionFactory;
- private HostValidator<ApplicationId> hostValidator;
-
- private TenantBuilder(GlobalComponentRegistry componentRegistry, TenantName tenant) {
- this.componentRegistry = componentRegistry;
- this.tenant = tenant;
- }
-
- public static TenantBuilder create(GlobalComponentRegistry componentRegistry, TenantName tenant) {
- return new TenantBuilder(componentRegistry, tenant);
- }
-
- public TenantBuilder withSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- return this;
- }
-
- public TenantBuilder withLocalSessionRepo(LocalSessionRepo localSessionRepo) {
- this.localSessionRepo = localSessionRepo;
- return this;
- }
-
- public TenantBuilder withApplicationRepo(TenantApplications applicationRepo) {
- this.applicationRepo = applicationRepo;
- return this;
- }
-
- public TenantBuilder withRequestHandler(RequestHandler requestHandler) {
- this.requestHandler = requestHandler;
- return this;
- }
-
- /**
- * Create a real tenant from the properties given by this builder.
- *
- * @return a new {@link Tenant} instance.
- */
- public Tenant build() {
- createTenantRequestHandler();
- createApplicationRepo();
- createRemoteSessionFactory();
- createRemoteSessionRepo();
- createSessionFactory();
- createLocalSessionRepo();
- return new Tenant(tenant,
- TenantRepository.getTenantPath(tenant),
- sessionFactory,
- localSessionRepo,
- remoteSessionRepo,
- requestHandler,
- reloadHandler,
- applicationRepo,
- componentRegistry.getCurator());
- }
-
- private void createLocalSessionRepo() {
- if (localSessionRepo == null) {
- localSessionRepo = new LocalSessionRepo(tenant, componentRegistry, localSessionLoader);
- }
- }
-
- private void createSessionFactory() {
- if (sessionFactory == null || localSessionLoader == null) {
- SessionFactoryImpl impl = new SessionFactoryImpl(componentRegistry, applicationRepo, hostValidator, tenant);
- if (sessionFactory == null) {
- sessionFactory = impl;
- }
- if (localSessionLoader == null) {
- localSessionLoader = impl;
- }
- }
- }
-
- private void createApplicationRepo() {
- if (applicationRepo == null) {
- applicationRepo = reloadHandler.applications();
- }
- }
-
- private void createTenantRequestHandler() {
- if (requestHandler == null || reloadHandler == null) {
- TenantRequestHandler impl = new TenantRequestHandler(componentRegistry.getMetrics(),
- tenant,
- Collections.singletonList(componentRegistry.getReloadListener()),
- ConfigResponseFactory.create(componentRegistry.getConfigserverConfig()),
- componentRegistry);
- this.hostValidator = impl;
- if (requestHandler == null) {
- requestHandler = impl;
- }
- reloadHandler = impl;
- }
- }
-
- private void createRemoteSessionFactory() {
- if (remoteSessionFactory == null) {
- remoteSessionFactory = new RemoteSessionFactory(componentRegistry, tenant);
- }
- }
-
- private void createRemoteSessionRepo() {
- remoteSessionRepo = new RemoteSessionRepo(componentRegistry,
- remoteSessionFactory,
- reloadHandler,
- tenant,
- applicationRepo);
-
- }
-
- public TenantName getTenantName() { return tenant; }
-}
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 0ae5ca86215..3c4ed16d669 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
@@ -7,10 +7,19 @@ import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.concurrent.StripedExecutor;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
-import java.util.logging.Level;
import com.yahoo.path.Path;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
+import com.yahoo.vespa.config.server.ReloadHandler;
+import com.yahoo.vespa.config.server.RequestHandler;
+import com.yahoo.vespa.config.server.application.TenantApplications;
+import com.yahoo.vespa.config.server.host.HostValidator;
import com.yahoo.vespa.config.server.monitoring.MetricUpdater;
+import com.yahoo.vespa.config.server.rpc.ConfigResponseFactory;
+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;
import com.yahoo.vespa.curator.Curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
@@ -35,6 +44,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -137,12 +147,13 @@ public class TenantRepository {
}
public synchronized void addTenant(TenantName tenantName) {
- addTenant(TenantBuilder.create(globalComponentRegistry, tenantName));
+ addTenant(tenantName, null, null);
}
- public synchronized void addTenant(TenantBuilder builder) {
- writeTenantPath(builder.getTenantName());
- createTenant(builder);
+ public synchronized void addTenant(TenantName tenantName, RequestHandler requestHandler,
+ ReloadHandler reloadHandler) {
+ writeTenantPath(tenantName);
+ createTenant(tenantName, requestHandler, reloadHandler);
}
private static Set<TenantName> readTenantsFromZooKeeper(Curator curator) {
@@ -193,17 +204,41 @@ public class TenantRepository {
}
}
- private void createTenant(TenantName tenantName) {
- createTenant(TenantBuilder.create(globalComponentRegistry, tenantName));
+ protected void createTenant(TenantName tenantName) {
+ createTenant(tenantName, null, null);
}
// Creates tenant and all its dependencies. This also includes loading active applications
- protected void createTenant(TenantBuilder builder) {
- TenantName tenantName = builder.getTenantName();
+ private void createTenant(TenantName tenantName, RequestHandler requestHandler, ReloadHandler reloadHandler) {
if (tenants.containsKey(tenantName)) return;
+ TenantRequestHandler tenantRequestHandler = null;
+ if (requestHandler == null) {
+ tenantRequestHandler = new TenantRequestHandler(globalComponentRegistry.getMetrics(),
+ tenantName,
+ List.of(globalComponentRegistry.getReloadListener()),
+ ConfigResponseFactory.create(globalComponentRegistry.getConfigserverConfig()),
+ globalComponentRegistry);
+ requestHandler = tenantRequestHandler;
+ }
+
+ if (reloadHandler == null && tenantRequestHandler != null)
+ reloadHandler = tenantRequestHandler;
+
+ HostValidator<ApplicationId> hostValidator = tenantRequestHandler;
+ TenantApplications applicationRepo = TenantApplications.create(globalComponentRegistry,
+ reloadHandler,
+ tenantName);
+ SessionFactory sessionFactory = new SessionFactoryImpl(globalComponentRegistry, applicationRepo, hostValidator, tenantName);
+ LocalSessionRepo localSessionRepo = new LocalSessionRepo(tenantName, globalComponentRegistry);
+ RemoteSessionRepo remoteSessionRepo = new RemoteSessionRepo(globalComponentRegistry,
+ new RemoteSessionFactory(globalComponentRegistry, tenantName),
+ reloadHandler,
+ tenantName,
+ applicationRepo);
log.log(Level.INFO, "Creating tenant '" + tenantName + "'");
- Tenant tenant = builder.build();
+ Tenant tenant = new Tenant(tenantName, sessionFactory, localSessionRepo, remoteSessionRepo, requestHandler,
+ reloadHandler, applicationRepo, globalComponentRegistry.getCurator());
notifyNewTenant(tenant);
tenants.putIfAbsent(tenantName, tenant);
}