From 0358ec707893e66fc1e915d75eb565a8e7bf8445 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 17 Jul 2017 18:14:14 +0200 Subject: [PATCH] SONAR-9514 Disable automatic creation of unknown Elasticsearch indices --- .../src/main/java/org/sonar/search/EsSettings.java | 3 ++- .../src/test/java/org/sonar/server/es/EsTester.java | 1 + .../server/es/request/ProxyDeleteRequestBuilderTest.java | 3 ++- .../qualityprofile/index/ActiveRuleIndexerTest.java | 8 +------- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java index bb882f38a0d..052e5e26bef 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java +++ b/server/sonar-search/src/main/java/org/sonar/search/EsSettings.java @@ -154,7 +154,8 @@ public class EsSettings implements EsSettingsMBean { .put("index.number_of_shards", "1") .put("index.refresh_interval", "30s") .put("action.auto_create_index", false) - .put("index.mapper.dynamic", false); + .put("index.mapper.dynamic", false) + .put("action.auto_create_index", false); } private void configureCluster(Settings.Builder builder) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java b/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java index 56fd0b9d5b5..077d997c2e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java @@ -219,6 +219,7 @@ public class EsTester extends ExternalResource { .put("processors", 1) .put("http.enabled", false) .put("config.ignore_system_properties", true) + .put("action.auto_create_index", false) .put("path.home", tmpDir)) .build(); node.start(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteRequestBuilderTest.java index ca7d0903324..dda250c948e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteRequestBuilderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteRequestBuilderTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.server.es.EsTester; +import org.sonar.server.es.FakeIndexDefinition; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -33,7 +34,7 @@ import static org.junit.Assert.fail; public class ProxyDeleteRequestBuilderTest { @ClassRule - public static EsTester esTester = new EsTester(); + public static EsTester esTester = new EsTester(new FakeIndexDefinition()); @Rule public LogTester logTester = new LogTester(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index 32011df23d6..0fa1fc57b54 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -120,8 +120,7 @@ public class ActiveRuleIndexerTest { @Test public void commitAndIndex_keeps_elements_to_recover_in_ES_QUEUE_on_errors() { ActiveRuleDto ar = db.qualityProfiles().activateRule(profile1, rule1); - // force error by deleting the index - deleteRulesIndex(); + es.lockWrites(INDEX_TYPE_ACTIVE_RULE); commitAndIndex(ar); @@ -177,11 +176,6 @@ public class ActiveRuleIndexerTest { assertThat(es.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isEqualTo(1); } - - private void deleteRulesIndex() { - es.deleteIndex(RuleIndexDefinition.INDEX_TYPE_RULE.getIndex()); - } - private void assertThatEsQueueTableIsEmpty() { assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isEqualTo(0); } -- 2.39.5