You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueueAction.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.computation.ws;
  21. import org.sonar.api.server.ws.Request;
  22. import org.sonar.api.server.ws.Response;
  23. import org.sonar.api.server.ws.WebService;
  24. import org.sonar.api.utils.text.JsonWriter;
  25. import org.sonar.db.compute.AnalysisReportDto;
  26. import org.sonar.server.computation.ReportQueue;
  27. import java.util.List;
  28. import static org.sonar.api.utils.DateUtils.longToDate;
  29. /**
  30. * @since 5.0
  31. */
  32. public class QueueAction implements ComputationWsAction {
  33. private final ReportQueue queue;
  34. public QueueAction(ReportQueue queue) {
  35. this.queue = queue;
  36. }
  37. @Override
  38. public void define(WebService.NewController controller) {
  39. controller
  40. .createAction("queue")
  41. .setDescription("List all the active analysis reports")
  42. .setSince("5.0")
  43. .setInternal(true)
  44. .setHandler(this);
  45. }
  46. @Override
  47. public void handle(Request request, Response response) throws Exception {
  48. List<AnalysisReportDto> reports = queue.all();
  49. JsonWriter json = response.newJsonWriter().beginObject();
  50. writeReports(reports, json);
  51. json.endObject();
  52. json.close();
  53. }
  54. private static void writeReports(List<AnalysisReportDto> reports, JsonWriter json) {
  55. json.name("reports").beginArray();
  56. for (AnalysisReportDto report : reports) {
  57. json.beginObject();
  58. json.prop("key", report.getId());
  59. json.prop("projectKey", report.getProjectKey());
  60. json.prop("projectName", report.getProjectName());
  61. json.propDateTime("startedAt", longToDate(report.getStartedAt()));
  62. json.propDateTime("finishedAt", longToDate(report.getFinishedAt()));
  63. json.propDateTime("submittedAt", longToDate(report.getCreatedAt()));
  64. json.prop("status", report.getStatus().toString());
  65. json.endObject();
  66. }
  67. json.endArray();
  68. }
  69. }