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.

IndexationStatusAction.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program 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. * This program 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.ce.ws;
  21. import org.sonar.api.server.ws.Change;
  22. import org.sonar.api.server.ws.Request;
  23. import org.sonar.api.server.ws.Response;
  24. import org.sonar.api.server.ws.WebService;
  25. import org.sonar.db.DbClient;
  26. import org.sonar.db.DbSession;
  27. import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
  28. import org.sonar.server.issue.index.IssueSyncProgress;
  29. import org.sonarqube.ws.Ce.IndexationStatusWsResponse;
  30. import static org.sonar.server.ws.WsUtils.writeProtobuf;
  31. public class IndexationStatusAction implements CeWsAction {
  32. private final IssueIndexSyncProgressChecker issueIndexSyncChecker;
  33. private final DbClient dbClient;
  34. public IndexationStatusAction(DbClient dbClient, IssueIndexSyncProgressChecker issueIndexSyncChecker) {
  35. this.dbClient = dbClient;
  36. this.issueIndexSyncChecker = issueIndexSyncChecker;
  37. }
  38. @Override
  39. public void define(WebService.NewController controller) {
  40. controller.createAction("indexation_status")
  41. .setDescription("Returns the count of projects with completed issue indexing.")
  42. .setResponseExample(getClass().getResource("indexation_status-example.json"))
  43. .setChangelog(new Change("10.2", "Project count is returned instead of branch percentage."))
  44. .setHandler(this)
  45. .setInternal(true)
  46. .setSince("8.4");
  47. }
  48. @Override
  49. public void handle(Request wsRequest, Response wsResponse) throws Exception {
  50. IndexationStatusWsResponse activityResponse = doHandle();
  51. writeProtobuf(activityResponse, wsRequest, wsResponse);
  52. }
  53. private IndexationStatusWsResponse doHandle() {
  54. IssueSyncProgress issueSyncProgress;
  55. try (DbSession dbSession = dbClient.openSession(false)) {
  56. issueSyncProgress = issueIndexSyncChecker.getIssueSyncProgress(dbSession);
  57. }
  58. return IndexationStatusWsResponse.newBuilder()
  59. .setIsCompleted(issueSyncProgress.isCompleted())
  60. .setHasFailures(issueSyncProgress.hasFailures())
  61. .setCompletedCount(issueSyncProgress.getCompletedCount())
  62. .setTotal(issueSyncProgress.getTotal())
  63. .build();
  64. }
  65. }