From 89c5a8c80bda8cf8520d54be9997cf1373ea6b08 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 24 Oct 2018 09:49:41 +0200 Subject: Bind the suspended url --- .../config/server/http/v2/ApplicationHandler.java | 3 ++- .../config/server/http/v2/SessionContentHandler.java | 7 +++---- .../src/main/resources/configserver-app/services.xml | 1 + .../yahoo/vespa/config/server/http/HandlerTest.java | 2 +- .../config/server/http/v2/ApplicationHandlerTest.java | 19 ++++++++++++++++++- 5 files changed, 25 insertions(+), 7 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index f05ea5eee8d..be99212c176 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -146,6 +146,7 @@ public class ApplicationHandler extends HttpHandler { "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/content/*", "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/filedistributionstatus", "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/restart", + "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/suspended", "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/serviceconverge", "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/serviceconverge/*", "http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/clustercontroller/*/status/*", @@ -155,7 +156,7 @@ public class ApplicationHandler extends HttpHandler { } private static boolean isIsSuspendedRequest(HttpRequest request) { - return getBindingMatch(request).groupCount() == 4 && + return getBindingMatch(request).groupCount() == 7 && request.getUri().getPath().endsWith("/suspended"); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java index 15faf267cce..94137f58a39 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandler.java @@ -18,17 +18,16 @@ import com.yahoo.vespa.config.server.http.Utils; * in the session's application package * * @author Ulf Lilleengen - * @since 5.1 */ public class SessionContentHandler extends SessionHandler { + private final TenantRepository tenantRepository; private final ContentHandler contentHandler = new ContentHandler(); @Inject public SessionContentHandler(SessionHandler.Context ctx, ApplicationRepository applicationRepository, - TenantRepository tenantRepository) - { + TenantRepository tenantRepository) { super(ctx, applicationRepository); this.tenantRepository = tenantRepository; } @@ -53,7 +52,7 @@ public class SessionContentHandler extends SessionHandler { } private SessionContentRequestV2 getContentRequest(HttpRequest request) { - final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request); + TenantName tenantName = Utils.getTenantNameFromSessionRequest(request); validateRequest(tenantName); long sessionId = getSessionIdV2(request); String contentPath = SessionContentRequestV2.getContentPath(request); diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml index 511cde23e89..8521ca8b31f 100644 --- a/configserver/src/main/resources/configserver-app/services.xml +++ b/configserver/src/main/resources/configserver-app/services.xml @@ -133,6 +133,7 @@ https://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/content/* http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/filedistributionstatus https://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/filedistributionstatus + http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/suspended http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/restart https://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/restart http://*/application/v2/tenant/*/application/*/environment/*/region/*/instance/*/converge diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HandlerTest.java index 5097ed1d67c..0e2cee24b60 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HandlerTest.java @@ -13,7 +13,6 @@ import static org.junit.Assert.*; * Base class for handler tests * * @author hmusum - * @since 5.1.14 */ public class HandlerTest { @@ -49,4 +48,5 @@ public class HandlerTest { public static void assertHttpStatusCodeAndMessage(HttpResponse response, int statusCode, String contentType, String message) throws IOException { assertHttpStatusCodeErrorCodeAndMessage(response, statusCode, null, contentType, message); } + } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index 149b2e17bd9..2c84e2d8ad4 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -60,10 +60,12 @@ public class ApplicationHandlerTest { private final static TenantName mytenantName = TenantName.from("mytenant"); private final static TenantName foobar = TenantName.from("foobar"); private final static ApplicationId applicationId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build(); + private TenantRepository tenantRepository; private ApplicationRepository applicationRepository; private SessionHandlerTest.MockProvisioner provisioner; private MockStateApiFactory stateApiFactory = new MockStateApiFactory(); + private OrchestratorMock orchestrator; @Before public void setup() { @@ -72,9 +74,10 @@ public class ApplicationHandlerTest { tenantRepository.addTenant(TenantBuilder.create(componentRegistry, mytenantName)); tenantRepository.addTenant(TenantBuilder.create(componentRegistry, foobar)); provisioner = new SessionHandlerTest.MockProvisioner(); + orchestrator = new OrchestratorMock(); applicationRepository = new ApplicationRepository(tenantRepository, provisioner, - new OrchestratorMock(), + orchestrator, Clock.systemUTC()); listApplicationsHandler = new ListApplicationsHandler(ListApplicationsHandler.testOnlyContext(), tenantRepository, @@ -137,6 +140,14 @@ public class ApplicationHandlerTest { assertEquals(applicationId, provisioner.lastApplicationId); } + @Test + public void testSuspended() throws Exception { + applicationRepository.deploy(testApp, prepareParams(applicationId)); + assertSuspended(false, applicationId, Zone.defaultZone()); + orchestrator.suspend(applicationId); + assertSuspended(true, applicationId, Zone.defaultZone()); + } + @Test public void testConverge() throws Exception { applicationRepository.deploy(testApp, prepareParams(applicationId)); @@ -241,6 +252,12 @@ public class ApplicationHandlerTest { assertApplicationGeneration(toUrlPath(applicationId, zone, fullAppIdInUrl), expectedGeneration); } + private void assertSuspended(boolean expectedValue, ApplicationId application, Zone zone) throws IOException { + String restartUrl = toUrlPath(application, zone, true) + "/suspended"; + HttpResponse response = createApplicationHandler().handle(HttpRequest.createTestRequest(restartUrl, com.yahoo.jdisc.http.HttpRequest.Method.GET)); + HandlerTest.assertHttpStatusCodeAndMessage(response, 200, "{\"suspended\":" + expectedValue + "}"); + } + private String toUrlPath(ApplicationId application, Zone zone, boolean fullAppIdInUrl) { String url = "http://myhost:14000/application/v2/tenant/" + application.tenant().value() + "/application/" + application.application().value(); if (fullAppIdInUrl) -- cgit v1.2.3