aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Process.java45
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java9
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java44
3 files changed, 66 insertions, 32 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Process.java b/server/sonar-process/src/main/java/org/sonar/process/Process.java
index f345adf4f42..c511bf7f127 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Process.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Process.java
@@ -19,6 +19,7 @@
*/
package org.sonar.process;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +31,10 @@ import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
@@ -54,11 +58,11 @@ public abstract class Process implements ProcessMXBean {
protected Long lastPing;
- final String name;
- final Integer port;
+ String name;
+ Integer port;
- final protected Props props;
- final private Thread shutdownHook;
+ protected final Props props;
+ private Thread shutdownHook;
private static final long MAX_ALLOWED_TIME = 3000L;
private ScheduledFuture<?> pingTask = null;
@@ -75,15 +79,40 @@ public abstract class Process implements ProcessMXBean {
}
};
+ public Process(String[] args) {
+ // loading arguments from file and system.
+ if (args.length < 1) {
+ throw new IllegalStateException("Process is missing argument!");
+ }
+
+ File propertyFile = new File(args[0]);
+ if (!propertyFile.exists()) {
+ throw new IllegalStateException("Property file '" + args[0] + "' does not exist! ");
+ }
+
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileReader(propertyFile));
+ } catch (IOException e) {
+ throw new IllegalStateException("Could not read properties from file '" + args[0] + "'", e);
+ }
+ props = Props.create(properties);
+ init();
+ }
+
+ @VisibleForTesting
public Process(Props props) {
-
- validateSonarHome(props);
-
- // Loading all Properties from file
this.props = props;
+ init();
+ }
+
+ private void init() {
+
+ // Loading all Properties from file
this.name = props.of(NAME_PROPERTY, null);
this.port = props.intOf(PORT_PROPERTY);
+ validateSonarHome(props);
// Testing required properties
if (StringUtils.isEmpty(this.name)) {
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
index c1b1ff5067b..9e0495eafc3 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
@@ -143,7 +143,7 @@ public class ProcessWrapper extends Thread {
if (properties.containsKey(Process.JAVA_OPS)) {
return properties.get(Process.JAVA_OPS);
} else {
- return "";
+ return null;
}
}
@@ -187,13 +187,16 @@ public class ProcessWrapper extends Thread {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command().add(getJavaCommand());
- processBuilder.command().add(getJavaOptions());
+
+ String javaOptions = getJavaOptions();
+ if (!StringUtils.isEmpty(javaOptions)) {
+ processBuilder.command().add(getJavaOptions());
+ }
processBuilder.command().addAll(getJMXOptions());
processBuilder.command().addAll(getClassPath());
processBuilder.command().add(className);
processBuilder.command().add(getPropertyFile());
-
//TODO remove once Process uses the temp file generated by getPropertyFile();
processBuilder.environment().putAll(properties);
diff --git a/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java b/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
index 29d0d880b72..a98e9e3b27b 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
@@ -19,6 +19,7 @@
*/
package org.sonar.search;
+import com.google.common.annotations.VisibleForTesting;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue;
@@ -44,12 +45,32 @@ public class ElasticSearch extends Process {
public static final String DEFAULT_CLUSTER_NAME = "sonarqube";
- private final Node node;
+ private Node node;
+ public ElasticSearch(String... args) {
+ super(args);
+ }
+
+ @VisibleForTesting
public ElasticSearch(Props props) {
super(props);
+ }
+ @Override
+ public boolean isReady() {
+ try {
+ return (node.client().admin().cluster().prepareHealth()
+ .setWaitForYellowStatus()
+ .setTimeout(TimeValue.timeValueSeconds(3L))
+ .get()
+ .getStatus() != ClusterHealthStatus.RED);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+ @Override
+ public void onStart() {
String home = props.of(ES_HOME_PROPERTY);
if (home == null) {
throw new IllegalStateException(MISSING_ES_HOME);
@@ -99,25 +120,7 @@ public class ElasticSearch extends Process {
node = NodeBuilder.nodeBuilder()
.settings(esSettings)
.build();
- }
-
- @Override
- public boolean isReady() {
- try {
- return (node.client().admin().cluster().prepareHealth()
- .setWaitForYellowStatus()
- .setTimeout(TimeValue.timeValueSeconds(3L))
- .get()
- .getStatus() != ClusterHealthStatus.RED);
- } catch (Exception e) {
- return false;
- }
- }
-
- @Override
- public void onStart() {
- node.start();
while (!node.isClosed()) {
try {
Thread.sleep(1000);
@@ -134,8 +137,7 @@ public class ElasticSearch extends Process {
}
public static void main(String... args) throws InterruptedException {
- Props props = Props.create(System.getProperties());
- final ElasticSearch elasticSearch = new ElasticSearch(props);
+ final ElasticSearch elasticSearch = new ElasticSearch(args);
elasticSearch.start();
}
}