From bf1ca1cbcd17a623ec9c53f5069ade9f792f2b3f Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Mon, 3 Jul 2017 12:15:00 +0200 Subject: [PATCH] SONAR-9481 Make operations on QProfiles resilient to ES errors --- .../org/sonar/db/version/schema-h2.ddl | 2 + .../main/java/org/sonar/db/es/EsQueueDto.java | 34 +- .../db/qualityprofile/ActiveRuleDao.java | 26 ++ .../db/qualityprofile/ActiveRuleMapper.java | 6 + .../qualityprofile/IndexedActiveRuleDto.java} | 38 ++- .../db/qualityprofile/QualityProfileDao.java | 5 + .../qualityprofile/QualityProfileMapper.java | 3 + .../main/java/org/sonar/db/rule/RuleDao.java | 24 +- .../org/sonar/db/rule/RuleForIndexingDto.java | 6 +- .../java/org/sonar/db/rule/RuleMapper.java | 8 +- .../org/sonar/db/rule/RuleMetadataDto.java | 4 + .../org/sonar/db/es/EsQueueMapper.xml | 6 + .../db/qualityprofile/ActiveRuleMapper.xml | 27 ++ .../qualityprofile/QualityProfileMapper.xml | 6 + .../org/sonar/db/rule/RuleMapper.xml | 76 +++-- .../db/qualityprofile/ActiveRuleDaoTest.java | 66 ++++ .../qualityprofile/QualityProfileDaoTest.java | 20 +- .../java/org/sonar/db/rule/RuleDaoTest.java | 300 ++++++++++++------ .../version/v65/CreateEsQueueTable.java | 10 + .../version/v65/CreateEsQueueTableTest.java | 2 + .../initial.sql | 4 +- .../java/org/sonar/server/es/BulkIndexer.java | 79 ++--- .../IndexingListener.java} | 12 +- ...IndexerResult.java => IndexingResult.java} | 52 ++- .../org/sonar/server/es/RecoveryIndexer.java | 16 +- .../server/es/ResiliencyIndexingListener.java | 64 ++++ .../org/sonar/server/es/ResilientIndexer.java | 2 +- .../sonar/server/es/queue/package-info.java | 23 -- .../platformlevel/PlatformLevel4.java | 2 - .../BuiltInQProfileInsertImpl.java | 8 +- .../BuiltInQProfileUpdateImpl.java | 3 +- .../qualityprofile/QProfileFactoryImpl.java | 8 +- .../qualityprofile/QProfileResetImpl.java | 3 +- .../server/qualityprofile/RuleActivator.java | 26 +- .../index/ActiveRuleIndexer.java | 203 ++++++++---- .../index/ActiveRuleIterator.java | 27 -- .../index/ActiveRuleIteratorFactory.java | 48 --- .../ActiveRuleIteratorForMultipleChunks.java | 69 ---- .../ActiveRuleIteratorForSingleChunk.java | 132 -------- .../qualityprofile/ws/ActivateRuleAction.java | 11 +- .../ws/ActivateRulesAction.java | 2 +- .../qualityprofile/ws/ChangeParentAction.java | 4 +- .../qualityprofile/ws/CreateAction.java | 3 +- .../ws/DeactivateRuleAction.java | 2 +- .../ws/DeactivateRulesAction.java | 2 +- .../org/sonar/server/rule/RegisterRules.java | 2 +- .../org/sonar/server/rule/index/RuleDoc.java | 40 +-- .../sonar/server/rule/index/RuleIndexer.java | 125 +++----- .../index/RuleIteratorForMultipleChunks.java | 80 ----- .../index/RuleIteratorForSingleChunk.java | 211 ------------ .../rule/index/RuleMetadataIterator.java | 126 -------- .../sonar/server/user/index/UserIndexer.java | 19 +- .../user/index/UserResultSetIterator.java | 121 ------- .../org/sonar/server/es/BulkIndexerTest.java | 7 +- .../java/org/sonar/server/es/EsTester.java | 8 +- .../sonar/server/es/IndexingResultTest.java | 78 +++++ .../sonar/server/es/RecoveryIndexerTest.java | 39 ++- .../server/es/ResilientIndexerResultTest.java | 62 ---- .../server/issue/index/IssueIndexTest.java | 2 +- .../ws/EnableSupportActionTest.java | 13 +- .../QProfileFactoryImplTest.java | 19 +- .../qualityprofile/RuleActivatorTest.java | 34 +- .../index/ActiveRuleIndexerTest.java | 138 ++++---- .../ws/ActivateRuleActionTest.java | 8 +- .../ws/ChangeParentActionTest.java | 9 +- .../qualityprofile/ws/CreateActionTest.java | 3 +- .../ws/DeactivateRuleActionTest.java | 4 +- .../ws/InheritanceActionTest.java | 5 +- .../qualityprofile/ws/ShowActionTest.java | 3 +- .../sonar/server/rule/RegisterRulesTest.java | 3 +- .../server/rule/index/RuleIndexTest.java | 3 +- .../index/RuleIteratorForSingleChunkTest.java | 201 ------------ .../server/rule/ws/DeleteActionTest.java | 4 +- .../server/rule/ws/SearchActionTest.java | 3 +- .../sonar/server/rule/ws/ShowActionTest.java | 5 +- tests/resilience/active_rule_indexer.btm | 12 + .../org/sonarqube/tests/Category5Suite.java | 2 + .../ActiveRuleEsResilienceTest.java | 107 +++++++ 78 files changed, 1264 insertions(+), 1706 deletions(-) rename server/{sonar-server/src/main/java/org/sonar/server/rule/index/RuleDocWithSystemScope.java => sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java} (58%) rename server/sonar-server/src/main/java/org/sonar/server/{rule/index/RuleIterator.java => es/IndexingListener.java} (80%) rename server/sonar-server/src/main/java/org/sonar/server/es/{ResilientIndexerResult.java => IndexingResult.java} (61%) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/es/ResiliencyIndexingListener.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/es/queue/package-info.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIterator.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIteratorFactory.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIteratorForMultipleChunks.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIteratorForSingleChunk.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIteratorForMultipleChunks.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIteratorForSingleChunk.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleMetadataIterator.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/es/IndexingResultTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/es/ResilientIndexerResultTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIteratorForSingleChunkTest.java create mode 100644 tests/resilience/active_rule_indexer.btm create mode 100644 tests/src/test/java/org/sonarqube/tests/qualityProfile/ActiveRuleEsResilienceTest.java diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index 3942cb98f86..81c8fe51945 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -663,6 +663,8 @@ CREATE TABLE "ES_QUEUE" ( "UUID" VARCHAR(40) NOT NULL PRIMARY KEY, "DOC_TYPE" VARCHAR(40) NOT NULL, "DOC_ID" VARCHAR(4000) NOT NULL, + "DOC_ID_TYPE" VARCHAR(20), + "DOC_ROUTING" VARCHAR(4000), "CREATED_AT" BIGINT NOT NULL ); CREATE UNIQUE INDEX "PK_ES_QUEUE" ON "ES_QUEUE" ("UUID"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/es/EsQueueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/es/EsQueueDto.java index 35c51c7f2e5..26f310d34ca 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/es/EsQueueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/es/EsQueueDto.java @@ -19,15 +19,20 @@ */ package org.sonar.db.es; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + public final class EsQueueDto { public enum Type { - USER, RULE, RULE_EXTENSION + USER, RULE, RULE_EXTENSION, ACTIVE_RULE } private String uuid; private Type docType; private String docId; + private String docIdType; + private String docRouting; public String getUuid() { return uuid; @@ -56,12 +61,34 @@ public final class EsQueueDto { return this; } + @CheckForNull + public String getDocIdType() { + return docIdType; + } + + private EsQueueDto setDocIdType(@Nullable String s) { + this.docIdType = s; + return this; + } + + @CheckForNull + public String getDocRouting() { + return docRouting; + } + + private EsQueueDto setDocRouting(@Nullable String s) { + this.docRouting = s; + return this; + } + @Override public String toString() { StringBuilder sb = new StringBuilder("EsQueueDto{"); sb.append("uuid='").append(uuid).append('\''); sb.append(", docType=").append(docType); sb.append(", docId='").append(docId).append('\''); + sb.append(", docIdType='").append(docIdType).append('\''); + sb.append(", docRouting='").append(docRouting).append('\''); sb.append('}'); return sb.toString(); } @@ -88,4 +115,9 @@ public final class EsQueueDto { public static EsQueueDto create(Type docType, String docUuid) { return new EsQueueDto().setDocType(docType).setDocId(docUuid); } + + public static EsQueueDto create(Type docType, String docId, @Nullable String docIdType, @Nullable String docRouting) { + return new EsQueueDto().setDocType(docType) + .setDocId(docId).setDocIdType(docIdType).setDocRouting(docRouting); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index a699eab7870..b19f4ee848f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Consumer; import org.sonar.db.Dao; import org.sonar.db.DatabaseUtils; import org.sonar.db.DbSession; @@ -31,6 +32,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleParamDto; import static org.sonar.db.DatabaseUtils.executeLargeInputs; +import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput; import static org.sonar.db.KeyLongValue.toMap; public class ActiveRuleDao implements Dao { @@ -170,6 +172,30 @@ public class ActiveRuleDao implements Dao { partition -> mapper(dbSession).countActiveRulesByQuery(query.getOrganization().getUuid(), partition, query.getRuleStatus(), query.getInheritance()))); } + public void scrollAllForIndexing(DbSession dbSession, Consumer consumer) { + mapper(dbSession).scrollAllForIndexing(context -> { + IndexedActiveRuleDto dto = (IndexedActiveRuleDto) context.getResultObject(); + consumer.accept(dto); + }); + } + + public void scrollByIdsForIndexing(DbSession dbSession, Collection ids, Consumer consumer) { + ActiveRuleMapper mapper = mapper(dbSession); + executeLargeInputsWithoutOutput(ids, + pageOfIds -> mapper + .scrollByIdsForIndexing(pageOfIds, context -> { + IndexedActiveRuleDto dto = (IndexedActiveRuleDto) context.getResultObject(); + consumer.accept(dto); + })); + } + + public void scrollByRuleProfileForIndexing(DbSession dbSession, String ruleProfileUuid, Consumer consumer) { + mapper(dbSession).scrollByRuleProfileUuidForIndexing(ruleProfileUuid, context -> { + IndexedActiveRuleDto dto = (IndexedActiveRuleDto) context.getResultObject(); + consumer.accept(dto); + }); + } + private static ActiveRuleMapper mapper(DbSession dbSession) { return dbSession.getMapper(ActiveRuleMapper.class); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java index 6a64c21ee4e..2821d3ae0c8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleMapper.java @@ -24,6 +24,7 @@ import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.session.ResultHandler; import org.sonar.api.rule.RuleStatus; import org.sonar.db.KeyLongValue; @@ -73,4 +74,9 @@ public interface ActiveRuleMapper { List countActiveRulesByQuery(@Param("organizationUuid") String organizationUuid, @Param("profileUuids") List profileUuids, @Nullable @Param("ruleStatus") RuleStatus ruleStatus, @Param("inheritance") String inheritance); + void scrollAllForIndexing(ResultHandler handler); + + void scrollByIdsForIndexing(@Param("ids") Collection ids, ResultHandler handler); + + void scrollByRuleProfileUuidForIndexing(@Param("ruleProfileUuid") String ruleProfileUuid, ResultHandler handler); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDocWithSystemScope.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java similarity index 58% rename from server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDocWithSystemScope.java rename to server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java index 1e581a9ff21..b34d33ffeb0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDocWithSystemScope.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java @@ -17,24 +17,40 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +package org.sonar.db.qualityprofile; -package org.sonar.server.rule.index; +import javax.annotation.CheckForNull; -public class RuleDocWithSystemScope { +public class IndexedActiveRuleDto { + private long id; + private int severity; + private String inheritance; + private String repository; + private String key; + private String ruleProfileUuid; - private final RuleDoc ruleDoc; - private final RuleExtensionDoc ruleExtensionDoc; + public long getId() { + return id; + } + + public int getSeverity() { + return severity; + } + + @CheckForNull + public String getInheritance() { + return inheritance; + } - public RuleDocWithSystemScope(RuleDoc ruleDoc, RuleExtensionDoc ruleExtensionDoc) { - this.ruleDoc = ruleDoc; - this.ruleExtensionDoc = ruleExtensionDoc; + public String getRepository() { + return repository; } - public RuleDoc getRuleDoc() { - return ruleDoc; + public String getKey() { + return key; } - public RuleExtensionDoc getRuleExtensionDoc() { - return ruleExtensionDoc; + public String getRuleProfileUuid() { + return ruleProfileUuid; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index 600be7ac278..ee81f42b8d1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -74,6 +74,11 @@ public class QualityProfileDao implements Dao { return mapper(dbSession).selectBuiltInRuleProfiles(); } + @CheckForNull + public RulesProfileDto selectRuleProfile(DbSession dbSession, String ruleProfileUuid) { + return mapper(dbSession).selectRuleProfile(ruleProfileUuid); + } + public void insert(DbSession dbSession, RulesProfileDto dto) { QualityProfileMapper mapper = mapper(dbSession); mapper.insertRuleProfile(dto, new Date(system.now())); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java index 04def0160fd..4f9e9c9df56 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java @@ -42,6 +42,9 @@ public interface QualityProfileMapper { List selectBuiltInRuleProfiles(); + @CheckForNull + RulesProfileDto selectRuleProfile(@Param("uuid") String ruleProfileUuid); + List selectOrderedByOrganizationUuid(@Param("organizationUuid") String organizationUuid); @CheckForNull diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index 94e47de330f..1af37e8cfd2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -25,12 +25,12 @@ import java.util.Optional; import java.util.function.Consumer; import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; -import org.sonar.db.es.RuleExtensionId; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleQuery; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; +import org.sonar.db.es.RuleExtensionId; import org.sonar.db.organization.OrganizationDto; import static com.google.common.base.Preconditions.checkNotNull; @@ -152,24 +152,38 @@ public class RuleDao implements Dao { } } - public void scrollRuleExtensionByRuleKeys(DbSession dbSession, Collection ruleExtensionIds, Consumer consumer) { + public void scrollIndexingRuleExtensionsByIds(DbSession dbSession, Collection ruleExtensionIds, Consumer consumer) { RuleMapper mapper = mapper(dbSession); executeLargeInputsWithoutOutput(ruleExtensionIds, pageOfRuleExtensionIds -> mapper - .selectRuleExtensionForIndexingByKeys(pageOfRuleExtensionIds) + .selectIndexingRuleExtensionsByIds(pageOfRuleExtensionIds) .forEach(consumer)); } - public void scrollRuleByRuleKeys(DbSession dbSession, Collection ruleKeys, Consumer consumer) { + public void scrollIndexingRuleExtensions(DbSession dbSession, Consumer consumer) { + mapper(dbSession).scrollIndexingRuleExtensions(context -> { + RuleExtensionForIndexingDto dto = (RuleExtensionForIndexingDto) context.getResultObject(); + consumer.accept(dto); + }); + } + + public void scrollIndexingRulesByKeys(DbSession dbSession, Collection ruleKeys, Consumer consumer) { RuleMapper mapper = mapper(dbSession); executeLargeInputsWithoutOutput(ruleKeys, pageOfRuleKeys -> mapper - .selectRuleForIndexingByKeys(pageOfRuleKeys) + .selectIndexingRulesByKeys(pageOfRuleKeys) .forEach(consumer)); } + public void scrollIndexingRules(DbSession dbSession, Consumer consumer) { + mapper(dbSession).scrollIndexingRules(context -> { + RuleForIndexingDto dto = (RuleForIndexingDto) context.getResultObject(); + consumer.accept(dto); + }); + } + private static RuleMapper mapper(DbSession session) { return session.getMapper(RuleMapper.class); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java index 52459e6338e..d255d5c2c38 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java @@ -40,7 +40,7 @@ public class RuleForIndexingDto { private boolean isTemplate; private String systemTags; private String templateRuleKey; - private String templateName; + private String templateRepository; private String internalKey; private String language; private int type; @@ -93,8 +93,8 @@ public class RuleForIndexingDto { return templateRuleKey; } - public String getTemplateName() { - return templateName; + public String getTemplateRepository() { + return templateRepository; } public String getInternalKey() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java index d5a98e60200..350bd23b3e3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java @@ -52,9 +52,13 @@ public interface RuleMapper { List selectDefinitionByKeys(@Param("ruleKeys") List keys); - List selectRuleForIndexingByKeys(@Param("ruleKeys") List keys); + void scrollIndexingRules(ResultHandler handler); - List selectRuleExtensionForIndexingByKeys(@Param("ruleExtensionIds") List ruleExtensionIds); + List selectIndexingRulesByKeys(@Param("ruleKeys") List keys); + + void scrollIndexingRuleExtensions(ResultHandler handler); + + List selectIndexingRuleExtensionsByIds(@Param("ruleExtensionIds") List ruleExtensionIds); List selectByQuery(@Param("organizationUuid") String organizationUuid, @Param("query") RuleQuery ruleQuery); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java index 594611079fc..17f27c40d8f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMetadataDto.java @@ -135,6 +135,10 @@ public class RuleMetadataDto { return tags == null ? new HashSet<>() : new TreeSet<>(Arrays.asList(StringUtils.split(tags, ','))); } + String getTagsAsString() { + return tags; + } + public RuleMetadataDto setTags(Set tags) { String raw = tags.isEmpty() ? null : StringUtils.join(tags, ','); checkArgument(raw == null || raw.length() <= 4000, "Rule tags are too long: %s", raw); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/es/EsQueueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/es/EsQueueMapper.xml index 62ec6e3421b..e1be847595c 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/es/EsQueueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/es/EsQueueMapper.xml @@ -7,6 +7,8 @@ uuid, doc_type as docType, doc_id as docId, + doc_id_type as docIdType, + doc_routing as docRouting, created_at as createdAt @@ -15,11 +17,15 @@ uuid, doc_type, doc_id, + doc_id_type, + doc_routing, created_at ) values ( #{dto.uuid, jdbcType=VARCHAR}, #{dto.docType, jdbcType=VARCHAR}, #{dto.docId, jdbcType=VARCHAR}, + #{dto.docIdType, jdbcType=VARCHAR}, + #{dto.docRouting, jdbcType=VARCHAR}, #{now, jdbcType=BIGINT} ) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml index 29ac1dc7481..5965b14ebde 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml @@ -272,5 +272,32 @@ group by oqp.uuid + + + + + + + + select + ar.id as "id", + ar.failure_level as "severity", + ar.inheritance as "inheritance", + r.plugin_name as "repository", + r.plugin_rule_key as "key", + rp.kee as "ruleProfileUuid" + from active_rules ar + inner join rules_profiles rp on rp.id = ar.profile_id + inner join rules r on r.id = ar.rule_id + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index 3f85132f1d4..4d75daa1067 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -109,6 +109,12 @@ where rp.is_built_in = ${_true} + + - + + and - ( r.plugin_name=#{ruleExtId.repositoryName,jdbcType=VARCHAR} and - r.plugin_rule_key=#{ruleExtId.ruleKey,jdbcType=VARCHAR} and - rm.organization_uuid=#{ruleExtId.organizationUuid,jdbcType=VARCHAR} ) + ( r.plugin_name = #{ruleExtId.repositoryName, jdbcType=VARCHAR} and + r.plugin_rule_key = #{ruleExtId.ruleKey, jdbcType=VARCHAR} and + rm.organization_uuid = #{ruleExtId.organizationUuid, jdbcType=VARCHAR} ) + + + + select + r.plugin_name as "pluginName", + r.plugin_rule_key as "pluginRuleKey", + rm.organization_uuid as "organizationUuid", + rm.tags as "tags" + from rules r + inner join rules_metadata rm on rm.rule_id = r.id + where + rm.tags is not null and + rm.tags != '' + + + + select + r.plugin_name as "pluginName", + r.plugin_rule_key as "pluginRuleKey", + rm.organization_uuid as "organizationUuid", + rm.tags as "tags" + from rules r + inner join rules_metadata rm on rm.rule_id = r.id + where + rm.tags is not null + + - + + where + + (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}) + + + + + + select r.id as "id", r.plugin_name as "repository", @@ -218,20 +249,15 @@ r.is_template as "isTemplate", r.system_tags as "systemTags", t.plugin_rule_key as "templateRuleKey", - t.plugin_name as "templateName", + t.plugin_name as "templateRepository", r.plugin_config_key as "internalKey", r.language as "language", r.rule_type as "type", r.created_at as "createdAt", r.updated_at as "updatedAt" - from - rules r + from rules r left outer join rules t on t.id = r.template_id - where - - (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}) - - +