]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4898 - fixed sonar-server SearchClient exceptions on server shutdown
authorStephane Gamard <stephane.gamard@sonarsource.com>
Fri, 29 Aug 2014 15:04:46 +0000 (17:04 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Fri, 29 Aug 2014 15:04:46 +0000 (17:04 +0200)
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-server/src/main/java/org/sonar/server/search/SearchClient.java

index c20747a58af602f264bef50df201c66e054112d3..0fbb934c7c794b7f5a1853a02bb3332bcd100244 100644 (file)
@@ -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);
 
index 29b2fc86f298aa4e52a03b08f6cd2c902df9de49..3ed0a7118ca5663f1df69b549df2104aeb6f6fe0 100644 (file)
@@ -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();
+  }
 }