]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14128 Renamed WebServer to NodeInformation
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Wed, 21 Dec 2022 08:15:42 +0000 (09:15 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 23 Dec 2022 20:02:51 +0000 (20:02 +0000)
38 files changed:
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
server/sonar-server-common/src/main/java/org/sonar/server/platform/DefaultNodeInformation.java [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/platform/NodeInformation.java [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java
server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServer.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServerImpl.java [deleted file]
server/sonar-server-common/src/test/java/org/sonar/server/platform/DefaultNodeInformationTest.java [new file with mode: 0644]
server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java
server/sonar-server-common/src/test/java/org/sonar/server/platform/WebServerImplTest.java [deleted file]
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ClusterVerification.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterVerificationTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/health/HealthCheckerImpl.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModule.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/HealthCheckerModule.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/RestartAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/projectdump/ExportSubmitterImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/CancelActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelServiceModuleTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevelTest.java

index b8dc9456d7ad8142882e008655e462c34cedc891..811b41814dc4c1ea2049901518c893979c5c0937 100644 (file)
@@ -49,7 +49,7 @@ import org.sonar.db.ce.CeTaskCharacteristicDto;
 import org.sonar.db.ce.DeleteIf;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.property.InternalProperties;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -69,13 +69,13 @@ public class CeQueueImpl implements CeQueue {
   private final System2 system2;
   private final DbClient dbClient;
   private final UuidFactory uuidFactory;
-  protected final WebServer webServer;
+  protected final NodeInformation nodeInformation;
 
-  public CeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, WebServer webServer) {
+  public CeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, NodeInformation nodeInformation) {
     this.system2 = system2;
     this.dbClient = dbClient;
     this.uuidFactory = uuidFactory;
-    this.webServer = webServer;
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
@@ -246,7 +246,7 @@ public class CeQueueImpl implements CeQueue {
 
   private void cancelImpl(DbSession dbSession, CeQueueDto q) {
     CeActivityDto activityDto = new CeActivityDto(q);
-    activityDto.setNodeName(webServer.getNodeName().orElse(null));
+    activityDto.setNodeName(nodeInformation.getNodeName().orElse(null));
     activityDto.setStatus(CeActivityDto.Status.CANCELED);
     remove(dbSession, q, activityDto);
   }
@@ -255,7 +255,7 @@ public class CeQueueImpl implements CeQueue {
   public void fail(DbSession dbSession, CeQueueDto task, @Nullable String errorType, @Nullable String errorMessage) {
     checkState(IN_PROGRESS.equals(task.getStatus()), "Task is not in-progress and can't be marked as failed [uuid=%s]", task.getUuid());
     CeActivityDto activityDto = new CeActivityDto(task);
-    activityDto.setNodeName(webServer.getNodeName().orElse(null));
+    activityDto.setNodeName(nodeInformation.getNodeName().orElse(null));
     activityDto.setStatus(CeActivityDto.Status.FAILED);
     activityDto.setErrorType(errorType);
     activityDto.setErrorMessage(errorMessage);
index 548bf5da50b8b4a2710c91968e871aa4cceb5bbf..121c60d07c491ebae4ea832f5aa1713927865452 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserTesting;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static com.google.common.collect.ImmutableList.of;
 import static java.util.Arrays.asList;
@@ -72,9 +72,9 @@ public class CeQueueImplTest {
 
   private UuidFactory uuidFactory = new SequenceUuidFactory();
 
-  private WebServer nodeInformationProvider = mock(WebServer.class);
+  private NodeInformation nodeInformation = mock(NodeInformation.class);
 
-  private CeQueue underTest = new CeQueueImpl(system2, db.getDbClient(), uuidFactory, nodeInformationProvider);
+  private CeQueue underTest = new CeQueueImpl(system2, db.getDbClient(), uuidFactory, nodeInformation);
 
   @Test
   public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
@@ -395,7 +395,7 @@ public class CeQueueImplTest {
 
   @Test
   public void cancel_pending_whenNodeNameProvided_setItInCeActivity() {
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.of(NODE_NAME));
+    when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
     CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
 
@@ -408,7 +408,7 @@ public class CeQueueImplTest {
 
   @Test
   public void cancel_pending_whenNodeNameNOtProvided_setNulInCeActivity() {
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.empty());
+    when(nodeInformation.getNodeName()).thenReturn(Optional.empty());
     CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
 
@@ -521,7 +521,7 @@ public class CeQueueImplTest {
 
   @Test
   public void fail_in_progress_task_whenNodeNameProvided_setsItInCeActivityDto() {
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.of(NODE_NAME));
+    when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
     CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
     CeQueueDto queueDto = db.getDbClient().ceQueueDao().tryToPeek(db.getSession(), task.getUuid(), WORKER_UUID).get();
 
index c6e84e7209c697c31926eb4d2fe51bca0afdfe6f..847bc10c2dcd1925901f2d3ce8a1a381cf553d17 100644 (file)
@@ -114,6 +114,7 @@ import org.sonar.server.metric.UnanalyzedLanguageMetrics;
 import org.sonar.server.notification.DefaultNotificationManager;
 import org.sonar.server.notification.NotificationService;
 import org.sonar.server.notification.email.EmailNotificationChannel;
+import org.sonar.server.platform.DefaultNodeInformation;
 import org.sonar.server.platform.OfficialDistribution;
 import org.sonar.server.platform.ServerFileSystemImpl;
 import org.sonar.server.platform.ServerImpl;
@@ -121,7 +122,6 @@ import org.sonar.server.platform.ServerLifecycleNotifier;
 import org.sonar.server.platform.StartupMetadataProvider;
 import org.sonar.server.platform.TempFolderProvider;
 import org.sonar.server.platform.UrlSettings;
-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.platform.monitoring.DbSection;
@@ -281,7 +281,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
       CeProcessLogging.class,
       UuidFactoryImpl.INSTANCE,
       NetworkUtilsImpl.INSTANCE,
-      WebServerImpl.class,
+      DefaultNodeInformation.class,
       LogbackHelper.class,
       DefaultDatabase.class,
       MyBatis.class,
index a95a102f4a5baea4b476c6a9e249e47c7a2d6f77..ae2ec86afcffced287759a2f5c66951c585dfc33 100644 (file)
@@ -47,7 +47,7 @@ import org.sonar.db.ce.CeQueueDao;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskCharacteristicDto;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
@@ -66,8 +66,8 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
   private final NextPendingTaskPicker nextPendingTaskPicker;
 
   public InternalCeQueueImpl(System2 system2, DbClient dbClient, UuidFactory uuidFactory, CEQueueStatus queueStatus,
-    ComputeEngineStatus computeEngineStatus, NextPendingTaskPicker nextPendingTaskPicker, WebServer webServer) {
-    super(system2, dbClient, uuidFactory, webServer);
+    ComputeEngineStatus computeEngineStatus, NextPendingTaskPicker nextPendingTaskPicker, NodeInformation nodeInformation) {
+    super(system2, dbClient, uuidFactory, nodeInformation);
     this.dbClient = dbClient;
     this.queueStatus = queueStatus;
     this.computeEngineStatus = computeEngineStatus;
@@ -114,7 +114,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
       CeQueueDto queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, task.getUuid())
         .orElseThrow(() -> new IllegalStateException("Task does not exist anymore: " + task));
       CeActivityDto activityDto = new CeActivityDto(queueDto);
-      activityDto.setNodeName(webServer.getNodeName().orElse(null));
+      activityDto.setNodeName(nodeInformation.getNodeName().orElse(null));
       activityDto.setStatus(status);
       executionTimeInMs = updateExecutionFields(activityDto);
       updateTaskResult(activityDto, taskResult);
@@ -178,7 +178,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
       List<CeQueueDto> wornOutTasks = dbClient.ceQueueDao().selectWornout(dbSession);
       wornOutTasks.forEach(queueDto -> {
         CeActivityDto activityDto = new CeActivityDto(queueDto);
-        activityDto.setNodeName(webServer.getNodeName().orElse(null));
+        activityDto.setNodeName(nodeInformation.getNodeName().orElse(null));
         activityDto.setStatus(CeActivityDto.Status.CANCELED);
         updateExecutionFields(activityDto);
         remove(dbSession, queueDto, activityDto);
index 445b29ec849ebdb51c720688ebcc58965ed931d4..3bd879066987e8f94a90a46002879c703bce7209 100644 (file)
@@ -48,7 +48,7 @@ import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyMap;
@@ -83,15 +83,15 @@ public class InternalCeQueueImplTest {
   private ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
   private Configuration config = mock(Configuration.class);
   private NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
-  private WebServer nodeInformationProvider = mock(WebServer.class);
+  private NodeInformation nodeInformation = mock(NodeInformation.class);
   private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
-    computeEngineStatus, nextPendingTaskPicker, nodeInformationProvider);
+    computeEngineStatus, nextPendingTaskPicker, nodeInformation);
 
   @Before
   public void setUp() {
     when(config.getBoolean(any())).thenReturn(Optional.of(false));
     when(computeEngineStatus.getStatus()).thenReturn(STARTED);
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.of(NODE_NAME));
+    when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
   }
 
   @Test
@@ -215,8 +215,8 @@ public class InternalCeQueueImplTest {
   }
 
   @Test
-  public void remove_sets_nodeName_in_CeActivity_when_nodeInformationProvider_defines_node_name() {
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.of(NODE_NAME));
+  public void remove_sets_nodeName_in_CeActivity_when_nodeInformation_defines_node_name() {
+    when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
     CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
@@ -228,8 +228,8 @@ public class InternalCeQueueImplTest {
   }
 
   @Test
-  public void remove_do_not_set_nodeName_in_CeActivity_when_nodeInformationProvider_does_not_define_node_name() {
-    when(nodeInformationProvider.getNodeName()).thenReturn(Optional.empty());
+  public void remove_do_not_set_nodeName_in_CeActivity_when_nodeInformation_does_not_define_node_name() {
+    when(nodeInformation.getNodeName()).thenReturn(Optional.empty());
     CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
 
     Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
@@ -278,7 +278,7 @@ public class InternalCeQueueImplTest {
     db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
     db.commit();
 
-    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatus, null, null, nodeInformationProvider);
+    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatus, null, null, nodeInformation);
 
     try {
       underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null);
@@ -295,7 +295,7 @@ public class InternalCeQueueImplTest {
     CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
     db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
     db.commit();
-    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformationProvider);
+    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
 
     try {
       underTest.remove(task, CeActivityDto.Status.FAILED, null, null);
@@ -313,7 +313,7 @@ public class InternalCeQueueImplTest {
     CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
     db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'");
     db.commit();
-    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformationProvider);
+    InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
 
     underTest.cancelWornOuts();
 
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/DefaultNodeInformation.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/DefaultNodeInformation.java
new file mode 100644 (file)
index 0000000..4ebbb98
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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 java.util.Optional;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.utils.log.Loggers;
+
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
+import static org.sonar.process.ProcessProperties.Property.CLUSTER_WEB_STARTUP_LEADER;
+
+public class DefaultNodeInformation implements NodeInformation {
+
+  private final boolean clusterEnabled;
+  private final boolean startupLeader;
+  private final String nodeName;
+
+  public DefaultNodeInformation(Configuration config) {
+    this.clusterEnabled = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
+    if (this.clusterEnabled) {
+      this.startupLeader = config.getBoolean(CLUSTER_WEB_STARTUP_LEADER.getKey()).orElse(false);
+      this.nodeName = config.get(CLUSTER_NODE_NAME.getKey()).orElse(CLUSTER_NODE_NAME.getDefaultValue());
+      Loggers.get(DefaultNodeInformation.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower");
+    } else {
+      this.startupLeader = true;
+      this.nodeName = null;
+    }
+  }
+
+  @Override
+  public boolean isStandalone() {
+    return !clusterEnabled;
+  }
+
+  @Override
+  public boolean isStartupLeader() {
+    return startupLeader;
+  }
+
+  @Override
+  public Optional<String> getNodeName() {
+    return Optional.ofNullable(nodeName);
+  }
+}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/NodeInformation.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/NodeInformation.java
new file mode 100644 (file)
index 0000000..3ea80d3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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 java.util.Optional;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.server.ServerSide;
+
+@ComputeEngineSide
+@ServerSide
+public interface NodeInformation {
+
+  /**
+   * Node is standalone when property {@link org.sonar.process.ProcessProperties.Property#CLUSTER_ENABLED} is {@code false} or
+   * undefined.
+   */
+  boolean isStandalone();
+
+  /**
+   * The startup leader is the first node to be started in a cluster. It's the only one
+   * to create and populate datastores.
+   * A standard node is automatically marked as "startup leader" when cluster
+   * is disabled (default).
+   */
+  boolean isStartupLeader();
+
+  Optional<String> getNodeName();
+
+}
index 19e714c9a287e39d5ded6b9070a983774514bc0b..f9eb25e4afba387381c2032f955602dde633b604 100644 (file)
@@ -39,8 +39,8 @@ import static org.sonar.api.CoreProperties.SERVER_STARTTIME;
 @ServerSide
 public class StartupMetadataProvider {
   @Bean("StartupMetadata")
-  public StartupMetadata provide(System2 system, SonarRuntime runtime, WebServer webServer, DbClient dbClient) {
-    if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && webServer.isStartupLeader()) {
+  public StartupMetadata provide(System2 system, SonarRuntime runtime, NodeInformation nodeInformation, DbClient dbClient) {
+    if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && nodeInformation.isStartupLeader()) {
       return generate(system);
     } else {
       return load(dbClient);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServer.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServer.java
deleted file mode 100644 (file)
index 97b7ffe..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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 java.util.Optional;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.server.ServerSide;
-
-@ComputeEngineSide
-@ServerSide
-public interface WebServer {
-
-  /**
-   * Node is standalone when property {@link org.sonar.process.ProcessProperties.Property#CLUSTER_ENABLED} is {@code false} or
-   * undefined.
-   */
-  boolean isStandalone();
-
-  /**
-   * The startup leader is the first node to be started in a cluster. It's the only one
-   * to create and populate datastores.
-   * A standard node is automatically marked as "startup leader" when cluster
-   * is disabled (default).
-   */
-  boolean isStartupLeader();
-
-  Optional<String> getNodeName();
-
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServerImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/WebServerImpl.java
deleted file mode 100644 (file)
index 07f3797..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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 java.util.Optional;
-import org.sonar.api.config.Configuration;
-import org.sonar.api.utils.log.Loggers;
-
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME;
-import static org.sonar.process.ProcessProperties.Property.CLUSTER_WEB_STARTUP_LEADER;
-
-public class WebServerImpl implements WebServer {
-
-  private final boolean clusterEnabled;
-  private final boolean startupLeader;
-  private final String nodeName;
-
-  public WebServerImpl(Configuration config) {
-    this.clusterEnabled = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
-    if (this.clusterEnabled) {
-      this.startupLeader = config.getBoolean(CLUSTER_WEB_STARTUP_LEADER.getKey()).orElse(false);
-      this.nodeName = config.get(CLUSTER_NODE_NAME.getKey()).orElse(CLUSTER_NODE_NAME.getDefaultValue());
-      Loggers.get(WebServerImpl.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower");
-    } else {
-      this.startupLeader = true;
-      this.nodeName = null;
-    }
-  }
-
-  @Override
-  public boolean isStandalone() {
-    return !clusterEnabled;
-  }
-
-  @Override
-  public boolean isStartupLeader() {
-    return startupLeader;
-  }
-
-  @Override
-  public Optional<String> getNodeName() {
-    return Optional.ofNullable(nodeName);
-  }
-}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/DefaultNodeInformationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/DefaultNodeInformationTest.java
new file mode 100644 (file)
index 0000000..bc8a98d
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.Test;
+import org.sonar.api.config.internal.MapSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultNodeInformationTest {
+
+
+  private MapSettings settings = new MapSettings();
+
+  @Test
+  public void cluster_is_disabled_by_default() {
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.isStandalone()).isTrue();
+    assertThat(underTest.isStartupLeader()).isTrue();
+  }
+
+  @Test
+  public void node_is_startup_leader_in_cluster() {
+    settings.setProperty("sonar.cluster.enabled", "true");
+    settings.setProperty("sonar.cluster.web.startupLeader", "true");
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.isStandalone()).isFalse();
+    assertThat(underTest.isStartupLeader()).isTrue();
+  }
+
+  @Test
+  public void node_is_startup_follower_by_default_in_cluster() {
+    settings.setProperty("sonar.cluster.enabled", "true");
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.isStandalone()).isFalse();
+    assertThat(underTest.isStartupLeader()).isFalse();
+  }
+
+  @Test
+  public void node_is_startup_follower_in_cluster() {
+    settings.setProperty("sonar.cluster.enabled", "true");
+    settings.setProperty("sonar.cluster.web.startupLeader", "false");
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.isStandalone()).isFalse();
+    assertThat(underTest.isStartupLeader()).isFalse();
+  }
+
+  @Test
+  public void getNodeName_whenNotACluster_isEmpty() {
+    settings.setProperty("sonar.cluster.enabled", "false");
+    settings.setProperty("sonar.cluster.node.name", "nameIgnored");
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.getNodeName()).isEmpty();
+  }
+
+  @Test
+  public void getNodeName_whenClusterAndNameNotDefined_fallbacksToDefaultName() {
+    settings.setProperty("sonar.cluster.enabled", "true");
+    settings.removeProperty("sonar.cluster.node.name");
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.getNodeName()).isNotEmpty();
+    String nodeNameFirstCallToGetNodeName = underTest.getNodeName().get();
+    assertThat(nodeNameFirstCallToGetNodeName).startsWith("sonarqube-");
+    String nodeNameSecondCallToGetNodeName = underTest.getNodeName().get();
+    assertThat(nodeNameFirstCallToGetNodeName).isEqualTo(nodeNameSecondCallToGetNodeName);
+  }
+
+  @Test
+  public void getNodeName_whenClusterAndNameDefined_returnName() {
+    String nodeName = "nodeName1";
+    settings.setProperty("sonar.cluster.enabled", "true");
+    settings.setProperty("sonar.cluster.node.name", nodeName);
+
+    DefaultNodeInformation underTest = new DefaultNodeInformation(settings.asConfig());
+
+    assertThat(underTest.getNodeName()).isNotEmpty();
+    assertThat(underTest.getNodeName().get()).startsWith(nodeName);
+  }
+
+}
index 1b1eb7f902a5e448378d1f20338fd045b5042ae3..ae8bc202d2bf7f702499461a1a41ea8806e08a0a 100644 (file)
@@ -46,15 +46,15 @@ public class StartupMetadataProviderTest {
 
   private final StartupMetadataProvider underTest = new StartupMetadataProvider();
   private final System2 system = mock(System2.class);
-  private final WebServer webServer = mock(WebServer.class);
+  private final NodeInformation nodeInformation = mock(NodeInformation.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, SonarEdition.COMMUNITY);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
-    StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
+    StartupMetadata metadata = underTest.provide(system, runtime, nodeInformation, dbTester.getDbClient());
     assertThat(metadata.getStartedAt()).isEqualTo(A_DATE);
 
     assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME);
@@ -63,7 +63,7 @@ public class StartupMetadataProviderTest {
   @Test
   public void load_from_database_if_server_is_startup_follower() {
     SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
     testLoadingFromDatabase(runtime, false);
   }
@@ -85,9 +85,9 @@ 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, SonarEdition.COMMUNITY);
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
-    assertThatThrownBy(() -> underTest.provide(system, runtime, webServer, dbTester.getDbClient()))
+    assertThatThrownBy(() -> underTest.provide(system, runtime, nodeInformation, dbTester.getDbClient()))
       .isInstanceOf(IllegalStateException.class)
       .hasMessage("Property sonar.core.startTime is missing in database");
   }
@@ -95,9 +95,9 @@ public class StartupMetadataProviderTest {
   private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) {
     dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)),
       null, null,null, null);
-    when(webServer.isStartupLeader()).thenReturn(isStartupLeader);
+    when(nodeInformation.isStartupLeader()).thenReturn(isStartupLeader);
 
-    StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
+    StartupMetadata metadata = underTest.provide(system, runtime, nodeInformation, dbTester.getDbClient());
     assertThat(metadata.getStartedAt()).isEqualTo(A_DATE);
 
     // still in database
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/WebServerImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/WebServerImplTest.java
deleted file mode 100644 (file)
index 9b1998a..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.Test;
-import org.sonar.api.config.internal.MapSettings;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class WebServerImplTest {
-
-
-  private MapSettings settings = new MapSettings();
-
-  @Test
-  public void cluster_is_disabled_by_default() {
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.isStandalone()).isTrue();
-    assertThat(underTest.isStartupLeader()).isTrue();
-  }
-
-  @Test
-  public void node_is_startup_leader_in_cluster() {
-    settings.setProperty("sonar.cluster.enabled", "true");
-    settings.setProperty("sonar.cluster.web.startupLeader", "true");
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.isStandalone()).isFalse();
-    assertThat(underTest.isStartupLeader()).isTrue();
-  }
-
-  @Test
-  public void node_is_startup_follower_by_default_in_cluster() {
-    settings.setProperty("sonar.cluster.enabled", "true");
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.isStandalone()).isFalse();
-    assertThat(underTest.isStartupLeader()).isFalse();
-  }
-
-  @Test
-  public void node_is_startup_follower_in_cluster() {
-    settings.setProperty("sonar.cluster.enabled", "true");
-    settings.setProperty("sonar.cluster.web.startupLeader", "false");
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.isStandalone()).isFalse();
-    assertThat(underTest.isStartupLeader()).isFalse();
-  }
-
-  @Test
-  public void getNodeName_whenNotACluster_isEmpty() {
-    settings.setProperty("sonar.cluster.enabled", "false");
-    settings.setProperty("sonar.cluster.node.name", "nameIgnored");
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.getNodeName()).isEmpty();
-  }
-
-  @Test
-  public void getNodeName_whenClusterAndNameNotDefined_fallbacksToDefaultName() {
-    settings.setProperty("sonar.cluster.enabled", "true");
-    settings.removeProperty("sonar.cluster.node.name");
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.getNodeName()).isNotEmpty();
-    String nodeNameFirstCallToGetNodeName = underTest.getNodeName().get();
-    assertThat(nodeNameFirstCallToGetNodeName).startsWith("sonarqube-");
-    String nodeNameSecondCallToGetNodeName = underTest.getNodeName().get();
-    assertThat(nodeNameFirstCallToGetNodeName).isEqualTo(nodeNameSecondCallToGetNodeName);
-  }
-
-  @Test
-  public void getNodeName_whenClusterAndNameDefined_returnName() {
-    String nodeName = "nodeName1";
-    settings.setProperty("sonar.cluster.enabled", "true");
-    settings.setProperty("sonar.cluster.node.name", nodeName);
-
-    WebServerImpl underTest = new WebServerImpl(settings.asConfig());
-
-    assertThat(underTest.getNodeName()).isNotEmpty();
-    assertThat(underTest.getNodeName().get()).startsWith(nodeName);
-  }
-
-}
index 25a8e4c1ce005732bc51a738815498738c347552..5816db58f6b760cd33ff0e11584a808ca80c4f15 100644 (file)
  */
 package org.sonar.server.platform;
 
+import javax.annotation.Nullable;
+import javax.inject.Inject;
 import org.sonar.api.Startable;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.MessageException;
 
-import javax.annotation.Nullable;
-import javax.inject.Inject;
-
 @ServerSide
 public class ClusterVerification implements Startable {
 
-  private final WebServer server;
+  private final NodeInformation server;
   @Nullable
   private final ClusterFeature feature;
 
   @Inject
-  public ClusterVerification(WebServer server, @Nullable ClusterFeature feature) {
+  public ClusterVerification(NodeInformation server, @Nullable ClusterFeature feature) {
     this.server = server;
     this.feature = feature;
   }
 
-  public ClusterVerification(WebServer server) {
+  public ClusterVerification(NodeInformation server) {
     this(server, null);
   }
 
index fa73319f0bde80b1d6bac9fff064434ecddffab5..062e6037e14bca11974cb728fa3aad0e0c45392a 100644 (file)
@@ -37,21 +37,21 @@ import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection;
 import org.sonar.server.platform.monitoring.cluster.EsClusterStateSection;
 import org.sonar.server.platform.monitoring.cluster.GlobalInfoLoader;
 import org.sonar.server.platform.monitoring.cluster.GlobalSystemSection;
-import org.sonar.server.platform.monitoring.cluster.ServerPushSection;
 import org.sonar.server.platform.monitoring.cluster.NodeSystemSection;
 import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
 import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoaderImpl;
+import org.sonar.server.platform.monitoring.cluster.ServerPushSection;
 
 public class SystemInfoWriterModule extends Module {
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
 
-  public SystemInfoWriterModule(WebServer webServer) {
-    this.webServer = webServer;
+  public SystemInfoWriterModule(NodeInformation nodeInformation) {
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
   protected void configureModule() {
-    boolean standalone = webServer.isStandalone();
+    boolean standalone = nodeInformation.isStandalone();
 
     add(
       new JvmPropertiesSection("Web JVM Properties"),
index 3f017c591151a747996abbce280f83ee2aeacd9c..2497bac7d6182096457ce4cbebcb0b651db9f885 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.core.platform.ServerId;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.property.PropertyDto;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.property.InternalProperties;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -45,21 +45,21 @@ public class ServerIdManager implements Startable {
   private final ServerIdFactory serverIdFactory;
   private final DbClient dbClient;
   private final SonarRuntime runtime;
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
 
-  public ServerIdManager(ServerIdChecksum serverIdChecksum, ServerIdFactory serverIdFactory,
-    DbClient dbClient, SonarRuntime runtime, WebServer webServer) {
+  public ServerIdManager(ServerIdChecksum serverIdChecksum, ServerIdFactory serverIdFactory, DbClient dbClient, SonarRuntime runtime,
+    NodeInformation nodeInformation) {
     this.serverIdChecksum = serverIdChecksum;
     this.serverIdFactory = serverIdFactory;
     this.dbClient = dbClient;
     this.runtime = runtime;
-    this.webServer = webServer;
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
   public void start() {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && webServer.isStartupLeader()) {
+      if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && nodeInformation.isStartupLeader()) {
         Optional<String> checksum = dbClient.internalPropertiesDao().selectByKey(dbSession, SERVER_ID_CHECKSUM);
 
         ServerId serverId = readCurrentServerId(dbSession)
index 7b1f287dabdae320afcee5e34e0b4d9bf4c142f5..ccbb09d519c2878e9ee91dcaa0453a285ccde4a8 100644 (file)
@@ -31,14 +31,14 @@ public class ClusterVerificationTest {
   private static final String ERROR_MESSAGE = "Cluster mode can't be enabled. Please install the Data Center Edition. More details at https://redirect.sonarsource.com/editions/datacenter.html.";
 
 
-  private WebServer webServer = mock(WebServer.class);
+  private NodeInformation nodeInformation = mock(NodeInformation.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);
+    when(nodeInformation.isStandalone()).thenReturn(false);
 
-    ClusterVerification underTest = new ClusterVerification(webServer);
+    ClusterVerification underTest = new ClusterVerification(nodeInformation);
 
     assertThatThrownBy(underTest::start)
       .isInstanceOf(MessageException.class)
@@ -47,9 +47,9 @@ public class ClusterVerificationTest {
 
   @Test
   public void throw_MessageException_if_cluster_is_enabled_but_HA_feature_is_not_enabled() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     when(feature.isEnabled()).thenReturn(false);
-    ClusterVerification underTest = new ClusterVerification(webServer, feature);
+    ClusterVerification underTest = new ClusterVerification(nodeInformation, feature);
 
     assertThatThrownBy(underTest::start)
       .isInstanceOf(MessageException.class)
@@ -58,9 +58,9 @@ public class ClusterVerificationTest {
 
   @Test
   public void do_not_fail_if_cluster_is_enabled_and_HA_feature_is_enabled() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     when(feature.isEnabled()).thenReturn(true);
-    ClusterVerification underTest = new ClusterVerification(webServer, feature);
+    ClusterVerification underTest = new ClusterVerification(nodeInformation, feature);
 
     // no failure
     underTest.start();
@@ -69,9 +69,9 @@ public class ClusterVerificationTest {
 
   @Test
   public void do_not_fail_if_cluster_is_disabled() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
 
-    ClusterVerification underTest = new ClusterVerification(webServer);
+    ClusterVerification underTest = new ClusterVerification(nodeInformation);
 
     // no failure
     underTest.start();
index d8b1f404e93eb8ac38b77906972a8efdc2935d2b..366873c7b3c884ab09beb60345d13ea0e14993a2 100644 (file)
@@ -27,12 +27,12 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class SystemInfoWriterModuleTest {
-  private final WebServer webServer = mock(WebServer.class);
-  private final SystemInfoWriterModule underTest = new SystemInfoWriterModule(webServer);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
+  private final SystemInfoWriterModule underTest = new SystemInfoWriterModule(nodeInformation);
 
   @Test
   public void verify_system_info_configuration_in_cluster_mode() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     ListContainer container = new ListContainer();
     underTest.configure(container);
     assertThat(container.getAddedObjects()).hasSize(21);
@@ -40,7 +40,7 @@ public class SystemInfoWriterModuleTest {
 
   @Test
   public void verify_system_info_configuration_in_standalone_mode() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
 
     ListContainer container = new ListContainer();
     underTest.configure(container);
index 78b85cd5d637971e7c5cbecefa2cac46b00ce525..4fcf306e5da51d18b5c892f3f0c57272382d308a 100644 (file)
@@ -36,7 +36,7 @@ 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.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.property.InternalProperties;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
@@ -66,7 +66,7 @@ public class ServerIdManagerTest {
   private final ServerIdFactory serverIdFactory = mock(ServerIdFactory.class);
   private final DbClient dbClient = dbTester.getDbClient();
   private final DbSession dbSession = dbTester.getSession();
-  private final WebServer webServer = mock(WebServer.class);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
   private ServerIdManager underTest;
 
   @After
@@ -80,7 +80,7 @@ public class ServerIdManagerTest {
   public void web_leader_persists_new_server_id_if_missing() {
     mockCreateNewServerId();
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
     test(SERVER);
 
@@ -93,7 +93,7 @@ public class ServerIdManagerTest {
     insertServerId("");
     mockCreateNewServerId();
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
     test(SERVER);
 
@@ -106,7 +106,7 @@ public class ServerIdManagerTest {
     insertServerId(WITH_DATABASE_ID_SERVER_ID);
     insertChecksum(CHECKSUM_1);
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
     test(SERVER);
 
@@ -121,7 +121,7 @@ public class ServerIdManagerTest {
     mockChecksumOf(currentServerId, "matches_WITH_DATABASE_ID_SERVER_ID");
     mockCreateNewServerIdFrom(currentServerId);
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
     test(SERVER);
 
@@ -133,7 +133,7 @@ public class ServerIdManagerTest {
   public void web_leader_generates_missing_checksum_for_current_serverId_with_databaseId() {
     insertServerId(WITH_DATABASE_ID_SERVER_ID);
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(true);
+    when(nodeInformation.isStartupLeader()).thenReturn(true);
 
     test(SERVER);
 
@@ -145,7 +145,7 @@ public class ServerIdManagerTest {
     insertServerId(WITH_DATABASE_ID_SERVER_ID);
     insertChecksum(CHECKSUM_1);
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
     test(SERVER);
 
@@ -155,7 +155,7 @@ public class ServerIdManagerTest {
 
   @Test
   public void web_follower_fails_if_server_id_is_missing() {
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
     expectMissingServerIdException(() -> test(SERVER));
   }
@@ -163,7 +163,7 @@ public class ServerIdManagerTest {
   @Test
   public void web_follower_fails_if_server_id_is_empty() {
     insertServerId("");
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
     expectEmptyServerIdException(() -> test(SERVER));
   }
@@ -174,7 +174,7 @@ public class ServerIdManagerTest {
     insertServerId(WITH_DATABASE_ID_SERVER_ID);
     insertChecksum(dbChecksum);
     mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
-    when(webServer.isStartupLeader()).thenReturn(false);
+    when(nodeInformation.isStartupLeader()).thenReturn(false);
 
     try {
       test(SERVER);
@@ -286,7 +286,7 @@ public class ServerIdManagerTest {
 
   private void test(SonarQubeSide side) {
     underTest = new ServerIdManager(serverIdChecksum, serverIdFactory, dbClient, SonarRuntimeImpl
-      .forSonarQube(Version.create(6, 7), side, SonarEdition.COMMUNITY), webServer);
+      .forSonarQube(Version.create(6, 7), side, SonarEdition.COMMUNITY), nodeInformation);
     underTest.start();
   }
 }
index 44b24091b9f72aa6b246e19ce4269b89779ffa94..f3841d4bcac0b908d0ccf4ad225bcd493177979d 100644 (file)
@@ -25,7 +25,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.process.cluster.health.NodeHealth;
 import org.sonar.process.cluster.health.SharedHealthState;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -36,7 +36,7 @@ import static com.google.common.collect.ImmutableList.copyOf;
  * available in the container.
  */
 public class HealthCheckerImpl implements HealthChecker {
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
   private final List<NodeHealthCheck> nodeHealthChecks;
   private final List<ClusterHealthCheck> clusterHealthChecks;
   @CheckForNull
@@ -46,17 +46,17 @@ public class HealthCheckerImpl implements HealthChecker {
    * Constructor used by the ioc container in standalone mode and in safe mode.
    */
   @Autowired(required = false)
-  public HealthCheckerImpl(WebServer webServer, NodeHealthCheck[] nodeHealthChecks) {
-    this(webServer, nodeHealthChecks, new ClusterHealthCheck[0], null);
+  public HealthCheckerImpl(NodeInformation nodeInformation, NodeHealthCheck[] nodeHealthChecks) {
+    this(nodeInformation, nodeHealthChecks, new ClusterHealthCheck[0], null);
   }
 
   /**
    * Constructor used by the ioc container in cluster mode.
    */
   @Autowired(required = false)
-  public HealthCheckerImpl(WebServer webServer, NodeHealthCheck[] nodeHealthChecks, ClusterHealthCheck[] clusterHealthChecks,
+  public HealthCheckerImpl(NodeInformation nodeInformation, NodeHealthCheck[] nodeHealthChecks, ClusterHealthCheck[] clusterHealthChecks,
     @Nullable SharedHealthState sharedHealthState) {
-    this.webServer = webServer;
+    this.nodeInformation = nodeInformation;
     this.nodeHealthChecks = copyOf(nodeHealthChecks);
     this.clusterHealthChecks = copyOf(clusterHealthChecks);
     this.sharedHealthState = sharedHealthState;
@@ -71,7 +71,7 @@ public class HealthCheckerImpl implements HealthChecker {
 
   @Override
   public ClusterHealth checkCluster() {
-    checkState(!webServer.isStandalone(), "Clustering is not enabled");
+    checkState(!nodeInformation.isStandalone(), "Clustering is not enabled");
     checkState(sharedHealthState != null, "HealthState instance can't be null when clustering is enabled");
 
     Set<NodeHealth> nodeHealths = sharedHealthState.readAll();
index c50d3fd62d3e25952c1c4b325a16e2e63bcff8a5..a7401d18886e109a3d77c0cc467a56ce160d6ba8 100644 (file)
 package org.sonar.server.platform.ws;
 
 import org.sonar.core.platform.Module;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 public class ChangeLogLevelServiceModule extends Module {
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
 
-  public ChangeLogLevelServiceModule(WebServer webServer) {
-    this.webServer = webServer;
+  public ChangeLogLevelServiceModule(NodeInformation nodeInformation) {
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
   protected void configureModule() {
-    if (webServer.isStandalone()) {
+    if (nodeInformation.isStandalone()) {
       add(ChangeLogLevelStandaloneService.class);
     } else {
       add(ChangeLogLevelClusterService.class);
index 42a2211a559bc66ae8578a8454c4af618b5f61d5..394fa418ce0681028082b99c394bb3332d4dc4f0 100644 (file)
@@ -23,19 +23,19 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.user.SystemPasscode;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.WsUtils;
 
 public class HealthAction implements SystemWsAction {
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
   private final HealthActionSupport support;
   private final SystemPasscode systemPasscode;
   private final UserSession userSession;
 
-  public HealthAction(WebServer webServer, HealthActionSupport support, SystemPasscode systemPasscode, UserSession userSession) {
-    this.webServer = webServer;
+  public HealthAction(NodeInformation nodeInformation, HealthActionSupport support, SystemPasscode systemPasscode, UserSession userSession) {
+    this.nodeInformation = nodeInformation;
     this.support = support;
     this.systemPasscode = systemPasscode;
     this.userSession = userSession;
@@ -52,7 +52,7 @@ public class HealthAction implements SystemWsAction {
       throw new ForbiddenException("Insufficient privileges");
     }
 
-    if (webServer.isStandalone()) {
+    if (nodeInformation.isStandalone()) {
       WsUtils.writeProtobuf(support.checkNodeHealth(), request, response);
     } else {
       WsUtils.writeProtobuf(support.checkClusterHealth(), request, response);
index 61c3248eb65db745a5926b235f9ba80ea15c2ef6..f5646eaa6cf9bc8901cf38de66e14f549e55073e 100644 (file)
@@ -27,13 +27,13 @@ import org.sonar.server.health.EsStatusClusterCheck;
 import org.sonar.server.health.EsStatusNodeCheck;
 import org.sonar.server.health.HealthCheckerImpl;
 import org.sonar.server.health.WebServerStatusNodeCheck;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 public class HealthCheckerModule extends Module {
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
 
-  public HealthCheckerModule(WebServer webServer) {
-    this.webServer = webServer;
+  public HealthCheckerModule(NodeInformation nodeInformation) {
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
@@ -42,7 +42,7 @@ public class HealthCheckerModule extends Module {
     add(WebServerStatusNodeCheck.class,
       DbConnectionNodeCheck.class,
       CeStatusNodeCheck.class);
-    if (webServer.isStandalone()) {
+    if (nodeInformation.isStandalone()) {
       add(EsStatusNodeCheck.class);
     } else {
       // ClusterHealthCheck implementations
index de87d55c6c3453cb4d97c63157d4fc56fe7c9b23..951cfe022d1afd48860ab6c83b8c0a8dce7f95a2 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.app.ProcessCommandWrapper;
 import org.sonar.server.app.RestartFlagHolder;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.user.UserSession;
 
 /**
@@ -39,14 +39,14 @@ public class RestartAction implements SystemWsAction {
   private final UserSession userSession;
   private final ProcessCommandWrapper processCommandWrapper;
   private final RestartFlagHolder restartFlagHolder;
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
 
   public RestartAction(UserSession userSession, ProcessCommandWrapper processCommandWrapper, RestartFlagHolder restartFlagHolder,
-    WebServer webServer) {
+    NodeInformation nodeInformation) {
     this.userSession = userSession;
     this.processCommandWrapper = processCommandWrapper;
     this.restartFlagHolder = restartFlagHolder;
-    this.webServer = webServer;
+    this.nodeInformation = nodeInformation;
   }
 
   @Override
@@ -61,7 +61,7 @@ public class RestartAction implements SystemWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    if (!webServer.isStandalone()) {
+    if (!nodeInformation.isStandalone()) {
       throw new IllegalArgumentException("Restart not allowed for cluster nodes");
     }
 
index fd59388942dcaf392480e01a30337ebba70b42f5..bbe34987ba04e5f6848e592f3589cfc597d0ab06 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.dialect.H2;
 import org.sonar.server.authentication.DefaultAdminCredentialsVerifier;
 import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.ui.PageRepository;
 import org.sonar.server.ui.VersionFormatter;
 import org.sonar.server.ui.WebAnalyticsLoader;
@@ -69,7 +69,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
   private final Configuration config;
   private final ResourceTypes resourceTypes;
   private final Server server;
-  private final WebServer webServer;
+  private final NodeInformation nodeInformation;
   private final DbClient dbClient;
   private final UserSession userSession;
   private final PlatformEditionProvider editionProvider;
@@ -78,14 +78,14 @@ public class GlobalAction implements NavigationWsAction, Startable {
   private final DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier;
 
   public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
-    WebServer webServer, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider,
+    NodeInformation nodeInformation, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider,
     WebAnalyticsLoader webAnalyticsLoader, IssueIndexSyncProgressChecker issueIndexSyncChecker,
     DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier) {
     this.pageRepository = pageRepository;
     this.config = config;
     this.resourceTypes = resourceTypes;
     this.server = server;
-    this.webServer = webServer;
+    this.nodeInformation = nodeInformation;
     this.dbClient = dbClient;
     this.userSession = userSession;
     this.editionProvider = editionProvider;
@@ -129,7 +129,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
       writeInstanceUsesDefaultAdminCredentials(json);
       editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
       writeNeedIssueSync(json);
-      json.prop("standalone", webServer.isStandalone());
+      json.prop("standalone", nodeInformation.isStandalone());
       writeWebAnalytics(json);
       json.endObject();
     }
index 5255dd6d7f79bdc577a97f8abc9a07b96ae22d35..fa51c8682756dd1e5a5c952cae6ded51798607fd 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -45,7 +45,7 @@ public class ExportSubmitterImplTest {
   public DbTester db = DbTester.create(system2);
 
   private final DbClient dbClient = db.getDbClient();
-  private final CeQueue ceQueue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(WebServer.class));
+  private final CeQueue ceQueue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(NodeInformation.class));
 
   private final ExportSubmitterImpl underTest = new ExportSubmitterImpl(ceQueue, dbClient);
 
index 6086a1219b66f9297ec0b125232c4ce286e68a6b..16de1288fb059242c8ebca02fc80f446ef4cab41 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 
@@ -53,7 +53,7 @@ public class CancelActionTest {
   public DbTester db = DbTester.create();
 
   private System2 system2 = new TestSystem2();
-  private CeQueue queue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(WebServer.class));
+  private CeQueue queue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(NodeInformation.class));
 
   private CancelAction underTest = new CancelAction(userSession, db.getDbClient(), queue);
   private WsActionTester tester = new WsActionTester(underTest);
index 127163463cea064e877afd20752155cf4ffd7223..fd1572b022953556c4a697f9ea75ee8aaca37cf9 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.Test;
 import org.sonar.process.cluster.health.NodeDetails;
 import org.sonar.process.cluster.health.NodeHealth;
 import org.sonar.process.cluster.health.SharedHealthState;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -49,13 +49,13 @@ import static org.sonar.server.health.Health.Status.YELLOW;
 
 public class HealthCheckerImplTest {
 
-  private final WebServer webServer = mock(WebServer.class);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
   private final SharedHealthState sharedHealthState = mock(SharedHealthState.class);
   private final Random random = new Random();
 
   @Test
   public void check_returns_green_status_without_any_cause_when_there_is_no_NodeHealthCheck() {
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0]);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0]);
 
     assertThat(underTest.checkNode()).isEqualTo(Health.GREEN);
   }
@@ -109,15 +109,15 @@ public class HealthCheckerImplTest {
       .toArray(NodeHealthCheck[]::new);
     String[] expected = Arrays.stream(nodeHealthChecks).map(NodeHealthCheck::check).flatMap(s -> s.getCauses().stream()).toArray(String[]::new);
 
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, nodeHealthChecks);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, nodeHealthChecks);
 
     assertThat(underTest.checkNode().getCauses()).containsOnly(expected);
   }
 
   @Test
   public void checkCluster_fails_with_ISE_in_standalone() {
-    when(webServer.isStandalone()).thenReturn(true);
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
+    when(nodeInformation.isStandalone()).thenReturn(true);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
 
     assertThatThrownBy(() -> underTest.checkCluster())
       .isInstanceOf(IllegalStateException.class)
@@ -126,8 +126,8 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_fails_with_ISE_in_clustering_and_HealthState_is_null() {
-    when(webServer.isStandalone()).thenReturn(false);
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], new ClusterHealthCheck[0], null);
+    when(nodeInformation.isStandalone()).thenReturn(false);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], null);
 
     assertThatThrownBy(() -> underTest.checkCluster())
       .isInstanceOf(IllegalStateException.class)
@@ -136,15 +136,15 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_returns_GREEN_when_there_is_no_ClusterHealthCheck() {
-    when(webServer.isStandalone()).thenReturn(false);
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
+    when(nodeInformation.isStandalone()).thenReturn(false);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
 
     assertThat(underTest.checkCluster().getHealth()).isEqualTo(Health.GREEN);
   }
 
   @Test
   public void checkCluster_returns_GREEN_status_if_only_GREEN_statuses_returned_by_ClusterHealthChecks() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     List<Health.Status> statuses = IntStream.range(1, 1 + random.nextInt(20)).mapToObj(i -> GREEN).collect(Collectors.toList());
     HealthCheckerImpl underTest = newClusterHealthCheckerImpl(statuses.stream());
 
@@ -155,7 +155,7 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_returns_YELLOW_status_if_only_GREEN_and_at_least_one_YELLOW_statuses_returned_by_ClusterHealthChecks() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     List<Health.Status> statuses = new ArrayList<>();
     Stream.concat(
       IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> YELLOW), // at least 1 YELLOW
@@ -170,7 +170,7 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_returns_RED_status_if_at_least_one_RED_status_returned_by_ClusterHealthChecks() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     List<Health.Status> statuses = new ArrayList<>();
     Stream.of(
         IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED
@@ -188,7 +188,7 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_returns_causes_of_all_ClusterHealthChecks_whichever_their_status() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     List<String[]> causesGroups = IntStream.range(0, 1 + random.nextInt(20))
       .mapToObj(s -> IntStream.range(0, random.nextInt(3)).mapToObj(i -> randomAlphanumeric(3)).toArray(String[]::new))
       .collect(Collectors.toList());
@@ -198,14 +198,14 @@ public class HealthCheckerImplTest {
       .toArray(ClusterHealthCheck[]::new);
     String[] expectedCauses = causesGroups.stream().flatMap(Arrays::stream).toArray(String[]::new);
 
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], clusterHealthChecks, sharedHealthState);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], clusterHealthChecks, sharedHealthState);
 
     assertThat(underTest.checkCluster().getHealth().getCauses()).containsOnly(expectedCauses);
   }
 
   @Test
   public void checkCluster_passes_set_of_NodeHealth_returns_by_HealthState_to_all_ClusterHealthChecks() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     ClusterHealthCheck[] mockedClusterHealthChecks = IntStream.range(0, 1 + random.nextInt(3))
       .mapToObj(i -> mock(ClusterHealthCheck.class))
       .toArray(ClusterHealthCheck[]::new);
@@ -215,7 +215,7 @@ public class HealthCheckerImplTest {
       when(mockedClusterHealthCheck.check(same(nodeHealths))).thenReturn(Health.GREEN);
     }
 
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], mockedClusterHealthChecks, sharedHealthState);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], mockedClusterHealthChecks, sharedHealthState);
     underTest.checkCluster();
 
     for (ClusterHealthCheck mockedClusterHealthCheck : mockedClusterHealthChecks) {
@@ -225,11 +225,11 @@ public class HealthCheckerImplTest {
 
   @Test
   public void checkCluster_returns_NodeHealths_returned_by_HealthState() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     Set<NodeHealth> nodeHealths = IntStream.range(0, 1 + random.nextInt(4)).mapToObj(i -> randomNodeHealth()).collect(Collectors.toSet());
     when(sharedHealthState.readAll()).thenReturn(nodeHealths);
 
-    HealthCheckerImpl underTest = new HealthCheckerImpl(webServer, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
+    HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState);
 
     ClusterHealth clusterHealth = underTest.checkCluster();
     assertThat(clusterHealth.getNodes()).isEqualTo(nodeHealths);
@@ -251,14 +251,14 @@ public class HealthCheckerImplTest {
   private HealthCheckerImpl newNodeHealthCheckerImpl(Stream<Health.Status> statuses) {
     Stream<HardcodedHealthNodeCheck> staticHealthCheckStream = statuses.map(HardcodedHealthNodeCheck::new);
     return new HealthCheckerImpl(
-      webServer,
+      nodeInformation,
       staticHealthCheckStream.map(NodeHealthCheck.class::cast).toArray(NodeHealthCheck[]::new));
   }
 
   private HealthCheckerImpl newClusterHealthCheckerImpl(Stream<Health.Status> statuses) {
     Stream<HardcodedHealthClusterCheck> staticHealthCheckStream = statuses.map(HardcodedHealthClusterCheck::new);
     return new HealthCheckerImpl(
-      webServer,
+      nodeInformation,
       new NodeHealthCheck[0],
       staticHealthCheckStream.map(ClusterHealthCheck.class::cast).toArray(ClusterHealthCheck[]::new),
       sharedHealthState);
index 21c00a6a4032e715e9d1be7472d40f4189a26496..65183c73d1caece0f765b8298b7bf23a02bebdf7 100644 (file)
@@ -21,19 +21,19 @@ package org.sonar.server.platform.ws;
 
 import org.junit.Test;
 import org.sonar.core.platform.ListContainer;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class ChangeLogLevelServiceModuleTest {
-  private final WebServer webServer = mock(WebServer.class);
-  private final ChangeLogLevelServiceModule underTest = new ChangeLogLevelServiceModule(webServer);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
+  private final ChangeLogLevelServiceModule underTest = new ChangeLogLevelServiceModule(nodeInformation);
 
   @Test
   public void provide_returns_ChangeLogLevelClusterService() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
@@ -43,7 +43,7 @@ public class ChangeLogLevelServiceModuleTest {
 
   @Test
   public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
index 76d47596723df4244e542e28d04cd78a82f9ea27..4de9869a6f0701898ad0c102afda76ba85b0c570 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.health.ClusterHealth;
 import org.sonar.server.health.Health;
 import org.sonar.server.health.HealthChecker;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.SystemPasscode;
 import org.sonar.server.ws.TestRequest;
@@ -69,9 +69,9 @@ public class HealthActionTest {
 
   private final Random random = new Random();
   private HealthChecker healthChecker = mock(HealthChecker.class);
-  private WebServer webServer = mock(WebServer.class);
+  private NodeInformation nodeInformation = mock(NodeInformation.class);
   private SystemPasscode systemPasscode = mock(SystemPasscode.class);
-  private WsActionTester underTest = new WsActionTester(new HealthAction(webServer, new HealthActionSupport(healthChecker), systemPasscode, userSessionRule));
+  private WsActionTester underTest = new WsActionTester(new HealthAction(nodeInformation, new HealthActionSupport(healthChecker), systemPasscode, userSessionRule));
 
   @Test
   public void verify_definition() {
@@ -134,7 +134,7 @@ public class HealthActionTest {
   @Test
   public void verify_response_example() {
     authenticateWithRandomMethod();
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     long time = parseDateTime("2015-08-13T23:34:59+0200").getTime();
     when(healthChecker.checkCluster())
       .thenReturn(
@@ -183,7 +183,7 @@ public class HealthActionTest {
     IntStream.range(0, new Random().nextInt(5)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).forEach(builder::addCause);
     Health health = builder.build();
     when(healthChecker.checkNode()).thenReturn(health);
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     TestRequest request = underTest.newRequest();
 
     System.HealthResponse healthResponse = request.executeProtobuf(System.HealthResponse.class);
@@ -199,7 +199,7 @@ public class HealthActionTest {
     Health.Builder healthBuilder = Health.builder()
       .setStatus(randomStatus);
     Arrays.stream(causes).forEach(healthBuilder::addCause);
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(healthBuilder.build(), emptySet()));
 
     System.HealthResponse clusterHealthResponse = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
@@ -213,7 +213,7 @@ public class HealthActionTest {
   public void response_contains_information_of_nodes_when_clustered() {
     authenticateWithRandomMethod();
     NodeHealth nodeHealth = randomNodeHealth();
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(GREEN, singleton(nodeHealth)));
 
     System.HealthResponse response = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
@@ -255,7 +255,7 @@ public class HealthActionTest {
     String[] expected = nodeHealths.stream().map(s -> formatDateTime(new Date(s.getDetails().getStartedAt()))).toArray(String[]::new);
     Collections.shuffle(nodeHealths);
 
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(GREEN, new HashSet<>(nodeHealths)));
 
     System.HealthResponse response = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
index b91322ca303890808631db6870fa278c7d030ee3..f20785d7454cb8dd57c70cff64c2aca9dcecc8ad 100644 (file)
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Random;
 import java.util.stream.Collectors;
 import org.junit.Test;
+import org.sonar.core.platform.ListContainer;
 import org.sonar.server.health.AppNodeClusterCheck;
 import org.sonar.server.health.CeStatusNodeCheck;
 import org.sonar.server.health.ClusterHealthCheck;
@@ -32,21 +33,20 @@ import org.sonar.server.health.EsStatusNodeCheck;
 import org.sonar.server.health.HealthCheckerImpl;
 import org.sonar.server.health.NodeHealthCheck;
 import org.sonar.server.health.WebServerStatusNodeCheck;
-import org.sonar.core.platform.ListContainer;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class HealthCheckerModuleTest {
-  private final WebServer webServer = mock(WebServer.class);
-  private final HealthCheckerModule underTest = new HealthCheckerModule(webServer);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
+  private final HealthCheckerModule underTest = new HealthCheckerModule(nodeInformation);
 
   @Test
   public void verify_HealthChecker() {
     boolean standalone = new Random().nextBoolean();
-    when(webServer.isStandalone()).thenReturn(standalone);
+    when(nodeInformation.isStandalone()).thenReturn(standalone);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
@@ -61,7 +61,7 @@ public class HealthCheckerModuleTest {
 
   @Test
   public void verify_installed_NodeHealthChecks_implementations_when_standalone() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
@@ -75,7 +75,7 @@ public class HealthCheckerModuleTest {
 
   @Test
   public void verify_installed_NodeHealthChecks_implementations_when_clustered() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
@@ -89,7 +89,7 @@ public class HealthCheckerModuleTest {
 
   @Test
   public void verify_installed_ClusterHealthChecks_implementations_in_standalone() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
@@ -103,7 +103,7 @@ public class HealthCheckerModuleTest {
 
   @Test
   public void verify_installed_ClusterHealthChecks_implementations_in_clustering() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
     ListContainer container = new ListContainer();
 
     underTest.configure(container);
index c06798ff59bcd9ef169f73b2261fad853f85f32b..5d63f8a6ae902a6ffbb39bbcf55661bcd22d9c18 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.server.app.ProcessCommandWrapper;
 import org.sonar.server.app.RestartFlagHolder;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
 
@@ -45,15 +45,15 @@ public class RestartActionTest {
 
   private ProcessCommandWrapper processCommandWrapper = mock(ProcessCommandWrapper.class);
   private RestartFlagHolder restartFlagHolder = mock(RestartFlagHolder.class);
-  private WebServer webServer = mock(WebServer.class);
-  private RestartAction sut = new RestartAction(userSessionRule, processCommandWrapper, restartFlagHolder, webServer);
+  private NodeInformation nodeInformation = mock(NodeInformation.class);
+  private RestartAction sut = new RestartAction(userSessionRule, processCommandWrapper, restartFlagHolder, nodeInformation);
   private InOrder inOrder = Mockito.inOrder(restartFlagHolder, processCommandWrapper);
 
   private WsActionTester actionTester = new WsActionTester(sut);
 
   @Test
   public void request_fails_in_production_mode_with_ForbiddenException_when_user_is_not_logged_in() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
 
     assertThatThrownBy(() -> actionTester.newRequest().execute())
       .isInstanceOf(ForbiddenException.class);
@@ -61,7 +61,7 @@ public class RestartActionTest {
 
   @Test
   public void request_fails_in_production_mode_with_ForbiddenException_when_user_is_not_system_administrator() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     userSessionRule.logIn().setNonSystemAdministrator();
 
     assertThatThrownBy(() -> actionTester.newRequest().execute())
@@ -70,7 +70,7 @@ public class RestartActionTest {
 
   @Test
   public void request_fails_in_cluster_mode_with_IllegalArgumentException() {
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
 
     assertThatThrownBy(() -> actionTester.newRequest().execute())
       .isInstanceOf(IllegalArgumentException.class)
@@ -79,7 +79,7 @@ public class RestartActionTest {
 
   @Test
   public void calls_ProcessCommandWrapper_requestForSQRestart_in_production_mode() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     userSessionRule.logIn().setSystemAdministrator();
 
     actionTester.newRequest().execute();
@@ -90,7 +90,7 @@ public class RestartActionTest {
 
   @Test
   public void logs_login_of_authenticated_user_requesting_the_restart_in_production_mode() {
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     String login = "BigBother";
     userSessionRule.logIn(login).setSystemAdministrator();
 
index 4fa843fd22fa8a9ebb98d3d9f52169a00d32bb87..182adb66d1edd7920fa23414010cc05096419bab 100644 (file)
@@ -23,8 +23,8 @@ import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.app.ProcessCommandWrapper;
 import org.sonar.server.app.RestartFlagHolder;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.platform.SystemInfoWriter;
-import org.sonar.server.platform.WebServer;
 import org.sonar.server.tester.AnonymousMockUserSession;
 import org.sonar.server.user.UserSession;
 
@@ -36,7 +36,7 @@ public class SystemWsTest {
   @Test
   public void define() {
     RestartAction action1 = new RestartAction(mock(UserSession.class), mock(ProcessCommandWrapper.class),
-      mock(RestartFlagHolder.class), mock(WebServer.class));
+      mock(RestartFlagHolder.class), mock(NodeInformation.class));
     InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), mock(SystemInfoWriter.class));
     SystemWs ws = new SystemWs(action1, action2);
     WebService.Context context = new WebService.Context();
index bdcb1b773b97dd7402907c04a2b854c56321d50c..f0c048ab946a7aab010bcffa88b7bd4bbff56f75 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.dialect.H2;
 import org.sonar.db.dialect.PostgreSql;
 import org.sonar.server.authentication.DefaultAdminCredentialsVerifier;
 import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ui.PageRepository;
 import org.sonar.server.ui.WebAnalyticsLoader;
@@ -61,7 +61,7 @@ public class GlobalActionTest {
   private final MapSettings settings = new MapSettings();
 
   private final Server server = mock(Server.class);
-  private final WebServer webServer = mock(WebServer.class);
+  private final NodeInformation nodeInformation = mock(NodeInformation.class);
   private final DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
   private final IssueIndexSyncProgressChecker indexSyncProgressChecker = mock(IssueIndexSyncProgressChecker.class);
   private final BranchFeatureRule branchFeature = new BranchFeatureRule();
@@ -244,7 +244,7 @@ public class GlobalActionTest {
   public void standalone_flag() {
     init();
     userSession.logIn().setSystemAdministrator();
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
 
     assertJson(call()).isSimilarTo("{\"standalone\":true}");
   }
@@ -253,7 +253,7 @@ public class GlobalActionTest {
   public void not_standalone_flag() {
     init();
     userSession.logIn().setSystemAdministrator();
-    when(webServer.isStandalone()).thenReturn(false);
+    when(nodeInformation.isStandalone()).thenReturn(false);
 
     assertJson(call()).isSimilarTo("{\"standalone\":false}");
   }
@@ -280,7 +280,7 @@ public class GlobalActionTest {
     });
     when(server.getVersion()).thenReturn("6.2");
     when(dbClient.getDatabase().getDialect()).thenReturn(new PostgreSql());
-    when(webServer.isStandalone()).thenReturn(true);
+    when(nodeInformation.isStandalone()).thenReturn(true);
     when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
 
     String result = call();
@@ -343,7 +343,7 @@ public class GlobalActionTest {
     }});
     pageRepository.start();
     GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
-      webServer, dbClient, userSession, editionProvider, webAnalyticsLoader,
+      nodeInformation, dbClient, userSession, editionProvider, webAnalyticsLoader,
       indexSyncProgressChecker, defaultAdminCredentialsVerifier);
     ws = new WsActionTester(wsAction);
     wsAction.start();
index 74eafc913bfe79a16af74cbe872812155bcaa3ee..c41f47f34ed2058bfce7f99d078ccc16268c3387 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Collection;
 import java.util.Optional;
 import javax.annotation.Nullable;
 import org.sonar.core.platform.SpringComponentContainer;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -144,10 +144,10 @@ public abstract class PlatformLevel {
     return addIfStandalone;
   }
 
-  protected WebServer getWebServer() {
+  protected NodeInformation getWebServer() {
     return Optional.ofNullable(parent)
-      .flatMap(p -> p.getOptional(WebServer.class))
-      .or(() -> getOptional(WebServer.class))
+      .flatMap(p -> p.getOptional(NodeInformation.class))
+      .or(() -> getOptional(NodeInformation.class))
       .orElseThrow(() -> new IllegalStateException("WebServer not available in the container"));
   }
 
index 9bbc457e8dd0c2013a57de4067ed338f3178163f..1a350ccc8dc64a3fa39da1b5fdd07ceeb3fab91a 100644 (file)
@@ -51,6 +51,7 @@ import org.sonar.server.es.EsModule;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
 import org.sonar.server.permission.index.WebAuthorizationTypeSupport;
+import org.sonar.server.platform.DefaultNodeInformation;
 import org.sonar.server.platform.DockerSupportImpl;
 import org.sonar.server.platform.LogServerVersion;
 import org.sonar.server.platform.Platform;
@@ -58,7 +59,6 @@ import org.sonar.server.platform.ServerFileSystemImpl;
 import org.sonar.server.platform.TempFolderProvider;
 import org.sonar.server.platform.UrlSettings;
 import org.sonar.server.platform.WebCoreExtensionsInstaller;
-import org.sonar.server.platform.WebServerImpl;
 import org.sonar.server.platform.db.EmbeddedDatabaseFactory;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.setting.ThreadLocalSettings;
@@ -148,7 +148,7 @@ public class PlatformLevel1 extends PlatformLevel {
     addAll(CorePropertyDefinitions.all());
 
     // cluster
-    add(WebServerImpl.class);
+    add(DefaultNodeInformation.class);
   }
 
   private void addExtraRootComponents() {
index 2b4344647da3be305f8ea2087366a48df652889b..24e407372077bcc91d03d15957726b5786ad2671 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.core.platform.SpringComponentContainer;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.platform.db.migration.charset.DatabaseCharsetChecker;
 import org.sonar.server.plugins.ServerPluginRepository;
 
@@ -60,12 +60,12 @@ public class PlatformLevel2Test {
     var parentContainer = mock(SpringComponentContainer.class);
     var container = mock(SpringComponentContainer.class);
     var platform = mock(PlatformLevel.class);
-    var webserver = mock(WebServer.class);
+    var webserver = mock(NodeInformation.class);
 
     when(parentContainer.createChild()).thenReturn(container);
     when(platform.getContainer()).thenReturn(parentContainer);
     when(parentContainer.getOptionalComponentByType(any())).thenReturn(Optional.empty());
-    when(container.getOptionalComponentByType(WebServer.class)).thenReturn(Optional.of(webserver));
+    when(container.getOptionalComponentByType(NodeInformation.class)).thenReturn(Optional.of(webserver));
     when(webserver.isStartupLeader()).thenReturn(true);
 
     PlatformLevel2 underTest = new PlatformLevel2(platform);
@@ -81,12 +81,12 @@ public class PlatformLevel2Test {
     var parentContainer = mock(SpringComponentContainer.class);
     var container = mock(SpringComponentContainer.class);
     var platform = mock(PlatformLevel.class);
-    var webserver = mock(WebServer.class);
+    var webserver = mock(NodeInformation.class);
 
     when(parentContainer.createChild()).thenReturn(container);
     when(platform.getContainer()).thenReturn(parentContainer);
     when(parentContainer.getOptionalComponentByType(any())).thenReturn(Optional.empty());
-    when(container.getOptionalComponentByType(WebServer.class)).thenReturn(Optional.of(webserver));
+    when(container.getOptionalComponentByType(NodeInformation.class)).thenReturn(Optional.of(webserver));
     when(webserver.isStartupLeader()).thenReturn(false);
 
     PlatformLevel2 underTest = new PlatformLevel2(platform);
index 3908150d902fcb16fcf7e35d75373a6fc049d254..a1a4b8e38d1bfc0e5840abfbb46fc76560ae1f28 100644 (file)
@@ -24,12 +24,11 @@ import java.util.stream.IntStream;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
-import static org.mockito.Mockito.mock;
-import org.sonar.server.platform.WebServer;
+import org.sonar.server.platform.NodeInformation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
 
 public class PlatformLevelTest {
 
@@ -61,7 +60,7 @@ public class PlatformLevelTest {
 
   @Test
   public void addIfStartupLeader_always_returns_the_same_instance() {
-    underTest.add(mock(WebServer.class));
+    underTest.add(mock(NodeInformation.class));
 
     PlatformLevel.AddIfStartupLeader addIfStartupLeader = underTest.addIfStartupLeader();
     IntStream.range(0, 1 + new Random().nextInt(4)).forEach(i -> assertThat(underTest.addIfStartupLeader()).isSameAs(addIfStartupLeader));
@@ -76,7 +75,7 @@ public class PlatformLevelTest {
 
   @Test
   public void addIfCluster_always_returns_the_same_instance() {
-    underTest.add(mock(WebServer.class));
+    underTest.add(mock(NodeInformation.class));
 
     PlatformLevel.AddIfCluster addIfCluster = underTest.addIfCluster();
     IntStream.range(0, 1 + new Random().nextInt(4)).forEach(i -> assertThat(underTest.addIfCluster()).isSameAs(addIfCluster));
@@ -91,7 +90,7 @@ public class PlatformLevelTest {
 
   @Test
   public void addIfStandalone_always_returns_the_same_instance() {
-    underTest.add(mock(WebServer.class));
+    underTest.add(mock(NodeInformation.class));
 
     PlatformLevel.AddIfCluster addIfCluster = underTest.addIfCluster();
     IntStream.range(0, 1 + new Random().nextInt(4)).forEach(i -> assertThat(underTest.addIfCluster()).isSameAs(addIfCluster));