]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 apply all breaking changes of ES 5.5
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 27 Jul 2017 11:32:12 +0000 (13:32 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/application/process/EsProcessMonitor.java
server/sonar-server/pom.xml
server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java
server/sonar-server/src/main/java/org/sonar/server/es/EsUtils.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationTypeSupport.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java
server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationTypeSupportTest.java

index d5b39eac99d18e3bd2d0adc658d42b1bab5ad17b..14ddd80220af53f2a76c38b3bf3f9279fd341287 100644 (file)
@@ -105,7 +105,7 @@ public class EsProcessMonitor extends AbstractProcessMonitor {
   static class MinimalTransportClient extends TransportClient {
 
     MinimalTransportClient(Settings settings) {
-      super(settings, Settings.EMPTY, unmodifiableList(singletonList(Netty4Plugin.class)));
+      super(settings, unmodifiableList(singletonList(Netty4Plugin.class)));
     }
 
     @Override
index 6278ee7499ec18bd59a4b32b6c932c2653536b98..f2400aa3a7d5807d0b9c270a7c8b474640dad224 100644 (file)
       <groupId>org.slf4j</groupId>
       <artifactId>jul-to-slf4j</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-to-slf4j</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
index a844a5f1d5908c845f9794b76d01b88fe8948966..8881940b02ab22d8a8f5b1a15c261b005526c843 100644 (file)
@@ -26,7 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nullable;
-import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.DocWriteRequest;
 import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
 import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder;
 import org.elasticsearch.action.bulk.BackoffPolicy;
@@ -35,7 +35,9 @@ import org.elasticsearch.action.bulk.BulkProcessor;
 import org.elasticsearch.action.bulk.BulkProcessor.Listener;
 import org.elasticsearch.action.bulk.BulkRequest;
 import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.delete.DeleteRequest;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
+import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -116,7 +118,17 @@ public class BulkIndexer {
     return result;
   }
 
-  public void add(ActionRequest request) {
+  public void add(IndexRequest request) {
+    result.incrementRequests();
+    bulkProcessor.add(request);
+  }
+
+  public void add(DeleteRequest request) {
+    result.incrementRequests();
+    bulkProcessor.add(request);
+  }
+
+  public void add(DocWriteRequest request) {
     result.incrementRequests();
     bulkProcessor.add(request);
   }
index 0ed12e5a20ec110c61a4be57aa01cdc98a0520e7..12a012d1b2d1d02b74bee400efcc6867dea9a851 100644 (file)
@@ -67,7 +67,7 @@ public class EsUtils {
 
   public static LinkedHashMap<String, Long> termsToMap(Terms terms) {
     LinkedHashMap<String, Long> map = new LinkedHashMap<>();
-    List<Terms.Bucket> buckets = terms.getBuckets();
+    List<? extends Terms.Bucket> buckets = terms.getBuckets();
     for (Terms.Bucket bucket : buckets) {
       map.put(bucket.getKeyAsString(), bucket.getDocCount());
     }
index 96fc1bec8f57d4dfe8bb5b825c774e6cc92b06f7..16af253251c6665dcb15f383fc68f2a64e49a6fb 100644 (file)
@@ -22,7 +22,7 @@ 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.DocWriteRequest;
 import org.elasticsearch.action.ListenableActionFuture;
 import org.elasticsearch.action.bulk.BulkAction;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
@@ -81,7 +81,7 @@ public class ProxyBulkRequestBuilder extends BulkRequestBuilder {
     message.append("Bulk[");
     Multiset<BulkRequestKey> groupedRequests = LinkedHashMultiset.create();
     for (int i = 0; i < request.requests().size(); i++) {
-      ActionRequest<?> item = request.requests().get(i);
+      DocWriteRequest item = request.requests().get(i);
       String requestType;
       String index;
       String docType;
index 59e54f1b91b124d613995a4c779b0de8c7f89983..4a955534caa24061f24f48697ced91ceebd9cd36 100644 (file)
@@ -47,6 +47,7 @@ import org.elasticsearch.indices.TermsLookup;
 import org.elasticsearch.search.aggregations.AggregationBuilder;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
+import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
 import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
 import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@@ -56,9 +57,9 @@ import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude
 import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
 import org.elasticsearch.search.aggregations.metrics.min.Min;
 import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder;
+import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount;
 import org.elasticsearch.search.sort.FieldSortBuilder;
 import org.joda.time.DateTimeZone;
-import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount;
 import org.joda.time.Duration;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
@@ -688,12 +689,14 @@ public class IssueIndex {
         );
     });
     SearchResponse response = request.get();
-    return response.getAggregations().asList().stream().flatMap(projectBucket -> {
-      long count = ((InternalValueCount) projectBucket.getProperty(projectBucket.getName() + "_count")).getValue();
+    return response.getAggregations().asList().stream()
+      .map(x -> (InternalFilter) x)
+      .flatMap(projectBucket -> {
+      long count = ((InternalValueCount) projectBucket.getAggregations().get(projectBucket.getName() + "_count")).getValue();
       if (count < 1L) {
         return Stream.empty();
       }
-      long lastIssueDate = (long) ((InternalMax) projectBucket.getProperty(projectBucket.getName() + "_maxFuncCreatedAt")).getValue();
+      long lastIssueDate = (long) ((InternalMax) projectBucket.getAggregations().get(projectBucket.getName() + "_maxFuncCreatedAt")).getValue();
       return Stream.of(new ProjectStatistics(projectBucket.getName(), count, lastIssueDate));
     }).collect(MoreCollectors.toList(projectUuids.size()));
   }
index 991e6a4233de41458fb7b8771e1aa5cf5b51c734..5555052289986567ec5a77e699fbc569c12c333d 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Optional;
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.join.query.JoinQueryBuilders;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 import org.sonar.db.user.GroupDto;
@@ -117,7 +118,7 @@ public class AuthorizationTypeSupport {
       .map(GroupDto::getId)
       .forEach(groupId -> filter.should(termQuery(FIELD_GROUP_IDS, groupId)));
 
-    return QueryBuilders.hasParentQuery(
+    return JoinQueryBuilders.hasParentQuery(
       TYPE_AUTHORIZATION,
       QueryBuilders.boolQuery().filter(filter),
       false);
index 7fd7069deda9568827b802010f27b90456122737..57f63f63196c6caa978c16cd7e7d4437874b005b 100644 (file)
@@ -35,11 +35,13 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.HasParentQueryBuilder;
 import org.elasticsearch.index.query.Operator;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.TermsQueryBuilder;
+import org.elasticsearch.join.aggregations.JoinAggregationBuilders;
+import org.elasticsearch.join.query.HasParentQueryBuilder;
+import org.elasticsearch.join.query.JoinQueryBuilders;
 import org.elasticsearch.search.aggregations.AggregationBuilder;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
@@ -258,7 +260,7 @@ public class RuleIndex {
         .map(tag -> boolQuery()
           .filter(QueryBuilders.termQuery(FIELD_RULE_EXTENSION_TAGS, tag))
           .filter(termsQuery(FIELD_RULE_EXTENSION_SCOPE, RuleExtensionScope.system().getScope(), RuleExtensionScope.organization(query.getOrganization()).getScope())))
-        .map(childQuery -> QueryBuilders.hasChildQuery(INDEX_TYPE_RULE_EXTENSION.getType(), childQuery, ScoreMode.None))
+        .map(childQuery -> JoinQueryBuilders.hasChildQuery(INDEX_TYPE_RULE_EXTENSION.getType(), childQuery, ScoreMode.None))
         .forEach(q::should);
       filters.put(FIELD_RULE_EXTENSION_TAGS, q);
     }
@@ -316,18 +318,18 @@ public class RuleIndex {
 
       if (TRUE.equals(query.getActivation())) {
         filters.put("activation",
-          QueryBuilders.hasChildQuery(INDEX_TYPE_ACTIVE_RULE.getType(),
+          JoinQueryBuilders.hasChildQuery(INDEX_TYPE_ACTIVE_RULE.getType(),
             childQuery, ScoreMode.None));
       } else if (FALSE.equals(query.getActivation())) {
         filters.put("activation",
           boolQuery().mustNot(
-            QueryBuilders.hasChildQuery(INDEX_TYPE_ACTIVE_RULE.getType(),
+            JoinQueryBuilders.hasChildQuery(INDEX_TYPE_ACTIVE_RULE.getType(),
               childQuery, ScoreMode.None)));
       }
       QProfileDto compareToQProfile = query.getCompareToQProfile();
       if (compareToQProfile != null) {
         filters.put("comparison",
-          QueryBuilders.hasChildQuery(
+          JoinQueryBuilders.hasChildQuery(
             INDEX_TYPE_ACTIVE_RULE.getType(),
             boolQuery().must(QueryBuilders.termQuery(FIELD_ACTIVE_RULE_PROFILE_UUID, compareToQProfile.getRulesProfileUuid())),
             ScoreMode.None));
@@ -393,7 +395,7 @@ public class RuleIndex {
             RuleExtensionScope.organization(query.getOrganization()).getScope()))
           .subAggregation(termsAggregation);
 
-        return AggregationBuilders.children("children_for_" + termsAggregation.getName(), INDEX_TYPE_RULE_EXTENSION.getType())
+        return JoinAggregationBuilders.children("children_for_" + termsAggregation.getName(), INDEX_TYPE_RULE_EXTENSION.getType())
           .subAggregation(scopeAggregation);
       };
 
@@ -437,7 +439,7 @@ public class RuleIndex {
       // 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")
-      HasParentQueryBuilder ruleFilter = QueryBuilders.hasParentQuery(
+      HasParentQueryBuilder ruleFilter = JoinQueryBuilders.hasParentQuery(
         INDEX_TYPE_RULE.getType(),
         stickyFacetBuilder.getStickyFacetFilter("activation"),
         false);
@@ -448,7 +450,7 @@ public class RuleIndex {
       RuleIndex.addTermFilter(childrenFilter, FIELD_ACTIVE_RULE_INHERITANCE, query.getInheritance());
       QueryBuilder activeRuleFilter = childrenFilter.must(ruleFilter);
 
-      AggregationBuilder activeSeverities = AggregationBuilders.children(FACET_ACTIVE_SEVERITIES + "_children", INDEX_TYPE_ACTIVE_RULE.getType())
+      AggregationBuilder activeSeverities = JoinAggregationBuilders.children(FACET_ACTIVE_SEVERITIES + "_children", INDEX_TYPE_ACTIVE_RULE.getType())
         .subAggregation(
           AggregationBuilders.filter(FACET_ACTIVE_SEVERITIES + "_filter", activeRuleFilter)
             .subAggregation(
index 8a1b1148eb545497ac829beb7c64d9c9adac9f32..100be3127102f2a882c9d090c78a293364302686 100644 (file)
@@ -87,8 +87,8 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
 import org.elasticsearch.indices.recovery.RecoverySettings;
 import org.elasticsearch.node.MockNode;
 import org.elasticsearch.node.Node;
+import org.elasticsearch.node.NodeService;
 import org.elasticsearch.node.NodeValidationException;
-import org.elasticsearch.node.service.NodeService;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.repositories.RepositoryMissingException;
 import org.elasticsearch.script.ScriptService;
index a0e6aaca9ecee6196c8afb2d3716634d22f3f767..3c27ce34a8bbb225ea0a987b34309fc41ab8ed6d 100644 (file)
@@ -114,7 +114,7 @@ public class EsTester extends ExternalResource {
       public Settings nodeSettings(int nodeOrdinal) {
         return Settings.builder()
           .put(NetworkModule.HTTP_ENABLED.getKey(), false)
-          .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
+          .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "single-node")
           .put(networkSettings.build())
           .build();
       }
@@ -207,17 +207,11 @@ public class EsTester extends ExternalResource {
   private void ensureClusterStateConsistency() throws IOException {
     if (cluster != null) {
       ClusterState masterClusterState = cluster.client().admin().cluster().prepareState().all().get().getState();
-      byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
-      // remove local node reference
-      masterClusterState = ClusterState.Builder.fromBytes(masterClusterStateBytes, null);
       Map<String, Object> masterStateMap = convertToMap(masterClusterState);
       int masterClusterStateSize = ClusterState.Builder.toBytes(masterClusterState).length;
       String masterId = masterClusterState.nodes().getMasterNodeId();
       for (Client client : cluster.getClients()) {
         ClusterState localClusterState = client.admin().cluster().prepareState().all().setLocal(true).get().getState();
-        byte[] localClusterStateBytes = ClusterState.Builder.toBytes(localClusterState);
-        // remove local node reference
-        localClusterState = ClusterState.Builder.fromBytes(localClusterStateBytes, null);
         final Map<String, Object> localStateMap = convertToMap(localClusterState);
         final int localClusterStateSize = ClusterState.Builder.toBytes(localClusterState).length;
         // Check that the non-master node has the same version of the cluster state as the master and
index f0efd0ff5b8cf92693e2f897b639be44d9f2a108..9fc5af7ecede2e7dd1187f37b140b83fa9aab1ff 100644 (file)
@@ -19,9 +19,9 @@
  */
 package org.sonar.server.permission.index;
 
-import org.elasticsearch.index.query.HasParentQueryBuilder;
 import org.elasticsearch.index.query.MatchAllQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.join.query.HasParentQueryBuilder;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.db.user.GroupDto;