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;
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
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);
}
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);
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;
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() {
@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();
@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();
@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();
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;
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;
CeProcessLogging.class,
UuidFactoryImpl.INSTANCE,
NetworkUtilsImpl.INSTANCE,
- WebServerImpl.class,
+ DefaultNodeInformation.class,
LogbackHelper.class,
DefaultDatabase.class,
MyBatis.class,
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;
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;
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);
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);
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;
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
}
@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);
}
@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);
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);
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);
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();
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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();
+
+}
@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);
+++ /dev/null
-/*
- * 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();
-
-}
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
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);
@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);
}
@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");
}
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
+++ /dev/null
-/*
- * 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);
- }
-
-}
*/
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);
}
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"),
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;
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)
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)
@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)
@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();
@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();
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);
@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);
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;
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
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);
insertServerId("");
mockCreateNewServerId();
mockChecksumOf(WITH_DATABASE_ID_SERVER_ID, CHECKSUM_1);
- when(webServer.isStartupLeader()).thenReturn(true);
+ when(nodeInformation.isStartupLeader()).thenReturn(true);
test(SERVER);
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);
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);
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);
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);
@Test
public void web_follower_fails_if_server_id_is_missing() {
- when(webServer.isStartupLeader()).thenReturn(false);
+ when(nodeInformation.isStartupLeader()).thenReturn(false);
expectMissingServerIdException(() -> test(SERVER));
}
@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));
}
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);
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();
}
}
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;
* 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
* 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;
@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();
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);
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;
throw new ForbiddenException("Insufficient privileges");
}
- if (webServer.isStandalone()) {
+ if (nodeInformation.isStandalone()) {
WsUtils.writeProtobuf(support.checkNodeHealth(), request, response);
} else {
WsUtils.writeProtobuf(support.checkClusterHealth(), request, response);
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
add(WebServerStatusNodeCheck.class,
DbConnectionNodeCheck.class,
CeStatusNodeCheck.class);
- if (webServer.isStandalone()) {
+ if (nodeInformation.isStandalone()) {
add(EsStatusNodeCheck.class);
} else {
// ClusterHealthCheck implementations
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;
/**
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
@Override
public void handle(Request request, Response response) {
- if (!webServer.isStandalone()) {
+ if (!nodeInformation.isStandalone()) {
throw new IllegalArgumentException("Restart not allowed for cluster nodes");
}
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;
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;
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;
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();
}
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;
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);
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;
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);
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;
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);
}
.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)
@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)
@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());
@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
@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
@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());
.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);
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) {
@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);
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);
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);
@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);
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;
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() {
@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(
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);
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);
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);
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);
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;
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);
@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);
@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);
@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);
@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);
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;
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);
@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())
@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)
@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();
@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();
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;
@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();
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;
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();
public void standalone_flag() {
init();
userSession.logIn().setSystemAdministrator();
- when(webServer.isStandalone()).thenReturn(true);
+ when(nodeInformation.isStandalone()).thenReturn(true);
assertJson(call()).isSimilarTo("{\"standalone\":true}");
}
public void not_standalone_flag() {
init();
userSession.logIn().setSystemAdministrator();
- when(webServer.isStandalone()).thenReturn(false);
+ when(nodeInformation.isStandalone()).thenReturn(false);
assertJson(call()).isSimilarTo("{\"standalone\":false}");
}
});
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();
}});
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();
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;
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"));
}
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;
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;
addAll(CorePropertyDefinitions.all());
// cluster
- add(WebServerImpl.class);
+ add(DefaultNodeInformation.class);
}
private void addExtraRootComponents() {
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;
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);
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);
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 {
@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));
@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));
@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));