-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More consistent index template allow list behavior #1174
Merged
peternied
merged 6 commits into
opensearch-project:main
from
peternied:template-defaults
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cffdd6
More consistent index template allow list behavior
peternied 8bc40a0
Removeed unused logger
peternied 1ed07a8
Add log messages when index creation is skipped for the filter
peternied b0703ed
Fix broken unit test
peternied ae672d2
PR feedback
peternied 54e3c4d
Keep using allow list in end to end test cases
peternied File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 6 additions & 12 deletions
18
RFS/src/main/java/org/opensearch/migrations/bulkload/common/FilterScheme.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package org.opensearch.migrations.bulkload.version_os_2_11; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.opensearch.migrations.MigrationMode; | ||
import org.opensearch.migrations.bulkload.common.FilterScheme; | ||
import org.opensearch.migrations.bulkload.common.OpenSearchClient; | ||
import org.opensearch.migrations.bulkload.models.GlobalMetadata; | ||
import org.opensearch.migrations.metadata.CreationResult; | ||
|
@@ -35,14 +36,13 @@ public GlobalMetadataCreatorResults create( | |
log.info("Setting Global Metadata"); | ||
|
||
var results = GlobalMetadataCreatorResults.builder(); | ||
GlobalMetadataData_OS_2_11 globalMetadata = new GlobalMetadataData_OS_2_11(root.toObjectNode()); | ||
results.legacyTemplates(createLegacyTemplates(globalMetadata, mode, context)); | ||
results.componentTemplates(createComponentTemplates(globalMetadata, mode, context)); | ||
results.indexTemplates(createIndexTemplates(globalMetadata, mode, context)); | ||
results.legacyTemplates(createLegacyTemplates(root, mode, context)); | ||
results.componentTemplates(createComponentTemplates(root, mode, context)); | ||
results.indexTemplates(createIndexTemplates(root, mode, context)); | ||
return results.build(); | ||
} | ||
|
||
public List<CreationResult> createLegacyTemplates(GlobalMetadataData_OS_2_11 metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
public List<CreationResult> createLegacyTemplates(GlobalMetadata metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
return createTemplates( | ||
metadata.getTemplates(), | ||
legacyTemplateAllowlist, | ||
|
@@ -52,7 +52,7 @@ public List<CreationResult> createLegacyTemplates(GlobalMetadataData_OS_2_11 met | |
); | ||
} | ||
|
||
public List<CreationResult> createComponentTemplates(GlobalMetadataData_OS_2_11 metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
public List<CreationResult> createComponentTemplates(GlobalMetadata metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
return createTemplates( | ||
metadata.getComponentTemplates(), | ||
componentTemplateAllowlist, | ||
|
@@ -62,7 +62,7 @@ public List<CreationResult> createComponentTemplates(GlobalMetadataData_OS_2_11 | |
); | ||
} | ||
|
||
public List<CreationResult> createIndexTemplates(GlobalMetadataData_OS_2_11 metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
public List<CreationResult> createIndexTemplates(GlobalMetadata metadata, MigrationMode mode, IClusterMetadataContext context) { | ||
return createTemplates( | ||
metadata.getIndexTemplates(), | ||
indexTemplateAllowlist, | ||
|
@@ -73,7 +73,7 @@ public List<CreationResult> createIndexTemplates(GlobalMetadataData_OS_2_11 meta | |
} | ||
|
||
@AllArgsConstructor | ||
private enum TemplateTypes { | ||
enum TemplateTypes { | ||
INDEX_TEMPLATE( | ||
(targetClient, name, body, context) -> targetClient.createIndexTemplate(name, body, context.createMigrateTemplateContext()), | ||
(targetClient, name) -> targetClient.hasIndexTemplate(name) | ||
|
@@ -118,49 +118,41 @@ private List<CreationResult> createTemplates( | |
return List.of(); | ||
} | ||
|
||
if (templateAllowlist != null && templateAllowlist.isEmpty()) { | ||
log.info("No {} in specified allowlist", templateType); | ||
return List.of(); | ||
} | ||
var templatesToCreate = getAllTemplates(templates, templateType); | ||
|
||
var templatesToCreate = getTemplatesToCreate(templates, templateAllowlist, templateType); | ||
|
||
return processTemplateCreation(templatesToCreate, templateType, mode, context); | ||
return processTemplateCreation(templatesToCreate, templateType, templateAllowlist, mode, context); | ||
} | ||
|
||
private Map<String, ObjectNode> getTemplatesToCreate(ObjectNode templates, List<String> templateAllowlist, TemplateTypes templateType) { | ||
Map<String, ObjectNode> getAllTemplates(ObjectNode templates, TemplateTypes templateType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the filtering from this method because it prevented reporting templates that were not migrated. |
||
var templatesToCreate = new HashMap<String, ObjectNode>(); | ||
|
||
if (templateAllowlist != null) { | ||
for (String templateName : templateAllowlist) { | ||
if (!templates.has(templateName) || templates.get(templateName) == null) { | ||
log.warn("{} not found: {}", templateType, templateName); | ||
continue; | ||
} | ||
ObjectNode settings = (ObjectNode) templates.get(templateName); | ||
templatesToCreate.put(templateName, settings); | ||
} | ||
} else { | ||
templates.fieldNames().forEachRemaining(templateName -> { | ||
ObjectNode settings = (ObjectNode) templates.get(templateName); | ||
templatesToCreate.put(templateName, settings); | ||
}); | ||
} | ||
templates.fieldNames().forEachRemaining(templateName -> { | ||
ObjectNode settings = (ObjectNode) templates.get(templateName); | ||
templatesToCreate.put(templateName, settings); | ||
}); | ||
|
||
return templatesToCreate; | ||
} | ||
|
||
private List<CreationResult> processTemplateCreation( | ||
Map<String, ObjectNode> templatesToCreate, | ||
TemplateTypes templateType, | ||
List<String> templateAllowList, | ||
MigrationMode mode, | ||
IClusterMetadataContext context | ||
) { | ||
var skipCreation = FilterScheme.filterByAllowList(templateAllowList).negate(); | ||
|
||
List<CreationResult> templateList = new ArrayList<>(); | ||
|
||
templatesToCreate.forEach((templateName, templateBody) -> { | ||
return templatesToCreate.entrySet().stream().map((kvp) -> { | ||
var templateName = kvp.getKey(); | ||
var templateBody = kvp.getValue(); | ||
var creationResult = CreationResult.builder().name(templateName); | ||
|
||
if (skipCreation.test(templateName)) { | ||
log.atInfo().setMessage("Template {} was skipped due to allowlist filter {}").addArgument(templateName).addArgument(templateAllowList).log(); | ||
return creationResult.failureType(CreationFailureType.SKIPPED_DUE_TO_FILTER).build(); | ||
} | ||
|
||
log.info("Creating {}: {}", templateType, templateName); | ||
try { | ||
if (mode == MigrationMode.SIMULATE) { | ||
|
@@ -179,9 +171,7 @@ private List<CreationResult> processTemplateCreation( | |
creationResult.failureType(CreationFailureType.TARGET_CLUSTER_FAILURE); | ||
creationResult.exception(e); | ||
} | ||
templateList.add(creationResult.build()); | ||
}); | ||
|
||
return templateList; | ||
return creationResult.build(); | ||
}).collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the logging features, IMO much cleaner to have the source of the filter know how/when to log directly.