Module org.elasticsearch.server
Class MetadataIndexTemplateService
java.lang.Object
org.elasticsearch.cluster.metadata.MetadataIndexTemplateService
Service responsible for submitting index templates updates
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final CompressedXContentstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionMetadataIndexTemplateService(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, IndicesService indicesService, IndexScopedSettings indexScopedSettings, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, IndexSettingProviders indexSettingProviders, DataStreamGlobalRetentionSettings globalRetentionSettings) -
Method Summary
Modifier and TypeMethodDescriptionaddComponentTemplate(ProjectMetadata project, boolean create, String name, ComponentTemplate template) addIndexTemplateV2(ProjectMetadata project, boolean create, String name, ComposableIndexTemplate template) addIndexTemplateV2(ProjectMetadata project, boolean create, String name, ComposableIndexTemplate template, boolean validateV2Overlaps) static List<CompressedXContent> collectMappings(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates, String indexName) Collect the given v2 template into an ordered list of mappings.static List<CompressedXContent> collectMappings(ProjectMetadata projectMetadata, String templateName, String indexName) Collect the given v2 template into an ordered list of mappings.static DataStreamLifecycle.BuildercomposeDataLifecycles(List<DataStreamLifecycle.Template> lifecycles) This method composes a series of lifecycles to a final one.static DataStreamOptions.BuildercomposeDataStreamOptions(List<ResettableValue<DataStreamOptions.Template>> dataStreamOptionsList) This method composes a series of data streams options to a final one.findConflictingV1Templates(ProjectMetadata project, String candidateName, List<String> indexPatterns) Return a map of v1 template names to their index patterns for v1 templates that would overlap with the given v2 template's index patterns.findConflictingV2Templates(ProjectMetadata project, String candidateName, List<String> indexPatterns) Return a map of v2 template names to their index patterns for v2 templates that would overlap with the given template's index patterns.static List<IndexTemplateMetadata> findV1Templates(ProjectMetadata projectMetadata, String indexName, Boolean isHidden) Finds index templates whose index pattern matched with the given index name.static StringfindV2Template(ProjectMetadata projectMetadata, String indexName, boolean isHidden) Return the name (id) of the highest matching index template for the given index name.static StringfindV2TemplateFromSortedList(ProjectMetadata projectMetadata, Collection<Map.Entry<String, ComposableIndexTemplate>> templates, String indexName, boolean isHidden) Return the name (id) of the highest matching index template out of the provided templates (that need to be sorted descending on priority beforehand), or the given index name.static ProjectMetadatainnerRemoveComponentTemplate(ProjectMetadata project, String... names) static ProjectMetadatainnerRemoveIndexTemplateV2(ProjectMetadata project, String... names) voidputComponentTemplate(String cause, boolean create, String name, TimeValue masterTimeout, ComponentTemplate template, ProjectId projectId, ActionListener<AcknowledgedResponse> listener) Add the given component template to the cluster state.voidputIndexTemplateV2(String cause, boolean create, String name, TimeValue masterTimeout, ComposableIndexTemplate template, ProjectId projectId, ActionListener<AcknowledgedResponse> listener) Add the given index template to the cluster state.voidputTemplate(ProjectId projectId, MetadataIndexTemplateService.PutRequest request, TimeValue timeout, ActionListener<AcknowledgedResponse> listener) voidremoveComponentTemplate(String[] names, TimeValue masterTimeout, ProjectMetadata project, ActionListener<AcknowledgedResponse> listener) Remove the given component template from the cluster state.voidremoveIndexTemplateV2(ProjectId projectId, String[] names, TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener) Remove the given index template from the cluster state.voidremoveTemplates(ProjectId projectId, String templatePattern, TimeValue timeout, ActionListener<AcknowledgedResponse> listener) static List<Map<String, AliasMetadata>> resolveAliases(List<IndexTemplateMetadata> templates) Resolve the given v1 templates into an ordered list of aliasesstatic List<Map<String, AliasMetadata>> resolveAliases(ProjectMetadata projectMetadata, String templateName) Resolve the given v2 template name into an ordered list of aliasesstatic DataStreamOptions.BuilderresolveDataStreamOptions(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamOptions.Builderobject that can be built to either aDataStreamOptionsor the equivalentDataStreamOptions.Template.static DataStreamOptions.BuilderresolveDataStreamOptions(ProjectMetadata projectMetadata, String templateName) Resolve the given v2 template into aDataStreamOptions.Builderobject that can be built to either aDataStreamOptionsor the equivalentDataStreamOptions.Template.static DataStreamLifecycle.BuilderresolveLifecycle(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamLifecycleobjectstatic DataStreamLifecycle.BuilderresolveLifecycle(ProjectMetadata metadata, String templateName) Resolve the given v2 template into aDataStreamLifecycleobjectstatic SettingsresolveSettings(List<IndexTemplateMetadata> templates) Resolve index settings for the given list of v1 templates, templates are apply in reverse order since they should be provided in order of priority/orderstatic SettingsresolveSettings(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into a collectedSettingsobjectstatic SettingsresolveSettings(ProjectMetadata projectMetadata, String templateName) Resolve the given v2 template into a collectedSettingsobjectv2TemplateOverlaps(Map<String, ComposableIndexTemplate> templatesV2, String name, ComposableIndexTemplate template, boolean validate) Calculates the conflicting v2 index template overlaps for a given composable index template.voidvalidate(String name, ComponentTemplate template) static voidvalidateTemplate(Settings validateSettings, CompressedXContent mappings, IndicesService indicesService) static voidvalidateV2TemplateRequest(Map<String, ComponentTemplate> componentTemplates, String name, ComposableIndexTemplate template) static voidvalidateV2TemplateRequest(ProjectMetadata metadata, String name, ComposableIndexTemplate template) static CompressedXContentwrapMappingsIfNecessary(CompressedXContent mappings, NamedXContentRegistry xContentRegistry) Mappings in templates don't have to include_doc, so update the mappings to include this single type if necessary
-
Field Details
-
DEFAULT_TIMESTAMP_FIELD
- See Also:
-
DEFAULT_TIMESTAMP_MAPPING_WITHOUT_ROUTING
-
VALIDATE_INDEX_NAME
- See Also:
-
VALIDATE_DATA_STREAM_NAME
- See Also:
-
-
Constructor Details
-
MetadataIndexTemplateService
@Inject public MetadataIndexTemplateService(ClusterService clusterService, MetadataCreateIndexService metadataCreateIndexService, IndicesService indicesService, IndexScopedSettings indexScopedSettings, NamedXContentRegistry xContentRegistry, SystemIndices systemIndices, IndexSettingProviders indexSettingProviders, DataStreamGlobalRetentionSettings globalRetentionSettings)
-
-
Method Details
-
removeTemplates
public void removeTemplates(ProjectId projectId, String templatePattern, TimeValue timeout, ActionListener<AcknowledgedResponse> listener) -
putComponentTemplate
public void putComponentTemplate(String cause, boolean create, String name, TimeValue masterTimeout, ComponentTemplate template, ProjectId projectId, ActionListener<AcknowledgedResponse> listener) Add the given component template to the cluster state. Ifcreateis true, an exception will be thrown if the component template already exists -
addComponentTemplate
public ProjectMetadata addComponentTemplate(ProjectMetadata project, boolean create, String name, ComponentTemplate template) throws Exception - Throws:
Exception
-
wrapMappingsIfNecessary
@Nullable public static CompressedXContent wrapMappingsIfNecessary(@Nullable CompressedXContent mappings, NamedXContentRegistry xContentRegistry) throws IOException Mappings in templates don't have to include_doc, so update the mappings to include this single type if necessary- Parameters:
mappings- mappings from a templatexContentRegistry- the xcontent registry used for parsing- Returns:
- a normalized form of the mapping provided
- Throws:
IOException- if reading or writing the mapping encounters a problem
-
removeComponentTemplate
public void removeComponentTemplate(String[] names, TimeValue masterTimeout, ProjectMetadata project, ActionListener<AcknowledgedResponse> listener) Remove the given component template from the cluster state. The component template name supports simple regex wildcards for removing multiple component templates at a time. -
innerRemoveComponentTemplate
public static ProjectMetadata innerRemoveComponentTemplate(ProjectMetadata project, String... names) -
putIndexTemplateV2
public void putIndexTemplateV2(String cause, boolean create, String name, TimeValue masterTimeout, ComposableIndexTemplate template, ProjectId projectId, ActionListener<AcknowledgedResponse> listener) Add the given index template to the cluster state. Ifcreateis true, an exception will be thrown if the component template already exists -
validateV2TemplateRequest
public static void validateV2TemplateRequest(ProjectMetadata metadata, String name, ComposableIndexTemplate template) -
validateV2TemplateRequest
public static void validateV2TemplateRequest(Map<String, ComponentTemplate> componentTemplates, String name, ComposableIndexTemplate template) -
addIndexTemplateV2
public ProjectMetadata addIndexTemplateV2(ProjectMetadata project, boolean create, String name, ComposableIndexTemplate template) throws Exception - Throws:
Exception
-
addIndexTemplateV2
public ProjectMetadata addIndexTemplateV2(ProjectMetadata project, boolean create, String name, ComposableIndexTemplate template, boolean validateV2Overlaps) throws Exception - Throws:
Exception
-
v2TemplateOverlaps
public static Map<String,List<String>> v2TemplateOverlaps(Map<String, ComposableIndexTemplate> templatesV2, String name, ComposableIndexTemplate template, boolean validate) Calculates the conflicting v2 index template overlaps for a given composable index template. Optionally if validate is true we throw anIllegalArgumentExceptionwith information about the conflicting templates.This method doesn't check for conflicting overlaps with v1 templates.
- Parameters:
templatesV2- the templates to check overlap againstname- the composable index template nametemplate- the full composable index template object we check for overlapsvalidate- should we throwIllegalArgumentExceptionif conflicts are found or just compute them- Returns:
- a map of v2 template names to their index patterns for v2 templates that would overlap with the given template
-
findConflictingV1Templates
public static Map<String,List<String>> findConflictingV1Templates(ProjectMetadata project, String candidateName, List<String> indexPatterns) Return a map of v1 template names to their index patterns for v1 templates that would overlap with the given v2 template's index patterns. -
findConflictingV2Templates
public static Map<String,List<String>> findConflictingV2Templates(ProjectMetadata project, String candidateName, List<String> indexPatterns) Return a map of v2 template names to their index patterns for v2 templates that would overlap with the given template's index patterns. -
removeIndexTemplateV2
public void removeIndexTemplateV2(ProjectId projectId, String[] names, TimeValue masterTimeout, ActionListener<AcknowledgedResponse> listener) Remove the given index template from the cluster state. The index template name supports simple regex wildcards for removing multiple index templates at a time. -
innerRemoveIndexTemplateV2
-
putTemplate
public void putTemplate(ProjectId projectId, MetadataIndexTemplateService.PutRequest request, TimeValue timeout, ActionListener<AcknowledgedResponse> listener) -
findV1Templates
public static List<IndexTemplateMetadata> findV1Templates(ProjectMetadata projectMetadata, String indexName, @Nullable Boolean isHidden) Finds index templates whose index pattern matched with the given index name. In the case of hidden indices, a template with a match all pattern or global template will not be returned.- Parameters:
projectMetadata- TheProjectMetadatacontaining all of theIndexTemplateMetadatavaluesindexName- The name of the index that templates are being found forisHidden- Whether or not the index is known to be hidden. May benullif the index being hidden has not been explicitly requested. Whennullif the result of template application results in a hidden index, then global templates will not be returned- Returns:
- a list of templates sorted by
IndexTemplateMetadata.order()descending.
-
findV2Template
@Nullable public static String findV2Template(ProjectMetadata projectMetadata, String indexName, boolean isHidden) Return the name (id) of the highest matching index template for the given index name. In the event that no templates are matched,nullis returned. -
findV2TemplateFromSortedList
@Nullable public static String findV2TemplateFromSortedList(ProjectMetadata projectMetadata, Collection<Map.Entry<String, ComposableIndexTemplate>> templates, String indexName, boolean isHidden) Return the name (id) of the highest matching index template out of the provided templates (that need to be sorted descending on priority beforehand), or the given index name. In the event that no templates are matched,nullis returned. -
collectMappings
public static List<CompressedXContent> collectMappings(ProjectMetadata projectMetadata, String templateName, String indexName) Collect the given v2 template into an ordered list of mappings. -
collectMappings
public static List<CompressedXContent> collectMappings(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates, String indexName) Collect the given v2 template into an ordered list of mappings. -
resolveSettings
Resolve index settings for the given list of v1 templates, templates are apply in reverse order since they should be provided in order of priority/order -
resolveSettings
Resolve the given v2 template into a collectedSettingsobject -
resolveSettings
public static Settings resolveSettings(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into a collectedSettingsobject -
resolveAliases
Resolve the given v1 templates into an ordered list of aliases -
resolveAliases
public static List<Map<String,AliasMetadata>> resolveAliases(ProjectMetadata projectMetadata, String templateName) Resolve the given v2 template name into an ordered list of aliases -
resolveLifecycle
@Nullable public static DataStreamLifecycle.Builder resolveLifecycle(ProjectMetadata metadata, String templateName) Resolve the given v2 template into aDataStreamLifecycleobject -
resolveLifecycle
@Nullable public static DataStreamLifecycle.Builder resolveLifecycle(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamLifecycleobject -
composeDataLifecycles
@Nullable public static DataStreamLifecycle.Builder composeDataLifecycles(List<DataStreamLifecycle.Template> lifecycles) This method composes a series of lifecycles to a final one. The lifecycles are getting composed one level deep, meaning that the keys present on the latest lifecycle will override the ones of the others. If a key is missing then it keeps the value of the previous lifecycles. For example, if we have the following two lifecycles: [ { "lifecycle": { "enabled": true, "data_retention" : "10d" } }, { "lifecycle": { "enabled": true, "data_retention" : "20d" } } ] The result will be { "lifecycle": { "enabled": true, "data_retention" : "20d"}} because the second data retention overrides the first. However, if we have the following two lifecycles: [ { "lifecycle": { "enabled": false, "data_retention" : "10d" } }, { "lifecycle": { "enabled": true } } ] The result will be { "lifecycle": { "enabled": true, "data_retention" : "10d"} } because the latest lifecycle does not have any information on retention.- Parameters:
lifecycles- a sorted list of lifecycles in the order that they will be composed- Returns:
- the builder that will build the final lifecycle or the template
-
resolveDataStreamOptions
@Nullable public static DataStreamOptions.Builder resolveDataStreamOptions(ProjectMetadata projectMetadata, String templateName) Resolve the given v2 template into aDataStreamOptions.Builderobject that can be built to either aDataStreamOptionsor the equivalentDataStreamOptions.Template. -
resolveDataStreamOptions
@Nullable public static DataStreamOptions.Builder resolveDataStreamOptions(ComposableIndexTemplate template, Map<String, ComponentTemplate> componentTemplates) Resolve the provided v2 template and component templates into aDataStreamOptions.Builderobject that can be built to either aDataStreamOptionsor the equivalentDataStreamOptions.Template. -
composeDataStreamOptions
@Nullable public static DataStreamOptions.Builder composeDataStreamOptions(List<ResettableValue<DataStreamOptions.Template>> dataStreamOptionsList) This method composes a series of data streams options to a final one.- Parameters:
dataStreamOptionsList- a sorted list of data stream options in the order that they will be composed- Returns:
- the final data stream option configuration
-
validateTemplate
public static void validateTemplate(Settings validateSettings, CompressedXContent mappings, IndicesService indicesService) throws Exception - Throws:
Exception
-
validate
-