--- /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.computation.ws;
+
+import java.util.List;
+import org.apache.ibatis.session.RowBounds;
+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.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.ce.CeActivityDto;
+import org.sonar.db.ce.CeActivityQuery;
+import org.sonar.server.user.UserSession;
+import org.sonar.server.ws.WsUtils;
+import org.sonarqube.ws.Common;
+import org.sonarqube.ws.WsCe;
+
+/**
+ * GET api/ce/activity
+ * <p>Get the past executed tasks</p>
+ */
+public class CeActivityWsAction implements CeWsAction {
+
+ private final UserSession userSession;
+ private final DbClient dbClient;
+ private final CeWsTaskFormatter formatter;
+
+ public CeActivityWsAction(UserSession userSession, DbClient dbClient, CeWsTaskFormatter formatter) {
+ this.userSession = userSession;
+ this.dbClient = dbClient;
+ this.formatter = formatter;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ controller.createAction("activity")
+ .setInternal(true)
+ .setResponseExample(getClass().getResource("CeActivityWsAction/example.json"))
+ .setHandler(this);
+ }
+
+ @Override
+ public void handle(Request wsRequest, Response wsResponse) throws Exception {
+ userSession.checkGlobalPermission(UserRole.ADMIN);
+ DbSession dbSession = dbClient.openSession(false);
+ try {
+ CeActivityQuery query = new CeActivityQuery();
+ List<CeActivityDto> dtos = dbClient.ceActivityDao().selectByQuery(dbSession, query, new RowBounds(0, 100));
+
+ WsCe.ActivityResponse.Builder wsResponseBuilder = WsCe.ActivityResponse.newBuilder();
+ wsResponseBuilder.addAllTasks(formatter.formatActivity(dbSession, dtos));
+ Common.Paging paging = Common.Paging.newBuilder()
+ .setPageIndex(1)
+ .setPageSize(dtos.size())
+ .setTotal(dtos.size())
+ .build();
+ wsResponseBuilder.setPaging(paging);
+ WsUtils.writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
+
+ } finally {
+ dbClient.closeSession(dbSession);
+ }
+ }
+}
}
WsCe.QueueResponse.Builder wsResponseBuilder = WsCe.QueueResponse.newBuilder();
- wsResponseBuilder.addAllTasks(formatter.format(dbSession, dtos));
+ wsResponseBuilder.addAllTasks(formatter.formatQueue(dbSession, dtos));
WsUtils.writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
} finally {
WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskId);
if (queueDto.isPresent()) {
- wsTaskResponse.setTask(wsTaskFormatter.format(dbSession, queueDto.get()));
+ wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get()));
} else {
Optional<CeActivityDto> activityDto = dbClient.ceActivityDao().selectByUuid(dbSession, taskId);
if (activityDto.isPresent()) {
- wsTaskResponse.setTask(wsTaskFormatter.format(dbSession, activityDto.get()));
+ wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, activityDto.get()));
} else {
throw new NotFoundException();
}
this.dbClient = dbClient;
}
- public List<WsCe.Task> format(DbSession dbSession, List<CeQueueDto> dtos) {
+ public List<WsCe.Task> formatQueue(DbSession dbSession, List<CeQueueDto> dtos) {
ComponentCache cache = new ComponentCache(dbSession);
List<WsCe.Task> result = new ArrayList<>();
for (CeQueueDto dto : dtos) {
- result.add(format(dto, cache));
+ result.add(formatQueue(dto, cache));
}
return result;
}
- public WsCe.Task format(DbSession dbSession, CeQueueDto dto) {
- return format(dto, new ComponentCache(dbSession));
+ public WsCe.Task formatQueue(DbSession dbSession, CeQueueDto dto) {
+ return formatQueue(dto, new ComponentCache(dbSession));
}
- private WsCe.Task format(CeQueueDto dto, ComponentCache componentCache) {
+ private WsCe.Task formatQueue(CeQueueDto dto, ComponentCache componentCache) {
WsCe.Task.Builder builder = WsCe.Task.newBuilder();
builder.setId(dto.getUuid());
builder.setStatus(WsCe.TaskStatus.valueOf(dto.getStatus().name()));
return builder.build();
}
- public WsCe.Task format(DbSession dbSession, CeActivityDto dto) {
- return format(dto, new ComponentCache(dbSession));
+ public WsCe.Task formatActivity(DbSession dbSession, CeActivityDto dto) {
+ return formatActivity(dto, new ComponentCache(dbSession));
}
- private WsCe.Task format(CeActivityDto dto, ComponentCache componentCache) {
+ public List<WsCe.Task> formatActivity(DbSession dbSession, List<CeActivityDto> dtos) {
+ ComponentCache cache = new ComponentCache(dbSession);
+ List<WsCe.Task> result = new ArrayList<>();
+ for (CeActivityDto dto : dtos) {
+ result.add(formatActivity(dto, cache));
+ }
+ return result;
+ }
+
+ private WsCe.Task formatActivity(CeActivityDto dto, ComponentCache componentCache) {
WsCe.Task.Builder builder = WsCe.Task.newBuilder();
builder.setId(dto.getUuid());
builder.setStatus(WsCe.TaskStatus.valueOf(dto.getStatus().name()));
import org.sonar.server.computation.ReportSubmitter;
import org.sonar.server.computation.monitoring.CEQueueStatusImpl;
import org.sonar.server.computation.monitoring.ComputeEngineQueueMonitor;
+import org.sonar.server.computation.ws.CeActivityWsAction;
import org.sonar.server.computation.ws.CeQueueWsAction;
import org.sonar.server.computation.ws.CeSubmitWsAction;
import org.sonar.server.computation.ws.CeTaskWsAction;
CeWsTaskFormatter.class,
CeTaskWsAction.class,
CeSubmitWsAction.class,
+ CeActivityWsAction.class,
CeQueueWsAction.class,
IsQueueEmptyWs.class,
DefaultPeriodCleaner.class,
--- /dev/null
+{
+ "tasks": [
+ {
+ "id": "BU_dO1vsORa8_beWCwsP",
+ "type": "REPORT",
+ "componentId": "AU-Tpxb--iU5OvuD2FLy",
+ "componentKey": "project_1",
+ "componentName": "Project One",
+ "status": "SUCCESS",
+ "submittedAt": "2015-08-13T23:34:59+0200",
+ "submitterLogin": "john",
+ "startedAt": "2015-08-13T23:35:00+0200",
+ "finishedAt": "2015-08-13T23:35:10+0200",
+ "executionTimeMs": 10000
+ },
+ {
+ "id": "AU_dO1vsORa8_beWCwmP",
+ "taskType": "REPORT",
+ "componentId": "AU_dO1vlORa8_beWCwmO",
+ "componentKey": "project_2",
+ "componentName": "Project Two",
+ "status": "FAILED",
+ "submittedAt": "2015-09-17T23:34:59+0200",
+ "startedAt": "2015-09-17T23:35:00+0200",
+ "finishedAt": "2015-08-13T23:37:00+0200",
+ "executionTimeMs": 120000
+ }
+ ]
+}
"componentId": "AU_dO1vlORa8_beWCwmO",
"componentKey": "project_2",
"componentName": "Project Two",
- "status": "IN_PROGRESS",
+ "status": "PENDING",
"submittedAt": "2015-09-17T23:34:59+0200",
"startedAt": "2015-09-17T23:35:00+0200"
}