3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.platform.platformlevel;
22 import org.sonar.api.utils.log.Loggers;
23 import org.sonar.core.platform.EditionProvider;
24 import org.sonar.core.platform.PlatformEditionProvider;
25 import org.sonar.server.app.ProcessCommandWrapper;
26 import org.sonar.server.ce.queue.CeQueueCleaner;
27 import org.sonar.server.es.IndexerStartupTask;
28 import org.sonar.server.platform.ServerLifecycleNotifier;
29 import org.sonar.server.platform.web.RegisterServletFilters;
30 import org.sonar.server.plugins.PluginConsentVerifier;
31 import org.sonar.server.qualitygate.ProjectsInWarningDaemon;
32 import org.sonar.server.qualitygate.RegisterQualityGates;
33 import org.sonar.server.qualityprofile.BuiltInQProfileInsertImpl;
34 import org.sonar.server.qualityprofile.BuiltInQProfileLoader;
35 import org.sonar.server.qualityprofile.BuiltInQProfileUpdateImpl;
36 import org.sonar.server.qualityprofile.BuiltInQualityProfilesUpdateListener;
37 import org.sonar.server.qualityprofile.RegisterQualityProfiles;
38 import org.sonar.server.rule.RegisterRules;
39 import org.sonar.server.rule.WebServerRuleFinder;
40 import org.sonar.server.startup.GeneratePluginIndex;
41 import org.sonar.server.startup.RegisterMetrics;
42 import org.sonar.server.startup.RegisterPermissionTemplates;
43 import org.sonar.server.startup.RegisterPlugins;
44 import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
45 import org.sonar.server.startup.UpgradeSuggestionsCleaner;
46 import org.sonar.server.user.DoPrivileged;
47 import org.sonar.server.user.ThreadLocalUserSession;
49 public class PlatformLevelStartup extends PlatformLevel {
50 public PlatformLevelStartup(PlatformLevel parent) {
51 super("startup tasks", parent);
55 protected void configureLevel() {
56 add(GeneratePluginIndex.class,
57 RegisterPlugins.class,
58 ServerLifecycleNotifier.class);
61 IndexerStartupTask.class,
62 RegisterMetrics.class,
63 RegisterQualityGates.class,
65 add(BuiltInQProfileLoader.class);
67 BuiltInQualityProfilesUpdateListener.class,
68 BuiltInQProfileInsertImpl.class,
69 BuiltInQProfileUpdateImpl.class,
70 RegisterQualityProfiles.class,
71 RegisterPermissionTemplates.class,
72 RenameDeprecatedPropertyKeys.class,
74 UpgradeSuggestionsCleaner.class,
75 PluginConsentVerifier.class);
77 // RegisterServletFilters makes the WebService engine of Level4 served by the MasterServletFilter, therefore it
78 // must be started after all the other startup tasks
79 add(RegisterServletFilters.class);
83 public PlatformLevel start() {
84 DoPrivileged.execute(new DoPrivileged.Task(get(ThreadLocalUserSession.class)) {
86 protected void doPrivileged() {
87 PlatformLevelStartup.super.start();
88 getOptional(IndexerStartupTask.class).ifPresent(IndexerStartupTask::execute);
89 // Need to be executed after indexing as it executes an ES query
90 get(ProjectsInWarningDaemon.class).notifyStart();
91 get(ServerLifecycleNotifier.class).notifyStart();
92 get(ProcessCommandWrapper.class).notifyOperational();
93 get(WebServerRuleFinder.class).stopCaching();
94 Loggers.get(PlatformLevelStartup.class)
95 .info("Running {} Edition", get(PlatformEditionProvider.class).get().map(EditionProvider.Edition::getLabel).orElse(""));