qpid_management 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 680e99b92e33b73931b81e0008846acc105eae5d
4
+ data.tar.gz: c39a443cc5b7205bd9a8a64f2c984f2024ed3e3e
5
+ SHA512:
6
+ metadata.gz: ba56998378d73cbe90b5887c7b2587773520c9b8c9893ebbed34d1d0438fbf08294e57301ebaf63fb37fcdd53d3d434a1f55b4dd9ebf45036292f704447b4056
7
+ data.tar.gz: 0a65eb4d520421451bd1d27bebc6bcdbe8b065ce846a20b4dddd8aa8b7cb19f4692c9720787e27ac2f8d20aee93a333fb44f844237ba2c5bae46ed13a5046e65
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ source "http://rubygems.org"
21
+
22
+ # Specify your gem's dependencies in qpid_config.gemspec
23
+ gemspec
24
+
25
+ # development deps
26
+ gem 'rspec'
27
+ gem 'pry'
28
+ gem 'pry-stack_explorer'
29
+ gem 'pry-debugger'
30
+ gem 'yard'
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qpid_management (1.0)
5
+ qpid_messaging
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ binding_of_caller (0.7.1)
11
+ debug_inspector (>= 0.0.1)
12
+ coderay (1.0.9)
13
+ columnize (0.3.6)
14
+ debug_inspector (0.0.2)
15
+ debugger (1.4.0)
16
+ columnize (>= 0.3.1)
17
+ debugger-linecache (~> 1.1.1)
18
+ debugger-ruby_core_source (~> 1.2.0)
19
+ debugger-linecache (1.1.2)
20
+ debugger-ruby_core_source (>= 1.1.1)
21
+ debugger-ruby_core_source (1.2.0)
22
+ diff-lcs (1.2.1)
23
+ method_source (0.8.1)
24
+ pry (0.9.12)
25
+ coderay (~> 1.0.5)
26
+ method_source (~> 0.8)
27
+ slop (~> 3.4)
28
+ pry-debugger (0.2.2)
29
+ debugger (~> 1.3)
30
+ pry (~> 0.9.10)
31
+ pry-stack_explorer (0.4.9)
32
+ binding_of_caller (>= 0.7)
33
+ pry (~> 0.9.11)
34
+ qpid_messaging (0.20.2)
35
+ rspec (2.13.0)
36
+ rspec-core (~> 2.13.0)
37
+ rspec-expectations (~> 2.13.0)
38
+ rspec-mocks (~> 2.13.0)
39
+ rspec-core (2.13.0)
40
+ rspec-expectations (2.13.0)
41
+ diff-lcs (>= 1.1.3, < 2.0)
42
+ rspec-mocks (2.13.0)
43
+ slop (3.4.3)
44
+ yard (0.8.5.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ pry
51
+ pry-debugger
52
+ pry-stack_explorer
53
+ qpid_management!
54
+ rspec
55
+ yard
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require "bundler/gem_tasks"
21
+ require 'rspec/core/rake_task'
22
+
23
+ require 'rake/clean'
24
+ CLOBBER.include('pkg')
25
+
26
+ RSpec::Core::RakeTask.new('spec')
27
+
@@ -0,0 +1,38 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+ module Management
22
+ # Representation of the access control list (ACL) for the broker. Properties
23
+ # include:
24
+ # - aclDenyCount
25
+ # - brokerRef
26
+ # - connectionDenyCount
27
+ # - enforcingAcl
28
+ # - lastAclLoad
29
+ # - maxConnectionsPerIp
30
+ # - maxConnectionsPerUser
31
+ # - maxQueuesPerUser
32
+ # - policyFile
33
+ # - queueQuotaDenyCount
34
+ # - transferAcl
35
+ class Acl < BrokerObject
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+ module Management
22
+ # Representation of a binding in the broker. Properties include:
23
+ # - arguments
24
+ # - bindingKey
25
+ # - exchangeRef
26
+ # - msgMatched
27
+ # - queueRef
28
+ class Binding < BrokerObject
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+ module Management
22
+ # Representation of a bridge to another broker. Properties include:
23
+ # - channelId
24
+ # - dest
25
+ # - durable
26
+ # - dynamic
27
+ # - excludes
28
+ # - key
29
+ # - linkRef
30
+ # - name
31
+ # - src
32
+ # - srcIsLocal
33
+ # - srcIsQueue
34
+ # - sync
35
+ # - tag
36
+ class Bridge < BrokerObject
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,278 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+ module Management
22
+ # Representation of the broker. Properties include:
23
+ # - abandoned
24
+ # - abandonedViaAlt
25
+ # - acquires
26
+ # - byteDepth
27
+ # - byteFtdDepth
28
+ # - byteFtdDequeues
29
+ # - byteFtdEnqueues
30
+ # - bytePersistDequeues
31
+ # - bytePersistEnqueues
32
+ # - byteTotalDequeues
33
+ # - byteTotalEnqueues
34
+ # - byteTxnDequeues
35
+ # - byteTxnEnqueues
36
+ # - connBacklog
37
+ # - dataDir
38
+ # - discardsLvq
39
+ # - discardsNoRoute
40
+ # - discardsOverflow
41
+ # - discardsPurge
42
+ # - discardsRing
43
+ # - discardsSubscriber
44
+ # - discardsTtl
45
+ # - maxConns
46
+ # - mgmtPubInterval
47
+ # - mgmtPublish
48
+ # - msgDepth
49
+ # - msgFtdDepth
50
+ # - msgFtdDequeues
51
+ # - msgFtdEnqueues
52
+ # - msgPersistDequeues
53
+ # - msgPersistEnqueues
54
+ # - msgTotalDequeues
55
+ # - msgTotalEnqueues
56
+ # - msgTxnDequeues
57
+ # - msgTxnEnqueues
58
+ # - name
59
+ # - port
60
+ # - queueCount
61
+ # - releases
62
+ # - reroutes
63
+ # - stagingThreshold
64
+ # - systemRef
65
+ # - uptime
66
+ # - version
67
+ # - workerThreads
68
+ class Broker < BrokerObject
69
+ # Adds methods for the specified collections to be able to access all instances
70
+ # of a given collection, as well as a single instance by oid.
71
+ #
72
+ # == Example
73
+ # <tt>has_many :queues</tt> which will add:
74
+ # * <tt>#queues</tt> to retrieve all queues
75
+ # * <tt>#queue(oid)</tt> to retrieve a queue by oid (note, this is the short form of the object id, e.g. "myqueue" for a queue instead of "org.apache.qpid.broker:queue:myqueue"
76
+ #
77
+ # @param collections one or more symbols for the collections of objects a broker manages
78
+ def self.has_many(*collections)
79
+ [*collections].each do |collection|
80
+ singular_form = collection.to_s[0..-2]
81
+ capitalized_type = singular_form.gsub(/^\w/) { $&.upcase }
82
+
83
+ define_method(collection) do
84
+ @agent.find_all_by_class(Qpid::Management::const_get(capitalized_type))
85
+ end
86
+
87
+ define_method(singular_form) do |oid|
88
+ @agent.find_by_object_id(Qpid::Management::const_get(capitalized_type), "org.apache.qpid.broker:#{singular_form}:#{oid}")
89
+ end
90
+ end
91
+ end
92
+
93
+ # Adds method for the specified types to be able to access the singular
94
+ # instance of a given type.
95
+ #
96
+ # == Example
97
+ # <tt>has_one :acl</tt> which will add:
98
+ # * <tt>#acl</tt> to retrieve the Acl data for the Broker
99
+ #
100
+ # @param types one or more symbols for the singular objects a broker manages
101
+ def self.has_one(*types)
102
+ [*types].each do |type|
103
+ capitalized_type = type.to_s.gsub(/^\w/) { $&.upcase }
104
+
105
+ define_method("#{type}") do
106
+ @agent.find_first_by_class(Qpid::Management::const_get(capitalized_type))
107
+ end
108
+ end
109
+ end
110
+
111
+ has_many :connections, :sessions, :subscriptions, :exchanges, :queues, :bindings, :links, :bridges
112
+ has_one :acl, :memory
113
+
114
+ # Adds an exchange to the broker
115
+ # @param [String] type exchange type (fanout, direct, topic, headers, xml)
116
+ # @param [String] name exchange name
117
+ # @param [Hash] options exchange creation options
118
+ def add_exchange(type, name, options={})
119
+ create_broker_object('exchange', name, options.merge!({'exchange-type' => type}))
120
+ end
121
+
122
+ # Deletes an exchange from the broekr
123
+ # @param [String] name exchange name
124
+ def delete_exchange(name)
125
+ invoke_method('delete', {'type' => 'exchange', 'name' => name})
126
+ end
127
+
128
+ # Adds a queue to the broker
129
+ # @param [String] name queue name
130
+ # @param [Hash] options queue creation options
131
+ def add_queue(name, options={})
132
+ create_broker_object('queue', name, options)
133
+ end
134
+
135
+ # Deletes a queue from the broker
136
+ # @param [String] name queue name
137
+ def delete_queue(name)
138
+ invoke_method('delete', {'type' => 'queue', 'name' => name})
139
+ end
140
+
141
+ # Adds a binding from an exchange to a queue
142
+ # @param [String] exchange exchange name
143
+ # @param [String] queue queue name
144
+ # @param [String] key binding key
145
+ # @param [Hash] options binding creation options
146
+ def add_binding(exchange, queue, key="", options={})
147
+ create_broker_object('binding', "#{exchange}/#{queue}/#{key}", options)
148
+ end
149
+
150
+ # Deletes a binding from an exchange to a queue
151
+ # @param [String] exchange exchange name
152
+ # @param [String] queue queue name
153
+ # @param [String] key binding key
154
+ def delete_binding(exchange, queue, key="")
155
+ invoke_method('delete', {'type' => 'binding', 'name' => "#{exchange}/#{queue}/#{key}"})
156
+ end
157
+
158
+ # Adds a link to a remote broker
159
+ # @param [String] name link name
160
+ # @param [String] host remote broker host name or IP address
161
+ # @param [Fixnum] port remote broker port
162
+ # @param [String] transport transport mechanism used to connect to the remote broker
163
+ # @param [Boolean] durable should this link be persistent
164
+ # @param [String] auth_mechanism authentication mechanism to use
165
+ # @param [String] username user name to authenticate with the remote broker
166
+ # @param [String] password password for the user name
167
+ def add_link(name, host, port, transport='tcp', durable=false, auth_mechanism="", username="", password="")
168
+ options = {
169
+ 'host' => host,
170
+ 'port' => port,
171
+ 'transport' => transport,
172
+ 'durable' => durable,
173
+ 'authMechanism' => auth_mechanism,
174
+ 'username' => username,
175
+ 'password' => password
176
+ }
177
+
178
+ create_broker_object('link', name, options)
179
+ end
180
+
181
+ # Deletes a link to a remote broker
182
+ # @param [String] name link name
183
+ def delete_link(name)
184
+ invoke_method('delete', {'type' => 'link', 'name' => name})
185
+ end
186
+
187
+ # Adds a queue route
188
+ # @param [String] name the name of the bridge to create
189
+ # @param [Hash] options options for the queue route
190
+ # @option options [String] :link the name of the link to use (required)
191
+ # @option options [String] :queue the name of the source queue from which messages are pulled (required)
192
+ # @option options [String] :exchange the name of the destination exchange to which messages are sent (required)
193
+ # @option options [Fixnum] :sync the number of messages to send before issuing an explicit session sync (required)
194
+ def add_queue_route(name, options={})
195
+ validate_options(options, [:link, :queue, :exchange, :sync])
196
+
197
+ properties = {
198
+ 'link' => options[:link],
199
+ 'src' => options[:queue],
200
+ 'dest' => options[:exchange],
201
+ 'srcIsQueue' => true,
202
+ 'sync' => options[:sync]
203
+ }
204
+
205
+ create_broker_object('bridge', name, properties)
206
+ end
207
+
208
+ # Adds an exchange route
209
+ # @param [String] name the name of the bridge to create
210
+ # @param [Hash] options options for the exchange route
211
+ # @option options [String] :link the name of the link to use (required)
212
+ # @option options [String] :exchange the name of the exchange to use (required)
213
+ # @option options [String] :key routing key to federate (required)
214
+ # @option options [Fixnum] :sync the number of messages to send before issuing an explicit session sync (required)
215
+ # @option options [String] :bridge_queue name of the queue to use as a bridge queue (optional)
216
+ def add_exchange_route(name, options={})
217
+ validate_options(options, [:link, :exchange, :key, :sync])
218
+
219
+ properties = {
220
+ 'link' => options[:link],
221
+ 'src' => options[:exchange],
222
+ 'dest' => options[:exchange],
223
+ 'key' => options[:key],
224
+ 'sync' => options[:sync]
225
+ }
226
+
227
+ properties['queue'] = options[:bridge_queue] if options.has_key?(:bridge_queue)
228
+
229
+ create_broker_object('bridge', name, properties)
230
+ end
231
+
232
+ # Adds a dynamic route
233
+ # @param [String] name the name of the bridge to create
234
+ # @param [Hash] options options for the dynamic route
235
+ # @option options [String] :link the name of the link to use (required)
236
+ # @option options [String] :exchange the name of the exchange to use (required)
237
+ # @option options [Fixnum] :sync the number of messages to send before issuing an explicit session sync (required)
238
+ # @option options [String] :bridge_queue name of the queue to use as a bridge queue (optional)
239
+ def add_dynamic_route(name, options={})
240
+ validate_options(options, [:link, :exchange, :sync])
241
+
242
+ properties = {
243
+ 'link' => options[:link],
244
+ 'src' => options[:exchange],
245
+ 'dest' => options[:exchange],
246
+ 'dynamic' => true,
247
+ 'sync' => options[:sync]
248
+ }
249
+
250
+ properties['queue'] = options[:bridge_queue] if options.has_key?(:bridge_queue)
251
+
252
+ create_broker_object('bridge', name, properties)
253
+ end
254
+
255
+ # Deletes a bridge (route)
256
+ # @param [String] name bridge name
257
+ def delete_bridge(name)
258
+ invoke_method('delete', {'type' => 'bridge', 'name' => name})
259
+ end
260
+
261
+ private
262
+
263
+ def create_broker_object(type, name, options)
264
+ invoke_method('create', {'type' => type,
265
+ 'name' => name,
266
+ 'properties' => options,
267
+ 'strict' => true})
268
+ end
269
+
270
+ def validate_options(options, required)
271
+ required.each do |req|
272
+ raise "Option :#{req.to_s} is required" unless options.has_key?(req)
273
+ end
274
+ end
275
+
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,173 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ # for simplistic UUID - may want to consider something better in the future
21
+ require 'securerandom'
22
+
23
+ # Ruby 1.8 doesn't include SecureRandom#uuid, so let's add it if it's missing
24
+ unless SecureRandom.respond_to? :uuid
25
+ module SecureRandom
26
+ def self.uuid
27
+ ary = self.random_bytes(16).unpack("NnnnnN")
28
+ ary[2] = (ary[2] & 0x0fff) | 0x4000
29
+ ary[3] = (ary[3] & 0x3fff) | 0x8000
30
+ "%08x-%04x-%04x-%04x-%04x%08x" % ary
31
+ end
32
+ end
33
+ end
34
+
35
+ module Qpid
36
+ module Management
37
+ # This is the primary class that interacts with a Qpid messaging broker for
38
+ # querying information from the broker and for configuring it.
39
+ class BrokerAgent
40
+ # Creates a new BrokerAgent instance. A new Qpid::Messaging::Session,
41
+ # Qpid::Messaging::Receiver, and Qpid::Messaging::Sender will be created
42
+ # so this instance of the BrokerAgent may send requests to the broker
43
+ # and receive replies back.
44
+ # @param [Qpid::Messaging::Connection] connection a valid, opened connection
45
+ def initialize(connection)
46
+ @connection = connection
47
+ @session = @connection.create_session()
48
+ @reply_to = "qmf.default.topic/direct.#{SecureRandom.uuid}; {node: {type:topic}, link:{x-declare:{auto-delete:True,exclusive:True}}}"
49
+ @reply_rx = @session.create_receiver(@reply_to)
50
+ @reply_rx.capacity = 10
51
+ @tx = @session.create_sender("qmf.default.direct/broker")
52
+ end
53
+
54
+ # Closes the Qpid::Messaging::Session for this BrokerAgent.
55
+ def close()
56
+ @session.close()
57
+ end
58
+
59
+ # Queries the broker for the Broker QMF object.
60
+ # @return [Broker] the broker QMF object
61
+ def broker()
62
+ find_first_by_class(Broker)
63
+ end
64
+
65
+ # Queries the broker for the Cluster QMF object.
66
+ # @return [Cluster] the cluster QMF object
67
+ def cluster
68
+ find_first_by_class(Cluster)
69
+ end
70
+
71
+ # Queries the broker for the HaBroker QMF object.
72
+ # @return [HaBroker] the HA broker QMF object
73
+ def ha_broker
74
+ find_first_by_class(HaBroker)
75
+ end
76
+
77
+ # Invokes a method on a target object.
78
+ # @param [String] method the name of the method to invoke
79
+ # @param [Hash] args the arguments to pass to the method
80
+ # @param [String] addr the full id of the target object
81
+ # @param [Fixnum] timeout the amount of time to wait for the broker to respond to the method invocation
82
+ def invoke_method(method, args, addr="org.apache.qpid.broker:broker:amqp-broker", timeout=10)
83
+ content = {'_object_id' => {'_object_name' => addr},
84
+ '_method_name' => method,
85
+ '_arguments' => args}
86
+
87
+ message = Qpid::Messaging::Message.new()
88
+ message.content = content
89
+ message.reply_to = @reply_to
90
+ message['method'] = 'request'
91
+ message['qmf.opcode'] = '_method_request'
92
+ message['x-amqp-0-10.app-id'] = 'qmf2'
93
+ message.subject = 'broker'
94
+
95
+ @tx.send(message)
96
+
97
+ response = @reply_rx.fetch(Qpid::Messaging::Duration.new(timeout * 1000))
98
+ @session.acknowledge()
99
+
100
+ raise "Exception from Agent: #{response.content['_values']}" if response.properties['qmf.opcode'] == '_exception'
101
+ raise "Bad response: #{response.properties}" if response.properties['qmf.opcode'] != '_method_response'
102
+
103
+ return response.content['_arguments']
104
+ end
105
+
106
+ def send_query(query)
107
+ message = Qpid::Messaging::Message.new()
108
+ message.content = query
109
+ message.reply_to = @reply_to
110
+ message['method'] = 'request'
111
+ message['qmf.opcode'] = '_query_request'
112
+ message['x-amqp-0-10.app-id'] = 'qmf2'
113
+ message.subject = 'broker'
114
+
115
+ @tx.send(message)
116
+
117
+ response = @reply_rx.fetch(Qpid::Messaging::Duration.new(10*1000))
118
+ @session.acknowledge()
119
+
120
+ raise 'Bad response' if response.properties['qmf.opcode'] != '_query_response'
121
+
122
+ items = response.content
123
+
124
+ while response.properties.has_key?('partial')
125
+ response = @reply_rx.fetch(Qpid::Messaging::Duration.new(10*1000))
126
+ items += response.content
127
+ @session.acknowledge()
128
+ end
129
+
130
+ return items
131
+ end
132
+
133
+ def find_all_by_class(clazz)
134
+ query = {
135
+ '_what' => 'OBJECT',
136
+ '_schema_id' => {
137
+ '_class_name' => BrokerObject.qmf_class(clazz)
138
+ }
139
+ }
140
+
141
+ items = send_query(query)
142
+
143
+ [].tap do |objs|
144
+ for item in items
145
+ objs << clazz.new(self, item)
146
+ end
147
+ end
148
+ end
149
+
150
+ def find_first_by_class(clazz)
151
+ objects = find_all_by_class(clazz)
152
+ return objects[0] if objects.size > 0
153
+ return nil
154
+ end
155
+
156
+ def find_by_object_id(clazz, oid)
157
+ query = {
158
+ '_what' => 'OBJECT',
159
+ '_object_id' => {
160
+ '_object_name' => oid
161
+ }
162
+ }
163
+
164
+ results = send_query(query)
165
+
166
+ return clazz.new(self, results[0]) if results.count == 1 and not results[0].nil?
167
+
168
+ # return nil if not found
169
+ return nil
170
+ end
171
+ end
172
+ end
173
+ end