summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-06-19 13:38:09 +0200
committerGitHub <noreply@github.com>2020-06-19 13:38:09 +0200
commit561d1c9c20538dd2d6d095616b64aaf124560f4f (patch)
treee0bc7d178c988b4a9de697e94b979baf960a2731
parente398b94104efdb0e1b0a702a61c682d987344c20 (diff)
parente070542323d739ac932c548c531d5180e6d7fd9c (diff)
Merge pull request #13636 from vespa-engine/hmusum/configserver-refactoring-13
Merge watcher classes for sessions into one class
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java10
-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/LocalSessionStateWatcher.java74
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/Session.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java34
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java (renamed from configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionStateWatcher.java)51
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SilentDeployLogger.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenant.java4
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java14
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java5
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java22
11 files changed, 80 insertions, 144 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index c44a839d24d..becf01c191c 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -490,7 +490,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
Tenant tenant = tenantRepository.getTenant(applicationId.tenant());
if (tenant == null) throw new NotFoundException("Tenant '" + applicationId.tenant() + "' not found");
long sessionId = getSessionIdForApplication(tenant, applicationId);
- RemoteSession session = tenant.getSessionRepo().getRemoteSession(sessionId);
+ RemoteSession session = tenant.getSessionRepository().getRemoteSession(sessionId);
if (session == null) throw new NotFoundException("Remote session " + sessionId + " not found");
return session.ensureApplicationLoaded().getForVersionOrLatest(version, clock.instant());
} catch (NotFoundException e) {
@@ -528,7 +528,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
private boolean localSessionHasBeenDeleted(ApplicationId applicationId, long sessionId, Duration waitTime) {
- SessionRepository sessionRepository = tenantRepository.getTenant(applicationId.tenant()).getSessionRepo();
+ SessionRepository sessionRepository = tenantRepository.getTenant(applicationId.tenant()).getSessionRepository();
Instant end = Instant.now().plus(waitTime);
do {
if (sessionRepository.getRemoteSession(sessionId) == null) return true;
@@ -690,7 +690,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
public int deleteExpiredRemoteSessions(Clock clock, Duration expiryTime) {
return tenantRepository.getAllTenants()
.stream()
- .map(tenant -> tenant.getSessionRepo().deleteExpiredRemoteSessions(clock, expiryTime))
+ .map(tenant -> tenant.getSessionRepository().deleteExpiredRemoteSessions(clock, expiryTime))
.mapToInt(i -> i)
.sum();
}
@@ -765,7 +765,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
private RemoteSession getRemoteSession(Tenant tenant, long sessionId) {
- RemoteSession session = tenant.getSessionRepo().getRemoteSession(sessionId);
+ RemoteSession session = tenant.getSessionRepository().getRemoteSession(sessionId);
if (session == null) throw new NotFoundException("Session " + sessionId + " was not found");
return session;
@@ -816,7 +816,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
private RemoteSession getActiveSession(Tenant tenant, ApplicationId applicationId) {
TenantApplications applicationRepo = tenant.getApplicationRepo();
if (applicationRepo.activeApplications().contains(applicationId)) {
- return tenant.getSessionRepo().getRemoteSession(applicationRepo.requireActiveSessionOf(applicationId));
+ return tenant.getSessionRepository().getRemoteSession(applicationRepo.requireActiveSessionOf(applicationId));
}
return null;
}
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 def629f738c..0fb1407830a 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
@@ -63,10 +63,10 @@ public class Deployment implements com.yahoo.config.provision.Deployment {
/** The (optional) Athenz domain this application should use */
private final Optional<AthenzDomain> athenzDomain;
- private boolean prepared = false;
-
/** Whether this model should be validated (only takes effect if prepared=false) */
- private boolean validate;
+ private final boolean validate;
+
+ private boolean prepared = false;
private boolean ignoreSessionStaleFailure = false;
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionStateWatcher.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionStateWatcher.java
deleted file mode 100644
index acbb1dc81ce..00000000000
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/LocalSessionStateWatcher.java
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2018 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 java.util.logging.Level;
-import com.yahoo.text.Utf8;
-import com.yahoo.vespa.curator.Curator;
-import org.apache.curator.framework.recipes.cache.ChildData;
-
-import java.util.concurrent.Executor;
-import java.util.logging.Logger;
-
-/**
- * Watches one particular local session (/config/v2/tenants/&lt;tenantName&gt;/sessions/&lt;n&gt;/sessionState in ZooKeeper)
- * to pick up when an application is deleted (the delete might be done on any config server in the cluster)
- *
- * @author Harald Musum
- */
-public class LocalSessionStateWatcher {
-
- private static final Logger log = Logger.getLogger(LocalSessionStateWatcher.class.getName());
-
- private final Curator.FileCache fileCache;
- private final LocalSession session;
- private final SessionRepository sessionRepository;
- private final Executor zkWatcherExecutor;
-
- LocalSessionStateWatcher(Curator.FileCache fileCache, LocalSession session,
- SessionRepository sessionRepository, Executor zkWatcherExecutor) {
- this.fileCache = fileCache;
- this.session = session;
- this.sessionRepository = sessionRepository;
- this.zkWatcherExecutor = zkWatcherExecutor;
- this.fileCache.start();
- this.fileCache.addListener(this::nodeChanged);
- }
-
- // Will delete session if it exists in local session repo
- private void sessionChanged(Session.Status status) {
- long sessionId = session.getSessionId();
- log.log(status == Session.Status.DELETE ? Level.INFO : Level.FINE,
- session.logPre() + "Session change: Local session " + sessionId + " changed status to " + status);
-
- if (status.equals(Session.Status.DELETE) && sessionRepository.getLocalSession(sessionId) != null) {
- log.log(Level.FINE, session.logPre() + "Deleting session " + sessionId);
- sessionRepository.deleteLocalSession(session);
- }
- }
-
- public long getSessionId() {
- return session.getSessionId();
- }
-
- public void close() {
- try {
- fileCache.close();
- } catch (Exception e) {
- log.log(Level.WARNING, "Exception when closing watcher", e);
- }
- }
-
- public void nodeChanged() {
- zkWatcherExecutor.execute(() -> {
- try {
- ChildData node = fileCache.getCurrentData();
- if (node != null) {
- sessionChanged(Session.Status.parse(Utf8.toString(node.getData())));
- }
- } catch (Exception e) {
- log.log(Level.WARNING, session.logPre() + "Error handling session changed for session " + getSessionId(), e);
- }
- });
- }
-
-}
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 1e832548342..77058d8d6d9 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
@@ -20,6 +20,7 @@ import java.util.Optional;
* system ({@link LocalSession}s) and sessions working on zookeeper {@link RemoteSession}s.
*
* @author Ulf Lilleengen
+ * @author hmusum
*/
public abstract class Session implements Comparable<Session> {
@@ -32,6 +33,7 @@ public abstract class Session implements Comparable<Session> {
this.sessionId = sessionId;
this.sessionZooKeeperClient = sessionZooKeeperClient;
}
+
/**
* Retrieve the session id for this session.
* @return the session id.
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
index c7dc295c42d..392c5e93122 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
@@ -72,8 +72,7 @@ public class SessionRepository {
private final SessionCache<LocalSession> localSessionCache = new SessionCache<>();
private final SessionCache<RemoteSession> remoteSessionCache = new SessionCache<>();
- private final Map<Long, LocalSessionStateWatcher> localSessionStateWatchers = new HashMap<>();
- private final Map<Long, RemoteSessionStateWatcher> remoteSessionStateWatchers = new HashMap<>();
+ private final Map<Long, SessionStateWatcher> sessionStateWatchers = new HashMap<>();
private final Duration sessionLifetime;
private final Clock clock;
private final Curator curator;
@@ -120,10 +119,11 @@ public class SessionRepository {
public synchronized void addSession(LocalSession session) {
localSessionCache.addSession(session);
- Path sessionsPath = TenantRepository.getSessionsPath(session.getTenantName());
long sessionId = session.getSessionId();
- Curator.FileCache fileCache = curator.createFileCache(sessionsPath.append(String.valueOf(sessionId)).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH).getAbsolute(), false);
- localSessionStateWatchers.put(sessionId, new LocalSessionStateWatcher(fileCache, session, this, zkWatcherExecutor));
+ Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
+ RemoteSession remoteSession = new RemoteSession(tenantName, sessionId, componentRegistry, createSessionZooKeeperClient(sessionId));
+ sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, reloadHandler, remoteSession,
+ Optional.of(session), metrics, zkWatcherExecutor, this));
}
public LocalSession getLocalSession(long sessionId) {
@@ -208,7 +208,7 @@ public class SessionRepository {
public void deleteLocalSession(LocalSession session) {
long sessionId = session.getSessionId();
log.log(Level.FINE, "Deleting local session " + sessionId);
- LocalSessionStateWatcher watcher = localSessionStateWatchers.remove(sessionId);
+ SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId);
if (watcher != null) watcher.close();
localSessionCache.removeSession(sessionId);
NestedTransaction transaction = new NestedTransaction();
@@ -318,21 +318,22 @@ public class SessionRepository {
*/
public void sessionAdded(long sessionId) {
log.log(Level.FINE, () -> "Adding session to SessionRepository: " + sessionId);
- RemoteSession session = createRemoteSession(sessionId);
- Path sessionPath = sessionsPath.append(String.valueOf(sessionId));
- Curator.FileCache fileCache = curator.createFileCache(sessionPath.append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH).getAbsolute(), false);
+ RemoteSession remoteSession = createRemoteSession(sessionId);
+ Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
fileCache.addListener(this::nodeChanged);
- loadSessionIfActive(session);
- addRemoteSession(session);
- remoteSessionStateWatchers.put(sessionId, new RemoteSessionStateWatcher(fileCache, reloadHandler, session, metrics, zkWatcherExecutor));
+ loadSessionIfActive(remoteSession);
+ addRemoteSession(remoteSession);
+ Optional<LocalSession> localSession = Optional.empty();
if (distributeApplicationPackage.value()) {
- Optional<LocalSession> localSession = createLocalSessionUsingDistributedApplicationPackage(sessionId);
+ localSession = createLocalSessionUsingDistributedApplicationPackage(sessionId);
localSession.ifPresent(this::addSession);
}
+ sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, reloadHandler, remoteSession, localSession,
+ metrics, zkWatcherExecutor, this));
}
private void sessionRemoved(long sessionId) {
- RemoteSessionStateWatcher watcher = remoteSessionStateWatchers.remove(sessionId);
+ SessionStateWatcher watcher = sessionStateWatchers.remove(sessionId);
if (watcher != null) watcher.close();
remoteSessionCache.removeSession(sessionId);
metrics.incRemovedSessions();
@@ -571,10 +572,13 @@ public class SessionRepository {
return new SessionCounter(componentRegistry.getConfigCurator(), tenantName).nextSessionId();
}
- private Path getSessionPath(long sessionId) {
+ public Path getSessionPath(long sessionId) {
return sessionsPath.append(String.valueOf(sessionId));
}
+ Path getSessionStatePath(long sessionId) {
+ return getSessionPath(sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH);
+ }
private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) {
String serverId = componentRegistry.getConfigserverConfig().serverId();
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionStateWatcher.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java
index 68345d3862d..14f2ef6f271 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/RemoteSessionStateWatcher.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionStateWatcher.java
@@ -1,6 +1,7 @@
// 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 java.util.Optional;
import java.util.logging.Level;
import com.yahoo.text.Utf8;
import com.yahoo.vespa.config.server.ReloadHandler;
@@ -16,47 +17,61 @@ import java.util.logging.Logger;
* The session must be in the session repo.
*
* @author Vegard Havdal
+ * @author hmusum
*/
-public class RemoteSessionStateWatcher {
+public class SessionStateWatcher {
- private static final Logger log = Logger.getLogger(RemoteSessionStateWatcher.class.getName());
+ private static final Logger log = Logger.getLogger(SessionStateWatcher.class.getName());
private final Curator.FileCache fileCache;
private final ReloadHandler reloadHandler;
- private final RemoteSession session;
+ private final RemoteSession remoteSession;
+ private final Optional<LocalSession> localSession;
private final MetricUpdater metrics;
private final Executor zkWatcherExecutor;
+ private final SessionRepository sessionRepository;
- RemoteSessionStateWatcher(Curator.FileCache fileCache,
- ReloadHandler reloadHandler,
- RemoteSession session,
- MetricUpdater metrics,
- Executor zkWatcherExecutor) {
+ SessionStateWatcher(Curator.FileCache fileCache,
+ ReloadHandler reloadHandler,
+ RemoteSession remoteSession,
+ Optional<LocalSession> localSession,
+ MetricUpdater metrics,
+ Executor zkWatcherExecutor,
+ SessionRepository sessionRepository) {
this.fileCache = fileCache;
this.reloadHandler = reloadHandler;
- this.session = session;
+ this.remoteSession = remoteSession;
+ this.localSession = localSession;
this.metrics = metrics;
this.fileCache.start();
this.fileCache.addListener(this::nodeChanged);
this.zkWatcherExecutor = zkWatcherExecutor;
+ this.sessionRepository = sessionRepository;
}
private void sessionChanged(Session.Status status) {
+ long sessionId = remoteSession.getSessionId();
+
// valid for NEW -> PREPARE transitions, not ACTIVATE -> PREPARE.
if (status.equals(Session.Status.PREPARE)) {
- log.log(Level.FINE, session.logPre() + "Loading prepared session: " + session.getSessionId());
- session.loadPrepared();
+ log.log(Level.FINE, remoteSession.logPre() + "Loading prepared session: " + remoteSession.getSessionId());
+ remoteSession.loadPrepared();
} else if (status.equals(Session.Status.ACTIVATE)) {
- session.makeActive(reloadHandler);
+ remoteSession.makeActive(reloadHandler);
} else if (status.equals(Session.Status.DEACTIVATE)) {
- session.deactivate();
+ remoteSession.deactivate();
} else if (status.equals(Session.Status.DELETE)) {
- session.deactivate();
+ remoteSession.deactivate();
+ log.log(Level.INFO, remoteSession.logPre() + "Session change: Local session " + sessionId + " changed status to " + status);
+ localSession.ifPresent(session -> {
+ log.log(Level.FINE, session.logPre() + "Deleting session " + sessionId);
+ sessionRepository.deleteLocalSession(session);
+ });
}
}
public long getSessionId() {
- return session.getSessionId();
+ return remoteSession.getSessionId();
}
public void close() {
@@ -69,18 +84,18 @@ public class RemoteSessionStateWatcher {
private void nodeChanged() {
zkWatcherExecutor.execute(() -> {
- Session.Status currentStatus = session.getStatus();
+ Session.Status currentStatus = remoteSession.getStatus();
Session.Status newStatus = Session.Status.NONE;
try {
ChildData node = fileCache.getCurrentData();
if (node != null) {
newStatus = Session.Status.parse(Utf8.toString(node.getData()));
- log.log(Level.FINE, session.logPre() + "Session change: Remote session " + session.getSessionId() +
+ log.log(Level.FINE, remoteSession.logPre() + "Session change: Remote session " + remoteSession.getSessionId() +
" changed status from " + currentStatus.name() + " to " + newStatus.name());
sessionChanged(newStatus);
}
} catch (Exception e) {
- log.log(Level.WARNING, session.logPre() + "Error handling session change from " + currentStatus.name() +
+ log.log(Level.WARNING, remoteSession.logPre() + "Error handling session change from " + currentStatus.name() +
" to " + newStatus.name() + " for session " + getSessionId(), e);
metrics.incSessionChangeErrors();
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SilentDeployLogger.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SilentDeployLogger.java
index 92ab6b3fbf5..445837104d4 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SilentDeployLogger.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SilentDeployLogger.java
@@ -7,7 +7,7 @@ import java.util.logging.Logger;
import com.yahoo.config.application.api.DeployLogger;
/**
- * The purpose of this is to mute the log messages from model and application building in {@link RemoteSession} that is triggered by {@link RemoteSessionStateWatcher}, since those messages already
+ * The purpose of this is to mute the log messages from model and application building in {@link RemoteSession} that is triggered by {@link SessionStateWatcher}, since those messages already
* have been emitted by the prepare handler, for the same prepare operation.
*
* @author vegardh
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 f7c8ae9d5c3..cbcb96d0b36 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
@@ -66,10 +66,6 @@ public class Tenant implements TenantHandlerProvider {
return requestHandler;
}
- public SessionRepository getSessionRepo() {
- return sessionRepository;
- }
-
public TenantName getName() {
return name;
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index f0aa38a228e..8745a9bf596 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -4,7 +4,6 @@ package com.yahoo.vespa.config.server;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.config.ConfigInstance;
-import com.yahoo.config.FileReference;
import com.yahoo.config.SimpletypesConfig;
import com.yahoo.config.application.api.ApplicationMetaData;
import com.yahoo.config.model.NullConfigModelRegistry;
@@ -304,15 +303,16 @@ public class ApplicationRepositoryTest {
public void delete() {
TenantName tenantName = applicationId().tenant();
Tenant tenant = tenantRepository.getTenant(tenantName);
+ SessionRepository sessionRepository = tenant.getSessionRepository();
{
PrepareResult result = deployApp(testApp);
long sessionId = result.sessionId();
- LocalSession applicationData = tenant.getSessionRepository().getLocalSession(sessionId);
+ LocalSession applicationData = sessionRepository.getLocalSession(sessionId);
assertNotNull(applicationData);
assertNotNull(applicationData.getApplicationId());
- assertNotNull(tenant.getSessionRepo().getLocalSession(sessionId));
+ assertNotNull(sessionRepository.getLocalSession(sessionId));
assertNotNull(applicationRepository.getActiveSession(applicationId()));
- String sessionNode = TenantRepository.getSessionsPath(tenantName).append(String.valueOf(sessionId)).getAbsolute();
+ String sessionNode = sessionRepository.getSessionPath(sessionId).getAbsolute();
assertTrue(configCurator.exists(sessionNode));
TenantFileSystemDirs tenantFileSystemDirs = tenant.getApplicationRepo().getTenantFileSystemDirs();
File sessionFile = new File(tenantFileSystemDirs.sessionsPath(), String.valueOf(sessionId));
@@ -321,8 +321,8 @@ public class ApplicationRepositoryTest {
// Delete app and verify that it has been deleted from repos and provisioner
assertTrue(applicationRepository.delete(applicationId()));
assertNull(applicationRepository.getActiveSession(applicationId()));
- assertNull(tenant.getSessionRepository().getLocalSession(sessionId));
- assertNull(tenant.getSessionRepo().getLocalSession(sessionId));
+ assertNull(sessionRepository.getLocalSession(sessionId));
+ assertNull(sessionRepository.getLocalSession(sessionId));
assertTrue(provisioner.removed);
assertEquals(tenant.getName(), provisioner.lastApplicationId.tenant());
assertEquals(applicationId(), provisioner.lastApplicationId);
@@ -364,7 +364,7 @@ public class ApplicationRepositoryTest {
// A new delete should cleanup and be successful
RemoteSession activeSession = applicationRepository.getActiveSession(applicationId());
assertNull(activeSession);
- assertNull(tenant.getSessionRepo().getLocalSession(prepareResult.sessionId()));
+ assertNull(sessionRepository.getLocalSession(prepareResult.sessionId()));
assertTrue(applicationRepository.delete(applicationId()));
}
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 37181abfcf4..d8724cb4db2 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
@@ -38,8 +38,9 @@ import java.util.Collections;
*/
// TODO: Try to move testing to ApplicationRepositoryTest and avoid all the low-level setup code here
public class HostHandlerTest {
+
private static final String urlPrefix = "http://myhost:14000/application/v2/host/";
- private static File testApp = new File("src/test/apps/app");
+ private static final File testApp = new File("src/test/apps/app");
private HostHandler handler;
private final static TenantName mytenant = TenantName.from("mytenant");
@@ -55,7 +56,7 @@ public class HostHandlerTest {
TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
.modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))))
.build();
- tenant.getSessionRepo().addRemoteSession(new RemoteSession(tenant.getName(), sessionId, componentRegistry, new MockSessionZKClient(app)));
+ tenant.getSessionRepository().addRemoteSession(new RemoteSession(tenant.getName(), sessionId, componentRegistry, new MockSessionZKClient(app)));
}
@Before
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
index b9e872261c5..13a27e570c2 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
@@ -10,9 +10,7 @@ import com.yahoo.vespa.config.server.GlobalComponentRegistry;
import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.application.OrchestratorMock;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
-import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
-import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import com.yahoo.vespa.flags.FlagSource;
@@ -44,6 +42,7 @@ public class SessionRepositoryTest {
private MockCurator curator;
private TenantRepository tenantRepository;
private ApplicationRepository applicationRepository;
+ private SessionRepository sessionRepository;
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -71,6 +70,7 @@ public class SessionRepositoryTest {
new SessionHandlerTest.MockProvisioner(),
new OrchestratorMock(),
Clock.systemUTC());
+ sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
}
@Test
@@ -78,7 +78,6 @@ public class SessionRepositoryTest {
setup();
long firstSessionId = deploy();
long secondSessionId = deploy();
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
assertNotNull(sessionRepository.getLocalSession(firstSessionId));
assertNotNull(sessionRepository.getLocalSession(secondSessionId));
assertNull(sessionRepository.getLocalSession(secondSessionId + 1));
@@ -96,7 +95,6 @@ public class SessionRepositoryTest {
long firstSessionId = deploy();
long secondSessionId = deploy();
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
assertNotNull(sessionRepository.getLocalSession(firstSessionId));
assertNotNull(sessionRepository.getLocalSession(secondSessionId));
assertNull(sessionRepository.getLocalSession(secondSessionId + 1));
@@ -130,7 +128,6 @@ public class SessionRepositoryTest {
com.yahoo.path.Path session = TenantRepository.getSessionsPath(tenantName).append("" + sessionId);
curator.delete(session);
assertSessionRemoved(sessionId);
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
assertNull(sessionRepository.getRemoteSession(sessionId));
}
@@ -145,21 +142,18 @@ public class SessionRepositoryTest {
TenantName mytenant = TenantName.from("mytenant");
curator.set(TenantRepository.getApplicationsPath(mytenant).append("mytenant:appX:default"), new byte[0]); // Invalid data
tenantRepository.addTenant(mytenant);
- Tenant tenant = tenantRepository.getTenant(mytenant);
curator.create(TenantRepository.getSessionsPath(mytenant));
- SessionRepository sessionRepository = tenant.getSessionRepo();
assertThat(sessionRepository.getRemoteSessions().size(), is(0));
- createSession(sessionId, true, mytenant);
+ createSession(sessionId, true);
assertThat(sessionRepository.getRemoteSessions().size(), is(1));
}
private void createSession(long sessionId, boolean wait) {
- createSession(sessionId, wait, tenantName);
+ createSession(sessionId, wait, sessionRepository);
}
- private void createSession(long sessionId, boolean wait, TenantName tenantName) {
- com.yahoo.path.Path sessionsPath = TenantRepository.getSessionsPath(tenantName);
- SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, sessionsPath.append(String.valueOf(sessionId)));
+ private void createSession(long sessionId, boolean wait, SessionRepository sessionRepository) {
+ SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, sessionRepository.getSessionPath(sessionId));
zkc.createNewSession(Instant.now());
if (wait) {
Curator.CompletionWaiter waiter = zkc.getUploadWaiter();
@@ -168,14 +162,13 @@ public class SessionRepositoryTest {
}
private void assertStatusChange(long sessionId, Session.Status status) throws Exception {
- com.yahoo.path.Path statePath = TenantRepository.getSessionsPath(tenantName).append("" + sessionId).append(ConfigCurator.SESSIONSTATE_ZK_SUBPATH);
+ com.yahoo.path.Path statePath = sessionRepository.getSessionStatePath(sessionId);
curator.create(statePath);
curator.framework().setData().forPath(statePath.getAbsolute(), Utf8.toBytes(status.toString()));
assertRemoteSessionStatus(sessionId, status);
}
private void assertSessionRemoved(long sessionId) {
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
waitFor(p -> sessionRepository.getRemoteSession(sessionId) == null, sessionId);
assertNull(sessionRepository.getRemoteSession(sessionId));
}
@@ -185,7 +178,6 @@ public class SessionRepositoryTest {
}
private void assertRemoteSessionStatus(long sessionId, Session.Status status) {
- SessionRepository sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
waitFor(p -> sessionRepository.getRemoteSession(sessionId) != null &&
sessionRepository.getRemoteSession(sessionId).getStatus() == status, sessionId);
assertNotNull(sessionRepository.getRemoteSession(sessionId));