aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-08-25 11:54:26 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-13 15:50:49 +0200
commit80269a5d22553335f22f3e8a8a5840724fb154f9 (patch)
treedf2a88bb4ae61251040499ec77f2d217246512a1 /server
parent904cd8b327790c31d1abe0bceb0007015e74dfdf (diff)
downloadsonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.tar.gz
sonarqube-80269a5d22553335f22f3e8a8a5840724fb154f9.zip
SONAR-9741 move shared cluster related classes to sonar-cluster
Diffstat (limited to 'server')
-rw-r--r--server/pom.xml1
-rw-r--r--server/sonar-ce/pom.xml11
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java6
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java2
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java4
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java17
-rw-r--r--server/sonar-cluster/pom.xml63
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/NetworkUtils.java (renamed from server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java)2
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java (renamed from server/sonar-process/src/main/java/org/sonar/process/cluster/ClusterObjectKeys.java)2
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterProperties.java54
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java (renamed from server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java)23
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapper.java (renamed from server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapper.java)2
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapperImpl.java (renamed from server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java)13
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/package-info.java23
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/package-info.java (renamed from server/sonar-ce/src/main/java/org/sonar/ce/cluster/package-info.java)2
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/package-info.java (renamed from server/sonar-process/src/main/java/org/sonar/process/cluster/package-info.java)2
-rw-r--r--server/sonar-cluster/src/test/java/org/sonar/NetworkUtilsTest.java (renamed from server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java)4
-rw-r--r--server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastClientWrapperImplTest.java (renamed from server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java)37
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/AppLogging.java4
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java2
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/AppStateImpl.java2
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/cluster/AppStateClusterImpl.java11
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/cluster/ClusterProperties.java35
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/cluster/HazelcastCluster.java28
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java21
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java8
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java5
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java10
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java26
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/TestAppState.java2
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/AppStateClusterImplTest.java17
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterPropertiesTest.java52
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTest.java30
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastClusterTestHelper.java (renamed from server/sonar-main/src/test/java/org/sonar/application/cluster/HazelcastTestHelper.java)35
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java123
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java9
-rw-r--r--server/sonar-process/pom.xml4
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/NodeType.java3
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java24
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java11
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java23
-rw-r--r--server/sonar-server/pom.xml4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java30
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java7
50 files changed, 490 insertions, 331 deletions
diff --git a/server/pom.xml b/server/pom.xml
index bd0564d4620..ed4377b805e 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -13,6 +13,7 @@
<name>SonarQube :: Server :: Parent</name>
<modules>
+ <module>sonar-cluster</module>
<module>sonar-process</module>
<module>sonar-main</module>
<module>sonar-db-core</module>
diff --git a/server/sonar-ce/pom.xml b/server/sonar-ce/pom.xml
index 007270e7793..03472a98f01 100644
--- a/server/sonar-ce/pom.xml
+++ b/server/sonar-ce/pom.xml
@@ -12,11 +12,16 @@
<dependencies>
<dependency>
- <groupId>org.sonarsource.sonarqube</groupId>
+ <groupId>${project.groupId}</groupId>
<artifactId>sonar-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>sonar-cluster</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.nanohttpd</groupId>
<artifactId>nanohttpd</artifactId>
</dependency>
@@ -30,10 +35,6 @@
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast-client</artifactId>
- </dependency>
<!-- unit tests -->
<dependency>
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
index cfb52e7cc95..87436b26d1c 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/CeDistributedInformationImpl.java
@@ -24,12 +24,12 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import org.picocontainer.Startable;
-import org.sonar.ce.cluster.HazelcastClientWrapper;
import org.sonar.ce.taskprocessor.CeWorkerFactory;
-import org.sonar.process.cluster.ClusterObjectKeys;
+import org.sonar.cluster.ClusterObjectKeys;
+import org.sonar.cluster.localclient.HazelcastClientWrapper;
+import static org.sonar.cluster.ClusterObjectKeys.WORKER_UUIDS;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
-import static org.sonar.process.cluster.ClusterObjectKeys.WORKER_UUIDS;
/**
* Provide the set of worker's UUID in a clustered SonarQube instance
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
index 0536be88443..d05761ecd7d 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -46,7 +46,6 @@ import org.sonar.ce.CeQueueModule;
import org.sonar.ce.CeTaskCommonsModule;
import org.sonar.ce.StandaloneCeDistributedInformation;
import org.sonar.ce.cleaning.CeCleaningModule;
-import org.sonar.ce.cluster.HazelcastClientWrapperImpl;
import org.sonar.ce.db.ReadOnlyPropertiesDao;
import org.sonar.ce.log.CeProcessLogging;
import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
@@ -56,6 +55,7 @@ import org.sonar.ce.settings.ProjectConfigurationFactory;
import org.sonar.ce.taskprocessor.CeProcessingScheduler;
import org.sonar.ce.taskprocessor.CeTaskProcessorModule;
import org.sonar.ce.user.CeUserSession;
+import org.sonar.cluster.localclient.HazelcastClientWrapperImpl;
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.config.ConfigurationProvider;
import org.sonar.core.config.CorePropertyDefinitions;
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
index 6bb5387cf7d..74b34822f6a 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/CeDistributedInformationImplTest.java
@@ -26,14 +26,14 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
-import org.sonar.ce.cluster.HazelcastClientWrapperImpl;
import org.sonar.ce.taskprocessor.CeWorkerFactory;
+import org.sonar.cluster.localclient.HazelcastClientWrapperImpl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.process.cluster.ClusterObjectKeys.WORKER_UUIDS;
+import static org.sonar.cluster.ClusterObjectKeys.WORKER_UUIDS;
public class CeDistributedInformationImplTest {
private String clientUUID1 = "1";
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 85608130f81..28b8e81f499 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -33,17 +33,17 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.MutablePicoContainer;
+import org.sonar.NetworkUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.ce.CeDistributedInformationImpl;
import org.sonar.ce.StandaloneCeDistributedInformation;
-import org.sonar.ce.cluster.HazelcastClientWrapperImpl;
-import org.sonar.ce.cluster.HazelcastTestHelper;
+import org.sonar.cluster.internal.HazelcastTestHelper;
+import org.sonar.cluster.localclient.HazelcastClientWrapperImpl;
import org.sonar.db.DbTester;
import org.sonar.db.property.PropertyDto;
-import org.sonar.process.NetworkUtils;
import org.sonar.process.ProcessId;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
@@ -51,6 +51,9 @@ import org.sonar.process.Props;
import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE;
import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
import static org.sonar.process.ProcessProperties.PATH_DATA;
@@ -82,12 +85,12 @@ public class ComputeEngineContainerImplTest {
@Test
public void real_start_with_cluster() throws IOException {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
- HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(port);
+ HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(NetworkUtils.getHostname(), port);
Properties properties = getProperties();
- properties.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "application");
- properties.setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
- properties.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, String.format("%s:%d", hzInstance.getCluster().getLocalMember().getAddress().getHost(), port));
+ properties.setProperty(CLUSTER_NODE_TYPE, "application");
+ properties.setProperty(CLUSTER_ENABLED, "true");
+ properties.setProperty(CLUSTER_LOCALENDPOINT, String.format("%s:%d", hzInstance.getCluster().getLocalMember().getAddress().getHost(), port));
// required persisted properties
insertProperty(CoreProperties.SERVER_ID, "a_startup_id");
diff --git a/server/sonar-cluster/pom.xml b/server/sonar-cluster/pom.xml
new file mode 100644
index 00000000000..5ab47ff6fb2
--- /dev/null
+++ b/server/sonar-cluster/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.sonarsource.sonarqube</groupId>
+ <artifactId>server</artifactId>
+ <version>6.6-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>sonar-cluster</artifactId>
+ <name>SonarQube :: Cluster</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <!-- unit tests -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java b/server/sonar-cluster/src/main/java/org/sonar/NetworkUtils.java
index d643cf9ca75..0121f95aa79 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/NetworkUtils.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.process;
+package org.sonar;
import java.io.IOException;
import java.net.Inet4Address;
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/ClusterObjectKeys.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java
index 4fd578d0429..b9634c02f41 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/ClusterObjectKeys.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterObjectKeys.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.process.cluster;
+package org.sonar.cluster;
/**
* This class holds all object keys accessible via Hazelcast
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterProperties.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterProperties.java
new file mode 100644
index 00000000000..018150341f8
--- /dev/null
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/ClusterProperties.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.cluster;
+
+import java.util.Properties;
+
+import static java.lang.String.valueOf;
+
+public final class ClusterProperties {
+ public static final String CLUSTER_ENABLED = "sonar.cluster.enabled";
+ public static final String CLUSTER_NODE_TYPE = "sonar.cluster.node.type";
+ public static final String CLUSTER_SEARCH_HOSTS = "sonar.cluster.search.hosts";
+ public static final String CLUSTER_HOSTS = "sonar.cluster.hosts";
+ public static final String CLUSTER_NODE_PORT = "sonar.cluster.node.port";
+ public static final String CLUSTER_NODE_HOST = "sonar.cluster.node.host";
+ public static final String CLUSTER_NODE_NAME = "sonar.cluster.node.name";
+ public static final String CLUSTER_NAME = "sonar.cluster.name";
+ public static final String HAZELCAST_LOG_LEVEL = "sonar.log.level.app.hazelcast";
+ public static final String CLUSTER_WEB_LEADER = "sonar.cluster.web.startupLeader";
+ // Internal property used by sonar-application to share the local endpoint of Hazelcast
+ public static final String CLUSTER_LOCALENDPOINT = "sonar.cluster.hazelcast.localEndPoint";
+ // Internal property used by sonar-application to share the local UUID of the Hazelcast member
+ public static final String CLUSTER_MEMBERUUID = "sonar.cluster.hazelcast.memberUUID";
+
+ private ClusterProperties() {
+ // prevents instantiation
+ }
+
+ public static void putClusterDefaults(Properties properties) {
+ properties.put(CLUSTER_ENABLED, valueOf(false));
+ properties.put(CLUSTER_NAME, "sonarqube");
+ properties.put(CLUSTER_NODE_HOST, "");
+ properties.put(CLUSTER_HOSTS, "");
+ properties.put(CLUSTER_NODE_PORT, "9003");
+ properties.put(HAZELCAST_LOG_LEVEL, "WARN");
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java
index 5774dbce735..f3a51e8757f 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastTestHelper.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/HazelcastTestHelper.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.ce.cluster;
+package org.sonar.cluster.internal;
import com.hazelcast.config.Config;
import com.hazelcast.config.JoinConfig;
@@ -28,13 +28,14 @@ import com.hazelcast.core.ClientListener;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.net.InetAddress;
-
-import static org.sonar.process.NetworkUtils.getHostname;
-import static org.sonar.process.cluster.ClusterObjectKeys.CLIENT_UUIDS;
+import org.sonar.cluster.ClusterObjectKeys;
public class HazelcastTestHelper {
+ private HazelcastTestHelper() {
+ // prevents instantiation
+ }
- public static HazelcastInstance createHazelcastCluster(int port) {
+ public static HazelcastInstance createHazelcastCluster(String hostname, int port) {
Config hzConfig = new Config();
hzConfig.getGroupConfig().setName("sonarqube");
@@ -44,9 +45,9 @@ public class HazelcastTestHelper {
.setPort(port)
.setReuseAddress(true);
- netConfig.getInterfaces()
- .setEnabled(true)
- .addInterface(InetAddress.getLoopbackAddress().getHostAddress());
+ netConfig.getInterfaces()
+ .setEnabled(true)
+ .addInterface(InetAddress.getLoopbackAddress().getHostAddress());
// Only allowing TCP/IP configuration
JoinConfig joinConfig = netConfig.getJoin();
@@ -66,7 +67,7 @@ public class HazelcastTestHelper {
.setProperty("hazelcast.logging.type", "slf4j");
// Trying to resolve the hostname
- hzConfig.getMemberAttributeConfig().setStringAttribute("HOSTNAME", getHostname());
+ hzConfig.getMemberAttributeConfig().setStringAttribute("HOSTNAME", hostname);
// We are not using the partition group of Hazelcast, so disabling it
hzConfig.getPartitionGroupConfig().setEnabled(false);
@@ -84,12 +85,12 @@ public class HazelcastTestHelper {
@Override
public void clientConnected(Client client) {
- hzInstance.getSet(CLIENT_UUIDS).add(client.getUuid());
+ hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).add(client.getUuid());
}
@Override
public void clientDisconnected(Client client) {
- hzInstance.getSet(CLIENT_UUIDS).remove(client.getUuid());
+ hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS).remove(client.getUuid());
}
}
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapper.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapper.java
index a9ee247cd39..ae42934f52a 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapper.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapper.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.ce.cluster;
+package org.sonar.cluster.localclient;
import java.util.List;
import java.util.Map;
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapperImpl.java
index a4b40580540..223b5ce6700 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/HazelcastClientWrapperImpl.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClientWrapperImpl.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.ce.cluster;
+package org.sonar.cluster.localclient;
import com.google.common.annotations.VisibleForTesting;
import com.hazelcast.client.HazelcastClient;
@@ -30,11 +30,12 @@ import java.util.Set;
import java.util.concurrent.locks.Lock;
import org.picocontainer.Startable;
import org.sonar.api.config.Configuration;
-import org.sonar.process.ProcessProperties;
+import org.sonar.cluster.ClusterObjectKeys;
import static com.google.common.base.Preconditions.checkState;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
-import static org.sonar.process.cluster.ClusterObjectKeys.CLIENT_UUIDS;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT;
/**
* This class will connect as a Hazelcast client to the local instance of Hazelcluster
@@ -48,8 +49,8 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
protected HazelcastInstance hzInstance;
public HazelcastClientWrapperImpl(Configuration config) {
- boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
- String clusterLocalEndPoint = config.get(ProcessProperties.CLUSTER_LOCALENDPOINT).orElse(null);
+ boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false);
+ String clusterLocalEndPoint = config.get(CLUSTER_LOCALENDPOINT).orElse(null);
checkState(clusterEnabled, "Cluster is not enabled");
checkState(isNotEmpty(clusterLocalEndPoint), "LocalEndPoint have not been set");
@@ -95,7 +96,7 @@ public class HazelcastClientWrapperImpl implements Startable, HazelcastClientWra
@Override
public Set<String> getConnectedClients() {
- return hzInstance.getSet(CLIENT_UUIDS);
+ return hzInstance.getSet(ClusterObjectKeys.CLIENT_UUIDS);
}
@Override
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/package-info.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/package-info.java
new file mode 100644
index 00000000000..f9f4c523bdc
--- /dev/null
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.cluster.localclient;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/package-info.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/package-info.java
index 42c5c45b237..fd38c5d9291 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/cluster/package-info.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.ce.cluster;
+package org.sonar.cluster;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/package-info.java b/server/sonar-cluster/src/main/java/org/sonar/package-info.java
index 65df8dff487..9a6f335c580 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/cluster/package-info.java
+++ b/server/sonar-cluster/src/main/java/org/sonar/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.process.cluster;
+package org.sonar;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java b/server/sonar-cluster/src/test/java/org/sonar/NetworkUtilsTest.java
index 6450790490d..2b8a1c9a8f5 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
+++ b/server/sonar-cluster/src/test/java/org/sonar/NetworkUtilsTest.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.process;
+package org.sonar;
import java.net.InetAddress;
import java.util.HashSet;
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.process.NetworkUtils.getNextAvailablePort;
+import static org.sonar.NetworkUtils.getNextAvailablePort;
public class NetworkUtilsTest {
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastClientWrapperImplTest.java
index 58be787c69f..41c81e58349 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/cluster/HazelcastClientWrapperImplTest.java
+++ b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastClientWrapperImplTest.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.ce.cluster;
+package org.sonar.cluster.localclient;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
@@ -40,6 +40,7 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.RandomStringUtils;
+import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -49,13 +50,15 @@ 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.api.config.PropertyDefinitions;
import org.sonar.api.config.internal.MapSettings;
-import org.sonar.process.NetworkUtils;
-import org.sonar.process.ProcessProperties;
+import org.sonar.cluster.internal.HazelcastTestHelper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT;
public class HazelcastClientWrapperImplTest {
@Rule
@@ -70,7 +73,7 @@ public class HazelcastClientWrapperImplTest {
@BeforeClass
public static void setupHazelcastClusterAndHazelcastClient() {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
- hzCluster = HazelcastTestHelper.createHazelcastCluster(port);
+ hzCluster = HazelcastTestHelper.createHazelcastCluster(NetworkUtils.getHostname(), port);
MapSettings settings = createClusterSettings("localhost:" + port);
hzClient = new HazelcastClientWrapperImpl(settings.asConfig());
@@ -114,7 +117,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_CLUSTER_ENABLED_is_false() {
MapSettings settings = createClusterSettings("localhost:9003");
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
+ settings.setProperty(CLUSTER_ENABLED, false);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cluster is not enabled");
@@ -125,7 +128,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_ENABLED() {
MapSettings settings = createClusterSettings("localhost:9003");
- settings.removeProperty(ProcessProperties.CLUSTER_ENABLED);
+ settings.removeProperty(CLUSTER_ENABLED);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cluster is not enabled");
@@ -136,7 +139,7 @@ public class HazelcastClientWrapperImplTest {
@Test
public void constructor_throws_ISE_if_missing_CLUSTER_LOCALENDPOINT() {
MapSettings settings = createClusterSettings("localhost:9003");
- settings.removeProperty(ProcessProperties.CLUSTER_LOCALENDPOINT);
+ settings.removeProperty(CLUSTER_LOCALENDPOINT);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("LocalEndPoint have not been set");
@@ -148,7 +151,7 @@ public class HazelcastClientWrapperImplTest {
public void client_must_connect_to_hazelcast() throws InterruptedException {
int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress());
// Launch a fake Hazelcast instance
- HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(port);
+ HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(NetworkUtils.getHostname(), port);
MapSettings settings = createClusterSettings("localhost:" + port);
HazelcastClientWrapperImpl hazelcastClientWrapperImpl = new HazelcastClientWrapperImpl(settings.asConfig());
@@ -174,9 +177,9 @@ public class HazelcastClientWrapperImplTest {
Arrays.asList(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10)));
Map<String, Set<String>> replicatedMap = hzClient.getReplicatedMap("TEST1");
replicatedMap.put("KEY1", ImmutableSet.copyOf(setTest));
- assertThat(hzCluster.getReplicatedMap("TEST1"))
+ Assertions.assertThat(hzCluster.getReplicatedMap("TEST1"))
.containsOnlyKeys("KEY1");
- assertThat(hzCluster.getReplicatedMap("TEST1").get("KEY1"))
+ Assertions.assertThat(hzCluster.getReplicatedMap("TEST1").get("KEY1"))
.isEqualTo(setTest);
} finally {
hzClient.stop();
@@ -231,9 +234,9 @@ public class HazelcastClientWrapperImplTest {
hzClient.start();
try {
HazelcastClientInstanceImpl realClient = ((HazelcastClientProxy) hzClient.hzInstance).client;
- assertThat(realClient.getClientConfig().getProperty("hazelcast.tcp.join.port.try.count")).isEqualTo("10");
- assertThat(realClient.getClientConfig().getProperty("hazelcast.phone.home.enabled")).isEqualTo("false");
- assertThat(realClient.getClientConfig().getProperty("hazelcast.logging.type")).isEqualTo("slf4j");
+ Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.tcp.join.port.try.count")).isEqualTo("10");
+ Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.phone.home.enabled")).isEqualTo("false");
+ Assertions.assertThat(realClient.getClientConfig().getProperty("hazelcast.logging.type")).isEqualTo("slf4j");
} finally {
hzClient.stop();
}
@@ -251,9 +254,9 @@ public class HazelcastClientWrapperImplTest {
hzClient.start();
hzClient.stop();
memoryAppender.stop();
- assertThat(memoryAppender.events).isNotEmpty();
+ Assertions.assertThat(memoryAppender.events).isNotEmpty();
memoryAppender.events.stream().forEach(
- e -> assertThat(e.getLoggerName()).startsWith("com.hazelcast"));
+ e -> Assertions.assertThat(e.getLoggerName()).startsWith("com.hazelcast"));
}
private class ClientListenerImpl implements ClientListener {
@@ -272,8 +275,8 @@ public class HazelcastClientWrapperImplTest {
private static MapSettings createClusterSettings(String localEndPoint) {
return new MapSettings(new PropertyDefinitions())
- .setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, localEndPoint)
- .setProperty(ProcessProperties.CLUSTER_ENABLED, "true");
+ .setProperty(CLUSTER_LOCALENDPOINT, localEndPoint)
+ .setProperty(CLUSTER_ENABLED, "true");
}
private class MemoryAppender<E> extends AppenderBase<E> {
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();
diff --git a/server/sonar-process/pom.xml b/server/sonar-process/pom.xml
index ac07efaa96c..75075eae1ad 100644
--- a/server/sonar-process/pom.xml
+++ b/server/sonar-process/pom.xml
@@ -17,6 +17,10 @@
<dependencies>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>sonar-cluster</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
diff --git a/server/sonar-process/src/main/java/org/sonar/process/NodeType.java b/server/sonar-process/src/main/java/org/sonar/process/NodeType.java
index 63c532b687d..ecd8e44bc95 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/NodeType.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/NodeType.java
@@ -20,6 +20,7 @@
package org.sonar.process;
import static java.util.Arrays.stream;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE;
public enum NodeType {
APPLICATION("application"), SEARCH("search");
@@ -38,7 +39,7 @@ public enum NodeType {
return stream(values())
.filter(t -> nodeType.equals(t.value))
.findFirst()
- .orElseThrow(() -> new IllegalArgumentException("Invalid value for [" + ProcessProperties.CLUSTER_NODE_TYPE + "]: [" + nodeType + "]"));
+ .orElseThrow(() -> new IllegalArgumentException("Invalid value for [" + CLUSTER_NODE_TYPE + "]: [" + nodeType + "]"));
}
public static boolean isValid(String nodeType) {
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
index fa35616bc06..24b9be0885f 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java
@@ -23,26 +23,15 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Properties;
+import org.sonar.NetworkUtils;
+
+import static org.sonar.cluster.ClusterProperties.putClusterDefaults;
/**
* Constants shared by search, web server and app processes.
* They are almost all the properties defined in conf/sonar.properties.
*/
public class ProcessProperties {
- public static final String CLUSTER_ENABLED = "sonar.cluster.enabled";
- public static final String CLUSTER_NODE_TYPE = "sonar.cluster.node.type";
- public static final String CLUSTER_SEARCH_HOSTS = "sonar.cluster.search.hosts";
- public static final String CLUSTER_HOSTS = "sonar.cluster.hosts";
- public static final String CLUSTER_NODE_PORT = "sonar.cluster.node.port";
- public static final String CLUSTER_NODE_HOST = "sonar.cluster.node.host";
- public static final String CLUSTER_NODE_NAME = "sonar.cluster.node.name";
- public static final String CLUSTER_NAME = "sonar.cluster.name";
- public static final String HAZELCAST_LOG_LEVEL = "sonar.log.level.app.hazelcast";
- public static final String CLUSTER_WEB_LEADER = "sonar.cluster.web.startupLeader";
- // Internal property used by sonar-application to share the local endpoint of Hazelcast
- public static final String CLUSTER_LOCALENDPOINT = "sonar.cluster.hazelcast.localEndPoint";
- // Internal property used by sonar-application to share the local UUID of the Hazelcast member
- public static final String CLUSTER_MEMBERUUID = "sonar.cluster.hazelcast.memberUUID";
public static final String JDBC_URL = "sonar.jdbc.url";
public static final String JDBC_DRIVER_PATH = "sonar.jdbc.driverPath";
@@ -137,12 +126,7 @@ public class ProcessProperties {
defaults.put(JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS, "600000");
defaults.put(JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS, "30000");
- defaults.put(CLUSTER_ENABLED, "false");
- defaults.put(CLUSTER_NAME, "sonarqube");
- defaults.put(CLUSTER_NODE_HOST, "");
- defaults.put(CLUSTER_HOSTS, "");
- defaults.put(CLUSTER_NODE_PORT, "9003");
- defaults.put(HAZELCAST_LOG_LEVEL, "WARN");
+ putClusterDefaults(defaults);
return defaults;
}
diff --git a/server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java b/server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java
index d690821d8f9..f06380774ee 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java
@@ -34,7 +34,10 @@ import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
import static java.lang.String.valueOf;
-import static org.sonar.process.ProcessProperties.CLUSTER_NODE_NAME;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_NAME;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS;
import static org.sonar.process.ProcessProperties.SEARCH_MARVEL_HOSTS;
public class EsSettings {
@@ -53,8 +56,8 @@ public class EsSettings {
this.props = props;
this.fileSystem = fileSystem;
- this.clusterName = props.nonNullValue(ProcessProperties.CLUSTER_NAME);
- this.clusterEnabled = props.valueAsBoolean(ProcessProperties.CLUSTER_ENABLED);
+ this.clusterName = props.nonNullValue(CLUSTER_NAME);
+ this.clusterEnabled = props.valueAsBoolean(CLUSTER_ENABLED);
if (this.clusterEnabled) {
this.nodeName = props.value(CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString());
} else {
@@ -124,7 +127,7 @@ public class EsSettings {
minimumMasterNodes = props.valueAsInt(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, 2);
initialStateTimeOut = props.value(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "120s");
- String hosts = props.value(ProcessProperties.CLUSTER_SEARCH_HOSTS, "");
+ String hosts = props.value(CLUSTER_SEARCH_HOSTS, "");
LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts);
builder.put("discovery.zen.ping.unicast.hosts", hosts);
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java
index 643e80c859f..c11fc2589a0 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java
@@ -28,12 +28,15 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.cluster.ClusterProperties;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS;
public class EsSettingsTest {
@@ -55,7 +58,7 @@ public class EsSettingsTest {
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath());
- props.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ props.set(CLUSTER_NAME, "sonarqube");
EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
@@ -91,9 +94,9 @@ public class EsSettingsTest {
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath());
- props.set(ProcessProperties.CLUSTER_NAME, "sonarqube-1");
- props.set(ProcessProperties.CLUSTER_ENABLED, "true");
- props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1");
+ props.set(ClusterProperties.CLUSTER_NAME, "sonarqube-1");
+ props.set(ClusterProperties.CLUSTER_ENABLED, "true");
+ props.set(ClusterProperties.CLUSTER_NODE_NAME, "node-1");
EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
@@ -106,8 +109,8 @@ public class EsSettingsTest {
public void test_node_name_default_for_cluster_mode() throws Exception {
File homeDir = temp.newFolder();
Props props = new Props(new Properties());
- props.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
- props.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ props.set(ClusterProperties.CLUSTER_NAME, "sonarqube");
+ props.set(ClusterProperties.CLUSTER_ENABLED, "true");
props.set(ProcessProperties.SEARCH_PORT, "1234");
props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
@@ -122,8 +125,8 @@ public class EsSettingsTest {
public void test_node_name_default_for_standalone_mode() throws Exception {
File homeDir = temp.newFolder();
Props props = new Props(new Properties());
- props.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
- props.set(ProcessProperties.CLUSTER_ENABLED, "false");
+ props.set(ClusterProperties.CLUSTER_NAME, "sonarqube");
+ props.set(ClusterProperties.CLUSTER_ENABLED, "false");
props.set(ProcessProperties.SEARCH_PORT, "1234");
props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
@@ -153,7 +156,7 @@ public class EsSettingsTest {
@Test
public void set_discovery_settings_if_cluster_is_enabled() throws Exception {
Props props = minProps(CLUSTER_ENABLED);
- props.set(ProcessProperties.CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080");
+ props.set(CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080");
Map<String, String> settings = new EsSettings(props, new EsFileSystem(props)).build();
assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080");
@@ -246,7 +249,7 @@ public class EsSettingsTest {
Props props = new Props(new Properties());
ProcessProperties.completeDefaults(props);
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
- props.set(ProcessProperties.CLUSTER_ENABLED, Boolean.toString(cluster));
+ props.set(ClusterProperties.CLUSTER_ENABLED, Boolean.toString(cluster));
return props;
}
}
diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml
index 19037022f46..95dae9f72e7 100644
--- a/server/sonar-server/pom.xml
+++ b/server/sonar-server/pom.xml
@@ -168,6 +168,10 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast-client</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java
index 009d0c4c4ff..138ea698fcd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java
@@ -37,6 +37,10 @@ import org.sonar.api.utils.log.Loggers;
import org.sonar.process.NodeType;
import org.sonar.process.ProcessProperties;
+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;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS;
import static org.sonar.process.NodeType.SEARCH;
@ComputeEngineSide
@@ -52,14 +56,14 @@ public class EsClientProvider extends ProviderAdapter {
org.elasticsearch.common.settings.Settings.Builder esSettings = org.elasticsearch.common.settings.Settings.builder();
// mandatory property defined by bootstrap process
- esSettings.put("cluster.name", config.get(ProcessProperties.CLUSTER_NAME).get());
+ esSettings.put("cluster.name", config.get(CLUSTER_NAME).get());
- boolean clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
- boolean searchNode = !clusterEnabled || SEARCH.equals(NodeType.parse(config.get(ProcessProperties.CLUSTER_NODE_TYPE).orElse(null)));
+ boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false);
+ boolean searchNode = !clusterEnabled || SEARCH.equals(NodeType.parse(config.get(CLUSTER_NODE_TYPE).orElse(null)));
final TransportClient nativeClient = new PreBuiltTransportClient(esSettings.build());
if (clusterEnabled && !searchNode) {
esSettings.put("client.transport.sniff", true);
- Arrays.stream(config.getStringArray(ProcessProperties.CLUSTER_SEARCH_HOSTS))
+ Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS))
.map(HostAndPort::fromString)
.forEach(h -> addHostToClient(h, nativeClient));
LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
index c6ffc745a0f..9a98d51369e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
@@ -39,6 +39,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.lang.String.valueOf;
import static java.util.Objects.requireNonNull;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
import static org.sonar.server.es.DefaultIndexSettings.FIELDDATA_ENABLED;
import static org.sonar.server.es.DefaultIndexSettings.FIELD_FIELDDATA;
@@ -68,7 +69,7 @@ public class NewIndex {
settings.put("index.refresh_interval", refreshInterval(settingsConfiguration));
Configuration config = settingsConfiguration.getConfiguration();
- boolean clusterMode = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+ boolean clusterMode = config.getBoolean(CLUSTER_ENABLED).orElse(false);
int shards = config.getInt(format("sonar.search.%s.shards", indexName))
.orElse(settingsConfiguration.getDefaultNbOfShards());
int replicas = clusterMode ? config.getInt(ProcessProperties.SEARCH_REPLICAS).orElse(1) : 0;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java
index a9940038bc8..1f38ad853ea 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/WebServerImpl.java
@@ -21,9 +21,9 @@ package org.sonar.server.platform;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.ProcessProperties;
-import static org.sonar.process.ProcessProperties.CLUSTER_WEB_LEADER;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_WEB_LEADER;
public class WebServerImpl implements WebServer {
@@ -31,7 +31,7 @@ public class WebServerImpl implements WebServer {
private final boolean startupLeader;
public WebServerImpl(Configuration config) {
- this.clusterEnabled = config.getBoolean(ProcessProperties.CLUSTER_ENABLED).orElse(false);
+ this.clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false);
if (this.clusterEnabled) {
this.startupLeader = config.getBoolean(CLUSTER_WEB_LEADER).orElse(false);
Loggers.get(WebServerImpl.class).info("Cluster enabled (startup {})", startupLeader ? "leader" : "follower");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
index e4a74d5ef40..662049a47ec 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
@@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.process.NetworkUtils;
+import org.sonar.NetworkUtils;
import org.sonar.process.Props;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java
index c6ea52d7bcb..413b058ece8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsClientProviderTest.java
@@ -34,6 +34,10 @@ import org.sonar.process.ProcessProperties;
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_NAME;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS;
public class EsClientProviderTest {
@@ -50,14 +54,14 @@ public class EsClientProviderTest {
@Before
public void setUp() throws Exception {
// mandatory property
- settings.setProperty(ProcessProperties.CLUSTER_NAME, "the_cluster_name");
+ settings.setProperty(CLUSTER_NAME, "the_cluster_name");
localhost = InetAddress.getLocalHost().getHostAddress();
}
@Test
public void connection_to_local_es_when_cluster_mode_is_disabled() throws Exception {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, false);
+ settings.setProperty(CLUSTER_ENABLED, false);
settings.setProperty(ProcessProperties.SEARCH_HOST, localhost);
settings.setProperty(ProcessProperties.SEARCH_PORT, 8080);
@@ -75,9 +79,9 @@ public class EsClientProviderTest {
@Test
public void connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled() throws Exception {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
- settings.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "application");
- settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s:8080,%s:8081", localhost, localhost));
+ settings.setProperty(CLUSTER_ENABLED, true);
+ settings.setProperty(CLUSTER_NODE_TYPE, "application");
+ settings.setProperty(CLUSTER_SEARCH_HOSTS, format("%s:8080,%s:8081", localhost, localhost));
EsClient client = underTest.provide(settings.asConfig());
TransportClient transportClient = (TransportClient) client.nativeClient();
@@ -96,9 +100,9 @@ public class EsClientProviderTest {
@Test
public void es_client_provider_must_throw_ISE_when_incorrect_port_is_used_when_search_disabled() throws Exception {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
- settings.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "application");
- settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s:100000,%s:8081", localhost, localhost));
+ settings.setProperty(CLUSTER_ENABLED, true);
+ settings.setProperty(CLUSTER_NODE_TYPE, "application");
+ settings.setProperty(CLUSTER_SEARCH_HOSTS, format("%s:100000,%s:8081", localhost, localhost));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(format("Port number out of range: %s:100000", localhost));
@@ -108,8 +112,8 @@ public class EsClientProviderTest {
@Test
public void es_client_provider_must_throw_ISE_when_incorrect_port_is_used() throws Exception {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
- settings.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "search");
+ settings.setProperty(CLUSTER_ENABLED, true);
+ settings.setProperty(CLUSTER_NODE_TYPE, "search");
settings.setProperty(ProcessProperties.SEARCH_HOST, "localhost");
settings.setProperty(ProcessProperties.SEARCH_PORT, "100000");
@@ -121,9 +125,9 @@ public class EsClientProviderTest {
@Test
public void es_client_provider_must_add_default_port_when_not_specified() throws Exception {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
- settings.setProperty(ProcessProperties.CLUSTER_NODE_TYPE, "application");
- settings.setProperty(ProcessProperties.CLUSTER_SEARCH_HOSTS, format("%s,%s:8081", localhost, localhost));
+ settings.setProperty(CLUSTER_ENABLED, true);
+ settings.setProperty(CLUSTER_NODE_TYPE, "application");
+ settings.setProperty(CLUSTER_SEARCH_HOSTS, format("%s,%s:8081", localhost, localhost));
EsClient client = underTest.provide(settings.asConfig());
TransportClient transportClient = (TransportClient) client.nativeClient();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
index 794d13c28b7..9d2d020fa64 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
@@ -32,7 +32,7 @@ import org.sonar.process.ProcessProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;
import static org.junit.Assert.fail;
-import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
import static org.sonar.server.es.NewIndex.SettingsConfiguration.newBuilder;
public class NewIndexTest {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
index f9190c373e8..65b96b35b88 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/EmbeddedDatabaseTest.java
@@ -34,7 +34,7 @@ import org.junit.rules.Timeout;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.process.NetworkUtils;
+import org.sonar.NetworkUtils;
import static junit.framework.Assert.fail;
import static org.mockito.Mockito.mock;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
index 1a6b4570388..6d4f706e963 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
@@ -26,13 +26,13 @@ import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
-import org.sonar.process.ProcessProperties;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
+import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED;
import static org.sonar.server.es.DefaultIndexSettingsElement.ENGLISH_HTML_ANALYZER;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_HTML_DESCRIPTION;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_RULE_KEY;
@@ -64,7 +64,7 @@ public class RuleIndexDefinitionTest {
@Test
public void enable_replica_if_clustering_is_enabled() {
- settings.setProperty(ProcessProperties.CLUSTER_ENABLED, true);
+ settings.setProperty(CLUSTER_ENABLED, true);
IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext();
underTest.define(context);
@@ -78,8 +78,7 @@ public class RuleIndexDefinitionTest {
List<AnalyzeResponse.AnalyzeToken> tokens = analyzeIndexedTokens(longText);
assertThat(tokens).extracting(AnalyzeResponse.AnalyzeToken::getTerm).containsOnly(
- "quick", "brown", "fox", "jump", "over", "lazi", "dog"
- );
+ "quick", "brown", "fox", "jump", "over", "lazi", "dog");
// the following method fails if PUT fails
tester.putDocuments(INDEX_TYPE_RULE, new RuleDoc(ImmutableMap.of(