aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-08-22 14:56:53 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-05 14:24:13 +0200
commit31984d0209d0383adc83de87918cfb6b49dba7cc (patch)
treeaae877cd025e242997196453ab5acc8f18490523 /server/sonar-process
parent2c35d9b2f0597289e526c615c720431314b25f43 (diff)
downloadsonarqube-31984d0209d0383adc83de87918cfb6b49dba7cc.tar.gz
sonarqube-31984d0209d0383adc83de87918cfb6b49dba7cc.zip
SONAR-6966 let the user define node names in sonar.cluster.node.name for Elasticsearch
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java2
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/es/EsSettings.java8
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java33
3 files changed, 38 insertions, 5 deletions
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 a4bd2f15e35..fa35616bc06 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
@@ -35,6 +35,7 @@ public class ProcessProperties {
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";
@@ -67,6 +68,7 @@ public class ProcessProperties {
public static final String SEARCH_REPLICAS = "sonar.search.replicas";
public static final String SEARCH_MINIMUM_MASTER_NODES = "sonar.search.minimumMasterNodes";
public static final String SEARCH_INITIAL_STATE_TIMEOUT = "sonar.search.initialStateTimeout";
+ public static final String SEARCH_MARVEL_HOSTS = "sonar.search.marvelHosts";
public static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
public static final String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
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 4761bc30638..d690821d8f9 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,12 +34,12 @@ 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.process.ProcessProperties.SEARCH_MARVEL_HOSTS;
public class EsSettings {
private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class);
- private static final String PROP_MARVEL_HOSTS = "sonar.search.marvelHosts";
- private static final String CLUSTER_SEARCH_NODE_NAME = "sonar.cluster.search.nodeName";
private static final String STANDALONE_NODE_NAME = "sonarqube";
private final Props props;
@@ -56,7 +56,7 @@ public class EsSettings {
this.clusterName = props.nonNullValue(ProcessProperties.CLUSTER_NAME);
this.clusterEnabled = props.valueAsBoolean(ProcessProperties.CLUSTER_ENABLED);
if (this.clusterEnabled) {
- this.nodeName = props.value(CLUSTER_SEARCH_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString());
+ this.nodeName = props.value(CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString());
} else {
this.nodeName = STANDALONE_NODE_NAME;
}
@@ -141,7 +141,7 @@ public class EsSettings {
private void configureMarvel(Map<String, String> builder) {
Set<String> marvels = new TreeSet<>();
- marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ",")));
+ marvels.addAll(Arrays.asList(StringUtils.split(props.value(SEARCH_MARVEL_HOSTS, ""), ",")));
// If we're collecting indexing data send them to the Marvel host(s)
if (!marvels.isEmpty()) {
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 673a849ae5c..edad4dadc24 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
@@ -55,6 +55,7 @@ public class EsSettingsTest {
props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
props.set(ProcessProperties.CLUSTER_NAME, "sonarqube");
+ props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1");
EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
@@ -64,7 +65,7 @@ public class EsSettingsTest {
// no cluster, but cluster and node names are set though
assertThat(generated.get("cluster.name")).isEqualTo("sonarqube");
- assertThat(generated.get("node.name")).isEqualTo("sonarqube");
+ assertThat(generated.get("node.name")).isEqualTo("sonar-1");
assertThat(generated.get("path.data")).isNotNull();
assertThat(generated.get("path.logs")).isNotNull();
@@ -82,6 +83,36 @@ public class EsSettingsTest {
}
@Test
+ 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(ProcessProperties.SEARCH_PORT, "1234");
+ props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
+ props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
+ EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
+ Map<String, String> generated = esSettings.build();
+ assertThat(generated.get("node.name")).startsWith("sonarqube-");
+ }
+
+ @Test
+ 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(ProcessProperties.SEARCH_PORT, "1234");
+ props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1");
+ props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath());
+ EsSettings esSettings = new EsSettings(props, new EsFileSystem(props));
+ Map<String, String> generated = esSettings.build();
+ assertThat(generated.get("node.name")).isEqualTo("sonarqube");
+ }
+
+ @Test
public void path_properties_are_values_from_EsFileSystem_argument() throws IOException {
EsFileSystem mockedEsFileSystem = mock(EsFileSystem.class);
when(mockedEsFileSystem.getHomeDirectory()).thenReturn(new File("/foo/home"));