--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.process;
+
+/**
+ * Constants shared by search, web server and monitor processes.
+ * It represents more or less all the properties commented in conf/sonar.properties
+ */
+public interface ProcessConstants {
+
+ String CLUSTER_ACTIVATION = "sonar.cluster.activation";
+ String CLUSTER_MASTER_HOSTS = "sonar.cluster.master";
+ String CLUSTER_NAME = "sonar.cluster.name";
+ String CLUSTER_NODE_NAME = "sonar.node.name";
+
+ String JDBC_URL = "sonar.jdbc.url";
+ String JDBC_LOGIN = "sonar.jdbc.username";
+ String JDBC_PASSWORD = "sonar.jdbc.password";
+ String JDBC_DRIVER_PATH = "sonar.jdbc.driverPath";
+
+ String PATH_DATA = "sonar.path.data";
+ String PATH_HOME = "sonar.path.home";
+ String PATH_LOGS = "sonar.path.logs";
+ String PATH_TEMP = "sonar.path.temp";
+ String PATH_WEB = "sonar.path.web";
+
+ String SEARCH_PORT = "sonar.search.port";
+ String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
+ String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
+ String SEARCH_TYPE = "sonar.search.type";
+
+ String WEB_JAVA_OPTS = "sonar.web.javaOpts";
+ String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
+
+ /**
+ * Used by Orchestrator to ask for shutdown of monitor process
+ */
+ String ENABLE_STOP_COMMAND = "sonar.enableStopCommand";
+
+}
monitored = mp;
try {
- LoggerFactory.getLogger(getClass()).warn("Starting " + getKey());
+ LoggerFactory.getLogger(getClass()).info("Starting " + getKey());
Runtime.getRuntime().addShutdownHook(shutdownHook);
stopWatcher.start();
public class ProcessLogging {
- private static final String PATH_LOGS_PROPERTY = "sonar.path.logs";
-
public void configure(Props props, String logbackXmlResource) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
- context.putProperty(PATH_LOGS_PROPERTY, props.nonNullValue(PATH_LOGS_PROPERTY));
+ context.putProperty(ProcessConstants.PATH_LOGS, props.nonNullValue(ProcessConstants.PATH_LOGS));
doConfigure(configurator, logbackXmlResource);
} catch (JoranException ignored) {
// StatusPrinter will handle this
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 org.apache.commons.lang.StringUtils;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.elasticsearch.common.settings.Settings;
-import org.slf4j.LoggerFactory;
-import org.sonar.process.MessageException;
-import org.sonar.process.Props;
-import org.sonar.search.script.ListUpdate;
-
-import java.io.File;
-import java.net.InetAddress;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.TreeSet;
-
-class EsSettings {
-
- // set by monitor process, so value is never null
- public static final String PROP_TCP_PORT = "sonar.search.port";
-
- public static final String PROP_CLUSTER_ACTIVATION = "sonar.cluster.activation";
- public static final String PROP_NODE_NAME = "sonar.node.name";
- public static final String PROP_CLUSTER_NAME = "sonar.cluster.name";
- public static final String PROP_CLUSTER_MASTER = "sonar.cluster.master";
- public static final String PROP_HTTP_PORT = "sonar.search.httpPort";
- public static final String PROP_MARVEL = "sonar.search.marvel";
-
- public static final String SONAR_PATH_HOME = "sonar.path.home";
- public static final String SONAR_PATH_DATA = "sonar.path.data";
- public static final String SONAR_PATH_TEMP = "sonar.path.temp";
- public static final String SONAR_PATH_LOG = "sonar.path.log";
-
- private final Props props;
- private final Set<String> clusterNodes = new LinkedHashSet<String>();
- private final String clusterName;
- private final int tcpPort;
-
- EsSettings(Props props) {
- this.props = props;
- clusterNodes.addAll(Arrays.asList(StringUtils.split(props.value(PROP_CLUSTER_MASTER, ""), ",")));
-
- clusterName = props.value(PROP_CLUSTER_NAME);
- Integer port = props.valueAsInt(PROP_TCP_PORT);
- if (port == null) {
- throw new MessageException("Property is not set: " + PROP_TCP_PORT);
- }
- tcpPort = port.intValue();
- }
-
- boolean inCluster() {
- return !clusterNodes.isEmpty();
- }
-
- String clusterName() {
- return clusterName;
- }
-
- int tcpPort() {
- return tcpPort;
- }
-
- Settings build() {
- ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
- configureFileSystem(builder);
- configureStorage(builder);
- configurePlugins(builder);
- configureNetwork(builder);
- configureCluster(builder);
- configureMarvel(builder);
- System.out.println(builder.build());
- return builder.build();
- }
-
- private void configureFileSystem(ImmutableSettings.Builder builder) {
- File homeDir = props.nonNullValueAsFile(SONAR_PATH_HOME);
- File dataDir, workDir, logDir;
-
- // data dir
- String dataPath = props.value(SONAR_PATH_DATA);
- if (StringUtils.isNotEmpty(dataPath)) {
- dataDir = new File(dataPath, "es");
- } else {
- dataDir = new File(homeDir, "data/es");
- }
- builder.put("path.data", dataDir.getAbsolutePath());
-
- // working dir
- String workPath = props.value(SONAR_PATH_TEMP);
- if (StringUtils.isNotEmpty(workPath)) {
- workDir = new File(workPath);
- } else {
- workDir = new File(homeDir, "temp");
- }
- builder.put("path.work", workDir.getAbsolutePath());
- builder.put("path.plugins", workDir.getAbsolutePath());
-
- // log dir
- String logPath = props.value(SONAR_PATH_LOG);
- if (StringUtils.isNotEmpty(logPath)) {
- logDir = new File(logPath);
- } else {
- logDir = new File(homeDir, "log");
- }
- builder.put("path.logs", logDir.getAbsolutePath());
- }
-
- private void configurePlugins(ImmutableSettings.Builder builder) {
- builder
- .put("script.default_lang", "native")
- .put("script.native." + ListUpdate.NAME + ".type", ListUpdate.UpdateListScriptFactory.class.getName());
- }
-
- private void configureNetwork(ImmutableSettings.Builder builder) {
- // disable multicast
- builder.put("discovery.zen.ping.multicast.enabled", "false");
-
- builder.put("transport.tcp.port", tcpPort);
-
- Integer httpPort = props.valueAsInt(PROP_HTTP_PORT);
- if (httpPort ==null) {
- // standard configuration
- builder.put("http.enabled", false);
- } else {
- builder.put("http.enabled", true);
- builder.put("http.host", "127.0.0.1");
- builder.put("http.port", httpPort);
- }
- }
-
- private void configureStorage(ImmutableSettings.Builder builder) {
- builder
- .put("index.number_of_shards", "1")
- .put("index.refresh_interval", "30s")
- .put("index.store.type", "mmapfs")
- .put("indices.store.throttle.type", "none")
- .put("index.merge.scheduler.max_thread_count",
- Math.max(1, Math.min(3, Runtime.getRuntime().availableProcessors() / 2)));
- }
-
- private void configureCluster(ImmutableSettings.Builder builder) {
- if (!clusterNodes.isEmpty()) {
- LoggerFactory.getLogger(SearchServer.class).info("Joining ES cluster with master: {}", clusterNodes);
- builder.put("discovery.zen.ping.unicast.hosts", StringUtils.join(clusterNodes, ","));
- builder.put("node.master", false);
-
- // Enforce a N/2+1 number of masters in cluster
- builder.put("discovery.zen.minimum_master_nodes", 1);
- }
-
- // When SQ is ran as a cluster
- // see https://jira.codehaus.org/browse/SONAR-5687
- int replicationFactor = props.valueAsBoolean(PROP_CLUSTER_ACTIVATION, false) ? 1 : 0;
- builder.put("index.number_of_replicas", replicationFactor);
-
- // Set cluster coordinates
- builder.put("cluster.name", clusterName);
- builder.put("cluster.routing.allocation.awareness.attributes", "rack_id");
- builder.put("node.rack_id", props.value(PROP_NODE_NAME, "unknown"));
- if (props.contains(PROP_NODE_NAME)) {
- builder.put("node.name", props.value(PROP_NODE_NAME));
- } else {
- try {
- builder.put("node.name", InetAddress.getLocalHost().getHostName());
- } catch (Exception e) {
- LoggerFactory.getLogger(SearchServer.class).warn("Could not determine hostname", e);
- builder.put("node.name", "sq-" + System.currentTimeMillis());
- }
- }
- }
-
- private void configureMarvel(ImmutableSettings.Builder builder) {
- Set<String> marvels = new TreeSet<String>();
- marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL, ""), ",")));
-
- // Enable marvel's index creation
- builder.put("action.auto_create_index", ".marvel-*");
- // If we're collecting indexing data send them to the Marvel host(s)
- if (!marvels.isEmpty()) {
- builder.put("marvel.agent.exporter.es.hosts", StringUtils.join(marvels, ","));
- }
- }
-}
public class SearchServer implements Monitored {
- private final EsSettings settings;
+ private final SearchSettings settings;
private InternalNode node;
public SearchServer(Props props) {
- this.settings = new EsSettings(props);
+ this.settings = new SearchSettings(props);
new MinimumViableSystem().check();
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 org.apache.commons.lang.StringUtils;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.process.MessageException;
+import org.sonar.process.ProcessConstants;
+import org.sonar.process.Props;
+import org.sonar.search.script.ListUpdate;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+class SearchSettings {
+
+ private static Logger LOGGER = LoggerFactory.getLogger(SearchSettings.class);
+
+ public static final String PROP_HTTP_PORT = "sonar.search.httpPort";
+ public static final String PROP_MARVEL_HOSTS = "sonar.search.marvelHosts";
+
+ private final Props props;
+ private final Set<String> clusterNodes = new LinkedHashSet<String>();
+ private final String clusterName;
+ private final int tcpPort;
+
+ SearchSettings(Props props) {
+ this.props = props;
+ clusterNodes.addAll(Arrays.asList(StringUtils.split(props.value(ProcessConstants.CLUSTER_MASTER_HOSTS, ""), ",")));
+ clusterName = props.value(ProcessConstants.CLUSTER_NAME);
+ Integer port = props.valueAsInt(ProcessConstants.SEARCH_PORT);
+ if (port == null) {
+ throw new MessageException("Property is not set: " + ProcessConstants.SEARCH_PORT);
+ }
+ tcpPort = port.intValue();
+ }
+
+ boolean inCluster() {
+ return !clusterNodes.isEmpty();
+ }
+
+ String clusterName() {
+ return clusterName;
+ }
+
+ int tcpPort() {
+ return tcpPort;
+ }
+
+ Settings build() {
+ ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
+ configureFileSystem(builder);
+ configureStorage(builder);
+ configurePlugins(builder);
+ configureNetwork(builder);
+ configureCluster(builder);
+ configureMarvel(builder);
+ return builder.build();
+ }
+
+ private void configureFileSystem(ImmutableSettings.Builder builder) {
+ File homeDir = props.nonNullValueAsFile(ProcessConstants.PATH_HOME);
+ File dataDir, workDir, logDir;
+
+ // data dir
+ String dataPath = props.value(ProcessConstants.PATH_DATA);
+ if (StringUtils.isNotEmpty(dataPath)) {
+ dataDir = new File(dataPath, "es");
+ } else {
+ dataDir = new File(homeDir, "data/es");
+ }
+ builder.put("path.data", dataDir.getAbsolutePath());
+
+ // working dir
+ String workPath = props.value(ProcessConstants.PATH_TEMP);
+ if (StringUtils.isNotEmpty(workPath)) {
+ workDir = new File(workPath);
+ } else {
+ workDir = new File(homeDir, "temp");
+ }
+ builder.put("path.work", workDir.getAbsolutePath());
+ builder.put("path.plugins", workDir.getAbsolutePath());
+
+ // log dir
+ String logPath = props.value(ProcessConstants.PATH_LOGS);
+ if (StringUtils.isNotEmpty(logPath)) {
+ logDir = new File(logPath);
+ } else {
+ logDir = new File(homeDir, "log");
+ }
+ builder.put("path.logs", logDir.getAbsolutePath());
+ }
+
+ private void configurePlugins(ImmutableSettings.Builder builder) {
+ builder
+ .put("script.default_lang", "native")
+ .put("script.native." + ListUpdate.NAME + ".type", ListUpdate.UpdateListScriptFactory.class.getName());
+ }
+
+ private void configureNetwork(ImmutableSettings.Builder builder) {
+ // disable multicast
+ builder.put("discovery.zen.ping.multicast.enabled", "false");
+ builder.put("transport.tcp.port", tcpPort);
+
+ Integer httpPort = props.valueAsInt(PROP_HTTP_PORT);
+ if (httpPort == null) {
+ // standard configuration
+ builder.put("http.enabled", false);
+ } else {
+ LOGGER.warn(String.format(
+ "Elasticsearch HTTP connector is enabled on port %d. MUST NOT BE USED INTO PRODUCTION", httpPort));
+ builder.put("http.enabled", true);
+ builder.put("http.host", "127.0.0.1");
+ builder.put("http.port", httpPort);
+ }
+ }
+
+ private void configureStorage(ImmutableSettings.Builder builder) {
+ builder
+ .put("index.number_of_shards", "1")
+ .put("index.refresh_interval", "30s")
+ .put("index.store.type", "mmapfs")
+ .put("indices.store.throttle.type", "none")
+ .put("index.merge.scheduler.max_thread_count",
+ Math.max(1, Math.min(3, Runtime.getRuntime().availableProcessors() / 2)));
+ }
+
+ private void configureCluster(ImmutableSettings.Builder builder) {
+ if (!clusterNodes.isEmpty()) {
+ LoggerFactory.getLogger(SearchServer.class).info("Joining ES cluster with master: {}", clusterNodes);
+ builder.put("discovery.zen.ping.unicast.hosts", StringUtils.join(clusterNodes, ","));
+ builder.put("node.master", false);
+
+ // Enforce a N/2+1 number of masters in cluster
+ builder.put("discovery.zen.minimum_master_nodes", 1);
+ }
+
+ // When SQ is ran as a cluster
+ // see https://jira.codehaus.org/browse/SONAR-5687
+ int replicationFactor = props.valueAsBoolean(ProcessConstants.CLUSTER_ACTIVATION, false) ? 1 : 0;
+ builder.put("index.number_of_replicas", replicationFactor);
+
+ // Set cluster coordinates
+ builder.put("cluster.name", clusterName);
+ builder.put("cluster.routing.allocation.awareness.attributes", "rack_id");
+ builder.put("node.rack_id", props.value(ProcessConstants.CLUSTER_NODE_NAME, "unknown"));
+ if (props.contains(ProcessConstants.CLUSTER_NODE_NAME)) {
+ builder.put("node.name", props.value(ProcessConstants.CLUSTER_NODE_NAME));
+ } else {
+ try {
+ builder.put("node.name", InetAddress.getLocalHost().getHostName());
+ } catch (Exception e) {
+ LoggerFactory.getLogger(SearchServer.class).warn("Could not determine hostname", e);
+ builder.put("node.name", "sq-" + System.currentTimeMillis());
+ }
+ }
+ }
+
+ private void configureMarvel(ImmutableSettings.Builder builder) {
+ Set<String> marvels = new TreeSet<String>();
+ marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ",")));
+
+ // Enable marvel's index creation
+ builder.put("action.auto_create_index", ".marvel-*");
+ // If we're collecting indexing data send them to the Marvel host(s)
+ if (!marvels.isEmpty()) {
+ String hosts = StringUtils.join(marvels, ",");
+ LOGGER.info(String.format("Elasticsearch Marvel is enabled for %s", hosts));
+ builder.put("marvel.agent.exporter.es.hosts", hosts);
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 org.elasticsearch.common.settings.Settings;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.process.MessageException;
-import org.sonar.process.Props;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class EsSettingsTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void fail_if_tcp_port_is_not_set() throws Exception {
- try {
- new EsSettings(new Props(new Properties()));
- fail();
- } catch (MessageException e) {
- assertThat(e).hasMessage("Property is not set: sonar.search.port");
- }
- }
-
- @Test
- public void test_default_settings() throws Exception {
- File homeDir = temp.newFolder();
- Props props = new Props(new Properties());
- props.set(EsSettings.PROP_TCP_PORT, "1234");
- props.set(EsSettings.SONAR_PATH_HOME, homeDir.getAbsolutePath());
- props.set(EsSettings.PROP_CLUSTER_NAME, "test");
-
- EsSettings esSettings = new EsSettings(props);
- assertThat(esSettings.inCluster()).isFalse();
- assertThat(esSettings.clusterName()).isEqualTo("test");
- assertThat(esSettings.tcpPort()).isEqualTo(1234);
-
- Settings generated = esSettings.build();
- assertThat(generated.get("transport.tcp.port")).isEqualTo("1234");
- assertThat(generated.get("cluster.name")).isEqualTo("test");
- assertThat(generated.get("path.data")).isNotNull();
- assertThat(generated.get("path.logs")).isNotNull();
- assertThat(generated.get("path.work")).isNotNull();
-
- // http is disabled for security reasons
- assertThat(generated.get("http.enabled")).isEqualTo("false");
-
- // no cluster, but node name is set though
- assertThat(generated.get("index.number_of_replicas")).isEqualTo("0");
- assertThat(generated.get("discovery.zen.ping.unicast.hosts")).isNull();
- assertThat(generated.get("node.name")).isNotEmpty();
- }
-
- @Test
- public void override_dirs() throws Exception {
- File homeDir = temp.newFolder(), dataDir = temp.newFolder(), logDir = temp.newFolder(), tempDir = temp.newFolder();
- Props props = new Props(new Properties());
- props.set(EsSettings.PROP_TCP_PORT, "1234");
- props.set(EsSettings.SONAR_PATH_HOME, homeDir.getAbsolutePath());
- props.set(EsSettings.SONAR_PATH_DATA, dataDir.getAbsolutePath());
- props.set(EsSettings.SONAR_PATH_LOG, logDir.getAbsolutePath());
- props.set(EsSettings.SONAR_PATH_TEMP, tempDir.getAbsolutePath());
- props.set(EsSettings.PROP_CLUSTER_NAME, "test");
-
- Settings settings = new EsSettings(props).build();
-
- assertThat(settings.get("path.data")).isEqualTo(new File(dataDir, "es").getAbsolutePath());
- assertThat(settings.get("path.logs")).isEqualTo(logDir.getAbsolutePath());
- assertThat(settings.get("path.work")).isEqualTo(tempDir.getAbsolutePath());
- }
-
- @Test
- public void test_cluster_master() throws Exception {
- Props props = minProps();
- props.set(EsSettings.PROP_CLUSTER_ACTIVATION, "true");
- Settings settings = new EsSettings(props).build();
-
- assertThat(settings.get("index.number_of_replicas")).isEqualTo("1");
- assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isNull();
- // TODO set node.master=true ?
- }
-
- @Test
- public void test_cluster_slave() throws Exception {
- Props props = minProps();
- props.set(EsSettings.PROP_CLUSTER_MASTER, "127.0.0.2,127.0.0.3");
- Settings settings = new EsSettings(props).build();
-
- assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("127.0.0.2,127.0.0.3");
- assertThat(settings.get("node.master")).isEqualTo("false");
- }
-
- @Test
- public void enable_marvel() throws Exception {
- Props props = minProps();
- props.set(EsSettings.PROP_MARVEL, "127.0.0.2,127.0.0.3");
- Settings settings = new EsSettings(props).build();
-
- assertThat(settings.get("marvel.agent.exporter.es.hosts")).isEqualTo("127.0.0.2,127.0.0.3");
- }
-
- @Test
- public void enable_http_connector() throws Exception {
- Props props = minProps();
- props.set(EsSettings.PROP_HTTP_PORT, "9010");
- Settings settings = new EsSettings(props).build();
-
- assertThat(settings.get("http.port")).isEqualTo("9010");
- assertThat(settings.get("http.host")).isEqualTo("127.0.0.1");
- assertThat(settings.get("http.enabled")).isEqualTo("true");
- }
-
- private Props minProps() throws IOException {
- File homeDir = temp.newFolder();
- Props props = new Props(new Properties());
- props.set(EsSettings.PROP_TCP_PORT, "1234");
- props.set(EsSettings.SONAR_PATH_HOME, homeDir.getAbsolutePath());
- props.set(EsSettings.PROP_CLUSTER_NAME, "test");
- return props;
- }
-}
import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.util.Properties;
@Test
public void start_stop_server() throws Exception {
Props props = new Props(new Properties());
- props.set(EsSettings.PROP_TCP_PORT, String.valueOf(port));
- props.set(EsSettings.PROP_CLUSTER_NAME, CLUSTER_NAME);
- props.set(EsSettings.SONAR_PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.SEARCH_PORT, String.valueOf(port));
+ props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
searchServer = new SearchServer(props);
searchServer.start();
public void slave_success_replication() throws Exception {
Props props = new Props(new Properties());
- props.set(EsSettings.PROP_CLUSTER_ACTIVATION, "true");
- props.set(EsSettings.PROP_TCP_PORT, String.valueOf(port));
- props.set(EsSettings.PROP_NODE_NAME, "MASTER");
- props.set(EsSettings.PROP_CLUSTER_NAME, CLUSTER_NAME);
- props.set(EsSettings.SONAR_PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_ACTIVATION, "true");
+ props.set(ProcessConstants.SEARCH_PORT, String.valueOf(port));
+ props.set(ProcessConstants.CLUSTER_NODE_NAME, "MASTER");
+ props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
searchServer = new SearchServer(props);
assertThat(searchServer).isNotNull();
// start a slave
props = new Props(new Properties());
- props.set(EsSettings.PROP_CLUSTER_MASTER, "localhost:" + port);
- props.set(EsSettings.PROP_NODE_NAME, "SLAVE");
- props.set(EsSettings.PROP_TCP_PORT, String.valueOf(NetworkUtils.freePort()));
- props.set(EsSettings.PROP_CLUSTER_NAME, CLUSTER_NAME);
- props.set(EsSettings.SONAR_PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_MASTER_HOSTS, "localhost:" + port);
+ props.set(ProcessConstants.CLUSTER_NODE_NAME, "SLAVE");
+ props.set(ProcessConstants.SEARCH_PORT, String.valueOf(NetworkUtils.freePort()));
+ props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
SearchServer slaveServer = new SearchServer(props);
assertThat(slaveServer).isNotNull();
@Test
public void slave_failed_replication() throws Exception {
Props props = new Props(new Properties());
- props.set(EsSettings.PROP_CLUSTER_ACTIVATION, "false");
- props.set(EsSettings.PROP_TCP_PORT, String.valueOf(port));
- props.set(EsSettings.PROP_NODE_NAME, "MASTER");
- props.set(EsSettings.PROP_CLUSTER_NAME, CLUSTER_NAME);
- props.set(EsSettings.SONAR_PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_ACTIVATION, "false");
+ props.set(ProcessConstants.SEARCH_PORT, String.valueOf(port));
+ props.set(ProcessConstants.CLUSTER_NODE_NAME, "MASTER");
+ props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
searchServer = new SearchServer(props);
assertThat(searchServer).isNotNull();
// start a slave
props = new Props(new Properties());
- props.set(EsSettings.PROP_CLUSTER_MASTER, "localhost:" + port);
- props.set(EsSettings.PROP_NODE_NAME, "SLAVE");
- props.set(EsSettings.PROP_TCP_PORT, String.valueOf(NetworkUtils.freePort()));
- props.set(EsSettings.PROP_CLUSTER_NAME, CLUSTER_NAME);
- props.set(EsSettings.SONAR_PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_MASTER_HOSTS, "localhost:" + port);
+ props.set(ProcessConstants.CLUSTER_NODE_NAME, "SLAVE");
+ props.set(ProcessConstants.SEARCH_PORT, String.valueOf(NetworkUtils.freePort()));
+ props.set(ProcessConstants.CLUSTER_NAME, CLUSTER_NAME);
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
SearchServer slaveServer = new SearchServer(props);
assertThat(slaveServer).isNotNull();
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 org.elasticsearch.common.settings.Settings;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.process.MessageException;
+import org.sonar.process.ProcessConstants;
+import org.sonar.process.Props;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class SearchSettingsTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Test
+ public void fail_if_tcp_port_is_not_set() throws Exception {
+ try {
+ new SearchSettings(new Props(new Properties()));
+ fail();
+ } catch (MessageException e) {
+ assertThat(e).hasMessage("Property is not set: sonar.search.port");
+ }
+ }
+
+ @Test
+ public void test_default_settings() throws Exception {
+ File homeDir = temp.newFolder();
+ Props props = new Props(new Properties());
+ props.set(ProcessConstants.SEARCH_PORT, "1234");
+ props.set(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_NAME, "test");
+
+ SearchSettings searchSettings = new SearchSettings(props);
+ assertThat(searchSettings.inCluster()).isFalse();
+ assertThat(searchSettings.clusterName()).isEqualTo("test");
+ assertThat(searchSettings.tcpPort()).isEqualTo(1234);
+
+ Settings generated = searchSettings.build();
+ assertThat(generated.get("transport.tcp.port")).isEqualTo("1234");
+ assertThat(generated.get("cluster.name")).isEqualTo("test");
+ assertThat(generated.get("path.data")).isNotNull();
+ assertThat(generated.get("path.logs")).isNotNull();
+ assertThat(generated.get("path.work")).isNotNull();
+
+ // http is disabled for security reasons
+ assertThat(generated.get("http.enabled")).isEqualTo("false");
+
+ // no cluster, but node name is set though
+ assertThat(generated.get("index.number_of_replicas")).isEqualTo("0");
+ assertThat(generated.get("discovery.zen.ping.unicast.hosts")).isNull();
+ assertThat(generated.get("node.name")).isNotEmpty();
+ }
+
+ @Test
+ public void override_dirs() throws Exception {
+ File homeDir = temp.newFolder(), dataDir = temp.newFolder(), logDir = temp.newFolder(), tempDir = temp.newFolder();
+ Props props = new Props(new Properties());
+ props.set(ProcessConstants.SEARCH_PORT, "1234");
+ props.set(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessConstants.PATH_DATA, dataDir.getAbsolutePath());
+ props.set(ProcessConstants.PATH_LOGS, logDir.getAbsolutePath());
+ props.set(ProcessConstants.PATH_TEMP, tempDir.getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_NAME, "test");
+
+ Settings settings = new SearchSettings(props).build();
+
+ assertThat(settings.get("path.data")).isEqualTo(new File(dataDir, "es").getAbsolutePath());
+ assertThat(settings.get("path.logs")).isEqualTo(logDir.getAbsolutePath());
+ assertThat(settings.get("path.work")).isEqualTo(tempDir.getAbsolutePath());
+ }
+
+ @Test
+ public void test_cluster_master() throws Exception {
+ Props props = minProps();
+ props.set(ProcessConstants.CLUSTER_ACTIVATION, "true");
+ Settings settings = new SearchSettings(props).build();
+
+ assertThat(settings.get("index.number_of_replicas")).isEqualTo("1");
+ assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isNull();
+ // TODO set node.master=true ?
+ }
+
+ @Test
+ public void test_cluster_slave() throws Exception {
+ Props props = minProps();
+ props.set(ProcessConstants.CLUSTER_MASTER_HOSTS, "127.0.0.2,127.0.0.3");
+ Settings settings = new SearchSettings(props).build();
+
+ assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("127.0.0.2,127.0.0.3");
+ assertThat(settings.get("node.master")).isEqualTo("false");
+ }
+
+ @Test
+ public void enable_marvel() throws Exception {
+ Props props = minProps();
+ props.set(SearchSettings.PROP_MARVEL_HOSTS, "127.0.0.2,127.0.0.3");
+ Settings settings = new SearchSettings(props).build();
+
+ assertThat(settings.get("marvel.agent.exporter.es.hosts")).isEqualTo("127.0.0.2,127.0.0.3");
+ }
+
+ @Test
+ public void enable_http_connector() throws Exception {
+ Props props = minProps();
+ props.set(SearchSettings.PROP_HTTP_PORT, "9010");
+ Settings settings = new SearchSettings(props).build();
+
+ assertThat(settings.get("http.port")).isEqualTo("9010");
+ assertThat(settings.get("http.host")).isEqualTo("127.0.0.1");
+ assertThat(settings.get("http.enabled")).isEqualTo("true");
+ }
+
+ private Props minProps() throws IOException {
+ File homeDir = temp.newFolder();
+ Props props = new Props(new Properties());
+ props.set(ProcessConstants.SEARCH_PORT, "1234");
+ props.set(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
+ props.set(ProcessConstants.CLUSTER_NAME, "test");
+ return props;
+ }
+}
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
import org.slf4j.LoggerFactory;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
}
private File tomcatBasedir() {
- return new File(props.value("sonar.path.temp"), "tc");
+ return new File(props.value(ProcessConstants.PATH_TEMP), "tc");
}
void terminate() {
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.sonar.core.config.Logback;
import org.sonar.core.profiling.Profiling;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
String configProfilingLevel = props.value(Profiling.CONFIG_PROFILING_LEVEL, "NONE");
Profiling.Level profilingLevel = Profiling.Level.fromConfigString(configProfilingLevel);
Map<String, String> variables = ImmutableMap.of(
- "sonar.path.logs", props.nonNullValue("sonar.path.logs"),
+ ProcessConstants.PATH_LOGS, props.nonNullValue(ProcessConstants.PATH_LOGS),
"LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT);
Logback.configure("/org/sonar/server/platform/logback.xml", variables);
}
if (props.valueAsBoolean(PROPERTY_ENABLE_ACCESS_LOGS, true)) {
LogbackValve valve = new LogbackValve();
valve.setQuiet(true);
- valve.setFilename(new File(props.nonNullValue("sonar.path.web"), ACCESS_RELATIVE_PATH).getAbsolutePath());
+ valve.setFilename(new File(props.nonNullValue(ProcessConstants.PATH_WEB), ACCESS_RELATIVE_PATH).getAbsolutePath());
tomcat.getHost().getPipeline().addValve(valve);
}
}
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
static String webappPath(Props props) {
String webDir = props.value("sonar.web.dev.sources");
if (StringUtils.isEmpty(webDir)) {
- webDir = new File(props.value("sonar.path.home"), "web").getAbsolutePath();
+ webDir = new File(props.value(ProcessConstants.PATH_HOME), "web").getAbsolutePath();
}
LoggerFactory.getLogger(Webapp.class).info(String.format("Webapp directory: %s", webDir));
return webDir;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.SonarException;
+import org.sonar.process.ProcessConstants;
import java.io.File;
import java.sql.DriverManager;
@VisibleForTesting
File getDataDirectory(Settings settings) {
- return new File(settings.getString("sonar.path.data"));
+ return new File(settings.getString(ProcessConstants.PATH_DATA));
}
private String getSetting(String name, String defaultValue) {
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerFileSystem;
+import org.sonar.process.ProcessConstants;
import java.io.File;
import java.io.FileFilter;
public DefaultServerFileSystem(Settings settings, Server server) {
this.server = server;
- this.homeDir = new File(settings.getString("sonar.path.home"));
+ this.homeDir = new File(settings.getString(ProcessConstants.PATH_HOME));
}
/**
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
+import org.sonar.process.ProcessConstants;
import java.io.File;
import java.io.IOException;
// Remove trailing slashes
.replaceFirst("(\\/+)$", "");
- sonarHome = new File(settings.getString("sonar.path.home"));
+ sonarHome = new File(settings.getString(ProcessConstants.PATH_HOME));
if (!sonarHome.isDirectory()) {
throw new IllegalStateException("SonarQube home directory is not valid");
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.search;
-
-public final class IndexProperties {
-
- private IndexProperties() {
- // only static stuff
- }
-
- public static final String CLUSTER_ACTIVATION = "sonar.cluster.activation";
- public static final String NODE_PORT = "sonar.search.port";
- public static final String CLUSTER_NAME = "sonar.cluster.name";
- public static final String NODE_NAME = "sonar.node.name";
-
-}
import org.sonar.core.profiling.Profiling;
import org.sonar.core.profiling.StopWatch;
import org.sonar.process.LoopbackAddress;
+import org.sonar.process.ProcessConstants;
/**
* ElasticSearch Node used to connect to index.
public SearchClient(Settings settings) {
super(ImmutableSettings.settingsBuilder()
- .put("node.name", StringUtils.defaultIfEmpty(settings.getString(IndexProperties.NODE_NAME), "sq_local_client"))
+ .put("node.name", StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.CLUSTER_NODE_NAME), "sq_local_client"))
.put("network.bind_host", "localhost")
- .put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(IndexProperties.NODE_NAME), "unknown"))
- .put("cluster.name", StringUtils.defaultIfBlank(settings.getString(IndexProperties.CLUSTER_NAME), "sonarqube"))
+ .put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(ProcessConstants.CLUSTER_NODE_NAME), "unknown"))
+ .put("cluster.name", StringUtils.defaultIfBlank(settings.getString(ProcessConstants.CLUSTER_NAME), "sonarqube"))
.build());
initLogging();
this.addTransportAddress(new InetSocketTransportAddress(LoopbackAddress.get().getHostAddress(),
- settings.getInt(IndexProperties.NODE_PORT)));
+ settings.getInt(ProcessConstants.SEARCH_PORT)));
this.profiling = new Profiling(settings);
}
import org.sonar.core.preview.PreviewCache;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.timemachine.Periods;
+import org.sonar.process.ProcessConstants;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.db.migrations.DatabaseMigrator;
import org.sonar.server.measure.MeasureFilterEngine;
}
public String getServerHome() {
- return get(Settings.class).getString("sonar.path.home");
+ return get(Settings.class).getString(ProcessConstants.PATH_HOME);
}
public ComponentContainer getContainer() {
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.slf4j.Logger;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
public void enable_access_logs_by_Default() throws Exception {
Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
Props props = new Props(new Properties());
- props.set("sonar.path.web", temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.PATH_WEB, temp.newFolder().getAbsolutePath());
Logging.configure(tomcat, props);
verify(tomcat.getHost().getPipeline()).addValve(argThat(new ArgumentMatcher<Valve>() {
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.ProcessConstants;
import java.io.File;
import java.io.IOException;
.setProperty(DatabaseProperties.PROP_USER, "login")
.setProperty(DatabaseProperties.PROP_PASSWORD, "pwd")
.setProperty(DatabaseProperties.PROP_EMBEDDED_PORT, "" + port)
- .setProperty("sonar.path.data", "./target/testDB");
+ .setProperty(ProcessConstants.PATH_DATA, "./target/testDB");
}
}
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
+import org.sonar.process.ProcessConstants;
import java.io.File;
@Before
public void setUp() throws Exception {
- settings = new Settings().setProperty("sonar.path.home", sonarHome.getRoot().getAbsolutePath());
+ settings = new Settings().setProperty(ProcessConstants.PATH_HOME, sonarHome.getRoot().getAbsolutePath());
new File(sonarHome.getRoot(), "web/deploy").mkdirs();
server = new ServerImpl(settings, "/org/sonar/server/platform/ServerImplTest/build.properties", "/org/sonar/server/platform/ServerImplTest/version.txt");
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Settings;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import org.sonar.search.SearchServer;
clusterName = "cluster-mem-" + System.currentTimeMillis();
clusterPort = NetworkUtils.freePort();
Properties properties = new Properties();
- properties.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
- properties.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
- properties.setProperty("sonar.path.home", temp.getRoot().getAbsolutePath());
+ properties.setProperty(ProcessConstants.CLUSTER_NAME, clusterName);
+ properties.setProperty(ProcessConstants.SEARCH_PORT, clusterPort.toString());
+ properties.setProperty(ProcessConstants.PATH_HOME, temp.getRoot().getAbsolutePath());
try {
searchServer = new SearchServer(new Props(properties));
} catch (Exception e) {
public void setup() throws IOException {
File dataDir = temp.newFolder();
Settings settings = new Settings();
- settings.setProperty(IndexProperties.CLUSTER_ACTIVATION, false);
- settings.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
- settings.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
- settings.setProperty("sonar.path.home", dataDir.getAbsolutePath());
+ settings.setProperty(ProcessConstants.CLUSTER_ACTIVATION, false);
+ settings.setProperty(ProcessConstants.CLUSTER_NAME, clusterName);
+ settings.setProperty(ProcessConstants.SEARCH_PORT, clusterPort.toString());
+ settings.setProperty(ProcessConstants.PATH_HOME, dataDir.getAbsolutePath());
searchClient = new SearchClient(settings);
}
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.resources.Language;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import org.sonar.search.SearchServer;
import org.sonar.server.platform.BackendCleanup;
import org.sonar.server.platform.Platform;
-import org.sonar.server.search.IndexProperties;
import org.sonar.server.ws.WsTester;
import javax.annotation.Nullable;
clusterName = "cluster-mem-" + System.currentTimeMillis();
clusterPort = NetworkUtils.freePort();
Properties properties = new Properties();
- properties.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
- properties.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
- properties.setProperty("sonar.path.home", homeDir.getAbsolutePath());
+ properties.setProperty(ProcessConstants.CLUSTER_NAME, clusterName);
+ properties.setProperty(ProcessConstants.SEARCH_PORT, clusterPort.toString());
+ properties.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
searchServer = new SearchServer(new Props(properties));
}
Properties properties = new Properties();
properties.putAll(initialProps);
-
- properties.setProperty(IndexProperties.CLUSTER_NAME, clusterName);
- properties.setProperty(IndexProperties.NODE_PORT, clusterPort.toString());
-
- properties.setProperty("sonar.path.home", homeDir.getAbsolutePath());
+ properties.setProperty(ProcessConstants.CLUSTER_NAME, clusterName);
+ properties.setProperty(ProcessConstants.SEARCH_PORT, clusterPort.toString());
+ properties.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:" + homeDir.getAbsolutePath() + "/h2");
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
String key = entry.getKey().toString();
import org.apache.commons.lang.StringUtils;
import org.sonar.process.MinimumViableSystem;
import org.sonar.process.ProcessCommands;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.ProcessLogging;
import org.sonar.process.Props;
import org.sonar.process.StopWatcher;
}
public void start(Props props) {
- if (props.valueAsBoolean("sonar.enableStopCommand", false)) {
+ if (props.valueAsBoolean(ProcessConstants.ENABLE_STOP_COMMAND, false)) {
// stop application when file <temp>/app.stop is created
- File tempDir = props.nonNullValueAsFile("sonar.path.temp");
+ File tempDir = props.nonNullValueAsFile(ProcessConstants.PATH_TEMP);
ProcessCommands commands = new ProcessCommands(tempDir, "app");
stopWatcher = new StopWatcher(commands, this);
stopWatcher.start();
List<JavaCommand> createCommands(Props props) {
List<JavaCommand> commands = new ArrayList<JavaCommand>();
- File homeDir = props.nonNullValueAsFile("sonar.path.home");
- File tempDir = props.nonNullValueAsFile("sonar.path.temp");
+ File homeDir = props.nonNullValueAsFile(ProcessConstants.PATH_HOME);
+ File tempDir = props.nonNullValueAsFile(ProcessConstants.PATH_TEMP);
JavaCommand elasticsearch = new JavaCommand("search");
elasticsearch
.setWorkDir(homeDir)
.addJavaOptions("-Djava.awt.headless=true")
- .addJavaOptions(props.nonNullValue(DefaultSettings.SEARCH_JAVA_OPTS))
- .addJavaOptions(props.nonNullValue(DefaultSettings.SEARCH_JAVA_ADDITIONAL_OPTS))
+ .addJavaOptions(props.nonNullValue(ProcessConstants.SEARCH_JAVA_OPTS))
+ .addJavaOptions(props.nonNullValue(ProcessConstants.SEARCH_JAVA_ADDITIONAL_OPTS))
.setTempDir(tempDir.getAbsoluteFile())
.setClassName("org.sonar.search.SearchServer")
.setArguments(props.rawProperties())
commands.add(elasticsearch);
// do not yet start SQ in cluster mode. See SONAR-5483 & SONAR-5391
- if (StringUtils.isEmpty(props.value(DefaultSettings.CLUSTER_MASTER))) {
+ if (StringUtils.isEmpty(props.value(ProcessConstants.CLUSTER_MASTER_HOSTS))) {
JavaCommand webServer = new JavaCommand("web")
.setWorkDir(homeDir)
.addJavaOptions("-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false")
- .addJavaOptions(props.nonNullValue(DefaultSettings.WEB_JAVA_OPTS))
- .addJavaOptions(props.nonNullValue(DefaultSettings.WEB_JAVA_ADDITIONAL_OPTS))
+ .addJavaOptions(props.nonNullValue(ProcessConstants.WEB_JAVA_OPTS))
+ .addJavaOptions(props.nonNullValue(ProcessConstants.WEB_JAVA_ADDITIONAL_OPTS))
.setTempDir(tempDir.getAbsoluteFile())
// required for logback tomcat valve
- .setEnvVariable("sonar.path.logs", props.nonNullValue("sonar.path.logs"))
+ .setEnvVariable(ProcessConstants.PATH_LOGS, props.nonNullValue(ProcessConstants.PATH_LOGS))
.setClassName("org.sonar.server.app.WebServer")
.setArguments(props.rawProperties())
.addClasspath("./lib/common/*")
.addClasspath("./lib/server/*");
- String driverPath = props.value(JdbcSettings.PROPERTY_DRIVER_PATH);
+ String driverPath = props.value(ProcessConstants.JDBC_DRIVER_PATH);
if (driverPath != null) {
webServer.addClasspath(driverPath);
}
package org.sonar.application;
import org.sonar.process.NetworkUtils;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.util.HashMap;
// only static stuff
}
- static final String CLUSTER_MASTER = "sonar.cluster.master";
- static final String CLUSTER_NAME = "sonar.cluster.name";
- static final String CLUSTER_NODE_NAME = "sonar.node.name";
- static final String SEARCH_PORT = "sonar.search.port";
- static final String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
- static final String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
- static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
- static final String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
- static final String JDBC_URL = "sonar.jdbc.url";
- static final String JDBC_LOGIN = "sonar.jdbc.username";
- static final String JDBC_PASSWORD = "sonar.jdbc.password";
-
static void init(Props props) {
// forced property
- props.set("sonar.search.type", "TRANSPORT");
+ props.set(ProcessConstants.SEARCH_TYPE, "TRANSPORT");
// init string properties
for (Map.Entry<String, String> entry : defaults().entrySet()) {
private static Map<String, String> defaults() {
Map<String, String> defaults = new HashMap<String, String>();
- defaults.put(CLUSTER_NAME, "sonarqube");
- defaults.put(SEARCH_JAVA_OPTS, "-Xmx256m -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
+ defaults.put(ProcessConstants.CLUSTER_NAME, "sonarqube");
+ defaults.put(ProcessConstants.SEARCH_JAVA_OPTS, "-Xmx256m -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
"-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
"-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true");
- defaults.put(SEARCH_JAVA_ADDITIONAL_OPTS, "");
- defaults.put(CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
- defaults.put(WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true " +
+ defaults.put(ProcessConstants.SEARCH_JAVA_ADDITIONAL_OPTS, "");
+ defaults.put(ProcessConstants.CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
+ defaults.put(ProcessConstants.WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true " +
"-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false");
- defaults.put(WEB_JAVA_ADDITIONAL_OPTS, "");
- defaults.put(JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
- defaults.put(JDBC_LOGIN, "sonar");
- defaults.put(JDBC_PASSWORD, "sonar");
+ defaults.put(ProcessConstants.WEB_JAVA_ADDITIONAL_OPTS, "");
+ defaults.put(ProcessConstants.JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
+ defaults.put(ProcessConstants.JDBC_LOGIN, "sonar");
+ defaults.put(ProcessConstants.JDBC_PASSWORD, "sonar");
return defaults;
}
private static Map<String, Integer> defaultPorts() {
Map<String, Integer> defaults = new HashMap<String, Integer>();
- defaults.put(SEARCH_PORT, 9001);
+ defaults.put(ProcessConstants.SEARCH_PORT, 9001);
return defaults;
}
}
import org.apache.commons.io.FileUtils;
import org.slf4j.LoggerFactory;
import org.sonar.process.MessageException;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import javax.annotation.CheckForNull;
public class JdbcSettings {
- static final String PROPERTY_DRIVER_PATH = "sonar.jdbc.driverPath";
-
static enum Provider {
h2(null), jtds("lib/jdbc/jtds"), mysql("lib/jdbc/mysql"), oracle("extensions/jdbc-driver/oracle"),
postgresql("lib/jdbc/postgresql");
}
public void checkAndComplete(File homeDir, Props props) {
- String url = props.nonNullValue(DefaultSettings.JDBC_URL);
+ String url = props.nonNullValue(ProcessConstants.JDBC_URL);
Provider provider = driverProvider(url);
checkUrlParameters(provider, url);
String driverPath = driverPath(homeDir, provider);
if (driverPath != null) {
- props.set(PROPERTY_DRIVER_PATH, driverPath);
+ props.set(ProcessConstants.JDBC_DRIVER_PATH, driverPath);
}
}
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.sonar.process.ConfigurationUtils;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
Props build() throws IOException {
Properties p = loadPropertiesFile(homeDir);
p.putAll(rawProperties);
- p.setProperty("sonar.path.home", homeDir.getAbsolutePath());
+ p.setProperty(ProcessConstants.PATH_HOME, homeDir.getAbsolutePath());
p = ConfigurationUtils.interpolateVariables(p, System.getenv());
// the difference between Properties and Props is that the latter
DefaultSettings.init(props);
// init file system
- initExistingDir(props, "sonar.path.data", "data");
- initExistingDir(props, "sonar.path.web", "web");
- initExistingDir(props, "sonar.path.logs", "logs");
+ initExistingDir(props, ProcessConstants.PATH_DATA, "data");
+ initExistingDir(props, ProcessConstants.PATH_WEB, "web");
+ initExistingDir(props, ProcessConstants.PATH_LOGS, "logs");
initTempDir(props);
// check JDBC properties and set path to driver
}
private void initTempDir(Props props) throws IOException {
- File dir = configureDir(props, "sonar.path.temp", "temp");
+ File dir = configureDir(props, ProcessConstants.PATH_TEMP, "temp");
FileUtils.deleteQuietly(dir);
FileUtils.forceMkdir(dir);
}
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import org.sonar.process.monitor.JavaCommand;
import org.sonar.process.monitor.Monitor;
private Props initDefaultProps() throws IOException {
Props props = new Props(new Properties());
DefaultSettings.init(props);
- props.set("sonar.path.home", temp.newFolder().getAbsolutePath());
- props.set("sonar.path.temp", temp.newFolder().getAbsolutePath());
- props.set("sonar.path.logs", temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.PATH_HOME, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.PATH_TEMP, temp.newFolder().getAbsolutePath());
+ props.set(ProcessConstants.PATH_LOGS, temp.newFolder().getAbsolutePath());
return props;
}
}
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.process.MessageException;
+import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:oracle:thin:@localhost/XE");
settings.checkAndComplete(home, props);
- assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar");
settings.checkAndComplete(home, props);
- assertThat(props.value(JdbcSettings.PROPERTY_DRIVER_PATH)).isNull();
+ assertThat(props.value(ProcessConstants.JDBC_DRIVER_PATH)).isNull();
}
@Test
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
settings.checkAndComplete(home, props);
- assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test
Props props = new Props(new Properties());
props.set("sonar.jdbc.url", "jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor");
settings.checkAndComplete(home, props);
- assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+ assertThat(props.nonNullValueAsFile(ProcessConstants.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
}
@Test