]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16635 force reloading of all plugins
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Fri, 15 Jul 2022 14:19:28 +0000 (16:19 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 15 Jul 2022 20:02:53 +0000 (20:02 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPlugins.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/DbVersion95.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHash.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v96/DbVersion96.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest.java [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest/schema.sql [deleted file]

diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPlugins.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPlugins.java
new file mode 100644 (file)
index 0000000..ec63d57
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.platform.db.migration.step;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+
+public class ForceReloadingOfAllPlugins extends DataChange {
+  @VisibleForTesting
+  static final String OVERWRITE_HASH = "cccccccccccccccccccccccccccccccc";
+
+  public ForceReloadingOfAllPlugins(Database db) {
+    super(db);
+  }
+
+  @Override protected void execute(Context context) throws SQLException {
+    Upsert upsert = context.prepareUpsert("update plugins set file_hash = ? ");
+    upsert.setString(1, OVERWRITE_HASH);
+    upsert.execute();
+    upsert.commit();
+  }
+}
index ff1ef92b923fdc49cf45d9b1003cbe8ef4c9b9d0..f95b029d457fd7449281e74161d73dbf9b8ec5cf 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform.db.migration.version.v95;
 
+import org.sonar.server.platform.db.migration.step.ForceReloadingOfAllPlugins;
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
 
@@ -38,7 +39,7 @@ public class DbVersion95 implements DbVersion {
       .add(6408, "Drop column DESCRIPTIONS from RULES table", DropRuleDescriptionColumn.class)
       .add(6409, "Drop column CREATED_AT from RULES_METADATA table", DropRuleMetadataCreatedAtColumn.class)
       .add(6410, "Drop column UPDATED_AT from RULES_METADATA table", DropRuleMetadataUpdatedAtColumn.class)
-      .add(6411, "Overwrite plugin file hash to force reloading rules", OverwritePluginFileHash.class)
+      .add(6411, "Overwrite plugin file hash to force reloading rules", ForceReloadingOfAllPlugins.class)
 
       .add(6412, "Add rules_metadata columns to rules table", AddRulesMetadataColumnsToRulesTable.class)
       .add(6413, "Populate rules metadata in rules table", PopulateRulesMetadataInRuleTable.class)
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHash.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHash.java
deleted file mode 100644 (file)
index 578aca5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.platform.db.migration.version.v95;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.Upsert;
-
-public class OverwritePluginFileHash extends DataChange {
-  @VisibleForTesting
-  static final String OVERWRITE_HASH = "cccccccccccccccccccccccccccccccc";
-
-  public OverwritePluginFileHash(Database db) {
-    super(db);
-  }
-
-  @Override protected void execute(Context context) throws SQLException {
-    Upsert upsert = context.prepareUpsert("update plugins set file_hash = ? ");
-    upsert.setString(1, OVERWRITE_HASH);
-    upsert.execute();
-    upsert.commit();
-  }
-}
index 5a473258ad5c28a1118a7c52b1788814548c181d..4c3ad0be119ca1f9cea97bbd792d37e4f1042832 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform.db.migration.version.v96;
 
+import org.sonar.server.platform.db.migration.step.ForceReloadingOfAllPlugins;
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
 
@@ -34,6 +35,7 @@ public class DbVersion96 implements DbVersion {
       .add(6504, "Add column 'expiration_date' to 'user_tokens'", AddExpirationDateColumnToUserTokens.class)
       .add(6505, "Add column 'rule_description_context_key' to 'issues'", AddRuleDescriptionContextKeyInIssuesTable.class)
       .add(6506, "Add column 'education_principles' to 'rules'", AddEducationPrinciplesColumnToRuleTable.class)
+      .add(6507, "Overwrite plugin file hash to force reloading rules", ForceReloadingOfAllPlugins.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest.java
new file mode 100644 (file)
index 0000000..948bdd1
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.platform.db.migration.step;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.step.ForceReloadingOfAllPlugins.OVERWRITE_HASH;
+
+public class ForceReloadingOfAllPluginsTest {
+  private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(ForceReloadingOfAllPluginsTest.class, "schema.sql");
+
+  private final DataChange underTest = new ForceReloadingOfAllPlugins(db.database());
+
+  @Test
+  public void migration_overwrite_file_hash_on_all_plugins() throws SQLException {
+    String pluginUuid1 = insertPlugin();
+    String pluginUuid2 = insertPlugin();
+
+    underTest.execute();
+
+    assertPluginFileHashOverwrite(pluginUuid1);
+    assertPluginFileHashOverwrite(pluginUuid2);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    String pluginUuid1 = insertPlugin();
+    String pluginUuid2 = insertPlugin();
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    assertPluginFileHashOverwrite(pluginUuid1);
+    assertPluginFileHashOverwrite(pluginUuid2);
+  }
+
+  private void assertPluginFileHashOverwrite(String pluginUuid) {
+    String selectSql = String.format("select file_hash from plugins where uuid='%s'", pluginUuid);
+    var selectResult = db.select(selectSql);
+    assertThat(selectResult.get(0)).containsEntry("FILE_HASH", OVERWRITE_HASH);
+  }
+
+  private String insertPlugin() {
+    Map<String, Object> map = new HashMap<>();
+    String uuid = uuidFactory.create();
+    map.put("UUID", uuid);
+    map.put("KEE", randomAlphabetic(20));
+    map.put("FILE_HASH", randomAlphabetic(32));
+    map.put("CREATED_AT", System.currentTimeMillis());
+    map.put("UPDATED_AT", System.currentTimeMillis());
+    map.put("TYPE", "EXTERNAL");
+    map.put("REMOVED", false);
+    db.executeInsert("plugins", map);
+
+    return uuid;
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest.java
deleted file mode 100644 (file)
index 57f0e9b..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.platform.db.migration.version.v95;
-
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.platform.db.migration.version.v95.OverwritePluginFileHash.OVERWRITE_HASH;
-
-public class OverwritePluginFileHashTest {
-  private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(OverwritePluginFileHashTest.class, "schema.sql");
-
-  private final DataChange underTest = new OverwritePluginFileHash(db.database());
-
-  @Test
-  public void migration_overwrite_file_hash_on_all_plugins() throws SQLException {
-    String pluginUuid1 = insertPlugin();
-    String pluginUuid2 = insertPlugin();
-
-    underTest.execute();
-
-    assertPluginFileHashOverwrite(pluginUuid1);
-    assertPluginFileHashOverwrite(pluginUuid2);
-  }
-
-  @Test
-  public void migration_should_be_reentrant() throws SQLException {
-    String pluginUuid1 = insertPlugin();
-    String pluginUuid2 = insertPlugin();
-
-    underTest.execute();
-    // re-entrant
-    underTest.execute();
-
-    assertPluginFileHashOverwrite(pluginUuid1);
-    assertPluginFileHashOverwrite(pluginUuid2);
-  }
-
-  private void assertPluginFileHashOverwrite(String pluginUuid) {
-    String selectSql = String.format("select file_hash from plugins where uuid='%s'", pluginUuid);
-    var selectResult = db.select(selectSql);
-    assertThat(selectResult.get(0)).containsEntry("FILE_HASH", OVERWRITE_HASH);
-  }
-
-  private String insertPlugin() {
-    Map<String, Object> map = new HashMap<>();
-    String uuid = uuidFactory.create();
-    map.put("UUID", uuid);
-    map.put("KEE", randomAlphabetic(20));
-    map.put("FILE_HASH", randomAlphabetic(32));
-    map.put("CREATED_AT", System.currentTimeMillis());
-    map.put("UPDATED_AT", System.currentTimeMillis());
-    map.put("TYPE", "EXTERNAL");
-    map.put("REMOVED", false);
-    db.executeInsert("plugins", map);
-
-    return uuid;
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/step/ForceReloadingOfAllPluginsTest/schema.sql
new file mode 100644 (file)
index 0000000..d51d626
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "PLUGINS"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "KEE" CHARACTER VARYING(200) NOT NULL,
+    "BASE_PLUGIN_KEY" CHARACTER VARYING(200),
+    "FILE_HASH" CHARACTER VARYING(200) NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL,
+    "TYPE" CHARACTER VARYING(10) NOT NULL,
+    "REMOVED" BOOLEAN DEFAULT FALSE NOT NULL
+);
+ALTER TABLE "PLUGINS" ADD CONSTRAINT "PK_PLUGINS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v95/OverwritePluginFileHashTest/schema.sql
deleted file mode 100644 (file)
index d51d626..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-CREATE TABLE "PLUGINS"(
-    "UUID" CHARACTER VARYING(40) NOT NULL,
-    "KEE" CHARACTER VARYING(200) NOT NULL,
-    "BASE_PLUGIN_KEY" CHARACTER VARYING(200),
-    "FILE_HASH" CHARACTER VARYING(200) NOT NULL,
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL,
-    "TYPE" CHARACTER VARYING(10) NOT NULL,
-    "REMOVED" BOOLEAN DEFAULT FALSE NOT NULL
-);
-ALTER TABLE "PLUGINS" ADD CONSTRAINT "PK_PLUGINS" PRIMARY KEY("UUID");
-CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE" NULLS FIRST);