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;
// ws
RestartHandler.class,
- PlatformWs.class
+ SystemWs.class
);
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.ws;
-
-import org.sonar.api.server.ws.WebService;
-
-public class PlatformWs implements WebService {
-
- private final RestartHandler restartHandler;
-
- public PlatformWs(RestartHandler restartHandler) {
- this.restartHandler = restartHandler;
- }
-
- @Override
- public void define(Context context) {
- NewController controller = context.createController("api/platform")
- .setSince("4.3");
-
- restartHandler.define(controller);
-
- controller.done();
- }
-
-}
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 {
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);
}
response.noContent();
} else {
- throw new BadRequestException("Available in development mode only (sonar.dev=true)");
+ throw new ForbiddenException();
}
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+public class SystemWs implements WebService {
+
+ private final RestartHandler restartHandler;
+
+ public SystemWs(RestartHandler restartHandler) {
+ this.restartHandler = restartHandler;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/system")
+ .setSince("4.3");
+
+ restartHandler.define(controller);
+
+ controller.done();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.ws;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.platform.Platform;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class PlatformWsTest {
-
- @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);
- 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();
- }
-}
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;
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();
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);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.ws;
+
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.platform.Platform;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class SystemWsTest {
+
+ @Test
+ public void define() throws Exception {
+ Platform platform = mock(Platform.class);
+ Settings settings = new Settings();
+ RestartHandler restartHandler = new RestartHandler(settings, platform);
+ SystemWs ws = new SystemWs(restartHandler);
+ WebService.Context context = new WebService.Context();
+
+ ws.define(context);
+
+ assertThat(context.controllers()).hasSize(1);
+ assertThat(context.controller("api/system")).isNotNull();
+ assertThat(context.controller("api/system").actions()).isNotEmpty();
+ }
+}
* Synchronously start a database migration.
*/
Migration migrate(long timeoutInSeconds, long rateInSeconds);
+
+ /**
+ * Restart server. Available only in development mode.
+ * @since 4.3
+ */
+ void restart();
}
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 {
@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);
}
return migration;
}
+ @Override
+ public void restart() {
+ requestFactory.post("/api/system/restart", Collections.<String, Object>emptyMap());
+ }
+
private void sleepQuietly(long rateInMs) {
try {
Thread.sleep(rateInMs);
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 {
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());
+ }
}