com.proofpoint.discovery.cli 1.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.
- data/bin/dcurl +43 -0
- data/bin/djconsole +38 -0
- data/lib/discovery/discovery.rb +50 -0
- data/lib/discovery/version.rb +3 -0
- metadata +82 -0
data/bin/dcurl
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'httpclient'
|
5
|
+
require 'json'
|
6
|
+
require 'discovery/discovery'
|
7
|
+
|
8
|
+
begin
|
9
|
+
Verbose = !ARGV.delete("--DEBUG").nil?
|
10
|
+
|
11
|
+
out_args = ARGV.map do |arg|
|
12
|
+
md = /(\w+):\/\/([^\/]+)(\/.*)/.match(arg)
|
13
|
+
next arg if md.nil?
|
14
|
+
|
15
|
+
protocol, host, path = *md[1..-1]
|
16
|
+
|
17
|
+
|
18
|
+
md = /^(?:(\w+)\.)*?(\w+)(?:\.(\w+))?$/.match(host)
|
19
|
+
next arg if md.nil?
|
20
|
+
|
21
|
+
pool, type, environment = *md[1..-1]
|
22
|
+
|
23
|
+
pool ||= "general"
|
24
|
+
|
25
|
+
puts "Looking up service '#{type}' in pool '#{pool}' in environment '#{environment}'" if Verbose
|
26
|
+
discovery = Discovery::Discovery.for_environment(environment)
|
27
|
+
base_url = discovery.lookup(type, pool).map { |service_descriptor| service_descriptor['properties'][protocol] }.compact.first
|
28
|
+
|
29
|
+
if base_url.nil? then
|
30
|
+
puts "Service type #{type} in pool #{pool} not found"
|
31
|
+
exit 42
|
32
|
+
end
|
33
|
+
|
34
|
+
"#{base_url}#{path}"
|
35
|
+
end
|
36
|
+
puts "Executing curl #{out_args.map{|v| "\"#{v}\"" }.join(" ")}" if Verbose
|
37
|
+
exec "curl", *out_args
|
38
|
+
|
39
|
+
rescue => e
|
40
|
+
puts e.message
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
data/bin/djconsole
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'httpclient'
|
5
|
+
require 'json'
|
6
|
+
require 'discovery/discovery'
|
7
|
+
|
8
|
+
begin
|
9
|
+
Verbose = !ARGV.delete("--DEBUG").nil?
|
10
|
+
|
11
|
+
md = /^(?:(\w+)\.)*?(\w+)(?:\.(\w+))?$/.match(ARGV[0] || "")
|
12
|
+
raise "USAGE: djconsole POOL.TYPE.ENVIRONMENT" if ARGV.length != 1 || md.nil?
|
13
|
+
|
14
|
+
pool, type, environment = *md[1..-1]
|
15
|
+
|
16
|
+
pool ||= "general"
|
17
|
+
|
18
|
+
puts "Looking up service '#{type}' in pool '#{pool}' in environment '#{environment}'" if Verbose
|
19
|
+
discovery = Discovery::Discovery.for_environment(environment)
|
20
|
+
|
21
|
+
node_jmx = Hash[ discovery.lookup("jmx", pool).map{|sd| [ sd['nodeId'], sd['properties']['jmx'] ] } ]
|
22
|
+
|
23
|
+
service_descriptors = discovery.lookup(type, pool)
|
24
|
+
base_url = service_descriptors.map{ |sd| node_jmx[sd['nodeId']] }.compact.first
|
25
|
+
|
26
|
+
if base_url.nil? then
|
27
|
+
puts "Service type #{type} in pool #{pool} not found"
|
28
|
+
exit 42
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "Executing jconsole \"#{base_url}\"" if Verbose
|
32
|
+
exec "jconsole", base_url
|
33
|
+
|
34
|
+
rescue => e
|
35
|
+
puts e.message
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Discovery
|
2
|
+
class Discovery
|
3
|
+
def self.for_environment(environment)
|
4
|
+
environment ||= "local"
|
5
|
+
|
6
|
+
discoveryrc = File.expand_path("~/.discoveryrc")
|
7
|
+
unless File.exist?(discoveryrc) then
|
8
|
+
File.open(discoveryrc, "w"){ |f| f.puts("local = http://localhost:8080") }
|
9
|
+
end
|
10
|
+
|
11
|
+
value = File.readlines(discoveryrc).map { |l| l.strip.split(/\s*=\s*/, 2) }.select { |k, v| k == environment }.map { |k, v| v }.first
|
12
|
+
raise "No such environment '#{environment}'" if value.nil?
|
13
|
+
discovery_uris = value.split(/\s*,\s*/)
|
14
|
+
return Discovery.new(discovery_uris)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(discovery_uris, client = HTTPClient.new)
|
18
|
+
@client = client
|
19
|
+
@discovery_uris = discovery_uris
|
20
|
+
end
|
21
|
+
|
22
|
+
def lookup(type, pool)
|
23
|
+
service_descriptors = []
|
24
|
+
@discovery_uris.each do |discovery_uri|
|
25
|
+
begin
|
26
|
+
url = "#{discovery_uri}/v1/service/#{type}/#{pool}"
|
27
|
+
puts "Getting services at \"#{url}\"" if Verbose
|
28
|
+
response = @client.get(url)
|
29
|
+
if response.status == HTTP::Status::OK then
|
30
|
+
body = response.body
|
31
|
+
if body.is_a?(HTTP::Message::Body) then
|
32
|
+
body = body.content
|
33
|
+
end
|
34
|
+
service_descriptors = JSON.parse(body)["services"]
|
35
|
+
break
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
# ignored
|
39
|
+
p "ERROR:: #{e}" if Verbose
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if service_descriptors.nil? then
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
|
47
|
+
return service_descriptors
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: com.proofpoint.discovery.cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "1.0"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dain Sundstrom
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-13 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: httpclient
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.2.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json_pure
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.5.1
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Discovery command line interface
|
39
|
+
email:
|
40
|
+
- dain@iq80.com
|
41
|
+
executables:
|
42
|
+
- dcurl
|
43
|
+
- djconsole
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files: []
|
47
|
+
|
48
|
+
files:
|
49
|
+
- bin/dcurl
|
50
|
+
- bin/djconsole
|
51
|
+
- lib/discovery/discovery.rb
|
52
|
+
- lib/discovery/version.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: https://github.com/dain/discovery-server
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: discovery
|
77
|
+
rubygems_version: 1.6.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: discovery
|
81
|
+
test_files: []
|
82
|
+
|