@@ -430,8 +430,16 @@ public ProjectMetadata addComponentTemplate(
430
430
return ProjectMetadata .builder (project ).put (name , finalComponentTemplate ).build ();
431
431
}
432
432
433
+ /**
434
+ * Mappings in templates don't have to include <code>_doc</code>, so update the mappings to include this single type if necessary
435
+ *
436
+ * @param mappings mappings from a template
437
+ * @param xContentRegistry the xcontent registry used for parsing
438
+ * @return a normalized form of the mapping provided
439
+ * @throws IOException if reading or writing the mapping encounters a problem
440
+ */
433
441
@ Nullable
434
- private static CompressedXContent wrapMappingsIfNecessary (@ Nullable CompressedXContent mappings , NamedXContentRegistry xContentRegistry )
442
+ public static CompressedXContent wrapMappingsIfNecessary (@ Nullable CompressedXContent mappings , NamedXContentRegistry xContentRegistry )
435
443
throws IOException {
436
444
// Mappings in templates don't have to include _doc, so update
437
445
// the mappings to include this single type if necessary
@@ -593,14 +601,22 @@ public ProjectMetadata execute(ProjectMetadata currentProject) throws Exception
593
601
}
594
602
595
603
public static void validateV2TemplateRequest (ProjectMetadata metadata , String name , ComposableIndexTemplate template ) {
604
+ validateV2TemplateRequest (metadata .componentTemplates (), name , template );
605
+ }
606
+
607
+ public static void validateV2TemplateRequest (
608
+ Map <String , ComponentTemplate > componentTemplates ,
609
+ String name ,
610
+ ComposableIndexTemplate template
611
+ ) {
596
612
if (template .createdDateMillis ().isPresent ()) {
597
613
throw new InvalidIndexTemplateException (name , "provided a template property which is managed by the system: created_date" );
598
614
}
599
615
if (template .modifiedDateMillis ().isPresent ()) {
600
616
throw new InvalidIndexTemplateException (name , "provided a template property which is managed by the system: modified_date" );
601
617
}
602
618
if (template .indexPatterns ().stream ().anyMatch (Regex ::isMatchAllPattern )) {
603
- Settings mergedSettings = resolveSettings (template , metadata . componentTemplates () );
619
+ Settings mergedSettings = resolveSettings (template , componentTemplates );
604
620
if (IndexMetadata .INDEX_HIDDEN_SETTING .exists (mergedSettings )) {
605
621
throw new InvalidIndexTemplateException (
606
622
name ,
@@ -609,7 +625,6 @@ public static void validateV2TemplateRequest(ProjectMetadata metadata, String na
609
625
}
610
626
}
611
627
612
- final Map <String , ComponentTemplate > componentTemplates = metadata .componentTemplates ();
613
628
final List <String > ignoreMissingComponentTemplates = (template .getIgnoreMissingComponentTemplates () == null
614
629
? List .of ()
615
630
: template .getIgnoreMissingComponentTemplates ());
@@ -661,7 +676,7 @@ public ProjectMetadata addIndexTemplateV2(
661
676
throw new IllegalArgumentException ("index template [" + name + "] already exists" );
662
677
}
663
678
664
- Map <String , List <String >> overlaps = v2TemplateOverlaps (project , name , template , validateV2Overlaps );
679
+ Map <String , List <String >> overlaps = v2TemplateOverlaps (project . templatesV2 () , name , template , validateV2Overlaps );
665
680
666
681
overlaps = findConflictingV1Templates (project , name , template .indexPatterns ());
667
682
if (overlaps .size () > 0 ) {
@@ -725,20 +740,20 @@ public ProjectMetadata addIndexTemplateV2(
725
740
* we throw an {@link IllegalArgumentException} with information about the conflicting templates.
726
741
* <p>
727
742
* This method doesn't check for conflicting overlaps with v1 templates.
728
- * @param project the current project
743
+ * @param templatesV2 the templates to check overlap against
729
744
* @param name the composable index template name
730
745
* @param template the full composable index template object we check for overlaps
731
746
* @param validate should we throw {@link IllegalArgumentException} if conflicts are found or just compute them
732
747
* @return a map of v2 template names to their index patterns for v2 templates that would overlap with the given template
733
748
*/
734
749
public static Map <String , List <String >> v2TemplateOverlaps (
735
- final ProjectMetadata project ,
750
+ Map < String , ComposableIndexTemplate > templatesV2 ,
736
751
String name ,
737
752
final ComposableIndexTemplate template ,
738
753
boolean validate
739
754
) {
740
755
Map <String , List <String >> overlaps = findConflictingV2Templates (
741
- project ,
756
+ templatesV2 ,
742
757
name ,
743
758
template .indexPatterns (),
744
759
true ,
@@ -1028,7 +1043,7 @@ public static Map<String, List<String>> findConflictingV2Templates(
1028
1043
final String candidateName ,
1029
1044
final List <String > indexPatterns
1030
1045
) {
1031
- return findConflictingV2Templates (project , candidateName , indexPatterns , false , 0L );
1046
+ return findConflictingV2Templates (project . templatesV2 () , candidateName , indexPatterns , false , 0L );
1032
1047
}
1033
1048
1034
1049
/**
@@ -1042,15 +1057,15 @@ public static Map<String, List<String>> findConflictingV2Templates(
1042
1057
* index templates with the same priority).
1043
1058
*/
1044
1059
static Map <String , List <String >> findConflictingV2Templates (
1045
- final ProjectMetadata project ,
1060
+ final Map < String , ComposableIndexTemplate > templatesV2 ,
1046
1061
final String candidateName ,
1047
1062
final List <String > indexPatterns ,
1048
1063
boolean checkPriority ,
1049
1064
long priority
1050
1065
) {
1051
1066
Automaton v1automaton = Regex .simpleMatchToAutomaton (indexPatterns .toArray (Strings .EMPTY_ARRAY ));
1052
1067
Map <String , List <String >> overlappingTemplates = new TreeMap <>();
1053
- for (Map .Entry <String , ComposableIndexTemplate > entry : project . templatesV2 () .entrySet ()) {
1068
+ for (Map .Entry <String , ComposableIndexTemplate > entry : templatesV2 .entrySet ()) {
1054
1069
String name = entry .getKey ();
1055
1070
ComposableIndexTemplate template = entry .getValue ();
1056
1071
Automaton v2automaton = Regex .simpleMatchToAutomaton (template .indexPatterns ().toArray (Strings .EMPTY_ARRAY ));
@@ -1993,7 +2008,8 @@ private static void validateCompositeTemplate(
1993
2008
});
1994
2009
}
1995
2010
1996
- static void validateTemplate (Settings validateSettings , CompressedXContent mappings , IndicesService indicesService ) throws Exception {
2011
+ public static void validateTemplate (Settings validateSettings , CompressedXContent mappings , IndicesService indicesService )
2012
+ throws Exception {
1997
2013
// Hard to validate settings if they're non-existent, so used empty ones if none were provided
1998
2014
Settings settings = validateSettings ;
1999
2015
if (settings == null ) {
@@ -2024,7 +2040,7 @@ static void validateTemplate(Settings validateSettings, CompressedXContent mappi
2024
2040
});
2025
2041
}
2026
2042
2027
- private void validate (String name , ComponentTemplate template ) {
2043
+ public void validate (String name , ComponentTemplate template ) {
2028
2044
validate (name , template .template (), Collections .emptyList ());
2029
2045
}
2030
2046
0 commit comments