aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main/src
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-12-04 12:10:10 +0100
committersonartech <sonartech@sonarsource.com>2020-12-09 20:07:21 +0000
commitd4a6de2b1520c99bba1d4d97c70a904498baf43b (patch)
treed4ba1d67ebcc27a548ba0e8b5c7ba99f5e29ec46 /server/sonar-main/src
parente2ec80f28723ad04d3be47da4e76cc10716a3526 (diff)
downloadsonarqube-d4a6de2b1520c99bba1d4d97c70a904498baf43b.tar.gz
sonarqube-d4a6de2b1520c99bba1d4d97c70a904498baf43b.zip
Fix various code smells
Diffstat (limited to 'server/sonar-main/src')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java32
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java1
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java10
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java13
4 files changed, 39 insertions, 17 deletions
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 504f6885483..cfa65c7824e 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
@@ -83,26 +83,34 @@ public class ClusterSettings implements Consumer<Props> {
NodeType nodeType = toNodeType(props);
switch (nodeType) {
case APPLICATION:
- ensureNotH2(props);
- requireValue(props, AUTH_JWT_SECRET);
- Set<AddressAndPort> hzNodes = parseHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS));
- ensureNotLoopbackAddresses(CLUSTER_HZ_HOSTS, hzNodes);
- checkClusterNodeHost(props);
- checkClusterSearchHosts(props);
+ checkForApplicationNode(props);
break;
case SEARCH:
- ensureNoSearchNodeForbiddenSettings(props);
- AddressAndPort searchHost = parseAndCheckHost(CLUSTER_NODE_SEARCH_HOST, requireValue(props, CLUSTER_NODE_SEARCH_HOST));
- ensureLocalButNotLoopbackAddress(CLUSTER_NODE_SEARCH_HOST, searchHost);
- AddressAndPort esHost = parseAndCheckHost(CLUSTER_NODE_ES_HOST, requireValue(props, CLUSTER_NODE_ES_HOST));
- ensureLocalButNotLoopbackAddress(CLUSTER_NODE_ES_HOST, esHost);
- checkClusterEsHosts(props);
+ checkForSearchNode(props);
break;
default:
throw new UnsupportedOperationException("Unknown value: " + nodeType);
}
}
+ private void checkForApplicationNode(Props props) {
+ ensureNotH2(props);
+ requireValue(props, AUTH_JWT_SECRET);
+ Set<AddressAndPort> hzNodes = parseHosts(CLUSTER_HZ_HOSTS, requireValue(props, CLUSTER_HZ_HOSTS));
+ ensureNotLoopbackAddresses(CLUSTER_HZ_HOSTS, hzNodes);
+ checkClusterNodeHost(props);
+ checkClusterSearchHosts(props);
+ }
+
+ private void checkForSearchNode(Props props) {
+ ensureNoSearchNodeForbiddenSettings(props);
+ AddressAndPort searchHost = parseAndCheckHost(CLUSTER_NODE_SEARCH_HOST, requireValue(props, CLUSTER_NODE_SEARCH_HOST));
+ ensureLocalButNotLoopbackAddress(CLUSTER_NODE_SEARCH_HOST, searchHost);
+ AddressAndPort esHost = parseAndCheckHost(CLUSTER_NODE_ES_HOST, requireValue(props, CLUSTER_NODE_ES_HOST));
+ ensureLocalButNotLoopbackAddress(CLUSTER_NODE_ES_HOST, esHost);
+ checkClusterEsHosts(props);
+ }
+
private void checkClusterNodeHost(Props props) {
AddressAndPort clusterNodeHost = parseAndCheckHost(CLUSTER_NODE_HOST, requireValue(props, CLUSTER_NODE_HOST));
ensureLocalButNotLoopbackAddress(CLUSTER_NODE_HOST, clusterNodeHost);
diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java
index 5657f094adb..c36d2af8b3b 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java
@@ -50,7 +50,6 @@ public class EsInstallation {
private EsJvmOptions esJvmOptions;
private EsYmlSettings esYmlSettings;
private Properties log4j2Properties;
- private String clusterName;
private String host;
private int httpPort;
diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java
index dc3b606d1c4..cefea6fe707 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java
@@ -58,6 +58,8 @@ public class EsSettings {
private static final String SECCOMP_PROPERTY = "bootstrap.system_call_filter";
private static final String ALLOW_MMAP = "node.store.allow_mmap";
+ private static final String JAVA_ADDITIONAL_OPS_PROPERTY = "sonar.search.javaAdditionalOpts";
+
private final Props props;
private final EsInstallation fileSystem;
@@ -114,7 +116,7 @@ public class EsSettings {
int transportPort = Integer.parseInt(props.nonNullValue(ES_PORT.getKey()));
- //we have no use of transport port in non-DCE editions
+ // we have no use of transport port in non-DCE editions
builder.put(ES_TRANSPORT_HOST_KEY, this.loopbackAddress.getHostAddress());
builder.put(ES_TRANSPORT_PORT_KEY, valueOf(transportPort));
}
@@ -185,15 +187,15 @@ public class EsSettings {
private void configureOthers(Map<String, String> builder) {
builder.put("action.auto_create_index", String.valueOf(false));
- if (props.value("sonar.search.javaAdditionalOpts", "").contains("-D" + SECCOMP_PROPERTY + "=false")) {
+ if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-D" + SECCOMP_PROPERTY + "=false")) {
builder.put(SECCOMP_PROPERTY, "false");
}
- if (props.value("sonar.search.javaAdditionalOpts", "").contains("-Dnode.store.allow_mmapfs=false")) {
+ if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-Dnode.store.allow_mmapfs=false")) {
throw new MessageException("Property 'node.store.allow_mmapfs' is no longer supported. Use 'node.store.allow_mmap' instead.");
}
- if (props.value("sonar.search.javaAdditionalOpts", "").contains("-D" + ALLOW_MMAP + "=false")) {
+ if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-D" + ALLOW_MMAP + "=false")) {
builder.put(ALLOW_MMAP, "false");
}
}
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 fa8fae1a190..f91f674a4b9 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
@@ -97,6 +97,19 @@ public class ClusterSettingsTest {
}
@Test
+ @UseDataProvider("validIPv4andIPv6Addresses")
+ public void valid_configuration_of_app_node_does_not_throw_exception(String host) {
+ mockValidHost(host);
+ mockLocalNonLoopback(host);
+ TestAppSettings settings = newSettingsForAppNode(host);
+ ClusterSettings clusterSettings = new ClusterSettings(network);
+ Props props = settings.getProps();
+
+ assertThatCode(() -> clusterSettings.accept(props))
+ .doesNotThrowAnyException();
+ }
+
+ @Test
public void accept_throws_MessageException_if_no_node_type_is_configured() {
TestAppSettings settings = new TestAppSettings(of(CLUSTER_ENABLED.getKey(), "true"));
ClusterSettings clusterSettings = new ClusterSettings(network);