diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-08-25 11:54:26 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:49 +0200 |
commit | 80269a5d22553335f22f3e8a8a5840724fb154f9 (patch) | |
tree | df2a88bb4ae61251040499ec77f2d217246512a1 /server/sonar-main | |
parent | 904cd8b327790c31d1abe0bceb0007015e74dfdf (diff) | |
download | sonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.tar.gz sonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.zip |
SONAR-9741 move shared cluster related classes to sonar-cluster
Diffstat (limited to 'server/sonar-main')
18 files changed, 211 insertions, 209 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppLogging.java b/server/sonar-main/src/main/java/org/sonar/application/AppLogging.java index 5e19aab5945..f35c78b0bf3 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppLogging.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppLogging.java @@ -28,13 +28,13 @@ import ch.qos.logback.core.FileAppender; import org.sonar.application.config.AppSettings; import org.sonar.application.process.StreamGobbler; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.logging.LogLevelConfig; import org.sonar.process.logging.LogbackHelper; import org.sonar.process.logging.RootLoggerConfig; import static org.slf4j.Logger.ROOT_LOGGER_NAME; import static org.sonar.application.process.StreamGobbler.LOGGER_GOBBLER; +import static org.sonar.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder; /** @@ -141,7 +141,7 @@ public class AppLogging { .rootLevelFor(ProcessId.APP) .immutableLevel("com.hazelcast", Level.toLevel( - appSettings.getProps().nonNullValue(ProcessProperties.HAZELCAST_LOG_LEVEL))) + appSettings.getProps().nonNullValue(HAZELCAST_LOG_LEVEL))) .build(), appSettings.getProps()); diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java b/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java index 3463c1effd6..06dbec1fe0f 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java @@ -28,7 +28,7 @@ import org.sonar.process.MessageException; import org.sonar.process.Props; import static java.lang.String.format; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; import static org.sonar.process.ProcessProperties.PATH_DATA; import static org.sonar.process.ProcessProperties.PATH_LOGS; import static org.sonar.process.ProcessProperties.PATH_TEMP; diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java b/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java index 093ca304e25..b571f2c19dc 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; -import org.sonar.process.NetworkUtils; +import org.sonar.NetworkUtils; import org.sonar.process.ProcessId; public class AppStateImpl implements AppState { diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java index 2af58b8b196..498ef00ef12 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java @@ -31,7 +31,10 @@ import org.sonar.application.AppState; import org.sonar.application.AppStateListener; import org.sonar.application.config.AppSettings; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; + +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; +import static org.sonar.cluster.ClusterProperties.CLUSTER_MEMBERUUID; public class AppStateClusterImpl implements AppState { private static Logger LOGGER = LoggerFactory.getLogger(AppStateClusterImpl.class); @@ -40,7 +43,7 @@ public class AppStateClusterImpl implements AppState { private final HazelcastCluster hazelcastCluster; public AppStateClusterImpl(AppSettings appSettings) { - if (!appSettings.getProps().valueAsBoolean(ProcessProperties.CLUSTER_ENABLED)) { + if (!appSettings.getProps().valueAsBoolean(CLUSTER_ENABLED)) { throw new IllegalStateException("Cluster is not enabled on this instance"); } @@ -49,8 +52,8 @@ public class AppStateClusterImpl implements AppState { hazelcastCluster = HazelcastCluster.create(clusterProperties); // Add the local endpoint to be used by processes - appSettings.getProps().set(ProcessProperties.CLUSTER_LOCALENDPOINT, hazelcastCluster.getLocalEndPoint()); - appSettings.getProps().set(ProcessProperties.CLUSTER_MEMBERUUID, hazelcastCluster.getLocalUUID()); + appSettings.getProps().set(CLUSTER_LOCALENDPOINT, hazelcastCluster.getLocalEndPoint()); + appSettings.getProps().set(CLUSTER_MEMBERUUID, hazelcastCluster.getLocalUUID()); String members = hazelcastCluster.getMembers().stream().collect(Collectors.joining(",")); LOGGER.info("Joined a SonarQube cluster that contains the following hosts : [{}]", members); diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java index bfa81351013..a197b7bd4e0 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java @@ -33,7 +33,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.application.config.AppSettings; import org.sonar.process.NodeType; -import org.sonar.process.ProcessProperties; + +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; /** * Properties of the cluster configuration @@ -50,15 +55,11 @@ final class ClusterProperties { private final String nodeName; ClusterProperties(AppSettings appSettings) { - port = appSettings.getProps().valueAsInt(ProcessProperties.CLUSTER_NODE_PORT); - networkInterfaces = extractNetworkInterfaces( - appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_HOST, "") - ); - hosts = extractHosts( - appSettings.getProps().value(ProcessProperties.CLUSTER_HOSTS, "") - ); - nodeType = NodeType.parse(appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_TYPE)); - nodeName = appSettings.getProps().value(ProcessProperties.CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString()); + port = appSettings.getProps().valueAsInt(CLUSTER_NODE_PORT); + networkInterfaces = extractNetworkInterfaces(appSettings.getProps().value(CLUSTER_NODE_HOST, "")); + hosts = extractHosts(appSettings.getProps().value(CLUSTER_HOSTS, "")); + nodeType = NodeType.parse(appSettings.getProps().value(CLUSTER_NODE_TYPE)); + nodeName = appSettings.getProps().value(CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString()); } int getPort() { @@ -86,8 +87,7 @@ final class ClusterProperties { checkArgument( port > 0 && port < 65_536, "Cluster port have been set to %d which is outside the range [1-65535].", - port - ); + port); // Test the networkInterfaces parameter try { @@ -97,9 +97,7 @@ final class ClusterProperties { inet -> checkArgument( StringUtils.isEmpty(inet) || localInterfaces.contains(inet), "Interface %s is not available on this machine.", - inet - ) - ); + inet)); } catch (SocketException e) { LOGGER.warn("Unable to retrieve network networkInterfaces. Interfaces won't be checked", e); } @@ -111,8 +109,7 @@ final class ClusterProperties { if (StringUtils.isNotEmpty(host)) { if (!host.contains(":")) { result.add( - String.format("%s:%s", host, DEFAULT_PORT) - ); + String.format("%s:%s", host, DEFAULT_PORT)); } else { result.add(host); } @@ -147,8 +144,8 @@ final class ClusterProperties { } private static void checkArgument(boolean expression, - @Nullable String messageTemplate, - @Nullable Object... args) { + @Nullable String messageTemplate, + @Nullable Object... args) { if (!expression) { throw new IllegalArgumentException(String.format(messageTemplate, args)); } diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java index 54c0c7bd69b..4769a8a1d95 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java @@ -52,18 +52,18 @@ import org.sonar.process.ProcessId; import static java.lang.String.format; import static java.util.stream.Collectors.toList; +import static org.sonar.NetworkUtils.getHostname; +import static org.sonar.NetworkUtils.getIPAddresses; import static org.sonar.application.cluster.ClusterProperties.HAZELCAST_CLUSTER_NAME; -import static org.sonar.process.NetworkUtils.getHostname; -import static org.sonar.process.NetworkUtils.getIPAddresses; -import static org.sonar.process.cluster.ClusterObjectKeys.CLIENT_UUIDS; -import static org.sonar.process.cluster.ClusterObjectKeys.CLUSTER_NAME; -import static org.sonar.process.cluster.ClusterObjectKeys.HOSTNAME; -import static org.sonar.process.cluster.ClusterObjectKeys.IP_ADDRESSES; -import static org.sonar.process.cluster.ClusterObjectKeys.LEADER; -import static org.sonar.process.cluster.ClusterObjectKeys.NODE_NAME; -import static org.sonar.process.cluster.ClusterObjectKeys.NODE_TYPE; -import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; -import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; +import static org.sonar.cluster.ClusterObjectKeys.CLIENT_UUIDS; +import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME; +import static org.sonar.cluster.ClusterObjectKeys.HOSTNAME; +import static org.sonar.cluster.ClusterObjectKeys.IP_ADDRESSES; +import static org.sonar.cluster.ClusterObjectKeys.LEADER; +import static org.sonar.cluster.ClusterObjectKeys.NODE_NAME; +import static org.sonar.cluster.ClusterObjectKeys.NODE_TYPE; +import static org.sonar.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; +import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; public class HazelcastCluster implements AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(HazelcastCluster.class); @@ -156,8 +156,7 @@ public class HazelcastCluster implements AutoCloseable { String clusterVersion = sqVersion.get(); if (!sqVersion.get().equals(sonarqubeVersion)) { throw new IllegalStateException( - format("The local version %s is not the same as the cluster %s", sonarqubeVersion, clusterVersion) - ); + format("The local version %s is not the same as the cluster %s", sonarqubeVersion, clusterVersion)); } } @@ -183,8 +182,7 @@ public class HazelcastCluster implements AutoCloseable { String clusterValue = property.get(); if (!property.get().equals(nodeValue)) { throw new MessageException( - format("This node has a cluster name [%s], which does not match [%s] from the cluster", nodeValue, clusterValue) - ); + format("This node has a cluster name [%s], which does not match [%s] from the cluster", nodeValue, clusterValue)); } } diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index d0fbdbd8ad4..d8ec697ddc7 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -33,7 +33,6 @@ import org.apache.commons.lang.StringUtils; import org.sonar.process.MessageException; import org.sonar.process.NodeType; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static com.google.common.net.InetAddresses.forString; @@ -43,12 +42,12 @@ import static java.util.Arrays.stream; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.joining; import static org.apache.commons.lang.StringUtils.isBlank; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_WEB_LEADER; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; +import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_WEB_LEADER; import static org.sonar.process.ProcessProperties.JDBC_URL; import static org.sonar.process.ProcessProperties.SEARCH_HOST; @@ -69,9 +68,9 @@ public class ClusterSettings implements Consumer<Props> { // Mandatory properties ensureMandatoryProperty(props, CLUSTER_NODE_TYPE); - String nodeTypeValue = props.nonNullValue(ProcessProperties.CLUSTER_NODE_TYPE); + String nodeTypeValue = props.nonNullValue(CLUSTER_NODE_TYPE); if (!NodeType.isValid(nodeTypeValue)) { - throw new MessageException(format("Invalid value for property [%s]: [%s], only [%s] are allowed", ProcessProperties.CLUSTER_NODE_TYPE, nodeTypeValue, + throw new MessageException(format("Invalid value for property [%s]: [%s], only [%s] are allowed", CLUSTER_NODE_TYPE, nodeTypeValue, Arrays.stream(NodeType.values()).map(NodeType::getValue).collect(joining(", ")))); } ensureMandatoryProperty(props, CLUSTER_HOSTS); @@ -182,7 +181,7 @@ public class ClusterSettings implements Consumer<Props> { if (!isClusterEnabled(settings)) { return asList(ProcessId.ELASTICSEARCH, ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); } - NodeType nodeType = NodeType.parse(settings.getValue(ProcessProperties.CLUSTER_NODE_TYPE).orElse(null)); + NodeType nodeType = NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE).orElse(null)); switch (nodeType) { case APPLICATION: return asList(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); @@ -196,7 +195,7 @@ public class ClusterSettings implements Consumer<Props> { public static boolean isLocalElasticsearchEnabled(AppSettings settings) { // elasticsearch is enabled on "search" nodes, but disabled on "application" nodes if (isClusterEnabled(settings.getProps())) { - return NodeType.parse(settings.getValue(ProcessProperties.CLUSTER_NODE_TYPE).orElse(null)) == NodeType.SEARCH; + return NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE).orElse(null)) == NodeType.SEARCH; } // elasticsearch is enabled in standalone mode diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java index 61b5feb26db..d993d930431 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java @@ -48,6 +48,8 @@ import org.sonar.process.logging.LogbackHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.slf4j.Logger.ROOT_LOGGER_NAME; import static org.sonar.application.process.StreamGobbler.LOGGER_GOBBLER; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.HAZELCAST_LOG_LEVEL; public class AppLoggingTest { @@ -248,7 +250,7 @@ public class AppLoggingTest { @Test public void no_info_log_from_hazelcast() throws IOException { - settings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); + settings.getProps().set(CLUSTER_ENABLED, "true"); underTest.configure(); assertThat( @@ -257,8 +259,8 @@ public class AppLoggingTest { @Test public void configure_logging_for_hazelcast() throws IOException { - settings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.getProps().set(ProcessProperties.HAZELCAST_LOG_LEVEL, "INFO"); + settings.getProps().set(CLUSTER_ENABLED, "true"); + settings.getProps().set(HAZELCAST_LOG_LEVEL, "INFO"); underTest.configure(); assertThat( diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java index 972720a6c7e..c950788e599 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; public class AppReloaderImplTest { @@ -67,7 +68,7 @@ public class AppReloaderImplTest { @Test public void throw_ISE_if_cluster_is_enabled() throws IOException { - AppSettings settings = new TestAppSettings().set(ProcessProperties.CLUSTER_ENABLED, "true"); + AppSettings settings = new TestAppSettings().set(CLUSTER_ENABLED, "true"); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Restart is not possible with cluster mode"); @@ -89,7 +90,7 @@ public class AppReloaderImplTest { @Test public void throw_MessageException_if_cluster_mode_changed() throws IOException { - verifyFailureIfPropertyValueChanged(ProcessProperties.CLUSTER_ENABLED); + verifyFailureIfPropertyValueChanged(CLUSTER_ENABLED); } private void verifyFailureIfPropertyValueChanged(String propertyKey) throws IOException { diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java index 760c6021c3b..3998aabe983 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java @@ -22,9 +22,11 @@ package org.sonar.application; import org.junit.Test; import org.sonar.application.cluster.AppStateClusterImpl; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.ProcessProperties; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; public class AppStateFactoryTest { @@ -33,9 +35,9 @@ public class AppStateFactoryTest { @Test public void create_cluster_implementation_if_cluster_is_enabled() { - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); - settings.set(ProcessProperties.CLUSTER_NAME, "foo"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_NAME, "foo"); AppState appState = underTest.create(); assertThat(appState).isInstanceOf(AppStateClusterImpl.class); diff --git a/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java index 7d3c5cee24d..91bd75d1ba4 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java @@ -41,7 +41,6 @@ import org.sonar.application.config.TestAppSettings; import org.sonar.application.process.ProcessLauncher; import org.sonar.application.process.ProcessMonitor; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.command.AbstractCommand; import org.sonar.process.command.CommandFactory; import org.sonar.process.command.EsCommand; @@ -53,6 +52,8 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; import static org.sonar.process.ProcessId.COMPUTE_ENGINE; import static org.sonar.process.ProcessId.ELASTICSEARCH; import static org.sonar.process.ProcessId.WEB_SERVER; @@ -130,9 +131,6 @@ public class SchedulerImplTest { underTest.awaitTermination(); } - private void enableAllProcesses() { - } - @Test public void all_processes_are_stopped_if_one_process_goes_down() throws Exception { Scheduler underTest = startAll(); @@ -237,8 +235,8 @@ public class SchedulerImplTest { @Test public void search_node_starts_only_elasticsearch() throws Exception { - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "search"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "search"); SchedulerImpl underTest = newScheduler(); underTest.schedule(); @@ -251,8 +249,8 @@ public class SchedulerImplTest { @Test public void application_node_starts_only_web_and_ce() throws Exception { appState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "application"); SchedulerImpl underTest = newScheduler(); underTest.schedule(); @@ -270,8 +268,8 @@ public class SchedulerImplTest { assertThat(appState.tryToLockWebLeader()).isTrue(); appState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "search"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "search"); SchedulerImpl underTest = newScheduler(); underTest.schedule(); @@ -287,8 +285,8 @@ public class SchedulerImplTest { assertThat(appState.tryToLockWebLeader()).isTrue(); appState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "application"); SchedulerImpl underTest = newScheduler(); underTest.schedule(); @@ -306,8 +304,8 @@ public class SchedulerImplTest { @Test public void web_server_waits_for_remote_elasticsearch_to_be_started_if_local_es_is_disabled() throws Exception { - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NODE_TYPE, "application"); SchedulerImpl underTest = newScheduler(); underTest.schedule(); diff --git a/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java b/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java index 9ac3dea9bec..b590e5937d8 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java +++ b/server/sonar-main/src/test/java/org/sonar/application/TestAppState.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; -import org.sonar.process.NetworkUtils; +import org.sonar.NetworkUtils; import org.sonar.process.ProcessId; public class TestAppState implements AppState { diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java index e1a903db8fd..7e8610c5e80 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java @@ -32,7 +32,6 @@ import org.sonar.application.AppStateListener; import org.sonar.application.config.TestAppSettings; import org.sonar.process.MessageException; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; @@ -41,10 +40,11 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.sonar.application.cluster.HazelcastTestHelper.createHazelcastClient; -import static org.sonar.application.cluster.HazelcastTestHelper.newApplicationSettings; -import static org.sonar.process.cluster.ClusterObjectKeys.CLUSTER_NAME; -import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.createHazelcastClient; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.newApplicationSettings; +import static org.sonar.cluster.ClusterObjectKeys.CLUSTER_NAME; +import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; public class AppStateClusterImplTest { @@ -57,7 +57,7 @@ public class AppStateClusterImplTest { @Test public void instantiation_throws_ISE_if_cluster_mode_is_disabled() throws Exception { TestAppSettings settings = new TestAppSettings(); - settings.set(ProcessProperties.CLUSTER_ENABLED, "false"); + settings.set(CLUSTER_ENABLED, "false"); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cluster is not enabled on this instance"); @@ -76,7 +76,7 @@ public class AppStateClusterImplTest { } @Test - public void log_when_sonarqube_is_joining_a_cluster () throws IOException, InterruptedException, IllegalAccessException, NoSuchFieldException { + public void log_when_sonarqube_is_joining_a_cluster() throws IOException, InterruptedException, IllegalAccessException, NoSuchFieldException { // Now launch an instance that try to be part of the hzInstance cluster TestAppSettings settings = newApplicationSettings(); @@ -86,8 +86,7 @@ public class AppStateClusterImplTest { try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(settings)) { verify(logger).info( eq("Joined a SonarQube cluster that contains the following hosts : [{}]"), - anyString() - ); + anyString()); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java index 68c257040f7..1b8c4870f14 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java @@ -20,18 +20,22 @@ package org.sonar.application.cluster; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.application.config.AppSettings; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.ProcessProperties; - -import java.util.Arrays; -import java.util.Collections; -import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; public class ClusterPropertiesTest { @Rule @@ -41,8 +45,8 @@ public class ClusterPropertiesTest { @Test public void test_default_values() throws Exception { - appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + appSettings.getProps().set(CLUSTER_ENABLED, "true"); + appSettings.getProps().set(CLUSTER_NODE_TYPE, "application"); ClusterProperties props = new ClusterProperties(appSettings); assertThat(props.getNetworkInterfaces()) @@ -55,13 +59,13 @@ public class ClusterPropertiesTest { @Test public void test_port_parameter() { - appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + appSettings.getProps().set(CLUSTER_ENABLED, "true"); + appSettings.getProps().set(CLUSTER_NAME, "sonarqube"); + appSettings.getProps().set(CLUSTER_NODE_TYPE, "application"); Stream.of("-50", "0", "65536", "128563").forEach( port -> { - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_PORT, port); + appSettings.getProps().set(CLUSTER_NODE_PORT, port); ClusterProperties clusterProperties = new ClusterProperties(appSettings); expectedException.expect(IllegalArgumentException.class); @@ -74,10 +78,10 @@ public class ClusterPropertiesTest { @Test public void test_interfaces_parameter() { - appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_HOST, "8.8.8.8"); // This IP belongs to Google - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + appSettings.getProps().set(CLUSTER_ENABLED, "true"); + appSettings.getProps().set(CLUSTER_NAME, "sonarqube"); + appSettings.getProps().set(CLUSTER_NODE_HOST, "8.8.8.8"); // This IP belongs to Google + appSettings.getProps().set(CLUSTER_NODE_TYPE, "application"); ClusterProperties clusterProperties = new ClusterProperties(appSettings); expectedException.expect(IllegalArgumentException.class); @@ -88,9 +92,9 @@ public class ClusterPropertiesTest { @Test public void validate_does_not_fail_if_cluster_enabled_and_name_specified() { - appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + appSettings.getProps().set(CLUSTER_ENABLED, "true"); + appSettings.getProps().set(CLUSTER_NAME, "sonarqube"); + appSettings.getProps().set(CLUSTER_NODE_TYPE, "application"); ClusterProperties clusterProperties = new ClusterProperties(appSettings); clusterProperties.validate(); @@ -98,25 +102,25 @@ public class ClusterPropertiesTest { @Test public void test_members() { - appSettings.getProps().set(ProcessProperties.CLUSTER_ENABLED, "true"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - appSettings.getProps().set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + appSettings.getProps().set(CLUSTER_ENABLED, "true"); + appSettings.getProps().set(CLUSTER_NAME, "sonarqube"); + appSettings.getProps().set(CLUSTER_NODE_TYPE, "application"); assertThat( new ClusterProperties(appSettings).getHosts()).isEqualTo( Collections.emptyList()); - appSettings.getProps().set(ProcessProperties.CLUSTER_HOSTS, "192.168.1.1"); + appSettings.getProps().set(CLUSTER_HOSTS, "192.168.1.1"); assertThat( new ClusterProperties(appSettings).getHosts()).isEqualTo( Arrays.asList("192.168.1.1:9003")); - appSettings.getProps().set(ProcessProperties.CLUSTER_HOSTS, "192.168.1.2:5501"); + appSettings.getProps().set(CLUSTER_HOSTS, "192.168.1.2:5501"); assertThat( new ClusterProperties(appSettings).getHosts()).containsExactlyInAnyOrder( "192.168.1.2:5501"); - appSettings.getProps().set(ProcessProperties.CLUSTER_HOSTS, "192.168.1.2:5501,192.168.1.1"); + appSettings.getProps().set(CLUSTER_HOSTS, "192.168.1.2:5501,192.168.1.1"); assertThat( new ClusterProperties(appSettings).getHosts()).containsExactlyInAnyOrder( "192.168.1.2:5501", "192.168.1.1:9003"); diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java index 2be53baca1d..4f2dfe53a2a 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java @@ -41,12 +41,11 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.slf4j.LoggerFactory; +import org.sonar.NetworkUtils; import org.sonar.application.AppStateListener; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.NetworkUtils; +import org.sonar.cluster.ClusterObjectKeys; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; -import org.sonar.process.cluster.ClusterObjectKeys; import static java.lang.String.format; import static junit.framework.TestCase.fail; @@ -55,16 +54,17 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.sonar.application.cluster.HazelcastTestHelper.closeAllHazelcastClients; -import static org.sonar.application.cluster.HazelcastTestHelper.createHazelcastClient; -import static org.sonar.application.cluster.HazelcastTestHelper.newApplicationSettings; -import static org.sonar.application.cluster.HazelcastTestHelper.newSearchSettings; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_PORT; -import static org.sonar.process.cluster.ClusterObjectKeys.LEADER; -import static org.sonar.process.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; -import static org.sonar.process.cluster.ClusterObjectKeys.SONARQUBE_VERSION; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.closeAllHazelcastClients; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.createHazelcastClient; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.newApplicationSettings; +import static org.sonar.application.cluster.HazelcastClusterTestHelper.newSearchSettings; +import static org.sonar.cluster.ClusterObjectKeys.LEADER; +import static org.sonar.cluster.ClusterObjectKeys.OPERATIONAL_PROCESSES; +import static org.sonar.cluster.ClusterObjectKeys.SONARQUBE_VERSION; +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_PORT; public class HazelcastClusterTest { @Rule @@ -158,7 +158,7 @@ public class HazelcastClusterTest { ClusterProperties clusterProperties = new ClusterProperties(testAppSettings); try (HazelcastCluster hzCluster = HazelcastCluster.create(clusterProperties)) { assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).isEmpty(); - HazelcastInstance hzClient = HazelcastTestHelper.createHazelcastClient(hzCluster); + HazelcastInstance hzClient = createHazelcastClient(hzCluster); assertThat(hzCluster.hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS)).containsExactly(hzClient.getLocalEndpoint().getUuid()); CountDownLatch latch = new CountDownLatch(1); @@ -241,7 +241,7 @@ public class HazelcastClusterTest { @Test public void simulate_network_cluster() throws InterruptedException { TestAppSettings settings = newApplicationSettings(); - settings.set(ProcessProperties.CLUSTER_NODE_HOST, InetAddress.getLoopbackAddress().getHostAddress()); + settings.set(CLUSTER_NODE_HOST, InetAddress.getLoopbackAddress().getHostAddress()); AppStateListener listener = mock(AppStateListener.class); try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(settings)) { diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTestHelper.java index 24186ffd180..b1a03efba0b 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTestHelper.java @@ -27,9 +27,12 @@ import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.ProcessProperties; -public class HazelcastTestHelper { +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; + +public class HazelcastClusterTestHelper { // Be careful this test won't work if parallel tests is used private static final List<HazelcastInstance> HAZELCAST_INSTANCES = new ArrayList<>(); @@ -41,8 +44,7 @@ public class HazelcastTestHelper { clientConfig.getNetworkConfig().getAddresses().add( String.format("%s:%d", socketAddress.getHostString(), - socketAddress.getPort() - )); + socketAddress.getPort())); clientConfig.getGroupConfig().setName(hzCluster.getName()); HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig); HAZELCAST_INSTANCES.add(hazelcastInstance); @@ -55,29 +57,28 @@ public class HazelcastTestHelper { static void closeAllHazelcastClients() { HAZELCAST_INSTANCES.stream().forEach( - hz -> { - try { - hz.shutdown(); - } catch (Exception ex) { - // Ignore it - } + hz -> { + try { + hz.shutdown(); + } catch (Exception ex) { + // Ignore it } - ); + }); } static TestAppSettings newApplicationSettings() { TestAppSettings settings = new TestAppSettings(); - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NAME, "sonarqube"); + settings.set(CLUSTER_NODE_TYPE, "application"); return settings; } static TestAppSettings newSearchSettings() { TestAppSettings settings = new TestAppSettings(); - settings.set(ProcessProperties.CLUSTER_ENABLED, "true"); - settings.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - settings.set(ProcessProperties.CLUSTER_NODE_TYPE, "search"); + settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_NAME, "sonarqube"); + settings.set(CLUSTER_NODE_TYPE, "search"); return settings; } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java index 4e0c1e500ed..be22b4f8bf2 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java @@ -34,11 +34,11 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.sonar.process.MessageException; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_HOST; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; +import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.JDBC_URL; import static org.sonar.process.ProcessProperties.SEARCH_HOST; @@ -52,61 +52,61 @@ public class ClusterSettingsLoopbackTest { @DataPoints("parameter") public static final ValueAndResult[] VALID_SINGLE_IP = { - // Valid IPs - new ValueAndResult("1.2.3.4", NOT_LOCAL_ADDRESS), - new ValueAndResult("1.2.3.4:9001", NOT_LOCAL_ADDRESS), - new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", NOT_LOCAL_ADDRESS), - new ValueAndResult("[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", NOT_LOCAL_ADDRESS), - - // Valid Name - new ValueAndResult("www.sonarqube.org", NOT_LOCAL_ADDRESS), - new ValueAndResult("www.google.fr", NOT_LOCAL_ADDRESS), - new ValueAndResult("www.google.com, www.sonarsource.com, wwww.sonarqube.org", NOT_LOCAL_ADDRESS), - - new ValueAndResult("...", NOT_RESOLVABLE), - new ValueAndResult("භඦආ\uD801\uDC8C\uD801\uDC8B", NOT_RESOLVABLE), - - // Valide IPs List - new ValueAndResult("1.2.3.4,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", NOT_LOCAL_ADDRESS), - new ValueAndResult("1.2.3.4:9001,[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", NOT_LOCAL_ADDRESS), - new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,1.2.3.4:9001", NOT_LOCAL_ADDRESS), - new ValueAndResult("[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccc", NOT_LOCAL_ADDRESS), - - // Loopback IPs - new ValueAndResult("localhost", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.0.0.1", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.1.1.1", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.243.136.241", LOOPBACK_FORBIDDEN), - new ValueAndResult("::1", LOOPBACK_FORBIDDEN), - new ValueAndResult("0:0:0:0:0:0:0:1", LOOPBACK_FORBIDDEN), - new ValueAndResult("localhost:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.0.0.1:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.1.1.1:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.243.136.241:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[::1]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), - - // Loopback IPs list - new ValueAndResult("127.0.0.1,192.168.11.25", LOOPBACK_FORBIDDEN), - new ValueAndResult("192.168.11.25,127.1.1.1", LOOPBACK_FORBIDDEN), - new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,0:0:0:0:0:0:0:1", LOOPBACK_FORBIDDEN), - new ValueAndResult("0:0:0:0:0:0:0:1,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), - new ValueAndResult("2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb,::1", LOOPBACK_FORBIDDEN), - new ValueAndResult("::1,2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), - new ValueAndResult("::1,2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb,2a01:e34:ef1f:dbb0:b3f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), - new ValueAndResult("localhost:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.0.0.1:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.1.1.1:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.243.136.241:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[::1]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("127.0.0.1,192.168.11.25:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("192.168.11.25:9001,127.1.1.1:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[0:0:0:0:0:0:0:1]:9001,[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001,[::1]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[::1]:9001,[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN), - new ValueAndResult("[::1]:9001,[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001,[2a01:e34:ef1f:dbb0:b3f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN) + // Valid IPs + new ValueAndResult("1.2.3.4", NOT_LOCAL_ADDRESS), + new ValueAndResult("1.2.3.4:9001", NOT_LOCAL_ADDRESS), + new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", NOT_LOCAL_ADDRESS), + new ValueAndResult("[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", NOT_LOCAL_ADDRESS), + + // Valid Name + new ValueAndResult("www.sonarqube.org", NOT_LOCAL_ADDRESS), + new ValueAndResult("www.google.fr", NOT_LOCAL_ADDRESS), + new ValueAndResult("www.google.com, www.sonarsource.com, wwww.sonarqube.org", NOT_LOCAL_ADDRESS), + + new ValueAndResult("...", NOT_RESOLVABLE), + new ValueAndResult("භඦආ\uD801\uDC8C\uD801\uDC8B", NOT_RESOLVABLE), + + // Valide IPs List + new ValueAndResult("1.2.3.4,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", NOT_LOCAL_ADDRESS), + new ValueAndResult("1.2.3.4:9001,[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", NOT_LOCAL_ADDRESS), + new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,1.2.3.4:9001", NOT_LOCAL_ADDRESS), + new ValueAndResult("[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccc", NOT_LOCAL_ADDRESS), + + // Loopback IPs + new ValueAndResult("localhost", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.0.0.1", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.1.1.1", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.243.136.241", LOOPBACK_FORBIDDEN), + new ValueAndResult("::1", LOOPBACK_FORBIDDEN), + new ValueAndResult("0:0:0:0:0:0:0:1", LOOPBACK_FORBIDDEN), + new ValueAndResult("localhost:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.0.0.1:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.1.1.1:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.243.136.241:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[::1]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), + + // Loopback IPs list + new ValueAndResult("127.0.0.1,192.168.11.25", LOOPBACK_FORBIDDEN), + new ValueAndResult("192.168.11.25,127.1.1.1", LOOPBACK_FORBIDDEN), + new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,0:0:0:0:0:0:0:1", LOOPBACK_FORBIDDEN), + new ValueAndResult("0:0:0:0:0:0:0:1,2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), + new ValueAndResult("2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb,::1", LOOPBACK_FORBIDDEN), + new ValueAndResult("::1,2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), + new ValueAndResult("::1,2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb,2a01:e34:ef1f:dbb0:b3f6:a978:c5c0:9ccb", LOOPBACK_FORBIDDEN), + new ValueAndResult("localhost:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.0.0.1:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.1.1.1:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.243.136.241:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[::1]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("127.0.0.1,192.168.11.25:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("192.168.11.25:9001,127.1.1.1:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb,[0:0:0:0:0:0:0:1]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[0:0:0:0:0:0:0:1]:9001,[2a01:e34:ef1f:dbb0:c2f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001,[::1]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[::1]:9001,[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN), + new ValueAndResult("[::1]:9001,[2a01:e34:ef1f:dbb0:c3f6:a978:c5c0:9ccb]:9001,[2a01:e34:ef1f:dbb0:b3f6:a978:c5c0:9ccb]:9001", LOOPBACK_FORBIDDEN) }; @DataPoints("key") @@ -117,7 +117,6 @@ public class ClusterSettingsLoopbackTest { new Key(CLUSTER_HOSTS, true, true) }; - @DataPoints("unresolvable_hosts") public static final String[] UNRESOLVABLE_HOSTS = { }; @@ -152,7 +151,7 @@ public class ClusterSettingsLoopbackTest { } } - private static TestAppSettings getClusterSettings() { + private static TestAppSettings getClusterSettings() { String localAddress = null; try { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java index 166a0e0967a..dc35de91b52 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java @@ -32,13 +32,13 @@ import org.sonar.process.MessageException; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; +import static org.sonar.cluster.ClusterProperties.CLUSTER_HOSTS; +import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; +import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessId.COMPUTE_ENGINE; import static org.sonar.process.ProcessId.ELASTICSEARCH; import static org.sonar.process.ProcessId.WEB_SERVER; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; import static org.sonar.process.ProcessProperties.JDBC_URL; import static org.sonar.process.ProcessProperties.SEARCH_HOST; @@ -134,7 +134,6 @@ public class ClusterSettingsTest { new ClusterSettings().accept(settings.getProps()); } - @Test public void accept_does_nothing_if_cluster_is_disabled() { TestAppSettings settings = new TestAppSettings(); |