From bf1ca1cbcd17a623ec9c53f5069ade9f792f2b3f Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Mon, 3 Jul 2017 12:15:00 +0200 Subject: SONAR-9481 Make operations on QProfiles resilient to ES errors --- .../resources/org/sonar/db/version/schema-h2.ddl | 2 + .../src/main/java/org/sonar/db/es/EsQueueDto.java | 34 ++- .../org/sonar/db/qualityprofile/ActiveRuleDao.java | 26 ++ .../sonar/db/qualityprofile/ActiveRuleMapper.java | 6 + .../db/qualityprofile/IndexedActiveRuleDto.java | 56 ++++ .../sonar/db/qualityprofile/QualityProfileDao.java | 5 + .../db/qualityprofile/QualityProfileMapper.java | 3 + .../src/main/java/org/sonar/db/rule/RuleDao.java | 24 +- .../java/org/sonar/db/rule/RuleForIndexingDto.java | 6 +- .../main/java/org/sonar/db/rule/RuleMapper.java | 8 +- .../java/org/sonar/db/rule/RuleMetadataDto.java | 4 + .../resources/org/sonar/db/es/EsQueueMapper.xml | 6 + .../sonar/db/qualityprofile/ActiveRuleMapper.xml | 27 ++ .../db/qualityprofile/QualityProfileMapper.xml | 6 + .../resources/org/sonar/db/rule/RuleMapper.xml | 76 ++++-- .../sonar/db/qualityprofile/ActiveRuleDaoTest.java | 66 +++++ .../db/qualityprofile/QualityProfileDaoTest.java | 20 +- .../test/java/org/sonar/db/rule/RuleDaoTest.java | 300 +++++++++++++-------- .../migration/version/v65/CreateEsQueueTable.java | 10 + .../version/v65/CreateEsQueueTableTest.java | 2 + .../v65/AddIndexOnEsQueueCreatedAtTest/initial.sql | 4 +- .../main/java/org/sonar/server/es/BulkIndexer.java | 79 ++---- .../java/org/sonar/server/es/IndexingListener.java | 31 +++ .../java/org/sonar/server/es/IndexingResult.java | 75 ++++++ .../java/org/sonar/server/es/RecoveryIndexer.java | 16 +- .../server/es/ResiliencyIndexingListener.java | 64 +++++ .../java/org/sonar/server/es/ResilientIndexer.java | 2 +- .../sonar/server/es/ResilientIndexerResult.java | 77 ------ .../org/sonar/server/es/queue/package-info.java | 23 -- .../platform/platformlevel/PlatformLevel4.java | 2 - .../qualityprofile/BuiltInQProfileInsertImpl.java | 8 +- .../qualityprofile/BuiltInQProfileUpdateImpl.java | 3 +- .../server/qualityprofile/QProfileFactoryImpl.java | 8 +- .../server/qualityprofile/QProfileResetImpl.java | 3 +- .../sonar/server/qualityprofile/RuleActivator.java | 26 +- .../qualityprofile/index/ActiveRuleIndexer.java | 203 +++++++++----- .../qualityprofile/index/ActiveRuleIterator.java | 27 -- .../index/ActiveRuleIteratorFactory.java | 48 ---- .../index/ActiveRuleIteratorForMultipleChunks.java | 69 ----- .../index/ActiveRuleIteratorForSingleChunk.java | 132 --------- .../qualityprofile/ws/ActivateRuleAction.java | 11 +- .../qualityprofile/ws/ActivateRulesAction.java | 2 +- .../qualityprofile/ws/ChangeParentAction.java | 4 +- .../server/qualityprofile/ws/CreateAction.java | 3 +- .../qualityprofile/ws/DeactivateRuleAction.java | 2 +- .../qualityprofile/ws/DeactivateRulesAction.java | 2 +- .../java/org/sonar/server/rule/RegisterRules.java | 2 +- .../java/org/sonar/server/rule/index/RuleDoc.java | 40 +-- .../server/rule/index/RuleDocWithSystemScope.java | 40 --- .../org/sonar/server/rule/index/RuleIndexer.java | 125 ++++----- .../org/sonar/server/rule/index/RuleIterator.java | 29 -- .../rule/index/RuleIteratorForMultipleChunks.java | 80 ------ .../rule/index/RuleIteratorForSingleChunk.java | 211 --------------- .../server/rule/index/RuleMetadataIterator.java | 126 --------- .../org/sonar/server/user/index/UserIndexer.java | 19 +- .../server/user/index/UserResultSetIterator.java | 121 --------- .../java/org/sonar/server/es/BulkIndexerTest.java | 7 +- .../test/java/org/sonar/server/es/EsTester.java | 8 +- .../org/sonar/server/es/IndexingResultTest.java | 78 ++++++ .../org/sonar/server/es/RecoveryIndexerTest.java | 39 ++- .../server/es/ResilientIndexerResultTest.java | 62 ----- .../sonar/server/issue/index/IssueIndexTest.java | 2 +- .../organization/ws/EnableSupportActionTest.java | 13 +- .../qualityprofile/QProfileFactoryImplTest.java | 19 +- .../server/qualityprofile/RuleActivatorTest.java | 34 ++- .../index/ActiveRuleIndexerTest.java | 138 ++++++---- .../qualityprofile/ws/ActivateRuleActionTest.java | 8 +- .../qualityprofile/ws/ChangeParentActionTest.java | 9 +- .../server/qualityprofile/ws/CreateActionTest.java | 3 +- .../ws/DeactivateRuleActionTest.java | 4 +- .../qualityprofile/ws/InheritanceActionTest.java | 5 +- .../server/qualityprofile/ws/ShowActionTest.java | 3 +- .../org/sonar/server/rule/RegisterRulesTest.java | 3 +- .../org/sonar/server/rule/index/RuleIndexTest.java | 3 +- .../rule/index/RuleIteratorForSingleChunkTest.java | 201 -------------- .../org/sonar/server/rule/ws/DeleteActionTest.java | 4 +- .../org/sonar/server/rule/ws/SearchActionTest.java | 3 +- .../org/sonar/server/rule/ws/ShowActionTest.java | 5 +- 78 files changed, 1246 insertions(+), 1809 deletions(-) create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/es/IndexingListener.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/es/IndexingResult.java 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/ResilientIndexerResult.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/RuleDocWithSystemScope.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIterator.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 (limited to 'server') 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-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java new file mode 100644 index 00000000000..b34d33ffeb0 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/IndexedActiveRuleDto.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * 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; + +import javax.annotation.CheckForNull; + +public class IndexedActiveRuleDto { + private long id; + private int severity; + private String inheritance; + private String repository; + private String key; + private String ruleProfileUuid; + + public long getId() { + return id; + } + + public int getSeverity() { + return severity; + } + + @CheckForNull + public String getInheritance() { + return inheritance; + } + + public String getRepository() { + return repository; + } + + public String getKey() { + return key; + } + + 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}) - - +