elastic_manager 0.1.6 → 0.1.7
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 +4 -4
- data/README.md +5 -2
- data/elastic_manager.gemspec +1 -1
- data/lib/elastic_manager/config.rb +18 -2
- data/lib/elastic_manager/logger.rb +6 -6
- data/lib/elastic_manager/open.rb +7 -8
- data/lib/elastic_manager/request.rb +5 -5
- data/lib/elastic_manager/utils.rb +0 -6
- data/lib/elastic_manager.rb +0 -2
- metadata +2 -3
- data/lib/elastic_manager/close.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5905bd89d21941b7ce9443d94d601c73fc035e038f7f7ab6ce570d94d1f9feb3
|
4
|
+
data.tar.gz: 4eb528d29478710268b64ee7cba733fe885f6e1681c9aedf619491ba4fadcedf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46d51004f9b1bc3fd5521f119783179cf13ebe8a90ff3867ce71aedb3e4650bfa23e91039504e3a7935bfe702ee545f8f4885f9884e220419cd87ca9855b4de
|
7
|
+
data.tar.gz: bd2764cba6ec941db093e45cf03e9a6a5b09b5c3c04fe226d8e628b36b38c08f55005f3931c4092da014699ea074426cdb54261eebf302a42baf91637632d38d
|
data/README.md
CHANGED
@@ -8,7 +8,10 @@ Progress:
|
|
8
8
|
|
9
9
|
- [x] Open closed indices
|
10
10
|
- [x] Open indices in snapshot (restore snapshot)
|
11
|
-
- [x]
|
11
|
+
- [x] Open by date from and to
|
12
|
+
- [x] Open by daysago
|
13
|
+
- [x] Open all indices
|
14
|
+
- [ ] Close indices
|
12
15
|
- [ ] Chill indices
|
13
16
|
- [ ] Snapshot indices
|
14
|
-
- [ ] Delete snapshots
|
17
|
+
- [ ] Delete snapshots
|
data/elastic_manager.gemspec
CHANGED
@@ -36,7 +36,6 @@ module Config
|
|
36
36
|
default['timeout']['read'] = '120'
|
37
37
|
default['daysago'] = ''
|
38
38
|
default['settings'] = {}
|
39
|
-
default['daysago'] = ''
|
40
39
|
|
41
40
|
log.debug "default config: #{default.inspect}"
|
42
41
|
default
|
@@ -75,9 +74,26 @@ module Config
|
|
75
74
|
fail_and_exit('not enough env variables. TASK, INDICES')
|
76
75
|
end
|
77
76
|
|
78
|
-
|
77
|
+
if !config['from'].empty? && !config['to'].empty?
|
78
|
+
log.debug 'will use from and to'
|
79
|
+
%w[from to].each do |key|
|
80
|
+
config[key] = Date.strptime(config[key], '%Y-%m-%d')
|
81
|
+
rescue ArgumentError => e
|
82
|
+
fail_and_exit("can't parse date #{key}: #{e.message}")
|
83
|
+
end
|
84
|
+
elsif config['from'].empty? || config['to'].empty?
|
85
|
+
fail_and_exit('not enough env variables. FROM/TO or DAYSAGO')
|
86
|
+
elsif !config['daysago'].empty?
|
87
|
+
log.debug 'will use daysago'
|
88
|
+
config['from'], config['to'] = nil
|
89
|
+
config['daysago'] = config['daysago'].to_i
|
90
|
+
else
|
79
91
|
fail_and_exit('not enough env variables. FROM/TO or DAYSAGO')
|
80
92
|
end
|
93
|
+
|
94
|
+
# unless (!config['from'].empty? && !config['to'].empty?) || !config['daysago'].empty?
|
95
|
+
# fail_and_exit('not enough env variables. FROM/TO or DAYSAGO')
|
96
|
+
# end
|
81
97
|
end
|
82
98
|
|
83
99
|
def load_from_env
|
@@ -7,12 +7,12 @@ require 'colorize'
|
|
7
7
|
module Logging
|
8
8
|
|
9
9
|
SEVERITY_COLORS = {
|
10
|
-
DEBUG
|
11
|
-
INFO
|
12
|
-
WARN
|
13
|
-
ERROR
|
14
|
-
FATAL
|
15
|
-
UNKNOWN
|
10
|
+
'DEBUG' => 'cyan',
|
11
|
+
'INFO' => 'green',
|
12
|
+
'WARN' => 'yellow',
|
13
|
+
'ERROR' => 'light_red',
|
14
|
+
'FATAL' => 'red',
|
15
|
+
'UNKNOWN' => 'magenta'
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
def log
|
data/lib/elastic_manager/open.rb
CHANGED
@@ -14,8 +14,10 @@ module Open
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
unless true?(@config['force'])
|
18
|
-
|
17
|
+
unless true?(@config['force'])
|
18
|
+
unless @elastic.green?
|
19
|
+
fail_and_exit("elasticsearch on #{@config['es']['url']} is not green")
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -55,13 +57,10 @@ module Open
|
|
55
57
|
|
56
58
|
def open_prepare_vars
|
57
59
|
indices = @config['indices'].split(',')
|
58
|
-
daysago = @config['daysago']
|
60
|
+
daysago = @config['daysago']
|
59
61
|
date_from = @config['from']
|
60
62
|
date_to = @config['to']
|
61
63
|
|
62
|
-
date_from = date_from.empty? ? nil : Date.parse(date_from)
|
63
|
-
date_to = date_to.empty? ? nil : Date.parse(date_to)
|
64
|
-
|
65
64
|
[indices, date_from, date_to, daysago]
|
66
65
|
end
|
67
66
|
|
@@ -107,9 +106,9 @@ module Open
|
|
107
106
|
response = @elastic.request(:get, "/_cat/indices/#{index}")
|
108
107
|
|
109
108
|
if index_exist?(response)
|
110
|
-
next if
|
109
|
+
next if already_open?(response)
|
111
110
|
|
112
|
-
action_with_log('
|
111
|
+
action_with_log('open_index', index)
|
113
112
|
else
|
114
113
|
log.warn "#{index} index not found"
|
115
114
|
log.info "#{index} trying snapshot restore"
|
@@ -137,7 +137,7 @@ module Request
|
|
137
137
|
def get_all_indices
|
138
138
|
req_path = '/_cluster/state/metadata/'
|
139
139
|
req_params = '?filter_path=metadata.indices.*.state,'
|
140
|
-
req_params
|
140
|
+
req_params += 'metadata.indices.*.settings.index.routing.allocation.require.box_type'
|
141
141
|
|
142
142
|
response = request(:get, req_path + req_params)
|
143
143
|
|
@@ -220,17 +220,17 @@ module Request
|
|
220
220
|
true
|
221
221
|
end
|
222
222
|
|
223
|
-
def
|
224
|
-
response = request(:post, "/#{
|
223
|
+
def open_index(index)
|
224
|
+
response = request(:post, "/#{index}/_open?master_timeout=1m")
|
225
225
|
|
226
226
|
if response.code == 200
|
227
227
|
response = json_parse(response)
|
228
228
|
else
|
229
|
-
log.fatal "wrong response code for #{index}
|
229
|
+
log.fatal "wrong response code for #{index} open"
|
230
230
|
exit 1
|
231
231
|
end
|
232
232
|
|
233
|
-
response['acknowledged'].
|
233
|
+
response['acknowledged'].is_a?(TrueClass)
|
234
234
|
end
|
235
235
|
end
|
236
236
|
end
|
@@ -2,17 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'yajl'
|
5
|
-
require 'elastic_manager/logger'
|
6
5
|
|
7
6
|
# Sharable methods
|
8
7
|
module Utils
|
9
8
|
include Logging
|
10
9
|
|
11
|
-
TASK_TO_STATE = {
|
12
|
-
open: 'close',
|
13
|
-
close: 'open'
|
14
|
-
}.freeze
|
15
|
-
|
16
10
|
def true?(obj)
|
17
11
|
obj.to_s.casecmp('true').zero?
|
18
12
|
end
|
data/lib/elastic_manager.rb
CHANGED
@@ -7,7 +7,6 @@ require 'elastic_manager/logger'
|
|
7
7
|
require 'elastic_manager/request'
|
8
8
|
require 'elastic_manager/utils'
|
9
9
|
require 'elastic_manager/open'
|
10
|
-
require 'elastic_manager/close'
|
11
10
|
|
12
11
|
# Main
|
13
12
|
class ElasticManager
|
@@ -16,7 +15,6 @@ class ElasticManager
|
|
16
15
|
include Request
|
17
16
|
include Utils
|
18
17
|
include Open
|
19
|
-
include Close
|
20
18
|
|
21
19
|
def initialize
|
22
20
|
@config = load_from_env
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antony Ryabov
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- bin/elastic_manager
|
95
95
|
- elastic_manager.gemspec
|
96
96
|
- lib/elastic_manager.rb
|
97
|
-
- lib/elastic_manager/close.rb
|
98
97
|
- lib/elastic_manager/config.rb
|
99
98
|
- lib/elastic_manager/logger.rb
|
100
99
|
- lib/elastic_manager/open.rb
|
@@ -120,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
119
|
version: '0'
|
121
120
|
requirements: []
|
122
121
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.7.
|
122
|
+
rubygems_version: 2.7.8
|
124
123
|
signing_key:
|
125
124
|
specification_version: 4
|
126
125
|
summary: Because qurator sucks
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Close
|
2
|
-
def do_close(indices, date)
|
3
|
-
indices.each do |index_name|
|
4
|
-
next if skip?('close', index_name)
|
5
|
-
|
6
|
-
index = "#{index_name}-#{date}"
|
7
|
-
response = @elastic.request(:get, "/_cat/indices/#{index}")
|
8
|
-
|
9
|
-
if index_exist?(response)
|
10
|
-
next if already?('close', response, index)
|
11
|
-
|
12
|
-
action_with_log('close', index)
|
13
|
-
else
|
14
|
-
log.warn "#{index} index not found, maybe already snapshoted"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|