Class: ElasticGraph::Admin::ClusterConfigurator
- Inherits:
-
Object
- Object
- ElasticGraph::Admin::ClusterConfigurator
- Defined in:
- lib/elastic_graph/admin/cluster_configurator.rb,
lib/elastic_graph/admin/cluster_configurator/action_reporter.rb,
lib/elastic_graph/admin/cluster_configurator/script_configurator.rb,
lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb
Overview
Facade responsible for overall cluster configuration. Delegates to other classes as necessary to configure different aspects of the cluster (such as index configuration, cluster settings, etc).
Defined Under Namespace
Classes: ActionReporter, ClusterSettingsManager, ScriptConfigurator
Instance Method Summary collapse
- #accessible_index_definitions ⇒ Object
-
#configure_cluster(output) ⇒ Object
Attempts to configure all aspects of the datastore cluster.
-
#initialize(datastore_clients_by_name:, index_defs:, index_configurations_by_name:, index_template_configurations_by_name:, scripts:, cluster_settings_manager:, clock:) ⇒ ClusterConfigurator
constructor
A new instance of ClusterConfigurator.
Constructor Details
#initialize(datastore_clients_by_name:, index_defs:, index_configurations_by_name:, index_template_configurations_by_name:, scripts:, cluster_settings_manager:, clock:) ⇒ ClusterConfigurator
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elastic_graph/admin/cluster_configurator.rb', line 20 def initialize( datastore_clients_by_name:, index_defs:, index_configurations_by_name:, index_template_configurations_by_name:, scripts:, cluster_settings_manager:, clock: ) @datastore_clients_by_name = datastore_clients_by_name @index_defs = index_defs @index_configurations_by_name = index_configurations_by_name.merge(index_template_configurations_by_name) @scripts_by_id = scripts @cluster_settings_manager = cluster_settings_manager @clock = clock end |
Instance Method Details
#accessible_index_definitions ⇒ Object
68 69 70 |
# File 'lib/elastic_graph/admin/cluster_configurator.rb', line 68 def accessible_index_definitions @accessible_index_definitions ||= @index_defs.reject { |i| i.all_accessible_cluster_names.empty? } end |
#configure_cluster(output) ⇒ Object
Attempts to configure all aspects of the datastore cluster. Known/expected failure cases are pre-validated so that an error can be raised before applying any changes to any indices, so that we hopefully don’t wind up in a “partially configured” state.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elastic_graph/admin/cluster_configurator.rb', line 40 def configure_cluster(output) # Note: we do not want to cache `index_configurators_for` here in a variable, because it's important # for our tests that different instances are used for `validate` vs `configure!`. That's the case because # each `index_configurator` memoizes some datastore responses (e.g. when it fetches the settings or # mappings for an index...). In our tests, we use different datastore clients that connect to the same # datastore server, and that means that when we reuse the same `index_configurator`, the datastore # index winds up being mutated (via another client) in between `validate` and `configure!` breaking assumptions # of the datastore response memoization. By using different index configurators for the two steps it # avoids some odd bugs. script_configurators = script_configurators_for(output) errors = script_configurators.flat_map(&:validate) + index_definition_configurators_for(output).flat_map(&:validate) if errors.any? error_descriptions = errors.map.with_index do |error, index| "#{index + 1}): #{error}" end.join("\n#{"=" * 80}\n\n") raise Errors::ClusterOperationError, "Got #{errors.size} validation error(s):\n\n#{error_descriptions}" end script_configurators.each(&:configure!) @cluster_settings_manager.in_index_maintenance_mode(:all_clusters) do index_definition_configurators_for(output).each(&:configure!) end end |