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);
private EsJvmOptions esJvmOptions;
private EsYmlSettings esYmlSettings;
private Properties log4j2Properties;
- private String clusterName;
private String host;
private int httpPort;
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;
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));
}
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");
}
}
assertThat(ClusterSettings.getEnabledProcesses(settings)).containsOnly(ELASTICSEARCH);
}
+ @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"));
bulk.stop();
}
- private void addProjectDeletionToBulkIndexer(BulkIndexer bulkIndexer, String projectUuid) {
+ private static void addProjectDeletionToBulkIndexer(BulkIndexer bulkIndexer, String projectUuid) {
SearchRequest searchRequest = EsClient.prepareSearch(TYPE_COMPONENT.getMainType())
.source(new SearchSourceBuilder().query(QueryBuilders.termQuery(ComponentIndexDefinition.FIELD_PROJECT_UUID, projectUuid)))
.routing(AuthorizationDoc.idOf(projectUuid));
bulk.stop();
}
- private IndexRequest newIndexRequest(IssueDoc issue) {
+ private static IndexRequest newIndexRequest(IssueDoc issue) {
return new IndexRequest(TYPE_ISSUE.getMainType().getIndex().getName(), TYPE_ISSUE.getMainType().getType())
.id(issue.getId())
.routing(issue.getRouting().orElseThrow(() -> new IllegalStateException("IssueDoc should define a routing")))
.source(issue.getFields());
}
- private void addProjectDeletionToBulkIndexer(BulkIndexer bulkIndexer, String projectUuid) {
+ private static void addProjectDeletionToBulkIndexer(BulkIndexer bulkIndexer, String projectUuid) {
SearchRequest search = EsClient.prepareSearch(TYPE_ISSUE.getMainType())
.routing(AuthorizationDoc.idOf(projectUuid))
.source(new SearchSourceBuilder().query(boolQuery().must(termQuery(FIELD_ISSUE_PROJECT_UUID, projectUuid))));
}
}
- private Optional<ZoneId> parseTimeZone(@Nullable String timeZone) {
+ private static Optional<ZoneId> parseTimeZone(@Nullable String timeZone) {
if (timeZone == null) {
return Optional.empty();
}