]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaws
authorStephane Gamard <stephane.gamard@sonarsource.com>
Wed, 8 Oct 2014 14:57:41 +0000 (16:57 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Wed, 8 Oct 2014 15:22:30 +0000 (17:22 +0200)
12 files changed:
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteKey.java
server/sonar-server/src/main/java/org/sonar/server/search/action/DeleteNestedItem.java
server/sonar-server/src/main/java/org/sonar/server/search/action/IndexAction.java
server/sonar-server/src/main/java/org/sonar/server/search/action/InsertDto.java
server/sonar-server/src/main/java/org/sonar/server/search/action/RefreshIndex.java
server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertDto.java
server/sonar-server/src/main/java/org/sonar/server/search/action/UpsertNestedItem.java

index 9a32277c96fb2b7880de457d368e45c811ad52be..64a23f35ce7d48880459f826dd650fc23572ddfa 100644 (file)
@@ -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 {
index e10e619b656114b95f2848ad95ba28b7d4463871..bae141797a22ea28696b093b7965b5c8408f8740 100644 (file)
@@ -82,8 +82,8 @@ public class RuleService implements ServerComponent {
    * List all tags, including system tags, defined on rules
    */
   public Set<String> 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) {
index 12bfa36c88316493e33d7b47a4cc0702816efac8..9d49c9d4f315e706e6e147153a368aeea107c7ad 100644 (file)
@@ -182,10 +182,10 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
     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<Rule, RuleDto, RuleKey> {
     }
 
     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<Rule, RuleDto, RuleKey> {
 
     BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
     for (Map.Entry<String, FilterBuilder> 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<Rule, RuleDto, RuleKey> {
             .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))));
index 35dd09ef217229b87037d1306f396bb42809ef95..e94ad6abbbdbb01aa3232ad8134939dbfe957da8 100644 (file)
@@ -113,7 +113,7 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
     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<IndexField> ALL_FIELDS = getAllFields();
@@ -193,13 +193,15 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> {
 
       // 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<RuleDto, RuleKey> {
 
       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<String, Object> upsert = getUpsertFor(RuleField.ALL_FIELDS, update);
index 5a17f0b23a2aeced6f9a47086b567829754dc68d..1a01f78e8fd71a4483c8b1d78ce311bdf1335eca 100644 (file)
@@ -135,22 +135,14 @@ public class IndexQueue implements ServerComponent, WorkQueue<IndexAction<?>> {
         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());
           }
         }
index afa639306171579075afb1922193e93af5d05a8b..da01dd568c4c7d8fc7dce3724413f40f4855bcbf 100644 (file)
@@ -42,7 +42,7 @@ public class DeleteKey<K extends Serializable> extends IndexAction<DeleteRequest
   }
 
   @Override
-  public List<DeleteRequest> doCall(Index index) throws Exception {
+  public List<DeleteRequest> doCall(Index index) {
     List<DeleteRequest> requests = new ArrayList<DeleteRequest>();
     requests.add(Requests.deleteRequest(index.getIndexName())
       .id(getKey())
index 99cba5ea20b6d0734f08e5a88fcc1bf878dbdfba..cebe2828083cb8a03b48b5e1f72fdaba8aa6bcc9 100644 (file)
@@ -45,7 +45,7 @@ public class DeleteNestedItem<K extends Serializable> extends IndexAction<Update
   }
 
   @Override
-  public List<UpdateRequest> doCall(Index index) throws Exception {
+  public List<UpdateRequest> doCall(Index index) {
     List<UpdateRequest> updates = new ArrayList<UpdateRequest>();
     updates.addAll(deleteItem(index, item, key));
     for (Object otherItem : items) {
index 830e1b6cc8b330424a25782386bffe9db82fa7f9..d7fe1040d92ad66ec7087f6398e42adf0448399d 100644 (file)
@@ -54,14 +54,14 @@ public abstract class IndexAction<K extends ActionRequest> implements ClusterAct
   }
 
   @Override
-  public final List<K> call() throws Exception {
+  public final List<K> call() throws IllegalStateException {
     if (index == null) {
       throw new IllegalStateException(MISSING_INDEX_EXCEPTION);
     }
     return doCall(index);
   }
 
-  public abstract List<K> doCall(Index index) throws Exception;
+  public abstract List<K> doCall(Index index);
 
   public boolean needsRefresh() {
     return this.requiresRefresh;
index 216874f0ef2f79fe68d074a18493372ceffb9ac7..467272b2cb25821b68eb21cb18d1bca564097108 100644 (file)
@@ -42,7 +42,7 @@ public class InsertDto<DTO extends Dto> extends IndexAction<ActionRequest> {
   }
 
   @Override
-  public List<ActionRequest> doCall(Index index) throws Exception {
+  public List<ActionRequest> doCall(Index index) {
     List<ActionRequest> inserts = new ArrayList<ActionRequest>();
     List<UpdateRequest> updates = index.getNormalizer().normalize(dto);
     for (UpdateRequest update : updates) {
index d432250bae5e896aed78b74150c36a54e6a141ed..f3b0101663ea70710857fdc2c579ed522539fe68 100644 (file)
@@ -37,7 +37,7 @@ public class RefreshIndex extends IndexAction<RefreshRequest> {
   }
 
   @Override
-  public List<RefreshRequest> doCall(Index index) throws Exception {
+  public List<RefreshRequest> doCall(Index index) {
     return ImmutableList.of(
       new RefreshRequest()
         .force(false)
index eee6f6001c2e2ab95c9b00310ccc79963326b180..23a625ffcacfc11918cef5cf640754d5f93f3a61 100644 (file)
@@ -44,7 +44,7 @@ public class UpsertDto<DTO extends Dto> extends IndexAction<UpdateRequest> {
   }
 
   @Override
-  public List<UpdateRequest> doCall(Index index) throws Exception {
+  public List<UpdateRequest> doCall(Index index) {
     List<UpdateRequest> updates = index.getNormalizer().normalize(dto);
     for (UpdateRequest update : updates) {
       update.index(index.getIndexName())
index 099d60b7d30dbdf01facb3111575d7a09cb9ca49..a1029e3913652a438651c4f198f116f20c8ab844 100644 (file)
@@ -45,7 +45,7 @@ public class UpsertNestedItem<K extends Serializable> extends IndexAction<Update
   }
 
   @Override
-  public List<UpdateRequest> doCall(Index index) throws Exception {
+  public List<UpdateRequest> doCall(Index index) {
     List<UpdateRequest> updates = new ArrayList<UpdateRequest>();
     updates.addAll(normalizeItem(index, item, key));
     for (Object otherItem : items) {