Class IndexTemplateRegistry

java.lang.Object
org.elasticsearch.xpack.core.template.IndexTemplateRegistry
All Implemented Interfaces:
ClusterStateListener
Direct Known Subclasses:
YamlTemplateRegistry

public abstract class IndexTemplateRegistry extends Object implements ClusterStateListener
Abstracts the logic of managing versioned index templates, ingest pipelines and lifecycle policies for plugins that require such things.
  • Field Details

  • Constructor Details

    • IndexTemplateRegistry

      public IndexTemplateRegistry(Settings nodeSettings, ClusterService clusterService, ThreadPool threadPool, Client client, org.elasticsearch.xcontent.NamedXContentRegistry xContentRegistry)
  • Method Details

    • getLifecycleConfigs

      protected List<LifecyclePolicyConfig> getLifecycleConfigs()
      Returns the configured configurations for the lifecycle policies. Subclasses should provide the ILM configurations and they will be loaded if we're not running data stream only mode (controlled via DataStreamLifecycle.DATA_STREAMS_LIFECYCLE_ONLY_SETTING_NAME). The loaded lifecycle configurations will be installed if returned by getLifecyclePolicies(). Child classes have a chance to override getLifecyclePolicies() in case they want additional control over if these policies should be installed or not (say, if they belong to functionalities that can be enabled/disabled via a flag).
      Returns:
      The lifecycle policies configurations that pertain to this template registry.
    • initialize

      public void initialize()
      Initialize the template registry, adding it as a listener so templates will be installed as necessary
    • getLegacyTemplateConfigs

      protected List<IndexTemplateConfig> getLegacyTemplateConfigs()
      Retrieves return a list of IndexTemplateConfig that represents the index templates that should be installed and managed.
      Returns:
      The configurations for the templates that should be installed.
    • getComponentTemplateConfigs

      protected Map<String,ComponentTemplate> getComponentTemplateConfigs()
      Retrieves return a list of IndexTemplateConfig that represents the component templates that should be installed and managed. Component templates are always installed prior composable templates, so they may be referenced by a composable template.
      Returns:
      The configurations for the templates that should be installed.
    • getComposableTemplateConfigs

      protected Map<String,ComposableIndexTemplate> getComposableTemplateConfigs()
      Retrieves return a list of IndexTemplateConfig that represents the composable templates that should be installed and managed.
      Returns:
      The configurations for the templates that should be installed.
    • getLifecyclePolicies

      protected List<LifecyclePolicy> getLifecyclePolicies()
      Retrieves a list of LifecyclePolicy that represents the ILM policies that should be installed and managed. Only called if ILM is enabled.
      Returns:
      The lifecycle policies that should be installed.
    • getIngestPipelines

      protected List<IngestPipelineConfig> getIngestPipelines()
      Retrieves a list of IngestPipelineConfig that represents the ingest pipelines that should be installed and managed.
      Returns:
      The configurations for ingest pipelines that should be installed.
    • getOrigin

      protected abstract String getOrigin()
      Retrieves an identifier that is used to identify which plugin is asking for this.
      Returns:
      A string ID for the plugin managing these templates.
    • onPutTemplateFailure

      protected void onPutTemplateFailure(String templateName, Exception e)
      Called when creation of an index template fails.
      Parameters:
      templateName - the template name that failed to be created.
      e - The exception that caused the failure.
    • onPutPolicyFailure

      protected void onPutPolicyFailure(LifecyclePolicy policy, Exception e)
      Called when creation of a lifecycle policy fails.
      Parameters:
      policy - The lifecycle policy that failed to be created.
      e - The exception that caused the failure.
    • clusterChanged

      public void clusterChanged(ClusterChangedEvent event)
      Specified by:
      clusterChanged in interface ClusterStateListener
    • isClusterReady

      protected boolean isClusterReady(ClusterChangedEvent event)
      A method that can be overridden to add additional conditions to be satisfied before installing the template registry components.
    • requiresMasterNode

      protected boolean requiresMasterNode()
      Whether the registry should only apply changes when running on the master node. This is useful for plugins where certain actions are performed on master nodes and the templates should match the respective version.
    • isUpgradeRequired

      protected boolean isUpgradeRequired(LifecyclePolicy currentPolicy, LifecyclePolicy newPolicy)
      Determines whether an index lifecycle policy should be upgraded to a newer version.
      Parameters:
      currentPolicy - The current lifecycle policy. Never null.
      newPolicy - The new lifecycle policy. Never null.
      Returns:
      true if newPolicy should replace currentPolicy.
    • parseComposableTemplates

      protected static Map<String,ComposableIndexTemplate> parseComposableTemplates(IndexTemplateConfig... config)
    • applyRolloverAfterTemplateV2Update

      protected boolean applyRolloverAfterTemplateV2Update()
      Allows registries to opt-in for automatic rollover of "relevant" data streams immediately after a composable index template gets updated, including its initial installation. If set to true, then every time a composable index template is being updated, all data streams of which name matches this template's index patterns AND of all matching templates the upgraded one has the highest priority, will be rolled over.
      Returns:
      true if this registry wants to apply automatic rollovers after template V2 upgrades
    • onPutPipelineFailure

      protected void onPutPipelineFailure(String pipelineId, Exception e)
      Called when creation of an ingest pipeline fails.
      Parameters:
      pipelineId - the pipeline that failed to be created.
      e - The exception that caused the failure.