Class: ElasticGraph::Admin::IndexDefinitionConfigurator::ForIndexTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb

Overview

Responsible for managing an index template’s configuration, including both mappings and settings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datastore_client, index_template, env_agnostic_index_config_parent, output, clock) ⇒ ForIndexTemplate

Returns a new instance of ForIndexTemplate.



24
25
26
27
28
29
30
31
32
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb', line 24

def initialize(datastore_client, index_template, env_agnostic_index_config_parent, output, clock)
  @datastore_client = datastore_client
  @index_template = index_template
  @env_agnostic_index_config_parent = env_agnostic_index_config_parent
  @env_agnostic_index_config = env_agnostic_index_config_parent.fetch("template")
  @reporter = ClusterConfigurator::ActionReporter.new(output)
  @output = output
  @clock = clock
end

Instance Attribute Details

#index_templateObject (readonly)

Returns the value of attribute index_template.



22
23
24
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb', line 22

def index_template
  @index_template
end

Instance Method Details

#configure!Object

Attempts to idempotently update the index configuration to the desired configuration exposed by the ‘IndexDefinition` object. Based on the configuration of the passed index and the state of the index in the datastore, does one of the following:

- If the index did not already exist: creates the index with the desired mappings and settings.
- If the desired mapping has fewer fields than what is in the index: raises an exception,
  because the datastore provides no way to remove fields from a mapping and it would be confusing
  for this method to silently ignore the issue.
- If the settings have desired changes: updates the settings, restoring any setting that
  no longer has a desired value to its default.
- If the mapping has desired changes: updates the mappings.

Note that any of the writes to the index may fail. There are many things that cannot be changed on an existing index (such as static settings, field mapping types, etc). We do not attempt to validate those things ahead of time and instead rely on the datastore to fail if an invalid operation is attempted.



50
51
52
53
54
55
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb', line 50

def configure!
  related_index_configurators.each(&:configure!)

  # there is no partial update for index template config and the same API both creates and updates it
  put_index_template if has_mapping_updates? || settings_updates.any?
end

#validateObject



57
58
59
60
61
62
63
64
65
# File 'lib/elastic_graph/admin/index_definition_configurator/for_index_template.rb', line 57

def validate
  errors = related_index_configurators.flat_map(&:validate)

  return errors unless index_template_exists?

  errors << cannot_modify_mapping_field_type_error if mapping_type_changes.any?

  errors
end