Skip to content

Commit

Permalink
MAINT: enforce v1 template type in index config
Browse files Browse the repository at this point in the history
Signed-off-by: George Chen <[email protected]>
  • Loading branch information
chenqi0805 committed Aug 2, 2023
1 parent c1acf76 commit a2dd541
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class IndexConfiguration {
public static final String DOCUMENT_ROOT_KEY = "document_root_key";

private IndexType indexType;
private final TemplateType templateType;
private TemplateType templateType;
private final String indexAlias;
private final Map<String, Object> indexTemplate;
private final String documentIdField;
Expand Down Expand Up @@ -90,7 +90,7 @@ private IndexConfiguration(final Builder builder) {
this.s3AwsExternalId = builder.s3AwsStsExternalId;
this.s3Client = builder.s3Client;

this.templateType = builder.templateType != null ? builder.templateType : TemplateType.V1;
determineTemplateType(builder);
this.indexTemplate = readIndexTemplate(builder.templateFile, indexType, templateType);

if (builder.numReplicas > 0) {
Expand Down Expand Up @@ -130,6 +130,11 @@ private IndexConfiguration(final Builder builder) {
this.documentRootKey = builder.documentRootKey;
}

private void determineTemplateType(Builder builder) {
this.templateType = DistributionVersion.ES6.equals(builder.distributionVersion) ? TemplateType.V1 :
(builder.templateType != null ? builder.templateType : TemplateType.V1);
}

private void determineIndexType(Builder builder) {
if(builder.indexType != null) {
Optional<IndexType> mappedIndexType = IndexType.getByValue(builder.indexType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ public void testReadIndexConfig_es6Override() {
final Map<String, Object> metadata = initializeConfigMetaData(
null, "foo", null, null, null, null);
metadata.put(DISTRIBUTION_VERSION, "es6");
metadata.put(TEMPLATE_TYPE, TemplateType.INDEX_TEMPLATE.getTypeName());
final PluginSetting pluginSetting = getPluginSetting(metadata);
final IndexConfiguration indexConfiguration = IndexConfiguration.readIndexConfig(pluginSetting);
assertEquals(indexConfiguration.getDistributionVersion(), DistributionVersion.ES6);
assertEquals(TemplateType.V1, indexConfiguration.getTemplateType());
assertEquals(IndexType.CUSTOM, indexConfiguration.getIndexType());
}

Expand Down

0 comments on commit a2dd541

Please sign in to comment.