Skip to content

Commit b7855d5

Browse files
committed
[API] Updates freeze and unfreeze indices endpoints
1 parent 41e711a commit b7855d5

File tree

4 files changed

+60
-40
lines changed

4 files changed

+60
-40
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/indices/freeze.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,47 @@ module Elasticsearch
1919
module API
2020
module Indices
2121
module Actions
22-
# In order to keep indices available and queryable for a longer period but at the same time reduce their
23-
# hardware requirements they can be transitioned into a frozen state. Once an index is frozen, all of its
24-
# transient shard memory (aside from mappings and analyzers) is moved to persistent storage.
22+
# Freezes an index. A frozen index has almost no overhead on the cluster (except for maintaining its metadata in memory) and is read-only.
2523
#
26-
# @option arguments [List] :index A comma separated list of indices to freeze. (*Required*)
24+
# @option arguments [String] :index The name of the index to freeze
25+
# @option arguments [Time] :timeout Explicit operation timeout
26+
# @option arguments [Time] :master_timeout Specify timeout for connection to master
27+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
28+
# @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
29+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
30+
# @option arguments [String] :wait_for_active_shards Sets the number of active shards to wait for before the operation returns.
31+
# @option arguments [Hash] :headers Custom HTTP headers
2732
#
28-
# @note This feature is available in the Platinum distribution of Elasticsearch.
29-
#
30-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen-indices.html
33+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/freeze-index-api.html
3134
#
3235
def freeze(arguments = {})
3336
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
3437

35-
valid_params = [
36-
:timeout,
37-
:master_timeout,
38-
:ignore_unavailable,
39-
:allow_no_indices,
40-
:expand_wildcards,
41-
:wait_for_active_shards
42-
]
38+
headers = arguments.delete(:headers) || {}
4339

4440
arguments = arguments.clone
45-
index = arguments.delete(:index)
41+
42+
_index = arguments.delete(:index)
4643

4744
method = Elasticsearch::API::HTTP_POST
48-
path = Elasticsearch::API::Utils.__pathify Elasticsearch::API::Utils.__listify(index), '_freeze'
49-
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, valid_params
45+
path = "#{Utils.__listify(_index)}/_freeze"
46+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
5047

51-
perform_request(method, path, params).body
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
5250
end
51+
52+
# Register this action with its valid params when the module is loaded.
53+
#
54+
# @since 6.2.0
55+
ParamsRegistry.register(:freeze, [
56+
:timeout,
57+
:master_timeout,
58+
:ignore_unavailable,
59+
:allow_no_indices,
60+
:expand_wildcards,
61+
:wait_for_active_shards
62+
].freeze)
5363
end
5464
end
5565
end

elasticsearch-api/lib/elasticsearch/api/actions/indices/unfreeze.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,47 @@ module Elasticsearch
1919
module API
2020
module Indices
2121
module Actions
22-
# In order to keep indices available and queryable for a longer period but at the same time reduce their
23-
# hardware requirements they can be transitioned into a frozen state. Once an index is frozen, all of its
24-
# transient shard memory (aside from mappings and analyzers) is moved to persistent storage.
22+
# Unfreezes an index. When a frozen index is unfrozen, the index goes through the normal recovery process and becomes writeable again.
2523
#
26-
# @option arguments [List] :index A comma separated list of indices to unfreeze. (*Required*)
24+
# @option arguments [String] :index The name of the index to unfreeze
25+
# @option arguments [Time] :timeout Explicit operation timeout
26+
# @option arguments [Time] :master_timeout Specify timeout for connection to master
27+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
28+
# @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
29+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
30+
# @option arguments [String] :wait_for_active_shards Sets the number of active shards to wait for before the operation returns.
31+
# @option arguments [Hash] :headers Custom HTTP headers
2732
#
28-
# @note This feature is available in the Platinum distribution of Elasticsearch.
29-
#
30-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen-indices.html
33+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/unfreeze-index-api.html
3134
#
3235
def unfreeze(arguments = {})
3336
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
3437

35-
valid_params = [
36-
:timeout,
37-
:master_timeout,
38-
:ignore_unavailable,
39-
:allow_no_indices,
40-
:expand_wildcards,
41-
:wait_for_active_shards
42-
]
38+
headers = arguments.delete(:headers) || {}
4339

4440
arguments = arguments.clone
45-
index = arguments.delete(:index)
41+
42+
_index = arguments.delete(:index)
4643

4744
method = Elasticsearch::API::HTTP_POST
48-
path = Elasticsearch::API::Utils.__pathify Elasticsearch::API::Utils.__listify(index), '_unfreeze'
49-
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, valid_params
45+
path = "#{Utils.__listify(_index)}/_unfreeze"
46+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
5047

51-
perform_request(method, path, params).body
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
5250
end
51+
52+
# Register this action with its valid params when the module is loaded.
53+
#
54+
# @since 6.2.0
55+
ParamsRegistry.register(:unfreeze, [
56+
:timeout,
57+
:master_timeout,
58+
:ignore_unavailable,
59+
:allow_no_indices,
60+
:expand_wildcards,
61+
:wait_for_active_shards
62+
].freeze)
5363
end
5464
end
5565
end

elasticsearch-api/spec/elasticsearch/api/actions/indices/freeze_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
url,
2626
params,
2727
nil,
28-
nil
28+
{}
2929
]
3030
end
3131

elasticsearch-api/spec/elasticsearch/api/actions/indices/unfreeze_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
url,
2626
params,
2727
nil,
28-
nil
28+
{}
2929
]
3030
end
3131

0 commit comments

Comments
 (0)