aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@sonarsource.com>2014-08-29 17:04:46 +0200
committerStephane Gamard <stephane.gamard@sonarsource.com>2014-08-29 17:04:46 +0200
commit7aa4861592da6891836160aabee437419054cf95 (patch)
treea750a239a4b21b51816bbe755356db32f518f364
parent6fdd43039ff5e219b731528bb400dac1705e04b1 (diff)
downloadsonarqube-7aa4861592da6891836160aabee437419054cf95.tar.gz
sonarqube-7aa4861592da6891836160aabee437419054cf95.zip
SONAR-4898 - fixed sonar-server SearchClient exceptions on server shutdown
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java18
2 files changed, 15 insertions, 4 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
index c20747a58af..0fbb934c7c7 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
@@ -97,7 +97,6 @@ public class SearchServer extends MonitoredProcess {
protected void doStart() {
synchronized (lock) {
-
Integer port = props.valueAsInt(ES_PORT_PROPERTY);
String clusterName = props.value(ES_CLUSTER_PROPERTY);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java b/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
index 29b2fc86f29..3ed0a7118ca 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java
@@ -33,16 +33,18 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.profiling.StopWatch;
+import org.sonar.process.LoopbackAddress;
/**
* ElasticSearch Node used to connect to index.
*/
-public class SearchClient extends TransportClient {
+public class SearchClient extends TransportClient implements Startable {
private static final Logger LOGGER = LoggerFactory.getLogger(SearchClient.class);
@@ -50,12 +52,13 @@ public class SearchClient extends TransportClient {
public SearchClient(Settings settings) {
super(ImmutableSettings.settingsBuilder()
+ .put("node.name", StringUtils.defaultIfEmpty(settings.getString(IndexProperties.NODE_NAME), "sq_local_client"))
.put("network.bind_host", "localhost")
.put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(IndexProperties.NODE_NAME), "unknown"))
.put("cluster.name", StringUtils.defaultIfBlank(settings.getString(IndexProperties.CLUSTER_NAME), "sonarqube"))
.build());
initLogging();
- this.addTransportAddress(new InetSocketTransportAddress("localhost",
+ this.addTransportAddress(new InetSocketTransportAddress(LoopbackAddress.get().getHostAddress(),
settings.getInt(IndexProperties.NODE_PORT)));
this.profiling = new Profiling(settings);
}
@@ -111,7 +114,16 @@ public class SearchClient extends TransportClient {
} catch (Exception e) {
LOGGER.error("could not execute request: " + response);
throw new IllegalStateException("ES error: ", e);
-
}
}
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
+ super.close();
+ }
}