diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-08-29 11:42:42 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:49 +0200 |
commit | 904cd8b327790c31d1abe0bceb0007015e74dfdf (patch) | |
tree | 6b191092eb27c5da5a1ece3ac152f2df20b3d106 | |
parent | b812e849cde8fec183a7459ef92c9875f1e5e5c8 (diff) | |
download | sonarqube-904cd8b327790c31d1abe0bceb0007015e74dfdf.tar.gz sonarqube-904cd8b327790c31d1abe0bceb0007015e74dfdf.zip |
SONAR-9739 rename Cluster to WebServer
18 files changed, 86 insertions, 158 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index ca967e1b59d..0536be88443 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -120,7 +120,7 @@ import org.sonar.server.platform.ServerLogging; import org.sonar.server.platform.StartupMetadataProvider; import org.sonar.server.platform.TempFolderProvider; import org.sonar.server.platform.UrlSettings; -import org.sonar.server.platform.cluster.ClusterImpl; +import org.sonar.server.platform.WebServerImpl; import org.sonar.server.platform.db.migration.MigrationConfigurationModule; import org.sonar.server.platform.db.migration.version.DatabaseVersion; import org.sonar.server.plugins.InstalledPluginReferentialFactory; @@ -244,7 +244,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.COMPUTE_ENGINE), CeProcessLogging.class, UuidFactoryImpl.INSTANCE, - ClusterImpl.class, + WebServerImpl.class, LogbackHelper.class, DefaultDatabase.class, DatabaseChecker.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java index 33c219b7d51..f211e84e6db 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java @@ -30,7 +30,6 @@ import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.property.PropertyDto; -import org.sonar.server.platform.cluster.Cluster; import static com.google.common.base.Preconditions.checkState; import static org.apache.commons.lang.StringUtils.isBlank; @@ -39,13 +38,13 @@ import static org.sonar.api.CoreProperties.SERVER_ID; public class ServerIdManager implements Startable { private final DbClient dbClient; private final SonarRuntime runtime; - private final Cluster cluster; + private final WebServer webServer; private final UuidFactory uuidFactory; - public ServerIdManager(DbClient dbClient, SonarRuntime runtime, Cluster cluster, UuidFactory uuidFactory) { + public ServerIdManager(DbClient dbClient, SonarRuntime runtime, WebServer webServer, UuidFactory uuidFactory) { this.dbClient = dbClient; this.runtime = runtime; - this.cluster = cluster; + this.webServer = webServer; this.uuidFactory = uuidFactory; } @@ -53,7 +52,7 @@ public class ServerIdManager implements Startable { public void start() { try (DbSession dbSession = dbClient.openSession(false)) { PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(dbSession, SERVER_ID); - if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && cluster.isStartupLeader()) { + if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && webServer.isStartupLeader()) { persistServerIdIfMissingOrOldFormatted(dbSession, dto); } else { ensureServerIdIsSet(dto); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java b/server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java index 9882a7c67cd..1d210b465d0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java @@ -30,7 +30,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.property.PropertyDto; -import org.sonar.server.platform.cluster.Cluster; import static com.google.common.base.Preconditions.checkState; import static org.apache.commons.lang.StringUtils.isBlank; @@ -42,9 +41,9 @@ public class StartupMetadataProvider extends ProviderAdapter { private StartupMetadata cache = null; - public StartupMetadata provide(System2 system, SonarRuntime runtime, Cluster cluster, DbClient dbClient) { + public StartupMetadata provide(System2 system, SonarRuntime runtime, WebServer webServer, DbClient dbClient) { if (cache == null) { - if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && cluster.isStartupLeader()) { + if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && webServer.isStartupLeader()) { cache = generate(system); } else { cache = load(dbClient); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/Cluster.java b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java index 5806e4d91f3..367a73c1614 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/Cluster.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServer.java @@ -17,14 +17,15 @@ * 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.cluster; +package org.sonar.server.platform; -public interface Cluster { +public interface WebServer { /** - * Cluster is enabled when property {@link org.sonar.process.ProcessProperties#CLUSTER_ENABLED} is {@code true} + * WebServer is standalone when property {@link org.sonar.process.ProcessProperties#CLUSTER_ENABLED} is {@code false} or + * undefined. */ - boolean isEnabled(); + boolean isStandalone(); /** * The startup leader is the first node to be started in a cluster. It's the only one diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java index 08e93f695ed..a9940038bc8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/ClusterImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java @@ -17,7 +17,7 @@ * 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.cluster; +package org.sonar.server.platform; import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Loggers; @@ -25,24 +25,24 @@ import org.sonar.process.ProcessProperties; import static org.sonar.process.ProcessProperties.CLUSTER_WEB_LEADER; -public class ClusterImpl implements Cluster { +public class WebServerImpl implements WebServer { - private final boolean enabled; + private final boolean clusterEnabled; private final boolean startupLeader; - public ClusterImpl(Configuration config) { - this.enabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false); - if (this.enabled) { + public WebServerImpl(Configuration config) { + this.clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false); + if (this.clusterEnabled) { this.startupLeader = config.getBoolean(CLUSTER_WEB_LEADER).orElse(false); - Loggers.get(ClusterImpl.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower"); + Loggers.get(WebServerImpl.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower"); } else { this.startupLeader = true; } } @Override - public boolean isEnabled() { - return enabled; + public boolean isStandalone() { + return !clusterEnabled; } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/package-info.java deleted file mode 100644 index f5567b21759..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/cluster/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.platform.cluster; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java index c95b279cb2d..73e108e749d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java @@ -26,7 +26,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.Module; -import org.sonar.server.platform.cluster.Cluster; +import org.sonar.server.platform.WebServer; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -162,7 +162,7 @@ public abstract class PlatformLevel { } private boolean isStartupLeader() { - Optional<Cluster> cluster = getOptional(Cluster.class); + Optional<WebServer> cluster = getOptional(WebServer.class); checkState(cluster.isPresent(), "Cluster settings not loaded yet"); return cluster.get().isStartupLeader(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 4f67d5f0bb3..3941da73054 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -48,7 +48,7 @@ import org.sonar.server.platform.Platform; import org.sonar.server.platform.ServerFileSystemImpl; import org.sonar.server.platform.TempFolderProvider; import org.sonar.server.platform.UrlSettings; -import org.sonar.server.platform.cluster.ClusterImpl; +import org.sonar.server.platform.WebServerImpl; import org.sonar.server.platform.db.EmbeddedDatabaseFactory; import org.sonar.server.rule.index.RuleIndex; import org.sonar.server.search.EsSearchModule; @@ -124,7 +124,7 @@ public class PlatformLevel1 extends PlatformLevel { addAll(CorePropertyDefinitions.all()); // cluster - add(ClusterImpl.class); + add(WebServerImpl.class); } private void addExtraRootComponents() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterHealthRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerHealthRequestBuilderTest.java index e11fa2d1ed2..896194a4ee6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterHealthRequestBuilderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerHealthRequestBuilderTest.java @@ -33,7 +33,7 @@ import org.sonar.server.es.EsTester; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class ProxyClusterHealthRequestBuilderTest { +public class ProxyWebServerHealthRequestBuilderTest { @ClassRule public static EsTester esTester = new EsTester(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterStateRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerStateRequestBuilderTest.java index 0e709dfced4..d441dad6df1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterStateRequestBuilderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerStateRequestBuilderTest.java @@ -31,7 +31,7 @@ import org.sonar.server.es.EsTester; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class ProxyClusterStateRequestBuilderTest { +public class ProxyWebServerStateRequestBuilderTest { @ClassRule public static EsTester esTester = new EsTester(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterStatsRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerStatsRequestBuilderTest.java index d2fe6aa842d..91382390712 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterStatsRequestBuilderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyWebServerStatsRequestBuilderTest.java @@ -31,7 +31,7 @@ import org.sonar.server.es.EsTester; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -public class ProxyClusterStatsRequestBuilderTest { +public class ProxyWebServerStatsRequestBuilderTest { @ClassRule public static EsTester esTester = new EsTester(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java index b97df9224c2..42c1b93673d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java @@ -52,47 +52,47 @@ public class HealthCheckerImplTest { HealthCheckerImpl underTest = newHealthCheckerImpl(statuses.stream()); assertThat(underTest.checkNode().getStatus()) - .describedAs("%s should have been computed from %s statuses", GREEN, statuses) - .isEqualTo(GREEN); + .describedAs("%s should have been computed from %s statuses", GREEN, statuses) + .isEqualTo(GREEN); } @Test public void checkNode_returns_YELLOW_status_if_only_GREEN_and_at_least_one_YELLOW_statuses_returned_by_HealthChecks() { List<Health.Status> statuses = new ArrayList<>(); Stream.concat( - IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> YELLOW), // at least 1 YELLOW - IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN)).forEach(statuses::add); // between 0 and 19 GREEN + IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> YELLOW), // at least 1 YELLOW + IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN)).forEach(statuses::add); // between 0 and 19 GREEN Collections.shuffle(statuses); HealthCheckerImpl underTest = newHealthCheckerImpl(statuses.stream()); assertThat(underTest.checkNode().getStatus()) - .describedAs("%s should have been computed from %s statuses", YELLOW, statuses) - .isEqualTo(YELLOW); + .describedAs("%s should have been computed from %s statuses", YELLOW, statuses) + .isEqualTo(YELLOW); } @Test public void checkNode_returns_RED_status_if_at_least_one_RED_status_returned_by_HealthChecks() { List<Health.Status> statuses = new ArrayList<>(); Stream.of( - IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED - IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW - IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN + IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED + IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW + IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN ).flatMap(s -> s) - .forEach(statuses::add); + .forEach(statuses::add); Collections.shuffle(statuses); HealthCheckerImpl underTest = newHealthCheckerImpl(statuses.stream()); assertThat(underTest.checkNode().getStatus()) - .describedAs("%s should have been computed from %s statuses", RED, statuses) - .isEqualTo(RED); + .describedAs("%s should have been computed from %s statuses", RED, statuses) + .isEqualTo(RED); } @Test public void checkNode_returns_causes_of_all_HealthChecks_whichever_their_status() { NodeHealthCheck[] nodeHealthChecks = IntStream.range(0, 1 + random.nextInt(20)) - .mapToObj(s -> new HardcodedHealthNodeCheck(IntStream.range(0, random.nextInt(3)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).toArray(String[]::new))) - .map(NodeHealthCheck.class::cast) - .toArray(NodeHealthCheck[]::new); + .mapToObj(s -> new HardcodedHealthNodeCheck(IntStream.range(0, random.nextInt(3)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).toArray(String[]::new))) + .map(NodeHealthCheck.class::cast) + .toArray(NodeHealthCheck[]::new); String[] expected = Arrays.stream(nodeHealthChecks).map(NodeHealthCheck::check).flatMap(s -> s.getCauses().stream()).toArray(String[]::new); HealthCheckerImpl underTest = new HealthCheckerImpl(nodeHealthChecks); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java index 6ba5c34955f..f4138d89e5d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java @@ -33,7 +33,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.property.PropertyDto; -import org.sonar.server.platform.cluster.ClusterMock; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -52,7 +51,7 @@ public class ServerIdManagerTest { private DbClient dbClient = dbTester.getDbClient(); private DbSession dbSession = dbTester.getSession(); - private ClusterMock cluster = new ClusterMock(); + private WebServer webServer = mock(WebServer.class); private UuidFactory uuidFactory = mock(UuidFactory.class); private static SonarRuntime runtimeFor(SonarQubeSide side) { @@ -62,9 +61,9 @@ public class ServerIdManagerTest { @Test public void start_persists_new_serverId_if_server_startupLeader_and_serverId_does_not_exist() { when(uuidFactory.create()).thenReturn(SOME_UUID); - cluster.setStartupLeader(true); + when(webServer.isStartupLeader()).thenReturn(true); - new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory) + new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory) .start(); assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID)) @@ -76,9 +75,9 @@ public class ServerIdManagerTest { public void start_persists_new_serverId_if_server_startupLeader_and_serverId_is_an_old_date() { insertPropertyCoreId("20161123150657"); when(uuidFactory.create()).thenReturn(SOME_UUID); - cluster.setStartupLeader(true); + when(webServer.isStartupLeader()).thenReturn(true); - new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory) + new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory) .start(); assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID)) @@ -95,9 +94,9 @@ public class ServerIdManagerTest { public void start_persists_new_serverId_if_server_startupLeader_and_serverId_is_empty() { insertPropertyCoreId(""); when(uuidFactory.create()).thenReturn(SOME_UUID); - cluster.setStartupLeader(true); + when(webServer.isStartupLeader()).thenReturn(true); - new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory) + new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory) .start(); assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID)) @@ -107,9 +106,9 @@ public class ServerIdManagerTest { @Test public void start_fails_with_ISE_if_serverId_is_null_and_server_is_not_startupLeader() { - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); - ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory); + ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory); expectMissingCoreIdException(); @@ -119,9 +118,9 @@ public class ServerIdManagerTest { @Test public void start_fails_with_ISE_if_serverId_is_empty_and_server_is_not_startupLeader() { insertPropertyCoreId(""); - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); - ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory); + ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory); expectEmptyCoreIdException(); @@ -130,9 +129,9 @@ public class ServerIdManagerTest { @Test public void start_fails_with_ISE_if_serverId_is_null_and_not_server() { - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); - ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory); + ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), webServer, uuidFactory); expectMissingCoreIdException(); @@ -143,7 +142,7 @@ public class ServerIdManagerTest { public void start_fails_with_ISE_if_serverId_is_empty_and_not_server() { insertPropertyCoreId(""); - ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory); + ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), webServer, uuidFactory); expectEmptyCoreIdException(); @@ -153,16 +152,16 @@ public class ServerIdManagerTest { @Test public void start_does_not_fail_if_serverId_exists_and_server_is_not_startupLeader() { insertPropertyCoreId(SOME_UUID); - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); - new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory).start(); + new ServerIdManager(dbClient, runtimeFor(SERVER), webServer, uuidFactory).start(); } @Test public void start_does_not_fail_if_serverId_exists_and_not_server() { insertPropertyCoreId(SOME_UUID); - new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory).start(); + new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), webServer, uuidFactory).start(); } private void expectEmptyCoreIdException() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java index 67ae3be8a25..e4502ed72f8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java @@ -31,7 +31,6 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; import org.sonar.db.DbTester; import org.sonar.db.property.PropertyDto; -import org.sonar.server.platform.cluster.ClusterMock; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -50,28 +49,28 @@ public class StartupMetadataProviderTest { private StartupMetadataProvider underTest = new StartupMetadataProvider(); private System2 system = mock(System2.class); - private ClusterMock cluster = new ClusterMock(); + private WebServer webServer = mock(WebServer.class); @Test public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() { when(system.now()).thenReturn(A_DATE); SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); - cluster.setStartupLeader(true); + when(webServer.isStartupLeader()).thenReturn(true); - StartupMetadata metadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient()); + StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(metadata.getStartedAt()).isEqualTo(A_DATE); assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME); // keep a cache - StartupMetadata secondMetadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient()); + StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(secondMetadata).isSameAs(metadata); } @Test public void load_from_database_if_server_is_startup_follower() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); testLoadingFromDatabase(runtime, false); } @@ -93,25 +92,25 @@ public class StartupMetadataProviderTest { @Test public void fail_to_load_from_database_if_properties_are_not_persisted() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); - cluster.setStartupLeader(false); + when(webServer.isStartupLeader()).thenReturn(false); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Property sonar.core.startTime is missing in database"); - underTest.provide(system, runtime, cluster, dbTester.getDbClient()); + underTest.provide(system, runtime, webServer, dbTester.getDbClient()); } private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) { new StartupMetadataPersister(new StartupMetadata(A_DATE), dbTester.getDbClient()).start(); - cluster.setStartupLeader(isStartupLeader); + when(webServer.isStartupLeader()).thenReturn(isStartupLeader); - StartupMetadata metadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient()); + StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(metadata.getStartedAt()).isEqualTo(A_DATE); // still in database assertPersistedProperty(CoreProperties.SERVER_STARTTIME, DateUtils.formatDateTime(A_DATE)); // keep a cache - StartupMetadata secondMetadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient()); + StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(secondMetadata).isSameAs(metadata); verifyZeroInteractions(system); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/WebServerImplTest.java index 554dd8ac303..00df69a4afb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/WebServerImplTest.java @@ -17,7 +17,7 @@ * 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.cluster; +package org.sonar.server.platform; import org.junit.Rule; import org.junit.Test; @@ -26,7 +26,7 @@ import org.sonar.api.config.internal.MapSettings; import static org.assertj.core.api.Assertions.assertThat; -public class ClusterImplTest { +public class WebServerImplTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -35,9 +35,9 @@ public class ClusterImplTest { @Test public void cluster_is_disabled_by_default() { - ClusterImpl underTest = new ClusterImpl(settings.asConfig()); + WebServerImpl underTest = new WebServerImpl(settings.asConfig()); - assertThat(underTest.isEnabled()).isFalse(); + assertThat(underTest.isStandalone()).isTrue(); assertThat(underTest.isStartupLeader()).isTrue(); } @@ -46,9 +46,9 @@ public class ClusterImplTest { settings.setProperty("sonar.cluster.enabled", "true"); settings.setProperty("sonar.cluster.web.startupLeader", "true"); - ClusterImpl underTest = new ClusterImpl(settings.asConfig()); + WebServerImpl underTest = new WebServerImpl(settings.asConfig()); - assertThat(underTest.isEnabled()).isTrue(); + assertThat(underTest.isStandalone()).isFalse(); assertThat(underTest.isStartupLeader()).isTrue(); } @@ -56,9 +56,9 @@ public class ClusterImplTest { public void node_is_startup_follower_by_default_in_cluster() { settings.setProperty("sonar.cluster.enabled", "true"); - ClusterImpl underTest = new ClusterImpl(settings.asConfig()); + WebServerImpl underTest = new WebServerImpl(settings.asConfig()); - assertThat(underTest.isEnabled()).isTrue(); + assertThat(underTest.isStandalone()).isFalse(); assertThat(underTest.isStartupLeader()).isFalse(); } @@ -67,9 +67,9 @@ public class ClusterImplTest { settings.setProperty("sonar.cluster.enabled", "true"); settings.setProperty("sonar.cluster.web.startupLeader", "false"); - ClusterImpl underTest = new ClusterImpl(settings.asConfig()); + WebServerImpl underTest = new WebServerImpl(settings.asConfig()); - assertThat(underTest.isEnabled()).isTrue(); + assertThat(underTest.isStandalone()).isFalse(); assertThat(underTest.isStartupLeader()).isFalse(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterMock.java b/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterMock.java deleted file mode 100644 index 6eb4f61228e..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/cluster/ClusterMock.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.cluster; - -public class ClusterMock implements Cluster { - - private boolean enabled = false; - private boolean startupLeader = false; - - public ClusterMock setEnabled(boolean b) { - this.enabled = b; - return this; - } - - @Override - public boolean isEnabled() { - return enabled; - } - - public ClusterMock setStartupLeader(boolean b) { - this.startupLeader = b; - return this; - } - - @Override - public boolean isStartupLeader() { - return startupLeader; - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel1Test.java b/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel1Test.java index dacd3b36e1a..a4875597ce9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel1Test.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel1Test.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.utils.System2; import org.sonar.server.platform.Platform; -import org.sonar.server.platform.cluster.Cluster; +import org.sonar.server.platform.WebServer; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -39,7 +39,7 @@ public class PlatformLevel1Test { underTest.configureLevel(); assertThat(underTest.getAll(PropertyDefinition.class)).isNotEmpty(); - assertThat(underTest.getOptional(Cluster.class)).isPresent(); + assertThat(underTest.getOptional(WebServer.class)).isPresent(); assertThat(underTest.getOptional(System2.class)).isPresent(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java b/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java index ba6740d2351..ba25f1b3fd4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java @@ -28,7 +28,7 @@ import org.sonar.api.utils.System2; import org.sonar.core.platform.PluginRepository; import org.sonar.process.ProcessProperties; import org.sonar.server.platform.Platform; -import org.sonar.server.platform.cluster.Cluster; +import org.sonar.server.platform.WebServer; import org.sonar.server.platform.db.migration.charset.DatabaseCharsetChecker; import static org.assertj.core.api.Assertions.assertThat; @@ -58,7 +58,7 @@ public class PlatformLevel2Test { underTest.configure(); // some level1 components - assertThat(underTest.getOptional(Cluster.class)).isPresent(); + assertThat(underTest.getOptional(WebServer.class)).isPresent(); assertThat(underTest.getOptional(System2.class)).isPresent(); // level2 component that does not depend on cluster state @@ -77,7 +77,7 @@ public class PlatformLevel2Test { PlatformLevel2 underTest = new PlatformLevel2(level1); underTest.configure(); - assertThat(underTest.get(Cluster.class).isStartupLeader()).isFalse(); + assertThat(underTest.get(WebServer.class).isStartupLeader()).isFalse(); // level2 component that does not depend on cluster state assertThat(underTest.getOptional(PluginRepository.class)).isPresent(); |