aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-03-21 16:40:07 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-03-21 16:40:15 +0100
commit4a77e99189510fd586d57900a7e9d7742647ff58 (patch)
tree732bcf005828d824bb4ed5ac86b6d08828d148aa
parentbe698baf4b4519eb43b5494be23a04703a550c9a (diff)
downloadsonarqube-4a77e99189510fd586d57900a7e9d7742647ff58.tar.gz
sonarqube-4a77e99189510fd586d57900a7e9d7742647ff58.zip
SONAR-4843 move URL to /api/system/restart and complete ws-client
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ws/RestartHandler.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ws/SystemWs.java (renamed from sonar-server/src/main/java/org/sonar/server/platform/ws/PlatformWs.java)6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java10
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java (renamed from sonar-server/src/test/java/org/sonar/server/platform/ws/PlatformWsTest.java)8
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/system/SystemClient.java6
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/system/internal/DefaultSystemClient.java9
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/system/internal/DefaultSystemClientTest.java11
8 files changed, 40 insertions, 20 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index d9dd54c0e01..2c8b84ed6fa 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -95,7 +95,7 @@ import org.sonar.server.notifications.NotificationService;
import org.sonar.server.permission.InternalPermissionService;
import org.sonar.server.permission.InternalPermissionTemplateService;
import org.sonar.server.permission.PermissionFinder;
-import org.sonar.server.platform.ws.PlatformWs;
+import org.sonar.server.platform.ws.SystemWs;
import org.sonar.server.platform.ws.RestartHandler;
import org.sonar.server.plugins.*;
import org.sonar.server.qualitygate.QgateProjectFinder;
@@ -191,7 +191,7 @@ class ServerComponents {
// ws
RestartHandler.class,
- PlatformWs.class
+ SystemWs.class
);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartHandler.java b/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartHandler.java
index 75b080a21f3..d40d0651887 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartHandler.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartHandler.java
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.platform.Platform;
public class RestartHandler implements RequestHandler {
@@ -41,7 +41,7 @@ public class RestartHandler implements RequestHandler {
void define(WebService.NewController controller) {
controller.createAction("restart")
- .setDescription("Restart server. Available only in development mode.")
+ .setDescription("Restart server. Available only on development mode (sonar.dev=true)")
.setPost(true)
.setHandler(this);
}
@@ -56,7 +56,7 @@ public class RestartHandler implements RequestHandler {
response.noContent();
} else {
- throw new BadRequestException("Available in development mode only (sonar.dev=true)");
+ throw new ForbiddenException();
}
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ws/PlatformWs.java b/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemWs.java
index ee9b878e103..282eb8b840f 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ws/PlatformWs.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemWs.java
@@ -21,17 +21,17 @@ package org.sonar.server.platform.ws;
import org.sonar.api.server.ws.WebService;
-public class PlatformWs implements WebService {
+public class SystemWs implements WebService {
private final RestartHandler restartHandler;
- public PlatformWs(RestartHandler restartHandler) {
+ public SystemWs(RestartHandler restartHandler) {
this.restartHandler = restartHandler;
}
@Override
public void define(Context context) {
- NewController controller = context.createController("api/platform")
+ NewController controller = context.createController("api/system")
.setSince("4.3");
restartHandler.define(controller);
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java
index 03b2b3d6428..ca18bb20d2f 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java
@@ -22,10 +22,9 @@ package org.sonar.server.platform.ws;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.server.ws.WsTester;
-import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.platform.Platform;
-import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -39,7 +38,7 @@ public class RestartHandlerTest {
Settings settings = new Settings();
settings.setProperty("sonar.dev", true);
RestartHandler restartHandler = new RestartHandler(settings, platform);
- PlatformWs ws = new PlatformWs(restartHandler);
+ SystemWs ws = new SystemWs(restartHandler);
WsTester tester = new WsTester(ws);
tester.newRequest("restart").execute();
@@ -52,14 +51,13 @@ public class RestartHandlerTest {
Platform platform = mock(Platform.class);
Settings settings = new Settings();
RestartHandler restartHandler = new RestartHandler(settings, platform);
- PlatformWs ws = new PlatformWs(restartHandler);
+ SystemWs ws = new SystemWs(restartHandler);
WsTester tester = new WsTester(ws);
try {
tester.newRequest("restart").execute();
fail();
- } catch (BadRequestException e) {
- assertThat(e).hasMessage("Available in development mode only (sonar.dev=true)");
+ } catch (ForbiddenException e) {
verifyZeroInteractions(platform);
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ws/PlatformWsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
index bd29268a20b..97800606bb3 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ws/PlatformWsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
@@ -27,20 +27,20 @@ import org.sonar.server.platform.Platform;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-public class PlatformWsTest {
+public class SystemWsTest {
@Test
public void define() throws Exception {
Platform platform = mock(Platform.class);
Settings settings = new Settings();
RestartHandler restartHandler = new RestartHandler(settings, platform);
- PlatformWs ws = new PlatformWs(restartHandler);
+ SystemWs ws = new SystemWs(restartHandler);
WebService.Context context = new WebService.Context();
ws.define(context);
assertThat(context.controllers()).hasSize(1);
- assertThat(context.controller("api/platform")).isNotNull();
- assertThat(context.controller("api/platform").actions()).isNotEmpty();
+ assertThat(context.controller("api/system")).isNotNull();
+ assertThat(context.controller("api/system").actions()).isNotEmpty();
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/system/SystemClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/system/SystemClient.java
index db5d48620a4..297925efaa2 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/system/SystemClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/system/SystemClient.java
@@ -33,4 +33,10 @@ public interface SystemClient {
* Synchronously start a database migration.
*/
Migration migrate(long timeoutInSeconds, long rateInSeconds);
+
+ /**
+ * Restart server. Available only in development mode.
+ * @since 4.3
+ */
+ void restart();
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/system/internal/DefaultSystemClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/system/internal/DefaultSystemClient.java
index a385ca3ce5d..7eacea238b4 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/system/internal/DefaultSystemClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/system/internal/DefaultSystemClient.java
@@ -24,7 +24,7 @@ import org.sonar.wsclient.internal.HttpRequestFactory;
import org.sonar.wsclient.system.Migration;
import org.sonar.wsclient.system.SystemClient;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.Map;
public class DefaultSystemClient implements SystemClient {
@@ -37,7 +37,7 @@ public class DefaultSystemClient implements SystemClient {
@Override
public Migration migrate() {
- String json = requestFactory.post("/api/server/setup", new HashMap<String, Object>());
+ String json = requestFactory.post("/api/server/setup", Collections.<String, Object>emptyMap());
return jsonToMigration(json);
}
@@ -61,6 +61,11 @@ public class DefaultSystemClient implements SystemClient {
return migration;
}
+ @Override
+ public void restart() {
+ requestFactory.post("/api/system/restart", Collections.<String, Object>emptyMap());
+ }
+
private void sleepQuietly(long rateInMs) {
try {
Thread.sleep(rateInMs);
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/system/internal/DefaultSystemClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/system/internal/DefaultSystemClientTest.java
index b2c05a2ef83..7d550852fda 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/system/internal/DefaultSystemClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/system/internal/DefaultSystemClientTest.java
@@ -25,11 +25,14 @@ import org.sonar.wsclient.MockHttpServerInterceptor;
import org.sonar.wsclient.internal.HttpRequestFactory;
import org.sonar.wsclient.system.Migration;
+import java.util.Collections;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class DefaultSystemClientTest {
@@ -112,4 +115,12 @@ public class DefaultSystemClientTest {
assertThat(e.getMessage()).isEqualTo("State is not set");
}
}
+
+ @Test
+ public void restart() {
+ HttpRequestFactory requestFactory = mock(HttpRequestFactory.class);
+ DefaultSystemClient client = new DefaultSystemClient(requestFactory);
+ client.restart();
+ verify(requestFactory).post("/api/system/restart", Collections.<String, Object>emptyMap());
+ }
}