diplomat 2.1.3 → 2.2.0
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/lib/diplomat/rest_client.rb +3 -2
- data/lib/diplomat/service.rb +15 -1
- data/lib/diplomat/version.rb +1 -1
- data/lib/diplomatic_bag.rb +7 -0
- data/lib/diplomatic_bag/datacenters.rb +11 -0
- data/lib/diplomatic_bag/info.rb +32 -0
- data/lib/diplomatic_bag/nodes.rb +28 -0
- data/lib/diplomatic_bag/service.rb +20 -0
- data/lib/diplomatic_bag/services.rb +38 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeda162dfc23369b377785a2cc09baa0544dfbfb234ee60b3c8d722916393479
|
4
|
+
data.tar.gz: 57fe7b8364bcbea2ba93b39c4c10da4bb735e80e8719ebff4017687a1efc9cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534b858e18d9fe81c87b04cc4a5a4abfc74529b1f8dd947cb07f09098ebad0cad034b5a2bf7a5765cd8df045237977b319bf83b46f4eae249095159fb7f235df
|
7
|
+
data.tar.gz: 8b8e2562535dbc7f8c1e2c2e38e2a4ff31b2b09074ac02b3e6ab6ff935435a3c52c07b6b6ceb044e51bee3973c7ae578c4e8d6a6d012b4b9a777457f4a6af705
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -58,8 +58,8 @@ module Diplomat
|
|
58
58
|
# See https://bugs.ruby-lang.org/issues/10969
|
59
59
|
begin
|
60
60
|
super
|
61
|
-
rescue NameError =>
|
62
|
-
raise NoMethodError,
|
61
|
+
rescue NameError => e
|
62
|
+
raise NoMethodError, e
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -198,6 +198,7 @@ module Diplomat
|
|
198
198
|
url += custom_params unless custom_params.nil?
|
199
199
|
begin
|
200
200
|
connection.get do |req|
|
201
|
+
req.options[:params_encoder] = options[:params_encoder] if options[:params_encoder]
|
201
202
|
req.url rest_options[:url_prefix] ? rest_options[:url_prefix] + concat_url(url) : concat_url(url)
|
202
203
|
rest_options[:headers].map { |k, v| req.headers[k.to_sym] = v } unless rest_options[:headers].nil?
|
203
204
|
req.options.timeout = options[:timeout] if options[:timeout]
|
data/lib/diplomat/service.rb
CHANGED
@@ -15,7 +15,21 @@ module Diplomat
|
|
15
15
|
custom_params << use_named_parameter('wait', options[:wait]) if options[:wait]
|
16
16
|
custom_params << use_named_parameter('index', options[:index]) if options[:index]
|
17
17
|
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
18
|
-
|
18
|
+
if options[:tag]
|
19
|
+
# tag can be either a String, or an array of strings
|
20
|
+
# by splatting it is guaranteed to be an array of strings
|
21
|
+
[*options[:tag]].each do |value|
|
22
|
+
custom_params << use_named_parameter('tag', value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# We have to provide a custom params encoder here because Faraday - by default - assumes that
|
27
|
+
# list keys have [] as part of their name. This is however not the case for consul tags, which
|
28
|
+
# just use repeated occurences of the same key.
|
29
|
+
#
|
30
|
+
# So faraday reduces this: http://localhost:8500?a=1&a=2 to http://localhost:8500?a=2 unless you
|
31
|
+
# explicitly tell it not to.
|
32
|
+
options[:params_encoder] = Faraday::FlatParamsEncoder
|
19
33
|
|
20
34
|
ret = send_get_request(@conn, ["/v1/catalog/service/#{key}"], options, custom_params)
|
21
35
|
if meta && ret.headers
|
data/lib/diplomat/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Usefull usage of Diplomat lib: Datacenter functions
|
2
|
+
module DiplomaticBag
|
3
|
+
def self.get_datacenters_list(dc, options = {})
|
4
|
+
dcs = []
|
5
|
+
datacenters = Diplomat::Datacenter.get(nil, options)
|
6
|
+
dc.each do |c|
|
7
|
+
dcs.concat(datacenters.select { |d| d[/#{c}/] })
|
8
|
+
end
|
9
|
+
dcs.uniq
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Usefull usage of Diplomat lib: Info functions
|
2
|
+
module DiplomaticBag
|
3
|
+
# rubocop:disable AbcSize
|
4
|
+
def self.consul_info(options = {})
|
5
|
+
consul_self = Diplomat::Agent.self(options)
|
6
|
+
puts 'Server: ' + consul_self['Config']['NodeName']
|
7
|
+
puts 'Datacenter: ' + consul_self['Config']['Datacenter']
|
8
|
+
puts 'Consul Version: ' + consul_self['Config']['Version']
|
9
|
+
if consul_self['Stats']['consul']['leader_addr']
|
10
|
+
puts 'Leader Address: ' + consul_self['Stats']['consul']['leader_addr']
|
11
|
+
puts 'applied_index: ' + consul_self['Stats']['raft']['applied_index']
|
12
|
+
puts 'commit_index: ' + consul_self['Stats']['raft']['commit_index']
|
13
|
+
end
|
14
|
+
members = Diplomat::Members.get(options)
|
15
|
+
servers = members.select { |member| member['Tags']['role'] == 'consul' }.sort_by { |n| n['Name'] }
|
16
|
+
nodes = members.select { |member| member['Tags']['role'] == 'node' }
|
17
|
+
leader = Diplomat::Status.leader(options).split(':')[0]
|
18
|
+
puts 'Servers Count: ' + servers.count.to_s
|
19
|
+
puts 'Nodes Count: ' + nodes.count.to_s
|
20
|
+
puts 'Servers:'
|
21
|
+
servers.map do |s|
|
22
|
+
if s['Tags']['role'] == 'consul'
|
23
|
+
if s['Addr'] == leader
|
24
|
+
puts ' ' + s['Name'] + ' ' + s['Addr'] + ' *Leader*'
|
25
|
+
else
|
26
|
+
puts ' ' + s['Name'] + ' ' + s['Addr']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# rubocop:enable AbcSize
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Usefull usage of Diplomat lib: Nodes functions
|
2
|
+
module DiplomaticBag
|
3
|
+
def self.get_duplicate_node_id(options = {})
|
4
|
+
status = {
|
5
|
+
1 => 'Alive',
|
6
|
+
2 => '?',
|
7
|
+
3 => 'Left',
|
8
|
+
4 => 'Failed'
|
9
|
+
}
|
10
|
+
result = []
|
11
|
+
members = Diplomat::Members.get(options)
|
12
|
+
grouped = members.group_by do |row|
|
13
|
+
[row['Tags']['id']]
|
14
|
+
end
|
15
|
+
filtered = grouped.values.select { |a| a.size > 1 }
|
16
|
+
filtered.each do |dup|
|
17
|
+
instance = {}
|
18
|
+
instance[:node_id] = dup[0]['Tags']['id']
|
19
|
+
nodes = []
|
20
|
+
dup.each do |inst|
|
21
|
+
nodes << { name: inst['Name'], status: status[inst['Status']] }
|
22
|
+
end
|
23
|
+
instance[:nodes] = nodes
|
24
|
+
result << instance
|
25
|
+
end
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Usefull usage of Diplomat lib: Service functions
|
2
|
+
module DiplomaticBag
|
3
|
+
def self.get_service_info(service, options = {})
|
4
|
+
result = {}
|
5
|
+
health = Diplomat::Health.service(service, options)
|
6
|
+
result[service] = {}
|
7
|
+
health.each do |h|
|
8
|
+
result[service][h['Node']['Node']] = {
|
9
|
+
'Address': h['Node']['Address'],
|
10
|
+
'Port': h['Service']['Port']
|
11
|
+
}
|
12
|
+
checks = {}
|
13
|
+
h['Checks'].each do |c|
|
14
|
+
checks[c['Name']] = { 'status': c['Status'], 'output': c['Output'] }
|
15
|
+
end
|
16
|
+
result[service][h['Node']['Node']]['Checks'] = checks
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Usefull usage of Diplomat lib: Services functions
|
2
|
+
module DiplomaticBag
|
3
|
+
def self.compute_service_name(s)
|
4
|
+
return '/node::health/' if s.nil? || s == ''
|
5
|
+
|
6
|
+
s
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get_all_services_status(options = {})
|
10
|
+
result = {}
|
11
|
+
services = Diplomat::Health.state('any', options)
|
12
|
+
grouped_by_service = services.group_by { |h| compute_service_name(h['ServiceName']) }.values
|
13
|
+
grouped_by_service.each do |s|
|
14
|
+
grouped_by_status = s.group_by { |h| h['Status'] }.values
|
15
|
+
status = {}
|
16
|
+
grouped_by_status.each do |state|
|
17
|
+
status[state[0]['Status']] = state.count
|
18
|
+
end
|
19
|
+
service_name = compute_service_name(s[0]['ServiceName'])
|
20
|
+
result[service_name] = status
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_services_list(service, options = {})
|
26
|
+
services = Diplomat::Service.get_all(options)
|
27
|
+
services.to_h.keys.grep(/#{service}/)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_services_info(service, options = {})
|
31
|
+
result = []
|
32
|
+
services = get_services_list(service, options)
|
33
|
+
services.each do |s|
|
34
|
+
result << get_service_info(s.to_s, options)
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -239,6 +239,12 @@ files:
|
|
239
239
|
- lib/diplomat/session.rb
|
240
240
|
- lib/diplomat/status.rb
|
241
241
|
- lib/diplomat/version.rb
|
242
|
+
- lib/diplomatic_bag.rb
|
243
|
+
- lib/diplomatic_bag/datacenters.rb
|
244
|
+
- lib/diplomatic_bag/info.rb
|
245
|
+
- lib/diplomatic_bag/nodes.rb
|
246
|
+
- lib/diplomatic_bag/service.rb
|
247
|
+
- lib/diplomatic_bag/services.rb
|
242
248
|
homepage: https://github.com/WeAreFarmGeek/diplomat
|
243
249
|
licenses:
|
244
250
|
- BSD-3-Clause
|