]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7653 upgrade to Elasticsearch 2.3.3
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 25 May 2016 11:32:48 +0000 (13:32 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 31 May 2016 19:30:56 +0000 (21:30 +0200)
108 files changed:
pom.xml
server/sonar-search/pom.xml
server/sonar-search/src/main/java/org/sonar/search/EsSettings.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-search/src/test/java/org/sonar/search/EsSettingsTest.java
server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java
server/sonar-server/pom.xml
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/IndexPurgeListener.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerRawInputFactory.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommonRule.java
server/sonar-server/src/main/java/org/sonar/server/computation/scm/ReportScmInfo.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-server/src/main/java/org/sonar/server/es/BaseDoc.java
server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java
server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java
server/sonar-server/src/main/java/org/sonar/server/es/Facets.java
server/sonar-server/src/main/java/org/sonar/server/es/IndexCreator.java
server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
server/sonar-server/src/main/java/org/sonar/server/es/StickyFacetBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyClearCacheRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyClusterHealthRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyClusterStateRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyClusterStatsRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCountRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyCreateIndexRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilder.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyDeleteRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyFlushRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyGetRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyIndexRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyIndicesExistsRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyIndicesStatsRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyNodesStatsRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyPutMappingRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyRefreshRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxySearchRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxySearchScrollRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDoc.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationIndexer.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/search/Facets.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java
server/sonar-server/src/main/java/org/sonar/server/test/index/CoveredFileDoc.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestDoc.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserDoc.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndex.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewDoc.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndex.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java
server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/IndexPurgeListenerTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/BulkIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/es/DefaultIndexSettingsTest.java
server/sonar-server/src/test/java/org/sonar/server/es/EsServerHolder.java
server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java
server/sonar-server/src/test/java/org/sonar/server/es/FakeDoc.java
server/sonar-server/src/test/java/org/sonar/server/es/SortingTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClearCacheRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyClusterHealthRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilderTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyPutMappingRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/search/BaseDocTest.java
server/sonar-server/src/test/java/org/sonar/server/search/FacetsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java
sonar-application/assembly.xml
sonar-application/pom.xml
sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
sonar-db/src/main/java/org/sonar/db/purge/PurgeListener.java
sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/should_delete_old_closed_issues.xml

diff --git a/pom.xml b/pom.xml
index 7a2e450a1ed5a8589eb9d6c3b8871f2d8a837816..ae356ad3e6ac6b770eb357b78c1690d73cf6da7d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@
     <logback.version>1.1.3</logback.version>
     <slf4j.version>1.7.12</slf4j.version>
     <tomcat.version>8.0.30</tomcat.version>
-    <elasticsearch.version>1.7.5</elasticsearch.version>
+    <elasticsearch.version>2.3.3</elasticsearch.version>
     <orchestrator.version>3.11</orchestrator.version>
     <okhttp.version>2.6.0</okhttp.version>
 
         <version>${sonarCSharp.version}</version>
         <type>sonar-plugin</type>
       </dependency>
+      <dependency>
+        <groupId>net.java.dev.jna</groupId>
+        <artifactId>jna</artifactId>
+        <version>4.1.0</version>
+      </dependency>
       <dependency>
         <groupId>org.elasticsearch</groupId>
         <artifactId>elasticsearch</artifactId>
         <version>${elasticsearch.version}</version>
-        <exclusions>
-          <exclusion>
-            <groupId>org.apache.lucene</groupId>
-            <artifactId>lucene-spatial</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.ow2.asm</groupId>
-            <artifactId>asm</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.ow2.asm</groupId>
-            <artifactId>asm-commons</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.antlr</groupId>
-            <artifactId>antlr-runtime</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.yaml</groupId>
-            <artifactId>snakeyaml</artifactId>
-          </exclusion>
-        </exclusions>
       </dependency>
       <dependency>
         <groupId>com.github.tlrx</groupId>
index c006f179e25d9621e72d5f31c2c9f8e0329974f4..d155517a24255bc9510758a2b5f6a848dd092586 100644 (file)
       <groupId>org.elasticsearch</groupId>
       <artifactId>elasticsearch</artifactId>
     </dependency>
+    <dependency>
+      <groupId>net.java.dev.jna</groupId>
+      <artifactId>jna</artifactId>
+    </dependency>
     <dependency>
       <groupId>com.google.code.findbugs</groupId>
       <artifactId>jsr305</artifactId>
index 5080242991847e3d3632a805399bbf9c54088bff..950afcfbc76a05cc071843bfa9416d4c8ecb570d 100644 (file)
 package org.sonar.search;
 
 import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
 import java.util.Set;
 import java.util.TreeSet;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
-import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,7 +73,7 @@ public class EsSettings implements EsSettingsMBean {
   }
 
   Settings build() {
-    ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
+    Settings.Builder builder = Settings.builder();
     configureFileSystem(builder);
     configureIndexDefaults(builder);
     configureNetwork(builder);
@@ -81,10 +82,9 @@ public class EsSettings implements EsSettingsMBean {
     return builder.build();
   }
 
-  private void configureFileSystem(ImmutableSettings.Builder builder) {
+  private void configureFileSystem(Settings.Builder builder) {
     File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME);
     File dataDir;
-    File workDir;
     File logDir;
 
     // data dir
@@ -96,15 +96,8 @@ public class EsSettings implements EsSettingsMBean {
     }
     builder.put("path.data", dataDir.getAbsolutePath());
 
-    // working dir
-    String workPath = props.value(ProcessProperties.PATH_TEMP);
-    if (StringUtils.isNotEmpty(workPath)) {
-      workDir = new File(workPath);
-    } else {
-      workDir = new File(homeDir, "temp");
-    }
-    builder.put("path.work", workDir.getAbsolutePath());
-    builder.put("path.plugins", workDir.getAbsolutePath());
+    String tempPath = props.value(ProcessProperties.PATH_TEMP);
+    builder.put("path.home", new File(tempPath, "es"));
 
     // log dir
     String logPath = props.value(ProcessProperties.PATH_LOGS);
@@ -116,16 +109,16 @@ public class EsSettings implements EsSettingsMBean {
     builder.put("path.logs", logDir.getAbsolutePath());
   }
 
-  private void configureNetwork(ImmutableSettings.Builder builder) {
-    // the following properties can't be null as default values are defined by app process
-    String host = props.nonNullValue(ProcessProperties.SEARCH_HOST);
+  private void configureNetwork(Settings.Builder builder) {
+    InetAddress host = readHost();
     int port = Integer.parseInt(props.nonNullValue(ProcessProperties.SEARCH_PORT));
     LOGGER.info("Elasticsearch listening on {}:{}", host, port);
 
     // disable multicast
     builder.put("discovery.zen.ping.multicast.enabled", "false");
     builder.put("transport.tcp.port", port);
-    builder.put("transport.host", host);
+    builder.put("transport.host", host.getHostAddress());
+    builder.put("network.host", host.getHostAddress());
 
     // Elasticsearch sets the default value of TCP reuse address to true only on non-MSWindows machines, but why ?
     builder.put("network.tcp.reuse_address", true);
@@ -140,12 +133,21 @@ public class EsSettings implements EsSettingsMBean {
       // see https://github.com/lmenezes/elasticsearch-kopf/issues/195
       builder.put("http.cors.enabled", true);
       builder.put("http.enabled", true);
-      builder.put("http.host", host);
+      builder.put("http.host", host.getHostAddress());
       builder.put("http.port", httpPort);
     }
   }
 
-  private static void configureIndexDefaults(ImmutableSettings.Builder builder) {
+  private InetAddress readHost() {
+    String hostProperty = props.nonNullValue(ProcessProperties.SEARCH_HOST);
+    try {
+      return InetAddress.getByName(hostProperty);
+    } catch (UnknownHostException e) {
+      throw new IllegalStateException("Can not resolve host [" + hostProperty + "]. Please check network settings and property " + ProcessProperties.SEARCH_HOST, e);
+    }
+  }
+
+  private static void configureIndexDefaults(Settings.Builder builder) {
     builder
       .put("index.number_of_shards", "1")
       .put("index.refresh_interval", "30s")
@@ -153,7 +155,7 @@ public class EsSettings implements EsSettingsMBean {
       .put("index.mapper.dynamic", false);
   }
 
-  private void configureCluster(ImmutableSettings.Builder builder) {
+  private void configureCluster(Settings.Builder builder) {
     int replicationFactor = 0;
     if (inCluster()) {
       replicationFactor = 1;
@@ -178,7 +180,7 @@ public class EsSettings implements EsSettingsMBean {
     builder.put("node.name", nodeName);
   }
 
-  private void configureMarvel(ImmutableSettings.Builder builder) {
+  private void configureMarvel(Settings.Builder builder) {
     Set<String> marvels = new TreeSet<>();
     marvels.addAll(Arrays.asList(StringUtils.split(props.value(PROP_MARVEL_HOSTS, ""), ",")));
 
index 899ab6891b8eeceddf37b942bbd27f9d10d54138..f21987fb994aae65eb0a1bb4cb69e2568ea3e0c4 100644 (file)
  */
 package org.sonar.search;
 
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
+import org.apache.lucene.util.StringHelper;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.node.internal.InternalNode;
+import org.elasticsearch.node.Node;
+import org.elasticsearch.node.NodeBuilder;
 import org.sonar.process.Jmx;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.Monitored;
@@ -31,7 +33,7 @@ import org.sonar.process.Props;
 public class SearchServer implements Monitored {
 
   private final EsSettings settings;
-  private InternalNode node;
+  private Node node;
 
   public SearchServer(Props props) {
     this.settings = new EsSettings(props);
@@ -42,10 +44,17 @@ public class SearchServer implements Monitored {
   @Override
   public void start() {
     Jmx.register(EsSettingsMBean.OBJECT_NAME, settings);
-    node = new InternalNode(settings.build(), false);
+    initBootstrap();
+    node = NodeBuilder.nodeBuilder().settings(settings.build()).build();
     node.start();
   }
 
+  // copied from https://github.com/elastic/elasticsearch/blob/v2.3.3/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
+  private void initBootstrap() {
+    // init lucene random seed. it will use /dev/urandom where available:
+    StringHelper.randomId();
+  }
+
   @Override
   public boolean isUp() {
     return node != null && node.client().admin().cluster().prepareHealth()
index f8f12f2527260729b946690c20597b4e784c9a58..35fd0c236ef7c4e11e6ce9a9e8907cffd486ef0d 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.search;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
 import org.elasticsearch.common.settings.Settings;
 import org.junit.Rule;
 import org.junit.Test;
@@ -27,10 +30,6 @@ import org.sonar.process.MessageException;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
@@ -60,7 +59,7 @@ public class EsSettingsTest {
 
     assertThat(generated.get("path.data")).isNotNull();
     assertThat(generated.get("path.logs")).isNotNull();
-    assertThat(generated.get("path.work")).isNotNull();
+    assertThat(generated.get("path.home")).isNotNull();
 
     // http is disabled for security reasons
     assertThat(generated.get("http.enabled")).isEqualTo("false");
@@ -98,7 +97,7 @@ public class EsSettingsTest {
 
     assertThat(settings.get("path.data")).isEqualTo(new File(dataDir, "es").getAbsolutePath());
     assertThat(settings.get("path.logs")).isEqualTo(logDir.getAbsolutePath());
-    assertThat(settings.get("path.work")).isEqualTo(tempDir.getAbsolutePath());
+    assertThat(settings.get("path.home")).isEqualTo(new File(tempDir, "es").getAbsolutePath());
   }
 
   @Test
index ebf7e106f4b7f8cb5c7c53e2a1bc279b2c5398cc..8b63fb52eb4d4037e6e7b95db5b7c0877fa31e6e 100644 (file)
@@ -21,11 +21,10 @@ package org.sonar.search;
 
 import java.net.InetAddress;
 import java.util.Properties;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.NoNodeAvailableException;
 import org.elasticsearch.client.transport.TransportClient;
-import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.junit.After;
@@ -72,8 +71,8 @@ public class SearchServerTest {
   public void start_stop_server() throws Exception {
     Props props = new Props(new Properties());
     // the following properties have always default values (see ProcessProperties)
-    String host = InetAddress.getLocalHost().getHostAddress();
-    props.set(ProcessProperties.SEARCH_HOST, host);
+    InetAddress host = InetAddress.getLocalHost();
+    props.set(ProcessProperties.SEARCH_HOST, host.getHostAddress());
     props.set(ProcessProperties.SEARCH_PORT, String.valueOf(port));
     props.set(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME);
     props.set(ProcessProperties.CLUSTER_NODE_NAME, "test");
@@ -84,8 +83,8 @@ public class SearchServerTest {
     searchServer.start();
     assertThat(searchServer.isUp()).isTrue();
 
-    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", CLUSTER_NAME).build();
-    client = new TransportClient(settings)
+    Settings settings = Settings.builder().put("cluster.name", CLUSTER_NAME).build();
+    client = TransportClient.builder().settings(settings).build()
       .addTransportAddress(new InetSocketTransportAddress(host, port));
     assertThat(client.admin().cluster().prepareClusterStats().get().getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
 
index 6131f87787bb2a610c857781034c95895958cd70..526c3701302562a041e33b62fb344382a23b5a6e 100644 (file)
@@ -116,7 +116,7 @@ public class IssueIndexBenchmarkTest {
     benchmark.expectAround("Throughput to index issues", throughputPerSecond, 6500, Benchmark.DEFAULT_ERROR_MARGIN_PERCENTS);
 
     // be sure that physical files do not evolve during estimation of size
-    tester.get(EsClient.class).prepareOptimize("issues").get();
+    tester.get(EsClient.class).prepareForceMerge("issues").get();
     long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir());
     LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize)));
     benchmark.expectBetween("ES dir size (b)", dirSize, 200L * FileUtils.ONE_MB, 420L * FileUtils.ONE_MB);
index 4b4895dfdc320fb6ec328bb8ad9b7bb0c34eb534..61954cd639559ae866019536324d13e7b7b5f31f 100644 (file)
       <groupId>org.elasticsearch</groupId>
       <artifactId>elasticsearch</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.elasticsearch</groupId>
+      <artifactId>elasticsearch</artifactId>
+      <version>${elasticsearch.version}</version>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>net.java.dev.jna</groupId>
+      <artifactId>jna</artifactId>
+    </dependency>
     <dependency>
       <groupId>com.google.protobuf</groupId>
       <artifactId>protobuf-java</artifactId>
index 02e17fd4beb0946e506be8451e4d29a37ddd98ed..5267da37dd4fb8b251be8a1071c155e6064b7cc0 100644 (file)
@@ -39,6 +39,21 @@ public class ActivityDoc extends BaseDoc {
     super(new HashMap<String, Object>());
   }
 
+  @Override
+  public String getId() {
+    return getKey();
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   public void setCreatedAt(Date date) {
     setField(ActivityIndexDefinition.FIELD_CREATED_AT, date);
   }
index 4a1ff8ffe62807d07937d265d783773a5d24f195..3e8042ce616c4cc49926ae8da5ebcce436c7123f 100644 (file)
 package org.sonar.server.activity.index;
 
 import com.google.common.base.Function;
+import java.util.Date;
+import java.util.Map;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.AndFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.OrFilterBuilder;
+import org.elasticsearch.index.query.AndQueryBuilder;
+import org.elasticsearch.index.query.OrQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.sort.SortOrder;
 import org.sonar.core.util.NonNullInputFunction;
@@ -33,9 +34,6 @@ import org.sonar.server.es.EsClient;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 
-import java.util.Date;
-import java.util.Map;
-
 public class ActivityIndex extends BaseIndex {
 
   /**
@@ -67,35 +65,33 @@ public class ActivityIndex extends BaseIndex {
     requestBuilder.setSize(options.getLimit());
     requestBuilder.addSort(ActivityIndexDefinition.FIELD_CREATED_AT, SortOrder.DESC);
 
-    AndFilterBuilder filter = FilterBuilders.andFilter();
+    AndQueryBuilder filter = QueryBuilders.andQuery();
     if (!query.getTypes().isEmpty()) {
-      OrFilterBuilder typeFilter = FilterBuilders.orFilter();
+      OrQueryBuilder typeQuery = QueryBuilders.orQuery();
       for (String type : query.getTypes()) {
-        typeFilter.add(FilterBuilders.termFilter(ActivityIndexDefinition.FIELD_TYPE, type));
+        typeQuery.add(QueryBuilders.termQuery(ActivityIndexDefinition.FIELD_TYPE, type));
       }
-      filter.add(typeFilter);
+      filter.add(typeQuery);
     }
 
     if (!query.getDataOrFilters().isEmpty()) {
       for (Map.Entry<String, Object> entry : query.getDataOrFilters().entrySet()) {
-        OrFilterBuilder orFilter = FilterBuilders.orFilter();
-        orFilter.add(FilterBuilders.nestedFilter(ActivityIndexDefinition.FIELD_DETAILS,
-          FilterBuilders.termFilter(ActivityIndexDefinition.FIELD_DETAILS + "." + entry.getKey(), entry.getValue())));
-        filter.add(orFilter);
+        OrQueryBuilder orQuery = QueryBuilders.orQuery();
+        orQuery.add(QueryBuilders.nestedQuery(ActivityIndexDefinition.FIELD_DETAILS,
+          QueryBuilders.termQuery(ActivityIndexDefinition.FIELD_DETAILS + "." + entry.getKey(), entry.getValue())));
+        filter.add(orQuery);
       }
     }
 
     Date since = query.getSince();
     if (since != null) {
-      filter.add(FilterBuilders.rangeFilter(ActivityIndexDefinition.FIELD_CREATED_AT)
-        .gt(since)
-        .cache(false));
+      filter.add(QueryBuilders.rangeQuery(ActivityIndexDefinition.FIELD_CREATED_AT)
+        .gt(since));
     }
     Date to = query.getTo();
     if (to != null) {
-      filter.add(FilterBuilders.rangeFilter(ActivityIndexDefinition.FIELD_CREATED_AT)
-        .lt(to)
-        .cache(false));
+      filter.add(QueryBuilders.rangeQuery(ActivityIndexDefinition.FIELD_CREATED_AT)
+        .lt(to));
     }
 
     requestBuilder.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filter));
index 0ded443ffde75308848cbc3bac0527a33369112b..180ef978dfeba3103305a3cb22317ca3f8cd8ef4 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.activity.index;
 
-import com.google.common.collect.ImmutableMap;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
@@ -54,7 +53,6 @@ public class ActivityIndexDefinition implements IndexDefinition {
 
     // type "activity"
     NewIndex.NewIndexType mapping = index.createType(TYPE);
-    mapping.setAttribute("_id", ImmutableMap.of("path", FIELD_KEY));
     mapping.stringFieldBuilder(FIELD_KEY).disableNorms().build();
     mapping.stringFieldBuilder(FIELD_TYPE).disableNorms().build();
     mapping.stringFieldBuilder(FIELD_ACTION).disableNorms().build();
index 32479e48960d5238cf25c21c75b2535a0c05c5b0..6d26474b0cb573a3060810a17a0e3e84ce9683bd 100644 (file)
@@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Arrays.asList;
-import static org.elasticsearch.common.lang3.StringUtils.trimToNull;
+import static org.apache.commons.lang.StringUtils.trimToNull;
 
 @Immutable
 public class ComponentImpl implements Component {
index 76f1f45aa0ae559423866bdebadfdbd047cf350b..75b70050590fe62bf67bd5e572c3cfe6a0cfa545 100644 (file)
@@ -41,8 +41,8 @@ public class IndexPurgeListener implements PurgeListener {
   }
 
   @Override
-  public void onIssuesRemoval(List<String> issueKeys) {
-    issueIndexer.deleteByKeys(issueKeys);
+  public void onIssuesRemoval(String projectUuid, List<String> issueKeys) {
+    issueIndexer.deleteByKeys(projectUuid, issueKeys);
   }
 
 }
index d692dfd0cd3281a403396727f6572e405fdb3749..bb81467ab44b04194d0a8b3a15ed4e5fc67141ee 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.computation.source.SourceLinesRepository;
 import org.sonar.server.rule.CommonRuleKeys;
 
 import static com.google.common.collect.Lists.newArrayList;
-import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
 
 public class TrackerRawInputFactory {
 
index 6ad789b61625e7bff5296bf57bfce4ca0346b7d2..aac4481a0d76b38438653b08131aea80b563cbd8 100644 (file)
@@ -21,13 +21,13 @@ package org.sonar.server.computation.issue.commonrule;
 
 import com.google.common.base.Optional;
 import javax.annotation.CheckForNull;
-import org.elasticsearch.common.lang3.StringUtils;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.qualityprofile.ActiveRule;
 import org.sonar.server.computation.qualityprofile.ActiveRulesHolder;
 
+import static org.apache.commons.lang.StringUtils.isNotBlank;
 import static org.sonar.server.rule.CommonRuleKeys.commonRepositoryForLang;
 
 public abstract class CommonRule {
@@ -80,7 +80,7 @@ public abstract class CommonRule {
 
   protected static double getMinDensityParam(ActiveRule activeRule, String paramKey) {
     String s = activeRule.getParams().get(paramKey);
-    if (StringUtils.isNoneBlank(s)) {
+    if (isNotBlank(s)) {
       double d = Double.parseDouble(s);
       if (d < 0.0 || d > 100.0) {
         throw new IllegalStateException(String.format("Minimum density of rule [%s] is incorrect. Got [%s] but must be between 0 and 100.", activeRule.getRuleKey(), s));
index e9a5cf0c3dda94163a4e494e51ac0384eb425bb8..5863a7e51596d2e2c56a73ab83c16ba56d461aa0 100644 (file)
@@ -32,7 +32,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.FluentIterable.from;
 import static java.util.Objects.requireNonNull;
-import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
 
 /**
  * ScmInfo implementation based on the changeset information from the Report
index 0bffb7e5f2dd56fac794fbf3a3d4494d78452fdd..ec74ba5ff2be8de663f1c9cff378b81b20e97c8e 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.server.computation.qualityprofile.QualityProfile;
 
 import static com.google.common.collect.Maps.transformValues;
 import static java.lang.String.format;
-import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
 
 /**
  * Feed analysis metadata holder with metadata from the analysis report.
index 4a1226f70a30e8ab5bc98ff1cdc31340c48d6a79..c4654208c2d6bac244d1460596452d4c9c75de03 100644 (file)
@@ -46,6 +46,14 @@ public abstract class BaseDoc {
     return (String) fields.get("key");
   }
 
+  public abstract String getId();
+
+  @CheckForNull
+  public abstract String getRouting();
+
+  @CheckForNull
+  public abstract String getParent();
+
   /**
    * Use this method when field value can be null. See warning in {@link #getField(String)}
    */
index 6c404a5f1b2f0730bdd7ad244b79df848c8aeaf6..86209815835edc9423f3a2d81742403c612673b9 100644 (file)
@@ -32,14 +32,16 @@ import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.delete.DeleteRequestBuilder;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.unit.ByteSizeUnit;
 import org.elasticsearch.common.unit.ByteSizeValue;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.SearchHitField;
+import org.elasticsearch.search.sort.SortOrder;
 import org.picocontainer.Startable;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -144,8 +146,8 @@ public class BulkIndexer implements Startable {
 
   public void addDeletion(SearchRequestBuilder searchRequest) {
     searchRequest
+      .addSort("_doc", SortOrder.ASC)
       .setScroll(TimeValue.timeValueMinutes(5))
-      .setSearchType(SearchType.SCAN)
       .setSize(100)
       // load only doc ids, not _source fields
       .setFetchSource(false);
@@ -157,14 +159,20 @@ public class BulkIndexer implements Startable {
     SearchResponse searchResponse = searchRequest.get();
 
     while (true) {
-      searchResponse = client.prepareSearchScroll(searchResponse.getScrollId())
-        .setScroll(TimeValue.timeValueMinutes(5))
-        .get();
       SearchHit[] hits = searchResponse.getHits().getHits();
       for (SearchHit hit : hits) {
-        add(client.prepareDelete(hit.index(), hit.type(), hit.getId()).request());
+        DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete(hit.index(), hit.type(), hit.getId());
+        SearchHitField routing = hit.field("_routing");
+        if (routing != null) {
+          deleteRequestBuilder.setRouting((String) routing.getValue());
+        }
+        add(deleteRequestBuilder.request());
       }
+
+      String scrollId = searchResponse.getScrollId();
+      searchResponse = client.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(5)).get();
       if (hits.length == 0) {
+        client.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
         break;
       }
     }
@@ -204,7 +212,7 @@ public class BulkIndexer implements Startable {
       // optimize lucene segments and revert index settings
       // Optimization must be done before re-applying replicas:
       // http://www.elasticsearch.org/blog/performance-considerations-elasticsearch-indexing/
-      client.prepareOptimize(indexName).get();
+      client.prepareForceMerge(indexName).get();
 
       updateSettings(largeInitialSettings);
     }
index 1432b5c5b6eecb29a7bc1d830dfd34c3e13e57ff..7e76057dc71cfd33e7f00e01054ae0f13c88b7cd 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.es;
 
 import org.elasticsearch.cluster.metadata.IndexMetaData;
-import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
 
 class DefaultIndexSettings {
 
@@ -28,8 +28,8 @@ class DefaultIndexSettings {
     // only static stuff
   }
 
-  static ImmutableSettings.Builder defaults() {
-    return ImmutableSettings.builder()
+  static Settings.Builder defaults() {
+    return Settings.builder()
       .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
       .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
       .put("index.refresh_interval", "30s")
index 333427452dad398df51c1ad91e1e49e1eccb5e31..e6c80612c577008f34640d447393e18baa35f9dc 100644 (file)
  */
 package org.sonar.server.es;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
@@ -29,14 +30,13 @@ import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheReque
 import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
 import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
 import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
+import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequestBuilder;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
-import org.elasticsearch.action.admin.indices.optimize.OptimizeRequestBuilder;
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.count.CountRequestBuilder;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
 import org.elasticsearch.action.get.GetRequestBuilder;
 import org.elasticsearch.action.get.MultiGetRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
@@ -44,10 +44,10 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.Priority;
 import org.elasticsearch.common.logging.ESLoggerFactory;
 import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory;
-import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -56,7 +56,6 @@ import org.picocontainer.Startable;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.LoopbackAddress;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.es.request.ProxyBulkRequestBuilder;
 import org.sonar.server.es.request.ProxyClearCacheRequestBuilder;
@@ -65,7 +64,6 @@ import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
 import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
 import org.sonar.server.es.request.ProxyCountRequestBuilder;
 import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
-import org.sonar.server.es.request.ProxyDeleteByQueryRequestBuilder;
 import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
 import org.sonar.server.es.request.ProxyFlushRequestBuilder;
 import org.sonar.server.es.request.ProxyGetRequestBuilder;
@@ -79,6 +77,8 @@ import org.sonar.server.es.request.ProxyRefreshRequestBuilder;
 import org.sonar.server.es.request.ProxySearchRequestBuilder;
 import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
 
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
 /**
  * Facade to connect to Elasticsearch node. Handles correctly errors (logging + exceptions
  * with context) and profiling of requests.
@@ -162,6 +162,10 @@ public class EsClient implements Startable {
     return new ProxyMultiGetRequestBuilder(nativeClient());
   }
 
+  /**
+   * @deprecated use {@link #prepareSearch(String...)} with size 0
+   */
+  @Deprecated
   public CountRequestBuilder prepareCount(String... indices) {
     return new ProxyCountRequestBuilder(nativeClient()).setIndices(indices);
   }
@@ -174,22 +178,13 @@ public class EsClient implements Startable {
     return new ProxyDeleteRequestBuilder(nativeClient(), index).setType(type).setId(id);
   }
 
-  /**
-   * @deprecated delete-by-query is dropped from ES 2.0 and should not be used. See
-   * https://www.elastic.co/guide/en/elasticsearch/reference/1.7/docs-delete-by-query.html
-   */
-  @Deprecated
-  public DeleteByQueryRequestBuilder prepareDeleteByQuery(String... indices) {
-    return new ProxyDeleteByQueryRequestBuilder(nativeClient()).setIndices(indices);
-  }
-
   public IndexRequestBuilder prepareIndex(String index, String type) {
     return new ProxyIndexRequestBuilder(nativeClient()).setIndex(index).setType(type);
   }
 
-  public OptimizeRequestBuilder prepareOptimize(String indexName) {
+  public ForceMergeRequestBuilder prepareForceMerge(String indexName) {
     // TODO add proxy for profiling
-    return nativeClient().admin().indices().prepareOptimize(indexName)
+    return nativeClient().admin().indices().prepareForceMerge(indexName)
       .setMaxNumSegments(1);
   }
 
@@ -212,17 +207,18 @@ public class EsClient implements Startable {
   public void start() {
     if (nativeClient == null) {
       ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory());
-      org.elasticsearch.common.settings.Settings esSettings = ImmutableSettings.settingsBuilder()
-        .put("node.name", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "sq_local_client"))
-        .put("network.bind_host", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.SEARCH_HOST), "localhost"))
-        .put("node.rack_id", StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "unknown"))
+      org.elasticsearch.common.settings.Settings esSettings = org.elasticsearch.common.settings.Settings.builder()
+        .put("node.name", defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "sq_local_client"))
+        .put("node.rack_id", defaultIfEmpty(settings.getString(ProcessProperties.CLUSTER_NODE_NAME), "unknown"))
         .put("cluster.name", StringUtils.defaultIfBlank(settings.getString(ProcessProperties.CLUSTER_NAME), "sonarqube"))
         .build();
-      nativeClient = new TransportClient(esSettings);
-      ((TransportClient) nativeClient).addTransportAddress(new InetSocketTransportAddress(StringUtils.defaultIfEmpty(settings.getString(ProcessProperties.SEARCH_HOST),
-        LoopbackAddress.get()
-          .getHostAddress()),
-        settings.getInt(ProcessProperties.SEARCH_PORT)));
+      nativeClient = TransportClient.builder().settings(esSettings).build();
+      String host = settings.getString(ProcessProperties.SEARCH_HOST);
+      try {
+        ((TransportClient) nativeClient).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), settings.getInt(ProcessProperties.SEARCH_PORT)));
+      } catch (UnknownHostException e) {
+        throw new IllegalStateException("Can not resolve host [" + host + "]", e);
+      }
     }
   }
 
index 9c74c0e3a4a065522c3d7632b4af72f3be912f4d..25770e0d97e53b7ba5210a8652647d378e14ce1f 100644 (file)
@@ -33,12 +33,16 @@ import java.util.NoSuchElementException;
 import java.util.Queue;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+import org.elasticsearch.action.bulk.BulkRequestBuilder;
+import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
-import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.joda.time.format.ISODateTimeFormat;
+
+import static java.lang.String.format;
 
 public class EsUtils {
 
@@ -60,7 +64,7 @@ public class EsUtils {
     LinkedHashMap<String, Long> map = new LinkedHashMap<>();
     List<Terms.Bucket> buckets = terms.getBuckets();
     for (Terms.Bucket bucket : buckets) {
-      map.put(bucket.getKey(), bucket.getDocCount());
+      map.put(bucket.getKeyAsString(), bucket.getDocCount());
     }
     return map;
   }
@@ -69,7 +73,7 @@ public class EsUtils {
     return Lists.transform(terms.getBuckets(), new Function<Terms.Bucket, String>() {
       @Override
       public String apply(Terms.Bucket bucket) {
-        return bucket.getKey();
+        return bucket.getKeyAsString();
       }
     });
   }
@@ -90,6 +94,15 @@ public class EsUtils {
     return null;
   }
 
+  public static BulkResponse executeBulkRequest(BulkRequestBuilder builder, String errorMessage, Object... errorMessageArgs) {
+    BulkResponse bulkResponse = builder.get();
+    if (bulkResponse.hasFailures()) {
+      // do not use Preconditions as the message is expensive to generate (see buildFailureMessage())
+      throw new IllegalStateException(format(errorMessage, errorMessageArgs) + ": " + bulkResponse.buildFailureMessage());
+    }
+    return bulkResponse;
+  }
+
   public static <D extends BaseDoc> Iterator<D> scroll(EsClient esClient, String scrollId, Function<Map<String, Object>, D> docConverter) {
     return new DocScrollIterator<>(esClient, scrollId, docConverter);
   }
index c96248e65a543393bc487a59390571b5067134e6..3a87bd5f387e7f21452f81a276c4294d39a55a3f 100644 (file)
@@ -30,7 +30,7 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.aggregations.Aggregation;
 import org.elasticsearch.search.aggregations.Aggregations;
 import org.elasticsearch.search.aggregations.HasAggregations;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram;
+import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
 import org.elasticsearch.search.aggregations.bucket.missing.Missing;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
 import org.elasticsearch.search.aggregations.metrics.sum.Sum;
@@ -64,8 +64,8 @@ public class Facets {
       processTermsAggregation((Terms) aggregation);
     } else if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
       processSubAggregations((HasAggregations) aggregation);
-    } else if (DateHistogram.class.isAssignableFrom(aggregation.getClass())) {
-      processDateHistogram((DateHistogram) aggregation);
+    } else if (Histogram.class.isAssignableFrom(aggregation.getClass())) {
+      processDateHistogram((Histogram) aggregation);
     } else if (Sum.class.isAssignableFrom(aggregation.getClass())) {
       processSum((Sum) aggregation);
     } else {
@@ -95,9 +95,9 @@ public class Facets {
     LinkedHashMap<String, Long> facet = getOrCreateFacet(facetName);
     for (Terms.Bucket value : aggregation.getBuckets()) {
       if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
-        facet.put(value.getKey(), Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
+        facet.put(value.getKeyAsString(), Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
       } else {
-        facet.put(value.getKey(), value.getDocCount());
+        facet.put(value.getKeyAsString(), value.getDocCount());
       }
     }
   }
@@ -108,13 +108,13 @@ public class Facets {
     }
   }
 
-  private void processDateHistogram(DateHistogram aggregation) {
+  private void processDateHistogram(Histogram aggregation) {
     LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName());
-    for (DateHistogram.Bucket value : aggregation.getBuckets()) {
+    for (Histogram.Bucket value : aggregation.getBuckets()) {
       if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
-        facet.put(value.getKey(), Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
+        facet.put(value.getKeyAsString(), Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
       } else {
-        facet.put(value.getKey(), value.getDocCount());
+        facet.put(value.getKeyAsString(), value.getDocCount());
       }
     }
   }
index 71a96209c302f442e1f7d15ed5a99b1821660d05..e08494d92643bc72ae96569596d449b30efb9c7f 100644 (file)
  */
 package org.sonar.server.es;
 
+import java.util.Map;
 import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
-import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
+import org.elasticsearch.common.settings.Settings;
 import org.picocontainer.Startable;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 
-import java.util.Map;
-
 /**
  * Creates/deletes all indices in Elasticsearch during server startup.
  */
@@ -76,7 +75,7 @@ public class IndexCreator implements Startable {
 
   private void createIndex(IndexDefinitions.Index index) {
     LOGGER.info(String.format("Create index %s", index.getName()));
-    ImmutableSettings.Builder settings = ImmutableSettings.builder();
+    Settings.Builder settings = Settings.builder();
     settings.put(index.getSettings());
     settings.put(SETTING_HASH, new IndexDefinitionHash().of(index));
     CreateIndexResponse indexResponse = client
@@ -93,7 +92,6 @@ public class IndexCreator implements Startable {
       LOGGER.info(String.format("Create type %s/%s", index.getName(), entry.getKey()));
       PutMappingResponse mappingResponse = client.preparePutMapping(index.getName())
         .setType(entry.getKey())
-        .setIgnoreConflicts(false)
         .setSource(entry.getValue().getAttributes())
         .get();
       if (!mappingResponse.isAcknowledged()) {
index e8a6260e69c0008f2b7a7d8d25fe3b5bc21f0f8a..099098a4253a4a0914234745907e32a728d386df 100644 (file)
@@ -23,14 +23,14 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedMap;
 import com.google.common.collect.Maps;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import javax.annotation.CheckForNull;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.sonar.api.config.Settings;
+import org.elasticsearch.common.settings.Settings;
 import org.sonar.process.ProcessProperties;
 
 import static java.lang.String.format;
@@ -89,10 +89,6 @@ public class NewIndex {
       return new StringFieldBuilder(this, fieldName);
     }
 
-    public NestedObjectBuilder nestedObjectBuilder(String fieldName, NewIndexType nestedMapping) {
-      return new NestedObjectBuilder(this, nestedMapping, fieldName);
-    }
-
     public NewIndexType createBooleanField(String fieldName) {
       return setProperty(fieldName, ImmutableMap.of("type", "boolean"));
     }
@@ -142,23 +138,6 @@ public class NewIndex {
     }
   }
 
-  public static class NestedObjectBuilder {
-    private final NewIndexType indexType;
-    private final NewIndexType nestedType;
-    private final String fieldName;
-
-    public NestedObjectBuilder(NewIndexType indexType, NewIndexType nestedType, String fieldName) {
-      this.indexType = indexType;
-      this.nestedType = nestedType;
-      this.fieldName = fieldName;
-    }
-
-    public void build() {
-      nestedType.setAttribute("type", "nested");
-      indexType.setProperty(fieldName, nestedType.attributes);
-    }
-  }
-
   /**
    * Helper to define a string field in mapping of index type
    */
@@ -290,8 +269,8 @@ public class NewIndex {
   }
 
   private final String indexName;
-  private final ImmutableSettings.Builder settings = DefaultIndexSettings.defaults();
-  private final SortedMap<String, NewIndexType> types = new TreeMap<>();
+  private final Settings.Builder settings = DefaultIndexSettings.defaults();
+  private final Map<String, NewIndexType> types = new LinkedHashMap<>();
 
   NewIndex(String indexName) {
     Preconditions.checkArgument(StringUtils.isAllLowerCase(indexName), "Index name must be lower-case: " + indexName);
@@ -302,7 +281,7 @@ public class NewIndex {
     return indexName;
   }
 
-  public ImmutableSettings.Builder getSettings() {
+  public Settings.Builder getSettings() {
     return settings;
   }
 
@@ -312,11 +291,11 @@ public class NewIndex {
     return type;
   }
 
-  public SortedMap<String, NewIndexType> getTypes() {
+  public Map<String, NewIndexType> getTypes() {
     return types;
   }
 
-  public void configureShards(Settings settings) {
+  public void configureShards(org.sonar.api.config.Settings settings) {
     boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE);
     int shards = settings.getInt(format("sonar.search.%s.shards", indexName));
     if (shards == 0) {
index b4d210936a06778b9839545e2c7dbf274cde3147..4c0070d08ac39081b69306c332f61637a6d7ea8a 100644 (file)
@@ -23,9 +23,7 @@ import com.google.common.base.Joiner;
 import java.util.Map;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.ArrayUtils;
-import org.elasticsearch.index.query.BoolFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
 import org.elasticsearch.search.aggregations.AggregationBuilder;
@@ -35,22 +33,25 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
 import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
 
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
+
 public class StickyFacetBuilder {
 
   private static final int FACET_DEFAULT_MIN_DOC_COUNT = 1;
   private static final int FACET_DEFAULT_SIZE = 10;
   private static final Order FACET_DEFAULT_ORDER = Terms.Order.count(false);
+  private static final Joiner PIPE_JOINER = Joiner.on('|');
 
   private final QueryBuilder query;
-  private final Map<String, FilterBuilder> filters;
+  private final Map<String, QueryBuilder> filters;
   private final AbstractAggregationBuilder subAggregation;
   private final Order order;
 
-  public StickyFacetBuilder(QueryBuilder query, Map<String, FilterBuilder> filters) {
+  public StickyFacetBuilder(QueryBuilder query, Map<String, QueryBuilder> filters) {
     this(query, filters, null, FACET_DEFAULT_ORDER);
   }
 
-  public StickyFacetBuilder(QueryBuilder query, Map<String, FilterBuilder> filters, @Nullable AbstractAggregationBuilder subAggregation, @Nullable Order order) {
+  public StickyFacetBuilder(QueryBuilder query, Map<String, QueryBuilder> filters, @Nullable AbstractAggregationBuilder subAggregation, @Nullable Order order) {
     this.query = query;
     this.filters = filters;
     this.subAggregation = subAggregation;
@@ -61,7 +62,7 @@ public class StickyFacetBuilder {
     return query;
   }
 
-  public Map<String, FilterBuilder> filters() {
+  public Map<String, QueryBuilder> filters() {
     return filters;
   }
 
@@ -70,7 +71,7 @@ public class StickyFacetBuilder {
   }
 
   public AggregationBuilder buildStickyFacet(String fieldName, String facetName, int size, Object... selected) {
-    BoolFilterBuilder facetFilter = getStickyFacetFilter(fieldName);
+    BoolQueryBuilder facetFilter = getStickyFacetFilter(fieldName);
     FilterAggregationBuilder facetTopAggregation = buildTopFacetAggregation(fieldName, facetName, facetFilter, size);
     facetTopAggregation = addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation, selected);
 
@@ -79,9 +80,9 @@ public class StickyFacetBuilder {
       .subAggregation(facetTopAggregation);
   }
 
-  public BoolFilterBuilder getStickyFacetFilter(String... fieldNames) {
-    BoolFilterBuilder facetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
-    for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
+  public BoolQueryBuilder getStickyFacetFilter(String... fieldNames) {
+    BoolQueryBuilder facetFilter = boolQuery().must(query);
+    for (Map.Entry<String, QueryBuilder> filter : filters.entrySet()) {
       if (filter.getValue() != null && !ArrayUtils.contains(fieldNames, filter.getKey())) {
         facetFilter.must(filter.getValue());
       }
@@ -89,11 +90,10 @@ public class StickyFacetBuilder {
     return facetFilter;
   }
 
-  public FilterAggregationBuilder buildTopFacetAggregation(String fieldName, String facetName, BoolFilterBuilder facetFilter, int size) {
+  public FilterAggregationBuilder buildTopFacetAggregation(String fieldName, String facetName, BoolQueryBuilder facetFilter, int size) {
     TermsBuilder termsAggregation = AggregationBuilders.terms(facetName)
       .field(fieldName)
       .order(order)
-      // .order(Terms.Order.aggregation("debt", false))
       .size(size)
       .minDocCount(FACET_DEFAULT_MIN_DOC_COUNT);
     if (subAggregation != null) {
@@ -109,12 +109,11 @@ public class StickyFacetBuilder {
     if (selected.length > 0) {
       TermsBuilder selectedTerms = AggregationBuilders.terms(facetName + "_selected")
         .field(fieldName)
-        .include(Joiner.on('|').join(selected));
+        .include(PIPE_JOINER.join(selected));
       if (subAggregation != null) {
         selectedTerms = selectedTerms.subAggregation(subAggregation);
       }
-      facetTopAggregation.subAggregation(
-        selectedTerms);
+      facetTopAggregation.subAggregation(selectedTerms);
     }
     return facetTopAggregation;
   }
index 108a3c2bf068c0773030ac1e78ef3951c5fa52ae..debb008dd6712d139a51d91017df7b88bc635390 100644 (file)
@@ -21,8 +21,10 @@ package org.sonar.server.es.request;
 
 import com.google.common.collect.LinkedHashMultiset;
 import com.google.common.collect.Multiset;
+import java.util.Set;
 import org.elasticsearch.action.ActionRequest;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.bulk.BulkAction;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.delete.DeleteRequest;
@@ -33,12 +35,10 @@ import org.elasticsearch.common.unit.TimeValue;
 import org.sonar.api.utils.log.Profiler;
 import org.sonar.server.es.EsClient;
 
-import java.util.Set;
-
 public class ProxyBulkRequestBuilder extends BulkRequestBuilder {
 
   public ProxyBulkRequestBuilder(Client client) {
-    super(client);
+    super(client, BulkAction.INSTANCE);
   }
 
   @Override
index ab499353924466af3e0f88c472004c534d7ea094..cbe465bc82a32e3c272643f625c0ae85a0489bff 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction;
 import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder;
 import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyClearCacheRequestBuilder extends ClearIndicesCacheRequestBuilder {
 
   public ProxyClearCacheRequestBuilder(Client client) {
-    super(client.admin().indices());
+    super(client.admin().indices(), ClearIndicesCacheAction.INSTANCE);
   }
 
   @Override
@@ -74,18 +75,14 @@ public class ProxyClearCacheRequestBuilder extends ClearIndicesCacheRequestBuild
     if (fields != null && fields.length > 0) {
       message.append(String.format(" on fields '%s'", StringUtils.join(fields, ",")));
     }
-    String[] filterKeys = request.filterKeys();
-    if (filterKeys != null && filterKeys.length > 0) {
-      message.append(String.format(" on filterKeys '%s'", StringUtils.join(filterKeys, ",")));
-    }
-    if (request.filterCache()) {
+    if (request.queryCache()) {
       message.append(" with filter cache");
     }
     if (request.fieldDataCache()) {
       message.append(" with field data cache");
     }
-    if (request.idCache()) {
-      message.append(" with id cache");
+    if (request.requestCache()) {
+      message.append(" with request cache");
     }
     return message.toString();
   }
index 9b73bdadfded9c5917616472e2ae21494dfafea0..fc2b85860672c37fd78ebc90b0b1115bbb88e3fd 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyClusterHealthRequestBuilder extends ClusterHealthRequestBuilder {
 
   public ProxyClusterHealthRequestBuilder(Client client) {
-    super(client.admin().cluster());
+    super(client.admin().cluster(), ClusterHealthAction.INSTANCE);
   }
 
   @Override
index 3ad580f7aca39745f9df9bf4ec69cc7bd1714baa..3a785862a5a316519b1462c44f342aad097f1fb3 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyClusterStateRequestBuilder extends ClusterStateRequestBuilder {
 
   public ProxyClusterStateRequestBuilder(Client client) {
-    super(client.admin().cluster());
+    super(client.admin().cluster(), ClusterStateAction.INSTANCE);
   }
 
   @Override
index a0ebe39b4805c547f47663342922091ac4574f82..13416461edc47f225180b04eeb3332dd387e9a6d 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction;
 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyClusterStatsRequestBuilder extends ClusterStatsRequestBuilder {
 
   public ProxyClusterStatsRequestBuilder(Client client) {
-    super(client.admin().cluster());
+    super(client.admin().cluster(), ClusterStatsAction.INSTANCE);
   }
 
   @Override
@@ -67,7 +68,7 @@ public class ProxyClusterStatsRequestBuilder extends ClusterStatsRequestBuilder
   public String toString() {
     StringBuilder message = new StringBuilder();
     message.append("ES cluster stats request");
-    if (request.nodesIds().length > 0) {
+    if (request.nodesIds() != null) {
       message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
     }
     return message.toString();
index 627f395650de232331fc33e8cb409c917e83aeb2..9c36df38502c6f34b3b499d587cde088ac44b8d4 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.count.CountAction;
 import org.elasticsearch.action.count.CountRequestBuilder;
 import org.elasticsearch.action.count.CountResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyCountRequestBuilder extends CountRequestBuilder {
 
   public ProxyCountRequestBuilder(Client client) {
-    super(client);
+    super(client, CountAction.INSTANCE);
   }
 
   @Override
index 2c7092d035cdb223a7493e6b7bce97a41a08b814..8b1ca4d25cb735785c78fcb9bc89921b106aead8 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
 import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
 import org.elasticsearch.client.Client;
@@ -32,7 +33,7 @@ public class ProxyCreateIndexRequestBuilder extends CreateIndexRequestBuilder {
   private final String index;
 
   public ProxyCreateIndexRequestBuilder(Client client, String index) {
-    super(client.admin().indices(), index);
+    super(client.admin().indices(), CreateIndexAction.INSTANCE, index);
     this.index = index;
   }
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilder.java
deleted file mode 100644 (file)
index d0b3b0c..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.es.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.common.xcontent.ToXContent;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.server.es.EsClient;
-
-import java.io.IOException;
-
-public class ProxyDeleteByQueryRequestBuilder extends DeleteByQueryRequestBuilder {
-
-  private QueryBuilder internalBuilder;
-
-  public ProxyDeleteByQueryRequestBuilder(Client client) {
-    super(client);
-  }
-
-  @Override
-  public DeleteByQueryResponse get() {
-    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
-    try {
-      return super.execute().actionGet();
-    } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
-    } finally {
-      if (profiler.isTraceEnabled()) {
-        profiler.stopTrace(toString());
-      }
-    }
-  }
-
-  @Override
-  public DeleteByQueryResponse get(TimeValue timeout) {
-    throw new UnsupportedOperationException("Not yet implemented");
-  }
-
-  @Override
-  public DeleteByQueryResponse get(String timeout) {
-    throw new UnsupportedOperationException("Not yet implemented");
-  }
-
-  @Override
-  public ListenableActionFuture<DeleteByQueryResponse> execute() {
-    throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
-  }
-
-  @Override
-  public DeleteByQueryRequestBuilder setQuery(QueryBuilder queryBuilder) {
-    this.internalBuilder = queryBuilder;
-    return super.setQuery(queryBuilder);
-  }
-
-  @Override
-  public String toString() {
-    StringBuilder message = new StringBuilder();
-    message.append(String.format("ES delete by query request '%s'", xContentToString(internalBuilder)));
-    if (request.indices().length > 0) {
-      message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
-    }
-    return message.toString();
-  }
-
-  private String xContentToString(ToXContent toXContent) {
-    if (internalBuilder == null) {
-      return "";
-    }
-    try {
-      XContentBuilder builder = XContentFactory.jsonBuilder();
-      toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
-      return builder.string();
-    } catch (IOException e) {
-      throw new IllegalStateException("Fail to convert request to string", e);
-    }
-  }
-}
index a7c2823e929ce448d65fd3be1df4d8ca7e89d024..b27d7ccd62cc058a18307a6b31bc3d5f06d3a6a7 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.delete.DeleteAction;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
 import org.elasticsearch.action.delete.DeleteResponse;
 import org.elasticsearch.client.Client;
@@ -30,7 +31,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyDeleteRequestBuilder extends DeleteRequestBuilder {
 
   public ProxyDeleteRequestBuilder(Client client, String index) {
-    super(client, index);
+    super(client, DeleteAction.INSTANCE, index);
   }
 
   @Override
index 83dc6f4f8629ad7e960f01935719837914470735..581740f66b3affa1364b8c285fb181f4a0762739 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.flush.FlushAction;
 import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
 import org.elasticsearch.action.admin.indices.flush.FlushResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyFlushRequestBuilder extends FlushRequestBuilder {
 
   public ProxyFlushRequestBuilder(Client client) {
-    super(client.admin().indices());
+    super(client.admin().indices(), FlushAction.INSTANCE);
   }
 
   @Override
index ddc7f3022431ace9c157a142a2aa565712af41d3..f0ca32b9dd2b3eb7bab839d2789e2d8096ca5641 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.get.GetAction;
 import org.elasticsearch.action.get.GetRequestBuilder;
 import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.client.Client;
@@ -30,7 +31,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyGetRequestBuilder extends GetRequestBuilder {
 
   public ProxyGetRequestBuilder(Client client) {
-    super(client);
+    super(client, GetAction.INSTANCE);
   }
 
   @Override
index 8679031514b21ef88b70d496f1a7d5a89cecb5e8..9f952f873ed93c16ba23294512d729f0e3b38a2e 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.index.IndexAction;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.client.Client;
@@ -30,7 +31,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyIndexRequestBuilder extends IndexRequestBuilder {
 
   public ProxyIndexRequestBuilder(Client client) {
-    super(client);
+    super(client, IndexAction.INSTANCE);
   }
 
   @Override
index b969f159b5cac06e3e8b559c7edda071517ba80f..6c4bec2e26ffff7684919841112b7c1e04178f10 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction;
 import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
 import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyIndicesExistsRequestBuilder extends IndicesExistsRequestBuilder {
 
   public ProxyIndicesExistsRequestBuilder(Client client, String... indices) {
-    super(client.admin().indices(), indices);
+    super(client.admin().indices(), IndicesExistsAction.INSTANCE, indices);
   }
 
   @Override
index 60928b1b7c2193be4609231e9c74e3cc5c279f01..993640422f2cea8b5edb3746134c17499f2ae2ee 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyIndicesStatsRequestBuilder extends IndicesStatsRequestBuilder {
 
   public ProxyIndicesStatsRequestBuilder(Client client) {
-    super(client.admin().indices());
+    super(client.admin().indices(), IndicesStatsAction.INSTANCE);
   }
 
   @Override
index b0ca86f9f77d89dbc2bcfa25c3045e3165e491c6..01b9bafe773fde9d94ea1f2674d097867c724678 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.get.MultiGetAction;
 import org.elasticsearch.action.get.MultiGetRequest;
 import org.elasticsearch.action.get.MultiGetRequestBuilder;
 import org.elasticsearch.action.get.MultiGetResponse;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyMultiGetRequestBuilder extends MultiGetRequestBuilder {
 
   public ProxyMultiGetRequestBuilder(Client client) {
-    super(client);
+    super(client, MultiGetAction.INSTANCE);
   }
 
   @Override
index 130b2f13502e3b5571a576985296045e38af0abd..9a65924cca25f4b0832d40e75ee9266d3ad11d6e 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction;
 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyNodesStatsRequestBuilder extends NodesStatsRequestBuilder {
 
   public ProxyNodesStatsRequestBuilder(Client client) {
-    super(client.admin().cluster());
+    super(client.admin().cluster(), NodesStatsAction.INSTANCE);
   }
 
   @Override
index 0861d115929f872dd47dfac80fd6c6fd267f9ff2..d05f1dd4f6704bc6702e482041bce1189645e5c0 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyPutMappingRequestBuilder extends PutMappingRequestBuilder {
 
   public ProxyPutMappingRequestBuilder(Client client) {
-    super(client.admin().indices());
+    super(client.admin().indices(), PutMappingAction.INSTANCE);
   }
 
   @Override
index 7f1d2d46049c95b6fc3d58a3da2c88e5b93bde5e..abd5924333c809051b564f49efffdddfc2344056 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
 import org.elasticsearch.client.Client;
@@ -31,7 +32,7 @@ import org.sonar.server.es.EsClient;
 public class ProxyRefreshRequestBuilder extends RefreshRequestBuilder {
 
   public ProxyRefreshRequestBuilder(Client client) {
-    super(client.admin().indices());
+    super(client.admin().indices(), RefreshAction.INSTANCE);
   }
 
   @Override
index 9ddd7fb3e3b1bdbac0968e0407ae2d6e389f4f81..0129b5c480040a3471aa57dacc261d7c7d0b52f9 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.es.request;
 import java.io.IOException;
 import java.util.Arrays;
 import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.search.SearchAction;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.client.Client;
@@ -35,7 +36,7 @@ import org.sonar.server.es.EsClient;
 public class ProxySearchRequestBuilder extends SearchRequestBuilder {
 
   public ProxySearchRequestBuilder(Client client) {
-    super(client);
+    super(client, SearchAction.INSTANCE);
   }
 
   @Override
index ca961b07e9b2190add0188309c37650b90eab5bf..f157bc040a0ee45ba877c31de8bd239e40a86405 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.es.request;
 
 import org.elasticsearch.action.ListenableActionFuture;
 import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchScrollAction;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.unit.TimeValue;
@@ -30,7 +31,7 @@ import org.sonar.server.es.EsClient;
 public class ProxySearchScrollRequestBuilder extends SearchScrollRequestBuilder {
 
   public ProxySearchScrollRequestBuilder(String scrollId, Client client) {
-    super(client, scrollId);
+    super(client, SearchScrollAction.INSTANCE, scrollId);
   }
 
   @Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDoc.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDoc.java
new file mode 100644 (file)
index 0000000..0ec8da3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.issue.index;
+
+import com.google.common.collect.Maps;
+import org.sonar.server.es.BaseDoc;
+
+public class IssueAuthorizationDoc extends BaseDoc {
+
+  public IssueAuthorizationDoc() {
+    super(Maps.<String, Object>newHashMap());
+  }
+
+  @Override
+  public String getId() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getRouting() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
+  public String projectUuid() {
+    return getField(IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID);
+  }
+
+  public IssueAuthorizationDoc setProjectUuid(String s) {
+    setField(IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID, s);
+    return this;
+  }
+}
index dc13c48a25c069fbdfdffc9e4d64aa20be008fc7..676942313f3410250e98c5afd51cd85bd2071285 100644 (file)
@@ -87,6 +87,7 @@ public class IssueAuthorizationIndexer extends BaseIndexer {
     esClient
       .prepareDelete(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, uuid)
       .setRefresh(refresh)
+      .setRouting(uuid)
       .get();
   }
 
index e43853c91347c4dd26e5deaf5ec11cc978a68632..8984c4e86cbd8e93cf196e8df3f1d622041000ca 100644 (file)
@@ -47,6 +47,21 @@ public class IssueDoc extends BaseDoc implements Issue {
     super(Maps.<String, Object>newHashMap());
   }
 
+  @Override
+  public String getId() {
+    return key();
+  }
+
+  @Override
+  public String getRouting() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getParent() {
+    return projectUuid();
+  }
+
   @Override
   public String key() {
     return getField(IssueIndexDefinition.FIELD_ISSUE_KEY);
index 6b4f76a60647ac9e6bdf0f3ac9d00e9e147ebafd..6f16aab83b52200fc1365f0c6cab7e2fc88e024e 100644 (file)
@@ -45,10 +45,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.BoolFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.OrFilterBuilder;
+import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.aggregations.AggregationBuilder;
@@ -56,7 +53,7 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
 import org.elasticsearch.search.aggregations.bucket.global.Global;
 import org.elasticsearch.search.aggregations.bucket.global.GlobalBuilder;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram;
+import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
 import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
@@ -83,6 +80,11 @@ import org.sonar.server.user.UserSession;
 import org.sonar.server.view.index.ViewIndexDefinition;
 
 import static com.google.common.collect.Lists.newArrayList;
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
+import static org.elasticsearch.index.query.QueryBuilders.existsQuery;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
 import static org.sonarqube.ws.client.issue.IssueFilterParameters.ASSIGNEES;
 import static org.sonarqube.ws.client.issue.IssueFilterParameters.AUTHORS;
 import static org.sonarqube.ws.client.issue.IssueFilterParameters.CREATED_AT;
@@ -215,16 +217,16 @@ public class IssueIndex extends BaseIndex {
     configureSorting(query, requestBuilder);
     configurePagination(options, requestBuilder);
 
-    QueryBuilder esQuery = QueryBuilders.matchAllQuery();
-    BoolFilterBuilder esFilter = FilterBuilders.boolFilter();
-    Map<String, FilterBuilder> filters = createFilters(query);
-    for (FilterBuilder filter : filters.values()) {
+    QueryBuilder esQuery = matchAllQuery();
+    BoolQueryBuilder esFilter = boolQuery();
+    Map<String, QueryBuilder> filters = createFilters(query);
+    for (QueryBuilder filter : filters.values()) {
       if (filter != null) {
         esFilter.must(filter);
       }
     }
     if (esFilter.hasClauses()) {
-      requestBuilder.setQuery(QueryBuilders.filteredQuery(esQuery, esFilter));
+      requestBuilder.setQuery(boolQuery().must(esQuery).filter(esFilter));
     } else {
       requestBuilder.setQuery(esQuery);
     }
@@ -243,27 +245,27 @@ public class IssueIndex extends BaseIndex {
     }
   }
 
-  protected void configurePagination(SearchOptions options, SearchRequestBuilder esSearch) {
+  private void configurePagination(SearchOptions options, SearchRequestBuilder esSearch) {
     esSearch.setFrom(options.getOffset()).setSize(options.getLimit());
   }
 
-  private Map<String, FilterBuilder> createFilters(IssueQuery query) {
-    Map<String, FilterBuilder> filters = new HashMap<>();
+  private Map<String, QueryBuilder> createFilters(IssueQuery query) {
+    Map<String, QueryBuilder> filters = new HashMap<>();
     filters.put("__authorization", createAuthorizationFilter(query.checkAuthorization(), query.userLogin(), query.userGroups()));
 
     // Issue is assigned Filter
     if (BooleanUtils.isTrue(query.assigned())) {
-      filters.put(IS_ASSIGNED_FILTER, FilterBuilders.existsFilter(IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE));
+      filters.put(IS_ASSIGNED_FILTER, existsQuery(IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE));
     } else if (BooleanUtils.isFalse(query.assigned())) {
-      filters.put(IS_ASSIGNED_FILTER, FilterBuilders.missingFilter(IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE));
+      filters.put(IS_ASSIGNED_FILTER, boolQuery().mustNot(existsQuery(IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE)));
     }
 
     // Issue is Resolved Filter
     String isResolved = "__isResolved";
     if (BooleanUtils.isTrue(query.resolved())) {
-      filters.put(isResolved, FilterBuilders.existsFilter(IssueIndexDefinition.FIELD_ISSUE_RESOLUTION));
+      filters.put(isResolved, existsQuery(IssueIndexDefinition.FIELD_ISSUE_RESOLUTION));
     } else if (BooleanUtils.isFalse(query.resolved())) {
-      filters.put(isResolved, FilterBuilders.missingFilter(IssueIndexDefinition.FIELD_ISSUE_RESOLUTION));
+      filters.put(isResolved, boolQuery().mustNot(existsQuery(IssueIndexDefinition.FIELD_ISSUE_RESOLUTION)));
     }
 
     // Field Filters
@@ -286,14 +288,14 @@ public class IssueIndex extends BaseIndex {
     return filters;
   }
 
-  private void addComponentRelatedFilters(IssueQuery query, Map<String, FilterBuilder> filters) {
-    FilterBuilder viewFilter = createViewFilter(query.viewUuids());
-    FilterBuilder componentFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, query.componentUuids());
-    FilterBuilder projectFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID, query.projectUuids());
-    FilterBuilder moduleRootFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, query.moduleRootUuids());
-    FilterBuilder moduleFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID, query.moduleUuids());
-    FilterBuilder directoryFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_DIRECTORY_PATH, query.directories());
-    FilterBuilder fileFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, query.fileUuids());
+  private void addComponentRelatedFilters(IssueQuery query, Map<String, QueryBuilder> filters) {
+    QueryBuilder viewFilter = createViewFilter(query.viewUuids());
+    QueryBuilder componentFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, query.componentUuids());
+    QueryBuilder projectFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID, query.projectUuids());
+    QueryBuilder moduleRootFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, query.moduleRootUuids());
+    QueryBuilder moduleFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID, query.moduleUuids());
+    QueryBuilder directoryFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_DIRECTORY_PATH, query.directories());
+    QueryBuilder fileFilter = createTermsFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, query.fileUuids());
 
     if (BooleanUtils.isTrue(query.onComponentOnly())) {
       filters.put(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, componentFilter);
@@ -312,68 +314,56 @@ public class IssueIndex extends BaseIndex {
   }
 
   @CheckForNull
-  private FilterBuilder createViewFilter(Collection<String> viewUuids) {
+  private QueryBuilder createViewFilter(Collection<String> viewUuids) {
     if (viewUuids.isEmpty()) {
       return null;
     }
 
-    OrFilterBuilder viewsFilter = FilterBuilders.orFilter();
+    BoolQueryBuilder viewsFilter = boolQuery();
     for (String viewUuid : viewUuids) {
-      viewsFilter.add(FilterBuilders.termsLookupFilter(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID)
+      viewsFilter.should(QueryBuilders.termsLookupQuery(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID)
         .lookupIndex(ViewIndexDefinition.INDEX)
         .lookupType(ViewIndexDefinition.TYPE_VIEW)
         .lookupId(viewUuid)
-        .lookupPath(ViewIndexDefinition.FIELD_PROJECTS))
-        .cacheKey(viewsLookupCacheKey(viewUuid));
+        .lookupPath(ViewIndexDefinition.FIELD_PROJECTS));
     }
     return viewsFilter;
   }
 
-  public static String viewsLookupCacheKey(String viewUuid) {
-    return String.format("%s%s%s", IssueIndexDefinition.TYPE_ISSUE, viewUuid, ViewIndexDefinition.TYPE_VIEW);
-  }
-
-  private static FilterBuilder createAuthorizationFilter(boolean checkAuthorization, @Nullable String userLogin, Set<String> userGroups) {
+  private static QueryBuilder createAuthorizationFilter(boolean checkAuthorization, @Nullable String userLogin, Set<String> userGroups) {
     if (checkAuthorization) {
-      OrFilterBuilder groupsAndUser = FilterBuilders.orFilter();
+      BoolQueryBuilder groupsAndUser = boolQuery();
       if (userLogin != null) {
-        groupsAndUser.add(FilterBuilders.termFilter(IssueIndexDefinition.FIELD_AUTHORIZATION_USERS, userLogin));
+        groupsAndUser.should(termQuery(IssueIndexDefinition.FIELD_AUTHORIZATION_USERS, userLogin));
       }
       for (String group : userGroups) {
-        groupsAndUser.add(FilterBuilders.termFilter(IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS, group));
+        groupsAndUser.should(termQuery(IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS, group));
       }
-      return FilterBuilders.hasParentFilter(IssueIndexDefinition.TYPE_AUTHORIZATION,
-        QueryBuilders.filteredQuery(
-          QueryBuilders.matchAllQuery(),
-          FilterBuilders.boolFilter()
-            .must(groupsAndUser)
-            .cache(true)));
-    } else {
-      return FilterBuilders.matchAllFilter();
+      return QueryBuilders.hasParentQuery(IssueIndexDefinition.TYPE_AUTHORIZATION,
+        QueryBuilders.boolQuery().must(matchAllQuery()).filter(groupsAndUser));
     }
+    return matchAllQuery();
   }
 
-  private void addDatesFilter(Map<String, FilterBuilder> filters, IssueQuery query) {
+  private void addDatesFilter(Map<String, QueryBuilder> filters, IssueQuery query) {
     Date createdAfter = query.createdAfter();
     Date createdBefore = query.createdBefore();
 
     validateCreationDateBounds(createdBefore, createdAfter);
 
     if (createdAfter != null) {
-      filters.put("__createdAfter", FilterBuilders
-        .rangeFilter(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT)
-        .gte(createdAfter)
-        .cache(false));
+      filters.put("__createdAfter", QueryBuilders
+        .rangeQuery(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT)
+        .gte(createdAfter));
     }
     if (createdBefore != null) {
-      filters.put("__createdBefore", FilterBuilders
-        .rangeFilter(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT)
-        .lt(createdBefore)
-        .cache(false));
+      filters.put("__createdBefore", QueryBuilders
+        .rangeQuery(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT)
+        .lt(createdBefore));
     }
     Date createdAt = query.createdAt();
     if (createdAt != null) {
-      filters.put("__createdAt", FilterBuilders.termFilter(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT, createdAt).cache(false));
+      filters.put("__createdAt", termQuery(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT, createdAt));
     }
   }
 
@@ -384,7 +374,7 @@ public class IssueIndex extends BaseIndex {
       "Start bound cannot be larger than end bound");
   }
 
-  private void configureStickyFacets(IssueQuery query, SearchOptions options, Map<String, FilterBuilder> filters, QueryBuilder esQuery, SearchRequestBuilder esSearch) {
+  private void configureStickyFacets(IssueQuery query, SearchOptions options, Map<String, QueryBuilder> filters, QueryBuilder esQuery, SearchRequestBuilder esSearch) {
     if (!options.getFacets().isEmpty()) {
       StickyFacetBuilder stickyFacetBuilder = newStickyFacetBuilder(query, filters, esQuery);
       // Execute Term aggregations
@@ -431,7 +421,7 @@ public class IssueIndex extends BaseIndex {
     }
   }
 
-  private static StickyFacetBuilder newStickyFacetBuilder(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder esQuery) {
+  private static StickyFacetBuilder newStickyFacetBuilder(IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
     if (hasQueryEffortFacet(query)) {
       return new StickyFacetBuilder(esQuery, filters, EFFORT_AGGREGATION, EFFORT_AGGREGATION_ORDER);
     }
@@ -456,10 +446,10 @@ public class IssueIndex extends BaseIndex {
     return FACET_MODE_EFFORT.equals(query.facetMode()) || DEPRECATED_FACET_MODE_DEBT.equals(query.facetMode());
   }
 
-  private AggregationBuilder getCreatedAtFacet(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder esQuery) {
+  private AggregationBuilder getCreatedAtFacet(IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
     long now = system.now();
 
-    DateHistogram.Interval bucketSize = DateHistogram.Interval.YEAR;
+    DateHistogramInterval bucketSize = DateHistogramInterval.YEAR;
     Date createdAfter = query.createdAfter();
     long startTime = createdAfter == null ? getMinCreatedAt(filters, esQuery) : createdAfter.getTime();
     Date createdBefore = query.createdBefore();
@@ -468,11 +458,11 @@ public class IssueIndex extends BaseIndex {
     Duration timeSpan = new Duration(startTime, endTime);
 
     if (timeSpan.isShorterThan(TWENTY_DAYS)) {
-      bucketSize = DateHistogram.Interval.DAY;
+      bucketSize = DateHistogramInterval.DAY;
     } else if (timeSpan.isShorterThan(TWENTY_WEEKS)) {
-      bucketSize = DateHistogram.Interval.WEEK;
+      bucketSize = DateHistogramInterval.WEEK;
     } else if (timeSpan.isShorterThan(TWENTY_MONTHS)) {
-      bucketSize = DateHistogram.Interval.MONTH;
+      bucketSize = DateHistogramInterval.MONTH;
     }
 
     // from GMT to server TZ
@@ -491,14 +481,14 @@ public class IssueIndex extends BaseIndex {
     return dateHistogram;
   }
 
-  private long getMinCreatedAt(Map<String, FilterBuilder> filters, QueryBuilder esQuery) {
+  private long getMinCreatedAt(Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
     String facetNameAndField = IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT;
     SearchRequestBuilder esRequest = getClient()
       .prepareSearch(IssueIndexDefinition.INDEX)
       .setTypes(IssueIndexDefinition.TYPE_ISSUE)
       .setSize(0);
-    BoolFilterBuilder esFilter = FilterBuilders.boolFilter();
-    for (FilterBuilder filter : filters.values()) {
+    BoolQueryBuilder esFilter = boolQuery();
+    for (QueryBuilder filter : filters.values()) {
       if (filter != null) {
         esFilter.must(filter);
       }
@@ -518,16 +508,16 @@ public class IssueIndex extends BaseIndex {
     }
   }
 
-  private AggregationBuilder createAssigneesFacet(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder queryBuilder) {
+  private AggregationBuilder createAssigneesFacet(IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder queryBuilder) {
     String fieldName = IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE;
     String facetName = ASSIGNEES;
 
     // Same as in super.stickyFacetBuilder
-    Map<String, FilterBuilder> assigneeFilters = Maps.newHashMap(filters);
+    Map<String, QueryBuilder> assigneeFilters = Maps.newHashMap(filters);
     assigneeFilters.remove(IS_ASSIGNED_FILTER);
     assigneeFilters.remove(fieldName);
     StickyFacetBuilder assigneeFacetBuilder = newStickyFacetBuilder(query, assigneeFilters, queryBuilder);
-    BoolFilterBuilder facetFilter = assigneeFacetBuilder.getStickyFacetFilter(fieldName);
+    BoolQueryBuilder facetFilter = assigneeFacetBuilder.getStickyFacetFilter(fieldName);
     FilterAggregationBuilder facetTopAggregation = assigneeFacetBuilder.buildTopFacetAggregation(fieldName, facetName, facetFilter, DEFAULT_FACET_SIZE);
 
     Collection<String> assigneesEscaped = escapeValuesForFacetInclusion(query.assignees());
@@ -555,7 +545,7 @@ public class IssueIndex extends BaseIndex {
     });
   }
 
-  private void addAssignedToMeFacetIfNeeded(SearchRequestBuilder builder, SearchOptions options, IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder queryBuilder) {
+  private void addAssignedToMeFacetIfNeeded(SearchRequestBuilder builder, SearchOptions options, IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder queryBuilder) {
     String login = userSession.getLogin();
 
     if (!options.getFacets().contains(FACET_ASSIGNED_TO_ME) || StringUtils.isEmpty(login)) {
@@ -567,7 +557,7 @@ public class IssueIndex extends BaseIndex {
 
     // Same as in super.stickyFacetBuilder
     StickyFacetBuilder assignedToMeFacetBuilder = newStickyFacetBuilder(query, filters, queryBuilder);
-    BoolFilterBuilder facetFilter = assignedToMeFacetBuilder.getStickyFacetFilter(IS_ASSIGNED_FILTER, fieldName);
+    BoolQueryBuilder facetFilter = assignedToMeFacetBuilder.getStickyFacetFilter(IS_ASSIGNED_FILTER, fieldName);
 
     FilterAggregationBuilder facetTopAggregation = AggregationBuilders
       .filter(facetName + "__filter")
@@ -579,16 +569,16 @@ public class IssueIndex extends BaseIndex {
         .subAggregation(facetTopAggregation));
   }
 
-  private static AggregationBuilder createResolutionFacet(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder esQuery) {
+  private static AggregationBuilder createResolutionFacet(IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
     String fieldName = IssueIndexDefinition.FIELD_ISSUE_RESOLUTION;
     String facetName = RESOLUTIONS;
 
     // Same as in super.stickyFacetBuilder
-    Map<String, FilterBuilder> resolutionFilters = Maps.newHashMap(filters);
+    Map<String, QueryBuilder> resolutionFilters = Maps.newHashMap(filters);
     resolutionFilters.remove("__isResolved");
     resolutionFilters.remove(fieldName);
     StickyFacetBuilder assigneeFacetBuilder = newStickyFacetBuilder(query, resolutionFilters, esQuery);
-    BoolFilterBuilder facetFilter = assigneeFacetBuilder.getStickyFacetFilter(fieldName);
+    BoolQueryBuilder facetFilter = assigneeFacetBuilder.getStickyFacetFilter(fieldName);
     FilterAggregationBuilder facetTopAggregation = assigneeFacetBuilder.buildTopFacetAggregation(fieldName, facetName, facetFilter, DEFAULT_FACET_SIZE);
     facetTopAggregation = assigneeFacetBuilder.addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation);
 
@@ -604,9 +594,9 @@ public class IssueIndex extends BaseIndex {
   }
 
   @CheckForNull
-  private FilterBuilder createTermsFilter(String field, Collection<?> values) {
+  private QueryBuilder createTermsFilter(String field, Collection<?> values) {
     if (!values.isEmpty()) {
-      return FilterBuilders.termsFilter(field, values);
+      return termsQuery(field, values);
     } else {
       return null;
     }
@@ -617,8 +607,7 @@ public class IssueIndex extends BaseIndex {
       .prepareSearch(IssueIndexDefinition.INDEX, RuleIndexDefinition.INDEX)
       .setTypes(IssueIndexDefinition.TYPE_ISSUE, RuleIndexDefinition.TYPE_RULE);
 
-    requestBuilder.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
-      createBoolFilter(query)));
+    requestBuilder.setQuery(boolQuery().must(matchAllQuery()).filter(createBoolFilter(query)));
 
     GlobalBuilder topAggreg = AggregationBuilders.global("tags");
     String tagsOnIssuesSubAggregation = "tags__issues";
@@ -669,8 +658,7 @@ public class IssueIndex extends BaseIndex {
       .setSize(0)
       .setTypes(IssueIndexDefinition.TYPE_ISSUE);
 
-    requestBuilder.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
-      createBoolFilter(query)));
+    requestBuilder.setQuery(boolQuery().must(QueryBuilders.matchAllQuery()).filter(createBoolFilter(query)));
 
     TermsBuilder aggreg = AggregationBuilders.terms("_ref")
       .field(fieldName)
@@ -685,15 +673,14 @@ public class IssueIndex extends BaseIndex {
     return searchResponse.getAggregations().get("_ref");
   }
 
-  private BoolFilterBuilder createBoolFilter(IssueQuery query) {
-    BoolFilterBuilder boolFilter = FilterBuilders.boolFilter();
-    for (FilterBuilder filter : createFilters(query).values()) {
-      // TODO Can it be null ?
+  private BoolQueryBuilder createBoolFilter(IssueQuery query) {
+    BoolQueryBuilder boolQuery = boolQuery();
+    for (QueryBuilder filter : createFilters(query).values()) {
       if (filter != null) {
-        boolFilter.must(filter);
+        boolQuery.must(filter);
       }
     }
-    return boolFilter;
+    return boolQuery;
   }
 
   /**
@@ -701,16 +688,16 @@ public class IssueIndex extends BaseIndex {
    * Only fields needed for the batch are returned.
    */
   public Iterator<IssueDoc> selectIssuesForBatch(ComponentDto component) {
-    BoolFilterBuilder filter = FilterBuilders.boolFilter()
+    BoolQueryBuilder filter = boolQuery()
       .must(createAuthorizationFilter(true, userSession.getLogin(), userSession.getUserGroups()))
-      .mustNot(FilterBuilders.termsFilter(IssueIndexDefinition.FIELD_ISSUE_STATUS, Issue.STATUS_CLOSED));
+      .mustNot(termsQuery(IssueIndexDefinition.FIELD_ISSUE_STATUS, Issue.STATUS_CLOSED));
 
     switch (component.scope()) {
       case Scopes.PROJECT:
-        filter.must(FilterBuilders.termsFilter(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, component.uuid()));
+        filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, component.uuid()));
         break;
       case Scopes.FILE:
-        filter.must(FilterBuilders.termsFilter(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, component.uuid()));
+        filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, component.uuid()));
         break;
       default:
         throw new IllegalStateException(String.format("Component of scope '%s' is not allowed", component.scope()));
@@ -721,7 +708,7 @@ public class IssueIndex extends BaseIndex {
       .setTypes(IssueIndexDefinition.TYPE_ISSUE)
       .setSearchType(SearchType.SCAN)
       .setScroll(TimeValue.timeValueMinutes(EsUtils.SCROLL_TIME_IN_MINUTES))
-      .setSize(10000)
+      .setSize(10_000)
       .setFetchSource(
         new String[] {IssueIndexDefinition.FIELD_ISSUE_KEY, IssueIndexDefinition.FIELD_ISSUE_RULE_KEY, IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID,
           IssueIndexDefinition.FIELD_ISSUE_FILE_PATH, IssueIndexDefinition.FIELD_ISSUE_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_MANUAL_SEVERITY,
@@ -729,7 +716,7 @@ public class IssueIndex extends BaseIndex {
           IssueIndexDefinition.FIELD_ISSUE_LINE, IssueIndexDefinition.FIELD_ISSUE_MESSAGE, IssueIndexDefinition.FIELD_ISSUE_CHECKSUM,
           IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT},
         null)
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filter));
+      .setQuery(boolQuery().must(matchAllQuery()).filter(filter));
     SearchResponse response = requestBuilder.get();
 
     return EsUtils.scroll(getClient(), response.getScrollId(), DOC_CONVERTER);
index d0f4ccc40b908c7e35c174a7b7e7dce2d8d59bc5..f26a51b6431c26ef106fc9bf253fa294cf1b986c 100644 (file)
@@ -93,19 +93,10 @@ public class IssueIndexDefinition implements IndexDefinition {
     index.refreshHandledByIndexer();
     index.configureShards(settings);
 
-    // type "authorization"
-    NewIndex.NewIndexType authorizationMapping = index.createType(TYPE_AUTHORIZATION);
-    authorizationMapping.setAttribute("_id", ImmutableMap.of("path", FIELD_AUTHORIZATION_PROJECT_UUID));
-    authorizationMapping.createDateTimeField(FIELD_AUTHORIZATION_UPDATED_AT);
-    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_PROJECT_UUID).disableNorms().build();
-    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_GROUPS).disableNorms().build();
-    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_USERS).disableNorms().build();
-
     // type "issue"
     NewIndex.NewIndexType issueMapping = index.createType(TYPE_ISSUE);
-    issueMapping.setAttribute("_id", ImmutableMap.of("path", FIELD_ISSUE_KEY));
     issueMapping.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION));
-    issueMapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", FIELD_ISSUE_PROJECT_UUID));
+    issueMapping.setAttribute("_routing", ImmutableMap.of("required", "true"));
     issueMapping.stringFieldBuilder(FIELD_ISSUE_ASSIGNEE).enableSorting().build();
     issueMapping.stringFieldBuilder(FIELD_ISSUE_ATTRIBUTES).docValues().disableNorms().disableSearch().build();
     issueMapping.stringFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().docValues().build();
@@ -132,5 +123,13 @@ public class IssueIndexDefinition implements IndexDefinition {
     issueMapping.stringFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
     issueMapping.createDateTimeField(FIELD_ISSUE_TECHNICAL_UPDATED_AT);
     issueMapping.stringFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
+
+    // type "authorization"
+    NewIndex.NewIndexType authorizationMapping = index.createType(TYPE_AUTHORIZATION);
+    authorizationMapping.setAttribute("_routing", ImmutableMap.of("required", "true"));
+    authorizationMapping.createDateTimeField(FIELD_AUTHORIZATION_UPDATED_AT);
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_PROJECT_UUID).disableNorms().build();
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_GROUPS).disableNorms().build();
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_USERS).disableNorms().build();
   }
 }
index 97e747ec8a76acbd5fbbb0c0c4fcbf24a21a3c84..d0e821c4f11a8cdc70dcdf10a0111c80705fff44 100644 (file)
@@ -25,21 +25,24 @@ import javax.annotation.Nullable;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.QueryBuilders;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
+import org.sonar.server.es.EsUtils;
 
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID;
 import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT;
 import static org.sonar.server.issue.index.IssueIndexDefinition.INDEX;
+import static org.sonar.server.issue.index.IssueIndexDefinition.TYPE_AUTHORIZATION;
 import static org.sonar.server.issue.index.IssueIndexDefinition.TYPE_ISSUE;
 
 public class IssueIndexer extends BaseIndexer {
 
+  private static final String DELETE_ERROR_MESSAGE = "Fail to delete some issues of project [%s]";
   private static final int MAX_BATCH_SIZE = 1000;
 
   private final DbClient dbClient;
@@ -106,16 +109,14 @@ public class IssueIndexer extends BaseIndexer {
     bulk.setDisableRefresh(false);
     bulk.start();
     SearchRequestBuilder search = esClient.prepareSearch(INDEX)
+      .setTypes(TYPE_ISSUE, TYPE_AUTHORIZATION)
       .setRouting(uuid)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(FIELD_ISSUE_PROJECT_UUID, uuid))
-        ));
+      .setQuery(boolQuery().must(termQuery(FIELD_ISSUE_PROJECT_UUID, uuid)));
     bulk.addDeletion(search);
     bulk.stop();
   }
 
-  public void deleteByKeys(List<String> issueKeys){
+  public void deleteByKeys(String projectUuid, List<String> issueKeys) {
     if (issueKeys.isEmpty()) {
       return;
     }
@@ -123,15 +124,17 @@ public class IssueIndexer extends BaseIndexer {
     int count = 0;
     BulkRequestBuilder builder = esClient.prepareBulk();
     for (String issueKey : issueKeys) {
-      builder.add(esClient.prepareDelete(INDEX, TYPE_ISSUE, issueKey));
+      builder.add(esClient.prepareDelete(INDEX, TYPE_ISSUE, issueKey)
+        .setRefresh(false)
+        .setRouting(projectUuid));
       count++;
       if (count >= MAX_BATCH_SIZE) {
-        builder.get();
+        EsUtils.executeBulkRequest(builder, DELETE_ERROR_MESSAGE, projectUuid);
         builder = esClient.prepareBulk();
         count = 0;
       }
     }
-    builder.get();
+    EsUtils.executeBulkRequest(builder, DELETE_ERROR_MESSAGE, projectUuid);
     esClient.prepareRefresh(INDEX).get();
   }
 
index d6b55b2d57332f9365775add8baba0a990b8fbb6..7850e8e0ee96aca3f18b2262403c8193f3f5ecca 100644 (file)
@@ -24,7 +24,6 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Statement;
 import org.apache.commons.dbutils.DbUtils;
-import org.elasticsearch.action.support.IndicesOptions;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.DbSession;
@@ -163,10 +162,7 @@ public class BackendCleanup {
    * Completely remove a index with all types
    */
   public void clearIndex(String indexName) {
-    String[] indicesToClear = esClient.prepareState().get().getState().getMetaData().concreteIndices(IndicesOptions.strictExpand(), indexName);
-    for (String index : indicesToClear) {
-      BulkIndexer.delete(esClient, index, esClient.prepareSearch(index).setQuery(matchAllQuery()));
-    }
+    BulkIndexer.delete(esClient, indexName, esClient.prepareSearch(indexName).setQuery(matchAllQuery()));
   }
 
 }
index 7f37d2b0f314f857d35521e081baff6334977638..69f757c0f231e4565736d0afba03bb50b818e15d 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.server.platform.monitoring;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
 import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
 import org.elasticsearch.action.admin.indices.stats.IndexStats;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.cluster.node.DiscoveryNode;
 import org.elasticsearch.common.breaker.CircuitBreaker;
 import org.sonar.server.es.EsClient;
@@ -105,19 +105,18 @@ public class EsMonitor extends BaseMonitorMBean implements EsMonitorMBean {
       nodeAttributes.put("Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().bytes()));
       nodeAttributes.put("Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes()));
       nodeAttributes.put("Open Files", stats.getProcess().getOpenFileDescriptors());
-      nodeAttributes.put("JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPrecent()));
+      nodeAttributes.put("JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent()));
       nodeAttributes.put("JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().bytes()));
       nodeAttributes.put("JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().bytes()));
       nodeAttributes.put("JVM Non Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getNonHeapUsed().bytes()));
-      nodeAttributes.put("JVM Threads", stats.getJvm().getThreads().count());
+      nodeAttributes.put("JVM Threads", stats.getJvm().getThreads().getCount());
       nodeAttributes.put("Field Data Memory", byteCountToDisplaySize(stats.getIndices().getFieldData().getMemorySizeInBytes()));
-      nodeAttributes.put("Field Data Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.Name.FIELDDATA).getLimit()));
-      nodeAttributes.put("Field Data Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.Name.FIELDDATA).getEstimated()));
-      nodeAttributes.put("Request Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.Name.REQUEST).getLimit()));
-      nodeAttributes.put("Request Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.Name.REQUEST).getEstimated()));
-      nodeAttributes.put("Filter Cache Memory", byteCountToDisplaySize(stats.getIndices().getFilterCache().getMemorySizeInBytes()));
+      nodeAttributes.put("Field Data Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getLimit()));
+      nodeAttributes.put("Field Data Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated()));
+      nodeAttributes.put("Request Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getLimit()));
+      nodeAttributes.put("Request Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getEstimated()));
       nodeAttributes.put("Query Cache Memory", byteCountToDisplaySize(stats.getIndices().getQueryCache().getMemorySizeInBytes()));
-      nodeAttributes.put("ID Cache Memory", byteCountToDisplaySize(stats.getIndices().getIdCache().getMemorySizeInBytes()));
+      nodeAttributes.put("Request Cache Memory", byteCountToDisplaySize(stats.getIndices().getRequestCache().getMemorySizeInBytes()));
       nodeAttributes.put("Query Cache Memory", byteCountToDisplaySize(stats.getIndices().getQueryCache().getMemorySizeInBytes()));
     }
     return nodes;
index bfebf07fd3146d2de8b1d6bec41f0460a58577ac..11b65c2c9cb898ea0380038849cba76fda420da1 100644 (file)
@@ -50,6 +50,21 @@ public class ActiveRuleDoc extends BaseDoc {
     setField(FIELD_ACTIVE_RULE_REPOSITORY, key.ruleKey().repository());
   }
 
+  @Override
+  public String getId() {
+    return key().toString();
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return key.ruleKey().toString();
+  }
+
   public ActiveRuleKey key() {
     return key;
   }
index 1e7c9c16f56411b1d7a9a9d38cb8149391cee70d..9a8b2a843729beabf8bcfda851e62f3a0e7971ce 100644 (file)
@@ -27,8 +27,7 @@ import java.util.Map;
 import javax.annotation.Nullable;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.aggregations.Aggregation;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -64,12 +63,12 @@ public class ActiveRuleIndex extends BaseIndex {
 
   public Map<String, Long> countAllByQualityProfileKey() {
     return countByField(FIELD_ACTIVE_RULE_PROFILE_KEY,
-      FilterBuilders.hasParentFilter(TYPE_RULE,
-        FilterBuilders.notFilter(
-          FilterBuilders.termFilter(FIELD_RULE_STATUS, "REMOVED"))));
+      QueryBuilders.hasParentQuery(TYPE_RULE,
+        QueryBuilders.boolQuery().mustNot(
+          QueryBuilders.termQuery(FIELD_RULE_STATUS, "REMOVED"))));
   }
 
-  private Map<String, Long> countByField(String indexField, FilterBuilder filter) {
+  private Map<String, Long> countByField(String indexField, QueryBuilder filter) {
     Map<String, Long> counts = new HashMap<>();
 
     SearchRequestBuilder request = getClient().prepareSearch(INDEX)
@@ -90,18 +89,17 @@ public class ActiveRuleIndex extends BaseIndex {
     Terms values = response.getAggregations().get(indexField);
 
     for (Terms.Bucket value : values.getBuckets()) {
-      counts.put(value.getKey(), value.getDocCount());
+      counts.put(value.getKeyAsString(), value.getDocCount());
     }
     return counts;
   }
 
   public Map<String, Multimap<String, FacetValue>> getStatsByProfileKeys(List<String> keys) {
     SearchRequestBuilder request = getClient().prepareSearch(INDEX)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, keys),
-        FilterBuilders.boolFilter()
-          .mustNot(FilterBuilders.hasParentFilter(TYPE_RULE,
-            FilterBuilders.termFilter(FIELD_RULE_STATUS, RuleStatus.REMOVED.name())))))
+      .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, keys)).filter(
+        QueryBuilders.boolQuery()
+          .mustNot(QueryBuilders.hasParentQuery(TYPE_RULE,
+            QueryBuilders.termQuery(FIELD_RULE_STATUS, RuleStatus.REMOVED.name())))))
       .addAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_PROFILE_KEY)
         .field(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).size(0)
         .subAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_INHERITANCE)
@@ -115,7 +113,7 @@ public class ActiveRuleIndex extends BaseIndex {
     Map<String, Multimap<String, FacetValue>> stats = new HashMap<>();
     Aggregation aggregation = response.getAggregations().get(FIELD_ACTIVE_RULE_PROFILE_KEY);
     for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
-      stats.put(value.getKey(), processAggregations(value.getAggregations()));
+      stats.put(value.getKeyAsString(), processAggregations(value.getAggregations()));
     }
 
     return stats;
@@ -127,7 +125,7 @@ public class ActiveRuleIndex extends BaseIndex {
       for (Aggregation aggregation : aggregations.asList()) {
         if (aggregation instanceof StringTerms) {
           for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
-            FacetValue facetValue = new FacetValue(value.getKey(), value.getDocCount());
+            FacetValue facetValue = new FacetValue(value.getKeyAsString(), value.getDocCount());
             stats.put(aggregation.getName(), facetValue);
           }
         } else if (aggregation instanceof InternalValueCount) {
index 4337e9eaad290786fc3cc92f57992b22fc28fd6c..29d1f9a5901e0fffc28930a428179886b0433549 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -36,8 +35,10 @@ import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 import org.sonar.server.qualityprofile.ActiveRuleChange;
-import org.sonar.server.rule.index.RuleIndexDefinition;
 
+import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT;
 import static org.sonar.server.rule.index.RuleIndexDefinition.INDEX;
 import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
@@ -100,10 +101,7 @@ public class ActiveRuleIndexer extends BaseIndexer {
     bulk.start();
     SearchRequestBuilder search = esClient.prepareSearch(INDEX)
       .setTypes(TYPE_ACTIVE_RULE)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY, qualityProfileKey))
-        ));
+      .setQuery(QueryBuilders.boolQuery().must(termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, qualityProfileKey)));
     bulk.addDeletion(search);
     bulk.stop();
   }
@@ -113,10 +111,7 @@ public class ActiveRuleIndexer extends BaseIndexer {
     bulk.start();
     SearchRequestBuilder search = esClient.prepareSearch(INDEX)
       .setTypes(TYPE_ACTIVE_RULE)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY, keys))
-        ));
+      .setQuery(QueryBuilders.boolQuery().must(termsQuery(FIELD_ACTIVE_RULE_KEY, keys)));
     bulk.addDeletion(search);
     bulk.stop();
   }
@@ -130,7 +125,6 @@ public class ActiveRuleIndexer extends BaseIndexer {
   private static IndexRequest newIndexRequest(ActiveRuleDoc doc) {
     return new IndexRequest(INDEX, TYPE_ACTIVE_RULE, doc.key().toString())
       .parent(doc.key().ruleKey().toString())
-      .routing(doc.key().ruleKey().repository())
       .source(doc.getFields());
   }
 
index 0f20bb301bb788b7026f8ff316ccae0768c9cf05..c29f1d92ed32dfe7ac9e49cecf92e8facf042d69 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.rule.index;
 
+import com.google.common.collect.Maps;
 import java.util.Collection;
 import java.util.Map;
 import javax.annotation.CheckForNull;
@@ -38,6 +39,25 @@ public class RuleDoc extends BaseDoc {
     super(fields);
   }
 
+  public RuleDoc() {
+    super(Maps.<String, Object>newHashMap());
+  }
+
+  @Override
+  public String getId() {
+    return key().toString();
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   public RuleKey key() {
     return RuleKey.parse(this.<String>getField(RuleIndexDefinition.FIELD_RULE_KEY));
   }
index ae5c60bd87d58bddf6fe107904330422178f4160..d7fe053024f38a6e43e63bab0d6d8af1e19d1a05 100644 (file)
@@ -40,11 +40,8 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.BoolFilterBuilder;
 import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.HasParentFilterBuilder;
+import org.elasticsearch.index.query.HasParentQueryBuilder;
 import org.elasticsearch.index.query.MatchQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -66,6 +63,7 @@ import org.sonar.server.es.SearchIdResult;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.StickyFacetBuilder;
 
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
 import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
 import static org.elasticsearch.index.query.QueryBuilders.simpleQueryStringQuery;
 import static org.sonar.server.es.EsUtils.SCROLL_TIME_IN_MINUTES;
@@ -120,7 +118,7 @@ public class RuleIndex extends BaseIndex {
       .setTypes(TYPE_RULE);
 
     QueryBuilder qb = buildQuery(query);
-    Map<String, FilterBuilder> filters = buildFilters(query);
+    Map<String, QueryBuilder> filters = buildFilters(query);
 
     if (!options.getFacets().isEmpty()) {
       for (AggregationBuilder aggregation : getFacets(query, options, qb, filters).values()) {
@@ -131,12 +129,12 @@ public class RuleIndex extends BaseIndex {
     setSorting(query, esSearch);
     setPagination(options, esSearch);
 
-    BoolFilterBuilder fb = FilterBuilders.boolFilter();
-    for (FilterBuilder filterBuilder : filters.values()) {
+    BoolQueryBuilder fb = boolQuery();
+    for (QueryBuilder filterBuilder : filters.values()) {
       fb.must(filterBuilder);
     }
 
-    esSearch.setQuery(QueryBuilders.filteredQuery(qb, fb));
+    esSearch.setQuery(boolQuery().must(qb).filter(fb));
     return new SearchIdResult<>(esSearch.get(), ToRuleKey.INSTANCE);
   }
 
@@ -151,15 +149,15 @@ public class RuleIndex extends BaseIndex {
       .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES));
 
     QueryBuilder qb = buildQuery(query);
-    Map<String, FilterBuilder> filters = buildFilters(query);
+    Map<String, QueryBuilder> filters = buildFilters(query);
     setSorting(query, esSearch);
 
-    BoolFilterBuilder fb = FilterBuilders.boolFilter();
-    for (FilterBuilder filterBuilder : filters.values()) {
+    BoolQueryBuilder fb = boolQuery();
+    for (QueryBuilder filterBuilder : filters.values()) {
       fb.must(filterBuilder);
     }
 
-    esSearch.setQuery(QueryBuilders.filteredQuery(qb, fb));
+    esSearch.setQuery(boolQuery().must(qb).filter(fb));
     SearchResponse response = esSearch.get();
     return scrollIds(getClient(), response.getScrollId(), ToRuleKey.INSTANCE);
   }
@@ -174,7 +172,7 @@ public class RuleIndex extends BaseIndex {
     }
 
     // Build RuleBased contextual query
-    BoolQueryBuilder qb = QueryBuilders.boolQuery();
+    BoolQueryBuilder qb = boolQuery();
     String queryString = query.getQueryText();
 
     // Human readable type of querying
@@ -210,58 +208,58 @@ public class RuleIndex extends BaseIndex {
   }
 
   /* Build main filter (match based) */
-  private static Map<String, FilterBuilder> buildFilters(RuleQuery query) {
+  private static Map<String, QueryBuilder> buildFilters(RuleQuery query) {
 
-    Map<String, FilterBuilder> filters = new HashMap<>();
+    Map<String, QueryBuilder> filters = new HashMap<>();
 
     /* Add enforced filter on rules that are REMOVED */
     filters.put(FIELD_RULE_STATUS,
-      FilterBuilders.boolFilter().mustNot(
-        FilterBuilders.termFilter(FIELD_RULE_STATUS,
+      boolQuery().mustNot(
+        QueryBuilders.termQuery(FIELD_RULE_STATUS,
           RuleStatus.REMOVED.toString())));
 
     if (StringUtils.isNotEmpty(query.getInternalKey())) {
       filters.put(FIELD_RULE_INTERNAL_KEY,
-        FilterBuilders.termFilter(FIELD_RULE_INTERNAL_KEY, query.getInternalKey()));
+        QueryBuilders.termQuery(FIELD_RULE_INTERNAL_KEY, query.getInternalKey()));
     }
 
     if (StringUtils.isNotEmpty(query.getRuleKey())) {
       filters.put(FIELD_RULE_RULE_KEY,
-        FilterBuilders.termFilter(FIELD_RULE_RULE_KEY, query.getRuleKey()));
+        QueryBuilders.termQuery(FIELD_RULE_RULE_KEY, query.getRuleKey()));
     }
 
     if (isNotEmpty(query.getLanguages())) {
       filters.put(FIELD_RULE_LANGUAGE,
-        FilterBuilders.termsFilter(FIELD_RULE_LANGUAGE, query.getLanguages()));
+        QueryBuilders.termsQuery(FIELD_RULE_LANGUAGE, query.getLanguages()));
     }
 
     if (isNotEmpty(query.getRepositories())) {
       filters.put(FIELD_RULE_REPOSITORY,
-        FilterBuilders.termsFilter(FIELD_RULE_REPOSITORY, query.getRepositories()));
+        QueryBuilders.termsQuery(FIELD_RULE_REPOSITORY, query.getRepositories()));
     }
 
     if (isNotEmpty(query.getSeverities())) {
       filters.put(FIELD_RULE_SEVERITY,
-        FilterBuilders.termsFilter(FIELD_RULE_SEVERITY, query.getSeverities()));
+        QueryBuilders.termsQuery(FIELD_RULE_SEVERITY, query.getSeverities()));
     }
 
     if (StringUtils.isNotEmpty(query.getKey())) {
       filters.put(FIELD_RULE_KEY,
-        FilterBuilders.termFilter(FIELD_RULE_KEY, query.getKey()));
+        QueryBuilders.termQuery(FIELD_RULE_KEY, query.getKey()));
     }
 
     if (isNotEmpty(query.getTags())) {
       filters.put(FIELD_RULE_ALL_TAGS,
-        FilterBuilders.termsFilter(FIELD_RULE_ALL_TAGS, query.getTags()));
+        QueryBuilders.termsQuery(FIELD_RULE_ALL_TAGS, query.getTags()));
     }
 
     if (isNotEmpty(query.getTypes())) {
       filters.put(FIELD_RULE_TYPE,
-        FilterBuilders.termsFilter(FIELD_RULE_TYPE, query.getTypes()));
+        QueryBuilders.termsQuery(FIELD_RULE_TYPE, query.getTypes()));
     }
 
     if (query.getAvailableSinceLong() != null) {
-      filters.put("availableSince", FilterBuilders.rangeFilter(FIELD_RULE_CREATED_AT)
+      filters.put("availableSince", QueryBuilders.rangeQuery(FIELD_RULE_CREATED_AT)
         .gte(query.getAvailableSinceLong()));
     }
 
@@ -271,55 +269,55 @@ public class RuleIndex extends BaseIndex {
         stringStatus.add(status.name());
       }
       filters.put(FIELD_RULE_STATUS,
-        FilterBuilders.termsFilter(FIELD_RULE_STATUS, stringStatus));
+        QueryBuilders.termsQuery(FIELD_RULE_STATUS, stringStatus));
     }
 
     Boolean isTemplate = query.isTemplate();
     if (isTemplate != null) {
       filters.put(FIELD_RULE_IS_TEMPLATE,
-        FilterBuilders.termFilter(FIELD_RULE_IS_TEMPLATE, Boolean.toString(isTemplate)));
+        QueryBuilders.termQuery(FIELD_RULE_IS_TEMPLATE, Boolean.toString(isTemplate)));
     }
 
     String template = query.templateKey();
     if (template != null) {
       filters.put(FIELD_RULE_TEMPLATE_KEY,
-        FilterBuilders.termFilter(FIELD_RULE_TEMPLATE_KEY, template));
+        QueryBuilders.termQuery(FIELD_RULE_TEMPLATE_KEY, template));
     }
 
     // ActiveRule Filter (profile and inheritance)
-    BoolFilterBuilder childrenFilter = FilterBuilders.boolFilter();
+    BoolQueryBuilder childrenFilter = boolQuery();
     addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_PROFILE_KEY, query.getQProfileKey());
     addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
     addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_SEVERITY, query.getActiveSeverities());
 
     // ChildQuery
-    FilterBuilder childQuery;
+    QueryBuilder childQuery;
     if (childrenFilter.hasClauses()) {
       childQuery = childrenFilter;
     } else {
-      childQuery = FilterBuilders.matchAllFilter();
+      childQuery = QueryBuilders.matchAllQuery();
     }
 
     /** Implementation of activation query */
     if (Boolean.TRUE.equals(query.getActivation())) {
       filters.put("activation",
-        FilterBuilders.hasChildFilter(TYPE_ACTIVE_RULE,
+        QueryBuilders.hasChildQuery(TYPE_ACTIVE_RULE,
           childQuery));
     } else if (Boolean.FALSE.equals(query.getActivation())) {
       filters.put("activation",
-        FilterBuilders.boolFilter().mustNot(
-          FilterBuilders.hasChildFilter(TYPE_ACTIVE_RULE,
+        boolQuery().mustNot(
+          QueryBuilders.hasChildQuery(TYPE_ACTIVE_RULE,
             childQuery)));
     }
 
     return filters;
   }
 
-  private static BoolFilterBuilder addTermFilter(BoolFilterBuilder filter, String field, @Nullable Collection<String> values) {
+  private static BoolQueryBuilder addTermFilter(BoolQueryBuilder filter, String field, @Nullable Collection<String> values) {
     if (isNotEmpty(values)) {
-      BoolFilterBuilder valuesFilter = FilterBuilders.boolFilter();
+      BoolQueryBuilder valuesFilter = boolQuery();
       for (String value : values) {
-        FilterBuilder valueFilter = FilterBuilders.termFilter(field, value);
+        QueryBuilder valueFilter = QueryBuilders.termQuery(field, value);
         valuesFilter.should(valueFilter);
       }
       filter.must(valuesFilter);
@@ -327,14 +325,14 @@ public class RuleIndex extends BaseIndex {
     return filter;
   }
 
-  private static BoolFilterBuilder addTermFilter(BoolFilterBuilder filter, String field, @Nullable String value) {
+  private static BoolQueryBuilder addTermFilter(BoolQueryBuilder filter, String field, @Nullable String value) {
     if (StringUtils.isNotEmpty(value)) {
-      filter.must(FilterBuilders.termFilter(field, value));
+      filter.must(QueryBuilders.termQuery(field, value));
     }
     return filter;
   }
 
-  private static Map<String, AggregationBuilder> getFacets(RuleQuery query, SearchOptions options, QueryBuilder queryBuilder, Map<String, FilterBuilder> filters) {
+  private static Map<String, AggregationBuilder> getFacets(RuleQuery query, SearchOptions options, QueryBuilder queryBuilder, Map<String, QueryBuilder> filters) {
     Map<String, AggregationBuilder> aggregations = new HashMap<>();
     StickyFacetBuilder stickyFacetBuilder = stickyFacetBuilder(queryBuilder, filters);
 
@@ -380,7 +378,7 @@ public class RuleIndex extends BaseIndex {
 
   private static void addStatusFacetIfNeeded(SearchOptions options, Map<String, AggregationBuilder> aggregations, StickyFacetBuilder stickyFacetBuilder) {
     if (options.getFacets().contains(FACET_STATUSES)) {
-      BoolFilterBuilder facetFilter = stickyFacetBuilder.getStickyFacetFilter(FIELD_RULE_STATUS);
+      BoolQueryBuilder facetFilter = stickyFacetBuilder.getStickyFacetFilter(FIELD_RULE_STATUS);
       AggregationBuilder statuses = AggregationBuilders.filter(FACET_STATUSES + "_filter")
         .filter(facetFilter)
         .subAggregation(
@@ -400,15 +398,15 @@ public class RuleIndex extends BaseIndex {
       // We are building a children aggregation on active rules
       // so the rule filter has to be used as parent filter for active rules
       // from which we remove filters that concern active rules ("activation")
-      HasParentFilterBuilder ruleFilter = FilterBuilders.hasParentFilter(
+      HasParentQueryBuilder ruleFilter = QueryBuilders.hasParentQuery(
         TYPE_RULE,
         stickyFacetBuilder.getStickyFacetFilter("activation"));
 
       // Rebuilding the active rule filter without severities
-      BoolFilterBuilder childrenFilter = FilterBuilders.boolFilter();
+      BoolQueryBuilder childrenFilter = boolQuery();
       addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_PROFILE_KEY, query.getQProfileKey());
       RuleIndex.addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
-      FilterBuilder activeRuleFilter;
+      QueryBuilder activeRuleFilter;
       if (childrenFilter.hasClauses()) {
         activeRuleFilter = childrenFilter.must(ruleFilter);
       } else {
@@ -430,7 +428,7 @@ public class RuleIndex extends BaseIndex {
     }
   }
 
-  private static StickyFacetBuilder stickyFacetBuilder(QueryBuilder query, Map<String, FilterBuilder> filters) {
+  private static StickyFacetBuilder stickyFacetBuilder(QueryBuilder query, Map<String, QueryBuilder> filters) {
     return new StickyFacetBuilder(query, filters);
   }
 
@@ -492,7 +490,7 @@ public class RuleIndex extends BaseIndex {
 
     if (aggregation != null) {
       for (Terms.Bucket value : aggregation.getBuckets()) {
-        tags.add(value.getKey());
+        tags.add(value.getKeyAsString());
       }
     }
     return tags;
index 19be74edf104cd14cc929a274a1fc0b16a59da59..ce9d2ac8d5dc86b2a88b2ad8ea02a04023b55c55 100644 (file)
@@ -83,15 +83,28 @@ public class RuleIndexDefinition implements IndexDefinition {
     index.refreshHandledByIndexer();
     index.configureShards(settings);
 
+    // Active rule type
+    NewIndex.NewIndexType activeRuleMapping = index.createType(RuleIndexDefinition.TYPE_ACTIVE_RULE);
+    activeRuleMapping.setEnableSource(false);
+    activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", RuleIndexDefinition.TYPE_RULE));
+
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY).enableSorting().build();
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY).enableSorting().build();
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY).build();
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).disableNorms().docValues().build();
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().docValues().build();
+    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY).disableNorms().docValues().build();
+
+    activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT);
+    activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT);
+
     // Rule type
     NewIndex.NewIndexType ruleMapping = index.createType(TYPE_RULE);
-    ruleMapping.setAttribute("_id", ImmutableMap.of("path", FIELD_RULE_KEY));
-    ruleMapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", RuleIndexDefinition.FIELD_RULE_REPOSITORY));
     ruleMapping.setEnableSource(false);
 
     ruleMapping.stringFieldBuilder(FIELD_RULE_KEY).enableSorting().build();
     ruleMapping.stringFieldBuilder(FIELD_RULE_RULE_KEY).enableSorting().build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_REPOSITORY).disableNorms().docValues().build();
+    ruleMapping.stringFieldBuilder(FIELD_RULE_REPOSITORY).build();
     ruleMapping.stringFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().docValues().build();
 
     ruleMapping.stringFieldBuilder(FIELD_RULE_NAME).enableSorting().enableWordSearch().build();
@@ -99,7 +112,7 @@ public class RuleIndexDefinition implements IndexDefinition {
       "type", "string",
       "index", "analyzed",
       "doc_values", "false",
-      "index_analyzer", "html_analyzer",
+      "analyzer", "html_analyzer",
       "search_analyzer", "html_analyzer"
       ));
     ruleMapping.stringFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().docValues().build();
@@ -114,22 +127,5 @@ public class RuleIndexDefinition implements IndexDefinition {
 
     ruleMapping.createLongField(FIELD_RULE_CREATED_AT);
     ruleMapping.createLongField(FIELD_RULE_UPDATED_AT);
-
-    // Active rule type
-    NewIndex.NewIndexType activeRuleMapping = index.createType(RuleIndexDefinition.TYPE_ACTIVE_RULE);
-    activeRuleMapping.setEnableSource(false);
-    activeRuleMapping.setAttribute("_id", ImmutableMap.of("path", RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY));
-    activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", RuleIndexDefinition.TYPE_RULE));
-    activeRuleMapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY));
-
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY).enableSorting().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY).disableNorms().disableSearch().docValues().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY).disableNorms().disableSearch().docValues().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).disableNorms().docValues().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().docValues().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY).disableNorms().docValues().build();
-
-    activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT);
-    activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT);
   }
 }
index 35da71cb5af089bbe8e3cd854efc5b96e9bcfa71..e8689201e07a067058ac2863e1d47b5d9455a83e 100644 (file)
@@ -83,8 +83,6 @@ public class RuleIndexer extends BaseIndexer {
   }
 
   private static IndexRequest newIndexRequest(RuleDoc rule) {
-    return new IndexRequest(INDEX, TYPE_RULE, rule.key().toString())
-      .routing(rule.repository())
-      .source(rule.getFields());
+    return new IndexRequest(INDEX, TYPE_RULE, rule.key().toString()).source(rule.getFields());
   }
 }
index 6b65220e09cc65b197e96ab0db7972249720b51b..25ed16776fd5ecd481f9beb76a04047bc96d814d 100644 (file)
@@ -21,20 +21,19 @@ package org.sonar.server.search;
 
 import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.aggregations.Aggregation;
 import org.elasticsearch.search.aggregations.HasAggregations;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram;
+import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
 import org.elasticsearch.search.aggregations.bucket.missing.Missing;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 public class Facets {
 
   private static final Logger LOGGER = Loggers.get(Facets.class);
@@ -58,7 +57,7 @@ public class Facets {
       processTermsAggregation(aggregation);
     } else if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
       processSubAggregations(aggregation);
-    } else if (DateHistogram.class.isAssignableFrom(aggregation.getClass())) {
+    } else if (Histogram.class.isAssignableFrom(aggregation.getClass())) {
       processDateHistogram(aggregation);
     } else {
       LOGGER.warn("Cannot process {} type of aggregation", aggregation.getClass());
@@ -85,7 +84,7 @@ public class Facets {
         facetName = facetName.substring(0, facetName.indexOf("__"));
       }
       facetName = facetName.replace("_selected", "");
-      this.facetValues.put(facetName, new FacetValue(value.getKey(), value.getDocCount()));
+      this.facetValues.put(facetName, new FacetValue(value.getKeyAsString(), value.getDocCount()));
     }
   }
 
@@ -97,9 +96,9 @@ public class Facets {
   }
 
   private void processDateHistogram(Aggregation aggregation) {
-    DateHistogram dateHistogram = (DateHistogram) aggregation;
-    for (DateHistogram.Bucket value : dateHistogram.getBuckets()) {
-      this.facetValues.put(dateHistogram.getName(), new FacetValue(value.getKeyAsText().toString(), value.getDocCount()));
+    Histogram dateHistogram = (Histogram) aggregation;
+    for (Histogram.Bucket value : dateHistogram.getBuckets()) {
+      this.facetValues.put(dateHistogram.getName(), new FacetValue(value.getKeyAsString(), value.getDocCount()));
     }
   }
 
index af35f16d7ddf535db0f149c3dc9fd92b654c303f..6536be850a1a8e7fb81dcbe5893670eb2ec6eb18 100644 (file)
  */
 package org.sonar.server.search;
 
-import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
-
+import java.util.Date;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
-import java.util.Date;
+import org.joda.time.format.ISODateTimeFormat;
 
 public class IndexUtils {
 
index 9668bf24b7fc49f948e5811706b5036d3279f003..c23d5645f6088a298533951755b44016c59f3c85 100644 (file)
@@ -33,6 +33,21 @@ public class CoveredFileDoc extends BaseDoc {
     super(fields);
   }
 
+  @Override
+  public String getId() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public String getRouting() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public String getParent() {
+    throw new UnsupportedOperationException();
+  }
+
   @VisibleForTesting
   public CoveredFileDoc() {
     super(Maps.<String, Object>newHashMapWithExpectedSize(2));
index 7a3d9b10d4ac738c8b598b50ce520bfd5e3ae191..9ada72ab9a9a69facd9f6f4b7fc6603676853981 100644 (file)
@@ -38,6 +38,7 @@ import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
 
 public class TestDoc extends BaseDoc {
+
   public TestDoc(Map<String, Object> fields) {
     super(fields);
   }
@@ -47,6 +48,21 @@ public class TestDoc extends BaseDoc {
     super(Maps.<String, Object>newHashMapWithExpectedSize(10));
   }
 
+  @Override
+  public String getId() {
+    return testUuid();
+  }
+
+  @Override
+  public String getRouting() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   public String projectUuid() {
     return getField(FIELD_PROJECT_UUID);
   }
index efeef12ebd272cfec28a48b5f1506f4f9c7f8376..53df2eeabbac428ff62f3bc8029514c36a99681f 100644 (file)
@@ -25,8 +25,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.SearchHit;
 import org.sonar.core.util.NonNullInputFunction;
 import org.sonar.server.es.BaseIndex;
@@ -34,6 +32,10 @@ import org.sonar.server.es.EsClient;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.nestedQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILES;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILE_LINES;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILE_UUID;
@@ -58,7 +60,7 @@ public class TestIndex extends BaseIndex {
     for (SearchHit hit : getClient().prepareSearch(TestIndexDefinition.INDEX)
       .setTypes(TestIndexDefinition.TYPE)
       .setSize(1)
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter(FIELD_TEST_UUID, testUuid)))
+      .setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_TEST_UUID, testUuid)))
       .get().getHits().getHits()) {
       coveredFiles.addAll(new TestDoc(hit.sourceAsMap()).coveredFiles());
     }
@@ -71,7 +73,7 @@ public class TestIndex extends BaseIndex {
       .setTypes(TestIndexDefinition.TYPE)
       .setSize(searchOptions.getLimit())
       .setFrom(searchOptions.getOffset())
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter(FIELD_FILE_UUID, testFileUuid)));
+      .setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_FILE_UUID, testFileUuid)));
 
     return new SearchResult<>(searchRequest.get(), CONVERTER);
   }
@@ -81,9 +83,9 @@ public class TestIndex extends BaseIndex {
       .setTypes(TestIndexDefinition.TYPE)
       .setSize(searchOptions.getLimit())
       .setFrom(searchOptions.getOffset())
-      .setQuery(QueryBuilders.nestedQuery(FIELD_COVERED_FILES, FilterBuilders.boolFilter()
-        .must(FilterBuilders.termFilter(FIELD_COVERED_FILES + "." + FIELD_COVERED_FILE_UUID, sourceFileUuid).cache(false))
-        .must(FilterBuilders.termFilter(FIELD_COVERED_FILES + "." + FIELD_COVERED_FILE_LINES, lineNumber).cache(false))));
+      .setQuery(nestedQuery(FIELD_COVERED_FILES, boolQuery()
+        .must(termQuery(FIELD_COVERED_FILES + "." + FIELD_COVERED_FILE_UUID, sourceFileUuid))
+        .must(termQuery(FIELD_COVERED_FILES + "." + FIELD_COVERED_FILE_LINES, lineNumber))));
 
     return new SearchResult<>(searchRequest.get(), CONVERTER);
   }
@@ -101,7 +103,7 @@ public class TestIndex extends BaseIndex {
     for (SearchHit hit : getClient().prepareSearch(TestIndexDefinition.INDEX)
       .setTypes(TestIndexDefinition.TYPE)
       .setSize(1)
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter(FIELD_TEST_UUID, testUuid)))
+      .setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_TEST_UUID, testUuid)))
       .get().getHits().getHits()) {
       return Optional.of(new TestDoc(hit.sourceAsMap()));
     }
@@ -114,7 +116,7 @@ public class TestIndex extends BaseIndex {
       .setTypes(TestIndexDefinition.TYPE)
       .setSize(searchOptions.getLimit())
       .setFrom(searchOptions.getOffset())
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter(FIELD_TEST_UUID, testUuid)));
+      .setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_TEST_UUID, testUuid)));
 
     return new SearchResult<>(searchRequest.get(), CONVERTER);
   }
index 6b4c532c4f87ee40e096518f2bf403f9070bbb6f..f5c8569d1ea058c4a3718283924d7f2430c72341 100644 (file)
@@ -53,13 +53,8 @@ public class TestIndexDefinition implements IndexDefinition {
     index.refreshHandledByIndexer();
     index.configureShards(settings);
 
-    NewIndex.NewIndexType nestedMapping = index.createType(TYPE);
-    nestedMapping.stringFieldBuilder(FIELD_COVERED_FILE_UUID).build();
-    nestedMapping.createIntegerField(FIELD_COVERED_FILE_LINES);
-
     NewIndex.NewIndexType mapping = index.createType(TYPE);
-    mapping.setAttribute("_id", ImmutableMap.of("path", FIELD_TEST_UUID));
-    mapping.setAttribute("_routing", ImmutableMap.of("required", true, "path", FIELD_PROJECT_UUID));
+    mapping.setAttribute("_routing", ImmutableMap.of("required", true));
     mapping.stringFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
     mapping.stringFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
     mapping.stringFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
@@ -68,7 +63,10 @@ public class TestIndexDefinition implements IndexDefinition {
     mapping.createLongField(FIELD_DURATION_IN_MS);
     mapping.stringFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
     mapping.stringFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
-    mapping.nestedObjectBuilder(FIELD_COVERED_FILES, nestedMapping).build();
+    mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
+      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", "string", "index", "not_analyzed"),
+      FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer")
+      )));
     mapping.createDateTimeField(FIELD_UPDATED_AT);
   }
 }
index c6c11cdcd97ff91f6999e08c28cc18c1050c165d..ad112c2f1b9e0f3de3544eccd8a50109d319026b 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Iterator;
 import javax.annotation.Nullable;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.update.UpdateRequest;
-import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -103,9 +102,7 @@ public class TestIndexer extends BaseIndexer {
   public void deleteByFile(String fileUuid) {
     SearchRequestBuilder searchRequest = esClient.prepareSearch(INDEX)
       .setTypes(TYPE)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.termFilter(FIELD_FILE_UUID, fileUuid).cache(false)));
+      .setQuery(QueryBuilders.termsQuery(FIELD_FILE_UUID, fileUuid));
     BulkIndexer.delete(esClient, INDEX, searchRequest);
   }
 
@@ -113,9 +110,7 @@ public class TestIndexer extends BaseIndexer {
     SearchRequestBuilder searchRequest = esClient.prepareSearch(INDEX)
       .setRouting(projectUuid)
       .setTypes(TYPE)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.termFilter(TestIndexDefinition.FIELD_PROJECT_UUID, projectUuid).cache(false)));
+      .setQuery(QueryBuilders.termQuery(TestIndexDefinition.FIELD_PROJECT_UUID, projectUuid));
     BulkIndexer.delete(esClient, INDEX, searchRequest);
   }
 }
index 995bfa7ffd5186a18f8f2a353e75c865ecbe2cf0..e5268e6046881739699294eb6ae52f03c7edca99 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.ResultSetIterator;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
+import org.sonar.server.es.EsUtils;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper.Row;
 
@@ -99,7 +100,7 @@ public class TestResultSetIterator extends ResultSetIterator<Row> {
       writer.prop(FIELD_DURATION_IN_MS, test.hasExecutionTimeMs() ? test.getExecutionTimeMs() : null);
       writer.prop(FIELD_MESSAGE, test.hasMsg() ? test.getMsg() : null);
       writer.prop(FIELD_STACKTRACE, test.hasStacktrace() ? test.getStacktrace() : null);
-      writer.prop(FIELD_UPDATED_AT, updatedAt.getTime());
+      writer.prop(FIELD_UPDATED_AT, EsUtils.formatDateTime(updatedAt));
       writer.name(FIELD_COVERED_FILES);
       writer.beginArray();
       for (DbFileSources.Test.CoveredFile coveredFile : test.getCoveredFileList()) {
index 65c6fe7251889a559c37d9ba0c89ecedba732ed0..ad0d9fbbdd470487dcbd5e03146dc9623a94e869 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.user.index;
 
 import com.google.common.collect.Maps;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Nullable;
@@ -36,6 +37,21 @@ public class UserDoc extends BaseDoc implements User {
     this(Maps.<String, Object>newHashMap());
   }
 
+  @Override
+  public String getId() {
+    return login();
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   @Override
   public String login() {
     return getField(UserIndexDefinition.FIELD_LOGIN);
@@ -62,11 +78,11 @@ public class UserDoc extends BaseDoc implements User {
   }
 
   public long createdAt() {
-    return getField(UserIndexDefinition.FIELD_CREATED_AT);
+    return getFieldAsDate(UserIndexDefinition.FIELD_CREATED_AT).getTime();
   }
 
   public long updatedAt() {
-    return getField(UserIndexDefinition.FIELD_UPDATED_AT);
+    return getFieldAsDate(UserIndexDefinition.FIELD_UPDATED_AT).getTime();
   }
 
   public UserDoc setLogin(@Nullable String s) {
@@ -95,12 +111,12 @@ public class UserDoc extends BaseDoc implements User {
   }
 
   public UserDoc setCreatedAt(long l) {
-    setField(UserIndexDefinition.FIELD_CREATED_AT, l);
+    setField(UserIndexDefinition.FIELD_CREATED_AT, new Date(l));
     return this;
   }
 
   public UserDoc setUpdatedAt(long l) {
-    setField(UserIndexDefinition.FIELD_UPDATED_AT, l);
+    setField(UserIndexDefinition.FIELD_UPDATED_AT, new Date(l));
     return this;
   }
 }
index 3a4453c7d637243def00a9814001a117627eb82f..a65bebaa1228c0b2e687247df9effca813e8ec74 100644 (file)
@@ -33,8 +33,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.BoolFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.MatchQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -49,6 +48,11 @@ import org.sonar.server.es.EsUtils;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
+
 @ServerSide
 @ComputeEngineSide
 public class UserIndex {
@@ -80,12 +84,12 @@ public class UserIndex {
     if (!StringUtils.isEmpty(scmAccount)) {
       SearchRequestBuilder request = esClient.prepareSearch(UserIndexDefinition.INDEX)
         .setTypes(UserIndexDefinition.TYPE_USER)
-        .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
-          FilterBuilders.boolFilter()
-            .must(FilterBuilders.termFilter(UserIndexDefinition.FIELD_ACTIVE, true))
-            .should(FilterBuilders.termFilter(UserIndexDefinition.FIELD_LOGIN, scmAccount))
-            .should(FilterBuilders.termFilter(UserIndexDefinition.FIELD_EMAIL, scmAccount))
-            .should(FilterBuilders.termFilter(UserIndexDefinition.FIELD_SCM_ACCOUNTS, scmAccount))))
+        .setQuery(boolQuery().must(matchAllQuery()).filter(
+          boolQuery()
+            .must(termQuery(UserIndexDefinition.FIELD_ACTIVE, true))
+            .should(termQuery(UserIndexDefinition.FIELD_LOGIN, scmAccount))
+            .should(termQuery(UserIndexDefinition.FIELD_EMAIL, scmAccount))
+            .should(termQuery(UserIndexDefinition.FIELD_SCM_ACCOUNTS, scmAccount))))
         .setSize(3);
       for (SearchHit hit : request.get().getHits().getHits()) {
         result.add(DOC_CONVERTER.apply(hit.sourceAsMap()));
@@ -95,8 +99,8 @@ public class UserIndex {
   }
 
   public Iterator<UserDoc> selectUsersForBatch(List<String> logins) {
-    BoolFilterBuilder filter = FilterBuilders.boolFilter()
-      .must(FilterBuilders.termsFilter(UserIndexDefinition.FIELD_LOGIN, logins));
+    BoolQueryBuilder filter = boolQuery()
+      .must(termsQuery(UserIndexDefinition.FIELD_LOGIN, logins));
 
     SearchRequestBuilder requestBuilder = esClient
       .prepareSearch(UserIndexDefinition.INDEX)
@@ -108,7 +112,7 @@ public class UserIndex {
       .setFetchSource(
         new String[] {UserIndexDefinition.FIELD_LOGIN, UserIndexDefinition.FIELD_NAME},
         null)
-      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filter));
+      .setQuery(QueryBuilders.filteredQuery(matchAllQuery(), filter));
     SearchResponse response = requestBuilder.get();
 
     return EsUtils.scroll(esClient, response.getScrollId(), DOC_CONVERTER);
@@ -121,12 +125,12 @@ public class UserIndex {
       .setFrom(options.getOffset())
       .addSort(UserIndexDefinition.FIELD_NAME, SortOrder.ASC);
 
-    BoolFilterBuilder userFilter = FilterBuilders.boolFilter()
-      .must(FilterBuilders.termFilter(UserIndexDefinition.FIELD_ACTIVE, true));
+    BoolQueryBuilder userQuery = boolQuery()
+      .must(termQuery(UserIndexDefinition.FIELD_ACTIVE, true));
 
     QueryBuilder query;
     if (StringUtils.isEmpty(searchText)) {
-      query = QueryBuilders.matchAllQuery();
+      query = matchAllQuery();
     } else {
       query = QueryBuilders.multiMatchQuery(searchText,
         UserIndexDefinition.FIELD_LOGIN,
@@ -137,7 +141,7 @@ public class UserIndex {
     }
 
     request.setQuery(QueryBuilders.filteredQuery(query,
-      userFilter));
+      userQuery));
 
     return new SearchResult<>(request.get(), DOC_CONVERTER);
   }
index 910055ab2435a8ffa5a0e1c3ce211606b7a8a6d9..a0d7d487769d3f84f96654896b780564cee65d65 100644 (file)
@@ -34,6 +34,21 @@ public class ViewDoc extends BaseDoc {
     super(Maps.<String, Object>newHashMap());
   }
 
+  @Override
+  public String getId() {
+    return uuid();
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   public String uuid() {
     return getField(ViewIndexDefinition.FIELD_UUID);
   }
index e8c4f6e8ed8d4f2f13fded267c787cb4d10ce7c1..3872c7f831ddbf7548d7eac1a6279f2cf5f2f682 100644 (file)
@@ -23,18 +23,18 @@ import java.util.Collection;
 import java.util.List;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.sort.SortOrder;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 
 import static com.google.common.collect.Lists.newArrayList;
-import static org.elasticsearch.index.query.FilterBuilders.termsFilter;
-import static org.elasticsearch.index.query.QueryBuilders.filteredQuery;
+import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
 import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
 
 @ServerSide
 @ComputeEngineSide
@@ -51,9 +51,9 @@ public class ViewIndex {
   public List<String> findAllViewUuids() {
     SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX)
       .setTypes(ViewIndexDefinition.TYPE_VIEW)
-      .setSearchType(SearchType.SCAN)
+      .addSort("_doc", SortOrder.ASC)
       .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
-      .setFetchSource(ViewIndexDefinition.FIELD_UUID, null)
+      .setFetchSource(false)
       .setSize(100)
       .setQuery(matchAllQuery());
 
@@ -62,13 +62,15 @@ public class ViewIndex {
     while (true) {
       List<SearchHit> hits = newArrayList(response.getHits());
       for (SearchHit hit : hits) {
-        result.add((String) hit.getSource().get(ViewIndexDefinition.FIELD_UUID));
+        result.add(hit.getId());
       }
-      response = esClient.prepareSearchScroll(response.getScrollId())
+      String scrollId = response.getScrollId();
+      response = esClient.prepareSearchScroll(scrollId)
         .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
         .get();
       // Break condition: No hits are returned
       if (response.getHits().getHits().length == 0) {
+        esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
         break;
       }
     }
@@ -78,8 +80,7 @@ public class ViewIndex {
   public void delete(Collection<String> viewUuids) {
     SearchRequestBuilder searchRequest = esClient.prepareSearch(ViewIndexDefinition.INDEX)
       .setTypes(ViewIndexDefinition.TYPE_VIEW)
-      .setQuery(filteredQuery(matchAllQuery(), termsFilter(ViewIndexDefinition.FIELD_UUID, viewUuids)
-        ));
+      .setQuery(boolQuery().must(matchAllQuery()).filter(termsQuery(ViewIndexDefinition.FIELD_UUID, viewUuids)));
     BulkIndexer.delete(esClient, ViewIndexDefinition.INDEX, searchRequest);
   }
 }
index 296a9cccaf88f0377693d0c1630488f5d600c927..aaf546137e23885e908464e034d444aa9c28160a 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.db.component.UuidWithProjectUuidDto;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
-import org.sonar.server.issue.index.IssueIndex;
 
 import static com.google.common.collect.Maps.newHashMap;
 
@@ -127,8 +126,7 @@ public class ViewIndexer extends BaseIndexer {
   private void clearLookupCache(String viewUuid) {
     try {
       esClient.prepareClearCache()
-        .setFilterCache(true)
-        .setFilterKeys(IssueIndex.viewsLookupCacheKey(viewUuid))
+        .setQueryCache(true)
         .get();
     } catch (Exception e) {
       throw new IllegalStateException(String.format("Unable to clear lookup cache of view '%s'", viewUuid), e);
index 3a5c58ea75798db029a804723e60f3857fb22205..fd4743abe7b9460a31696053d14d8568ecce3832 100644 (file)
@@ -43,9 +43,9 @@ public class IndexPurgeListenerTest {
 
   @Test
   public void test_onIssuesRemoval() {
-    underTest.onIssuesRemoval(asList("ISSUE1", "ISSUE2"));
+    underTest.onIssuesRemoval("P1", asList("ISSUE1", "ISSUE2"));
 
-    verify(issueIndexer).deleteByKeys(asList("ISSUE1", "ISSUE2"));
+    verify(issueIndexer).deleteByKeys("P1", asList("ISSUE1", "ISSUE2"));
   }
 
 }
index 4127332a2e7725163044a672ecb6272234b1bc38..030674412f08fec5516013c7160d45a1064cef40 100644 (file)
@@ -49,7 +49,7 @@ public class ScmAccountToUserLoaderTest {
       .setEmail("charlie@hebdo.com")
       .setActive(true)
       .setScmAccounts(asList("charlie", "jesuis@charlie.com"));
-    esTester.index(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, "charlie", user.getFields());
+    esTester.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, user);
 
     UserIndex index = new UserIndex(esTester.client());
     ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
@@ -66,14 +66,14 @@ public class ScmAccountToUserLoaderTest {
       .setEmail("charlie@hebdo.com")
       .setActive(true)
       .setScmAccounts(asList("charlie", "jesuis@charlie.com"));
-    esTester.index(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, user1.login(), user1.getFields());
+    esTester.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, user1);
 
     UserDoc user2 = new UserDoc()
       .setLogin("another.charlie")
       .setName("Another Charlie")
       .setActive(true)
       .setScmAccounts(asList("charlie"));
-    esTester.index(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, user2.login(), user2.getFields());
+    esTester.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, user2);
 
     UserIndex index = new UserIndex(esTester.client());
     ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
index 0f7f087fe5adf77693525971dc07f911472ae7b5..ff89f4a01b9aa5187e20d953604b18673a978d7a 100644 (file)
@@ -24,7 +24,6 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
-import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.junit.Rule;
 import org.junit.Test;
@@ -97,9 +96,7 @@ public class BulkIndexerTest {
 
     SearchRequestBuilder req = esTester.client().prepareSearch(FakeIndexDefinition.INDEX)
       .setTypes(FakeIndexDefinition.TYPE)
-      .setQuery(QueryBuilders.filteredQuery(
-        QueryBuilders.matchAllQuery(),
-        FilterBuilders.rangeFilter(FakeIndexDefinition.INT_FIELD).gte(removeFrom)));
+      .setQuery(QueryBuilders.rangeQuery(FakeIndexDefinition.INT_FIELD).gte(removeFrom));
     BulkIndexer.delete(esTester.client(), FakeIndexDefinition.INDEX, req);
 
     assertThat(count()).isEqualTo(removeFrom);
index 18c73bcc285cba8a9cb142e1d000bc6a28689a88..666b9276f3b8476c232312ca541c97b09f23edcc 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.es;
 
-import org.elasticsearch.common.collect.ImmutableMap;
+import java.util.Map;
 import org.junit.Test;
 import org.sonar.test.TestUtils;
 
@@ -29,7 +29,7 @@ public class DefaultIndexSettingsTest {
 
   @Test
   public void defaults() {
-    ImmutableMap<String, String> map = DefaultIndexSettings.defaults().build().getAsMap();
+    Map<String, String> map = DefaultIndexSettings.defaults().build().getAsMap();
     assertThat(map).isNotEmpty();
 
     // test some values
index be6fb6a12593daf30d472419e670e440adeb0385..e1634e7a2920297072daab702b29d9bd66783bab 100644 (file)
@@ -23,7 +23,7 @@ import java.io.File;
 import java.util.Properties;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
 import org.elasticsearch.client.transport.TransportClient;
-import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.sonar.process.LoopbackAddress;
 import org.sonar.process.NetworkUtils;
@@ -63,9 +63,9 @@ public class EsServerHolder {
   public int getPort() {
     return port;
   }
-  
+
   public String getHostName() {
-  return hostName;
+    return hostName;
   }
 
   public SearchServer getServer() {
@@ -77,12 +77,12 @@ public class EsServerHolder {
   }
 
   private void reset() {
-    TransportClient client = new TransportClient(ImmutableSettings.settingsBuilder()
+    TransportClient client = TransportClient.builder().settings(Settings.builder()
       .put("node.name", nodeName)
       .put("network.bind_host", "localhost")
       .put("cluster.name", clusterName)
-      .build());
-    client.addTransportAddress(new InetSocketTransportAddress(LoopbackAddress.get().getHostAddress(), port));
+      .build()).build();
+    client.addTransportAddress(new InetSocketTransportAddress(LoopbackAddress.get(), port));
 
     // wait for node to be ready
     client.admin().cluster().prepareHealth()
index 83285e45cea98e1b06358d489676ed4541e5be1b..c839686a3cca0a5948b6e25809b82778f2dc6fd5 100644 (file)
@@ -28,20 +28,17 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.List;
-import java.util.Map;
 import javax.annotation.Nonnull;
 import org.apache.commons.lang.math.RandomUtils;
 import org.apache.commons.lang.reflect.ConstructorUtils;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
-import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.cluster.node.DiscoveryNode;
-import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.node.Node;
@@ -54,7 +51,6 @@ import org.sonar.core.platform.ComponentContainer;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Lists.newArrayList;
 import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
 
 public class EsTester extends ExternalResource {
 
@@ -99,15 +95,12 @@ public class EsTester extends ExternalResource {
   public void putDocuments(String index, String type, BaseDoc... docs) throws Exception {
     BulkRequestBuilder bulk = client.prepareBulk().setRefresh(true);
     for (BaseDoc doc : docs) {
-      bulk.add(new IndexRequest(index, type).source(doc.getFields()));
+      bulk.add(new IndexRequest(index, type, doc.getId())
+        .parent(doc.getParent())
+        .routing(doc.getRouting())
+        .source(doc.getFields()));
     }
-    BulkResponse response = bulk.get();
-    assertThat(response.hasFailures()).as(response.buildFailureMessage()).isFalse();
-  }
-
-  public void index(String indexName, String typeName, String id, Map<String, Object> source) {
-    client.prepareIndex(indexName, typeName).setId(id).setSource(source).get();
-    client.prepareRefresh(indexName).get();
+    EsUtils.executeBulkRequest(bulk, "");
   }
 
   public long countDocuments(String indexName, String typeName) {
@@ -194,7 +187,7 @@ public class EsTester extends ExternalResource {
         Path tmpDir = Files.createTempDirectory("tmp-es");
         tmpDir.toFile().deleteOnExit();
 
-        node = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
+        node = NodeBuilder.nodeBuilder().local(true).data(true).settings(org.elasticsearch.common.settings.Settings.builder()
           .put("cluster.name", nodeName)
           .put("node.name", nodeName)
           // the two following properties are probably not used because they are
index 734c9972b854e7b75410d4876315cdf7121cdbcd..39229cb20de3554d9bc2ea9797e942703ebbe510 100644 (file)
@@ -29,6 +29,21 @@ public class FakeDoc extends BaseDoc {
     super(fields);
   }
 
+  @Override
+  public String getId() {
+    return null;
+  }
+
+  @Override
+  public String getRouting() {
+    return null;
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
   public FakeDoc() {
     super(Maps.<String, Object>newHashMap());
   }
index d68436df099ce11b8d22da57eb01a5eb4f9e0751..ea824d0e1763b9e038a39384b115941e5c1a60f9 100644 (file)
@@ -19,7 +19,9 @@
  */
 package org.sonar.server.es;
 
+import java.util.List;
 import org.apache.commons.lang.reflect.FieldUtils;
+import org.elasticsearch.action.search.SearchAction;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -28,8 +30,6 @@ import org.elasticsearch.search.sort.SortOrder;
 import org.junit.Test;
 import org.sonar.server.exceptions.BadRequestException;
 
-import java.util.List;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -58,7 +58,7 @@ public class SortingTest {
     Sorting sorting = new Sorting();
     sorting.add("updatedAt");
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fill(request, "updatedAt", true);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(1);
@@ -70,7 +70,7 @@ public class SortingTest {
     Sorting sorting = new Sorting();
     sorting.add("updatedAt");
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fill(request, "updatedAt", false);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(1);
@@ -82,7 +82,7 @@ public class SortingTest {
     Sorting sorting = new Sorting();
     sorting.add("updatedAt").missingLast();
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fill(request, "updatedAt", true);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(1);
@@ -94,7 +94,7 @@ public class SortingTest {
     Sorting sorting = new Sorting();
     sorting.add("updatedAt").missingLast();
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fill(request, "updatedAt", false);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(1);
@@ -110,7 +110,7 @@ public class SortingTest {
     sorting.add("fileLine", "severity").reverse();
     sorting.add("fileLine", "key").missingLast();
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fill(request, "fileLine", true);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(4);
@@ -126,7 +126,7 @@ public class SortingTest {
     sorting.add("file");
 
     try {
-      sorting.fill(new SearchRequestBuilder(mock(Client.class)), "unknown", true);
+      sorting.fill(new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE), "unknown", true);
       fail();
     } catch (BadRequestException e) {
       assertThat(e.getMessage()).isEqualTo("Bad sort field: unknown");
@@ -138,7 +138,7 @@ public class SortingTest {
     Sorting sorting = new Sorting();
     sorting.addDefault("file");
 
-    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class));
+    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
     sorting.fillDefault(request);
     List<SortBuilder> fields = fields(request);
     assertThat(fields).hasSize(1);
index 249909f3837229a66cd7ced62841da6c02ce0c9e..2e39087b8b2a989bfce6e5dd2df13a23a06cc6ae 100644 (file)
@@ -50,10 +50,8 @@ public class ProxyClearCacheRequestBuilderTest {
     assertThat(esTester.client().prepareClearCache().toString()).isEqualTo("ES clear cache request");
     assertThat(esTester.client().prepareClearCache("rules").toString()).isEqualTo("ES clear cache request on indices 'rules'");
     assertThat(esTester.client().prepareClearCache().setFields("key").toString()).isEqualTo("ES clear cache request on fields 'key'");
-    assertThat(esTester.client().prepareClearCache().setFilterKeys("rule1").toString()).isEqualTo("ES clear cache request on filterKeys 'rule1'");
-    assertThat(esTester.client().prepareClearCache().setFilterCache(true).toString()).isEqualTo("ES clear cache request with filter cache");
     assertThat(esTester.client().prepareClearCache().setFieldDataCache(true).toString()).isEqualTo("ES clear cache request with field data cache");
-    assertThat(esTester.client().prepareClearCache().setIdCache(true).toString()).isEqualTo("ES clear cache request with id cache");
+    assertThat(esTester.client().prepareClearCache().setRequestCache(true).toString()).isEqualTo("ES clear cache request with request cache");
   }
 
   @Test
index 342ee36988d32e0cbca76a6e0ba90fc914d20476..cbb9bcfca36b968c7536f00cc63097c2ba081abb 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.es.request;
 
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.unit.TimeValue;
 import org.junit.ClassRule;
 import org.junit.Rule;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilderTest.java
deleted file mode 100644 (file)
index a3f3a75..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.es.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.FakeIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-public class ProxyDeleteByQueryRequestBuilderTest {
-
-  @Rule
-  public EsTester esTester = new EsTester(new FakeIndexDefinition());
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void delete_by_query() {
-    esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
-  }
-
-  @Test
-  public void to_string() {
-    assertThat(esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).toString()).isEqualTo(
-      "ES delete by query request '{\"match_all\":{}}' on indices 'fakes'");
-    assertThat(esTester.client().prepareDeleteByQuery().toString()).isEqualTo("ES delete by query request ''");
-  }
-
-  @Test
-  public void trace_logs() {
-    logTester.setLevel(LoggerLevel.TRACE);
-
-    esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
-
-    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
-  }
-
-  @Test
-  public void get_with_string_timeout_is_not_yet_implemented() {
-    try {
-      esTester.client().prepareDeleteByQuery().get("1");
-      fail();
-    } catch (UnsupportedOperationException e) {
-      assertThat(e).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void get_with_time_value_timeout_is_not_yet_implemented() {
-    try {
-      esTester.client().prepareDeleteByQuery().get(TimeValue.timeValueMinutes(1));
-      fail();
-    } catch (UnsupportedOperationException e) {
-      assertThat(e).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void execute_should_throw_an_unsupported_operation_exception() {
-    try {
-      esTester.client().prepareDeleteByQuery().execute();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
-    }
-  }
-
-}
index 4f686ccab3017c00e95c7ef10803e11af3c0b21c..1f8e0e14a731aaa8e65da073748f5bc20f168bbc 100644 (file)
@@ -46,7 +46,6 @@ public class ProxyPutMappingRequestBuilderTest {
   public void put_mapping() {
     PutMappingRequestBuilder requestBuilder = esTester.client().preparePutMapping(FakeIndexDefinition.INDEX)
       .setType(FakeIndexDefinition.TYPE)
-      .setIgnoreConflicts(true)
       .setSource(mapDomain());
     requestBuilder.get();
   }
@@ -65,7 +64,6 @@ public class ProxyPutMappingRequestBuilderTest {
 
     PutMappingRequestBuilder requestBuilder = esTester.client().preparePutMapping(FakeIndexDefinition.INDEX)
       .setType(FakeIndexDefinition.TYPE)
-      .setIgnoreConflicts(true)
       .setSource(mapDomain());
     requestBuilder.get();
 
index f395b8513ea4bdc685a29ea28d9b03000ac69d98..a715a73e76184a0024193edc9194e35f42cf2bf2 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.TimeZone;
 import javax.annotation.Nullable;
 import org.assertj.core.api.Fail;
+import org.elasticsearch.test.ESTestCase;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
index e656d554a672d9307fa47c1080125fc0fe42c6fc..995909dcb3ff69bfa16d93c849738f10563021f5 100644 (file)
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.Nonnull;
+import org.elasticsearch.search.SearchHit;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -39,9 +40,10 @@ import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.server.issue.IssueTesting.newDoc;
 
-
 public class IssueIndexerTest {
 
+  private static final String A_PROJECT_UUID = "P1";
+
   @Rule
   public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
 
@@ -91,12 +93,13 @@ public class IssueIndexerTest {
   }
 
   @Test
-  public void delete_project_remove_issue() {
+  public void deleteProject_deletes_issues() {
     dbTester.prepareDbUnit(getClass(), "index.xml");
 
     IssueIndexer indexer = createIndexer();
     indexer.index();
 
+    List<SearchHit> docs = esTester.getDocuments("issues", "issue");
     assertThat(esTester.countDocuments("issues", "issue")).isEqualTo(1);
 
     indexer.deleteProject("THE_PROJECT");
@@ -116,46 +119,47 @@ public class IssueIndexerTest {
 
   @Test
   public void delete_issues_by_keys() throws Exception {
-    addIssue("Issue1");
-    addIssue("Issue2");
-    addIssue("Issue3");
+    addIssue("P1", "Issue1");
+    addIssue("P1", "Issue2");
+    addIssue("P1", "Issue3");
+    addIssue("P2", "Issue4");
 
     IssueIndexer indexer = createIndexer();
-    verifyIssueKeys("Issue1", "Issue2", "Issue3");
+    verifyIssueKeys("Issue1", "Issue2", "Issue3", "Issue4");
 
-    indexer.deleteByKeys(asList("Issue1", "Issue2"));
+    indexer.deleteByKeys("P1", asList("Issue1", "Issue2"));
 
-    verifyIssueKeys("Issue3");
+    verifyIssueKeys("Issue3", "Issue4");
   }
 
   @Test
   public void delete_more_than_one_thousand_issues_by_keys() throws Exception {
     int numberOfIssues = 1010;
     List<String> keys = new ArrayList<>(numberOfIssues);
-    List<IssueDoc> issueDocs = new ArrayList<>(numberOfIssues);
-    for (int i=0; i<numberOfIssues; i++) {
+    IssueDoc[] issueDocs = new IssueDoc[numberOfIssues];
+    for (int i = 0; i < numberOfIssues; i++) {
       String key = "Issue" + i;
-      issueDocs.add(newDoc().setKey(key));
+      issueDocs[i] = newDoc().setKey(key).setProjectUuid(A_PROJECT_UUID);
       keys.add(key);
     }
-    esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, issueDocs.toArray(new IssueDoc[]{}));
+    esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, issueDocs);
     IssueIndexer indexer = createIndexer();
 
     assertThat(esTester.countDocuments("issues", "issue")).isEqualTo(numberOfIssues);
-    indexer.deleteByKeys(keys);
+    indexer.deleteByKeys(A_PROJECT_UUID, keys);
     assertThat(esTester.countDocuments("issues", "issue")).isZero();
   }
 
   @Test
   public void nothing_to_do_when_delete_issues_on_empty_list() throws Exception {
-    addIssue("Issue1");
-    addIssue("Issue2");
-    addIssue("Issue3");
+    addIssue("P1", "Issue1");
+    addIssue("P1", "Issue2");
+    addIssue("P1", "Issue3");
 
     IssueIndexer indexer = createIndexer();
     verifyIssueKeys("Issue1", "Issue2", "Issue3");
 
-    indexer.deleteByKeys(Collections.<String>emptyList());
+    indexer.deleteByKeys("P1", Collections.<String>emptyList());
 
     verifyIssueKeys("Issue1", "Issue2", "Issue3");
   }
@@ -166,11 +170,12 @@ public class IssueIndexerTest {
     return indexer;
   }
 
-  private void addIssue(String issueKey) throws Exception {
-    esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, newDoc().setKey(issueKey));
+  private void addIssue(String projectUuid, String issueKey) throws Exception {
+    esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE,
+      newDoc().setKey(issueKey).setProjectUuid(projectUuid));
   }
 
-  private void verifyIssueKeys(String... expectedKeys){
+  private void verifyIssueKeys(String... expectedKeys) {
     List<String> keys = FluentIterable.from(esTester.getDocuments("issues", "issue", IssueDoc.class))
       .transform(DocToKey.INSTANCE)
       .toList();
index 3f3c79940ed0d029d380cbe615d9a0b61c8fa646..e610810347afd1851e2cdd85d8bc7f2b56ac705b 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.platform;
 
-import com.google.common.collect.ImmutableMap;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -111,9 +110,6 @@ public class BackendCleanupMediumTest {
   }
 
   private static RuleDoc newRuleDoc() {
-    return new RuleDoc(ImmutableMap.<String, Object>of(
-      RuleIndexDefinition.FIELD_RULE_KEY, RuleTesting.XOO_X1,
-      RuleIndexDefinition.FIELD_RULE_REPOSITORY, RuleTesting.XOO_X1.repository()
-      ));
+    return new RuleDoc().setKey(RuleTesting.XOO_X1.toString()).setRepository(RuleTesting.XOO_X1.repository());
   }
 }
index e02092137f6621eec699ecca1e317cc5752a0ff7..911aed32594980af816cf92bd5ffd0b184a037f0 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.platform.monitoring;
 
 import java.util.Map;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
+import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
index d8b55783f85737c2ad6c55c8fa92e2b42bbf7974..ed00c19b01f2e881ea9244db9dd6c42f9b8c0bc7 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.project.ws;
 
-import com.google.common.collect.ImmutableMap;
 import java.util.Arrays;
 import org.junit.Before;
 import org.junit.Rule;
@@ -48,6 +47,7 @@ import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
+import org.sonar.server.issue.index.IssueAuthorizationDoc;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
@@ -222,7 +222,7 @@ public class BulkDeleteActionTest {
     dbSession.commit();
 
     es.putDocuments(IssueIndexDefinition.INDEX, TYPE_ISSUE, IssueTesting.newDoc("issue-key-" + suffix, project));
-    es.index(IssueIndexDefinition.INDEX, TYPE_AUTHORIZATION, project.uuid(), ImmutableMap.<String, Object>of(FIELD_AUTHORIZATION_PROJECT_UUID, project.uuid()));
+    es.putDocuments(IssueIndexDefinition.INDEX, TYPE_AUTHORIZATION, new IssueAuthorizationDoc().setProjectUuid(project.uuid()));
 
     TestDoc testDoc = new TestDoc().setUuid("test-uuid-" + suffix).setProjectUuid(project.uuid()).setFileUuid(project.uuid());
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, testDoc);
index 8a073530bdd9497cc4ab8ad3133380d2db06ab29..e7708782b395833a4a5de82daed6043afbabe6f6 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.project.ws;
 
-import com.google.common.collect.ImmutableMap;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -46,6 +45,7 @@ import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
+import org.sonar.server.issue.index.IssueAuthorizationDoc;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
@@ -241,7 +241,7 @@ public class DeleteActionTest {
     dbSession.commit();
 
     es.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc("issue-key-" + suffix, project));
-    es.index(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, project.uuid(), ImmutableMap.<String, Object>of(IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID, project.uuid()));
+    es.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, new IssueAuthorizationDoc().setProjectUuid(project.uuid()));
 
     TestDoc testDoc = new TestDoc().setUuid("test-uuid-" + suffix).setProjectUuid(project.uuid()).setFileUuid(project.uuid());
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, testDoc);
index e1ca4f008885f29b4997640a958ea008c1f17fe2..bdfbd5edc8271ad121086be0b442e09d3ccd7e6b 100644 (file)
@@ -77,7 +77,7 @@ public class RuleIndexDefinitionTest {
     tester.putDocuments(INDEX, RuleIndexDefinition.TYPE_RULE, new RuleDoc(ImmutableMap.<String, Object>of(
       FIELD_RULE_HTML_DESCRIPTION, longText,
       FIELD_RULE_REPOSITORY, "squid",
-      FIELD_RULE_KEY, "S001")));
+      FIELD_RULE_KEY, "squid:S001")));
     assertThat(tester.countDocuments(INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(1);
 
     List<AnalyzeResponse.AnalyzeToken> tokens = analyzeIndexedTokens(longText);
index a60151de0fa54e84a0da68bddde1c4799f754b16..ac9cfd29fc8b42223cf72cf6ef66db754e667e97 100644 (file)
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableSet;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import org.elasticsearch.search.SearchHit;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -189,6 +190,10 @@ public class RuleIndexTest {
       newDoc(RuleKey.of("findbugs", "S001")),
       newDoc(RuleKey.of("pmd", "S002")));
 
+    List<SearchHit> docs = tester.getDocuments("rules", "rule");
+    for (SearchHit doc : docs) {
+      System.out.println(doc.getSourceAsString());
+    }
     RuleQuery query = new RuleQuery().setRepositories(asList("checkstyle", "pmd"));
     SearchIdResult results = index.search(query, new SearchOptions());
     assertThat(results.getIds()).containsOnly(RuleKey.of("pmd", "S002"));
@@ -611,7 +616,7 @@ public class RuleIndexTest {
     SearchIdResult result = index.search(new RuleQuery(), new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS, FACET_TYPES)));
     assertThat(result.getFacets().getAll()).hasSize(4);
     assertThat(result.getFacets().getAll().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol");
-    assertThat(result.getFacets().getAll().get(FACET_REPOSITORIES).keySet()).containsOnly("xoo", "foo");
+    assertThat(result.getFacets().getAll().get(FACET_REPOSITORIES).keySet()).containsExactly("xoo", "foo");
     assertThat(result.getFacets().getAll().get(FACET_TAGS).keySet()).containsOnly("T1", "T2", "T3", "T4");
     assertThat(result.getFacets().getAll().get(FACET_TYPES).keySet()).containsOnly("BUG", "CODE_SMELL", "VULNERABILITY");
 
index d694b16ff18308b1ae706e02d7b45c30eecc1fb3..e8891abba1c7632b1dac7b6a0a07cc39ae256b01 100644 (file)
@@ -38,6 +38,20 @@ public class BaseDocTest {
     fields.put("a_int", 42);
     fields.put("a_null", null);
     BaseDoc doc = new BaseDoc(fields) {
+      @Override
+      public String getId() {
+        return null;
+      }
+
+      @Override
+      public String getRouting() {
+        return null;
+      }
+
+      @Override
+      public String getParent() {
+        return null;
+      }
     };
 
     assertThat((String) doc.getNullableField("a_string")).isEqualTo("foo");
@@ -49,6 +63,20 @@ public class BaseDocTest {
   public void getField_fails_if_missing_field() {
     Map<String, Object> fields = Collections.emptyMap();
     BaseDoc doc = new BaseDoc(fields) {
+      @Override
+      public String getId() {
+        return null;
+      }
+
+      @Override
+      public String getRouting() {
+        return null;
+      }
+
+      @Override
+      public String getParent() {
+        return null;
+      }
     };
 
     try {
@@ -62,6 +90,20 @@ public class BaseDocTest {
   @Test
   public void getFieldAsDate() {
     BaseDoc doc = new BaseDoc(Maps.newHashMap()) {
+      @Override
+      public String getId() {
+        return null;
+      }
+
+      @Override
+      public String getRouting() {
+        return null;
+      }
+
+      @Override
+      public String getParent() {
+        return null;
+      }
     };
     long now = System.currentTimeMillis();
     doc.setField("javaDate", new Date(now));
@@ -74,6 +116,20 @@ public class BaseDocTest {
   @Test
   public void getNullableFieldAsDate() {
     BaseDoc doc = new BaseDoc(Maps.newHashMap()) {
+      @Override
+      public String getId() {
+        return null;
+      }
+
+      @Override
+      public String getRouting() {
+        return null;
+      }
+
+      @Override
+      public String getParent() {
+        return null;
+      }
     };
     long now = System.currentTimeMillis();
     doc.setField("javaDate", new Date(now));
index a4131becc04fb17d89dfa6950a3a09dafd61a237..e58c217455cf942a44655f4332f2bee5a40e336c 100644 (file)
  */
 package org.sonar.server.search;
 
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import java.util.Arrays;
 import java.util.Date;
-import java.util.Map;
+import java.util.List;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram.Interval;
+import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.DateUtils;
+import org.sonar.server.es.BaseDoc;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.NewIndex.NewIndexType;
 
@@ -57,11 +58,11 @@ public class FacetsMediumTest {
 
   @Test
   public void should_ignore_unknown_aggregation_type() throws Exception {
-    esTester.index(INDEX, TYPE, "noTags", newTagsDocument("noTags"));
-    esTester.index(INDEX, TYPE, "oneTag", newTagsDocument("oneTag", "tag1"));
-    esTester.index(INDEX, TYPE, "twoTags", newTagsDocument("twoTags", "tag1", "tag2"));
-    esTester.index(INDEX, TYPE, "threeTags", newTagsDocument("threeTags", "tag1", "tag2", "tag3"));
-    esTester.index(INDEX, TYPE, "fourTags", newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("noTags"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("oneTag", "tag1"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("twoTags", "tag1", "tag2"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("threeTags", "tag1", "tag2", "tag3"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
     SearchRequestBuilder search = esTester.client().prepareSearch(INDEX).setTypes(TYPE)
       .addAggregation(AggregationBuilders.cardinality(FIELD_TAGS).field(FIELD_TAGS));
 
@@ -72,9 +73,9 @@ public class FacetsMediumTest {
 
   @Test
   public void should_process_result_with_nested_missing_and_terms_aggregations() throws Exception {
-    esTester.index(INDEX, TYPE, "noTags", newTagsDocument("noTags"));
-    esTester.index(INDEX, TYPE, "oneTag", newTagsDocument("oneTag", "tag1"));
-    esTester.index(INDEX, TYPE, "fourTags", newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("noTags"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("oneTag", "tag1"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
 
     SearchRequestBuilder search = esTester.client().prepareSearch(INDEX).setTypes(TYPE)
       .addAggregation(AggregationBuilders.global("tags__global")
@@ -98,10 +99,10 @@ public class FacetsMediumTest {
 
   @Test
   public void should_ignore_empty_missing_aggregation() throws Exception {
-    esTester.index(INDEX, TYPE, "oneTag", newTagsDocument("oneTag", "tag1"));
-    esTester.index(INDEX, TYPE, "twoTags", newTagsDocument("twoTags", "tag1", "tag2"));
-    esTester.index(INDEX, TYPE, "threeTags", newTagsDocument("threeTags", "tag1", "tag2", "tag3"));
-    esTester.index(INDEX, TYPE, "fourTags", newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("oneTag", "tag1"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("twoTags", "tag1", "tag2"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("threeTags", "tag1", "tag2", "tag3"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("fourTags", "tag1", "tag2", "tag3", "tag4"));
 
     SearchRequestBuilder search = esTester.client().prepareSearch(INDEX).setTypes(TYPE)
       .addAggregation(AggregationBuilders.global("tags__global")
@@ -118,16 +119,16 @@ public class FacetsMediumTest {
 
   @Test
   public void should_process_result_with_date_histogram() throws Exception {
-    esTester.index(INDEX, TYPE, "first", newTagsDocument("first"));
-    esTester.index(INDEX, TYPE, "second", newTagsDocument("second"));
-    esTester.index(INDEX, TYPE, "third", newTagsDocument("third"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("first"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("second"));
+    esTester.putDocuments(INDEX, TYPE, newTagsDocument("third"));
 
     SearchRequestBuilder search = esTester.client().prepareSearch(INDEX).setTypes(TYPE)
       .addAggregation(
         AggregationBuilders.dateHistogram(FIELD_CREATED_AT)
           .minDocCount(0L)
           .field(FIELD_CREATED_AT)
-          .interval(Interval.MINUTE)
+          .interval(DateHistogramInterval.MINUTE)
           .format(DateUtils.DATETIME_FORMAT));
 
     Facets facets = new Facets(search.get());
@@ -139,15 +140,11 @@ public class FacetsMediumTest {
     assertThat(value.getValue()).isEqualTo(3L);
   }
 
-  private static Map<String, Object> newTagsDocument(String key, String... tags) {
-    ImmutableMap<String, Object> doc = ImmutableMap.of(
-      FIELD_KEY, key,
-      FIELD_TAGS, Arrays.asList(tags),
-      FIELD_CREATED_AT, new Date());
-    return doc;
+  private static TagsDoc newTagsDocument(String key, String... tags) {
+    return new TagsDoc().setKey(key).setTags(Arrays.asList(tags)).setCreatedAt(new Date());
   }
 
-  static class FacetsTestDefinition implements org.sonar.server.es.IndexDefinition {
+  private static class FacetsTestDefinition implements org.sonar.server.es.IndexDefinition {
 
     @Override
     public void define(IndexDefinitionContext context) {
@@ -157,4 +154,48 @@ public class FacetsMediumTest {
       newType.createDateTimeField(FIELD_CREATED_AT);
     }
   }
+
+  private static class TagsDoc extends BaseDoc {
+    public TagsDoc() {
+      super(Maps.<String, Object>newHashMap());
+    }
+
+    @Override
+    public String getId() {
+      return getKey();
+    }
+
+    @Override
+    public String getRouting() {
+      return null;
+    }
+
+    @Override
+    public String getParent() {
+      return null;
+    }
+
+    public String getKey() {
+      return getField(FIELD_KEY);
+    }
+
+    public List<String> getTags() {
+      return (List<String>) getField(FIELD_TAGS);
+    }
+
+    public TagsDoc setKey(String s) {
+      setField(FIELD_KEY, s);
+      return this;
+    }
+
+    public TagsDoc setTags(List<String> tags) {
+      setField(FIELD_TAGS, tags);
+      return this;
+    }
+
+    public TagsDoc setCreatedAt(Date date) {
+      setField(FIELD_CREATED_AT, date);
+      return this;
+    }
+  }
 }
index 7d91e5e71c7c96a6c2ccec04aeacbcaa7f5b1b44..885beb133bf55a7d702eee135d4da76945827dac 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.test.index;
 
 import com.google.common.base.Optional;
-import java.util.Arrays;
 import java.util.List;
 import org.junit.Rule;
 import org.junit.Test;
@@ -28,6 +27,7 @@ import org.sonar.api.config.Settings;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.SearchOptions;
 
+import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.guava.api.Assertions.assertThat;
 
@@ -40,8 +40,8 @@ public class TestIndexTest {
   @Test
   public void coveredFiles() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     List<CoveredFileDoc> result = underTest.coveredFiles("1");
 
@@ -53,9 +53,9 @@ public class TestIndexTest {
   @Test
   public void searchByTestFileUuid() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")),
-      newTestDoc("3", "TESTFILE2", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")),
+      newTestDoc("3", "TESTFILE2", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     List<TestDoc> result = underTest.searchByTestFileUuid("TESTFILE1", searchOptions()).getDocs();
 
@@ -66,9 +66,9 @@ public class TestIndexTest {
   @Test
   public void searchBySourceFileUuidAndLineNumber() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("10"), newCoverageBlock("11"), newCoverageBlock("12")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("3", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("10"), newCoveredFileDoc("11"), newCoveredFileDoc("12")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("3", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     List<TestDoc> result = underTest.searchBySourceFileUuidAndLineNumber("main-uuid-5", 82, searchOptions()).getDocs();
 
@@ -79,8 +79,8 @@ public class TestIndexTest {
   @Test
   public void searchByTestUuid() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     TestDoc test = underTest.getByTestUuid("1");
 
@@ -97,8 +97,8 @@ public class TestIndexTest {
   @Test
   public void getNullableByTestUuid() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     Optional<TestDoc> result = underTest.getNullableByTestUuid("1");
 
@@ -124,8 +124,8 @@ public class TestIndexTest {
   @Test
   public void searchByTestUuid_with_SearchOptions() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
-      newTestDoc("1", "TESTFILE1", newCoverageBlock("3"), newCoverageBlock("4"), newCoverageBlock("5")),
-      newTestDoc("2", "TESTFILE1", newCoverageBlock("5"), newCoverageBlock("6"), newCoverageBlock("7")));
+      newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
+      newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
 
     List<TestDoc> result = underTest.searchByTestUuid("1", searchOptions()).getDocs();
 
@@ -133,23 +133,23 @@ public class TestIndexTest {
     assertThat(result.get(0).testUuid()).isEqualTo("1");
   }
 
-  private CoveredFileDoc newCoverageBlock(String id) {
+  private CoveredFileDoc newCoveredFileDoc(String id) {
     return new CoveredFileDoc()
       .setFileUuid("main-uuid-" + id)
-      .setCoveredLines(Arrays.asList(25, 33, 82));
+      .setCoveredLines(asList(25, 33, 82));
   }
 
   private TestDoc newTestDoc(String testUuid, String fileUuid, CoveredFileDoc... coveredFiles) {
     return new TestDoc()
       .setUuid(testUuid)
-      .setProjectUuid("project-" + fileUuid)
+      .setProjectUuid("P1")
       .setName("name-" + testUuid)
       .setMessage("message-" + testUuid)
       .setStackTrace("stacktrace-" + testUuid)
       .setStatus("status-" + testUuid)
       .setDurationInMs(Long.valueOf(testUuid))
       .setFileUuid(fileUuid)
-      .setCoveredFiles(Arrays.asList(coveredFiles));
+      .setCoveredFiles(asList(coveredFiles));
   }
 
   private SearchOptions searchOptions() {
index ee3d15f35c45c42ff94db1632678e1ab2ab10a12..1cef3e8bd183cda56973e13aeb9a42b23f20af1c 100644 (file)
@@ -175,6 +175,7 @@ public class TestIndexerTest {
   private void indexTest(String projectUuid, String fileUuid, String testName, String uuid) throws IOException {
     es.client().prepareIndex(INDEX, TYPE)
       .setId(uuid)
+      .setRouting(projectUuid)
       .setSource(FileUtils.readFileToString(TestUtils.getResource(this.getClass(), projectUuid + "_" + fileUuid + "_" + testName + ".json")))
       .setRefresh(true)
       .get();
index 7485db97ce0bd4cd54b7d5efa93bbb38d5273891..6e6b5cff38f1ac4847a32bd8ab742a7cd27c309c 100644 (file)
@@ -45,7 +45,6 @@ import static org.sonar.server.test.index.TestIndexDefinition.FIELD_PROJECT_UUID
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STACKTRACE;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
-import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
 
 
 public class TestResultSetIteratorTest {
@@ -105,8 +104,7 @@ public class TestResultSetIteratorTest {
       entry(FIELD_MESSAGE, "MESSAGE_1"),
       entry(FIELD_DURATION_IN_MS, 1),
       entry(FIELD_STACKTRACE, "STACKTRACE_1"),
-      entry(FIELD_NAME, "NAME_1"),
-      entry(FIELD_UPDATED_AT, 1416239042000L));
+      entry(FIELD_NAME, "NAME_1"));
   }
 
   /**
@@ -135,8 +133,7 @@ public class TestResultSetIteratorTest {
       entry(FIELD_PROJECT_UUID, "P1"),
       entry(FIELD_FILE_UUID, "F1"),
       entry(FIELD_TEST_UUID, "U1"),
-      entry(FIELD_NAME, "N1"),
-      entry(FIELD_UPDATED_AT, 1416239042000L));
+      entry(FIELD_NAME, "N1"));
     ;
     // null values
     assertThat(doc).containsKeys(
index e6f708e3f551f6f7a55200618ed601840473ac98..6d542314170be499a09132f94bb08b32c957d497 100644 (file)
@@ -55,8 +55,8 @@ public class UserIndexTest {
   @Test
   public void get_nullable_by_login() throws Exception {
     UserDoc user1 = newUser(USER1_LOGIN, asList("scmA", "scmB"));
-    esTester.index(INDEX, TYPE_USER, USER1_LOGIN, user1.getFields());
-    esTester.index(INDEX, TYPE_USER, USER2_LOGIN, newUser(USER2_LOGIN, Collections.<String>emptyList()).getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, user1);
+    esTester.putDocuments(INDEX, TYPE_USER, newUser(USER2_LOGIN, Collections.<String>emptyList()));
 
     UserDoc userDoc = index.getNullableByLogin(USER1_LOGIN);
     assertThat(userDoc).isNotNull();
@@ -75,7 +75,7 @@ public class UserIndexTest {
   @Test
   public void get_nullable_by_login_should_be_case_sensitive() throws Exception {
     UserDoc user1 = newUser(USER1_LOGIN, asList("scmA", "scmB"));
-    esTester.index(INDEX, TYPE_USER, USER1_LOGIN, user1.getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, user1);
 
     assertThat(index.getNullableByLogin(USER1_LOGIN)).isNotNull();
     assertThat(index.getNullableByLogin("UsEr1")).isNull();
@@ -86,9 +86,9 @@ public class UserIndexTest {
     UserDoc user1 = newUser("user1", asList("user_1", "u1"));
     UserDoc user2 = newUser("user_with_same_email_as_user1", asList("user_2")).setEmail(user1.email());
     UserDoc user3 = newUser("inactive_user_with_same_scm_as_user1", user1.scmAccounts()).setActive(false);
-    esTester.index(INDEX, TYPE_USER, user1.login(), user1.getFields());
-    esTester.index(INDEX, TYPE_USER, user2.login(), user2.getFields());
-    esTester.index(INDEX, TYPE_USER, user3.login(), user3.getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, user1);
+    esTester.putDocuments(INDEX, TYPE_USER, user2);
+    esTester.putDocuments(INDEX, TYPE_USER, user3);
 
     assertThat(index.getAtMostThreeActiveUsersForScmAccount(user1.scmAccounts().get(0))).extractingResultOf("login").containsOnly(user1.login());
     assertThat(index.getAtMostThreeActiveUsersForScmAccount(user1.login())).extractingResultOf("login").containsOnly(user1.login());
@@ -104,7 +104,7 @@ public class UserIndexTest {
   public void getAtMostThreeActiveUsersForScmAccount_ignore_inactive_user() throws Exception {
     String scmAccount = "scmA";
     UserDoc user = newUser(USER1_LOGIN, asList(scmAccount)).setActive(false);
-    esTester.index(INDEX, TYPE_USER, user.login(), user.getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, user);
 
     assertThat(index.getAtMostThreeActiveUsersForScmAccount(user.login())).isEmpty();
     assertThat(index.getAtMostThreeActiveUsersForScmAccount(scmAccount)).isEmpty();
@@ -117,10 +117,10 @@ public class UserIndexTest {
     UserDoc user2 = newUser("user2", Collections.<String>emptyList()).setEmail(email);
     UserDoc user3 = newUser("user3", Collections.<String>emptyList()).setEmail(email);
     UserDoc user4 = newUser("user4", Collections.<String>emptyList()).setEmail(email);
-    esTester.index(INDEX, TYPE_USER, user1.login(), user1.getFields());
-    esTester.index(INDEX, TYPE_USER, user2.login(), user2.getFields());
-    esTester.index(INDEX, TYPE_USER, user3.login(), user3.getFields());
-    esTester.index(INDEX, TYPE_USER, user4.login(), user4.getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, user1);
+    esTester.putDocuments(INDEX, TYPE_USER, user2);
+    esTester.putDocuments(INDEX, TYPE_USER, user3);
+    esTester.putDocuments(INDEX, TYPE_USER, user4);
 
     // restrict results to 3 users
     assertThat(index.getAtMostThreeActiveUsersForScmAccount(email)).hasSize(3);
@@ -128,8 +128,8 @@ public class UserIndexTest {
 
   @Test
   public void searchUsers() throws Exception {
-    esTester.index(INDEX, TYPE_USER, USER1_LOGIN, newUser(USER1_LOGIN, Arrays.asList("user_1", "u1")).getFields());
-    esTester.index(INDEX, TYPE_USER, USER2_LOGIN, newUser(USER2_LOGIN, Collections.<String>emptyList()).getFields());
+    esTester.putDocuments(INDEX, TYPE_USER, newUser(USER1_LOGIN, Arrays.asList("user_1", "u1")));
+    esTester.putDocuments(INDEX, TYPE_USER, newUser(USER2_LOGIN, Collections.<String>emptyList()));
 
     assertThat(index.search(null, new SearchOptions()).getDocs()).hasSize(2);
     assertThat(index.search("user", new SearchOptions()).getDocs()).hasSize(2);
index 9d5683218809e57c0e34f3c4b8eed3d2a48eb657..4f0210e6b95c020127b911a99d19ddc1955664c8 100644 (file)
@@ -42,8 +42,8 @@ public class ViewIndexTest {
   public void find_all_view_uuids() throws Exception {
     ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1"));
     ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2"));
-    esTester.index(INDEX, TYPE_VIEW, view1.uuid(), view1.getFields());
-    esTester.index(INDEX, TYPE_VIEW, view2.uuid(), view2.getFields());
+    esTester.putDocuments(INDEX, TYPE_VIEW, view1);
+    esTester.putDocuments(INDEX, TYPE_VIEW, view2);
 
     List<String> result = newArrayList(index.findAllViewUuids());
 
@@ -62,9 +62,9 @@ public class ViewIndexTest {
     ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1"));
     ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2", "P3", "P4"));
     ViewDoc view3 = new ViewDoc().setUuid("UUID3").setProjects(asList("P2", "P3", "P4"));
-    esTester.index(INDEX, TYPE_VIEW, view1.uuid(), view1.getFields());
-    esTester.index(INDEX, TYPE_VIEW, view2.uuid(), view2.getFields());
-    esTester.index(INDEX, TYPE_VIEW, view3.uuid(), view3.getFields());
+    esTester.putDocuments(INDEX, TYPE_VIEW, view1);
+    esTester.putDocuments(INDEX, TYPE_VIEW, view2);
+    esTester.putDocuments(INDEX, TYPE_VIEW, view3);
 
     index.delete(asList(view1.uuid(), view2.uuid()));
 
index b04e3a21437d13ce498dcdfa98822b6109476823..a860949142d0dbec3eb53390492fd9f6e8699025 100644 (file)
@@ -42,6 +42,7 @@
       <useProjectArtifact>false</useProjectArtifact>
       <includes>
         <include>org.elasticsearch:elasticsearch</include>
+        <include>net.java.dev.jna:jna</include>
       </includes>
       <scope>provided</scope>
     </dependencySet>
index 087e497a6ac230761e2de6382936832210b2c5eb..02f76e4a60d4dc7266d1ea72afdabb11d4b397a6 100644 (file)
             <configuration>
               <rules>
                 <requireFilesSize>
-                  <minsize>110000000</minsize>
-                  <maxsize>120000000</maxsize>
+                  <minsize>120000000</minsize>
+                  <maxsize>125000000</maxsize>
                   <files>
                     <file>${project.build.directory}/sonarqube-${project.version}.zip</file>
                   </files>
index 53bd63175efea6a8c3446c749821865783054682..bc3c54e98685ae0377de6ed9256527a497982d23 100644 (file)
@@ -93,7 +93,7 @@ public class PurgeDao implements Dao {
     List<String> issueKeys = mapper.selectOldClosedIssueKeys(conf.rootProjectIdUuid().getUuid(), dateToLong(toDate));
     executeLargeInputs(issueKeys, new DeleteIssueChangesFromIssueKeys(mapper));
     executeLargeInputs(issueKeys, new DeleteIssuesFromKeys(mapper));
-    listener.onIssuesRemoval(issueKeys);
+    listener.onIssuesRemoval(conf.rootProjectIdUuid().getUuid(), issueKeys);
   }
 
   private static void deleteAbortedBuilds(ResourceDto project, PurgeCommands commands) {
index a2224c2d7157bdc4962db479e2b2741e2a76f631..1d77fcc5a971dce251a80bf58c64cd38a4fb65ee 100644 (file)
@@ -30,12 +30,12 @@ public interface PurgeListener {
     }
 
     @Override
-    public void onIssuesRemoval(List<String> issueKeys) {
+    public void onIssuesRemoval(String projectUuid, List<String> issueKeys) {
       // do nothing
     }
   };
 
   void onComponentDisabling(String uuid);
 
-  void onIssuesRemoval(List<String> issueKeys);
+  void onIssuesRemoval(String projectUuid, List<String> issueKeys);
 }
index 637a8f3e1039987c9cb41742c6566ae3ad572590..aace20f99df321d6b4258cc411dc74e220de909c 100644 (file)
@@ -44,6 +44,9 @@ import static org.sonar.db.ce.CeTaskTypes.REPORT;
 
 public class PurgeDaoTest {
 
+  private static final String THE_PROJECT_UUID = "P1";
+  private static final long THE_PROJECT_ID = 1L;
+
   System2 system2 = mock(System2.class);
 
   @Rule
@@ -79,7 +82,7 @@ public class PurgeDaoTest {
   @Test
   public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
     dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
-    underTest.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[]{Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
+    underTest.purge(new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
     dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots");
   }
 
@@ -95,18 +98,18 @@ public class PurgeDaoTest {
   @Test
   public void shouldDeleteSnapshots() {
     dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshots.xml");
-    underTest.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L), new PurgeProfiler());
+    underTest.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(THE_PROJECT_ID), new PurgeProfiler());
     dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshots-result.xml", "snapshots");
   }
 
   @Test
   public void shouldSelectPurgeableSnapshots() {
     dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableSnapshots.xml");
-    List<PurgeableSnapshotDto> snapshots = underTest.selectPurgeableSnapshots(1L);
+    List<PurgeableSnapshotDto> snapshots = underTest.selectPurgeableSnapshots(THE_PROJECT_ID);
 
     assertThat(snapshots).hasSize(3);
-    assertThat(getById(snapshots, 1L).isLast()).isTrue();
-    assertThat(getById(snapshots, 1L).hasEvents()).isFalse();
+    assertThat(getById(snapshots, THE_PROJECT_ID).isLast()).isTrue();
+    assertThat(getById(snapshots, THE_PROJECT_ID).hasEvents()).isFalse();
     assertThat(getById(snapshots, 4L).isLast()).isFalse();
     assertThat(getById(snapshots, 4L).hasEvents()).isFalse();
     assertThat(getById(snapshots, 5L).isLast()).isFalse();
@@ -182,16 +185,18 @@ public class PurgeDaoTest {
     dbTester.assertDbUnit(getClass(), "should_delete_old_closed_issues-result.xml", "issues", "issue_changes");
 
     Class<ArrayList<String>> listClass = (Class<ArrayList<String>>)(Class)ArrayList.class;
-    ArgumentCaptor<ArrayList<String>> argument = ArgumentCaptor.forClass(listClass);
+    ArgumentCaptor<ArrayList<String>> issueKeys = ArgumentCaptor.forClass(listClass);
+    ArgumentCaptor<String> projectUuid = ArgumentCaptor.forClass(String.class);
 
-    verify(purgeListener).onIssuesRemoval(argument.capture());
-    assertThat(argument.getValue()).containsOnly("ISSUE-1", "ISSUE-2");
+    verify(purgeListener).onIssuesRemoval(projectUuid.capture(), issueKeys.capture());
+    assertThat(projectUuid.getValue()).isEqualTo(THE_PROJECT_UUID);
+    assertThat(issueKeys.getValue()).containsOnly("ISSUE-1", "ISSUE-2");
   }
 
   @Test
   public void should_delete_all_closed_issues() {
     dbTester.prepareDbUnit(getClass(), "should_delete_all_closed_issues.xml");
-    underTest.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 0), PurgeListener.EMPTY, new PurgeProfiler());
+    underTest.purge(new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "1"), new String[0], 0), PurgeListener.EMPTY, new PurgeProfiler());
     dbTester.assertDbUnit(getClass(), "should_delete_all_closed_issues-result.xml", "issues", "issue_changes");
   }
 
@@ -222,10 +227,10 @@ public class PurgeDaoTest {
   }
 
   private static PurgeConfiguration newConfigurationWith30Days() {
-    return new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 30);
+    return new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, THE_PROJECT_UUID), new String[0], 30);
   }
 
   private static PurgeConfiguration newConfigurationWith30Days(System2 system2) {
-    return new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 30, system2);
+    return new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, THE_PROJECT_UUID), new String[0], 30, system2);
   }
 }
index 122cc876b8a95db3fe150bca2573f058859a972c..4dad1831f6c7494168808891e58189b899abfad5 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <projects id="1" uuid="1" enabled="[true]" root_id="[null]" created_at="[null]"
+  <projects id="1" uuid="P1" enabled="[true]" root_id="[null]" created_at="[null]"
             long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project"
             description="[null]" language="java" copy_resource_id="[null]" person_id="[null]"
             authorization_updated_at="[null]"/>
@@ -20,7 +20,7 @@
   <!--
   <issues id="1" kee="ISSUE-1"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1262300400000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500" manual_severity="[false]"
@@ -30,7 +30,7 @@
 
   <issues id="2" kee="ISSUE-2"
           component_uuid="1"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1262300400000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500" manual_severity="[false]"
@@ -42,7 +42,7 @@
   <!-- old open issues -> do not purge -->
   <issues id="3" kee="ISSUE-3"
           component_uuid="1"
-          project_uuid="1"
+          project_uuid="P1"
           status="OPEN"
           issue_close_date="[null]"
           resolution="[null]" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -58,7 +58,7 @@
   <!-- recent open and closed issues -> do not purge -->
   <issues id="4" kee="ISSUE-4"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="OPEN"
           issue_close_date="[null]"
           resolution="[null]" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -73,7 +73,7 @@
 
   <issues id="5" kee="ISSUE-5"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1735686000000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
index 9ae005782644d7c919aca4e2dd6914169230c2f6..d826ee8e3113f37db97e952ed37cb145619d61a0 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <projects id="1" uuid="1" enabled="[true]" root_id="[null]" created_at="[null]"
+  <projects id="1" uuid="P1" enabled="[true]" root_id="[null]" created_at="[null]"
             long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project"
             description="[null]" language="java" copy_resource_id="[null]" person_id="[null]"
             authorization_updated_at="[null]"/>
@@ -19,7 +19,7 @@
   <!-- old closed issues on file and project -> to be purged -->
   <issues id="1" kee="ISSUE-1"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1262300400000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -34,7 +34,7 @@
 
   <issues id="2" kee="ISSUE-2"
           component_uuid="1"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1262300400000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -50,7 +50,7 @@
   <!-- old open issues -> do not purge -->
   <issues id="3" kee="ISSUE-3"
           component_uuid="1"
-          project_uuid="1"
+          project_uuid="P1"
           status="OPEN"
           issue_close_date="[null]"
           resolution="[null]" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -66,7 +66,7 @@
   <!-- recent open and closed issues -> do not purge -->
   <issues id="4" kee="ISSUE-4"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="OPEN"
           issue_close_date="[null]"
           resolution="[null]" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"
@@ -81,7 +81,7 @@
 
   <issues id="5" kee="ISSUE-5"
           component_uuid="100"
-          project_uuid="1"
+          project_uuid="P1"
           status="CLOSED"
           issue_close_date="1735686000000"
           resolution="FIXED" line="200" severity="BLOCKER" reporter="[null]" assignee="arthur" rule_id="500"