From 5ed6c6dabcee4fbe4e8c8526c2fb4950e5cea25f Mon Sep 17 00:00:00 2001 From: Aleksandr Tuliakov Date: Mon, 17 Feb 2025 14:21:06 +0300 Subject: [PATCH] Add targetIndexSettings validation with test Signed-off-by: Aleksandr Tuliakov --- .../indexmanagement/rollup/model/Rollup.kt | 4 ++++ .../indexmanagement/rollup/model/RollupTests.kt | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt index 8283fc68b..6c4fe8af6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/rollup/model/Rollup.kt @@ -5,6 +5,7 @@ package org.opensearch.indexmanagement.rollup.model +import org.opensearch.common.settings.IndexScopedSettings import org.opensearch.common.settings.Settings import org.opensearch.commons.authuser.User import org.opensearch.core.common.io.stream.StreamInput @@ -89,6 +90,9 @@ data class Rollup( } } require(sourceIndex != targetIndex) { "Your source and target index cannot be the same" } + if (targetIndexSettings != null) { + IndexScopedSettings(null, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS).validate(targetIndexSettings, true) + } require(dimensions.filter { it.type == Dimension.Type.DATE_HISTOGRAM }.size == 1) { "Must specify precisely one date histogram dimension" // this covers empty dimensions case too } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt index e13f1d6e7..6577402a5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/model/RollupTests.kt @@ -5,6 +5,8 @@ package org.opensearch.indexmanagement.rollup.model +import org.opensearch.common.settings.Settings +import org.opensearch.common.settings.SettingsException import org.opensearch.indexmanagement.randomInstant import org.opensearch.indexmanagement.randomSchedule import org.opensearch.indexmanagement.rollup.randomDateHistogram @@ -52,6 +54,16 @@ class RollupTests : OpenSearchTestCase() { } } + fun `test rollup requires correct target index settings`() { + assertFailsWith(SettingsException::class, "Unknown property was `index.codec1`") { + randomRollup().copy(targetIndexSettings = Settings.builder().put("index.codec1", "zlib").build()) + } + + val sb = Settings.builder() + sb.put("index.codec", "zlib") + randomRollup().copy(targetIndexSettings = sb.build()) + } + fun `test rollup requires page size to be between 1 and 10k`() { assertFailsWith(IllegalArgumentException::class, "Page size was negative") { randomRollup().copy(pageSize = -1)