aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main
diff options
context:
space:
mode:
authorJacek Poreda <jacek.poreda@sonarsource.com>2023-11-17 15:18:49 +0100
committersonartech <sonartech@sonarsource.com>2023-11-28 20:02:42 +0000
commit87614500bffae2fc84f619b07808f56eeae58c9d (patch)
tree12a3e9b515f64fbf5e58255acb830c96c0208e87 /sonar-scanner-engine/src/main
parent982713f8d4749a7c9fa867e772e532069da2b186 (diff)
downloadsonarqube-87614500bffae2fc84f619b07808f56eeae58c9d.tar.gz
sonarqube-87614500bffae2fc84f619b07808f56eeae58c9d.zip
SONAR-21042 - Remove ES Rule index usage in Recently Added Rules and Scanner Engine
Diffstat (limited to 'sonar-scanner-engine/src/main')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java27
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesLoader.java4
2 files changed, 14 insertions, 17 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
index 1de4988f3b3..1155ba75d03 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
@@ -31,19 +31,18 @@ import org.sonar.api.batch.rule.LoadedActiveRule;
import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.DateUtils;
-import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.ScannerWsClient;
+import org.sonarqube.ws.Common.Paging;
import org.sonarqube.ws.Rules;
import org.sonarqube.ws.Rules.Active;
import org.sonarqube.ws.Rules.Active.Param;
import org.sonarqube.ws.Rules.ActiveList;
+import org.sonarqube.ws.Rules.ListResponse;
import org.sonarqube.ws.Rules.Rule;
-import org.sonarqube.ws.Rules.SearchResponse;
import org.sonarqube.ws.client.GetRequest;
public class DefaultActiveRulesLoader implements ActiveRulesLoader {
- private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?" +
- "f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt,deprecatedKeys&activation=true";
+ private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf?";
private final ScannerWsClient wsClient;
@@ -60,12 +59,14 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
while (true) {
GetRequest getRequest = new GetRequest(getUrl(qualityProfileKey, page, pageSize));
- SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
+ ListResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
List<LoadedActiveRule> pageRules = readPage(response);
ruleList.addAll(pageRules);
- loaded += response.getPs();
- if (response.getTotal() <= loaded) {
+ Paging paging = response.getPaging();
+ loaded += paging.getPageSize();
+
+ if (paging.getTotal() <= loaded) {
break;
}
page++;
@@ -77,15 +78,15 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
private static String getUrl(String qualityProfileKey, int page, int pageSize) {
StringBuilder builder = new StringBuilder(1024);
builder.append(RULES_SEARCH_URL);
- builder.append("&qprofile=").append(ScannerUtils.encodeForUrl(qualityProfileKey));
+ builder.append("qprofile=").append(ScannerUtils.encodeForUrl(qualityProfileKey));
builder.append("&ps=").append(pageSize);
builder.append("&p=").append(page);
return builder.toString();
}
- private static SearchResponse loadFromStream(InputStream is) {
+ private static ListResponse loadFromStream(InputStream is) {
try {
- return SearchResponse.parseFrom(is);
+ return ListResponse.parseFrom(is);
} catch (IOException e) {
throw new IllegalStateException("Failed to load quality profiles", e);
} finally {
@@ -93,7 +94,7 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
}
}
- private static List<LoadedActiveRule> readPage(SearchResponse response) {
+ private static List<LoadedActiveRule> readPage(ListResponse response) {
List<LoadedActiveRule> loadedRules = new LinkedList<>();
List<Rule> rulesList = response.getRulesList();
@@ -101,10 +102,6 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
for (Rule r : rulesList) {
ActiveList activeList = actives.get(r.getKey());
- if (activeList == null) {
- throw MessageException.of("Elasticsearch indices have become inconsistent. Consider re-indexing. " +
- "Check documentation for more information https://docs.sonarsource.com/sonarqube/latest/setup/troubleshooting");
- }
Active active = activeList.getActiveList(0);
LoadedActiveRule loadedRule = new LoadedActiveRule();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesLoader.java
index 953e51c894e..61c1c7393fa 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesLoader.java
@@ -20,8 +20,8 @@
package org.sonar.scanner.rule;
import java.util.List;
-import org.sonarqube.ws.Rules.ListResponse.Rule;
+import org.sonarqube.ws.Rules;
public interface RulesLoader {
- List<Rule> load();
+ List<Rules.Rule> load();
}