aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/java
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-03 18:19:28 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-04 10:29:06 +0200
commit11b71d31b0e275a13830bdf3014ab4ee0298b24f (patch)
treebe45bff106b31afbd470c9da65a72f0362e849a8 /sonar-server/src/main/java
parent46c588d9db7395d6185b95038a04dccf44e079b0 (diff)
downloadsonarqube-11b71d31b0e275a13830bdf3014ab4ee0298b24f.tar.gz
sonarqube-11b71d31b0e275a13830bdf3014ab4ee0298b24f.zip
SONAR-5007 - Fix date-synch for ES Synchronizer
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
index 83d457c1d59..6dd84f084df 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
@@ -26,6 +26,8 @@ import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRespon
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.Client;
@@ -42,8 +44,9 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.elasticsearch.search.aggregations.metrics.max.Max;
import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount;
-import org.elasticsearch.search.sort.SortOrder;
+import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.core.cluster.WorkQueue;
@@ -199,13 +202,17 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
public Date getLastSynchronization() {
Date date;
try {
- date = getClient().prepareSearch(this.getIndexName())
+ SearchRequestBuilder request = getClient().prepareSearch(this.getIndexName())
.setTypes(this.getIndexType())
.setQuery(QueryBuilders.matchAllQuery())
- .setSize(1)
- .addField(BaseNormalizer.UPDATED_AT_FIELD)
- .addSort(BaseNormalizer.UPDATED_AT_FIELD, SortOrder.DESC)
- .get().getHits().getAt(0).field(BaseNormalizer.UPDATED_AT_FIELD).getValue();
+ .setSize(0)
+ .addAggregation(AggregationBuilders.max("latest")
+ .field(BaseNormalizer.UPDATED_AT_FIELD));
+
+ SearchResponse response = request.get();
+
+ Max max = (Max) response.getAggregations().get("latest");
+ return new DateTime(Double.valueOf(max.getValue()).longValue()).toDate();
} catch (Exception e) {
date = new Date(0L);
}