aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-03-21 18:25:01 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-03-23 17:38:34 +0100
commitf49a935f1e586a4b71f931c13eb197d6ccdfdcff (patch)
tree5f69d702f14b59d6094e2d8ac5a572a3f1199473
parentbc30d3796db53f64829651c6df64c18a9b490565 (diff)
downloadsonarqube-f49a935f1e586a4b71f931c13eb197d6ccdfdcff.tar.gz
sonarqube-f49a935f1e586a4b71f931c13eb197d6ccdfdcff.zip
SONAR-8924 add and populate field "orgUuid" to ES index rules/activeRule
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java21
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java33
5 files changed, 40 insertions, 32 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
index 1c5760bfa4f..c50b6ee625a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
@@ -27,6 +27,7 @@ import org.sonar.server.qualityprofile.ActiveRule;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
+import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_ORGANIZATION_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
@@ -41,7 +42,7 @@ public class ActiveRuleDoc extends BaseDoc {
private final ActiveRuleKey key;
public ActiveRuleDoc(ActiveRuleKey key) {
- super(Maps.newHashMapWithExpectedSize(8));
+ super(Maps.newHashMapWithExpectedSize(9));
checkNotNull(key, "ActiveRuleKey cannot be null");
this.key = key;
setField(FIELD_ACTIVE_RULE_KEY, key.toString());
@@ -69,6 +70,15 @@ public class ActiveRuleDoc extends BaseDoc {
return key;
}
+ String organizationUuid() {
+ return getField(FIELD_ACTIVE_ORGANIZATION_UUID);
+ }
+
+ public ActiveRuleDoc setOrganizationUuid(String s) {
+ setField(FIELD_ACTIVE_ORGANIZATION_UUID, s);
+ return this;
+ }
+
String severity() {
return getNullableField(FIELD_ACTIVE_RULE_SEVERITY);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
index 0a05940133f..9bd7dc1fb3f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
@@ -63,8 +63,8 @@ public class ActiveRuleIndex extends BaseIndex {
public Map<String, Long> countAllByQualityProfileKey() {
return countByField(FIELD_ACTIVE_RULE_PROFILE_KEY,
QueryBuilders.hasParentQuery(INDEX_TYPE_RULE.getType(),
- QueryBuilders.boolQuery().mustNot(
- QueryBuilders.termQuery(FIELD_RULE_STATUS, RuleStatus.REMOVED.name()))));
+ QueryBuilders.boolQuery()
+ .mustNot(QueryBuilders.termQuery(FIELD_RULE_STATUS, RuleStatus.REMOVED.name()))));
}
public Map<String, Long> countAllDeprecatedByQualityProfileKey() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
index 2eddad484d6..ac003881fde 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
@@ -37,11 +37,11 @@ import org.sonar.server.qualityprofile.ActiveRule;
public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc> {
private static final String[] FIELDS = {
- // column 1
"a.failure_level",
"a.inheritance",
- "r.plugin_rule_key",
"r.plugin_name",
+ "r.plugin_rule_key",
+ "qp.organization_uuid",
"qp.kee",
"a.created_at",
"a.updated_at"
@@ -72,19 +72,22 @@ public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc
@Override
protected ActiveRuleDoc read(ResultSet rs) throws SQLException {
- RuleKey ruleKey = RuleKey.of(rs.getString(4), rs.getString(3));
- ActiveRuleKey activeRuleKey = ActiveRuleKey.of(rs.getString(5), ruleKey);
+ int severity = rs.getInt(1);
+ String inheritance = rs.getString(2);
+ RuleKey ruleKey = RuleKey.of(rs.getString(3), rs.getString(4));
+ String organizationUuid = rs.getString(5);
+ String profileKey = rs.getString(6);
+ ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profileKey, ruleKey);
ActiveRuleDoc doc = new ActiveRuleDoc(activeRuleKey);
-
+ doc.setOrganizationUuid(organizationUuid);
// all the fields must be present, even if value is null
- doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(1)));
+ doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(severity));
- String inheritance = rs.getString(2);
doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
- doc.setCreatedAt(rs.getLong(6));
- doc.setUpdatedAt(rs.getLong(7));
+ doc.setCreatedAt(rs.getLong(7));
+ doc.setUpdatedAt(rs.getLong(8));
return doc;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
index f9e1eb40a42..9f94a9042f8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
@@ -65,6 +65,7 @@ public class RuleIndexDefinition implements IndexDefinition {
// Active rule fields
public static final IndexType INDEX_TYPE_ACTIVE_RULE = new IndexType(INDEX, "activeRule");
+ public static final String FIELD_ACTIVE_ORGANIZATION_UUID = "organizationUuid";
public static final String FIELD_ACTIVE_RULE_KEY = "key";
public static final String FIELD_ACTIVE_RULE_REPOSITORY = "repo";
public static final String FIELD_ACTIVE_RULE_INHERITANCE = "inheritance";
@@ -92,6 +93,7 @@ public class RuleIndexDefinition implements IndexDefinition {
activeRuleMapping.setEnableSource(false);
activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", RuleIndexDefinition.INDEX_TYPE_RULE.getType()));
+ activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_ORGANIZATION_UUID).disableNorms().build();
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY).build();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
index 61b5f2dec30..abd481a0b3a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
@@ -19,10 +19,8 @@
*/
package org.sonar.server.qualityprofile.index;
-import com.google.common.base.Function;
import com.google.common.collect.Maps;
import java.util.Map;
-import javax.annotation.Nonnull;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
@@ -53,11 +51,12 @@ public class ActiveRuleResultSetIteratorTest {
ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S001"));
ActiveRuleDoc activeRule = activeRulesByKey.get(key);
+ assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
assertThat(activeRule.key()).isEqualTo(key);
assertThat(activeRule.severity()).isEqualTo(CRITICAL);
assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(1500000000000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1600000000000L);
+ assertThat(activeRule.createdAt()).isEqualTo(1_500_000_000_000L);
+ assertThat(activeRule.updatedAt()).isEqualTo(1_600_000_000_000L);
}
@Test
@@ -71,27 +70,30 @@ public class ActiveRuleResultSetIteratorTest {
ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S002"));
ActiveRuleDoc activeRule = activeRulesByKey.get(key);
+ assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
assertThat(activeRule.key()).isEqualTo(key);
assertThat(activeRule.severity()).isEqualTo(CRITICAL);
assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(2000000000000L);
- assertThat(activeRule.updatedAt()).isEqualTo(2100000000000L);
+ assertThat(activeRule.createdAt()).isEqualTo(2_000_000_000_000L);
+ assertThat(activeRule.updatedAt()).isEqualTo(2_100_000_000_000L);
key = ActiveRuleKey.of("parent", RuleKey.of("xoo", "S001"));
activeRule = activeRulesByKey.get(key);
+ assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
assertThat(activeRule.key()).isEqualTo(key);
assertThat(activeRule.severity()).isEqualTo(INFO);
assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
- assertThat(activeRule.createdAt()).isEqualTo(1700000000000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1800000000000L);
+ assertThat(activeRule.createdAt()).isEqualTo(1_700_000_000_000L);
+ assertThat(activeRule.updatedAt()).isEqualTo(1_800_000_000_000L);
key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
activeRule = activeRulesByKey.get(key);
+ assertThat(activeRule.organizationUuid()).isEqualTo("org-123");
assertThat(activeRule.key()).isEqualTo(key);
assertThat(activeRule.severity()).isEqualTo(BLOCKER);
assertThat(activeRule.inheritance()).isEqualTo(INHERITED);
- assertThat(activeRule.createdAt()).isEqualTo(1500000000000L);
- assertThat(activeRule.updatedAt()).isEqualTo(1600000000000L);
+ assertThat(activeRule.createdAt()).isEqualTo(1_500_000_000_000L);
+ assertThat(activeRule.updatedAt()).isEqualTo(1_600_000_000_000L);
}
@Test
@@ -136,16 +138,7 @@ public class ActiveRuleResultSetIteratorTest {
}
private static Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey(ActiveRuleResultSetIterator it) {
- return Maps.uniqueIndex(it, DocToKey.INSTANCE);
- }
-
- private enum DocToKey implements Function<ActiveRuleDoc, ActiveRuleKey> {
- INSTANCE;
-
- @Override
- public ActiveRuleKey apply(@Nonnull ActiveRuleDoc doc) {
- return doc.key();
- }
+ return Maps.uniqueIndex(it, ActiveRuleDoc::key);
}
}