Skip to content

Commit 2df6a00

Browse files
cosmo0920estolfo
authored andcommitted
[XPACK] Support Index Lifecycle Management(ILM) API
1 parent 5f2e39e commit 2df6a00

File tree

23 files changed

+759
-1
lines changed

23 files changed

+759
-1
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Client
2727
end
2828
end
2929

30-
Elasticsearch::API::COMMON_PARAMS.push :job_id, :datafeed_id, :filter_id, :snapshot_id, :category_id
30+
Elasticsearch::API::COMMON_PARAMS.push :job_id, :datafeed_id, :filter_id, :snapshot_id, :category_id, :policy_id
3131

3232
module Elasticsearch
3333
module Transport
@@ -71,6 +71,10 @@ def deprecation
7171
def data_frame
7272
@data_frame ||= xpack.data_frame
7373
end
74+
75+
def ilm
76+
@ilm ||= xpack.ilm
77+
end
7478
end
7579
end
7680
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Deletes a lifecycle policy
12+
#
13+
# @option arguments [String] :policy_id Identifier for the policy
14+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
15+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete-lifecycle.html
18+
#
19+
def delete_policy(arguments={})
20+
raise ArgumentError, "Required argument 'policy_id' missing" unless arguments[:policy_id]
21+
method = Elasticsearch::API::HTTP_DELETE
22+
path = Elasticsearch::API::Utils.__pathify "_ilm/policy",
23+
Elasticsearch::API::Utils.__escape(arguments[:policy_id])
24+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
25+
body = nil
26+
27+
perform_request(method, path, params, body).body
28+
end
29+
30+
# Register this action with its valid params when the module is loaded.
31+
#
32+
ParamsRegistry.register(:delete_policy, [ :master_timeout,
33+
:timeout ].freeze)
34+
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Shows an index’s current lifecycle status
12+
#
13+
# @option arguments [String] :index The target index (*Required*)
14+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
15+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html
18+
#
19+
def explain(arguments={})
20+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
21+
index = Elasticsearch::API::Utils.__escape(arguments.delete(:index))
22+
23+
method = Elasticsearch::API::HTTP_GET
24+
path = Elasticsearch::API::Utils.__pathify index, "_ilm/explain"
25+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
26+
body = nil
27+
28+
perform_request(method, path, params, body).body
29+
end
30+
31+
# Register this action with its valid params when the module is loaded.
32+
#
33+
ParamsRegistry.register(:explain, [ :master_timeout,
34+
:timeout ].freeze)
35+
36+
end
37+
end
38+
end
39+
end
40+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Retrieves a lifecycle policy
12+
#
13+
# @option arguments [String] :policy_id Identifier for the policy
14+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
15+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html
18+
#
19+
def get_policy(arguments={})
20+
method = Elasticsearch::API::HTTP_GET
21+
path = Elasticsearch::API::Utils.__pathify "_ilm/policy",
22+
Elasticsearch::API::Utils.__escape(arguments[:policy_id])
23+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
24+
body = nil
25+
26+
perform_request(method, path, params, body).body
27+
end
28+
29+
# Register this action with its valid params when the module is loaded.
30+
#
31+
ParamsRegistry.register(:get_policy, [ :master_timeout,
32+
:timeout ].freeze)
33+
34+
end
35+
end
36+
end
37+
end
38+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Retrieves the current index lifecycle management (ILM) status
12+
#
13+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
14+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
15+
#
16+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-status.html
17+
#
18+
def get_status(arguments={})
19+
method = Elasticsearch::API::HTTP_GET
20+
path = "_ilm/status"
21+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
22+
body = nil
23+
24+
perform_request(method, path, params, body).body
25+
end
26+
27+
# Register this action with its valid params when the module is loaded.
28+
#
29+
ParamsRegistry.register(:get_status, [ :master_timeout,
30+
:timeout ].freeze)
31+
32+
end
33+
end
34+
end
35+
end
36+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Triggers execution of a specific step in the lifecycle policy
12+
#
13+
# @option arguments [String] :index The target index (*Required*)
14+
# @option arguments [Hash] :body The request template content (*Required*)
15+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
16+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
17+
#
18+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html
19+
#
20+
def move_to_step(arguments={})
21+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
22+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
23+
method = Elasticsearch::API::HTTP_POST
24+
index = Elasticsearch::API::Utils.__escape(arguments.delete(:index))
25+
path = Elasticsearch::API::Utils.__pathify "_ilm/move",
26+
index
27+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
28+
body = arguments[:body]
29+
30+
perform_request(method, path, params, body).body
31+
end
32+
33+
# Register this action with its valid params when the module is loaded.
34+
#
35+
ParamsRegistry.register(:move_to_step, [ :master_timeout,
36+
:timeout ].freeze)
37+
end
38+
end
39+
end
40+
end
41+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
module ParamsRegistry
11+
12+
extend self
13+
14+
# A Mapping of all the actions to their list of valid params.
15+
#
16+
# @since 7.4.0
17+
PARAMS = {}
18+
19+
# Register an action with its list of valid params.
20+
#
21+
# @example Register the action.
22+
# ParamsRegistry.register(:benchmark, [ :verbose ])
23+
#
24+
# @param [ Symbol ] action The action to register.
25+
# @param [ Array[Symbol] ] valid_params The list of valid params.
26+
#
27+
# @since 7.4.0
28+
def register(action, valid_params)
29+
PARAMS[action.to_sym] = valid_params
30+
end
31+
32+
# Get the list of valid params for a given action.
33+
#
34+
# @example Get the list of valid params.
35+
# ParamsRegistry.get(:benchmark)
36+
#
37+
# @param [ Symbol ] action The action.
38+
#
39+
# @return [ Array<Symbol> ] The list of valid params for the action.
40+
#
41+
# @since 7.4.0
42+
def get(action)
43+
PARAMS.fetch(action, [])
44+
end
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Register a new watch in or update an existing one
12+
#
13+
# @option arguments [String] :policy_id Identifier for the policy (*Required*)
14+
# @option arguments [Hash] :body The policy (*Required*)
15+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
16+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
17+
#
18+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html
19+
#
20+
def put_policy(arguments={})
21+
raise ArgumentError, "Required argument 'policy_id' missing" unless arguments[:policy_id]
22+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
23+
method = Elasticsearch::API::HTTP_PUT
24+
path = Elasticsearch::API::Utils.__pathify "_ilm/policy",
25+
Elasticsearch::API::Utils.__escape(arguments[:policy_id])
26+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
27+
body = arguments[:body]
28+
29+
perform_request(method, path, params, body).body
30+
end
31+
32+
# Register this action with its valid params when the module is loaded.
33+
#
34+
ParamsRegistry.register(:put_policy, [ :master_timeout,
35+
:timeout ].freeze)
36+
end
37+
end
38+
end
39+
end
40+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Removes the assigned lifecycle policy from an index
12+
#
13+
# @option arguments [String] :index The target index (*Required*)
14+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
15+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html
18+
#
19+
def remove_policy(arguments={})
20+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
21+
method = Elasticsearch::API::HTTP_POST
22+
index = Elasticsearch::API::Utils.__escape(arguments.delete(:index))
23+
path = Elasticsearch::API::Utils.__pathify index, "_ilm/remove"
24+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
25+
body = nil
26+
27+
perform_request(method, path, params, body).body
28+
end
29+
30+
# Register this action with its valid params when the module is loaded.
31+
#
32+
ParamsRegistry.register(:remove_policy, [ :master_timeout,
33+
:timeout ].freeze)
34+
end
35+
end
36+
end
37+
end
38+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module IndexLifecycleManagement
9+
module Actions
10+
11+
# Retry executing the policy for an index that is in the ERROR step
12+
#
13+
# @option arguments [String] :index The target index (*Required*)
14+
# @option arguments [Time] :master_timeout Specifies the period of time to wait for a connection to the master node
15+
# @option arguments [Time] :timeout Specifies the period of time to wait for a response.
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html
18+
#
19+
def retry_policy(arguments={})
20+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
21+
method = Elasticsearch::API::HTTP_POST
22+
index = Elasticsearch::API::Utils.__escape(arguments.delete(:index))
23+
path = Elasticsearch::API::Utils.__pathify index, "_ilm/retry"
24+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
25+
body = nil
26+
27+
perform_request(method, path, params, body).body
28+
end
29+
30+
# Register this action with its valid params when the module is loaded.
31+
#
32+
ParamsRegistry.register(:retry_policy, [ :master_timeout,
33+
:timeout ].freeze)
34+
end
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)