diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-02-01 13:36:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 13:36:29 +0100 |
commit | e737a37b28a2504aa1a6387606841afd776f2fef (patch) | |
tree | 2ffc650ac5c2e4d3f22621a837db9e8304f1a04b /server/sonar-main | |
parent | 39f671dce022e19460606d9639f3727493a1faf2 (diff) | |
download | sonarqube-e737a37b28a2504aa1a6387606841afd776f2fef.tar.gz sonarqube-e737a37b28a2504aa1a6387606841afd776f2fef.zip |
SONAR-10300 Forbid system properties in api/settings
Diffstat (limited to 'server/sonar-main')
25 files changed, 450 insertions, 410 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppFileSystem.java b/server/sonar-main/src/main/java/org/sonar/application/AppFileSystem.java index 88cdd621c98..c2e01311f13 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppFileSystem.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppFileSystem.java @@ -38,10 +38,10 @@ import static java.lang.String.format; import static java.nio.file.FileVisitResult.CONTINUE; import static org.apache.commons.io.FileUtils.forceMkdir; import static org.sonar.process.FileUtils2.deleteDirectory; -import static org.sonar.process.ProcessProperties.PATH_DATA; -import static org.sonar.process.ProcessProperties.PATH_LOGS; -import static org.sonar.process.ProcessProperties.PATH_TEMP; -import static org.sonar.process.ProcessProperties.PATH_WEB; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; public class AppFileSystem implements FileSystem { @@ -56,10 +56,10 @@ public class AppFileSystem implements FileSystem { @Override public void reset() throws IOException { - createDirectory(PATH_DATA); - createDirectory(PATH_WEB); - createDirectory(PATH_LOGS); - File tempDir = createOrCleanTempDirectory(PATH_TEMP); + createDirectory(PATH_DATA.getKey()); + createDirectory(PATH_WEB.getKey()); + createDirectory(PATH_LOGS.getKey()); + File tempDir = createOrCleanTempDirectory(PATH_TEMP.getKey()); try (AllProcessesCommands allProcessesCommands = new AllProcessesCommands(tempDir)) { allProcessesCommands.clean(); } @@ -67,7 +67,7 @@ public class AppFileSystem implements FileSystem { @Override public File getTempDir() { - return settings.getProps().nonNullValueAsFile(PATH_TEMP); + return settings.getProps().nonNullValueAsFile(PATH_TEMP.getKey()); } private boolean createDirectory(String propKey) throws IOException { diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java b/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java index e1dd8694cf5..0b87be95c1c 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppReloaderImpl.java @@ -28,11 +28,11 @@ import org.sonar.process.MessageException; import org.sonar.process.Props; import static java.lang.String.format; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.PATH_DATA; -import static org.sonar.process.ProcessProperties.PATH_LOGS; -import static org.sonar.process.ProcessProperties.PATH_TEMP; -import static org.sonar.process.ProcessProperties.PATH_WEB; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; public class AppReloaderImpl implements AppReloader { @@ -63,11 +63,11 @@ public class AppReloaderImpl implements AppReloader { } private static void ensureUnchangedConfiguration(Props oldProps, Props newProps) { - verifyUnchanged(oldProps, newProps, PATH_DATA); - verifyUnchanged(oldProps, newProps, PATH_WEB); - verifyUnchanged(oldProps, newProps, PATH_LOGS); - verifyUnchanged(oldProps, newProps, PATH_TEMP); - verifyUnchanged(oldProps, newProps, CLUSTER_ENABLED); + verifyUnchanged(oldProps, newProps, PATH_DATA.getKey()); + verifyUnchanged(oldProps, newProps, PATH_WEB.getKey()); + verifyUnchanged(oldProps, newProps, PATH_LOGS.getKey()); + verifyUnchanged(oldProps, newProps, PATH_TEMP.getKey()); + verifyUnchanged(oldProps, newProps, CLUSTER_ENABLED.getKey()); } private static void verifyUnchanged(Props initialProps, Props newProps, String propKey) { diff --git a/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java b/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java index fa8b2f8dc53..45a5891d3a8 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java +++ b/server/sonar-main/src/main/java/org/sonar/application/AppStateFactory.java @@ -23,13 +23,17 @@ import org.sonar.application.cluster.ClusterAppStateImpl; import org.sonar.application.config.AppSettings; import org.sonar.application.config.ClusterSettings; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.cluster.NodeType; import org.sonar.process.cluster.hz.HazelcastMember; import org.sonar.process.cluster.hz.HazelcastMemberBuilder; import static java.util.Arrays.asList; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; public class AppStateFactory { @@ -49,11 +53,11 @@ public class AppStateFactory { private static HazelcastMember createHzMember(Props props) { HazelcastMemberBuilder builder = new HazelcastMemberBuilder() - .setNetworkInterface(props.nonNullValue(ProcessProperties.CLUSTER_NODE_HOST)) - .setMembers(asList(props.nonNullValue(ProcessProperties.CLUSTER_HOSTS).split(","))) - .setNodeType(NodeType.parse(props.nonNullValue(ProcessProperties.CLUSTER_NODE_TYPE))) - .setNodeName(props.nonNullValue(ProcessProperties.CLUSTER_NODE_NAME)) - .setPort(Integer.parseInt(props.nonNullValue(ProcessProperties.CLUSTER_NODE_PORT))) + .setNetworkInterface(props.nonNullValue(CLUSTER_NODE_HOST.getKey())) + .setMembers(asList(props.nonNullValue(CLUSTER_HOSTS.getKey()).split(","))) + .setNodeType(NodeType.parse(props.nonNullValue(CLUSTER_NODE_TYPE.getKey()))) + .setNodeName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) + .setPort(Integer.parseInt(props.nonNullValue(CLUSTER_NODE_PORT.getKey()))) .setProcessId(ProcessId.APP); return builder.build(); } diff --git a/server/sonar-main/src/main/java/org/sonar/application/cluster/health/SearchNodeHealthProvider.java b/server/sonar-main/src/main/java/org/sonar/application/cluster/health/SearchNodeHealthProvider.java index 5dc73b9841a..56a84cff1f9 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/cluster/health/SearchNodeHealthProvider.java +++ b/server/sonar-main/src/main/java/org/sonar/application/cluster/health/SearchNodeHealthProvider.java @@ -27,9 +27,9 @@ import org.sonar.process.cluster.health.NodeDetails; import org.sonar.process.cluster.health.NodeHealth; import org.sonar.process.cluster.health.NodeHealthProvider; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_PORT; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; public class SearchNodeHealthProvider implements NodeHealthProvider { @@ -44,15 +44,15 @@ public class SearchNodeHealthProvider implements NodeHealthProvider { this.clusterAppState = clusterAppState; this.nodeDetails = NodeDetails.newNodeDetailsBuilder() .setType(NodeDetails.Type.SEARCH) - .setName(props.nonNullValue(CLUSTER_NODE_NAME)) + .setName(props.nonNullValue(CLUSTER_NODE_NAME.getKey())) .setHost(getHost(props, networkUtils)) - .setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_PORT))) + .setPort(Integer.valueOf(props.nonNullValue(CLUSTER_NODE_PORT.getKey()))) .setStartedAt(clock.now()) .build(); } private static String getHost(Props props, NetworkUtils networkUtils) { - String host = props.value(CLUSTER_NODE_HOST); + String host = props.value(CLUSTER_NODE_HOST.getKey()); if (host != null && !host.isEmpty()) { return host; } diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java index d90a958e503..7c4c8c1b340 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java @@ -28,14 +28,26 @@ import org.sonar.application.es.EsLogging; import org.sonar.application.es.EsSettings; import org.sonar.application.es.EsYmlSettings; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.System2; -import static org.sonar.process.ProcessProperties.HTTPS_PROXY_HOST; -import static org.sonar.process.ProcessProperties.HTTPS_PROXY_PORT; -import static org.sonar.process.ProcessProperties.HTTP_PROXY_HOST; -import static org.sonar.process.ProcessProperties.HTTP_PROXY_PORT; +import static org.sonar.process.ProcessProperties.Property.CE_JAVA_ADDITIONAL_OPTS; +import static org.sonar.process.ProcessProperties.Property.CE_JAVA_OPTS; +import static org.sonar.process.ProcessProperties.Property.HTTPS_PROXY_HOST; +import static org.sonar.process.ProcessProperties.Property.HTTPS_PROXY_PORT; +import static org.sonar.process.ProcessProperties.Property.HTTP_AUTH_NLM_DOMAN; +import static org.sonar.process.ProcessProperties.Property.HTTP_NON_PROXY_HOSTS; +import static org.sonar.process.ProcessProperties.Property.HTTP_PROXY_HOST; +import static org.sonar.process.ProcessProperties.Property.HTTP_PROXY_PORT; +import static org.sonar.process.ProcessProperties.Property.JDBC_DRIVER_PATH; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_ADDITIONAL_OPTS; +import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_OPTS; +import static org.sonar.process.ProcessProperties.Property.SOCKS_PROXY_HOST; +import static org.sonar.process.ProcessProperties.Property.SOCKS_PROXY_PORT; +import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_ADDITIONAL_OPTS; +import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_OPTS; public class CommandFactoryImpl implements CommandFactory { private static final String ENV_VAR_JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS"; @@ -43,14 +55,14 @@ public class CommandFactoryImpl implements CommandFactory { * Properties about proxy that must be set as system properties */ private static final String[] PROXY_PROPERTY_KEYS = new String[] { - HTTP_PROXY_HOST, - HTTP_PROXY_PORT, - "http.nonProxyHosts", - HTTPS_PROXY_HOST, - HTTPS_PROXY_PORT, - "http.auth.ntlm.domain", - "socksProxyHost", - "socksProxyPort"}; + HTTP_PROXY_HOST.getKey(), + HTTP_PROXY_PORT.getKey(), + HTTP_NON_PROXY_HOSTS.getKey(), + HTTPS_PROXY_HOST.getKey(), + HTTPS_PROXY_PORT.getKey(), + HTTP_AUTH_NLM_DOMAN.getKey(), + SOCKS_PROXY_HOST.getKey(), + SOCKS_PROXY_PORT.getKey()}; private final Props props; private final File tempDir; @@ -93,11 +105,10 @@ public class CommandFactoryImpl implements CommandFactory { .setReadsArgumentsFromFile(false) .setArgument("path.conf", esInstallation.getConfDirectory().getAbsolutePath()) .setJvmOptions(new EsJvmOptions() - .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_OPTS) - .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS) + .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) + .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()) .add("-Delasticsearch") - .add("-Des.path.home=" + esInstallation.getHomeDirectory()) - ) + .add("-Des.path.home=" + esInstallation.getHomeDirectory())) .setEnvVariable("ES_JVM_OPTIONS", esInstallation.getJvmOptions().getAbsolutePath()) .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home")) .setClassName("org.elasticsearch.bootstrap.Elasticsearch") @@ -115,8 +126,8 @@ public class CommandFactoryImpl implements CommandFactory { esInstallation .setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory())) .setEsJvmOptions(new EsJvmOptions() - .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_OPTS) - .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS)) + .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) + .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())) .setEsYmlSettings(new EsYmlSettings(settingsMap)) .setClusterName(settingsMap.get("cluster.name")) .setHost(settingsMap.get("network.host")) @@ -126,11 +137,11 @@ public class CommandFactoryImpl implements CommandFactory { @Override public JavaCommand createWebCommand(boolean leader) { - File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); WebJvmOptions jvmOptions = new WebJvmOptions(tempDir) - .addFromMandatoryProperty(props, ProcessProperties.WEB_JAVA_OPTS) - .addFromMandatoryProperty(props, ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS); + .addFromMandatoryProperty(props, WEB_JAVA_OPTS.getKey()) + .addFromMandatoryProperty(props, WEB_JAVA_ADDITIONAL_OPTS.getKey()); addProxyJvmOptions(jvmOptions); JavaCommand<WebJvmOptions> command = new JavaCommand<WebJvmOptions>(ProcessId.WEB_SERVER, homeDir) @@ -138,12 +149,12 @@ public class CommandFactoryImpl implements CommandFactory { .setArguments(props.rawProperties()) .setJvmOptions(jvmOptions) // required for logback tomcat valve - .setEnvVariable(ProcessProperties.PATH_LOGS, props.nonNullValue(ProcessProperties.PATH_LOGS)) + .setEnvVariable(PATH_LOGS.getKey(), props.nonNullValue(PATH_LOGS.getKey())) .setArgument("sonar.cluster.web.startupLeader", Boolean.toString(leader)) .setClassName("org.sonar.server.app.WebServer") .addClasspath("./lib/common/*") .addClasspath("./lib/server/*"); - String driverPath = props.value(ProcessProperties.JDBC_DRIVER_PATH); + String driverPath = props.value(JDBC_DRIVER_PATH.getKey()); if (driverPath != null) { command.addClasspath(driverPath); } @@ -153,11 +164,11 @@ public class CommandFactoryImpl implements CommandFactory { @Override public JavaCommand createCeCommand() { - File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); CeJvmOptions jvmOptions = new CeJvmOptions(tempDir) - .addFromMandatoryProperty(props, ProcessProperties.CE_JAVA_OPTS) - .addFromMandatoryProperty(props, ProcessProperties.CE_JAVA_ADDITIONAL_OPTS); + .addFromMandatoryProperty(props, CE_JAVA_OPTS.getKey()) + .addFromMandatoryProperty(props, CE_JAVA_ADDITIONAL_OPTS.getKey()); addProxyJvmOptions(jvmOptions); JavaCommand<CeJvmOptions> command = new JavaCommand<CeJvmOptions>(ProcessId.COMPUTE_ENGINE, homeDir) @@ -168,7 +179,7 @@ public class CommandFactoryImpl implements CommandFactory { .addClasspath("./lib/common/*") .addClasspath("./lib/server/*") .addClasspath("./lib/ce/*"); - String driverPath = props.value(ProcessProperties.JDBC_DRIVER_PATH); + String driverPath = props.value(JDBC_DRIVER_PATH.getKey()); if (driverPath != null) { command.addClasspath(driverPath); } @@ -182,8 +193,8 @@ public class CommandFactoryImpl implements CommandFactory { } // defaults of HTTPS are the same than HTTP defaults - setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_HOST, HTTP_PROXY_HOST); - setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_PORT, HTTP_PROXY_PORT); + setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_HOST.getKey(), HTTP_PROXY_HOST.getKey()); + setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_PORT.getKey(), HTTP_PROXY_PORT.getKey()); } private void setSystemPropertyToDefaultIfNotSet(JvmOptions jvmOptions, diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java b/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java index 753adb3f557..e6d5fe010e1 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java @@ -31,10 +31,11 @@ import java.util.function.Consumer; import org.slf4j.LoggerFactory; import org.sonar.process.ConfigurationUtils; import org.sonar.process.NetworkUtilsImpl; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.sonar.process.ProcessProperties.completeDefaults; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; public class AppSettingsLoaderImpl implements AppSettingsLoader { @@ -61,14 +62,14 @@ public class AppSettingsLoaderImpl implements AppSettingsLoader { public AppSettings load() { Properties p = loadPropertiesFile(homeDir); p.putAll(CommandLineParser.parseArguments(cliArguments)); - p.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); + p.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath()); p = ConfigurationUtils.interpolateVariables(p, System.getenv()); // the difference between Properties and Props is that the latter // supports decryption of values, so it must be used when values // are accessed Props props = new Props(p); - ProcessProperties.completeDefaults(props); + completeDefaults(props); Arrays.stream(consumers).forEach(c -> c.accept(props)); return new AppSettingsImpl(props); diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index 4b7aaff0311..62bb6158381 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -38,15 +38,15 @@ import static java.util.Arrays.stream; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.joining; import static org.apache.commons.lang.StringUtils.isBlank; -import static org.sonar.process.ProcessProperties.AUTH_JWT_SECRET; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_WEB_STARTUP_LEADER; -import static org.sonar.process.ProcessProperties.JDBC_URL; -import static org.sonar.process.ProcessProperties.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.AUTH_JWT_SECRET; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_WEB_STARTUP_LEADER; +import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; public class ClusterSettings implements Consumer<Props> { @@ -65,33 +65,33 @@ public class ClusterSettings implements Consumer<Props> { private void checkClusterProperties(Props props) { // for internal use - if (props.value(CLUSTER_WEB_STARTUP_LEADER) != null) { - throw new MessageException(format("Property [%s] is forbidden", CLUSTER_WEB_STARTUP_LEADER)); + if (props.value(CLUSTER_WEB_STARTUP_LEADER.getKey()) != null) { + throw new MessageException(format("Property [%s] is forbidden", CLUSTER_WEB_STARTUP_LEADER.getKey())); } NodeType nodeType = toNodeType(props); switch (nodeType) { case APPLICATION: ensureNotH2(props); - requireValue(props, AUTH_JWT_SECRET); + requireValue(props, AUTH_JWT_SECRET.getKey()); break; case SEARCH: - requireValue(props, SEARCH_HOST); - ensureLocalButNotLoopbackAddress(props, SEARCH_HOST); + requireValue(props, SEARCH_HOST.getKey()); + ensureLocalButNotLoopbackAddress(props, SEARCH_HOST.getKey()); break; default: throw new UnsupportedOperationException("Unknown value: " + nodeType); } - ensureNotLoopbackAddresses(props, CLUSTER_HOSTS); - requireValue(props, CLUSTER_NODE_HOST); - ensureLocalButNotLoopbackAddress(props, CLUSTER_NODE_HOST); - ensureNotLoopbackAddresses(props, CLUSTER_SEARCH_HOSTS); + ensureNotLoopbackAddresses(props, CLUSTER_HOSTS.getKey()); + requireValue(props, CLUSTER_NODE_HOST.getKey()); + ensureLocalButNotLoopbackAddress(props, CLUSTER_NODE_HOST.getKey()); + ensureNotLoopbackAddresses(props, CLUSTER_SEARCH_HOSTS.getKey()); } private static NodeType toNodeType(Props props) { - String nodeTypeValue = requireValue(props, CLUSTER_NODE_TYPE); + String nodeTypeValue = requireValue(props, CLUSTER_NODE_TYPE.getKey()); if (!NodeType.isValid(nodeTypeValue)) { - throw new MessageException(format("Invalid value for property %s: [%s], only [%s] are allowed", CLUSTER_NODE_TYPE, nodeTypeValue, + throw new MessageException(format("Invalid value for property %s: [%s], only [%s] are allowed", CLUSTER_NODE_TYPE.getKey(), nodeTypeValue, Arrays.stream(NodeType.values()).map(NodeType::getValue).collect(joining(", ")))); } return NodeType.parse(nodeTypeValue); @@ -106,7 +106,7 @@ public class ClusterSettings implements Consumer<Props> { } private static void ensureNotH2(Props props) { - String jdbcUrl = props.value(JDBC_URL); + String jdbcUrl = props.value(JDBC_URL.getKey()); if (isBlank(jdbcUrl) || jdbcUrl.startsWith("jdbc:h2:")) { throw new MessageException("Embedded database is not supported in cluster mode"); } @@ -145,14 +145,14 @@ public class ClusterSettings implements Consumer<Props> { } private static boolean isClusterEnabled(Props props) { - return props.valueAsBoolean(CLUSTER_ENABLED); + return props.valueAsBoolean(CLUSTER_ENABLED.getKey()); } public static List<ProcessId> getEnabledProcesses(AppSettings settings) { if (!isClusterEnabled(settings)) { return asList(ProcessId.ELASTICSEARCH, ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); } - NodeType nodeType = NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE).orElse("")); + NodeType nodeType = NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE.getKey()).orElse("")); switch (nodeType) { case APPLICATION: return asList(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); @@ -166,7 +166,7 @@ public class ClusterSettings implements Consumer<Props> { public static boolean isLocalElasticsearchEnabled(AppSettings settings) { // elasticsearch is enabled on "search" nodes, but disabled on "application" nodes if (isClusterEnabled(settings.getProps())) { - return NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE).orElse("")) == NodeType.SEARCH; + return NodeType.parse(settings.getValue(CLUSTER_NODE_TYPE.getKey()).orElse("")) == NodeType.SEARCH; } // elasticsearch is enabled in standalone mode diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/FileSystemSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/FileSystemSettings.java index eae480b4412..67ef482ebfb 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/FileSystemSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/FileSystemSettings.java @@ -25,11 +25,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.process.Props; -import static org.sonar.process.ProcessProperties.PATH_DATA; -import static org.sonar.process.ProcessProperties.PATH_HOME; -import static org.sonar.process.ProcessProperties.PATH_LOGS; -import static org.sonar.process.ProcessProperties.PATH_TEMP; -import static org.sonar.process.ProcessProperties.PATH_WEB; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; public class FileSystemSettings implements Consumer<Props> { @@ -37,10 +37,10 @@ public class FileSystemSettings implements Consumer<Props> { @Override public void accept(Props props) { - ensurePropertyIsAbsolutePath(props, PATH_DATA); - ensurePropertyIsAbsolutePath(props, PATH_WEB); - ensurePropertyIsAbsolutePath(props, PATH_LOGS); - ensurePropertyIsAbsolutePath(props, PATH_TEMP); + ensurePropertyIsAbsolutePath(props, PATH_DATA.getKey()); + ensurePropertyIsAbsolutePath(props, PATH_WEB.getKey()); + ensurePropertyIsAbsolutePath(props, PATH_LOGS.getKey()); + ensurePropertyIsAbsolutePath(props, PATH_TEMP.getKey()); } private static File ensurePropertyIsAbsolutePath(Props props, String propKey) { @@ -48,7 +48,7 @@ public class FileSystemSettings implements Consumer<Props> { String path = props.nonNullValue(propKey); File d = new File(path); if (!d.isAbsolute()) { - File homeDir = props.nonNullValueAsFile(PATH_HOME); + File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); d = new File(homeDir, path); LOG.trace("Overriding property {} from relative path '{}' to absolute path '{}'", propKey, path, d.getAbsolutePath()); props.set(propKey, d.getAbsolutePath()); diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java index 933098b95f4..6645fdf2e88 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java @@ -32,14 +32,15 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.process.MessageException; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static java.lang.String.format; import static org.apache.commons.lang.StringUtils.isEmpty; import static org.apache.commons.lang.StringUtils.isNotEmpty; -import static org.sonar.process.ProcessProperties.JDBC_EMBEDDED_PORT; -import static org.sonar.process.ProcessProperties.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.JDBC_DRIVER_PATH; +import static org.sonar.process.ProcessProperties.Property.JDBC_EMBEDDED_PORT; +import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; public class JdbcSettings implements Consumer<Props> { @@ -58,12 +59,12 @@ public class JdbcSettings implements Consumer<Props> { @Override public void accept(Props props) { - File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); Provider provider = resolveProviderAndEnforceNonnullJdbcUrl(props); - String url = props.value(JDBC_URL); + String url = props.value(JDBC_URL.getKey()); checkUrlParameters(provider, url); String driverPath = driverPath(homeDir, provider); - props.set(ProcessProperties.JDBC_DRIVER_PATH, driverPath); + props.set(JDBC_DRIVER_PATH.getKey(), driverPath); } String driverPath(File homeDir, Provider provider) { @@ -83,19 +84,19 @@ public class JdbcSettings implements Consumer<Props> { } Provider resolveProviderAndEnforceNonnullJdbcUrl(Props props) { - String url = props.value(JDBC_URL); - Integer embeddedDatabasePort = props.valueAsInt(JDBC_EMBEDDED_PORT); + String url = props.value(JDBC_URL.getKey()); + Integer embeddedDatabasePort = props.valueAsInt(JDBC_EMBEDDED_PORT.getKey()); if (embeddedDatabasePort != null) { String correctUrl = buildH2JdbcUrl(embeddedDatabasePort); warnIfUrlIsSet(embeddedDatabasePort, url, correctUrl); - props.set(JDBC_URL, correctUrl); + props.set(JDBC_URL.getKey(), correctUrl); return Provider.H2; } if (isEmpty(url)) { - props.set(JDBC_URL, buildH2JdbcUrl(JDBC_EMBEDDED_PORT_DEFAULT_VALUE)); - props.set(JDBC_EMBEDDED_PORT, String.valueOf(JDBC_EMBEDDED_PORT_DEFAULT_VALUE)); + props.set(JDBC_URL.getKey(), buildH2JdbcUrl(JDBC_EMBEDDED_PORT_DEFAULT_VALUE)); + props.set(JDBC_EMBEDDED_PORT.getKey(), String.valueOf(JDBC_EMBEDDED_PORT_DEFAULT_VALUE)); return Provider.H2; } diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java index e7c2bc8bbb4..ee570c3630c 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsInstallation.java @@ -24,9 +24,13 @@ import java.util.Collections; import java.util.List; import java.util.Properties; import org.sonar.application.command.EsJvmOptions; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; + /** * Holds {@link File} to the various directories of ElasticSearch distribution embedded in SonarQube and provides * {@link File} objects to the various files of it SonarQube cares about. @@ -49,7 +53,7 @@ public class EsInstallation { private int port; public EsInstallation(Props props) { - File sqHomeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + File sqHomeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); this.homeDirectory = new File(sqHomeDir, "elasticsearch"); this.outdatedSearchDirectories = buildOutdatedSearchDirs(props); @@ -59,21 +63,21 @@ public class EsInstallation { } private static List<File> buildOutdatedSearchDirs(Props props) { - String dataPath = props.nonNullValue(ProcessProperties.PATH_DATA); + String dataPath = props.nonNullValue(PATH_DATA.getKey()); return Collections.singletonList(new File(dataPath, "es")); } private static File buildDataDir(Props props) { - String dataPath = props.nonNullValue(ProcessProperties.PATH_DATA); + String dataPath = props.nonNullValue(PATH_DATA.getKey()); return new File(dataPath, "es5"); } private static File buildLogPath(Props props) { - return props.nonNullValueAsFile(ProcessProperties.PATH_LOGS); + return props.nonNullValueAsFile(PATH_LOGS.getKey()); } private static File buildConfDir(Props props) { - File tempPath = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP); + File tempPath = props.nonNullValueAsFile(PATH_TEMP.getKey()); return new File(new File(tempPath, "conf"), "es"); } diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java index d4ea835e149..b4231f3f75f 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java @@ -26,15 +26,19 @@ import java.util.Map; import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.System2; import static java.lang.String.valueOf; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HTTP_PORT; +import static org.sonar.process.ProcessProperties.Property.SEARCH_INITIAL_STATE_TIMEOUT; +import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES; +import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; public class EsSettings { @@ -52,10 +56,10 @@ public class EsSettings { this.props = props; this.fileSystem = fileSystem; - this.clusterName = props.nonNullValue(CLUSTER_NAME); - this.clusterEnabled = props.valueAsBoolean(CLUSTER_ENABLED); + this.clusterName = props.nonNullValue(CLUSTER_NAME.getKey()); + this.clusterEnabled = props.valueAsBoolean(CLUSTER_ENABLED.getKey()); if (this.clusterEnabled) { - this.nodeName = props.value(CLUSTER_NODE_NAME, "sonarqube-" + UUID.randomUUID().toString()); + this.nodeName = props.value(CLUSTER_NODE_NAME.getKey(), "sonarqube-" + UUID.randomUUID().toString()); } else { this.nodeName = STANDALONE_NODE_NAME; } @@ -83,7 +87,7 @@ public class EsSettings { private void configureNetwork(Map<String, String> builder) { InetAddress host = readHost(); - int port = Integer.parseInt(props.nonNullValue(ProcessProperties.SEARCH_PORT)); + int port = Integer.parseInt(props.nonNullValue(SEARCH_PORT.getKey())); LOGGER.info("Elasticsearch listening on {}:{}", host, port); builder.put("transport.tcp.port", valueOf(port)); @@ -93,7 +97,7 @@ public class EsSettings { // Elasticsearch sets the default value of TCP reuse address to true only on non-MSWindows machines, but why ? builder.put("network.tcp.reuse_address", valueOf(true)); - int httpPort = props.valueAsInt(ProcessProperties.SEARCH_HTTP_PORT, -1); + int httpPort = props.valueAsInt(SEARCH_HTTP_PORT.getKey(), -1); if (httpPort < 0) { // standard configuration builder.put("http.enabled", valueOf(false)); @@ -109,11 +113,11 @@ public class EsSettings { } private InetAddress readHost() { - String hostProperty = props.nonNullValue(ProcessProperties.SEARCH_HOST); + String hostProperty = props.nonNullValue(SEARCH_HOST.getKey()); 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); + throw new IllegalStateException("Can not resolve host [" + hostProperty + "]. Please check network settings and property " + SEARCH_HOST.getKey(), e); } } @@ -124,10 +128,10 @@ public class EsSettings { String initialStateTimeOut = "30s"; if (clusterEnabled) { - minimumMasterNodes = props.valueAsInt(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, 2); - initialStateTimeOut = props.value(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "120s"); + minimumMasterNodes = props.valueAsInt(SEARCH_MINIMUM_MASTER_NODES.getKey(), 2); + initialStateTimeOut = props.value(SEARCH_INITIAL_STATE_TIMEOUT.getKey(), "120s"); - String hosts = props.value(CLUSTER_SEARCH_HOSTS, ""); + String hosts = props.value(CLUSTER_SEARCH_HOSTS.getKey(), ""); LOGGER.info("Elasticsearch cluster enabled. Connect to hosts [{}]", hosts); builder.put("discovery.zen.ping.unicast.hosts", hosts); } diff --git a/server/sonar-main/src/main/java/org/sonar/application/process/StopRequestWatcherImpl.java b/server/sonar-main/src/main/java/org/sonar/application/process/StopRequestWatcherImpl.java index 273ffd71b71..6ca35b669d9 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/process/StopRequestWatcherImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/process/StopRequestWatcherImpl.java @@ -22,10 +22,11 @@ package org.sonar.application.process; import org.sonar.application.FileSystem; import org.sonar.application.Scheduler; import org.sonar.application.config.AppSettings; +import org.sonar.process.ProcessId; import org.sonar.process.sharedmemoryfile.DefaultProcessCommands; import org.sonar.process.sharedmemoryfile.ProcessCommands; -import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; + +import static org.sonar.process.ProcessProperties.Property.ENABLE_STOP_COMMAND; public class StopRequestWatcherImpl extends Thread implements StopRequestWatcher { @@ -78,7 +79,7 @@ public class StopRequestWatcherImpl extends Thread implements StopRequestWatcher @Override public void startWatching() { - if (settings.getProps().valueAsBoolean(ProcessProperties.ENABLE_STOP_COMMAND)) { + if (settings.getProps().valueAsBoolean(ENABLE_STOP_COMMAND.getKey())) { start(); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppFileSystemTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppFileSystemTest.java index 8e35998d349..5aa864b28c4 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppFileSystemTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppFileSystemTest.java @@ -34,9 +34,13 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.application.config.TestAppSettings; import org.sonar.process.sharedmemoryfile.AllProcessesCommands; -import org.sonar.process.ProcessProperties; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; import static org.sonar.process.sharedmemoryfile.ProcessCommands.MAX_PROCESSES; public class AppFileSystemTest { @@ -62,11 +66,11 @@ public class AppFileSystemTest { logsDir = new File(homeDir, "logs"); webDir = new File(homeDir, "web"); - settings.getProps().set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - settings.getProps().set(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath()); - settings.getProps().set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - settings.getProps().set(ProcessProperties.PATH_LOGS, logsDir.getAbsolutePath()); - settings.getProps().set(ProcessProperties.PATH_WEB, webDir.getAbsolutePath()); + settings.getProps().set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + settings.getProps().set(PATH_DATA.getKey(), dataDir.getAbsolutePath()); + settings.getProps().set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + settings.getProps().set(PATH_LOGS.getKey(), logsDir.getAbsolutePath()); + settings.getProps().set(PATH_WEB.getKey(), webDir.getAbsolutePath()); } @Test @@ -152,22 +156,22 @@ public class AppFileSystemTest { @Test public void reset_throws_ISE_if_data_dir_is_a_file() throws Exception { - resetThrowsISEIfDirIsAFile(ProcessProperties.PATH_DATA); + resetThrowsISEIfDirIsAFile(PATH_DATA.getKey()); } @Test public void reset_throws_ISE_if_web_dir_is_a_file() throws Exception { - resetThrowsISEIfDirIsAFile(ProcessProperties.PATH_WEB); + resetThrowsISEIfDirIsAFile(PATH_WEB.getKey()); } @Test public void reset_throws_ISE_if_logs_dir_is_a_file() throws Exception { - resetThrowsISEIfDirIsAFile(ProcessProperties.PATH_LOGS); + resetThrowsISEIfDirIsAFile(PATH_LOGS.getKey()); } @Test public void reset_throws_ISE_if_temp_dir_is_a_file() throws Exception { - resetThrowsISEIfDirIsAFile(ProcessProperties.PATH_TEMP); + resetThrowsISEIfDirIsAFile(PATH_TEMP.getKey()); } private void resetThrowsISEIfDirIsAFile(String property) throws IOException { diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java index 537e970e35d..72f612c89b7 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java @@ -31,7 +31,6 @@ import ch.qos.logback.core.encoder.Encoder; import ch.qos.logback.core.joran.spi.ConsoleTarget; import ch.qos.logback.core.rolling.RollingFileAppender; import java.io.File; -import java.io.IOException; import java.util.Iterator; import org.junit.AfterClass; import org.junit.Before; @@ -42,13 +41,13 @@ import org.junit.rules.TemporaryFolder; import org.slf4j.LoggerFactory; import org.sonar.application.config.AppSettings; import org.sonar.application.config.TestAppSettings; -import org.sonar.process.ProcessProperties; import org.sonar.process.logging.LogbackHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.slf4j.Logger.ROOT_LOGGER_NAME; import static org.sonar.application.process.StreamGobbler.LOGGER_GOBBLER; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; public class AppLoggingTest { @@ -65,7 +64,7 @@ public class AppLoggingTest { @Before public void setUp() throws Exception { logDir = temp.newFolder(); - settings.getProps().set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath()); + settings.getProps().set(PATH_LOGS.getKey(), logDir.getAbsolutePath()); } @AfterClass @@ -249,7 +248,7 @@ public class AppLoggingTest { @Test public void no_info_log_from_hazelcast() { - settings.getProps().set(CLUSTER_ENABLED, "true"); + settings.getProps().set(CLUSTER_ENABLED.getKey(), "true"); underTest.configure(); assertThat( diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java index d233b33add5..908788abd29 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppReloaderImplTest.java @@ -27,7 +27,6 @@ import org.sonar.application.config.AppSettings; import org.sonar.application.config.AppSettingsLoader; import org.sonar.application.config.TestAppSettings; import org.sonar.process.MessageException; -import org.sonar.process.ProcessProperties; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.MapEntry.entry; @@ -35,7 +34,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; public class AppReloaderImplTest { @@ -68,7 +71,7 @@ public class AppReloaderImplTest { @Test public void throw_ISE_if_cluster_is_enabled() throws IOException { - AppSettings settings = new TestAppSettings().set(CLUSTER_ENABLED, "true"); + AppSettings settings = new TestAppSettings().set(CLUSTER_ENABLED.getKey(), "true"); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Restart is not possible with cluster mode"); @@ -82,15 +85,15 @@ public class AppReloaderImplTest { @Test public void throw_MessageException_if_path_properties_are_changed() throws IOException { - verifyFailureIfPropertyValueChanged(ProcessProperties.PATH_DATA); - verifyFailureIfPropertyValueChanged(ProcessProperties.PATH_LOGS); - verifyFailureIfPropertyValueChanged(ProcessProperties.PATH_TEMP); - verifyFailureIfPropertyValueChanged(ProcessProperties.PATH_WEB); + verifyFailureIfPropertyValueChanged(PATH_DATA.getKey()); + verifyFailureIfPropertyValueChanged(PATH_LOGS.getKey()); + verifyFailureIfPropertyValueChanged(PATH_TEMP.getKey()); + verifyFailureIfPropertyValueChanged(PATH_WEB.getKey()); } @Test public void throw_MessageException_if_cluster_mode_changed() throws IOException { - verifyFailureIfPropertyValueChanged(CLUSTER_ENABLED); + verifyFailureIfPropertyValueChanged(CLUSTER_ENABLED.getKey()); } private void verifyFailureIfPropertyValueChanged(String propertyKey) throws IOException { diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java index 2c60879b5cb..35a6fec19db 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppStateFactoryTest.java @@ -29,11 +29,11 @@ import org.sonar.process.NetworkUtilsImpl; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeThat; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; public class AppStateFactoryTest { @@ -45,11 +45,11 @@ public class AppStateFactoryTest { Optional<InetAddress> ip = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address(); assumeThat(ip.isPresent(), CoreMatchers.is(true)); - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "application"); - settings.set(CLUSTER_NODE_HOST, ip.get().getHostAddress()); - settings.set(CLUSTER_HOSTS, ip.get().getHostAddress()); - settings.set(CLUSTER_NAME, "foo"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "application"); + settings.set(CLUSTER_NODE_HOST.getKey(), ip.get().getHostAddress()); + settings.set(CLUSTER_HOSTS.getKey(), ip.get().getHostAddress()); + settings.set(CLUSTER_NAME.getKey(), "foo"); AppState appState = underTest.create(); assertThat(appState).isInstanceOf(ClusterAppStateImpl.class); diff --git a/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java index dc8c597afcc..32198868801 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/SchedulerImplTest.java @@ -55,11 +55,11 @@ import static org.mockito.Mockito.mock; import static org.sonar.process.ProcessId.COMPUTE_ENGINE; import static org.sonar.process.ProcessId.ELASTICSEARCH; import static org.sonar.process.ProcessId.WEB_SERVER; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_PORT; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; public class SchedulerImplTest { @@ -71,7 +71,6 @@ public class SchedulerImplTest { public TemporaryFolder temporaryFolder = new TemporaryFolder(); private EsScriptCommand esScriptCommand; - private JavaCommand esJavaCommand; private JavaCommand webLeaderCommand; private JavaCommand webFollowerCommand; private JavaCommand ceCommand; @@ -89,7 +88,6 @@ public class SchedulerImplTest { public void setUp() throws Exception { File tempDir = temporaryFolder.newFolder(); esScriptCommand = new EsScriptCommand(ELASTICSEARCH, tempDir); - esJavaCommand = new JavaCommand(ELASTICSEARCH, tempDir); webLeaderCommand = new JavaCommand(WEB_SERVER, tempDir); webFollowerCommand = new JavaCommand(WEB_SERVER, tempDir); ceCommand = new JavaCommand(COMPUTE_ENGINE, tempDir); @@ -211,8 +209,8 @@ public class SchedulerImplTest { @Test public void search_node_starts_only_elasticsearch() throws Exception { - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "search"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "search"); addRequiredNodeProperties(); SchedulerImpl underTest = newScheduler(true); underTest.schedule(); @@ -226,8 +224,8 @@ public class SchedulerImplTest { @Test public void application_node_starts_only_web_and_ce() throws Exception { clusterAppState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "application"); SchedulerImpl underTest = newScheduler(true); underTest.schedule(); @@ -245,8 +243,8 @@ public class SchedulerImplTest { assertThat(clusterAppState.tryToLockWebLeader()).isTrue(); clusterAppState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "search"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "search"); addRequiredNodeProperties(); SchedulerImpl underTest = newScheduler(true); underTest.schedule(); @@ -263,8 +261,8 @@ public class SchedulerImplTest { assertThat(clusterAppState.tryToLockWebLeader()).isTrue(); clusterAppState.setOperational(ProcessId.ELASTICSEARCH); - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "application"); SchedulerImpl underTest = newScheduler(true); underTest.schedule(); @@ -281,8 +279,8 @@ public class SchedulerImplTest { @Test public void web_server_waits_for_remote_elasticsearch_to_be_started_if_local_es_is_disabled() throws Exception { - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "application"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "application"); SchedulerImpl underTest = newScheduler(true); underTest.schedule(); @@ -321,9 +319,9 @@ public class SchedulerImplTest { } private void addRequiredNodeProperties() { - settings.set(CLUSTER_NODE_NAME, randomAlphanumeric(4)); - settings.set(CLUSTER_NODE_HOST, randomAlphanumeric(4)); - settings.set(CLUSTER_NODE_PORT, String.valueOf(1 + new Random().nextInt(999))); + settings.set(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(4)); + settings.set(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(4)); + settings.set(CLUSTER_NODE_PORT.getKey(), String.valueOf(1 + new Random().nextInt(999))); } private class TestCommandFactory implements CommandFactory { diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/health/SearchNodeHealthProviderTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/health/SearchNodeHealthProviderTest.java index 40a24345559..fd322b38aa9 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/health/SearchNodeHealthProviderTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/health/SearchNodeHealthProviderTest.java @@ -28,7 +28,6 @@ import org.junit.rules.ExpectedException; import org.sonar.application.cluster.ClusterAppState; import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.cluster.health.NodeHealth; @@ -38,9 +37,9 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_PORT; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_PORT; public class SearchNodeHealthProviderTest { @Rule @@ -64,7 +63,7 @@ public class SearchNodeHealthProviderTest { @Test public void constructor_throws_NPE_if_NetworkUtils_getHostname_returns_null_and_property_is_not_set() { Properties properties = new Properties(); - properties.put(ProcessProperties.CLUSTER_NODE_NAME, randomAlphanumeric(3)); + properties.put(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); Props props = new Props(properties); expectedException.expect(NullPointerException.class); @@ -75,7 +74,7 @@ public class SearchNodeHealthProviderTest { @Test public void constructor_throws_IAE_if_property_node_port_is_not_set() { Properties properties = new Properties(); - properties.put(ProcessProperties.CLUSTER_NODE_NAME, randomAlphanumeric(3)); + properties.put(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); Props props = new Props(properties); @@ -89,8 +88,8 @@ public class SearchNodeHealthProviderTest { public void constructor_throws_FormatException_if_property_node_port_is_not_an_integer() { String port = randomAlphabetic(3); Properties properties = new Properties(); - properties.put(ProcessProperties.CLUSTER_NODE_NAME, randomAlphanumeric(3)); - properties.put(ProcessProperties.CLUSTER_NODE_PORT, port); + properties.put(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); + properties.put(CLUSTER_NODE_PORT.getKey(), port); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); Props props = new Props(properties); @@ -105,8 +104,8 @@ public class SearchNodeHealthProviderTest { String name = randomAlphanumeric(3); int port = 1 + random.nextInt(4); Properties properties = new Properties(); - properties.setProperty(CLUSTER_NODE_NAME, name); - properties.setProperty(CLUSTER_NODE_PORT, valueOf(port)); + properties.setProperty(CLUSTER_NODE_NAME.getKey(), name); + properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(port)); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); when(clock.now()).thenReturn(1L + random.nextInt(87)); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); @@ -117,8 +116,8 @@ public class SearchNodeHealthProviderTest { assertThat(nodeHealth.getDetails().getPort()).isEqualTo(port); // change values in properties - properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(6)); - properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(99))); + properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(6)); + properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(99))); NodeHealth newNodeHealth = underTest.get(); @@ -130,9 +129,9 @@ public class SearchNodeHealthProviderTest { public void get_returns_host_from_property_if_set_at_constructor_time() { String host = randomAlphanumeric(55); Properties properties = new Properties(); - properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(3)); - properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(4))); - properties.setProperty(CLUSTER_NODE_HOST, host); + properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); + properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4))); + properties.setProperty(CLUSTER_NODE_HOST.getKey(), host); when(clock.now()).thenReturn(1L + random.nextInt(87)); SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock); @@ -141,7 +140,7 @@ public class SearchNodeHealthProviderTest { assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host); // change now - properties.setProperty(CLUSTER_NODE_HOST, randomAlphanumeric(96)); + properties.setProperty(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(96)); NodeHealth newNodeHealth = underTest.get(); @@ -161,10 +160,10 @@ public class SearchNodeHealthProviderTest { private void getReturnsHostFromNetworkUtils(@Nullable String hostPropertyValue) { String host = randomAlphanumeric(34); Properties properties = new Properties(); - properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(3)); - properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(4))); + properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); + properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4))); if (hostPropertyValue != null) { - properties.setProperty(CLUSTER_NODE_HOST, hostPropertyValue); + properties.setProperty(CLUSTER_NODE_HOST.getKey(), hostPropertyValue); } when(clock.now()).thenReturn(1L + random.nextInt(87)); when(networkUtils.getHostname()).thenReturn(host); @@ -226,8 +225,8 @@ public class SearchNodeHealthProviderTest { } private long setRequiredPropertiesAndMocks(Properties properties) { - properties.setProperty(CLUSTER_NODE_NAME, randomAlphanumeric(3)); - properties.setProperty(CLUSTER_NODE_PORT, valueOf(1 + random.nextInt(4))); + properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3)); + properties.setProperty(CLUSTER_NODE_PORT.getKey(), valueOf(1 + random.nextInt(4))); long now = 1L + random.nextInt(87); when(clock.now()).thenReturn(now); when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34)); diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java index 3c8abc90770..6e907ab3f40 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsLoopbackTest.java @@ -20,7 +20,6 @@ package org.sonar.application.config; import java.net.InetAddress; -import java.net.SocketException; import java.util.Optional; import org.hamcrest.CoreMatchers; import org.junit.Before; @@ -30,17 +29,16 @@ import org.junit.rules.ExpectedException; import org.sonar.process.MessageException; import org.sonar.process.NetworkUtils; import org.sonar.process.NetworkUtilsImpl; -import org.sonar.process.ProcessProperties; import static org.junit.Assume.assumeThat; import static org.mockito.Mockito.spy; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; -import static org.sonar.process.ProcessProperties.JDBC_URL; -import static org.sonar.process.ProcessProperties.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; public class ClusterSettingsLoopbackTest { @@ -60,26 +58,26 @@ public class ClusterSettingsLoopbackTest { } @Test - public void ClusterSettings_throws_MessageException_if_host_of_search_node_is_loopback() throws Exception { - verifySearchFailureIfLoopback(ProcessProperties.CLUSTER_NODE_HOST); - verifySearchFailureIfLoopback(ProcessProperties.CLUSTER_SEARCH_HOSTS); - verifySearchFailureIfLoopback(ProcessProperties.CLUSTER_HOSTS); - verifySearchFailureIfLoopback(ProcessProperties.SEARCH_HOST); + public void ClusterSettings_throws_MessageException_if_host_of_search_node_is_loopback() { + verifySearchFailureIfLoopback(CLUSTER_NODE_HOST.getKey()); + verifySearchFailureIfLoopback(CLUSTER_SEARCH_HOSTS.getKey()); + verifySearchFailureIfLoopback(CLUSTER_HOSTS.getKey()); + verifySearchFailureIfLoopback(SEARCH_HOST.getKey()); } @Test - public void ClusterSettings_throws_MessageException_if_host_of_app_node_is_loopback() throws Exception { - verifyAppFailureIfLoopback(ProcessProperties.CLUSTER_NODE_HOST); - verifyAppFailureIfLoopback(ProcessProperties.CLUSTER_SEARCH_HOSTS); - verifyAppFailureIfLoopback(ProcessProperties.CLUSTER_HOSTS); + public void ClusterSettings_throws_MessageException_if_host_of_app_node_is_loopback() { + verifyAppFailureIfLoopback(CLUSTER_NODE_HOST.getKey()); + verifyAppFailureIfLoopback(CLUSTER_SEARCH_HOSTS.getKey()); + verifyAppFailureIfLoopback(CLUSTER_HOSTS.getKey()); } - private void verifySearchFailureIfLoopback(String propertyKey) throws Exception { + private void verifySearchFailureIfLoopback(String propertyKey) { TestAppSettings settings = newSettingsForSearchNode(); verifyFailure(propertyKey, settings); } - private void verifyAppFailureIfLoopback(String propertyKey) throws Exception { + private void verifyAppFailureIfLoopback(String propertyKey) { TestAppSettings settings = newSettingsForAppNode(); verifyFailure(propertyKey, settings); } @@ -95,22 +93,22 @@ public class ClusterSettingsLoopbackTest { private TestAppSettings newSettingsForAppNode() { return new TestAppSettings() - .set(CLUSTER_ENABLED, "true") - .set(CLUSTER_NODE_TYPE, "application") - .set(CLUSTER_NODE_HOST, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_SEARCH_HOSTS, nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_ENABLED.getKey(), "true") + .set(CLUSTER_NODE_TYPE.getKey(), "application") + .set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) .set("sonar.auth.jwtBase64Hs256Secret", "abcde") - .set(JDBC_URL, "jdbc:mysql://localhost:3306/sonar"); + .set(JDBC_URL.getKey(), "jdbc:mysql://localhost:3306/sonar"); } private TestAppSettings newSettingsForSearchNode() { return new TestAppSettings() - .set(CLUSTER_ENABLED, "true") - .set(CLUSTER_NODE_TYPE, "search") - .set(CLUSTER_NODE_HOST, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_SEARCH_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(SEARCH_HOST, nonLoopbackLocal.getHostAddress()); + .set(CLUSTER_ENABLED.getKey(), "true") + .set(CLUSTER_NODE_TYPE.getKey(), "search") + .set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(SEARCH_HOST.getKey(), nonLoopbackLocal.getHostAddress()); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java index 4418808b4b7..0f6bf61666e 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/ClusterSettingsTest.java @@ -20,7 +20,6 @@ package org.sonar.application.config; import java.net.InetAddress; -import java.net.SocketException; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -36,13 +35,13 @@ import static org.mockito.Mockito.when; import static org.sonar.process.ProcessId.COMPUTE_ENGINE; import static org.sonar.process.ProcessId.ELASTICSEARCH; import static org.sonar.process.ProcessId.WEB_SERVER; -import static org.sonar.process.ProcessProperties.CLUSTER_ENABLED; -import static org.sonar.process.ProcessProperties.CLUSTER_HOSTS; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_HOST; -import static org.sonar.process.ProcessProperties.CLUSTER_NODE_TYPE; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; -import static org.sonar.process.ProcessProperties.JDBC_URL; -import static org.sonar.process.ProcessProperties.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; public class ClusterSettingsTest { @@ -59,11 +58,11 @@ public class ClusterSettingsTest { } @Test - public void test_isClusterEnabled() throws Exception { - TestAppSettings settings = newSettingsForAppNode().set(CLUSTER_ENABLED, "true"); + public void test_isClusterEnabled() { + TestAppSettings settings = newSettingsForAppNode().set(CLUSTER_ENABLED.getKey(), "true"); assertThat(ClusterSettings.isClusterEnabled(settings)).isTrue(); - settings = new TestAppSettings().set(CLUSTER_ENABLED, "false"); + settings = new TestAppSettings().set(CLUSTER_ENABLED.getKey(), "false"); assertThat(ClusterSettings.isClusterEnabled(settings)).isFalse(); } @@ -74,12 +73,12 @@ public class ClusterSettingsTest { @Test public void getEnabledProcesses_returns_all_processes_in_standalone_mode() { - TestAppSettings settings = new TestAppSettings().set(CLUSTER_ENABLED, "false"); + TestAppSettings settings = new TestAppSettings().set(CLUSTER_ENABLED.getKey(), "false"); assertThat(ClusterSettings.getEnabledProcesses(settings)).containsOnly(COMPUTE_ENGINE, ELASTICSEARCH, WEB_SERVER); } @Test - public void getEnabledProcesses_returns_configured_processes_in_cluster_mode() throws Exception { + public void getEnabledProcesses_returns_configured_processes_in_cluster_mode() { TestAppSettings settings = newSettingsForAppNode(); assertThat(ClusterSettings.getEnabledProcesses(settings)).containsOnly(COMPUTE_ENGINE, WEB_SERVER); @@ -90,7 +89,7 @@ public class ClusterSettingsTest { @Test public void accept_throws_MessageException_if_no_node_type_is_configured() { TestAppSettings settings = new TestAppSettings(); - settings.set(CLUSTER_ENABLED, "true"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); expectedException.expect(MessageException.class); expectedException.expectMessage("Property sonar.cluster.node.type is mandatory"); @@ -101,8 +100,8 @@ public class ClusterSettingsTest { @Test public void accept_throws_MessageException_if_node_type_is_not_correct() { TestAppSettings settings = new TestAppSettings(); - settings.set(CLUSTER_ENABLED, "true"); - settings.set(CLUSTER_NODE_TYPE, "bla"); + settings.set(CLUSTER_ENABLED.getKey(), "true"); + settings.set(CLUSTER_NODE_TYPE.getKey(), "bla"); expectedException.expect(MessageException.class); expectedException.expectMessage("Invalid value for property sonar.cluster.node.type: [bla], only [application, search] are allowed"); @@ -111,7 +110,7 @@ public class ClusterSettingsTest { } @Test - public void accept_throws_MessageException_if_internal_property_for_startup_leader_is_configured() throws Exception { + public void accept_throws_MessageException_if_internal_property_for_startup_leader_is_configured() { TestAppSettings settings = newSettingsForAppNode(); settings.set("sonar.cluster.web.startupLeader", "true"); @@ -124,7 +123,7 @@ public class ClusterSettingsTest { @Test public void accept_does_nothing_if_cluster_is_disabled() { TestAppSettings settings = new TestAppSettings(); - settings.set(CLUSTER_ENABLED, "false"); + settings.set(CLUSTER_ENABLED.getKey(), "false"); // this property is supposed to fail if cluster is enabled settings.set("sonar.cluster.web.startupLeader", "true"); @@ -132,7 +131,7 @@ public class ClusterSettingsTest { } @Test - public void accept_throws_MessageException_if_h2_on_application_node() throws Exception { + public void accept_throws_MessageException_if_h2_on_application_node() { TestAppSettings settings = newSettingsForAppNode(); settings.set("sonar.jdbc.url", "jdbc:h2:mem"); @@ -143,7 +142,7 @@ public class ClusterSettingsTest { } @Test - public void accept_does_not_verify_h2_on_search_node() throws Exception { + public void accept_does_not_verify_h2_on_search_node() { TestAppSettings settings = newSettingsForSearchNode(); settings.set("sonar.jdbc.url", "jdbc:h2:mem"); @@ -152,9 +151,9 @@ public class ClusterSettingsTest { } @Test - public void accept_throws_MessageException_on_application_node_if_default_jdbc_url() throws Exception { + public void accept_throws_MessageException_on_application_node_if_default_jdbc_url() { TestAppSettings settings = newSettingsForAppNode(); - settings.clearProperty(JDBC_URL); + settings.clearProperty(JDBC_URL.getKey()); expectedException.expect(MessageException.class); expectedException.expectMessage("Embedded database is not supported in cluster mode"); @@ -169,56 +168,56 @@ public class ClusterSettingsTest { } @Test - public void isLocalElasticsearchEnabled_returns_true_on_search_node() throws Exception { + public void isLocalElasticsearchEnabled_returns_true_on_search_node() { TestAppSettings settings = newSettingsForSearchNode(); assertThat(ClusterSettings.isLocalElasticsearchEnabled(settings)).isTrue(); } @Test - public void isLocalElasticsearchEnabled_returns_true_for_a_application_node() throws Exception { + public void isLocalElasticsearchEnabled_returns_true_for_a_application_node() { TestAppSettings settings = newSettingsForAppNode(); assertThat(ClusterSettings.isLocalElasticsearchEnabled(settings)).isFalse(); } @Test - public void accept_throws_MessageException_if_searchHost_is_missing() throws Exception { + public void accept_throws_MessageException_if_searchHost_is_missing() { TestAppSettings settings = newSettingsForSearchNode(); - settings.clearProperty(SEARCH_HOST); - assertThatPropertyIsMandatory(settings, SEARCH_HOST); + settings.clearProperty(SEARCH_HOST.getKey()); + assertThatPropertyIsMandatory(settings, SEARCH_HOST.getKey()); } @Test - public void accept_throws_MessageException_if_searchHost_is_empty() throws Exception { + public void accept_throws_MessageException_if_searchHost_is_empty() { TestAppSettings settings = newSettingsForSearchNode(); - settings.set(SEARCH_HOST, ""); - assertThatPropertyIsMandatory(settings, SEARCH_HOST); + settings.set(SEARCH_HOST.getKey(), ""); + assertThatPropertyIsMandatory(settings, SEARCH_HOST.getKey()); } @Test - public void accept_throws_MessageException_if_clusterHosts_is_missing() throws Exception { + public void accept_throws_MessageException_if_clusterHosts_is_missing() { TestAppSettings settings = newSettingsForSearchNode(); - settings.clearProperty(CLUSTER_HOSTS); - assertThatPropertyIsMandatory(settings, CLUSTER_HOSTS); + settings.clearProperty(CLUSTER_HOSTS.getKey()); + assertThatPropertyIsMandatory(settings, CLUSTER_HOSTS.getKey()); } @Test - public void accept_throws_MessageException_if_clusterSearchHosts_is_missing() throws Exception { + public void accept_throws_MessageException_if_clusterSearchHosts_is_missing() { TestAppSettings settings = newSettingsForSearchNode(); - settings.clearProperty(CLUSTER_SEARCH_HOSTS); - assertThatPropertyIsMandatory(settings, CLUSTER_SEARCH_HOSTS); + settings.clearProperty(CLUSTER_SEARCH_HOSTS.getKey()); + assertThatPropertyIsMandatory(settings, CLUSTER_SEARCH_HOSTS.getKey()); } @Test - public void accept_throws_MessageException_if_clusterSearchHosts_is_empty() throws Exception { + public void accept_throws_MessageException_if_clusterSearchHosts_is_empty() { TestAppSettings settings = newSettingsForSearchNode(); - settings.set(CLUSTER_SEARCH_HOSTS, ""); - assertThatPropertyIsMandatory(settings, CLUSTER_SEARCH_HOSTS); + settings.set(CLUSTER_SEARCH_HOSTS.getKey(), ""); + assertThatPropertyIsMandatory(settings, CLUSTER_SEARCH_HOSTS.getKey()); } @Test - public void accept_throws_MessageException_if_jwt_token_is_not_set_on_application_nodes() throws Exception { + public void accept_throws_MessageException_if_jwt_token_is_not_set_on_application_nodes() { TestAppSettings settings = newSettingsForAppNode(); settings.clearProperty("sonar.auth.jwtBase64Hs256Secret"); assertThatPropertyIsMandatory(settings, "sonar.auth.jwtBase64Hs256Secret"); @@ -233,22 +232,22 @@ public class ClusterSettingsTest { private TestAppSettings newSettingsForAppNode() { return new TestAppSettings() - .set(CLUSTER_ENABLED, "true") - .set(CLUSTER_NODE_TYPE, "application") - .set(CLUSTER_NODE_HOST, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_SEARCH_HOSTS, nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_ENABLED.getKey(), "true") + .set(CLUSTER_NODE_TYPE.getKey(), "application") + .set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) .set("sonar.auth.jwtBase64Hs256Secret", "abcde") - .set(JDBC_URL, "jdbc:mysql://localhost:3306/sonar"); + .set(JDBC_URL.getKey(), "jdbc:mysql://localhost:3306/sonar"); } private TestAppSettings newSettingsForSearchNode() { return new TestAppSettings() - .set(CLUSTER_ENABLED, "true") - .set(CLUSTER_NODE_TYPE, "search") - .set(CLUSTER_NODE_HOST, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(CLUSTER_SEARCH_HOSTS, nonLoopbackLocal.getHostAddress()) - .set(SEARCH_HOST, nonLoopbackLocal.getHostAddress()); + .set(CLUSTER_ENABLED.getKey(), "true") + .set(CLUSTER_NODE_TYPE.getKey(), "search") + .set(CLUSTER_NODE_HOST.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(CLUSTER_SEARCH_HOSTS.getKey(), nonLoopbackLocal.getHostAddress()) + .set(SEARCH_HOST.getKey(), nonLoopbackLocal.getHostAddress()); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/FileSystemSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/FileSystemSettingsTest.java index 4120596bfca..8a3a44a1e67 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/FileSystemSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/FileSystemSettingsTest.java @@ -29,12 +29,11 @@ import org.junit.rules.TemporaryFolder; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.process.ProcessProperties.PATH_DATA; -import static org.sonar.process.ProcessProperties.PATH_HOME; -import static org.sonar.process.ProcessProperties.PATH_LOGS; -import static org.sonar.process.ProcessProperties.PATH_TEMP; -import static org.sonar.process.ProcessProperties.PATH_WEB; - +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.PATH_WEB; public class FileSystemSettingsTest { @@ -54,22 +53,22 @@ public class FileSystemSettingsTest { @Test public void relative_paths_are_converted_to_absolute_paths() { Props props = new Props(new Properties()); - props.set(PATH_HOME, homeDir.getAbsolutePath()); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); // relative paths - props.set(PATH_DATA, "data"); - props.set(PATH_LOGS, "logs"); - props.set(PATH_TEMP, "temp"); + props.set(PATH_DATA.getKey(), "data"); + props.set(PATH_LOGS.getKey(), "logs"); + props.set(PATH_TEMP.getKey(), "temp"); // already absolute paths - props.set(PATH_WEB, new File(homeDir, "web").getAbsolutePath()); + props.set(PATH_WEB.getKey(), new File(homeDir, "web").getAbsolutePath()); underTest.accept(props); - assertThat(props.nonNullValue(PATH_DATA)).isEqualTo(new File(homeDir, "data").getAbsolutePath()); - assertThat(props.nonNullValue(PATH_LOGS)).isEqualTo(new File(homeDir, "logs").getAbsolutePath()); - assertThat(props.nonNullValue(PATH_TEMP)).isEqualTo(new File(homeDir, "temp").getAbsolutePath()); - assertThat(props.nonNullValue(PATH_WEB)).isEqualTo(new File(homeDir, "web").getAbsolutePath()); + assertThat(props.nonNullValue(PATH_DATA.getKey())).isEqualTo(new File(homeDir, "data").getAbsolutePath()); + assertThat(props.nonNullValue(PATH_LOGS.getKey())).isEqualTo(new File(homeDir, "logs").getAbsolutePath()); + assertThat(props.nonNullValue(PATH_TEMP.getKey())).isEqualTo(new File(homeDir, "temp").getAbsolutePath()); + assertThat(props.nonNullValue(PATH_WEB.getKey())).isEqualTo(new File(homeDir, "web").getAbsolutePath()); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/config/JdbcSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/config/JdbcSettingsTest.java index c7f89f7c33d..09b14e6ca66 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/config/JdbcSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/config/JdbcSettingsTest.java @@ -29,12 +29,13 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.process.MessageException; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.application.config.JdbcSettings.Provider; -import static org.sonar.process.ProcessProperties.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.JDBC_DRIVER_PATH; +import static org.sonar.process.ProcessProperties.Property.JDBC_URL; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; public class JdbcSettingsTest { @@ -57,7 +58,7 @@ public class JdbcSettingsTest { assertThat(underTest.resolveProviderAndEnforceNonnullJdbcUrl(props)) .isEqualTo(Provider.H2); - assertThat(props.nonNullValue(JDBC_URL)).isEqualTo(String.format("jdbc:h2:tcp://%s:9092/sonar", InetAddress.getLoopbackAddress().getHostAddress())); + assertThat(props.nonNullValue(JDBC_URL.getKey())).isEqualTo(String.format("jdbc:h2:tcp://%s:9092/sonar", InetAddress.getLoopbackAddress().getHostAddress())); } @Test @@ -88,15 +89,15 @@ public class JdbcSettingsTest { } private void checkProviderForUrlAndUnchangedUrl(String url, Provider expected) { - Props props = newProps(JDBC_URL, url); + Props props = newProps(JDBC_URL.getKey(), url); assertThat(underTest.resolveProviderAndEnforceNonnullJdbcUrl(props)).isEqualTo(expected); - assertThat(props.nonNullValue(JDBC_URL)).isEqualTo(url); + assertThat(props.nonNullValue(JDBC_URL.getKey())).isEqualTo(url); } @Test public void fail_with_MessageException_when_provider_is_not_supported() { - Props props = newProps(JDBC_URL, "jdbc:microsoft:sqlserver://localhost"); + Props props = newProps(JDBC_URL.getKey(), "jdbc:microsoft:sqlserver://localhost"); expectedException.expect(MessageException.class); expectedException.expectMessage("Unsupported JDBC driver provider: microsoft"); @@ -106,7 +107,7 @@ public class JdbcSettingsTest { @Test public void fail_with_MessageException_when_url_does_not_have_jdbc_prefix() { - Props props = newProps(JDBC_URL, "oracle:thin:@localhost/XE"); + Props props = newProps(JDBC_URL.getKey(), "oracle:thin:@localhost/XE"); expectedException.expect(MessageException.class); expectedException.expectMessage("Bad format of JDBC URL: oracle:thin:@localhost/XE"); @@ -136,9 +137,9 @@ public class JdbcSettingsTest { File driverFile = new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar"); FileUtils.touch(driverFile); - Props props = newProps(JDBC_URL, "jdbc:oracle:thin:@localhost/XE"); + Props props = newProps(JDBC_URL.getKey(), "jdbc:oracle:thin:@localhost/XE"); underTest.accept(props); - assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); + assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); } @Test @@ -146,9 +147,9 @@ public class JdbcSettingsTest { File driverFile = new File(homeDir, "lib/jdbc/h2/h2.jar"); FileUtils.touch(driverFile); - Props props = newProps(JDBC_URL, "jdbc:h2:tcp://localhost:9092/sonar"); + Props props = newProps(JDBC_URL.getKey(), "jdbc:h2:tcp://localhost:9092/sonar"); underTest.accept(props); - assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); + assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); } @Test @@ -156,9 +157,9 @@ public class JdbcSettingsTest { File driverFile = new File(homeDir, "lib/jdbc/postgresql/pg.jar"); FileUtils.touch(driverFile); - Props props = newProps(JDBC_URL, "jdbc:postgresql://localhost/sonar"); + Props props = newProps(JDBC_URL.getKey(), "jdbc:postgresql://localhost/sonar"); underTest.accept(props); - assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); + assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); } @Test @@ -166,9 +167,9 @@ public class JdbcSettingsTest { File driverFile = new File(homeDir, "lib/jdbc/mssql/sqljdbc4.jar"); FileUtils.touch(driverFile); - Props props = newProps(JDBC_URL, "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); + Props props = newProps(JDBC_URL.getKey(), "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); underTest.accept(props); - assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile); + assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); } @Test @@ -215,7 +216,7 @@ public class JdbcSettingsTest { properties.setProperty(params[i], params[i + 1]); i++; } - properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); + properties.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath()); return new Props(properties); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java index c2237b78a31..d0a1c7e1fc0 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsInstallationTest.java @@ -26,10 +26,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; public class EsInstallationTest { @@ -51,8 +54,8 @@ public class EsInstallationTest { @Test public void constructor_fails_with_IAE_if_temp_dir_property_is_not_defined() throws IOException { Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Property sonar.path.temp is not set"); @@ -63,7 +66,7 @@ public class EsInstallationTest { @Test public void constructor_fails_with_IAE_if_data_dir_property_is_not_defined() throws IOException { Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Missing property: sonar.path.data"); @@ -75,10 +78,10 @@ public class EsInstallationTest { public void getHomeDirectory_is_elasticsearch_subdirectory_of_sq_home_directory() throws IOException { File sqHomeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -91,11 +94,11 @@ public class EsInstallationTest { File tempDir = temp.newFolder(); File dataDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); + props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), dataDir.getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -107,10 +110,10 @@ public class EsInstallationTest { File sqHomeDir = temp.newFolder(); File logDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), logDir.getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -121,10 +124,10 @@ public class EsInstallationTest { public void conf_directory_is_conf_es_subdirectory_of_sq_temp_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -135,10 +138,10 @@ public class EsInstallationTest { public void getExecutable_resolve_executable_for_platform() throws IOException { File sqHomeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -153,10 +156,10 @@ public class EsInstallationTest { public void getLog4j2Properties_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -167,10 +170,10 @@ public class EsInstallationTest { public void getElasticsearchYml_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); @@ -181,10 +184,10 @@ public class EsInstallationTest { public void getJvmOptions_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java index 104a727146b..e4d01874159 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java @@ -32,6 +32,7 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.application.logging.ListAppender; import org.sonar.process.ProcessProperties; +import org.sonar.process.ProcessProperties.Property; import org.sonar.process.Props; import org.sonar.process.System2; @@ -39,8 +40,18 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.process.ProcessProperties.CLUSTER_NAME; -import static org.sonar.process.ProcessProperties.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME; +import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS; +import static org.sonar.process.ProcessProperties.Property.PATH_DATA; +import static org.sonar.process.ProcessProperties.Property.PATH_HOME; +import static org.sonar.process.ProcessProperties.Property.PATH_LOGS; +import static org.sonar.process.ProcessProperties.Property.PATH_TEMP; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HOST; +import static org.sonar.process.ProcessProperties.Property.SEARCH_HTTP_PORT; +import static org.sonar.process.ProcessProperties.Property.SEARCH_INITIAL_STATE_TIMEOUT; +import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES; +import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT; public class EsSettingsTest { @@ -97,11 +108,11 @@ public class EsSettingsTest { private Props minimalProps() { Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, randomAlphanumeric(12)); - props.set(ProcessProperties.PATH_DATA, randomAlphanumeric(12)); - props.set(ProcessProperties.PATH_TEMP, randomAlphanumeric(12)); - props.set(ProcessProperties.PATH_LOGS, randomAlphanumeric(12)); - props.set(CLUSTER_NAME, randomAlphanumeric(12)); + props.set(PATH_HOME.getKey(), randomAlphanumeric(12)); + props.set(PATH_DATA.getKey(), randomAlphanumeric(12)); + props.set(PATH_TEMP.getKey(), randomAlphanumeric(12)); + props.set(PATH_LOGS.getKey(), randomAlphanumeric(12)); + props.set(CLUSTER_NAME.getKey(), randomAlphanumeric(12)); return props; } @@ -109,13 +120,13 @@ public class EsSettingsTest { public void test_default_settings_for_standalone_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(CLUSTER_NAME, "sonarqube"); + props.set(SEARCH_PORT.getKey(), "1234"); + props.set(SEARCH_HOST.getKey(), "127.0.0.1"); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); + props.set(CLUSTER_NAME.getKey(), "sonarqube"); EsSettings esSettings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE); @@ -146,15 +157,15 @@ public class EsSettingsTest { public void test_default_settings_for_cluster_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube-1"); - props.set(ProcessProperties.CLUSTER_ENABLED, "true"); - props.set(ProcessProperties.CLUSTER_NODE_NAME, "node-1"); + props.set(SEARCH_PORT.getKey(), "1234"); + props.set(SEARCH_HOST.getKey(), "127.0.0.1"); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); + props.set(CLUSTER_NAME.getKey(), "sonarqube-1"); + props.set(Property.CLUSTER_ENABLED.getKey(), "true"); + props.set(CLUSTER_NODE_NAME.getKey(), "node-1"); EsSettings esSettings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE); @@ -167,14 +178,14 @@ public class EsSettingsTest { public void test_node_name_default_for_cluster_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - props.set(ProcessProperties.CLUSTER_ENABLED, "true"); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(CLUSTER_NAME.getKey(), "sonarqube"); + props.set(Property.CLUSTER_ENABLED.getKey(), "true"); + props.set(SEARCH_PORT.getKey(), "1234"); + props.set(SEARCH_HOST.getKey(), "127.0.0.1"); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsSettings esSettings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE); Map<String, String> generated = esSettings.build(); assertThat(generated.get("node.name")).startsWith("sonarqube-"); @@ -184,14 +195,14 @@ public class EsSettingsTest { public void test_node_name_default_for_standalone_mode() throws Exception { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); - props.set(ProcessProperties.CLUSTER_NAME, "sonarqube"); - props.set(ProcessProperties.CLUSTER_ENABLED, "false"); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_DATA, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); + props.set(CLUSTER_NAME.getKey(), "sonarqube"); + props.set(Property.CLUSTER_ENABLED.getKey(), "false"); + props.set(SEARCH_PORT.getKey(), "1234"); + props.set(SEARCH_HOST.getKey(), "127.0.0.1"); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); + props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsSettings esSettings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE); Map<String, String> generated = esSettings.build(); assertThat(generated.get("node.name")).isEqualTo("sonarqube"); @@ -216,7 +227,7 @@ public class EsSettingsTest { @Test public void set_discovery_settings_if_cluster_is_enabled() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080"); + props.set(CLUSTER_SEARCH_HOSTS.getKey(), "1.2.3.4:9000,1.2.3.5:8080"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); @@ -227,7 +238,7 @@ public class EsSettingsTest { @Test public void incorrect_values_of_minimum_master_nodes() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "ꝱꝲꝳପ"); + props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "ꝱꝲꝳପ"); EsSettings underTest = new EsSettings(props, new EsInstallation(props), System2.INSTANCE); @@ -239,7 +250,7 @@ public class EsSettingsTest { @Test public void cluster_is_enabled_with_defined_minimum_master_nodes() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "5"); + props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "5"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("5"); @@ -248,7 +259,7 @@ public class EsSettingsTest { @Test public void cluster_is_enabled_with_defined_initialTimeout() throws Exception { Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "10s"); + props.set(SEARCH_INITIAL_STATE_TIMEOUT.getKey(), "10s"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("10s"); @@ -257,7 +268,7 @@ public class EsSettingsTest { @Test public void in_standalone_initialTimeout_is_not_overridable() throws Exception { Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "10s"); + props.set(SEARCH_INITIAL_STATE_TIMEOUT.getKey(), "10s"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("30s"); @@ -266,7 +277,7 @@ public class EsSettingsTest { @Test public void in_standalone_minimumMasterNodes_is_not_overridable() throws Exception { Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "5"); + props.set(SEARCH_MINIMUM_MASTER_NODES.getKey(), "5"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("1"); @@ -275,7 +286,7 @@ public class EsSettingsTest { @Test public void enable_http_connector() throws Exception { Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); + props.set(SEARCH_HTTP_PORT.getKey(), "9010"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("http.port")).isEqualTo("9010"); @@ -286,8 +297,8 @@ public class EsSettingsTest { @Test public void enable_http_connector_different_host() throws Exception { Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.2"); + props.set(SEARCH_HTTP_PORT.getKey(), "9010"); + props.set(SEARCH_HOST.getKey(), "127.0.0.2"); Map<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); assertThat(settings.get("http.port")).isEqualTo("9010"); @@ -299,8 +310,8 @@ public class EsSettingsTest { File homeDir = temp.newFolder(); Props props = new Props(new Properties()); ProcessProperties.completeDefaults(props); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.CLUSTER_ENABLED, Boolean.toString(cluster)); + props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath()); + props.set(Property.CLUSTER_ENABLED.getKey(), Boolean.toString(cluster)); return props; } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java index 465b4247a8f..7d32c0e24eb 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/process/StopRequestWatcherImplTest.java @@ -30,7 +30,6 @@ import org.sonar.application.FileSystem; import org.sonar.application.Scheduler; import org.sonar.application.config.AppSettings; import org.sonar.process.sharedmemoryfile.ProcessCommands; -import org.sonar.process.ProcessProperties; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -40,6 +39,7 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.sonar.process.ProcessProperties.Property.ENABLE_STOP_COMMAND; public class StopRequestWatcherImplTest { @@ -108,7 +108,7 @@ public class StopRequestWatcherImplTest { } private void enableSetting(boolean b) { - when(settings.getProps().valueAsBoolean(ProcessProperties.ENABLE_STOP_COMMAND)).thenReturn(b); + when(settings.getProps().valueAsBoolean(ENABLE_STOP_COMMAND.getKey())).thenReturn(b); } } |