diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-10-18 17:21:27 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-10-18 19:40:47 +0200 |
commit | e1014a2f6b27cf1abc92c35b4f84d49485045677 (patch) | |
tree | a3ac66bf819aaa6eb3bf0882913009ce60320231 | |
parent | 76558f8bb1c7c7fff227e343d764656e97094453 (diff) | |
download | sonarqube-e1014a2f6b27cf1abc92c35b4f84d49485045677.tar.gz sonarqube-e1014a2f6b27cf1abc92c35b4f84d49485045677.zip |
Support High Availability plugin
6 files changed, 179 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterFeature.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterFeature.java new file mode 100644 index 00000000000..61262ad0ac0 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterFeature.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform; + +import org.sonar.api.ExtensionPoint; +import org.sonar.api.server.ServerSide; + +@ServerSide +@ExtensionPoint +public interface ClusterFeature { + + boolean isEnabled(); + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterVerification.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterVerification.java new file mode 100644 index 00000000000..2b3565b552a --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ClusterVerification.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform; + +import javax.annotation.Nullable; +import org.sonar.api.Startable; +import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.MessageException; + +@ServerSide +public class ClusterVerification implements Startable { + + private final WebServer server; + @Nullable + private final ClusterFeature feature; + + public ClusterVerification(WebServer server, @Nullable ClusterFeature feature) { + this.server = server; + this.feature = feature; + } + + public ClusterVerification(WebServer server) { + this(server, null); + } + + @Override + public void start() { + if (server.isStandalone()) { + return; + } + if (feature == null || !feature.isEnabled()) { + throw MessageException.of("Cluster mode can't be enabled. Please install the High Availability plugin."); + } + } + + @Override + public void stop() { + // nothing to do + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java index 367a73c1614..8655720607d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java @@ -19,6 +19,11 @@ */ package org.sonar.server.platform; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.server.ServerSide; + +@ComputeEngineSide +@ServerSide public interface WebServer { /** diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index b7ef5fd0193..56376b8e7a2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -105,6 +105,7 @@ import org.sonar.server.permission.index.PermissionIndexer; import org.sonar.server.permission.ws.PermissionsWsModule; import org.sonar.server.permission.ws.template.DefaultTemplatesResolverImpl; import org.sonar.server.platform.BackendCleanup; +import org.sonar.server.platform.ClusterVerification; import org.sonar.server.platform.PersistentSettings; import org.sonar.server.platform.ServerLogging; import org.sonar.server.platform.SettingsChangeNotifier; @@ -252,6 +253,7 @@ public class PlatformLevel4 extends PlatformLevel { ChangeLogLevelStandaloneService.class); add( + ClusterVerification.class, LogServerId.class, LogOAuthWarning.class, PluginDownloader.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ClusterVerificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ClusterVerificationTest.java new file mode 100644 index 00000000000..25ee2c8f2f5 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ClusterVerificationTest.java @@ -0,0 +1,83 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.MessageException; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterVerificationTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private WebServer webServer = mock(WebServer.class); + private ClusterFeature feature = mock(ClusterFeature.class); + + @Test + public void throw_MessageException_if_cluster_is_enabled_but_HA_plugin_is_not_installed() { + when(webServer.isStandalone()).thenReturn(false); + + ClusterVerification underTest = new ClusterVerification(webServer); + + expectedException.expect(MessageException.class); + expectedException.expectMessage("Cluster mode can't be enabled. Please install the High Availability plugin."); + underTest.start(); + } + + @Test + public void throw_MessageException_if_cluster_is_enabled_but_HA_feature_is_not_enabled() { + when(webServer.isStandalone()).thenReturn(false); + when(feature.isEnabled()).thenReturn(false); + ClusterVerification underTest = new ClusterVerification(webServer, feature); + + expectedException.expect(MessageException.class); + expectedException.expectMessage("Cluster mode can't be enabled. Please install the High Availability plugin."); + underTest.start(); + } + + @Test + public void do_not_fail_if_cluster_is_enabled_and_HA_feature_is_enabled() { + when(webServer.isStandalone()).thenReturn(false); + when(feature.isEnabled()).thenReturn(true); + ClusterVerification underTest = new ClusterVerification(webServer, feature); + + // no failure + underTest.start(); + underTest.stop(); + } + + @Test + public void do_not_fail_if_cluster_is_disabled() { + when(webServer.isStandalone()).thenReturn(true); + + ClusterVerification underTest = new ClusterVerification(webServer); + + // no failure + underTest.start(); + underTest.stop(); + } + + +} diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java index 4063610440e..5bcbcb6bebe 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java @@ -56,7 +56,7 @@ public class PluginLoader { * Defines the base keys (defined by {@link #basePluginKey(PluginInfo, Map)}) of the plugins which are allowed to * run a full server extensions. */ - private static final Set<String> PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>(asList("billing", "branch", "developer", "governance", "license"))); + private static final Set<String> PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>(asList("billing", "branch", "developer", "governance", "ha", "license"))); public static final Version COMPATIBILITY_MODE_MAX_VERSION = Version.create("5.2"); |