diff options
author | Jacek Poreda <jacek.poreda@sonarsource.com> | 2023-02-03 09:13:29 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-02-09 20:03:34 +0000 |
commit | e5717b5f638bae5aa844e35b32deea61ef9c5e38 (patch) | |
tree | 273aef6cc41550b2dc81b799ac21c9a8482d0c04 /server/sonar-webserver-core/src | |
parent | edb0bf919adfebe91a04ba84ed64e31744a0ef42 (diff) | |
download | sonarqube-e5717b5f638bae5aa844e35b32deea61ef9c5e38.tar.gz sonarqube-e5717b5f638bae5aa844e35b32deea61ef9c5e38.zip |
[NO-JIRA] Drop blue green deployment flag
Diffstat (limited to 'server/sonar-webserver-core/src')
8 files changed, 13 insertions, 292 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java deleted file mode 100644 index 8b35890be12..00000000000 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.es; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.client.indices.GetIndexRequest; -import org.sonar.api.utils.log.Loggers; -import org.sonar.core.util.stream.MoreCollectors; -import org.sonar.server.platform.db.migration.es.MigrationEsClient; - -public class MigrationEsClientImpl implements MigrationEsClient { - private final EsClient client; - private final Set<String> updatedIndices = new HashSet<>(); - - public MigrationEsClientImpl(EsClient client) { - this.client = client; - } - - @Override - public void deleteIndexes(String name, String... otherNames) { - String[] indices = client.getIndex(new GetIndexRequest("_all")).getIndices(); - Set<String> existingIndices = Arrays.stream(indices).collect(MoreCollectors.toSet()); - Stream.concat(Stream.of(name), Arrays.stream(otherNames)) - .distinct() - .filter(existingIndices::contains) - .forEach(this::deleteIndex); - } - - @Override - public void addMappingToExistingIndex(String index, String type, String mappingName, String mappingType, Map<String, String> options) { - //TODO:: remove? -// String[] indices = client.getIndex(new GetIndexRequest(index)).getIndices(); -// if (indices != null && indices.length == 1) { -// Loggers.get(getClass()).info("Add mapping [{}] to Elasticsearch index [{}]", mappingName, index); -// String mappingOptions = Stream.concat(Stream.of(Maps.immutableEntry("type", mappingType)), options.entrySet().stream()) -// .map(e -> e.getKey() + "=" + e.getValue()) -// .collect(Collectors.joining(",")); -// client.putMapping(new PutMappingRequest(index) -// .source(mappingName, mappingOptions)); -// updatedIndices.add(index); -// } else { -// throw new IllegalStateException("Expected only one index to be found, actual [" + String.join(",", indices) + "]"); -// } - } - - @Override - public Set<String> getUpdatedIndices() { - return updatedIndices; - } - - private void deleteIndex(String index) { - Loggers.get(getClass()).info("Drop Elasticsearch index [{}]", index); - client.deleteIndex(new DeleteIndexRequest(index)); - } -} diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DatabaseServerCompatibility.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DatabaseServerCompatibility.java index c33501c288f..3019b0f836f 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DatabaseServerCompatibility.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DatabaseServerCompatibility.java @@ -21,11 +21,9 @@ package org.sonar.server.platform; import java.util.Optional; import org.sonar.api.Startable; -import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.process.ProcessProperties; import org.sonar.server.platform.db.migration.version.DatabaseVersion; import static org.sonar.server.log.ServerProcessLogging.STARTUP_LOGGER_NAME; @@ -35,11 +33,9 @@ public class DatabaseServerCompatibility implements Startable { private static final String HIGHLIGHTER = "################################################################################"; private final DatabaseVersion version; - private final Configuration configuration; - public DatabaseServerCompatibility(DatabaseVersion version, Configuration configuration) { + public DatabaseServerCompatibility(DatabaseVersion version) { this.version = version; - this.configuration = configuration; } @Override @@ -54,16 +50,14 @@ public class DatabaseServerCompatibility implements Startable { if (currentVersion.isPresent() && currentVersion.get() < DatabaseVersion.MIN_UPGRADE_VERSION) { throw MessageException.of("The version of SonarQube is too old. Please upgrade to the Long Term Support version first."); } - boolean blueGreen = configuration.getBoolean(ProcessProperties.Property.BLUE_GREEN_ENABLED.getKey()).orElse(false); - if (!blueGreen) { - String msg = "The database must be manually upgraded. Please backup the database and browse /setup. " - + "For more information: https://docs.sonarqube.org/latest/setup/upgrading"; - Loggers.get(DatabaseServerCompatibility.class).warn(msg); - Logger logger = Loggers.get(STARTUP_LOGGER_NAME); - logger.warn(HIGHLIGHTER); - logger.warn(msg); - logger.warn(HIGHLIGHTER); - } + + String msg = "The database must be manually upgraded. Please backup the database and browse /setup. " + + "For more information: https://docs.sonarqube.org/latest/setup/upgrading"; + Loggers.get(DatabaseServerCompatibility.class).warn(msg); + Logger logger = Loggers.get(STARTUP_LOGGER_NAME); + logger.warn(HIGHLIGHTER); + logger.warn(msg); + logger.warn(HIGHLIGHTER); } } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DefaultServerUpgradeStatus.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DefaultServerUpgradeStatus.java index 4e32b381fd4..95505acd7b1 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DefaultServerUpgradeStatus.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/DefaultServerUpgradeStatus.java @@ -70,10 +70,6 @@ public class DefaultServerUpgradeStatus implements ServerUpgradeStatus, Startabl return (int) initialDbVersion; } - public boolean isBlueGreen() { - return configuration.getBoolean(ProcessProperties.Property.BLUE_GREEN_ENABLED.getKey()).orElse(false); - } - public boolean isAutoDbUpgrade() { return configuration.getBoolean(ProcessProperties.Property.AUTO_DATABASE_UPGRADE.getKey()).orElse(false); } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/migration/AutoDbMigration.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/migration/AutoDbMigration.java index af8c69334ba..da702850a87 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/migration/AutoDbMigration.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/migration/AutoDbMigration.java @@ -41,9 +41,6 @@ public class AutoDbMigration implements Startable { } else if (serverUpgradeStatus.isUpgraded() && serverUpgradeStatus.isAutoDbUpgrade()) { Loggers.get(getClass()).info("Automatically perform DB migration, as automatic database upgrade is enabled"); migrationEngine.execute(); - } else if (serverUpgradeStatus.isUpgraded() && serverUpgradeStatus.isBlueGreen()) { - Loggers.get(getClass()).info("Automatically perform DB migration on blue/green deployment"); - migrationEngine.execute(); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java deleted file mode 100644 index c039565e784..00000000000 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.es; - -import com.google.common.collect.ImmutableMap; -import java.util.Iterator; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.elasticsearch.client.indices.GetMappingsRequest; -import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.server.platform.db.migration.es.MigrationEsClient; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder; - -@Ignore -public class MigrationEsClientImplTest { - @Rule - public LogTester logTester = new LogTester(); - @Rule - public EsTester es = EsTester.createCustom( - new SimpleIndexDefinition("as"), - new SimpleIndexDefinition("bs"), - new SimpleIndexDefinition("cs")); - - private MigrationEsClient underTest = new MigrationEsClientImpl(es.client()); - - @Test - public void delete_existing_index() { - underTest.deleteIndexes("as"); - - assertThat(loadExistingIndices()) - .toIterable() - .doesNotContain("as") - .contains("bs", "cs"); - assertThat(logTester.logs(LoggerLevel.INFO)) - .contains("Drop Elasticsearch index [as]"); - } - - @Test - public void delete_index_that_does_not_exist() { - underTest.deleteIndexes("as", "xxx", "cs"); - - assertThat(loadExistingIndices()) - .toIterable() - .doesNotContain("as", "cs") - .contains("bs"); - assertThat(logTester.logs(LoggerLevel.INFO)) - .contains("Drop Elasticsearch index [as]", "Drop Elasticsearch index [cs]") - .doesNotContain("Drop Elasticsearch index [xxx]"); - } - - @Test - public void addMappingToExistingIndex() { - Map<String, String> mappingOptions = ImmutableMap.of("norms", "false"); - underTest.addMappingToExistingIndex("as", "s", "new_field", "keyword", mappingOptions); - - assertThat(loadExistingIndices()).toIterable().contains("as"); - Map<String, MappingMetadata> mappings = mappings(); - MappingMetadata mapping = mappings.get("as"); - assertThat(countMappingFields(mapping)).isOne(); - assertThat(field(mapping, "new_field")).isNotNull(); - - assertThat(logTester.logs(LoggerLevel.INFO)) - .contains("Add mapping [new_field] to Elasticsearch index [as]"); - assertThat(underTest.getUpdatedIndices()).containsExactly("as"); - } - - @Test - public void shouldFailIfMoreThanOneIndexReturned() { - String indexPattern = "*s"; - Map<String, String> mappingOptions = ImmutableMap.of("norms", "false"); - assertThatThrownBy(() -> underTest.addMappingToExistingIndex(indexPattern, "s", "new_field", "keyword", mappingOptions)) - .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("Expected only one index to be found, actual"); - } - - private Iterator<String> loadExistingIndices() { - return es.client().getMapping(new GetMappingsRequest()).mappings().keySet().iterator(); - } - - private Map<String, MappingMetadata> mappings() { - return es.client().getMapping(new GetMappingsRequest()).mappings(); - } - - @CheckForNull - @SuppressWarnings("unchecked") - private Map<String, Object> field(MappingMetadata mapping, String field) { - Map<String, Object> props = (Map<String, Object>) mapping.getSourceAsMap().get("properties"); - return (Map<String, Object>) props.get(field); - } - - private int countMappingFields(MappingMetadata mapping) { - return ((Map) mapping.getSourceAsMap().get("properties")).size(); - } - - private static class SimpleIndexDefinition implements IndexDefinition { - private final String indexName; - - public SimpleIndexDefinition(String indexName) { - this.indexName = indexName; - } - - @Override - public void define(IndexDefinitionContext context) { - IndexType.IndexMainType mainType = IndexType.main(Index.simple(indexName), indexName.substring(1)); - context.create( - mainType.getIndex(), - newBuilder(new MapSettings().asConfig()).build()) - .createTypeMapping(mainType); - } - } -} diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java index c0053e5c7be..46201b8a611 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DatabaseServerCompatibilityTest.java @@ -37,14 +37,12 @@ public class DatabaseServerCompatibilityTest { @Rule public LogTester logTester = new LogTester(); - private MapSettings settings = new MapSettings(); @Test public void fail_if_requires_downgrade() { DatabaseVersion version = mock(DatabaseVersion.class); when(version.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_DOWNGRADE); - var config = settings.asConfig(); - var compatibility = new DatabaseServerCompatibility(version, config); + var compatibility = new DatabaseServerCompatibility(version); assertThatThrownBy(compatibility::start) .isInstanceOf(MessageException.class) .hasMessage("Database was upgraded to a more recent version of SonarQube. " @@ -56,8 +54,7 @@ public class DatabaseServerCompatibilityTest { DatabaseVersion version = mock(DatabaseVersion.class); when(version.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_UPGRADE); when(version.getVersion()).thenReturn(Optional.of(12L)); - var config = settings.asConfig(); - var compatibility = new DatabaseServerCompatibility(version, config); + var compatibility = new DatabaseServerCompatibility(version); assertThatThrownBy(compatibility::start) .isInstanceOf(MessageException.class) .hasMessage("The version of SonarQube is too old. Please upgrade to the Long Term Support version first."); @@ -68,7 +65,7 @@ public class DatabaseServerCompatibilityTest { DatabaseVersion version = mock(DatabaseVersion.class); when(version.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_UPGRADE); when(version.getVersion()).thenReturn(Optional.of(DatabaseVersion.MIN_UPGRADE_VERSION)); - new DatabaseServerCompatibility(version, settings.asConfig()).start(); + new DatabaseServerCompatibility(version).start(); assertThat(logTester.logs()).hasSize(4); assertThat(logTester.logs(LoggerLevel.WARN)).contains( @@ -84,19 +81,7 @@ public class DatabaseServerCompatibilityTest { public void do_nothing_if_up_to_date() { DatabaseVersion version = mock(DatabaseVersion.class); when(version.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE); - new DatabaseServerCompatibility(version, settings.asConfig()).start(); + new DatabaseServerCompatibility(version).start(); // no error } - - @Test - public void upgrade_automatically_if_blue_green_deployment() { - settings.setProperty("sonar.blueGreenEnabled", "true"); - DatabaseVersion version = mock(DatabaseVersion.class); - when(version.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_UPGRADE); - when(version.getVersion()).thenReturn(Optional.of(DatabaseVersion.MIN_UPGRADE_VERSION)); - - new DatabaseServerCompatibility(version, settings.asConfig()).start(); - - assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); - } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DefaultServerUpgradeStatusTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DefaultServerUpgradeStatusTest.java index b4888664d88..2ed13ea98cb 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DefaultServerUpgradeStatusTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/DefaultServerUpgradeStatusTest.java @@ -78,19 +78,6 @@ public class DefaultServerUpgradeStatusTest { } @Test - public void isBlueGreen() { - settings.clear(); - assertThat(underTest.isBlueGreen()).isFalse(); - - settings.setProperty("sonar.blueGreenEnabled", true); - assertThat(underTest.isBlueGreen()).isTrue(); - - settings.setProperty("sonar.blueGreenEnabled", false); - assertThat(underTest.isBlueGreen()).isFalse(); - } - - - @Test public void isAutoDbUpgrade() { settings.clear(); assertThat(underTest.isAutoDbUpgrade()).isFalse(); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java index f12190b6a76..ae3718b8da3 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/AutoDbMigrationTest.java @@ -89,30 +89,6 @@ public class AutoDbMigrationTest { } @Test - public void start_runs_MigrationEngine_if_blue_green_upgrade() { - mockFreshInstall(false); - when(serverUpgradeStatus.isUpgraded()).thenReturn(true); - when(serverUpgradeStatus.isBlueGreen()).thenReturn(true); - - underTest.start(); - - verify(migrationEngine).execute(); - assertThat(logTester.logs(LoggerLevel.INFO)).contains("Automatically perform DB migration on blue/green deployment"); - } - - @Test - public void start_does_nothing_if_blue_green_but_no_upgrade() { - mockFreshInstall(false); - when(serverUpgradeStatus.isUpgraded()).thenReturn(false); - when(serverUpgradeStatus.isBlueGreen()).thenReturn(true); - - underTest.start(); - - verifyNoInteractions(migrationEngine); - assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty(); - } - - @Test public void start_runs_MigrationEngine_if_autoDbMigration_enabled() { mockFreshInstall(false); when(serverUpgradeStatus.isUpgraded()).thenReturn(true); |