]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5410 - Added transport mode to sonar-server
authorStephane Gamard <stephane.gamard@searchbox.com>
Thu, 17 Jul 2014 09:42:23 +0000 (11:42 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 18 Jul 2014 09:27:59 +0000 (11:27 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java

index f568a09c97e02cc9aa11f3b27482ea1408249527..b6334873455cf896b7bf075e8d5017b5a41431d0 100644 (file)
@@ -24,10 +24,12 @@ import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.client.Client;
+import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.logging.ESLoggerFactory;
 import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory;
 import org.elasticsearch.common.network.NetworkUtils;
 import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
 import org.picocontainer.Startable;
@@ -57,7 +59,7 @@ public class ESNode implements Startable {
   private final String healthTimeout;
 
   // available only after startup
-  private Node node;
+  private Client client;
 
   public ESNode(ServerFileSystem fileSystem, Settings settings) {
     this(fileSystem, settings, DEFAULT_HEALTH_TIMEOUT);
@@ -88,30 +90,32 @@ public class ESNode implements Startable {
       .put("script.default_lang", "native")
       .put("script.native." + ListUpdate.NAME + ".type", UpdateListScriptFactory.class.getName());
 
-    switch (type) {
-      case MEMORY:
+    initAnalysis(esSettings);
+
+
+    if (IndexProperties.ES_TYPE.TRANSPORT.equals(type)) {
+      client = new TransportClient(esSettings)
+        .addTransportAddress(new InetSocketTransportAddress("localhost",
+          settings.getInt(IndexProperties.NODE_PORT)));
+    } else {
+      if (IndexProperties.ES_TYPE.MEMORY.equals(type)) {
         initMemoryES(esSettings);
-        break;
-      case TRANSPORT:
-        initTransportES(esSettings);
-        break;
-      case DATA:
-      default:
+      } else if (IndexProperties.ES_TYPE.DATA.equals(type)) {
         initDataES(esSettings);
-        break;
-    }
+      }
+      initDirs(esSettings);
+      initRestConsole(esSettings);
+      initNetwork(esSettings);
 
-    initAnalysis(esSettings);
-    initDirs(esSettings);
-    initRestConsole(esSettings);
-    initNetwork(esSettings);
+      Node node = NodeBuilder.nodeBuilder()
+        .settings(esSettings)
+        .node();
+      node.start();
 
-    node = NodeBuilder.nodeBuilder()
-      .settings(esSettings)
-      .node();
-    node.start();
+      client = node.client();
+    }
 
-    if (node.client().admin().cluster().prepareHealth()
+    if (client.admin().cluster().prepareHealth()
       .setWaitForYellowStatus()
       .setTimeout(healthTimeout)
       .get()
@@ -156,7 +160,7 @@ public class ESNode implements Startable {
   }
 
   private void addIndexTemplates() {
-    node.client().admin().indices()
+    client.admin().indices()
       .preparePutTemplate("default")
       .setTemplate("*")
       .addMapping("_default_", "{\"dynamic\": \"strict\"}")
@@ -171,40 +175,40 @@ public class ESNode implements Startable {
     esSettings
       .put("index.mapper.dynamic", false)
 
-      // Sortable text analyzer
+        // Sortable text analyzer
       .put("index.analysis.analyzer.sortable.type", "custom")
       .put("index.analysis.analyzer.sortable.tokenizer", "keyword")
       .putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
 
-      // Edge NGram index-analyzer
+        // Edge NGram index-analyzer
       .put("index.analysis.analyzer.index_grams.type", "custom")
       .put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
 
-      // Edge NGram search-analyzer
+        // Edge NGram search-analyzer
       .put("index.analysis.analyzer.search_grams.type", "custom")
       .put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
 
-      // Word index-analyzer
+        // Word index-analyzer
       .put("index.analysis.analyzer.index_words.type", "custom")
       .put("index.analysis.analyzer.index_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.index_words.filter",
         "standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
 
-      // Word search-analyzer
+        // Word search-analyzer
       .put("index.analysis.analyzer.search_words.type", "custom")
       .put("index.analysis.analyzer.search_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.search_words.filter",
         "standard", "lowercase", "stop", "asciifolding", "porter_stem")
 
-      // Edge NGram filter
+        // Edge NGram filter
       .put("index.analysis.filter.gram_filter.type", "edgeNGram")
       .put("index.analysis.filter.gram_filter.min_gram", 2)
       .put("index.analysis.filter.gram_filter.max_gram", 15)
       .putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
 
-      // Word filter
+        // Word filter
       .put("index.analysis.filter.word_filter.type", "word_delimiter")
       .put("index.analysis.filter.word_filter.generate_word_parts", true)
       .put("index.analysis.filter.word_filter.catenate_words", true)
@@ -215,7 +219,7 @@ public class ESNode implements Startable {
       .put("index.analysis.filter.word_filter.split_on_numerics", true)
       .put("index.analysis.filter.word_filter.stem_english_possessive", true)
 
-      // Path Analyzer
+        // Path Analyzer
       .put("index.analysis.analyzer.path_analyzer.type", "custom")
       .put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
 
@@ -250,16 +254,16 @@ public class ESNode implements Startable {
 
   @Override
   public void stop() {
-    if (node != null) {
-      node.close();
-      node = null;
+    if (client != null) {
+      client.close();
+      client = null;
     }
   }
 
   public Client client() {
-    if (node == null) {
+    if (client == null) {
       throw new IllegalStateException("Elasticsearch is not started");
     }
-    return node.client();
+    return client;
   }
 }
index a2f67178aca2b94c561557410c9fbb33f2aa1387..dd6633d5708050f01a92462df7c6fcb6c8e30c83 100644 (file)
@@ -29,6 +29,7 @@ public final class IndexProperties {
     MEMORY, TRANSPORT, DATA
   }
 
-  public static final String TYPE = "sonar.es.type";
-  public static final String HTTP_PORT = "sonar.es.http.port";
+public static final String TYPE = "sonar.es.type";
+public static final String HTTP_PORT = "sonar.es.http.port";
+public static final String NODE_PORT = "sonar.es.node.port";
 }