Avoid crashing on using the index.lifecycle.name in the API body (#1060)
* Avoid crashing on using the index.lifecycle.name in the API body Signed-off-by: frotsch <frotsch@mailbox.org>
This commit is contained in:
parent
fbdc180944
commit
c34f9ab75c
|
@ -1044,7 +1044,10 @@ public class MetadataCreateIndexService {
|
|||
for (final String key : settings.keySet()) {
|
||||
final Setting<?> setting = indexScopedSettings.get(key);
|
||||
if (setting == null) {
|
||||
assert indexScopedSettings.isPrivateSetting(key) : "expected [" + key + "] to be private but it was not";
|
||||
// see: https://github.com/opensearch-project/OpenSearch/issues/1019
|
||||
if(!indexScopedSettings.isPrivateSetting(key)) {
|
||||
validationErrors.add("expected [" + key + "] to be private but it was not");
|
||||
}
|
||||
} else if (setting.isPrivateIndex()) {
|
||||
validationErrors.add("private index setting [" + key + "] can not be set explicitly");
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ import org.opensearch.common.unit.TimeValue;
|
|||
import org.opensearch.common.util.BigArrays;
|
||||
import org.opensearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.opensearch.common.xcontent.XContentFactory;
|
||||
import org.opensearch.env.Environment;
|
||||
import org.opensearch.index.Index;
|
||||
import org.opensearch.index.IndexNotFoundException;
|
||||
import org.opensearch.index.IndexSettings;
|
||||
|
@ -963,6 +964,31 @@ public class MetadataCreateIndexServiceTests extends OpenSearchTestCase {
|
|||
+ "and [index.translog.retention.size] are deprecated and effectively ignored. They will be removed in a future version.");
|
||||
}
|
||||
|
||||
public void testIndexLifecycleNameSetting() {
|
||||
// see: https://github.com/opensearch-project/OpenSearch/issues/1019
|
||||
final Settings ilnSetting = Settings.builder().put("index.lifecycle.name", "dummy").build();
|
||||
withTemporaryClusterService(((clusterService, threadPool) -> {
|
||||
MetadataCreateIndexService checkerService = new MetadataCreateIndexService(
|
||||
Settings.EMPTY,
|
||||
clusterService,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
createTestShardLimitService(randomIntBetween(1, 1000), clusterService),
|
||||
new Environment(Settings.builder().put("path.home", "dummy").build(), null),
|
||||
new IndexScopedSettings(ilnSetting, Collections.emptySet()),
|
||||
threadPool,
|
||||
null,
|
||||
new SystemIndices(Collections.emptyMap()),
|
||||
true
|
||||
);
|
||||
|
||||
final List<String> validationErrors = checkerService.getIndexSettingsValidationErrors(ilnSetting, true);
|
||||
assertThat(validationErrors.size(), is(1));
|
||||
assertThat(validationErrors.get(0), is("expected [index.lifecycle.name] to be private but it was not"));
|
||||
}));
|
||||
}
|
||||
|
||||
private IndexTemplateMetadata addMatchingTemplate(Consumer<IndexTemplateMetadata.Builder> configurator) {
|
||||
IndexTemplateMetadata.Builder builder = templateMetadataBuilder("template1", "te*");
|
||||
configurator.accept(builder);
|
||||
|
|
Loading…
Reference in New Issue