pcp-client 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/pcp-ping +112 -0
- data/lib/pcp-client/version.rb +4 -0
- data/lib/pcp/client.rb +8 -1
- data/lib/pcp/message.rb +10 -2
- metadata +18 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ccd94b628705ee8a3f3abcd2a0a91014fe40cd2
|
4
|
+
data.tar.gz: a0243198f1ea56931fe5fdc55d7c487cbba6dbe7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d77ed2f71cb68af0c14f589bd5e328ff2f193d245e6d8ce933ea07aae718683e78b500628d21ccc2026a614c81644ed44259010b9919e9982fc4e2e3ca2fc4da
|
7
|
+
data.tar.gz: 09655b7b2defada82e89e3da8063e2edf6898a60733fc76f6761859b1024b44efb7966270ad6a367aa966236431599631effd67e219a641c47680782bea0e1b1
|
data/bin/pcp-ping
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pcp/client'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
ssl_key = '../pcp-broker/test-resources/ssl/private_keys/client01.example.com.pem'
|
6
|
+
ssl_cert = '../pcp-broker/test-resources/ssl/certs/client01.example.com.pem'
|
7
|
+
ssl_ca_cert = '../pcp-broker/test-resources/ssl/ca/ca_crt.pem'
|
8
|
+
debug = false
|
9
|
+
server = 'wss://localhost:8142/pcp'
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.on("-d", "--debug", "Run noisily") { |v| debug = v }
|
13
|
+
opts.on("--ssl_key FILE", "Use this ssl key") { |v| ssl_key = v }
|
14
|
+
opts.on("--ssl_cert FILE", "Use this ssl cert") { |v| ssl_cert = v }
|
15
|
+
opts.on("--ssl_ca_cert FILE", "Use this ssl ca cert") { |v| ssl_ca_cert = v }
|
16
|
+
opts.on("--server URL", "Server to connect to") { |v| server = v }
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
start_time = Time.now.to_f
|
20
|
+
|
21
|
+
Thread.new { EM.run }
|
22
|
+
Thread.pass until EM.reactor_running?
|
23
|
+
|
24
|
+
client = PCP::Client.new({:ssl_key => ssl_key,
|
25
|
+
:ssl_cert => ssl_cert,
|
26
|
+
:ssl_ca_cert => ssl_ca_cert,
|
27
|
+
:loglevel => debug ? Logger::DEBUG : Logger::WARN,
|
28
|
+
:server => server,
|
29
|
+
})
|
30
|
+
|
31
|
+
# Record the expected set of destinations from the destination_report,
|
32
|
+
# then all the responses from the rpc_blocking_response
|
33
|
+
mutex = Mutex.new
|
34
|
+
have_responses = ConditionVariable.new
|
35
|
+
responses = {}
|
36
|
+
expected = nil
|
37
|
+
ping_time = nil
|
38
|
+
|
39
|
+
client.on_message = proc do |message|
|
40
|
+
mutex.synchronize do
|
41
|
+
case message[:message_type]
|
42
|
+
when 'http://puppetlabs.com/destination_report'
|
43
|
+
expected = JSON.load(message.data)['targets']
|
44
|
+
when 'http://puppetlabs.com/rpc_blocking_response'
|
45
|
+
sender = message[:sender]
|
46
|
+
time = Time.now.to_f - ping_time
|
47
|
+
responses[sender] = time
|
48
|
+
puts '%-55s %0.2f seconds' % [sender, time]
|
49
|
+
else
|
50
|
+
p [:unexpected_message, message]
|
51
|
+
end
|
52
|
+
|
53
|
+
have_responses.signal
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
client.connect
|
58
|
+
|
59
|
+
if !client.associated?
|
60
|
+
puts "Didn't connect to broker."
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
|
64
|
+
connect_time = Time.now.to_f - start_time
|
65
|
+
puts "Connected to broker in %0.2f seconds." % [connect_time]
|
66
|
+
puts
|
67
|
+
|
68
|
+
ping = ::PCP::Message.new(:message_type => 'http://puppetlabs.com/rpc_blocking_request',
|
69
|
+
:targets => ['pcp://*/agent'],
|
70
|
+
:destination_report => true)
|
71
|
+
|
72
|
+
ping.data = {:transaction_id => ping[:id],
|
73
|
+
:module => 'echo',
|
74
|
+
:action => 'echo',
|
75
|
+
:params => {:argument => 'echo'}}.to_json
|
76
|
+
|
77
|
+
ping.expires(3)
|
78
|
+
|
79
|
+
ping_time = Time.now.to_f
|
80
|
+
client.send(ping)
|
81
|
+
|
82
|
+
begin
|
83
|
+
Timeout::timeout(3) do
|
84
|
+
done = false
|
85
|
+
loop do
|
86
|
+
mutex.synchronize do
|
87
|
+
have_responses.wait(mutex)
|
88
|
+
if expected && expected.all? { |from| responses.include?(from) }
|
89
|
+
# Have all responses we expect, bail
|
90
|
+
run_time = Time.now.to_f - start_time
|
91
|
+
puts
|
92
|
+
puts "Received all responses in %0.2f seconds." % [run_time]
|
93
|
+
done = true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
break if done
|
97
|
+
end
|
98
|
+
end
|
99
|
+
rescue Timeout::Error
|
100
|
+
puts
|
101
|
+
if expected
|
102
|
+
puts "Received %d/%d responses. Following nodes were missing" % [responses.keys.size, expected.size]
|
103
|
+
puts
|
104
|
+
expected.select { |from| !responses.include?(from) }.each do |missing|
|
105
|
+
puts " #{missing}"
|
106
|
+
end
|
107
|
+
else
|
108
|
+
puts "Didn't get destination report, not sure how many responses to expect. We got %d." % [responses.keys.size]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
EM.stop
|
data/lib/pcp/client.rb
CHANGED
@@ -2,6 +2,7 @@ require 'eventmachine'
|
|
2
2
|
require 'faye/websocket'
|
3
3
|
require 'pcp/message'
|
4
4
|
require 'logger'
|
5
|
+
require 'openssl'
|
5
6
|
|
6
7
|
# So EventMachine when you specify :verify_peer => true in the TLS
|
7
8
|
# options decides what that means is it should just fire off a
|
@@ -80,6 +81,7 @@ module PCP
|
|
80
81
|
type = params[:type] || "ruby-pcp-client-#{$$}"
|
81
82
|
@identity = make_identity(@ssl_cert, type)
|
82
83
|
@on_message = params[:on_message]
|
84
|
+
@max_message_size = params[:max_message_size] || 64*1024*1024
|
83
85
|
@associated = false
|
84
86
|
end
|
85
87
|
|
@@ -114,7 +116,9 @@ module PCP
|
|
114
116
|
:xxx_hostname => URI.parse(@server).host,
|
115
117
|
}
|
116
118
|
|
117
|
-
@connection = Faye::WebSocket::Client.new(@server, nil, {:tls => start_tls_options
|
119
|
+
@connection = Faye::WebSocket::Client.new(@server, nil, {:tls => start_tls_options,
|
120
|
+
:ping => 30,
|
121
|
+
:max_length => @max_message_size})
|
118
122
|
|
119
123
|
@connection.on :open do |event|
|
120
124
|
begin
|
@@ -205,6 +209,9 @@ module PCP
|
|
205
209
|
def send(message)
|
206
210
|
EM.next_tick do
|
207
211
|
@logger.debug { [:send, message] }
|
212
|
+
if message[:expires].nil?
|
213
|
+
message.expires(3)
|
214
|
+
end
|
208
215
|
message[:sender] = identity
|
209
216
|
@connection.send(message.encode)
|
210
217
|
end
|
data/lib/pcp/message.rb
CHANGED
@@ -111,11 +111,19 @@ module PCP
|
|
111
111
|
chunks << frame_chunk(i + 2, @chunks[i])
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
validate
|
115
115
|
|
116
116
|
[1, frame_chunk(1, envelope.to_json), chunks].flatten
|
117
117
|
end
|
118
118
|
|
119
|
+
# Validate the data in message against schema
|
120
|
+
#
|
121
|
+
# @api public
|
122
|
+
# @return ignore
|
123
|
+
def validate
|
124
|
+
RSchema.validate!(PCP::Protocol::Envelope, envelope)
|
125
|
+
end
|
126
|
+
|
119
127
|
private
|
120
128
|
|
121
129
|
# Decodes an array of bytes into the message
|
@@ -144,7 +152,7 @@ module PCP
|
|
144
152
|
parsed.each do |k,v|
|
145
153
|
@envelope[k.to_sym] = v
|
146
154
|
end
|
147
|
-
|
155
|
+
validate
|
148
156
|
else
|
149
157
|
@chunks[type - 2] = body
|
150
158
|
end
|
metadata
CHANGED
@@ -1,98 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcp-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Puppet Labs
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: eventmachine
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.2'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.2'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: faye-websocket
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0.10'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0.10'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rschema
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '1.3'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '1.3'
|
62
55
|
description: See https://github.com/puppetlabs/pcp-specifications
|
63
56
|
email: puppet@puppetlabs.com
|
64
|
-
executables:
|
57
|
+
executables:
|
58
|
+
- pcp-ping
|
65
59
|
extensions: []
|
66
60
|
extra_rdoc_files: []
|
67
61
|
files:
|
62
|
+
- bin/pcp-ping
|
63
|
+
- lib/pcp-client/version.rb
|
64
|
+
- lib/pcp.rb
|
68
65
|
- lib/pcp/client.rb
|
69
66
|
- lib/pcp/message.rb
|
70
67
|
- lib/pcp/protocol.rb
|
71
68
|
- lib/pcp/simple_logger.rb
|
72
|
-
- lib/pcp.rb
|
73
69
|
homepage: https://github.com/puppetlabs/ruby-pcp-client
|
74
70
|
licenses:
|
75
71
|
- ASL 2.0
|
72
|
+
metadata: {}
|
76
73
|
post_install_message:
|
77
74
|
rdoc_options: []
|
78
75
|
require_paths:
|
79
76
|
- lib
|
80
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
78
|
requirements:
|
83
|
-
- -
|
79
|
+
- - ">="
|
84
80
|
- !ruby/object:Gem::Version
|
85
81
|
version: '0'
|
86
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
83
|
requirements:
|
89
|
-
- -
|
84
|
+
- - ">="
|
90
85
|
- !ruby/object:Gem::Version
|
91
86
|
version: '0'
|
92
87
|
requirements: []
|
93
88
|
rubyforge_project:
|
94
|
-
rubygems_version:
|
89
|
+
rubygems_version: 2.5.1
|
95
90
|
signing_key:
|
96
|
-
specification_version:
|
91
|
+
specification_version: 4
|
97
92
|
summary: Client library for PCP
|
98
93
|
test_files: []
|