diff options
Diffstat (limited to 'server/sonar-search/src/main')
4 files changed, 0 insertions, 295 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java deleted file mode 100644 index 4df00c79311..00000000000 --- a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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.search; - -import java.io.File; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.process.ProcessProperties; -import org.sonar.process.Props; - -public class EsSettings implements EsSettingsMBean { - - private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class); - public static final String PROP_MARVEL_HOSTS = "sonar.search.marvelHosts"; - public static final String CLUSTER_SEARCH_NODE_NAME = "sonar.cluster.search.nodeName"; - public static final String STANDALONE_NODE_NAME = "sonarqube"; - - private final Props props; - - private final boolean clusterEnabled; - private final String clusterName; - private final String nodeName; - - EsSettings(Props props) { - this.props = props; - - 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()); - } else { - this.nodeName = STANDALONE_NODE_NAME; - } - } - - @Override - public int getHttpPort() { - return props.valueAsInt(ProcessProperties.SEARCH_HTTP_PORT, -1); - } - - @Override - public String getClusterName() { - return clusterName; - } - - @Override - public String getNodeName() { - return nodeName; - } - - Map<String, String> build() { - Map<String, String> builder = new HashMap<>(); - configureFileSystem(builder); - configureNetwork(builder); - configureCluster(builder); - configureMarvel(builder); - return builder; - } - - private void configureFileSystem(Map<String, String> builder) { - File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); - File dataDir; - File logDir; - - // data dir - String dataPath = props.value(ProcessProperties.PATH_DATA); - if (StringUtils.isNotEmpty(dataPath)) { - dataDir = new File(dataPath, "es"); - } else { - dataDir = new File(homeDir, "data/es"); - } - builder.put("path.data", dataDir.getAbsolutePath()); - - String tempPath = props.value(ProcessProperties.PATH_TEMP); - builder.put("path.home", new File(tempPath, "es").getAbsolutePath()); - - // log dir - String logPath = props.value(ProcessProperties.PATH_LOGS); - if (StringUtils.isNotEmpty(logPath)) { - logDir = new File(logPath); - } else { - logDir = new File(homeDir, "log"); - } - builder.put("path.logs", logDir.getAbsolutePath()); - } - - private void configureNetwork(Map<String, String> builder) { - InetAddress host = readHost(); - int port = Integer.parseInt(props.nonNullValue(ProcessProperties.SEARCH_PORT)); - LOGGER.info("Elasticsearch listening on {}:{}", host, port); - - builder.put("transport.tcp.port", String.valueOf(port)); - builder.put("transport.host", String.valueOf(host.getHostAddress())); - builder.put("network.host", String.valueOf(host.getHostAddress())); - - // Elasticsearch sets the default value of TCP reuse address to true only on non-MSWindows machines, but why ? - builder.put("network.tcp.reuse_address", String.valueOf(true)); - - int httpPort = getHttpPort(); - if (httpPort < 0) { - // standard configuration - builder.put("http.enabled", String.valueOf(false)); - } else { - LOGGER.warn("Elasticsearch HTTP connector is enabled on port {}. MUST NOT BE USED FOR PRODUCTION", httpPort); - // see https://github.com/lmenezes/elasticsearch-kopf/issues/195 - builder.put("http.cors.enabled", String.valueOf(true)); - builder.put("http.cors.allow-origin", "*"); - builder.put("http.enabled", String.valueOf(true)); - builder.put("http.host", host.getHostAddress()); - builder.put("http.port", String.valueOf(httpPort)); - } - } - - private InetAddress readHost() { - String hostProperty = props.nonNullValue(ProcessProperties.SEARCH_HOST); - try { - return InetAddress.getByName(hostProperty); - } catch (UnknownHostException e) { - throw new IllegalStateException("Can not resolve host [" + hostProperty + "]. Please check network settings and property " + ProcessProperties.SEARCH_HOST, e); - } - } - - private void configureCluster(Map<String, String> builder) { - // Default value in a standalone mode, not overridable - int minimumMasterNodes = 1; - String initialStateTimeOut = "30s"; - - if (clusterEnabled) { - 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, ""); - LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts); - builder.put("discovery.zen.ping.unicast.hosts", hosts); - } - - builder.put("discovery.zen.minimum_master_nodes", String.valueOf(minimumMasterNodes)); - builder.put("discovery.initial_state_timeout", initialStateTimeOut); - builder.put("cluster.name", getClusterName()); - builder.put("cluster.routing.allocation.awareness.attributes", "rack_id"); - builder.put("node.attr.rack_id", nodeName); - builder.put("node.name", nodeName); - builder.put("node.data", String.valueOf(true)); - builder.put("node.master", String.valueOf(true)); - } - - private void configureMarvel(Map<String, String> builder) { - Set<String> marvels = new TreeSet<>(); - marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ","))); - - // If we're collecting indexing data send them to the Marvel host(s) - if (!marvels.isEmpty()) { - String hosts = StringUtils.join(marvels, ","); - LOGGER.info("Elasticsearch Marvel is enabled for %s", hosts); - builder.put("marvel.agent.exporter.es.hosts", hosts); - } - } -} diff --git a/server/sonar-search/src/main/java/org/sonar/search/EsSettingsMBean.java b/server/sonar-search/src/main/java/org/sonar/search/EsSettingsMBean.java deleted file mode 100644 index 58774b246fa..00000000000 --- a/server/sonar-search/src/main/java/org/sonar/search/EsSettingsMBean.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.search; - -/** - * MBean registered in the Elasticsearch process - */ -public interface EsSettingsMBean { - - String OBJECT_NAME = "SonarQube:name=ElasticsearchSettings"; - - /** - * @return the enabled HTTP port, -1 if disabled - */ - int getHttpPort(); - - String getClusterName(); - - String getNodeName(); - -} diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java b/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java deleted file mode 100644 index adeab47a2d2..00000000000 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.search; - -import ch.qos.logback.classic.LoggerContext; -import org.sonar.process.logging.LogLevelConfig; -import org.sonar.process.logging.LogbackHelper; -import org.sonar.process.ProcessId; -import org.sonar.process.Props; -import org.sonar.process.logging.RootLoggerConfig; - -import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder; - -public class SearchLogging { - - private LogbackHelper helper = new LogbackHelper(); - - public LoggerContext configure(Props props) { - LoggerContext ctx = helper.getRootContext(); - ctx.reset(); - - RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build(); - - String logPattern = helper.buildLogPattern(config); - helper.configureGlobalFileLog(props, config, logPattern); - helper.configureForSubprocessGobbler(props, logPattern); - - helper.apply(LogLevelConfig.newBuilder(helper.getRootLoggerName()).rootLevelFor(ProcessId.ELASTICSEARCH).build(), props); - - return ctx; - } - -} diff --git a/server/sonar-search/src/main/java/org/sonar/search/package-info.java b/server/sonar-search/src/main/java/org/sonar/search/package-info.java deleted file mode 100644 index 0164ade85ba..00000000000 --- a/server/sonar-search/src/main/java/org/sonar/search/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.search; - -import javax.annotation.ParametersAreNonnullByDefault; |