private final static Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class);
- public static final String NAME_PROPERTY = "pName";
+ private static final String DEBUG_AGENT = "-agentlib:jdwp";
private static final long AUTOKILL_TIMEOUT_MS = 30000L;
private static final long AUTOKILL_CHECK_DELAY_MS = 2000L;
+ public static final String NAME_PROPERTY = "pName";
public static final String MISSING_NAME_ARGUMENT = "Missing Name argument";
private Long lastPing;
private final boolean isMonitored;
protected MonitoredProcess(Props props) {
- this(props, false);
+ this(props, !props.containsValue(DEBUG_AGENT));
}
protected MonitoredProcess(Props props, boolean monitor) {
return terminated && monitor == null;
}
+ public boolean isMonitored() {
+ return this.isMonitored;
+ }
+
@Override
public final boolean isReady() {
try {
return properties.containsKey(key);
}
+ public boolean containsValue(String value) {
+ for (Object propertyValue : properties.values()) {
+ if (propertyValue.toString().contains(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@CheckForNull
public String of(String key) {
String value = properties.getProperty(key);
}
protected DummyProcess(Props props) throws Exception {
- this(props, false);
+ super(props);
}
@Override
assertThat(dummyProcess).isNotNull();
}
+ @Test
+ public void should_not_monitor_debug() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
+ properties.setProperty("sonar.search.javaOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
+ DummyProcess dummyProcess = new DummyProcess(new Props(properties));
+
+ assertThat(dummyProcess.isMonitored()).isFalse();
+ }
+
+ @Test
+ public void should_monitor_by_default() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
+ properties.setProperty("sonar.search.javaOpts", "hello world");
+ DummyProcess dummyProcess = new DummyProcess(new Props(properties));
+
+ assertThat(dummyProcess.isMonitored()).isTrue();
+ }
+
+
@Test(timeout = 3000L)
public void monitor_dies_when_no_pings() throws Exception {
Properties properties = new Properties();
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
+import org.elasticsearch.common.annotations.VisibleForTesting;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.Node;
private Node node;
- public SearchServer(final Props props, boolean monitored, boolean blocking) {
+ @VisibleForTesting
+ SearchServer(final Props props, boolean monitored, boolean blocking) {
super(props, monitored);
this.isBlocking = blocking;
}
public SearchServer(Props props) {
- this(props, true, true);
+ super(props);
+ this.isBlocking = false;
+ new MinimumViableSystem().check();
+
+ String esNodesInets = props.of(ES_CLUSTER_INET);
+ if (StringUtils.isNotEmpty(esNodesInets)) {
+ Collections.addAll(nodes, esNodesInets.split(","));
+ }
}
@Override