]> source.dussan.org Git - sonarqube.git/commitdiff
DAOv.2 - Implemented multiple methods for ESNode (DATA and MEMORY)
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 27 May 2014 16:24:11 +0000 (18:24 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 27 May 2014 16:46:35 +0000 (18:46 +0200)
sonar-server/src/main/java/org/sonar/server/search/ESNode.java
sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java [new file with mode: 0644]

index 5ab1e56201df95e4582b86b59a4b98e09e6bf2f5..fe5b20375e605e4c9789b18eec47caf331665571 100644 (file)
@@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.client.Client;
 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.node.Node;
 import org.elasticsearch.node.NodeBuilder;
@@ -71,8 +72,47 @@ public class ESNode implements Startable {
 
   @Override
   public void start() {
-    LOG.info("Start Elasticsearch...");
 
+    IndexProperties.ES_TYPE type = IndexProperties.ES_TYPE.valueOf(settings.getString(IndexProperties.TYPE));
+
+    switch (type) {
+      case MEMORY:
+        initMemoryES();
+        break;
+      case TRANSPORT:
+        initTransportES();
+        break;
+      case DATA:
+      default:
+        initDataES();
+        break;
+    }
+  }
+
+  private void initMemoryES(){
+    ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
+      .put("node.name", "node-test-" + System.currentTimeMillis())
+      .put("node.data", true)
+      .put("cluster.name", "cluster-test-" + NetworkUtils.getLocalAddress().getHostName())
+      .put("index.store.type", "memory")
+      .put("index.store.fs.memory.enabled", "true")
+      .put("gateway.type", "none")
+      .put("index.number_of_shards", "1")
+      .put("index.number_of_replicas", "0")
+      .put("cluster.routing.schedule", "50ms")
+      .put("node.local", true);
+
+    node = NodeBuilder.nodeBuilder()
+      .settings(builder)
+      .node();
+    node.start();
+  }
+
+  private void initTransportES(){
+    throw new IllegalStateException("Not implemented yet");
+  }
+
+  private void initDataES() {
     initLogging();
     ImmutableSettings.Builder esSettings = ImmutableSettings.builder()
       .loadFromUrl(getClass().getResource("config/elasticsearch.json"));
@@ -89,10 +129,10 @@ public class ESNode implements Startable {
 
     if (
       node.client().admin().cluster().prepareHealth()
-      .setWaitForYellowStatus()
-      .setTimeout(healthTimeout)
-      .execute().actionGet()
-      .getStatus() == ClusterHealthStatus.RED) {
+        .setWaitForYellowStatus()
+        .setTimeout(healthTimeout)
+        .execute().actionGet()
+        .getStatus() == ClusterHealthStatus.RED) {
       throw new IllegalStateException(
         String.format("Elasticsearch index is corrupt, please delete directory '%s/%s' and relaunch the SonarQube server.", fileSystem.getHomeDir().getAbsolutePath(), DATA_DIR));
     }
@@ -119,7 +159,7 @@ public class ESNode implements Startable {
   }
 
   private void initRestConsole(ImmutableSettings.Builder esSettings) {
-    int httpPort = settings.getInt("sonar.es.http.port");
+    int httpPort = settings.getInt(IndexProperties.HTTP_PORT);
     if (httpPort > 0) {
       LOG.warn("Elasticsearch HTTP console enabled on port {}. Only for debugging purpose.", httpPort);
       esSettings.put(HTTP_ENABLED, true);
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java b/sonar-server/src/main/java/org/sonar/server/search/IndexProperties.java
new file mode 100644 (file)
index 0000000..87a6842
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.search;
+
+/**
+ * @since 4.4
+ */
+public final class IndexProperties {
+
+  public static enum ES_TYPE {
+    MEMORY, TRANSPORT, DATA
+  }
+
+  public static final String TYPE = "sonar.es.type";
+  public static final String HTTP_PORT = "sonar.es.http.port";
+}