Skip to content

Commit d556c75

Browse files
committed
Avoid crashing on using the index.lifecycle.name in the API body (opensearch-project#1060)
* Avoid crashing on using the index.lifecycle.name in the API body Signed-off-by: frotsch <[email protected]>
1 parent a7ad3f7 commit d556c75

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,10 @@ private static List<String> validatePrivateSettingsNotExplicitlySet(Settings set
10441044
for (final String key : settings.keySet()) {
10451045
final Setting<?> setting = indexScopedSettings.get(key);
10461046
if (setting == null) {
1047-
assert indexScopedSettings.isPrivateSetting(key) : "expected [" + key + "] to be private but it was not";
1047+
// see: https://github.com/opensearch-project/OpenSearch/issues/1019
1048+
if(!indexScopedSettings.isPrivateSetting(key)) {
1049+
validationErrors.add("expected [" + key + "] to be private but it was not");
1050+
}
10481051
} else if (setting.isPrivateIndex()) {
10491052
validationErrors.add("private index setting [" + key + "] can not be set explicitly");
10501053
}

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

+26
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.opensearch.common.util.BigArrays;
6767
import org.opensearch.common.xcontent.NamedXContentRegistry;
6868
import org.opensearch.common.xcontent.XContentFactory;
69+
import org.opensearch.env.Environment;
6970
import org.opensearch.index.Index;
7071
import org.opensearch.index.IndexNotFoundException;
7172
import org.opensearch.index.IndexSettings;
@@ -963,6 +964,31 @@ null, Settings.EMPTY, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, randomShardLi
963964
+ "and [index.translog.retention.size] are deprecated and effectively ignored. They will be removed in a future version.");
964965
}
965966

967+
public void testIndexLifecycleNameSetting() {
968+
// see: https://github.com/opensearch-project/OpenSearch/issues/1019
969+
final Settings ilnSetting = Settings.builder().put("index.lifecycle.name", "dummy").build();
970+
withTemporaryClusterService(((clusterService, threadPool) -> {
971+
MetadataCreateIndexService checkerService = new MetadataCreateIndexService(
972+
Settings.EMPTY,
973+
clusterService,
974+
null,
975+
null,
976+
null,
977+
createTestShardLimitService(randomIntBetween(1, 1000), clusterService),
978+
new Environment(Settings.builder().put("path.home", "dummy").build(), null),
979+
new IndexScopedSettings(ilnSetting, Collections.emptySet()),
980+
threadPool,
981+
null,
982+
new SystemIndices(Collections.emptyMap()),
983+
true
984+
);
985+
986+
final List<String> validationErrors = checkerService.getIndexSettingsValidationErrors(ilnSetting, true);
987+
assertThat(validationErrors.size(), is(1));
988+
assertThat(validationErrors.get(0), is("expected [index.lifecycle.name] to be private but it was not"));
989+
}));
990+
}
991+
966992
private IndexTemplateMetadata addMatchingTemplate(Consumer<IndexTemplateMetadata.Builder> configurator) {
967993
IndexTemplateMetadata.Builder builder = templateMetadataBuilder("template1", "te*");
968994
configurator.accept(builder);

0 commit comments

Comments
 (0)