summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-06-10 17:34:50 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-06-10 17:34:50 +0200
commitcb0fdec3f93936e9a862eee27bb059d4e3c4ad96 (patch)
tree9e6a7401320ee2d8dddceb57060372090bf81630 /sonar-server/src/main
parent25a265324bfba9ebf64c471dc6c7f2bc5e334e4d (diff)
downloadsonarqube-cb0fdec3f93936e9a862eee27bb059d4e3c4ad96.tar.gz
sonarqube-cb0fdec3f93936e9a862eee27bb059d4e3c4ad96.zip
SONAR-5329 - Added LogServiceMediumTest
Diffstat (limited to 'sonar-server/src/main')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/log/index/LogIndex.java46
-rw-r--r--sonar-server/src/main/java/org/sonar/server/log/index/LogNormalizer.java3
2 files changed, 39 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/log/index/LogIndex.java b/sonar-server/src/main/java/org/sonar/server/log/index/LogIndex.java
index 673d1eec7e2..b57bfef5dac 100644
--- a/sonar-server/src/main/java/org/sonar/server/log/index/LogIndex.java
+++ b/sonar-server/src/main/java/org/sonar/server/log/index/LogIndex.java
@@ -19,8 +19,12 @@
*/
package org.sonar.server.log.index;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.log.Log;
@@ -31,6 +35,7 @@ import org.sonar.server.search.BaseIndex;
import org.sonar.server.search.ESNode;
import org.sonar.server.search.IndexDefinition;
import org.sonar.server.search.IndexField;
+import org.sonar.server.search.QueryOptions;
import java.io.IOException;
import java.util.HashMap;
@@ -47,7 +52,15 @@ public class LogIndex extends BaseIndex<Log, LogDto, LogKey> {
@Override
protected String getKeyValue(LogKey key) {
- return key.toString();
+ //FIXME too many collision with key.toString() due to lack of time precision
+ return null;//return key.toString();
+ }
+
+ @Override
+ protected Map mapKey() {
+ return null;
+// Map<String, Object> mapping = new HashMap<String, Object>();
+// return mapping;
}
@Override
@@ -65,13 +78,6 @@ public class LogIndex extends BaseIndex<Log, LogDto, LogKey> {
}
@Override
- protected Map mapKey() {
- Map<String, Object> mapping = new HashMap<String, Object>();
- mapping.put("path", LogNormalizer.LogFields.KEY.field());
- return mapping;
- }
-
- @Override
protected Log toDoc(final Map<String, Object> fields) {
return new LogDoc(fields);
}
@@ -82,4 +88,28 @@ public class LogIndex extends BaseIndex<Log, LogDto, LogKey> {
.setTypes(this.getIndexType())
.get());
}
+
+ public LogResult search(LogQuery query, QueryOptions options) {
+
+ SearchRequestBuilder esSearch = getClient()
+ .prepareSearch(this.getIndexName())
+ .setTypes(this.getIndexType())
+ .setIndices(this.getIndexName());
+
+ //TODO implement query and filters based on LogQuery
+ esSearch.setQuery(QueryBuilders.matchAllQuery());
+
+ if (options.isScroll()) {
+ esSearch.setSearchType(SearchType.SCAN);
+ esSearch.setScroll(TimeValue.timeValueMinutes(3));
+ }
+
+ SearchResponse esResult = esSearch.get();
+
+ if (options.isScroll()) {
+ return new LogResult(this, esResult);
+ } else {
+ return new LogResult(esResult);
+ }
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/log/index/LogNormalizer.java b/sonar-server/src/main/java/org/sonar/server/log/index/LogNormalizer.java
index 179d1706b25..c71926ef8f8 100644
--- a/sonar-server/src/main/java/org/sonar/server/log/index/LogNormalizer.java
+++ b/sonar-server/src/main/java/org/sonar/server/log/index/LogNormalizer.java
@@ -93,7 +93,6 @@ public class LogNormalizer extends BaseNormalizer<LogDto, LogKey> {
public List<UpdateRequest> normalize(LogDto dto) {
Map<String, Object> logDoc = new HashMap<String, Object>();
- logDoc.put("_id", dto.getKey());
logDoc.put(LogFields.KEY.field(), dto.getKey());
logDoc.put(LogFields.TYPE.field(), dto.getType());
logDoc.put(LogFields.AUTHOR.field(), dto.getAuthor());
@@ -104,7 +103,7 @@ public class LogNormalizer extends BaseNormalizer<LogDto, LogKey> {
/* Creating updateRequest */
return ImmutableList.of(new UpdateRequest()
- .id(dto.getKey().toString())
+ //Need to make a UUID because Key does not insure unicity
.doc(logDoc)
.upsert(logDoc));
}