Skip to content

Commit 7138e41

Browse files
committed
[API] Adds shutdown endpoints
1 parent 867c21f commit 7138e41

File tree

9 files changed

+399
-1
lines changed

9 files changed

+399
-1
lines changed

elasticsearch-api/lib/elasticsearch/api.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def self.included(base)
7373
Elasticsearch::API::Cat,
7474
Elasticsearch::API::Remote,
7575
Elasticsearch::API::DanglingIndices,
76-
Elasticsearch::API::Features
76+
Elasticsearch::API::Features,
77+
Elasticsearch::API::Shutdown
7778
end
7879

7980
# The serializer class
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 contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Shutdown
21+
module Actions
22+
# Removes a node from the shutdown list
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :node_id The node id of node to be removed from the shutdown state
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current
32+
#
33+
def delete_node(arguments = {})
34+
raise ArgumentError, "Required argument 'node_id' missing" unless arguments[:node_id]
35+
36+
headers = arguments.delete(:headers) || {}
37+
38+
arguments = arguments.clone
39+
40+
_node_id = arguments.delete(:node_id)
41+
42+
method = Elasticsearch::API::HTTP_DELETE
43+
path = "_nodes/#{Utils.__listify(_node_id)}/shutdown"
44+
params = {}
45+
46+
body = nil
47+
perform_request(method, path, params, body, headers).body
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Shutdown
21+
module Actions
22+
# Retrieve status of a node or nodes that are currently marked as shutting down
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :node_id Which node for which to retrieve the shutdown status
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current
32+
#
33+
def get_node(arguments = {})
34+
headers = arguments.delete(:headers) || {}
35+
36+
arguments = arguments.clone
37+
38+
_node_id = arguments.delete(:node_id)
39+
40+
method = Elasticsearch::API::HTTP_GET
41+
path = if _node_id
42+
"_nodes/#{Utils.__listify(_node_id)}/shutdown"
43+
else
44+
"_nodes/shutdown"
45+
end
46+
params = {}
47+
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
50+
end
51+
end
52+
end
53+
end
54+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Shutdown
21+
module Actions
22+
module ParamsRegistry
23+
extend self
24+
25+
# A Mapping of all the actions to their list of valid params.
26+
#
27+
# @since 6.1.1
28+
PARAMS = {}
29+
30+
# Register an action with its list of valid params.
31+
#
32+
# @example Register the action.
33+
# ParamsRegistry.register(:benchmark, [ :verbose ])
34+
#
35+
# @param [ Symbol ] action The action to register.
36+
# @param [ Array[Symbol] ] valid_params The list of valid params.
37+
#
38+
# @since 6.1.1
39+
def register(action, valid_params)
40+
PARAMS[action.to_sym] = valid_params
41+
end
42+
43+
# Get the list of valid params for a given action.
44+
#
45+
# @example Get the list of valid params.
46+
# ParamsRegistry.get(:benchmark)
47+
#
48+
# @param [ Symbol ] action The action.
49+
#
50+
# @return [ Array<Symbol> ] The list of valid params for the action.
51+
#
52+
# @since 6.1.1
53+
def get(action)
54+
PARAMS.fetch(action, [])
55+
end
56+
end
57+
end
58+
end
59+
end
60+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Shutdown
21+
module Actions
22+
# Adds a node to be shut down
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :node_id The node id of node to be shut down
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
# @option arguments [Hash] :body The shutdown type definition to register (*Required*)
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current
33+
#
34+
def put_node(arguments = {})
35+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
36+
raise ArgumentError, "Required argument 'node_id' missing" unless arguments[:node_id]
37+
38+
headers = arguments.delete(:headers) || {}
39+
40+
arguments = arguments.clone
41+
42+
_node_id = arguments.delete(:node_id)
43+
44+
method = Elasticsearch::API::HTTP_PUT
45+
path = "_nodes/#{Utils.__listify(_node_id)}/shutdown"
46+
params = {}
47+
48+
body = arguments[:body]
49+
perform_request(method, path, params, body, headers).body
50+
end
51+
end
52+
end
53+
end
54+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Shutdown
21+
module Actions; end
22+
23+
# Client for the "shutdown" namespace (includes the {Shutdown::Actions} methods)
24+
#
25+
class ShutdownClient
26+
include Common::Client, Common::Client::Base, Shutdown::Actions
27+
end
28+
29+
# Proxy method for {ShutdownClient}, available in the receiving object
30+
#
31+
def shutdown
32+
@shutdown ||= ShutdownClient.new(self)
33+
end
34+
35+
end
36+
end
37+
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 contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.shutdown#delete_node' do
21+
let(:expected_args) do
22+
[
23+
'DELETE',
24+
'_nodes/id/shutdown',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.shutdown.delete_node(node_id: 'id')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::API }.new
37+
end
38+
39+
it 'raises an error if no node_id is provided' do
40+
expect {
41+
client.shutdown.delete_node
42+
}.to raise_exception(ArgumentError)
43+
end
44+
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 contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.shutdown#get_node' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
context 'when id is provided' do
32+
let(:url) { '_nodes/id/shutdown' }
33+
34+
it 'performs the request' do
35+
expect(client_double.shutdown.get_node(node_id: 'id')).to eq({})
36+
end
37+
end
38+
39+
context 'when no id is provided' do
40+
let(:url) { '_nodes/shutdown' }
41+
42+
it 'performs the request' do
43+
expect(client_double.shutdown.get_node).to eq({})
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)