From eb5a7d26a5b7270351a78ba239068e197430b3ec Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Wed, 8 Oct 2014 16:57:41 +0200 Subject: [PATCH] fix quality flaws --- .../java/org/sonar/search/SearchServer.java | 8 +++---- .../org/sonar/server/rule/RuleService.java | 4 ++-- .../sonar/server/rule/index/RuleIndex.java | 12 +++++----- .../server/rule/index/RuleNormalizer.java | 14 +++++++----- .../org/sonar/server/search/IndexQueue.java | 22 ++++++------------- .../sonar/server/search/action/DeleteKey.java | 2 +- .../search/action/DeleteNestedItem.java | 2 +- .../server/search/action/IndexAction.java | 4 ++-- .../sonar/server/search/action/InsertDto.java | 2 +- .../server/search/action/RefreshIndex.java | 2 +- .../sonar/server/search/action/UpsertDto.java | 2 +- .../search/action/UpsertNestedItem.java | 2 +- 12 files changed, 35 insertions(+), 41 deletions(-) diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index 9a32277c96f..64a23f35ce7 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -99,9 +99,9 @@ public class SearchServer implements Monitored { .put("index.merge.scheduler.max_thread_count", Math.max(1, Math.min(3, Runtime.getRuntime().availableProcessors() / 2))) - // Optimization TBD (second one must have ES > 1.2 - // .put("indices.memory.index_buffer_size", "512mb") - // .put("index.translog.flush_threshold_size", "1gb") + // Optimization TBD (second one must have ES > 1.2) can be: + // indices.memory.index_buffer_size=512mb + // index.translog.flush_threshold_size=1gb // Install our own listUpdate scripts .put("script.default_lang", "native") @@ -143,7 +143,7 @@ public class SearchServer implements Monitored { // Set cluster coordinates esSettings.put("cluster.name", clusterName); esSettings.put("node.rack_id", props.value(SONAR_NODE_NAME, "unknown")); - // esSettings.put("cluster.routing.allocation.awareness.attributes", "rack_id"); + esSettings.put("cluster.routing.allocation.awareness.attributes", "rack_id"); if (props.contains(SONAR_NODE_NAME)) { esSettings.put("node.name", props.value(SONAR_NODE_NAME)); } else { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java index e10e619b656..bae141797a2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java @@ -82,8 +82,8 @@ public class RuleService implements ServerComponent { * List all tags, including system tags, defined on rules */ public Set listTags() { - /** using combined _TAGS field of ES until ES update that has multiTerms aggregation */ - return index.terms(RuleNormalizer.RuleField._TAGS.field()); + /** using combined ALL_TAGS field of ES until ES update that has multiTerms aggregation */ + return index.terms(RuleNormalizer.RuleField.ALL_TAGS.field()); } public void update(RuleUpdate update) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java index 12bfa36c883..9d49c9d4f31 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java @@ -182,10 +182,10 @@ public class RuleIndex extends BaseIndex { qb.should(this.termQuery(RuleNormalizer.RuleField.LANGUAGE, queryString, 3f)); qb.should(this.termQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 5f)); qb.should(this.termQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 5f)); - qb.should(this.termQuery(RuleNormalizer.RuleField._TAGS, queryString, 10f)); + qb.should(this.termQuery(RuleNormalizer.RuleField.ALL_TAGS, queryString, 10f)); qb.should(this.termAnyQuery(RuleNormalizer.RuleField.CHARACTERISTIC, queryString, 1f)); qb.should(this.termAnyQuery(RuleNormalizer.RuleField.SUB_CHARACTERISTIC, queryString, 1f)); - qb.should(this.termAnyQuery(RuleNormalizer.RuleField._TAGS, queryString, 1f)); + qb.should(this.termAnyQuery(RuleNormalizer.RuleField.ALL_TAGS, queryString, 1f)); return qb; } @@ -232,8 +232,8 @@ public class RuleIndex extends BaseIndex { } if (!CollectionUtils.isEmpty(query.getTags())) { - filters.put(RuleNormalizer.RuleField._TAGS.field(), - FilterBuilders.termsFilter(RuleNormalizer.RuleField._TAGS.field(), query.getTags())); + filters.put(RuleNormalizer.RuleField.ALL_TAGS.field(), + FilterBuilders.termsFilter(RuleNormalizer.RuleField.ALL_TAGS.field(), query.getTags())); } // Construct the debt filter on effective char and subChar @@ -357,7 +357,7 @@ public class RuleIndex extends BaseIndex { BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query)); for (Map.Entry filter : filters.entrySet()) { - if (!StringUtils.equals(filter.getKey(), RuleNormalizer.RuleField._TAGS.field())) { + if (!StringUtils.equals(filter.getKey(), RuleNormalizer.RuleField.ALL_TAGS.field())) { tagsFacetFilter.must(filter.getValue()); } } @@ -371,7 +371,7 @@ public class RuleIndex extends BaseIndex { .filter(tagsFacetFilter) .subAggregation( AggregationBuilders.terms(FACET_TAGS) - .field(RuleNormalizer.RuleField._TAGS.field()) + .field(RuleNormalizer.RuleField.ALL_TAGS.field()) .order(Terms.Order.count(false)) .size(10) .minDocCount(1)))); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java index 35dd09ef217..e94ad6abbbd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java @@ -113,7 +113,7 @@ public class RuleNormalizer extends BaseNormalizer { public static final IndexField NOTE_LOGIN = add(IndexField.Type.STRING, "noteLogin"); public static final IndexField NOTE_CREATED_AT = add(IndexField.Type.DATE, "noteCreatedAt"); public static final IndexField NOTE_UPDATED_AT = add(IndexField.Type.DATE, "noteUpdatedAt"); - public static final IndexField _TAGS = addSearchable(IndexField.Type.STRING, "_tags"); + public static final IndexField ALL_TAGS = addSearchable(IndexField.Type.STRING, "allTags"); public static final IndexField PARAMS = addEmbedded("params", RuleParamField.ALL_FIELDS); public static final Set ALL_FIELDS = getAllFields(); @@ -193,13 +193,15 @@ public class RuleNormalizer extends BaseNormalizer { // TODO Legacy PARENT_ID in DTO should be parent_key Integer templateId = rule.getTemplateId(); + String templateKeyFieldValue = null; if (templateId != null) { RuleDto templateRule = db.ruleDao().getById(session, templateId); - RuleKey templateKey = templateRule.getKey(); - update.put(RuleField.TEMPLATE_KEY.field(), templateKey != null ? templateKey.toString() : null); - } else { - update.put(RuleField.TEMPLATE_KEY.field(), null); + if (templateRule != null) { + RuleKey templateKey = templateRule.getKey(); + templateKeyFieldValue = templateKey != null ? templateKey.toString() : null; + } } + update.put(RuleField.TEMPLATE_KEY.field(), templateKeyFieldValue); // TODO Legacy ID in DTO should be Key update.put(RuleField.CHARACTERISTIC.field(), null); @@ -270,7 +272,7 @@ public class RuleNormalizer extends BaseNormalizer { update.put(RuleField.TAGS.field(), rule.getTags()); update.put(RuleField.SYSTEM_TAGS.field(), rule.getSystemTags()); - update.put(RuleField._TAGS.field(), Sets.union(rule.getSystemTags(), rule.getTags())); + update.put(RuleField.ALL_TAGS.field(), Sets.union(rule.getSystemTags(), rule.getTags())); /** Upsert elements */ Map upsert = getUpsertFor(RuleField.ALL_FIELDS, update); diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java b/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java index 5a17f0b23a2..1a01f78e8fd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java @@ -135,22 +135,14 @@ public class IndexQueue implements ServerComponent, WorkQueue> { for (ActionRequest update : updates.get()) { if (IndexRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add(((IndexRequest) update)); - } - - else if (UpdateRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add(((UpdateRequest) update)); - } - - else if (DeleteRequest.class.isAssignableFrom(update.getClass())) { - bulkRequestBuilder.add(((DeleteRequest) update)); - } - - else if (RefreshRequest.class.isAssignableFrom(update.getClass())) { + bulkRequestBuilder.add((IndexRequest) update); + } else if (UpdateRequest.class.isAssignableFrom(update.getClass())) { + bulkRequestBuilder.add((UpdateRequest) update); + } else if (DeleteRequest.class.isAssignableFrom(update.getClass())) { + bulkRequestBuilder.add((DeleteRequest) update); + } else if (RefreshRequest.class.isAssignableFrom(update.getClass())) { hasInlineRefreshRequest = true; - } - - else { + } else { throw new IllegalStateException("Un-managed request type: " + update.getClass()); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java index afa63930617..da01dd568c4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java @@ -42,7 +42,7 @@ public class DeleteKey extends IndexAction doCall(Index index) throws Exception { + public List doCall(Index index) { List requests = new ArrayList(); requests.add(Requests.deleteRequest(index.getIndexName()) .id(getKey()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java index 99cba5ea20b..cebe2828083 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java @@ -45,7 +45,7 @@ public class DeleteNestedItem extends IndexAction doCall(Index index) throws Exception { + public List doCall(Index index) { List updates = new ArrayList(); updates.addAll(deleteItem(index, item, key)); for (Object otherItem : items) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java index 830e1b6cc8b..d7fe1040d92 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java @@ -54,14 +54,14 @@ public abstract class IndexAction implements ClusterAct } @Override - public final List call() throws Exception { + public final List call() throws IllegalStateException { if (index == null) { throw new IllegalStateException(MISSING_INDEX_EXCEPTION); } return doCall(index); } - public abstract List doCall(Index index) throws Exception; + public abstract List doCall(Index index); public boolean needsRefresh() { return this.requiresRefresh; diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java index 216874f0ef2..467272b2cb2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java @@ -42,7 +42,7 @@ public class InsertDto extends IndexAction { } @Override - public List doCall(Index index) throws Exception { + public List doCall(Index index) { List inserts = new ArrayList(); List updates = index.getNormalizer().normalize(dto); for (UpdateRequest update : updates) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java index d432250bae5..f3b0101663e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java @@ -37,7 +37,7 @@ public class RefreshIndex extends IndexAction { } @Override - public List doCall(Index index) throws Exception { + public List doCall(Index index) { return ImmutableList.of( new RefreshRequest() .force(false) diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java index eee6f6001c2..23a625ffcac 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java @@ -44,7 +44,7 @@ public class UpsertDto extends IndexAction { } @Override - public List doCall(Index index) throws Exception { + public List doCall(Index index) { List updates = index.getNormalizer().normalize(dto); for (UpdateRequest update : updates) { update.index(index.getIndexName()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java index 099d60b7d30..a1029e39136 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java @@ -45,7 +45,7 @@ public class UpsertNestedItem extends IndexAction doCall(Index index) throws Exception { + public List doCall(Index index) { List updates = new ArrayList(); updates.addAll(normalizeItem(index, item, key)); for (Object otherItem : items) { -- 2.39.5