From 7aa4861592da6891836160aabee437419054cf95 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 29 Aug 2014 17:04:46 +0200 Subject: [PATCH] SONAR-4898 - fixed sonar-server SearchClient exceptions on server shutdown --- .../java/org/sonar/search/SearchServer.java | 1 - .../org/sonar/server/search/SearchClient.java | 18 +++++++++++++++--- 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(); + } } -- 2.39.5