elasticsearch-watcher 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +166 -0
- data/Rakefile +99 -0
- data/elasticsearch-watcher.gemspec +40 -0
- data/lib/elasticsearch-watcher.rb +1 -0
- data/lib/elasticsearch/watcher.rb +37 -0
- data/lib/elasticsearch/watcher/api/actions/ack_watch.rb +27 -0
- data/lib/elasticsearch/watcher/api/actions/delete_watch.rb +29 -0
- data/lib/elasticsearch/watcher/api/actions/execute_watch.rb +27 -0
- data/lib/elasticsearch/watcher/api/actions/get_watch.rb +31 -0
- data/lib/elasticsearch/watcher/api/actions/info.rb +23 -0
- data/lib/elasticsearch/watcher/api/actions/put_watch.rb +29 -0
- data/lib/elasticsearch/watcher/api/actions/restart.rb +24 -0
- data/lib/elasticsearch/watcher/api/actions/start.rb +23 -0
- data/lib/elasticsearch/watcher/api/actions/stats.rb +23 -0
- data/lib/elasticsearch/watcher/api/actions/stop.rb +23 -0
- data/lib/elasticsearch/watcher/version.rb +5 -0
- data/test/test_helper.rb +87 -0
- data/test/unit/ack_watch_test.rb +26 -0
- data/test/unit/delete_watch_test.rb +26 -0
- data/test/unit/execute_watch_test.rb +26 -0
- data/test/unit/get_watch_test.rb +26 -0
- data/test/unit/info_test.rb +26 -0
- data/test/unit/put_watch_test.rb +26 -0
- data/test/unit/restart_test.rb +26 -0
- data/test/unit/start_test.rb +26 -0
- data/test/unit/stats_test.rb +26 -0
- data/test/unit/stop_test.rb +26 -0
- metadata +310 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Force the execution of the watch actions (eg. for testing)
|
7
|
+
#
|
8
|
+
# @option arguments [String] :id Watch ID (*Required*)
|
9
|
+
# @option arguments [Hash] :body Execution control
|
10
|
+
#
|
11
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-execute-watch.html
|
12
|
+
#
|
13
|
+
def execute_watch(arguments={})
|
14
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
15
|
+
valid_params = [
|
16
|
+
]
|
17
|
+
method = 'PUT'
|
18
|
+
path = "_watcher/watch/#{arguments[:id]}/_execute"
|
19
|
+
params = {}
|
20
|
+
body = arguments[:body]
|
21
|
+
|
22
|
+
perform_request(method, path, params, body).body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Get a specific watch
|
7
|
+
#
|
8
|
+
# @option arguments [String] :id Watch ID (*Required*)
|
9
|
+
#
|
10
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-get-watch.html
|
11
|
+
#
|
12
|
+
def get_watch(arguments={})
|
13
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
14
|
+
valid_params = [
|
15
|
+
]
|
16
|
+
method = 'GET'
|
17
|
+
path = "_watcher/watch/#{arguments[:id]}"
|
18
|
+
params = {}
|
19
|
+
body = nil
|
20
|
+
|
21
|
+
perform_request(method, path, params, body).body
|
22
|
+
rescue Exception => e
|
23
|
+
# NOTE: Use exception name, not full class in Elasticsearch::Client to allow client plugability
|
24
|
+
if Array(arguments[:ignore]).include?(404) && e.class.to_s =~ /NotFound/; false
|
25
|
+
else raise(e)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Return information about the installed Watcher plugin
|
7
|
+
#
|
8
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-info.html
|
9
|
+
#
|
10
|
+
def info(arguments={})
|
11
|
+
valid_params = [
|
12
|
+
]
|
13
|
+
method = 'GET'
|
14
|
+
path = "/_watcher/"
|
15
|
+
params = {}
|
16
|
+
body = nil
|
17
|
+
|
18
|
+
perform_request(method, path, params, body).body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Create a new watch or update an existing one
|
7
|
+
#
|
8
|
+
# @option arguments [String] :id Watch ID (*Required*)
|
9
|
+
# @option arguments [Hash] :body The watch (*Required*)
|
10
|
+
# @option arguments [Boolean] :pretty Pretty the output
|
11
|
+
#
|
12
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-put-watch.html
|
13
|
+
#
|
14
|
+
def put_watch(arguments={})
|
15
|
+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
|
16
|
+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
|
17
|
+
valid_params = [
|
18
|
+
:master_timeout ]
|
19
|
+
method = 'PUT'
|
20
|
+
path = "_watcher/watch/#{arguments[:id]}"
|
21
|
+
params = Utils.__validate_and_extract_params arguments, valid_params
|
22
|
+
body = arguments[:body]
|
23
|
+
|
24
|
+
perform_request(method, path, params, body).body
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Restart the watcher service
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html
|
10
|
+
#
|
11
|
+
def restart(arguments={})
|
12
|
+
valid_params = [
|
13
|
+
]
|
14
|
+
method = 'PUT'
|
15
|
+
path = "/_watcher/_restart"
|
16
|
+
params = {}
|
17
|
+
body = nil
|
18
|
+
|
19
|
+
perform_request(method, path, params, body).body
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Start the watcher service
|
7
|
+
#
|
8
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html
|
9
|
+
#
|
10
|
+
def start(arguments={})
|
11
|
+
valid_params = [
|
12
|
+
]
|
13
|
+
method = 'PUT'
|
14
|
+
path = "/_watcher/_start"
|
15
|
+
params = {}
|
16
|
+
body = nil
|
17
|
+
|
18
|
+
perform_request(method, path, params, body).body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Return statistical information about the watcher service
|
7
|
+
#
|
8
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-stats.html
|
9
|
+
#
|
10
|
+
def stats(arguments={})
|
11
|
+
valid_params = [
|
12
|
+
]
|
13
|
+
method = 'GET'
|
14
|
+
path = "/_watcher/stats"
|
15
|
+
params = {}
|
16
|
+
body = nil
|
17
|
+
|
18
|
+
perform_request(method, path, params, body).body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module API
|
3
|
+
module Watcher
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
# Stop the watcher service
|
7
|
+
#
|
8
|
+
# @see http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html
|
9
|
+
#
|
10
|
+
def stop(arguments={})
|
11
|
+
valid_params = [
|
12
|
+
]
|
13
|
+
method = 'PUT'
|
14
|
+
path = "/_watcher/_stop"
|
15
|
+
params = {}
|
16
|
+
body = nil
|
17
|
+
|
18
|
+
perform_request(method, path, params, body).body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
JRUBY = defined?(JRUBY_VERSION)
|
2
|
+
|
3
|
+
if ENV['COVERAGE'] || ENV['CI']
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start { add_filter "/test|test_" }
|
6
|
+
end
|
7
|
+
|
8
|
+
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda-context'
|
12
|
+
require 'mocha/setup'
|
13
|
+
|
14
|
+
require 'minitest/reporters'
|
15
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
16
|
+
|
17
|
+
require 'elasticsearch'
|
18
|
+
require 'elasticsearch/extensions/test/cluster'
|
19
|
+
require 'elasticsearch/extensions/test/startup_shutdown'
|
20
|
+
|
21
|
+
require 'elasticsearch/watcher'
|
22
|
+
|
23
|
+
module Elasticsearch
|
24
|
+
module Test
|
25
|
+
class IntegrationTestCase < ::Test::Unit::TestCase
|
26
|
+
include Elasticsearch::Extensions::Test
|
27
|
+
extend StartupShutdown
|
28
|
+
|
29
|
+
startup do
|
30
|
+
Cluster.start(nodes: 1) if ENV['SERVER'] \
|
31
|
+
&& ! Elasticsearch::Extensions::Test::Cluster.running?
|
32
|
+
end
|
33
|
+
|
34
|
+
shutdown do
|
35
|
+
Cluster.stop if ENV['SERVER'] \
|
36
|
+
&& started? \
|
37
|
+
&& Elasticsearch::Extensions::Test::Cluster.running?
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup
|
41
|
+
@port = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i
|
42
|
+
|
43
|
+
@logger = Logger.new(STDERR)
|
44
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
45
|
+
color = case severity
|
46
|
+
when /INFO/ then :green
|
47
|
+
when /ERROR|WARN|FATAL/ then :red
|
48
|
+
when /DEBUG/ then :cyan
|
49
|
+
else :white
|
50
|
+
end
|
51
|
+
ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
@client = Elasticsearch::Client.new host: "localhost:#{@port}", logger: @logger
|
55
|
+
end
|
56
|
+
|
57
|
+
def teardown
|
58
|
+
@client.indices.delete index: '_all'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Elasticsearch
|
65
|
+
module Test
|
66
|
+
class FakeClient
|
67
|
+
include Elasticsearch::API::Watcher
|
68
|
+
|
69
|
+
def perform_request(method, path, params, body)
|
70
|
+
puts "PERFORMING REQUEST:", "--> #{method.to_s.upcase} #{path} #{params} #{body}"
|
71
|
+
FakeResponse.new(200, 'FAKE', {})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
FakeResponse = Struct.new(:status, :body, :headers) do
|
76
|
+
def status
|
77
|
+
values[0] || 200
|
78
|
+
end
|
79
|
+
def body
|
80
|
+
values[1] || '{}'
|
81
|
+
end
|
82
|
+
def headers
|
83
|
+
values[2] || {}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class WatcherAckWatchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Watcher: Ack watch" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'PUT', method
|
13
|
+
assert_equal '_watcher/watch/foo/_ack', url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.watcher.ack_watch id: 'foo'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class WatcherDeleteWatchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Watcher: Delete watch" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'DELETE', method
|
13
|
+
assert_equal "_watcher/watch/foo", url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.watcher.delete_watch id: 'foo'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class WatcherExecuteWatchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Watcher: Execute watch" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'PUT', method
|
13
|
+
assert_equal "_watcher/watch/foo/_execute", url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_equal Hash.new, body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.watcher.execute_watch id: 'foo', body: {}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class WatcherGetWatchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Watcher: Get watch" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'GET', method
|
13
|
+
assert_equal "_watcher/watch/foo", url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.watcher.get_watch id: 'foo'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class WatcherInfoTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Watcher: Info" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'GET', method
|
13
|
+
assert_equal '/_watcher/', url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.watcher.info
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|