From 952c70ec25d416f7f660677ca260e41864a4ccbd Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Wed, 23 Feb 2022 09:27:27 +0100 Subject: [PATCH] SONAR-15994 Fix cluster service class constructor --- .../monitoring/cluster/AppNodesInfoLoaderImpl.java | 7 ++----- .../platform/monitoring/cluster/CeQueueGlobalSection.java | 4 ---- .../monitoring/cluster/CeQueueGlobalSectionTest.java | 6 +++--- .../server/platform/ws/ChangeLogLevelClusterService.java | 7 ++----- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java index 81863d8be31..218225631aa 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/AppNodesInfoLoaderImpl.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import javax.annotation.Nullable; import org.sonar.api.server.ServerSide; import org.sonar.process.ProcessId; import org.sonar.process.cluster.hz.DistributedAnswer; @@ -44,14 +45,10 @@ public class AppNodesInfoLoaderImpl implements AppNodesInfoLoader { private final HazelcastMember hzMember; - public AppNodesInfoLoaderImpl(HazelcastMember hzMember) { + public AppNodesInfoLoaderImpl(@Nullable HazelcastMember hzMember) { this.hzMember = hzMember; } - public AppNodesInfoLoaderImpl() { - this(null); - } - public Collection load() throws InterruptedException { Map nodesByName = new HashMap<>(); MemberSelector memberSelector = HazelcastMemberSelectors.selectorForProcessIds(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java index a38a9247b2c..07db982ec30 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java @@ -46,10 +46,6 @@ public class CeQueueGlobalSection implements SystemInfoSection, Global { this.workerCountProvider = workerCountProvider; } - public CeQueueGlobalSection(DbClient dbClient) { - this(dbClient, null); - } - @Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java index b92384c4592..23cfcf88434 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java @@ -36,15 +36,15 @@ import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatA public class CeQueueGlobalSectionTest { - private DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS); - private WorkerCountProvider workerCountProvider = mock(WorkerCountProvider.class); + private final DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS); + private final WorkerCountProvider workerCountProvider = mock(WorkerCountProvider.class); @Test public void test_queue_state_with_default_settings() { when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(10); when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(1); - CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient); + CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient, null); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThatAttributeIs(section, "Total Pending", 10); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelClusterService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelClusterService.java index 1de0b9b3671..11ba960b28d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelClusterService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelClusterService.java @@ -19,6 +19,7 @@ */ package org.sonar.server.platform.ws; +import javax.annotation.Nullable; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.api.utils.log.Loggers; @@ -35,14 +36,10 @@ public class ChangeLogLevelClusterService implements ChangeLogLevelService { private final HazelcastMember member; - public ChangeLogLevelClusterService(HazelcastMember member) { + public ChangeLogLevelClusterService(@Nullable HazelcastMember member) { this.member = member; } - public ChangeLogLevelClusterService() { - this(null); - } - public void changeLogLevel(LoggerLevel level) throws InterruptedException { member.call(setLogLevelForNode(level), HazelcastMemberSelectors.selectorForProcessIds(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE), CLUSTER_TIMEOUT_MILLIS) .propagateExceptions(); -- 2.39.5