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.

PlatformLevelStartup.java 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.platform.platformlevel;
  21. import org.sonar.api.utils.log.Loggers;
  22. import org.sonar.core.platform.EditionProvider;
  23. import org.sonar.core.platform.PlatformEditionProvider;
  24. import org.sonar.server.app.ProcessCommandWrapper;
  25. import org.sonar.server.es.IndexerStartupTask;
  26. import org.sonar.server.organization.DefaultOrganizationEnforcer;
  27. import org.sonar.server.platform.ServerLifecycleNotifier;
  28. import org.sonar.server.platform.web.RegisterServletFilters;
  29. import org.sonar.server.qualitygate.ProjectsInWarningDaemon;
  30. import org.sonar.server.qualitygate.RegisterQualityGates;
  31. import org.sonar.server.qualityprofile.BuiltInQProfileInsertImpl;
  32. import org.sonar.server.qualityprofile.BuiltInQProfileLoader;
  33. import org.sonar.server.qualityprofile.BuiltInQProfileUpdateImpl;
  34. import org.sonar.server.qualityprofile.BuiltInQualityProfilesUpdateListener;
  35. import org.sonar.server.qualityprofile.RegisterQualityProfiles;
  36. import org.sonar.server.rule.RegisterRules;
  37. import org.sonar.server.rule.WebServerRuleFinder;
  38. import org.sonar.server.startup.GeneratePluginIndex;
  39. import org.sonar.server.startup.RegisterMetrics;
  40. import org.sonar.server.startup.RegisterPermissionTemplates;
  41. import org.sonar.server.startup.RegisterPlugins;
  42. import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
  43. import org.sonar.server.user.DoPrivileged;
  44. import org.sonar.server.user.ThreadLocalUserSession;
  45. public class PlatformLevelStartup extends PlatformLevel {
  46. public PlatformLevelStartup(PlatformLevel parent) {
  47. super("startup tasks", parent);
  48. }
  49. @Override
  50. protected void configureLevel() {
  51. add(GeneratePluginIndex.class,
  52. RegisterPlugins.class,
  53. ServerLifecycleNotifier.class,
  54. DefaultOrganizationEnforcer.class);
  55. addIfStartupLeader(
  56. IndexerStartupTask.class,
  57. RegisterMetrics.class,
  58. RegisterQualityGates.class,
  59. RegisterRules.class);
  60. add(BuiltInQProfileLoader.class);
  61. addIfStartupLeader(
  62. BuiltInQualityProfilesUpdateListener.class,
  63. BuiltInQProfileInsertImpl.class,
  64. BuiltInQProfileUpdateImpl.class,
  65. RegisterQualityProfiles.class,
  66. RegisterPermissionTemplates.class,
  67. RenameDeprecatedPropertyKeys.class);
  68. // RegisterServletFilters makes the WebService engine of Level4 served by the MasterServletFilter, therefor it
  69. // must be started after all the other startup tasks
  70. add(RegisterServletFilters.class);
  71. }
  72. @Override
  73. public PlatformLevel start() {
  74. DoPrivileged.execute(new DoPrivileged.Task(get(ThreadLocalUserSession.class)) {
  75. @Override
  76. protected void doPrivileged() {
  77. PlatformLevelStartup.super.start();
  78. getOptional(IndexerStartupTask.class).ifPresent(IndexerStartupTask::execute);
  79. // Need to be executed after indexing as it executes an ES query
  80. get(ProjectsInWarningDaemon.class).notifyStart();
  81. get(ServerLifecycleNotifier.class).notifyStart();
  82. get(ProcessCommandWrapper.class).notifyOperational();
  83. get(WebServerRuleFinder.class).stopCaching();
  84. Loggers.get(PlatformLevelStartup.class)
  85. .info("Running {} Edition", get(PlatformEditionProvider.class).get().map(EditionProvider.Edition::getLabel).orElse(""));
  86. }
  87. });
  88. return this;
  89. }
  90. }