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;
@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"));
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));
}
}
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);
--- /dev/null
+/*
+ * 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";
+}