aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-16 16:53:38 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-17 14:33:49 +0100
commit8f75baf20d973c2d675b5e5ead86c1a0993d2413 (patch)
tree70103bc9a24dab4ae9770374a46ba88aeb2d8667
parent4b95fc51186b0f5708cd2886b076c7d2deeb509f (diff)
downloadsonarqube-8f75baf20d973c2d675b5e5ead86c1a0993d2413.tar.gz
sonarqube-8f75baf20d973c2d675b5e5ead86c1a0993d2413.zip
SONAR-7326 WS api/ce/queue removed
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java94
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/computation/ws/queue-example.json28
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java121
-rw-r--r--sonar-ws/src/main/protobuf/ws-ce.proto5
6 files changed, 1 insertions, 250 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
index 76e06f1ce7a..dacfb596435 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/CeWsModule.java
@@ -29,7 +29,6 @@ public class CeWsModule extends Module {
ActivityAction.class,
CancelAction.class,
CancelAllAction.class,
- QueueAction.class,
IsQueueEmptyWs.class,
LogsAction.class,
ComponentAction.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java
deleted file mode 100644
index f2858f33513..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.computation.ws;
-
-import java.util.List;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.web.UserRole;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.ce.CeQueueDto;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.user.UserSession;
-import org.sonar.server.ws.WsUtils;
-import org.sonarqube.ws.WsCe;
-
-public class QueueAction implements CeWsAction {
-
- public static final String PARAM_COMPONENT_UUID = "componentId";
-
- private final UserSession userSession;
- private final DbClient dbClient;
- private final TaskFormatter formatter;
-
- public QueueAction(UserSession userSession, DbClient dbClient, TaskFormatter formatter) {
- this.userSession = userSession;
- this.dbClient = dbClient;
- this.formatter = formatter;
- }
-
- @Override
- public void define(WebService.NewController controller) {
- WebService.NewAction action = controller.createAction("queue")
- .setDescription("Gets the pending and in-progress tasks. Requires system administration permission.")
- .setInternal(true)
- .setSince("5.2")
- .setResponseExample(getClass().getResource("queue-example.json"))
- .setHandler(this);
-
- action
- .createParam(PARAM_COMPONENT_UUID)
- .setDescription("Optional filter on component. Requires administration permission of the component.")
- .setExampleValue(Uuids.UUID_EXAMPLE_01);
- }
-
- @Override
- public void handle(Request wsRequest, Response wsResponse) throws Exception {
- String componentUuid = wsRequest.param(PARAM_COMPONENT_UUID);
-
- DbSession dbSession = dbClient.openSession(false);
- try {
- List<CeQueueDto> dtos;
- if (componentUuid == null) {
- // no filters
- userSession.checkPermission(UserRole.ADMIN);
- dtos = dbClient.ceQueueDao().selectAllInAscOrder(dbSession);
- } else {
- // filter by component
- if (userSession.hasPermission(GlobalPermissions.SYSTEM_ADMIN) || userSession.hasComponentUuidPermission(UserRole.ADMIN, componentUuid)) {
- dtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, componentUuid);
- } else {
- throw new ForbiddenException("Requires system administration permission");
- }
- }
-
- WsCe.QueueResponse.Builder wsResponseBuilder = WsCe.QueueResponse.newBuilder();
- wsResponseBuilder.addAllTasks(formatter.formatQueue(dbSession, dtos));
- WsUtils.writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
-
- } finally {
- dbClient.closeSession(dbSession);
- }
- }
-}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/queue-example.json b/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/queue-example.json
deleted file mode 100644
index d392ee07254..00000000000
--- a/server/sonar-server/src/main/resources/org/sonar/server/computation/ws/queue-example.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "tasks": [
- {
- "id": "BU_dO1vsORa8_beWCwsP",
- "type": "REPORT",
- "componentId": "AU-Tpxb--iU5OvuD2FLy",
- "componentKey": "project_1",
- "componentName": "Project One",
- "componentQualifier": "TRK",
- "status": "IN_PROGRESS",
- "submittedAt": "2015-08-13T23:34:59+0200",
- "submitterLogin": "john",
- "logs": true
- },
- {
- "id": "AU_dO1vsORa8_beWCwmP",
- "taskType": "REPORT",
- "componentId": "AU_dO1vlORa8_beWCwmO",
- "componentKey": "project_2",
- "componentName": "Project Two",
- "componentQualifier": "TRK",
- "status": "PENDING",
- "submittedAt": "2015-09-17T23:34:59+0200",
- "startedAt": "2015-09-17T23:35:00+0200",
- "logs": true
- }
- ]
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
index d4878ad772d..5186c1a4f41 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/CeWsModuleTest.java
@@ -30,6 +30,6 @@ public class CeWsModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new CeWsModule().configure(container);
- assertThat(container.size()).isEqualTo(12 + 2 /* injected by ComponentContainer */);
+ assertThat(container.size()).isEqualTo(11 + 2 /* injected by ComponentContainer */);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java
deleted file mode 100644
index 22d07a88f60..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.computation.ws;
-
-import com.google.common.base.Optional;
-import java.io.File;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
-import org.sonar.core.util.Protobuf;
-import org.sonar.db.DbTester;
-import org.sonar.db.ce.CeQueueDto;
-import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.log.CeLogging;
-import org.sonar.server.computation.log.LogFileRef;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonarqube.ws.MediaTypes;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.TestResponse;
-import org.sonar.server.ws.WsActionTester;
-import org.sonarqube.ws.WsCe;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class QueueActionTest {
-
- @Rule
- public UserSessionRule userSession = UserSessionRule.standalone();
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- CeLogging ceLogging = mock(CeLogging.class);
- TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), ceLogging, System2.INSTANCE);
- QueueAction underTest = new QueueAction(userSession, dbTester.getDbClient(), formatter);
- WsActionTester tester = new WsActionTester(underTest);
-
- @Before
- public void setUp() {
- when(ceLogging.getFile(any(LogFileRef.class))).thenReturn(Optional.<File>absent());
- }
-
- @Test
- public void get_all_queue() {
- userSession.setGlobalPermissions(UserRole.ADMIN);
- insert("T1", "PROJECT_1", CeQueueDto.Status.PENDING);
- insert("T2", "PROJECT_2", CeQueueDto.Status.IN_PROGRESS);
-
- TestResponse wsResponse = tester.newRequest()
- .setMediaType(MediaTypes.PROTOBUF)
- .execute();
-
- // verify the protobuf response
- WsCe.QueueResponse queueResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.QueueResponse.PARSER);
- assertThat(queueResponse.getTasksCount()).isEqualTo(2);
- assertThat(queueResponse.getTasks(0).getId()).isEqualTo("T1");
- assertThat(queueResponse.getTasks(0).getStatus()).isEqualTo(WsCe.TaskStatus.PENDING);
- assertThat(queueResponse.getTasks(0).getComponentId()).isEqualTo("PROJECT_1");
- assertThat(queueResponse.getTasks(1).getId()).isEqualTo("T2");
- assertThat(queueResponse.getTasks(1).getStatus()).isEqualTo(WsCe.TaskStatus.IN_PROGRESS);
- assertThat(queueResponse.getTasks(1).getComponentId()).isEqualTo("PROJECT_2");
- }
-
- @Test
- public void get_queue_of_project() {
- userSession.addComponentUuidPermission(UserRole.ADMIN, "PROJECT_1", "PROJECT_1");
- insert("T1", "PROJECT_1", CeQueueDto.Status.PENDING);
- insert("T2", "PROJECT_2", CeQueueDto.Status.PENDING);
- insert("T3", "PROJECT_2", CeQueueDto.Status.IN_PROGRESS);
-
- TestResponse wsResponse = tester.newRequest()
- .setParam("componentId", "PROJECT_1")
- .setMediaType(MediaTypes.PROTOBUF)
- .execute();
-
- // verify the protobuf response
- WsCe.QueueResponse queueResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.QueueResponse.PARSER);
- assertThat(queueResponse.getTasksCount()).isEqualTo(1);
- assertThat(queueResponse.getTasks(0).getId()).isEqualTo("T1");
- }
-
- @Test(expected = ForbiddenException.class)
- public void requires_admin_permission() {
- tester.newRequest()
- .setMediaType(MediaTypes.PROTOBUF)
- .execute();
- }
-
- private CeQueueDto insert(String taskUuid, String componentUuid, CeQueueDto.Status status) {
- CeQueueDto queueDto = new CeQueueDto();
- queueDto.setTaskType(CeTaskTypes.REPORT);
- queueDto.setComponentUuid(componentUuid);
- queueDto.setUuid(taskUuid);
- queueDto.setStatus(status);
- dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
- dbTester.getSession().commit();
- return queueDto;
- }
-}
diff --git a/sonar-ws/src/main/protobuf/ws-ce.proto b/sonar-ws/src/main/protobuf/ws-ce.proto
index 8a8a3f85036..1db7111abcf 100644
--- a/sonar-ws/src/main/protobuf/ws-ce.proto
+++ b/sonar-ws/src/main/protobuf/ws-ce.proto
@@ -37,11 +37,6 @@ message TaskResponse {
optional Task task = 1;
}
-// GET api/ce/queue
-message QueueResponse {
- repeated Task tasks = 1;
-}
-
// GET api/ce/activity
message ActivityResponse {
optional sonarqube.ws.commons.Paging paging = 1;