You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProcessProperties.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.process;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. /**
  24. * Constants shared by search, web server and app processes.
  25. * They are almost all the properties defined in conf/sonar.properties.
  26. */
  27. public class ProcessProperties {
  28. public static final String CLUSTER_ACTIVATE = "sonar.cluster.activate";
  29. public static final String CLUSTER_MASTER = "sonar.cluster.master";
  30. public static final String CLUSTER_MASTER_HOST = "sonar.cluster.masterHost";
  31. public static final String CLUSTER_NAME = "sonar.cluster.name";
  32. public static final String CLUSTER_NODE_NAME = "sonar.node.name";
  33. public static final String JDBC_URL = "sonar.jdbc.url";
  34. public static final String JDBC_LOGIN = "sonar.jdbc.username";
  35. public static final String JDBC_PASSWORD = "sonar.jdbc.password";
  36. public static final String JDBC_DRIVER_PATH = "sonar.jdbc.driverPath";
  37. public static final String JDBC_MAX_ACTIVE = "sonar.jdbc.maxActive";
  38. public static final String JDBC_MAX_IDLE = "sonar.jdbc.maxIdle";
  39. public static final String JDBC_MIN_IDLE = "sonar.jdbc.minIdle";
  40. public static final String JDBC_MAX_WAIT = "sonar.jdbc.maxWait";
  41. public static final String JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS = "sonar.jdbc.minEvictableIdleTimeMillis";
  42. public static final String JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS = "sonar.jdbc.timeBetweenEvictionRunsMillis";
  43. public static final String PATH_DATA = "sonar.path.data";
  44. public static final String PATH_HOME = "sonar.path.home";
  45. public static final String PATH_LOGS = "sonar.path.logs";
  46. public static final String PATH_TEMP = "sonar.path.temp";
  47. public static final String PATH_WEB = "sonar.path.web";
  48. public static final String SEARCH_HOST = "sonar.search.host";
  49. public static final String SEARCH_PORT = "sonar.search.port";
  50. public static final String SEARCH_HTTP_PORT = "sonar.search.httpPort";
  51. public static final String SEARCH_JAVA_OPTS = "sonar.search.javaOpts";
  52. public static final String SEARCH_JAVA_ADDITIONAL_OPTS = "sonar.search.javaAdditionalOpts";
  53. public static final String WEB_JAVA_OPTS = "sonar.web.javaOpts";
  54. public static final String WEB_JAVA_ADDITIONAL_OPTS = "sonar.web.javaAdditionalOpts";
  55. /**
  56. * Used by Orchestrator to ask for shutdown of monitor process
  57. */
  58. public static final String ENABLE_STOP_COMMAND = "sonar.enableStopCommand";
  59. // Constants declared by the ES plugin ListUpdate (see sonar-search)
  60. // that are used by sonar-server
  61. public static final String ES_PLUGIN_LISTUPDATE_SCRIPT_NAME = "listUpdate";
  62. public static final String ES_PLUGIN_LISTUPDATE_ID_FIELD = "idField";
  63. public static final String ES_PLUGIN_LISTUPDATE_ID_VALUE = "idValue";
  64. public static final String ES_PLUGIN_LISTUPDATE_FIELD = "field";
  65. public static final String ES_PLUGIN_LISTUPDATE_VALUE = "value";
  66. public static final String WEB_ENFORCED_JVM_ARGS = "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false " +
  67. // jruby is slow with java 8: https://jira.sonarsource.com/browse/SONAR-6115
  68. "-Djruby.compile.invokedynamic=false";
  69. private ProcessProperties() {
  70. // only static stuff
  71. }
  72. public static void completeDefaults(Props props) {
  73. // init string properties
  74. for (Map.Entry<String, String> entry : defaults().entrySet()) {
  75. props.setDefault(entry.getKey(), entry.getValue());
  76. }
  77. // init ports
  78. for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
  79. String key = entry.getKey();
  80. int port = props.valueAsInt(key, -1);
  81. if (port == -1) {
  82. // default port
  83. props.set(key, String.valueOf((int) entry.getValue()));
  84. } else if (port == 0) {
  85. // pick one available port
  86. props.set(key, String.valueOf(NetworkUtils.freePort()));
  87. }
  88. }
  89. }
  90. public static Map<String, String> defaults() {
  91. Map<String, String> defaults = new HashMap<>();
  92. defaults.put(ProcessProperties.CLUSTER_NAME, "sonarqube");
  93. defaults.put(ProcessProperties.CLUSTER_NODE_NAME, "sonar-" + System.currentTimeMillis());
  94. defaults.put(ProcessProperties.SEARCH_HOST, "127.0.0.1");
  95. defaults.put(ProcessProperties.SEARCH_JAVA_OPTS, "-Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true " +
  96. "-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly " +
  97. "-XX:+HeapDumpOnOutOfMemoryError");
  98. defaults.put(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS, "");
  99. defaults.put(ProcessProperties.WEB_JAVA_OPTS, "-Xmx768m -XX:MaxPermSize=160m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true");
  100. defaults.put(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS, "");
  101. defaults.put(ProcessProperties.JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar");
  102. defaults.put(ProcessProperties.JDBC_LOGIN, "sonar");
  103. defaults.put(ProcessProperties.JDBC_PASSWORD, "sonar");
  104. defaults.put(ProcessProperties.JDBC_MAX_ACTIVE, "50");
  105. defaults.put(ProcessProperties.JDBC_MAX_IDLE, "5");
  106. defaults.put(ProcessProperties.JDBC_MIN_IDLE, "2");
  107. defaults.put(ProcessProperties.JDBC_MAX_WAIT, "5000");
  108. defaults.put(ProcessProperties.JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS, "600000");
  109. defaults.put(ProcessProperties.JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS, "30000");
  110. return defaults;
  111. }
  112. private static Map<String, Integer> defaultPorts() {
  113. Map<String, Integer> defaults = new HashMap<>();
  114. defaults.put(ProcessProperties.SEARCH_PORT, 9001);
  115. return defaults;
  116. }
  117. }