.loadFromUrl(getClass().getResource("config/elasticsearch.json"));
initDirs(esSettings);
initRestConsole(esSettings);
+ initNetwork(esSettings);
node = NodeBuilder.nodeBuilder()
.settings(esSettings)
node.client().admin().indices().preparePutTemplate("default")
.setSource(IOUtils.toString(getClass().getResource("config/templates/default.json")))
.execute().actionGet();
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
throw new IllegalStateException("Unable to load index templates", ioe);
}
}
ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory());
}
+ private void initNetwork(ImmutableSettings.Builder esSettings) {
+ esSettings.put("network.bind_host", "127.0.0.1");
+ }
+
private void initRestConsole(ImmutableSettings.Builder esSettings) {
int httpPort = settings.getInt("sonar.es.http.port");
if (httpPort > 0) {
*/
package org.sonar.server.rule2;
-import org.sonar.core.cluster.IndexAction;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.rule.RuleConstants;
import org.sonar.core.rule.RuleDao;
+import org.sonar.server.es.ESNode;
import org.sonar.server.search.BaseIndex;
import java.io.IOException;
-import java.util.Collection;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
private static final Logger LOG = LoggerFactory.getLogger(RuleIndex.class);
- public RuleIndex(WorkQueue queue, RuleDao dao, Profiling profiling) {
- super(queue, dao, profiling);
+ public RuleIndex(WorkQueue queue, RuleDao dao, Profiling profiling, ESNode node) {
+ super(queue, dao, profiling, node);
}
@Override
*/
package org.sonar.server.search;
+import org.sonar.server.es.ESNode;
+
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
private final Profiling profiling;
private Client client;
+ private final ESNode node;
private WorkQueue workQueue;
private IndexSynchronizer<K> synchronizer;
protected Dao<?, K> dao;
- public BaseIndex(WorkQueue workQueue, Dao<?, K> dao, Profiling profiling) {
+ public BaseIndex(WorkQueue workQueue, Dao<?, K> dao, Profiling profiling, ESNode node) {
this.profiling = profiling;
this.workQueue = workQueue;
this.synchronizer = new IndexSynchronizer<K>(this, dao, this.workQueue);
this.dao = dao;
+ this.node = node;
}
protected Dao<?, K> getDao() {
}
public void connect() {
- /* Settings to access our local ES node */
- Settings settings = ImmutableSettings.settingsBuilder()
- .put("client.transport.sniff", true)
- .put("cluster.name", ES_CLUSTER_NAME)
- .put("node.name", "localclient_")
- .build();
-
- this.client = new TransportClient(settings)
- .addTransportAddress(new InetSocketTransportAddress(LOCAL_ES_NODE_HOST, LOCAL_ES_NODE_PORT));
-
- /*
- * Cannot do that yet, need version >= 1.0
- * ImmutableList<DiscoveryNode> nodes = client.connectedNodes();
- * if (nodes.isEmpty()) {
- * throw new ElasticSearchUnavailableException("No nodes available. Verify ES is running!");
- * } else {
- * log.info("connected to nodes: " + nodes.toString());
- * }
- */
+ this.client = this.node.client();
+// /* Settings to access our local ES node */
+// Settings settings = ImmutableSettings.settingsBuilder()
+// .put("client.transport.sniff", true)
+// .put("cluster.name", ES_CLUSTER_NAME)
+// .put("node.name", "localclient_")
+// .build();
+//
+// this.client = new TransportClient(settings)
+// .addTransportAddress(new InetSocketTransportAddress(LOCAL_ES_NODE_HOST, LOCAL_ES_NODE_PORT));
+//
+// /*
+// * Cannot do that yet, need version >= 1.0
+// * ImmutableList<DiscoveryNode> nodes = client.connectedNodes();
+// * if (nodes.isEmpty()) {
+// * throw new ElasticSearchUnavailableException("No nodes available. Verify ES is running!");
+// * } else {
+// * log.info("connected to nodes: " + nodes.toString());
+// * }
+// */
}
/* Cluster And ES Stats/Client methods */
},
"node": {
"name": "sonarqube",
- "local": false,
+ "local": true,
"data": true
},
"discovery": {
@Ignore("Same problem as with BaseIndex test")
public class RuleIndexTest {
- private static final String TEST_NODE_NAME = "es_node_for_tests";
-
- @ElasticsearchNode(name = TEST_NODE_NAME,
- clusterName = BaseIndex.ES_CLUSTER_NAME,
- local = false, data = true)
- private Node node;
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- private RuleIndex getRuleIndex(){
- LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
- Settings settings = new Settings();
- settings.setProperty("sonar.log.profilingLevel", "BASIC");
- RuleIndex rindex = new RuleIndex(queue, null, new Profiling(settings));
- return rindex;
- }
-
- @After
- public void tearDown() {
- if (node != null && !node.isClosed()) {
- node.close();
- }
- }
-
- @Test
- public void test_ruleIndex_conencts_to_es() {
-
- RuleIndex ruleIndex = getRuleIndex();
- ruleIndex.connect();
-
- assertThat(node.client().admin().cluster().prepareClusterStats().get().getNodesStats().getCounts().getTotal())
- .isEqualTo(ruleIndex.getNodesStats().getCounts().getTotal());
-
- ruleIndex.stop();
-
- }
+// private static final String TEST_NODE_NAME = "es_node_for_tests";
+//
+// @ElasticsearchNode(name = TEST_NODE_NAME,
+// clusterName = BaseIndex.ES_CLUSTER_NAME,
+// local = false, data = true)
+// private Node node;
+//
+// @Before
+// public void setUp() throws Exception {
+//
+// }
+//
+// private RuleIndex getRuleIndex(){
+// LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+// Settings settings = new Settings();
+// settings.setProperty("sonar.log.profilingLevel", "BASIC");
+// RuleIndex rindex = new RuleIndex(queue, null, new Profiling(settings));
+// return rindex;
+// }
+//
+// @After
+// public void tearDown() {
+// if (node != null && !node.isClosed()) {
+// node.close();
+// }
+// }
+//
+// @Test
+// public void test_ruleIndex_conencts_to_es() {
+//
+// RuleIndex ruleIndex = getRuleIndex();
+// ruleIndex.connect();
+//
+// assertThat(node.client().admin().cluster().prepareClusterStats().get().getNodesStats().getCounts().getTotal())
+// .isEqualTo(ruleIndex.getNodesStats().getCounts().getTotal());
+//
+// ruleIndex.stop();
+//
+// }
}
+++ /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;
-
-import org.sonar.core.cluster.IndexAction;
-
-import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode;
-import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
-import org.elasticsearch.client.transport.NoNodeAvailableException;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.node.Node;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.cluster.LocalNonBlockingWorkQueue;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-@Ignore("Should be fixed")
-@RunWith(ElasticsearchRunner.class)
-public class BaseIndexTest {
-
- private static final String TEST_NODE_NAME = "es_node_for_tests";
-
- @ElasticsearchNode(name = TEST_NODE_NAME,
- clusterName = BaseIndex.ES_CLUSTER_NAME,
- local = false, data = true)
- private Node node;
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- private BaseIndex<?> getBaseIndex(){
- LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
- Settings settings = new Settings();
- settings.setProperty("sonar.log.profilingLevel", "BASIC");
- return new BaseIndex<Serializable>(queue, null, new Profiling(settings)) {
-
- @Override
- public String getIndexName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected org.elasticsearch.common.settings.Settings getIndexSettings() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected String getType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected XContentBuilder getMapping() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected QueryBuilder getKeyQuery(Serializable key) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Map<String, Object> normalize(Serializable key) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void executeAction(IndexAction action) {
- // TODO Auto-generated method stub
-
- }
- };
- }
-
- @After
- public void tearDown() {
- if (node != null && !node.isClosed()) {
- node.close();
- }
- }
-
- @Test
- public void baseIndex_connects_to_es() {
- BaseIndex<?> searchIndex = getBaseIndex();
- searchIndex.connect();
- assertThat(node.client().admin().cluster().prepareClusterStats().get().getNodesStats().getCounts().getTotal())
- .isEqualTo(searchIndex.getNodesStats().getCounts().getTotal());
-
- searchIndex.stop();
- }
-
- @Test(expected = NoNodeAvailableException.class)
- public void baseIndex_fails_when_es_gone(){
- BaseIndex<?> searchIndex = getBaseIndex();
- searchIndex.connect();
- node.close();
- assertThat(searchIndex.getNodesStats().getCounts().getTotal()).isNotNull();
- }
-}