aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-30 10:09:48 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-08-03 17:57:17 +0200
commit5291ade14f2a05d923dd0af2421247b804c2b418 (patch)
tree6cc29b5cbf568a3d45136bb44bb9beb38833833e /sonar-application
parent80ada8c264e73426330c79e40e44f36ded7dcc19 (diff)
downloadsonarqube-5291ade14f2a05d923dd0af2421247b804c2b418.tar.gz
sonarqube-5291ade14f2a05d923dd0af2421247b804c2b418.zip
SONAR-7908 ability to disable Elasticsearch process
Diffstat (limited to 'sonar-application')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/App.java23
-rw-r--r--sonar-application/src/test/java/org/sonar/application/AppTest.java42
2 files changed, 52 insertions, 13 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java
index b8f08d18bf3..8109f0ed0ac 100644
--- a/sonar-application/src/main/java/org/sonar/application/App.java
+++ b/sonar-application/src/main/java/org/sonar/application/App.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang.StringUtils;
import org.sonar.process.ProcessId;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
@@ -57,22 +56,26 @@ public class App implements Stoppable {
private static List<JavaCommand> createCommands(Props props) {
File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME);
List<JavaCommand> commands = new ArrayList<>(3);
- commands.add(createESCommand(props, homeDir));
+ if (isProcessEnabled(props, ProcessProperties.CLUSTER_SEARCH_DISABLED)) {
+ commands.add(createESCommand(props, homeDir));
+ }
- // do not yet start WebServer nor CE on elasticsearch slaves
- if (StringUtils.isBlank(props.value(ProcessProperties.CLUSTER_MASTER_HOST))) {
- if (!props.valueAsBoolean(ProcessProperties.CLUSTER_WEB_DISABLED)) {
- commands.add(createWebServerCommand(props, homeDir));
- }
+ if (isProcessEnabled(props, ProcessProperties.CLUSTER_WEB_DISABLED)) {
+ commands.add(createWebServerCommand(props, homeDir));
+ }
- if (!props.valueAsBoolean(ProcessProperties.CLUSTER_CE_DISABLED)) {
- commands.add(createCeServerCommand(props, homeDir));
- }
+ if (isProcessEnabled(props, ProcessProperties.CLUSTER_CE_DISABLED)) {
+ commands.add(createCeServerCommand(props, homeDir));
}
return commands;
}
+ private static boolean isProcessEnabled(Props props, String disabledPropertyKey) {
+ return !props.valueAsBoolean(ProcessProperties.CLUSTER_ENABLED) ||
+ !props.valueAsBoolean(disabledPropertyKey);
+ }
+
private static JavaCommand createESCommand(Props props, File homeDir) {
JavaCommand elasticsearch = new JavaCommand(ProcessId.ELASTICSEARCH);
elasticsearch
diff --git a/sonar-application/src/test/java/org/sonar/application/AppTest.java b/sonar-application/src/test/java/org/sonar/application/AppTest.java
index 5a31d7d8e35..ac2bdf272d3 100644
--- a/sonar-application/src/test/java/org/sonar/application/AppTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/AppTest.java
@@ -53,7 +53,7 @@ public class AppTest {
}
@Test
- public void start_all_processes_by_default() throws Exception {
+ public void start_all_processes_if_cluster_mode_is_disabled() throws Exception {
Monitor monitor = mock(Monitor.class);
App app = new App(monitor);
Props props = initDefaultProps();
@@ -63,14 +63,50 @@ public class AppTest {
verify(monitor).start(argument.capture());
assertThat(argument.getValue()).extracting("processId").containsExactly(ProcessId.ELASTICSEARCH, ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE);
+
+ app.stopAsync();
+ }
+
+ @Test
+ public void start_only_web_server_node_in_cluster() throws Exception {
+ Monitor monitor = mock(Monitor.class);
+ App app = new App(monitor);
+ Props props = initDefaultProps();
+ props.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ props.set(ProcessProperties.CLUSTER_CE_DISABLED, "true");
+ props.set(ProcessProperties.CLUSTER_SEARCH_DISABLED, "true");
+ app.start(props);
+
+ ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor();
+ verify(monitor).start(argument.capture());
+
+ assertThat(argument.getValue()).extracting("processId").containsOnly(ProcessId.WEB_SERVER);
+ }
+
+ @Test
+ public void start_only_compute_engine_node_in_cluster() throws Exception {
+ Monitor monitor = mock(Monitor.class);
+ App app = new App(monitor);
+ Props props = initDefaultProps();
+ props.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ props.set(ProcessProperties.CLUSTER_WEB_DISABLED, "true");
+ props.set(ProcessProperties.CLUSTER_SEARCH_DISABLED, "true");
+ app.start(props);
+
+ ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor();
+ verify(monitor).start(argument.capture());
+
+ assertThat(argument.getValue()).extracting("processId").containsOnly(ProcessId.COMPUTE_ENGINE);
}
@Test
- public void do_not_start_WebServer_nor_CE_if_elasticsearch_slave() throws Exception {
+ public void start_only_elasticsearch_node_in_cluster() throws Exception {
Monitor monitor = mock(Monitor.class);
App app = new App(monitor);
Props props = initDefaultProps();
- props.set("sonar.cluster.masterHost", "1.2.3.4");
+ props.set(ProcessProperties.CLUSTER_ENABLED, "true");
+ props.set(ProcessProperties.CLUSTER_WEB_DISABLED, "true");
+ props.set(ProcessProperties.CLUSTER_CE_DISABLED, "true");
app.start(props);
ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor();