aboutsummaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2016-12-12 09:18:51 +0100
committerHarald Musum <musum@yahoo-inc.com>2016-12-12 09:18:51 +0100
commitfad43c5b4763a591a91751dc4ae39c0a47884f57 (patch)
tree0fed0533d17e2e8c8454cd1035beafd30473af0f /configserver
parentde5aae2629450ebfd5ae2c50b404749b0d5286b1 (diff)
Refactor http session activation
* Remove unneded base class * Move everything regarding session into ApplicationRepository * Avoid using LocalSession in reponse class
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java35
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionActiveHandlerBase.java52
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java1
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java30
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java7
5 files changed, 57 insertions, 68 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 f46ed8b0aef..df49ce9ed43 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
@@ -1,6 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;
+import com.yahoo.config.application.api.ApplicationMetaData;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.HostFilter;
@@ -18,7 +19,6 @@ import com.yahoo.vespa.config.server.application.TenantApplications;
import com.yahoo.vespa.config.server.deploy.Deployment;
import com.yahoo.vespa.config.server.http.ContentHandler;
import com.yahoo.vespa.config.server.http.NotFoundException;
-import com.yahoo.vespa.config.server.http.Utils;
import com.yahoo.vespa.config.server.http.v2.ApplicationContentRequest;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.session.LocalSession;
@@ -143,7 +143,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
return true;
}
-
+
public String grabLog(Tenant tenant, ApplicationId applicationId) {
Application application = getApplication(tenant, applicationId);
return logServerLogGrabber.grabLog(application);
@@ -179,6 +179,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
return session.ensureApplicationLoaded().getForVersionOrLatest(Optional.empty());
}
+ // TODO: Don't use the NotFoundException here
public LocalSession getLocalSession(Tenant tenant, long sessionId) {
LocalSession session = tenant.getLocalSessionRepo().getSession(sessionId);
if (session == null) throw new NotFoundException("Session " + sessionId + " was not found");
@@ -186,6 +187,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
return session;
}
+ // TODO: Don't use the NotFoundException here
public RemoteSession getRemoteSession(Tenant tenant, long sessionId) {
RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId);
if (session == null) throw new NotFoundException("Session " + sessionId + " was not found");
@@ -199,8 +201,10 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
public Tenant verifyTenantAndApplication(ApplicationId applicationId) {
- final TenantName tenantName = applicationId.tenant();
- Utils.checkThatTenantExists(tenants, tenantName);
+ TenantName tenantName = applicationId.tenant();
+ if (!tenants.checkThatTenantExists(tenantName)) {
+ throw new IllegalArgumentException("Tenant " + tenantName + " was not found.");
+ }
Tenant tenant = tenants.getTenant(tenantName);
List<ApplicationId> applicationIds = listApplicationIds(tenant);
if (!applicationIds.contains(applicationId)) {
@@ -209,6 +213,29 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
return tenant;
}
+ public ApplicationId activate(Tenant tenant,
+ long sessionId,
+ TimeoutBudget timeoutBudget,
+ boolean ignoreLockFailure,
+ boolean ignoreSessionStaleFailure) {
+ LocalSession localSession = getLocalSession(tenant, sessionId);
+ LocalSessionRepo localSessionRepo = tenant.getLocalSessionRepo();
+ ActivateLock activateLock = tenant.getActivateLock();
+ // TODO: Get rid of the activateLock and localSessionRepo arguments in deployFromPreparedSession
+ Deployment deployment = deployFromPreparedSession(localSession,
+ activateLock,
+ localSessionRepo,
+ timeoutBudget.timeLeft());
+ deployment.setIgnoreLockFailure(ignoreLockFailure);
+ deployment.setIgnoreSessionStaleFailure(ignoreSessionStaleFailure);
+ deployment.activate();
+ return localSession.getApplicationId();
+ }
+
+ public ApplicationMetaData getMetadataFromSession(Tenant tenant, long sessionId) {
+ return getLocalSession(tenant, sessionId).getMetaData();
+ }
+
private List<ApplicationId> listApplicationIds(Tenant tenant) {
TenantApplications applicationRepo = tenant.getApplicationRepo();
return applicationRepo.listApplications();
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionActiveHandlerBase.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionActiveHandlerBase.java
deleted file mode 100644
index a25d598114a..00000000000
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionActiveHandlerBase.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.config.server.http;
-
-import com.yahoo.container.jdisc.HttpRequest;
-import com.yahoo.container.logging.AccessLog;
-import com.yahoo.vespa.config.server.tenant.ActivateLock;
-import com.yahoo.vespa.config.server.TimeoutBudget;
-import com.yahoo.vespa.config.server.ApplicationRepository;
-import com.yahoo.vespa.config.server.deploy.Deployment;
-import com.yahoo.vespa.config.server.session.LocalSession;
-import com.yahoo.vespa.config.server.session.LocalSessionRepo;
-
-import java.util.concurrent.Executor;
-
-/**
- * @author lulf
- */
-public class SessionActiveHandlerBase extends SessionHandler {
-
- public SessionActiveHandlerBase(Executor executor, AccessLog accessLog, ApplicationRepository applicationRepository ) {
- super(executor, accessLog, applicationRepository);
- }
-
- protected void activate(HttpRequest request,
- LocalSessionRepo localSessionRepo,
- ActivateLock activateLock,
- TimeoutBudget timeoutBudget,
- LocalSession localSession) {
- // TODO: Get rid of the activateLock and localSessionRepo arguments in deployFromPreparedSession
- Deployment deployment = applicationRepository.deployFromPreparedSession(localSession,
- activateLock,
- localSessionRepo,
- timeoutBudget.timeLeft());
- deployment.setIgnoreLockFailure(shouldIgnoreLockFailure(request));
- deployment.setIgnoreSessionStaleFailure(shouldIgnoreSessionStaleFailure(request));
- deployment.activate();
- }
-
- private boolean shouldIgnoreLockFailure(HttpRequest request) {
- return request.getBooleanProperty("force");
- }
-
- /**
- * True if this request should ignore activation failure because the session was made from an active session that is not active now
- * @param request a {@link com.yahoo.container.jdisc.HttpRequest}
- * @return true if ignore failure
- */
- private boolean shouldIgnoreSessionStaleFailure(HttpRequest request) {
- return request.getBooleanProperty("force");
- }
-
-}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java
index 28730a08e56..da8ed5530e6 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/Utils.java
@@ -5,7 +5,6 @@ import com.yahoo.config.provision.TenantName;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.jdisc.application.BindingMatch;
import com.yahoo.jdisc.application.UriPattern;
-import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.Tenants;
import java.net.URI;
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
index 135ddef4e6a..ad8b6e34e36 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandler.java
@@ -4,6 +4,8 @@ package com.yahoo.vespa.config.server.http.v2;
import java.util.concurrent.Executor;
import com.google.inject.Inject;
+import com.yahoo.config.application.api.ApplicationMetaData;
+import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.HttpRequest;
@@ -13,10 +15,8 @@ import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.vespa.config.server.TimeoutBudget;
-import com.yahoo.vespa.config.server.http.SessionActiveHandlerBase;
import com.yahoo.vespa.config.server.http.SessionHandler;
import com.yahoo.vespa.config.server.http.Utils;
-import com.yahoo.vespa.config.server.session.LocalSession;
/**
* Handler that activates a session given by tenant and id (PUT).
@@ -24,7 +24,7 @@ import com.yahoo.vespa.config.server.session.LocalSession;
* @author vegardh
* @since 5.1
*/
-public class SessionActiveHandler extends SessionActiveHandlerBase {
+public class SessionActiveHandler extends SessionHandler {
private final Tenants tenants;
private final Zone zone;
@@ -42,13 +42,29 @@ public class SessionActiveHandler extends SessionActiveHandlerBase {
@Override
protected HttpResponse handlePUT(HttpRequest request) {
- TimeoutBudget timeoutBudget = getTimeoutBudget(request, SessionHandler.DEFAULT_ACTIVATE_TIMEOUT);
final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
Utils.checkThatTenantExists(tenants, tenantName);
Tenant tenant = tenants.getTenant(tenantName);
- LocalSession localSession = applicationRepository.getLocalSession(tenant, getSessionIdV2(request));
- activate(request, tenant.getLocalSessionRepo(), tenant.getActivateLock(), timeoutBudget, localSession);
- return new SessionActiveResponse(localSession.getMetaData().getSlime(), tenantName, request, localSession, zone);
+ TimeoutBudget timeoutBudget = getTimeoutBudget(request, SessionHandler.DEFAULT_ACTIVATE_TIMEOUT);
+ final Long sessionId = getSessionIdV2(request);
+ ApplicationId applicationId = applicationRepository.activate(tenant, sessionId, timeoutBudget,
+ shouldIgnoreLockFailure(request),
+ shouldIgnoreSessionStaleFailure(request));
+ ApplicationMetaData metaData = applicationRepository.getMetadataFromSession(tenant, sessionId);
+ return new SessionActiveResponse(metaData.getSlime(), request, applicationId, sessionId, zone);
+ }
+
+ private boolean shouldIgnoreLockFailure(HttpRequest request) {
+ return request.getBooleanProperty("force");
+ }
+
+ /**
+ * True if this request should ignore activation failure because the session was made from an active session that is not active now
+ * @param request a {@link com.yahoo.container.jdisc.HttpRequest}
+ * @return true if ignore failure
+ */
+ private boolean shouldIgnoreSessionStaleFailure(HttpRequest request) {
+ return request.getBooleanProperty("force");
}
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java
index b5948c7e786..b531db3a1c3 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionActiveResponse.java
@@ -7,16 +7,15 @@ import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.slime.Slime;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.config.server.http.SessionResponse;
-import com.yahoo.vespa.config.server.session.LocalSession;
public class SessionActiveResponse extends SessionResponse {
- public SessionActiveResponse(Slime metaData, TenantName tenantName, HttpRequest request, LocalSession session, Zone zone) {
+ public SessionActiveResponse(Slime metaData, HttpRequest request, ApplicationId applicationId, long sessionId, Zone zone) {
super(metaData, metaData.get());
- String message = "Session " + session.getSessionId() + " for tenant '" + tenantName + "' activated.";
+ TenantName tenantName = applicationId.tenant();
+ String message = "Session " + sessionId + " for tenant '" + tenantName.value() + "' activated.";
root.setString("tenant", tenantName.value());
root.setString("message", message);
- final ApplicationId applicationId = session.getApplicationId();
root.setString("url", "http://" + request.getHost() + ":" + request.getPort() +
"/application/v2/tenant/" + tenantName +
"/application/" + applicationId.application().value() +