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 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program 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. * This program 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.net.InetAddress;
  22. import java.net.UnknownHostException;
  23. import java.util.Arrays;
  24. import java.util.Map;
  25. import java.util.Objects;
  26. import java.util.Properties;
  27. import java.util.UUID;
  28. import java.util.stream.Collectors;
  29. import javax.annotation.Nullable;
  30. /**
  31. * Constants shared by search, web server and app processes.
  32. * They are almost all the properties defined in conf/sonar.properties.
  33. */
  34. public class ProcessProperties {
  35. public enum Property {
  36. JDBC_URL("sonar.jdbc.url"),
  37. JDBC_USERNAME("sonar.jdbc.username", ""),
  38. JDBC_PASSWORD("sonar.jdbc.password", ""),
  39. JDBC_DRIVER_PATH("sonar.jdbc.driverPath"),
  40. JDBC_MAX_ACTIVE("sonar.jdbc.maxActive", "60"),
  41. JDBC_MAX_IDLE("sonar.jdbc.maxIdle", "5"),
  42. JDBC_MIN_IDLE("sonar.jdbc.minIdle", "2"),
  43. JDBC_MAX_WAIT("sonar.jdbc.maxWait", "5000"),
  44. JDBC_MIN_EVICTABLE_IDLE_TIME_MILLIS("sonar.jdbc.minEvictableIdleTimeMillis", "600000"),
  45. JDBC_TIME_BETWEEN_EVICTION_RUNS_MILLIS("sonar.jdbc.timeBetweenEvictionRunsMillis", "30000"),
  46. JDBC_EMBEDDED_PORT("sonar.embeddedDatabase.port"),
  47. PATH_DATA("sonar.path.data", "data"),
  48. PATH_HOME("sonar.path.home"),
  49. PATH_LOGS("sonar.path.logs", "logs"),
  50. PATH_TEMP("sonar.path.temp", "temp"),
  51. PATH_WEB("sonar.path.web", "web"),
  52. SEARCH_HOST("sonar.search.host", InetAddress.getLoopbackAddress().getHostAddress()),
  53. SEARCH_PORT("sonar.search.port", "9001"),
  54. SEARCH_HTTP_PORT("sonar.search.httpPort"),
  55. SEARCH_JAVA_OPTS("sonar.search.javaOpts", "-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError"),
  56. SEARCH_JAVA_ADDITIONAL_OPTS("sonar.search.javaAdditionalOpts", ""),
  57. SEARCH_REPLICAS("sonar.search.replicas"),
  58. SEARCH_MINIMUM_MASTER_NODES("sonar.search.minimumMasterNodes"),
  59. SEARCH_INITIAL_STATE_TIMEOUT("sonar.search.initialStateTimeout"),
  60. WEB_JAVA_OPTS("sonar.web.javaOpts", "-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError"),
  61. WEB_JAVA_ADDITIONAL_OPTS("sonar.web.javaAdditionalOpts", ""),
  62. WEB_PORT("sonar.web.port"),
  63. CE_JAVA_OPTS("sonar.ce.javaOpts", "-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError"),
  64. CE_JAVA_ADDITIONAL_OPTS("sonar.ce.javaAdditionalOpts", ""),
  65. HTTP_PROXY_HOST("http.proxyHost"),
  66. HTTPS_PROXY_HOST("https.proxyHost"),
  67. HTTP_PROXY_PORT("http.proxyPort"),
  68. HTTPS_PROXY_PORT("https.proxyPort"),
  69. HTTP_PROXY_USER("http.proxyUser"),
  70. HTTP_PROXY_PASSWORD("http.proxyPassword"),
  71. HTTP_NON_PROXY_HOSTS("http.nonProxyHosts"),
  72. HTTP_AUTH_NLM_DOMAN("http.auth.ntlm.domain"),
  73. SOCKS_PROXY_HOST("socksProxyHost"),
  74. SOCKS_PROXY_PORT("socksProxyPort"),
  75. CLUSTER_ENABLED("sonar.cluster.enabled", "false"),
  76. CLUSTER_NODE_TYPE("sonar.cluster.node.type"),
  77. CLUSTER_SEARCH_HOSTS("sonar.cluster.search.hosts"),
  78. CLUSTER_HZ_HOSTS("sonar.cluster.hosts"),
  79. CLUSTER_NODE_HZ_PORT("sonar.cluster.node.port", "9003"),
  80. CLUSTER_NODE_HOST("sonar.cluster.node.host"),
  81. CLUSTER_NODE_NAME("sonar.cluster.node.name", "sonarqube-" + UUID.randomUUID().toString()),
  82. CLUSTER_NAME("sonar.cluster.name", "sonarqube"),
  83. CLUSTER_WEB_STARTUP_LEADER("sonar.cluster.web.startupLeader"),
  84. AUTH_JWT_SECRET("sonar.auth.jwtBase64Hs256Secret"),
  85. SONAR_WEB_SSO_ENABLE("sonar.web.sso.enable", "false"),
  86. SONAR_WEB_SSO_LOGIN_HEADER("sonar.web.sso.loginHeader", "X-Forwarded-Login"),
  87. SONAR_WEB_SSO_NAME_HEADER("sonar.web.sso.nameHeader", "X-Forwarded-Name"),
  88. SONAR_WEB_SSO_EMAIL_HEADER("sonar.web.sso.emailHeader", "X-Forwarded-Email"),
  89. SONAR_WEB_SSO_GROUPS_HEADER("sonar.web.sso.groupsHeader", "X-Forwarded-Groups"),
  90. SONAR_WEB_SSO_REFRESH_INTERVAL_IN_MINUTES("sonar.web.sso.refreshIntervalInMinutes", "5"),
  91. SONAR_SECURITY_REALM("sonar.security.realm"),
  92. SONAR_AUTHENTICATOR_IGNORE_STARTUP_FAILURE("sonar.authenticator.ignoreStartupFailure", "false"),
  93. SONAR_TELEMETRY_ENABLE("sonar.telemetry.enable", "true"),
  94. SONAR_TELEMETRY_URL("sonar.telemetry.url", "https://telemetry.sonarsource.com/sonarqube"),
  95. SONAR_TELEMETRY_FREQUENCY_IN_SECONDS("sonar.telemetry.frequencyInSeconds", "21600"),
  96. SONAR_UPDATECENTER_ACTIVATE("sonar.updatecenter.activate", "true"),
  97. SONARCLOUD_ENABLED("sonar.sonarcloud.enabled", "false"),
  98. SONARCLOUD_HOMEPAGE_URL("sonar.homepage.url", ""),
  99. SONAR_PRISMIC_ACCESS_TOKEN("sonar.prismic.accessToken", ""),
  100. SONAR_ANALYTICS_GA_TRACKING_ID("sonar.analytics.ga.trackingId", ""),
  101. SONAR_ANALYTICS_GTM_TRACKING_ID("sonar.analytics.gtm.trackingId", ""),
  102. ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS("sonar.onboardingTutorial.showToNewUsers", "true"),
  103. BITBUCKETCLOUD_APP_KEY("sonar.bitbucketcloud.appKey", "sonarcloud"),
  104. BITBUCKETCLOUD_ENDPOINT("sonar.bitbucketcloud.endpoint", "https://api.bitbucket.org"),
  105. /**
  106. * Used by Orchestrator to ask for shutdown of monitor process
  107. */
  108. ENABLE_STOP_COMMAND("sonar.enableStopCommand"),
  109. // whether the blue/green deployment of server is enabled
  110. BLUE_GREEN_ENABLED("sonar.blueGreenEnabled", "false");
  111. private final String key;
  112. private final String defaultValue;
  113. Property(String key, @Nullable String defaultValue) {
  114. this.key = key;
  115. this.defaultValue = defaultValue;
  116. }
  117. Property(String key) {
  118. this(key, null);
  119. }
  120. public String getKey() {
  121. return key;
  122. }
  123. public String getDefaultValue() {
  124. Objects.requireNonNull(defaultValue, "There's no default value on this property");
  125. return defaultValue;
  126. }
  127. public boolean hasDefaultValue() {
  128. return defaultValue != null;
  129. }
  130. }
  131. private ProcessProperties() {
  132. // only static stuff
  133. }
  134. public static void completeDefaults(Props props) {
  135. // init string properties
  136. for (Map.Entry<Object, Object> entry : defaults().entrySet()) {
  137. props.setDefault(entry.getKey().toString(), entry.getValue().toString());
  138. }
  139. fixPortIfZero(props, Property.SEARCH_HOST.getKey(), Property.SEARCH_PORT.getKey());
  140. }
  141. public static Properties defaults() {
  142. Properties defaults = new Properties();
  143. defaults.putAll(Arrays.stream(Property.values())
  144. .filter(Property::hasDefaultValue)
  145. .collect(Collectors.toMap(Property::getKey, Property::getDefaultValue)));
  146. return defaults;
  147. }
  148. private static void fixPortIfZero(Props props, String addressPropertyKey, String portPropertyKey) {
  149. String port = props.value(portPropertyKey);
  150. if ("0".equals(port)) {
  151. String address = props.nonNullValue(addressPropertyKey);
  152. try {
  153. props.set(portPropertyKey, String.valueOf(NetworkUtilsImpl.INSTANCE.getNextAvailablePort(InetAddress.getByName(address))));
  154. } catch (UnknownHostException e) {
  155. throw new IllegalStateException("Cannot resolve address [" + address + "] set by property [" + addressPropertyKey + "]", e);
  156. }
  157. }
  158. }
  159. }