static class MinimalTransportClient extends TransportClient {
MinimalTransportClient(Settings settings) {
- super(settings, Settings.EMPTY, unmodifiableList(singletonList(Netty4Plugin.class)));
+ super(settings, unmodifiableList(singletonList(Netty4Plugin.class)));
}
@Override
<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>
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;
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;
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);
}
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());
}
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;
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;
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;
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;
);
});
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()));
}
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;
.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);
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;
.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);
}
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));
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);
};
// 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);
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(
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;
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();
}
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
*/
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;