]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11643 Drop elasticsearch index 'tests'
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Jan 2019 17:39:50 +0000 (18:39 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 11 Feb 2019 08:11:40 +0000 (09:11 +0100)
12 files changed:
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTests.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/package-info.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTestsTest.java [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/test/index/package-info.java [deleted file]
server/sonar-server-common/src/test/java/org/sonar/server/es/EsTester.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java

index f50a10319f54db6da0a336491cc908ac55717373..c42071ea97abb3799d48407cc13065b462e27e5f 100644 (file)
@@ -115,7 +115,7 @@ public class ComputeEngineContainerImplTest {
       );
       assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
         CONTAINER_ITSELF
-          + 20 // MigrationConfigurationModule
+          + 21 // MigrationConfigurationModule
           + 17 // level 2
       );
       assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
index 3da0c4e4d838f87c7b387b49d4fb70fad64c33ef..16524dc220d5536a991fab60ea231b8ef0aeb3b4 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.server.platform.db.migration.version.v73.DbVersion73;
 import org.sonar.server.platform.db.migration.version.v74.DbVersion74;
 import org.sonar.server.platform.db.migration.version.v75.DbVersion75;
 import org.sonar.server.platform.db.migration.version.v76.DbVersion76;
+import org.sonar.server.platform.db.migration.version.v77.DbVersion77;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -63,6 +64,7 @@ public class MigrationConfigurationModule extends Module {
       DbVersion74.class,
       DbVersion75.class,
       DbVersion76.class,
+      DbVersion77.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java
new file mode 100644 (file)
index 0000000..5f1b46b
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion77 implements DbVersion {
+
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(2600, "Drop elasticsearch index 'tests'", DropElasticsearchIndexTests.class)
+    ;
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTests.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTests.java
new file mode 100644 (file)
index 0000000..3b30eab
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.SupportsBlueGreen;
+import org.sonar.server.platform.db.migration.es.MigrationEsClient;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+@SupportsBlueGreen
+public class DropElasticsearchIndexTests extends DdlChange {
+
+  private final MigrationEsClient migrationEsClient;
+
+  public DropElasticsearchIndexTests(Database db, MigrationEsClient migrationEsClient) {
+    super(db);
+    this.migrationEsClient = migrationEsClient;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    migrationEsClient.deleteIndexes("tests");
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/package-info.java
new file mode 100644 (file)
index 0000000..84451d7
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v77;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 134f20de5c684f53919ad90a58dc0970e10cab57..7e83b3e82632241d1777b8f4fbc9fb4beefe50b4 100644 (file)
@@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest {
     assertThat(container.getPicoContainer().getComponentAdapters())
       .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER
         // DbVersion classes
-        + 17
+        + 18
         // Others
         + 3);
   }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java
new file mode 100644 (file)
index 0000000..607aa16
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import org.junit.Test;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion77Test {
+
+  private DbVersion77 underTest = new DbVersion77();
+
+  @Test
+  public void migrationNumber_starts_at_2500() {
+    verifyMinimumMigrationNumber(underTest, 2600);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 1);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTestsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropElasticsearchIndexTestsTest.java
new file mode 100644 (file)
index 0000000..4f7aa3d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.v77;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.es.MigrationEsClient;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class DropElasticsearchIndexTestsTest {
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createEmpty();
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private MigrationEsClient esClient = mock(MigrationEsClient.class);
+  private DropElasticsearchIndexTests underTest = new DropElasticsearchIndexTests(db.database(), esClient);
+
+  @Test
+  public void rename_column() throws SQLException {
+    underTest.execute();
+
+    verify(esClient).deleteIndexes("tests");
+  }
+
+  public void migration_is_reentrant() throws SQLException {
+    underTest.execute();
+
+    underTest.execute();
+
+    verify(esClient).deleteIndexes("tests");
+  }
+
+}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
deleted file mode 100644 (file)
index d470528..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.test.index;
-
-import com.google.common.collect.ImmutableMap;
-import org.sonar.api.config.Configuration;
-import org.sonar.server.es.IndexDefinition;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.NewIndex;
-
-import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
-import static org.sonar.server.es.DefaultIndexSettings.INDEX_SEARCHABLE;
-import static org.sonar.server.es.NewIndex.SettingsConfiguration.MANUAL_REFRESH_INTERVAL;
-import static org.sonar.server.es.NewIndex.SettingsConfiguration.newBuilder;
-
-public class TestIndexDefinition implements IndexDefinition {
-
-  public static final IndexType INDEX_TYPE_TEST = new IndexType("tests", "test");
-  public static final String FIELD_PROJECT_UUID = "projectUuid";
-  public static final String FIELD_FILE_UUID = "fileUuid";
-  public static final String FIELD_TEST_UUID = "testUuid";
-  public static final String FIELD_NAME = "name";
-  public static final String FIELD_STATUS = "status";
-  public static final String FIELD_DURATION_IN_MS = "durationInMs";
-  public static final String FIELD_MESSAGE = "message";
-  public static final String FIELD_STACKTRACE = "stacktrace";
-  public static final String FIELD_COVERED_FILES = "coveredFiles";
-  public static final String FIELD_COVERED_FILE_UUID = "sourceFileUuid";
-  public static final String FIELD_COVERED_FILE_LINES = "coveredLines";
-  public static final String FIELD_UPDATED_AT = "updatedAt";
-
-  private final Configuration config;
-
-  public TestIndexDefinition(Configuration config) {
-    this.config = config;
-  }
-
-  @Override
-  public void define(IndexDefinitionContext context) {
-    NewIndex index = context.create(
-      INDEX_TYPE_TEST.getIndex(),
-      newBuilder(config)
-        .setRefreshInterval(MANUAL_REFRESH_INTERVAL)
-        .setDefaultNbOfShards(5)
-        .build());
-
-    NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType());
-    mapping.setAttribute("_routing", ImmutableMap.of("required", true));
-    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
-    mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
-    mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
-    mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().disableSortingAndAggregating().build();
-    mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build();
-    mapping.createLongField(FIELD_DURATION_IN_MS);
-    mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().disableSortingAndAggregating().build();
-    mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().disableSortingAndAggregating().build();
-    mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
-      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", INDEX_SEARCHABLE),
-      FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer"))));
-    mapping.createDateTimeField(FIELD_UPDATED_AT);
-  }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/test/index/package-info.java b/server/sonar-server-common/src/main/java/org/sonar/server/test/index/package-info.java
deleted file mode 100644 (file)
index 6082779..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.test.index;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
index e11cc2ec8c0c2325f5b98f3d1aabf5526ad7f1a8..0b3b266053de28b25c78ddbadd2a4fa334210c84 100644 (file)
@@ -63,7 +63,6 @@ import org.sonar.server.component.index.ComponentIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.measure.index.ProjectMeasuresIndexDefinition;
 import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.test.index.TestIndexDefinition;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.view.index.ViewIndexDefinition;
 
@@ -109,7 +108,6 @@ public class EsTester extends ExternalResource {
         IssueIndexDefinition.createForTest(),
         new ProjectMeasuresIndexDefinition(config),
         RuleIndexDefinition.createForTest(),
-        new TestIndexDefinition(config),
         new UserIndexDefinition(config),
         new ViewIndexDefinition(config));
 
index 07edaae0eeaece7d66c4b0e2ec02c5651d559c20..b373c4cacd24555f77ad273610e83aa409f9f15e 100644 (file)
@@ -199,7 +199,6 @@ import org.sonar.server.startup.LogServerId;
 import org.sonar.server.telemetry.TelemetryClient;
 import org.sonar.server.telemetry.TelemetryDaemon;
 import org.sonar.server.telemetry.TelemetryDataLoader;
-import org.sonar.server.test.index.TestIndexDefinition;
 import org.sonar.server.test.ws.TestsWs;
 import org.sonar.server.text.MacroInterpreter;
 import org.sonar.server.ui.DeprecatedViews;
@@ -476,7 +475,6 @@ public class PlatformLevel4 extends PlatformLevel {
 
       // Tests
       TestsWs.class,
-      TestIndexDefinition.class,
 
       // Settings
       PersistentSettings.class,