Skip to content

Commit 4bda2c4

Browse files
committed
[X-Pack] Adds transform endpoint
1 parent a2cc708 commit 4bda2c4

File tree

11 files changed

+437
-0
lines changed

11 files changed

+437
-0
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def ilm
7979
def license
8080
@license ||= xpack.license
8181
end
82+
83+
def transform
84+
@transform ||= xpack.transform
85+
end
8286
end
8387
end
8488
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id of the transform to delete
14+
# @option arguments [Boolean] :force When `true`, the transform is deleted regardless of its current state. The default value is `false`, meaning that the transform must be `stopped` before it can be deleted.
15+
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-transform.html
18+
#
19+
def delete_transform(arguments = {})
20+
raise ArgumentError, "Required argument 'transform_id' missing" unless arguments[:transform_id]
21+
22+
arguments = arguments.clone
23+
24+
_transform_id = arguments.delete(:transform_id)
25+
26+
method = Elasticsearch::API::HTTP_DELETE
27+
path = "_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}"
28+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
29+
30+
body = nil
31+
perform_request(method, path, params, body).body
32+
end
33+
34+
# Register this action with its valid params when the module is loaded.
35+
#
36+
# @since 6.2.0
37+
ParamsRegistry.register(:delete_transform, [
38+
:force
39+
].freeze)
40+
end
41+
end
42+
end
43+
end
44+
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id or comma delimited list of id expressions of the transforms to get, '_all' or '*' implies get all transforms
14+
# @option arguments [Int] :from skips a number of transform configs, defaults to 0
15+
# @option arguments [Int] :size specifies a max number of transforms to get, defaults to 100
16+
# @option arguments [Boolean] :allow_no_match Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)
17+
18+
#
19+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform.html
20+
#
21+
def get_transform(arguments = {})
22+
arguments = arguments.clone
23+
24+
_transform_id = arguments.delete(:transform_id)
25+
26+
method = Elasticsearch::API::HTTP_GET
27+
path = if _transform_id
28+
"_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}"
29+
else
30+
"_transform"
31+
end
32+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
33+
34+
body = nil
35+
perform_request(method, path, params, body).body
36+
end
37+
38+
# Register this action with its valid params when the module is loaded.
39+
#
40+
# @since 6.2.0
41+
ParamsRegistry.register(:get_transform, [
42+
:from,
43+
:size,
44+
:allow_no_match
45+
].freeze)
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id of the transform for which to get stats. '_all' or '*' implies all transforms
14+
# @option arguments [Number] :from skips a number of transform stats, defaults to 0
15+
# @option arguments [Number] :size specifies a max number of transform stats to get, defaults to 100
16+
# @option arguments [Boolean] :allow_no_match Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)
17+
18+
#
19+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform-stats.html
20+
#
21+
def get_transform_stats(arguments = {})
22+
raise ArgumentError, "Required argument 'transform_id' missing" unless arguments[:transform_id]
23+
24+
arguments = arguments.clone
25+
26+
_transform_id = arguments.delete(:transform_id)
27+
28+
method = Elasticsearch::API::HTTP_GET
29+
path = "_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}/_stats"
30+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
31+
32+
body = nil
33+
perform_request(method, path, params, body).body
34+
end
35+
36+
# Register this action with its valid params when the module is loaded.
37+
#
38+
# @since 6.2.0
39+
ParamsRegistry.register(:get_transform_stats, [
40+
:from,
41+
:size,
42+
:allow_no_match
43+
].freeze)
44+
end
45+
end
46+
end
47+
end
48+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 Transform
9+
module Actions
10+
module ParamsRegistry
11+
extend self
12+
13+
# A Mapping of all the actions to their list of valid params.
14+
#
15+
# @since 7.4.0
16+
PARAMS = {}
17+
18+
# Register an action with its list of valid params.
19+
#
20+
# @example Register the action.
21+
# ParamsRegistry.register(:benchmark, [ :verbose ])
22+
#
23+
# @param [ Symbol ] action The action to register.
24+
# @param [ Array[Symbol] ] valid_params The list of valid params.
25+
#
26+
# @since 7.4.0
27+
def register(action, valid_params)
28+
PARAMS[action.to_sym] = valid_params
29+
end
30+
31+
# Get the list of valid params for a given action.
32+
#
33+
# @example Get the list of valid params.
34+
# ParamsRegistry.get(:benchmark)
35+
#
36+
# @param [ Symbol ] action The action.
37+
#
38+
# @return [ Array<Symbol> ] The list of valid params for the action.
39+
#
40+
# @since 7.4.0
41+
def get(action)
42+
PARAMS.fetch(action, [])
43+
end
44+
end
45+
end
46+
end
47+
end
48+
end
49+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
# @option arguments [Hash] :body The definition for the transform to preview (*Required*)
13+
#
14+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-transform.html
15+
#
16+
def preview_transform(arguments = {})
17+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
18+
19+
arguments = arguments.clone
20+
21+
method = Elasticsearch::API::HTTP_POST
22+
path = "_transform/_preview"
23+
params = {}
24+
25+
body = arguments[:body]
26+
perform_request(method, path, params, body).body
27+
end
28+
end
29+
end
30+
end
31+
end
32+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id of the new transform.
14+
# @option arguments [Boolean] :defer_validation If validations should be deferred until transform starts, defaults to false.
15+
16+
# @option arguments [Hash] :body The transform definition (*Required*)
17+
#
18+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html
19+
#
20+
def put_transform(arguments = {})
21+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
22+
raise ArgumentError, "Required argument 'transform_id' missing" unless arguments[:transform_id]
23+
24+
arguments = arguments.clone
25+
26+
_transform_id = arguments.delete(:transform_id)
27+
28+
method = Elasticsearch::API::HTTP_PUT
29+
path = "_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}"
30+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
31+
32+
body = arguments[:body]
33+
perform_request(method, path, params, body).body
34+
end
35+
36+
# Register this action with its valid params when the module is loaded.
37+
#
38+
# @since 6.2.0
39+
ParamsRegistry.register(:put_transform, [
40+
:defer_validation
41+
].freeze)
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id of the transform to start
14+
# @option arguments [Time] :timeout Controls the time to wait for the transform to start
15+
16+
#
17+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/start-transform.html
18+
#
19+
def start_transform(arguments = {})
20+
raise ArgumentError, "Required argument 'transform_id' missing" unless arguments[:transform_id]
21+
22+
arguments = arguments.clone
23+
24+
_transform_id = arguments.delete(:transform_id)
25+
26+
method = Elasticsearch::API::HTTP_POST
27+
path = "_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}/_start"
28+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
29+
30+
body = nil
31+
perform_request(method, path, params, body).body
32+
end
33+
34+
# Register this action with its valid params when the module is loaded.
35+
#
36+
# @since 6.2.0
37+
ParamsRegistry.register(:start_transform, [
38+
:timeout
39+
].freeze)
40+
end
41+
end
42+
end
43+
end
44+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 Transform
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :transform_id The id of the transform to stop
14+
# @option arguments [Boolean] :force Whether to force stop a failed transform or not. Default to false
15+
# @option arguments [Boolean] :wait_for_completion Whether to wait for the transform to fully stop before returning or not. Default to false
16+
# @option arguments [Time] :timeout Controls the time to wait until the transform has stopped. Default to 30 seconds
17+
# @option arguments [Boolean] :allow_no_match Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)
18+
# @option arguments [Boolean] :wait_for_checkpoint Whether to wait for the transform to reach a checkpoint before stopping. Default to false
19+
20+
#
21+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-transform.html
22+
#
23+
def stop_transform(arguments = {})
24+
raise ArgumentError, "Required argument 'transform_id' missing" unless arguments[:transform_id]
25+
26+
arguments = arguments.clone
27+
28+
_transform_id = arguments.delete(:transform_id)
29+
30+
method = Elasticsearch::API::HTTP_POST
31+
path = "_transform/#{Elasticsearch::API::Utils.__listify(_transform_id)}/_stop"
32+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
33+
34+
body = nil
35+
perform_request(method, path, params, body).body
36+
end
37+
38+
# Register this action with its valid params when the module is loaded.
39+
#
40+
# @since 6.2.0
41+
ParamsRegistry.register(:stop_transform, [
42+
:force,
43+
:wait_for_completion,
44+
:timeout,
45+
:allow_no_match,
46+
:wait_for_checkpoint
47+
].freeze)
48+
end
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)