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.

UninstallAction.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 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.edition.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.server.edition.EditionManagementState.PendingStatus;
  25. import org.sonar.server.edition.MutableEditionManagementState;
  26. import org.sonar.server.exceptions.BadRequestException;
  27. import org.sonar.server.plugins.edition.EditionInstaller;
  28. import org.sonar.server.user.UserSession;
  29. import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE;
  30. import static org.sonar.server.edition.EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS;
  31. public class UninstallAction implements EditionsWsAction {
  32. private final UserSession userSession;
  33. private final MutableEditionManagementState mutableEditionManagementState;
  34. private final EditionInstaller editionInstaller;
  35. public UninstallAction(UserSession userSession, MutableEditionManagementState mutableEditionManagementState, EditionInstaller editionInstaller) {
  36. this.userSession = userSession;
  37. this.mutableEditionManagementState = mutableEditionManagementState;
  38. this.editionInstaller = editionInstaller;
  39. }
  40. @Override
  41. public void define(WebService.NewController controller) {
  42. controller.createAction("uninstall")
  43. .setSince("6.7")
  44. .setPost(true)
  45. .setDescription("Uninstall the currently installed edition. Requires 'Administer System' permission.")
  46. .setHandler(this);
  47. }
  48. @Override
  49. public void handle(Request request, Response response) throws Exception {
  50. userSession.checkLoggedIn().checkIsSystemAdministrator();
  51. PendingStatus status = mutableEditionManagementState.getPendingInstallationStatus();
  52. if (status != NONE && status != UNINSTALL_IN_PROGRESS) {
  53. throw BadRequestException.create("Uninstall of the current edition is not allowed when install of an edition is in progress");
  54. }
  55. editionInstaller.uninstall();
  56. mutableEditionManagementState.uninstall();
  57. response.noContent();
  58. }
  59. }