aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-03-17 17:16:26 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-03-23 17:54:56 +0100
commit408295ca5c76d8c497daff2d57cfff3515759442 (patch)
tree9690779e78a725f48240a2bbd0094ab7e3d3d4bd
parent1cd640b1a817add0aedcf1e4ecc68ab2c7acffab (diff)
downloadsonarqube-408295ca5c76d8c497daff2d57cfff3515759442.tar.gz
sonarqube-408295ca5c76d8c497daff2d57cfff3515759442.zip
SONAR-6547 remove now useless ClearRulesOverloadedDebt
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java116
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java168
3 files changed, 0 insertions, 286 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
index ae4211f0733..8de7a204477 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
@@ -30,7 +30,6 @@ import org.sonar.server.qualityprofile.CachingRuleActivatorContextFactory;
import org.sonar.server.qualityprofile.DefinedQProfileLoader;
import org.sonar.server.qualityprofile.RegisterQualityProfiles;
import org.sonar.server.rule.RegisterRules;
-import org.sonar.server.startup.ClearRulesOverloadedDebt;
import org.sonar.server.startup.DeleteOldAnalysisReportsFromFs;
import org.sonar.server.startup.DisplayLogOnDeprecatedProjects;
import org.sonar.server.startup.GeneratePluginIndex;
@@ -64,7 +63,6 @@ public class PlatformLevelStartup extends PlatformLevel {
RegisterPermissionTemplates.class,
RenameDeprecatedPropertyKeys.class,
DisplayLogOnDeprecatedProjects.class,
- ClearRulesOverloadedDebt.class,
DeleteOldAnalysisReportsFromFs.class);
// RegisterServletFilters makes the WebService engine of Level4 served by the MasterServletFilter, therefor it
diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java b/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java
deleted file mode 100644
index 419fc30282b..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.server.startup;
-
-import org.picocontainer.Startable;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.server.rule.index.RuleIndexer;
-
-import static org.sonar.db.loadedtemplate.LoadedTemplateDto.ONE_SHOT_TASK_TYPE;
-
-/**
- * Clear the overloaded technical debt of rules when SQALE plugin is not installed.
- * See <a href="https://jira.sonarsource.com/browse/SONAR-6547">SONAR-6547</a>.
- *
- * Should be removed after LTS 5.X
- *
- * @since 5.2
- */
-public class ClearRulesOverloadedDebt implements Startable {
-
- private static final Logger LOG = Loggers.get(ClearRulesOverloadedDebt.class);
-
- private static final String TEMPLATE_KEY = "ClearRulesOverloadedDebt";
-
- private static final String SQALE_LICENSE_PROPERTY = "sonar.sqale.licenseHash.secured";
-
- private final System2 system2;
-
- private final DbClient dbClient;
-
- private final RuleIndexer ruleIndexer;
-
- public ClearRulesOverloadedDebt(System2 system2, DbClient dbClient, RuleIndexer ruleIndexer) {
- this.system2 = system2;
- this.dbClient = dbClient;
- this.ruleIndexer = ruleIndexer;
- }
-
- @Override
- public void start() {
- try (DbSession dbSession = dbClient.openSession(false)) {
- if (hasAlreadyBeenExecuted(dbSession)) {
- return;
- }
- if (!isSqalePluginInstalled(dbSession)) {
- clearDebt(dbSession);
- }
- markAsExecuted(dbSession);
- dbSession.commit();
- ruleIndexer.index();
- }
- }
-
- private void clearDebt(DbSession session) {
- int countClearedRules = 0;
- for (RuleDto rule : dbClient.ruleDao().selectAll(session)) {
- if (isDebtOverridden(rule)) {
- rule.setRemediationFunction(null);
- rule.setRemediationGapMultiplier(null);
- rule.setRemediationBaseEffort(null);
- rule.setUpdatedAt(system2.now());
- dbClient.ruleDao().update(session, rule);
- countClearedRules++;
- }
- }
- if (countClearedRules > 0) {
- LOG.warn("The SQALE model has been cleaned to remove any redundant data left over from previous migrations.");
- LOG.warn("=> As a result, the technical debt of existing issues in your projects may change slightly when those projects are reanalyzed.");
- }
- }
-
- private static boolean isDebtOverridden(RuleDto ruleDto) {
- return ruleDto.getRemediationFunction() != null || ruleDto.getRemediationGapMultiplier() != null
- || ruleDto.getRemediationBaseEffort() != null;
- }
-
- private boolean isSqalePluginInstalled(DbSession session) {
- return dbClient.propertiesDao().selectGlobalProperty(session, SQALE_LICENSE_PROPERTY) != null;
- }
-
- private boolean hasAlreadyBeenExecuted(DbSession session) {
- return dbClient.loadedTemplateDao().countByTypeAndKey(ONE_SHOT_TASK_TYPE, TEMPLATE_KEY, session) > 0;
- }
-
- private void markAsExecuted(DbSession session) {
- dbClient.loadedTemplateDao().insert(new LoadedTemplateDto(TEMPLATE_KEY, ONE_SHOT_TASK_TYPE), session);
- }
-
- @Override
- public void stop() {
- // Nothing to do
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
deleted file mode 100644
index 0b24025575b..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.server.startup;
-
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.property.PropertyDto;
-import org.sonar.db.rule.RuleDao;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.rule.index.RuleIndexer;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.sonar.db.loadedtemplate.LoadedTemplateDto.ONE_SHOT_TASK_TYPE;
-
-public class ClearRulesOverloadedDebtTest {
-
- private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
- private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
-
- private System2 system2 = mock(System2.class);
-
- @Rule
- public DbTester tester = DbTester.create(system2);
-
- @Rule
- public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
-
- @Rule
- public LogTester logTester = new LogTester();
-
- private DbClient dbClient = tester.getDbClient();
- private DbSession dbSession = tester.getSession();
- private RuleDao ruleDao = new RuleDao();
- private RuleIndexer ruleIndexer = new RuleIndexer(system2, dbClient, esTester.client());
-
- private ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(system2, dbClient, ruleIndexer);
-
- @Test
- public void remove_overridden_debt() throws Exception {
- // Characteristic and remediation function is overridden
- insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d");
- // Only characteristic is overridden
- insertRuleDto(RULE_KEY_2, null, null, null);
- // Only remediation function is overridden
- insertRuleDto(RULE_KEY_3, "CONSTANT_ISSUE", "5min", null);
-
- underTest.start();
-
- verifyRuleHasNotOverriddenDebt(RULE_KEY_1);
- verifyRuleHasNotOverriddenDebt(RULE_KEY_2);
- verifyRuleHasNotOverriddenDebt(RULE_KEY_3);
- verifyTaskRegistered();
- verifyLog();
- }
-
- @Test
- public void not_update_rule_debt_not_overridden() throws Exception {
- RuleDto rule = insertRuleDto(RULE_KEY_1, null, null, null);
- long updateAt = rule.getUpdatedAt();
-
- underTest.start();
-
- RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
- assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
- verifyRuleHasNotOverriddenDebt(RULE_KEY_1);
-
- verifyTaskRegistered();
- verifyEmptyLog();
- }
-
- @Test
- public void not_update_rule_debt_when_sqale_is_installed() throws Exception {
- insertSqaleProperty();
- RuleDto rule = insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d");
- long updateAt = rule.getUpdatedAt();
-
- underTest.start();
-
- RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
- assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
-
- verifyTaskRegistered();
- verifyEmptyLog();
- }
-
- @Test
- public void not_execute_task_when_already_executed() throws Exception {
- insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d");
- underTest.start();
- verifyLog();
- verifyTaskRegistered();
-
- logTester.clear();
- underTest.start();
- assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
- verifyEmptyLog();
- }
-
- private void verifyRuleHasNotOverriddenDebt(RuleKey ruleKey) {
- // Refresh session
- dbSession.commit(true);
-
- RuleDto ruleDto = ruleDao.selectOrFailByKey(dbSession, ruleKey);
- assertThat(ruleDto.getRemediationFunction()).isNull();
- assertThat(ruleDto.getRemediationGapMultiplier()).isNull();
- assertThat(ruleDto.getRemediationBaseEffort()).isNull();
- }
-
- private RuleDto insertRuleDto(RuleKey ruleKey, @Nullable String function, @Nullable String coeff, @Nullable String offset) {
- RuleDto ruleDto = RuleTesting.newDto(ruleKey).setRemediationFunction(function).setRemediationBaseEffort(offset).setRemediationGapMultiplier(coeff);
- ruleDao.insert(dbSession,
- ruleDto
- );
- dbSession.commit();
- ruleIndexer.index();
- return ruleDto;
- }
-
- private void insertSqaleProperty() {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.sqale.licenseHash.secured").setValue("ABCD"));
- dbSession.commit();
- }
-
- private void verifyTaskRegistered() {
- assertThat(dbClient.loadedTemplateDao().countByTypeAndKey(ONE_SHOT_TASK_TYPE, "ClearRulesOverloadedDebt", dbSession)).isEqualTo(1);
- }
-
- private void verifyLog() {
- assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
- "The SQALE model has been cleaned to remove any redundant data left over from previous migrations.",
- "=> As a result, the technical debt of existing issues in your projects may change slightly when those projects are reanalyzed.");
- }
-
- private void verifyEmptyLog() {
- assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
- }
-}