package org.sonar.process;
import com.google.common.io.Closeables;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
final int port;
final String name;
+ final String workDir;
final String className;
final String[] classPath;
final Map<String, String> properties;
- public ProcessWrapper(String className, Map<String, String> properties, final String name, Integer port, String... classPath) {
- LOGGER.info("Creating Process for '{}' with monitoring port: {}", name, port);
+ public ProcessWrapper(String workDir, String className, Map<String, String> properties, final String name, String... classPath) {
+ this.port = NetworkUtils.freePort();
+ LOGGER.info("Creating Process for '{}' with workDir: '{}' and monitoring port: {}", name, workDir, port);
+ this.workDir = workDir;
this.name = name;
- this.port = port;
this.className = className;
this.classPath = classPath;
this.properties = properties;
processBuilder.environment().put(Process.NAME_PROPERTY, this.getName());
processBuilder.environment().put(Process.PORT_PROPERTY, Integer.toString(port));
+ //check that working directory exists.
+ File workDirectory = new File(workDir);
+ if(!workDirectory.exists()) {
+ throw new IllegalStateException("Work directory does not exist.");
+ } else {
+ processBuilder.directory(FileUtils.getFile(workDir));
+ }
+
try {
java.lang.Process process = processBuilder.start();
errorGobbler = new StreamGobbler(process.getErrorStream(), this.getName() + "-ERROR");
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.slf4j.Logger;
@Override
public boolean isReady() {
try {
- ClusterHealthStatus status = node.client().admin().cluster().prepareClusterStats()
- .get().getStatus();
- return status != null && status == ClusterHealthStatus.GREEN;
+ return (node.client().admin().cluster().prepareHealth()
+ .setWaitForYellowStatus()
+ .setTimeout(TimeValue.timeValueSeconds(3L))
+ .get()
+ .getStatus() != ClusterHealthStatus.RED);
+// ClusterHealthStatus status = node.client().admin().cluster().prepareClusterStats()
+// .get().getStatus();
+// return status != null && status == ClusterHealthStatus.GREEN;
} catch (Exception e) {
return false;
}