cuboid 0.0.3alpha → 0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +14 -13
- data/cuboid.gemspec +1 -1
- data/lib/cuboid/application.rb +10 -10
- data/lib/cuboid/option_groups/agent.rb +54 -0
- data/lib/cuboid/option_groups/paths.rb +13 -4
- data/lib/cuboid/options.rb +1 -1
- data/lib/cuboid/processes/{dispatchers.rb → agents.rb} +40 -26
- data/lib/cuboid/processes/executables/agent.rb +5 -0
- data/lib/cuboid/processes/helpers/agents.rb +23 -0
- data/lib/cuboid/processes/helpers/instances.rb +4 -4
- data/lib/cuboid/processes/helpers.rb +1 -1
- data/lib/cuboid/processes/instances.rb +22 -10
- data/lib/cuboid/processes/schedulers.rb +16 -3
- data/lib/cuboid/processes.rb +2 -2
- data/lib/cuboid/rest/server/instance_helpers.rb +13 -13
- data/lib/cuboid/rest/server/routes/dispatcher.rb +11 -11
- data/lib/cuboid/rest/server/routes/grid.rb +8 -8
- data/lib/cuboid/rest/server/routes/instances.rb +1 -1
- data/lib/cuboid/rest/server.rb +5 -5
- data/lib/cuboid/rpc/client/{dispatcher.rb → agent.rb} +4 -4
- data/lib/cuboid/rpc/client/instance.rb +2 -2
- data/lib/cuboid/rpc/client.rb +1 -1
- data/lib/cuboid/rpc/server/agent/node.rb +247 -0
- data/lib/cuboid/rpc/server/{dispatcher → agent}/service.rb +13 -13
- data/lib/cuboid/rpc/server/{dispatcher.rb → agent.rb} +62 -32
- data/lib/cuboid/rpc/server/application_wrapper.rb +5 -4
- data/lib/cuboid/rpc/server/instance.rb +4 -4
- data/lib/cuboid/rpc/server/scheduler.rb +13 -12
- data/lib/version +1 -1
- data/spec/cuboid/option_groups/dispatcher_spec.rb +2 -2
- data/spec/cuboid/option_groups/paths_spec.rb +6 -3
- data/spec/cuboid/rest/server_spec.rb +45 -45
- data/spec/cuboid/rpc/client/dispatcher_spec.rb +2 -2
- data/spec/cuboid/rpc/server/dispatcher/node_spec.rb +65 -65
- data/spec/cuboid/rpc/server/dispatcher/service_spec.rb +16 -16
- data/spec/cuboid/rpc/server/dispatcher_spec.rb +187 -72
- data/spec/cuboid/rpc/server/scheduler_spec.rb +8 -8
- data/spec/support/fixtures/executables/node.rb +3 -3
- data/spec/support/fixtures/mock_app/test_service.rb +8 -8
- data/spec/support/fixtures/mock_app.rb +1 -1
- data/spec/support/fixtures/services/echo.rb +6 -6
- data/spec/support/helpers/resets.rb +1 -1
- data/spec/support/lib/web_server_client.rb +2 -2
- data/spec/support/lib/web_server_dispatcher.rb +1 -1
- metadata +18 -58
- data/lib/cuboid/option_groups/dispatcher.rb +0 -38
- data/lib/cuboid/processes/executables/dispatcher.rb +0 -5
- data/lib/cuboid/processes/helpers/dispatchers.rb +0 -23
- data/lib/cuboid/rpc/server/dispatcher/node.rb +0 -247
- data/spec/support/logs/Dispatcher - 51489-29703.log +0 -6
- data/spec/support/logs/Scheduler - 51474-42556.log +0 -3
- data/spec/support/logs/Scheduler - 51477-63074.log +0 -6
- data/spec/support/logs/Scheduler - 51496-16039.log +0 -3
- data/spec/support/logs/Scheduler - 51499-40309.log +0 -6
- data/spec/support/logs/Scheduler - 51521-54983.log +0 -4
- data/spec/support/logs/Scheduler - 51533-50145.log +0 -1
- data/spec/support/logs/Scheduler - 51537-26476.log +0 -3
- data/spec/support/logs/Scheduler - 51541-33347.log +0 -6
- data/spec/support/logs/Scheduler - 51556-5765.log +0 -3
- data/spec/support/logs/Scheduler - 51559-22349.log +0 -6
- data/spec/support/logs/Scheduler - 51567-20476.log +0 -3
- data/spec/support/logs/Scheduler - 51570-37548.log +0 -6
- data/spec/support/logs/Scheduler - 52668-26175.log +0 -3
- data/spec/support/reports/3480c2e4463df854d3457b247e3ba679.crf +0 -0
- data/spec/support/reports/45958408cb49a7f3391a973e05bf673b.crf +0 -0
- data/spec/support/reports/62a7f8d6c8914bb086e7e5f8c418d974.crf +0 -0
- data/spec/support/reports/6363927e13ec27b5cbd973b86bd8e52c.crf +0 -0
- data/spec/support/reports/b68f94be3aa96d0c27477dcfe1e25143.crf +0 -0
- data/spec/support/reports/bbb7496056393de17e72855a63d3acfb.crf +0 -0
@@ -14,23 +14,25 @@ class Server
|
|
14
14
|
#
|
15
15
|
# The process goes something like this:
|
16
16
|
#
|
17
|
-
# * A client issues a {#
|
18
|
-
# * The
|
17
|
+
# * A client issues a {#spawn} call.
|
18
|
+
# * The Agent spawns and returns Instance info to the client (url, auth token, etc.).
|
19
19
|
# * The client connects to the Instance using that info.
|
20
20
|
#
|
21
21
|
# Once the client finishes using the RPC Instance it *must* shut it down
|
22
22
|
# otherwise the system will be eaten away by zombie processes.
|
23
23
|
#
|
24
24
|
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
25
|
-
class
|
26
|
-
require Options.paths.lib + 'rpc/server/
|
27
|
-
require Options.paths.lib + 'rpc/server/
|
25
|
+
class Agent
|
26
|
+
require Options.paths.lib + 'rpc/server/agent/node'
|
27
|
+
require Options.paths.lib + 'rpc/server/agent/service'
|
28
28
|
|
29
29
|
include Utilities
|
30
30
|
include UI::Output
|
31
31
|
|
32
32
|
SERVICE_NAMESPACE = Service
|
33
33
|
|
34
|
+
PREFERENCE_STRATEGIES = Cuboid::OptionGroups::Agent::STRATEGIES
|
35
|
+
|
34
36
|
def initialize( options = Options.instance )
|
35
37
|
@options = options
|
36
38
|
|
@@ -44,20 +46,20 @@ class Dispatcher
|
|
44
46
|
method.parameters.flatten.include? :block
|
45
47
|
end
|
46
48
|
|
47
|
-
Options.
|
49
|
+
Options.agent.url = @url = @server.url
|
48
50
|
|
49
51
|
prep_logging
|
50
52
|
|
51
53
|
print_status 'Starting the RPC Server...'
|
52
54
|
|
53
|
-
@server.add_handler( '
|
55
|
+
@server.add_handler( 'agent', self )
|
54
56
|
|
55
57
|
# trap interrupts and exit cleanly when required
|
56
58
|
trap_interrupts { shutdown }
|
57
59
|
|
58
60
|
@instances = []
|
59
61
|
|
60
|
-
Cuboid::Application.application.
|
62
|
+
Cuboid::Application.application.agent_services.each do |name, service|
|
61
63
|
@server.add_handler( name.to_s, service.new( @options, self ) )
|
62
64
|
end
|
63
65
|
|
@@ -68,7 +70,7 @@ class Dispatcher
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def services
|
71
|
-
Cuboid::Application.application.
|
73
|
+
Cuboid::Application.application.agent_services.keys
|
72
74
|
end
|
73
75
|
|
74
76
|
# @return [TrueClass]
|
@@ -77,13 +79,24 @@ class Dispatcher
|
|
77
79
|
@server.alive?
|
78
80
|
end
|
79
81
|
|
82
|
+
# @param [Symbol] strategy
|
83
|
+
# `:horizontal` -- Pick the Agent with the least amount of workload.
|
84
|
+
# `:vertical` -- Pick the Agent with the most amount of workload.
|
85
|
+
#
|
80
86
|
# @return [String, nil]
|
81
|
-
# Depending on availability:
|
87
|
+
# Depending on strategy and availability:
|
82
88
|
#
|
83
|
-
# * URL of the
|
84
|
-
#
|
85
|
-
# * `nil` if all nodes are at max utilization.
|
86
|
-
|
89
|
+
# * URL of the preferred Agent. If not a grid member it will return
|
90
|
+
# this Agent's URL.
|
91
|
+
# * `nil` if all nodes are at max utilization or on error.
|
92
|
+
# * `ArgumentError` -- On invalid `strategy`.
|
93
|
+
def preferred( strategy = Cuboid::Options.agent.strategy, &block )
|
94
|
+
strategy = strategy.to_sym
|
95
|
+
if !PREFERENCE_STRATEGIES.include? strategy
|
96
|
+
block.call :error_unknown_strategy
|
97
|
+
raise ArgumentError, "Unknown strategy: #{strategy}"
|
98
|
+
end
|
99
|
+
|
87
100
|
if !@node.grid_member?
|
88
101
|
block.call( self.utilization == 1 ? nil : @url )
|
89
102
|
return
|
@@ -94,9 +107,19 @@ class Dispatcher
|
|
94
107
|
nil : [url, utilization]
|
95
108
|
end
|
96
109
|
|
97
|
-
|
98
|
-
|
99
|
-
|
110
|
+
adjust_score_by_strategy = proc do |score|
|
111
|
+
case strategy
|
112
|
+
when :horizontal
|
113
|
+
score
|
114
|
+
|
115
|
+
when :vertical
|
116
|
+
-score
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
each = proc do |peer, iter|
|
121
|
+
connect_to_peer( peer ).utilization do |utilization|
|
122
|
+
iter.return pick_utilization.call( peer, utilization )
|
100
123
|
end
|
101
124
|
end
|
102
125
|
|
@@ -110,41 +133,48 @@ class Dispatcher
|
|
110
133
|
next
|
111
134
|
end
|
112
135
|
|
113
|
-
block.call nodes.sort_by { |_, score| score }[0][0]
|
136
|
+
block.call nodes.sort_by { |_, score| adjust_score_by_strategy.call score }[0][0]
|
114
137
|
end
|
115
138
|
|
116
|
-
Arachni::Reactor.global.create_iterator( @node.
|
139
|
+
Arachni::Reactor.global.create_iterator( @node.peers ).map( each, after )
|
117
140
|
end
|
118
141
|
|
119
142
|
# Dispatches an {Instance}.
|
120
143
|
#
|
121
|
-
# @param [String]
|
144
|
+
# @param [String] options
|
145
|
+
# @option [String] strategy
|
146
|
+
# @option [String] owner
|
122
147
|
# An owner to assign to the {Instance}.
|
123
|
-
# @
|
148
|
+
# @option [Hash] helpers
|
124
149
|
# Hash of helper data to be added to the instance info.
|
125
|
-
# @
|
126
|
-
#
|
127
|
-
# or from this one directly?
|
150
|
+
# @option [Boolean] load_balance
|
151
|
+
# Use the Grid (when available) or this one directly?
|
128
152
|
#
|
129
153
|
# @return [Hash, nil]
|
130
154
|
# Depending on availability:
|
131
155
|
#
|
132
156
|
# * `Hash`: Connection and proc info.
|
133
157
|
# * `nil`: Max utilization, wait for one of the instances to finish and retry.
|
134
|
-
def
|
158
|
+
def spawn( options = {}, &block )
|
135
159
|
options = options.my_symbolize_keys
|
160
|
+
strategy = options.delete(:strategy)
|
136
161
|
owner = options[:owner]
|
137
162
|
helpers = options[:helpers] || {}
|
138
163
|
load_balance = options[:load_balance].nil? ? true : options[:load_balance]
|
139
164
|
|
140
165
|
if load_balance && @node.grid_member?
|
141
|
-
preferred do |url|
|
166
|
+
preferred *[strategy].compact do |url|
|
142
167
|
if !url
|
143
168
|
block.call
|
144
169
|
next
|
145
170
|
end
|
146
171
|
|
147
|
-
|
172
|
+
if url == :error_unknown_strategy
|
173
|
+
block.call :error_unknown_strategy
|
174
|
+
next
|
175
|
+
end
|
176
|
+
|
177
|
+
connect_to_peer( url ).spawn( options.merge(
|
148
178
|
helpers: helpers.merge( via: @url ),
|
149
179
|
load_balance: false
|
150
180
|
),
|
@@ -214,7 +244,7 @@ class Dispatcher
|
|
214
244
|
end
|
215
245
|
|
216
246
|
# @return [Float]
|
217
|
-
# Workload score for this
|
247
|
+
# Workload score for this Agent, calculated using {System#utilization}.
|
218
248
|
#
|
219
249
|
# * `0.0` => No utilization.
|
220
250
|
# * `1.0` => Max utilization.
|
@@ -256,7 +286,7 @@ class Dispatcher
|
|
256
286
|
end
|
257
287
|
end
|
258
288
|
|
259
|
-
# Starts the
|
289
|
+
# Starts the agent's server
|
260
290
|
def run
|
261
291
|
Arachni::Reactor.global.on_error do |_, e|
|
262
292
|
print_error "Reactor: #{e}"
|
@@ -285,7 +315,7 @@ class Dispatcher
|
|
285
315
|
def spawn_instance( options = {}, &block )
|
286
316
|
Processes::Instances.spawn( options.merge(
|
287
317
|
address: @server.address,
|
288
|
-
port_range: Options.
|
318
|
+
port_range: Options.agent.instance_port_range,
|
289
319
|
token: Utilities.generate_token,
|
290
320
|
application: Options.paths.application
|
291
321
|
)) do |client|
|
@@ -302,12 +332,12 @@ class Dispatcher
|
|
302
332
|
def prep_logging
|
303
333
|
# reroute all output to a logfile
|
304
334
|
@logfile ||= reroute_to_file( @options.paths.logs +
|
305
|
-
"/
|
335
|
+
"/Agent - #{Process.pid}-#{@options.rpc.server_port}.log" )
|
306
336
|
end
|
307
337
|
|
308
338
|
def connect_to_peer( url )
|
309
339
|
@rpc_clients ||= {}
|
310
|
-
@rpc_clients[url] ||= Client::
|
340
|
+
@rpc_clients[url] ||= Client::Agent.new( url )
|
311
341
|
end
|
312
342
|
|
313
343
|
end
|
@@ -15,9 +15,10 @@ class ApplicationWrapper
|
|
15
15
|
attr_reader :application
|
16
16
|
|
17
17
|
extend Forwardable
|
18
|
-
def_delegators :@application, :suspended?, :suspend!, :status,
|
19
|
-
:pause!, :running?, :status_messages, :paused?,
|
20
|
-
:snapshot_path, :restore!, :resume!, :generate_report
|
18
|
+
def_delegators :@application, :suspended?, :suspending?, :suspend!, :status,
|
19
|
+
:pause!, :running?, :status_messages, :paused?, :pausing?,
|
20
|
+
:snapshot_path, :restore!, :resume!, :generate_report,
|
21
|
+
:abort!, :aborting?, :aborted?
|
21
22
|
|
22
23
|
# {RPC::Server::Application} error namespace.
|
23
24
|
#
|
@@ -110,7 +111,7 @@ class ApplicationWrapper
|
|
110
111
|
busy: running?,
|
111
112
|
application: @application.class.to_s,
|
112
113
|
seed: Utilities.random_seed,
|
113
|
-
|
114
|
+
agent_url: Cuboid::Options.agent.url,
|
114
115
|
scheduler_url: Cuboid::Options.scheduler.url
|
115
116
|
}
|
116
117
|
|
@@ -90,10 +90,10 @@ class Instance
|
|
90
90
|
end
|
91
91
|
|
92
92
|
# @return [String, nil]
|
93
|
-
#
|
94
|
-
#
|
95
|
-
def
|
96
|
-
@options.
|
93
|
+
# Agent URL that provided this Instance, `nil` if not provided by a
|
94
|
+
# Agent.
|
95
|
+
def agent_url
|
96
|
+
@options.agent.url
|
97
97
|
end
|
98
98
|
|
99
99
|
# @param (see Cuboid::Application#restore)
|
@@ -6,7 +6,7 @@ require lib + 'processes/manager'
|
|
6
6
|
require lib + 'processes/instances'
|
7
7
|
|
8
8
|
require lib + 'rpc/client/instance'
|
9
|
-
require lib + 'rpc/client/
|
9
|
+
require lib + 'rpc/client/agent'
|
10
10
|
|
11
11
|
require lib + 'rpc/server/base'
|
12
12
|
require lib + 'rpc/server/output'
|
@@ -33,9 +33,9 @@ class Server
|
|
33
33
|
# * {#attach Attached} to the queue monitor and transfer the management
|
34
34
|
# responsibility to the queue.
|
35
35
|
#
|
36
|
-
# If a {
|
37
|
-
# {
|
38
|
-
# If no {
|
36
|
+
# If a {Agent} has been provided, {Instance instances} will be
|
37
|
+
# {Agent#spawn provided} by it.
|
38
|
+
# If no {Agent} has been given, {Instance instances} will be spawned on the
|
39
39
|
# Scheduler machine.
|
40
40
|
#
|
41
41
|
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
@@ -379,7 +379,7 @@ class Scheduler
|
|
379
379
|
end
|
380
380
|
end
|
381
381
|
|
382
|
-
# Starts the
|
382
|
+
# Starts the agent's server
|
383
383
|
def run
|
384
384
|
reactor.on_error do |_, e|
|
385
385
|
print_error "Reactor: #{e}"
|
@@ -415,15 +415,16 @@ class Scheduler
|
|
415
415
|
)
|
416
416
|
end
|
417
417
|
|
418
|
-
def
|
419
|
-
return if !Options.
|
420
|
-
@
|
418
|
+
def agent
|
419
|
+
return if !Options.agent.url
|
420
|
+
@agent ||= RPC::Client::Agent.new( Options.agent.url )
|
421
421
|
end
|
422
422
|
|
423
423
|
def spawn_instance( &block )
|
424
|
-
if
|
424
|
+
if agent
|
425
425
|
options = {
|
426
|
-
owner:
|
426
|
+
owner: self.class.to_s,
|
427
|
+
strategy: Cuboid::Options.agent.strategy,
|
427
428
|
helpers: {
|
428
429
|
owner: {
|
429
430
|
url: @url
|
@@ -431,9 +432,9 @@ class Scheduler
|
|
431
432
|
}
|
432
433
|
}
|
433
434
|
|
434
|
-
|
435
|
+
agent.spawn options do |info|
|
435
436
|
if info.rpc_exception?
|
436
|
-
print_error "Failed to contact
|
437
|
+
print_error "Failed to contact Agent at: #{agent.url}"
|
437
438
|
print_error "[#{info.class}] #{info.to_s}"
|
438
439
|
block.call :error
|
439
440
|
next
|
data/lib/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Cuboid::OptionGroups::
|
3
|
+
describe Cuboid::OptionGroups::Agent do
|
4
4
|
include_examples 'option_group'
|
5
5
|
subject { described_class.new }
|
6
6
|
|
7
|
-
%w(url instance_port_range
|
7
|
+
%w(url instance_port_range peer ping_interval name).each do |method|
|
8
8
|
it { is_expected.to respond_to method }
|
9
9
|
it { is_expected.to respond_to "#{method}=" }
|
10
10
|
end
|
@@ -70,7 +70,7 @@ describe Cuboid::OptionGroups::Paths do
|
|
70
70
|
|
71
71
|
describe '#logs' do
|
72
72
|
it 'returns the default location' do
|
73
|
-
expect(subject.logs).to eq("#{subject.
|
73
|
+
expect(subject.logs).to eq("#{subject.home_path}logs/")
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'when the CUBOID_LOGDIR environment variable' do
|
@@ -91,13 +91,14 @@ describe Cuboid::OptionGroups::Paths do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
expect(described_class.new.logs).to eq('logs-stuff/')
|
94
|
+
@created_resources << described_class.new.logs
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
98
99
|
describe '#snapshots' do
|
99
100
|
it 'returns the default location' do
|
100
|
-
expect(subject.snapshots).to eq("#{subject.
|
101
|
+
expect(subject.snapshots).to eq("#{subject.home_path}snapshots/")
|
101
102
|
end
|
102
103
|
|
103
104
|
context "when #{described_class}.config['snapshots']" do
|
@@ -109,13 +110,14 @@ describe Cuboid::OptionGroups::Paths do
|
|
109
110
|
end
|
110
111
|
|
111
112
|
expect(described_class.new.snapshots).to eq('snapshots-stuff/')
|
113
|
+
@created_resources << described_class.new.snapshots
|
112
114
|
end
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
116
118
|
describe '#reports' do
|
117
119
|
it 'returns the default location' do
|
118
|
-
expect(subject.reports).to eq("#{subject.
|
120
|
+
expect(subject.reports).to eq("#{subject.home_path}reports/")
|
119
121
|
end
|
120
122
|
|
121
123
|
context "when #{described_class}.config['reports']" do
|
@@ -127,6 +129,7 @@ describe Cuboid::OptionGroups::Paths do
|
|
127
129
|
end
|
128
130
|
|
129
131
|
expect(described_class.new.reports).to eq('reports-stuff/')
|
132
|
+
@created_resources << described_class.new.reports
|
130
133
|
end
|
131
134
|
end
|
132
135
|
end
|
@@ -15,7 +15,7 @@ describe Cuboid::Rest::Server do
|
|
15
15
|
let(:id) { @id }
|
16
16
|
let(:non_existent_id) { 'stuff' }
|
17
17
|
|
18
|
-
let(:
|
18
|
+
let(:agent) { Cuboid::Processes::Agents.spawn }
|
19
19
|
let(:scheduler) { Cuboid::Processes::Schedulers.spawn }
|
20
20
|
|
21
21
|
def create_instance
|
@@ -235,17 +235,17 @@ describe Cuboid::Rest::Server do
|
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
|
-
context 'when a
|
238
|
+
context 'when a Agent has been set' do
|
239
239
|
|
240
240
|
it 'uses it' do
|
241
|
-
put '/
|
241
|
+
put '/agent/url', agent.url
|
242
242
|
|
243
|
-
get "/grid/#{
|
243
|
+
get "/grid/#{agent.url}"
|
244
244
|
expect(response_data['running_instances']).to be_empty
|
245
245
|
|
246
246
|
create_instance
|
247
247
|
|
248
|
-
get "/grid/#{
|
248
|
+
get "/grid/#{agent.url}"
|
249
249
|
expect(response_data['running_instances'].size).to eq 1
|
250
250
|
end
|
251
251
|
end
|
@@ -623,32 +623,32 @@ describe Cuboid::Rest::Server do
|
|
623
623
|
end
|
624
624
|
end
|
625
625
|
|
626
|
-
describe 'GET /
|
627
|
-
let(:tpl_url) { '/
|
626
|
+
describe 'GET /agent/url' do
|
627
|
+
let(:tpl_url) { '/agent/url' }
|
628
628
|
|
629
|
-
it 'returns the
|
630
|
-
put url,
|
629
|
+
it 'returns the Agent' do
|
630
|
+
put url, agent.url
|
631
631
|
expect(response_code).to eq 200
|
632
632
|
|
633
633
|
get url
|
634
634
|
expect(response_code).to eq 200
|
635
|
-
expect(response_data).to eq
|
635
|
+
expect(response_data).to eq agent.url
|
636
636
|
end
|
637
637
|
|
638
|
-
context 'when no
|
638
|
+
context 'when no Agent has been set' do
|
639
639
|
it 'returns 501' do
|
640
640
|
get url
|
641
641
|
expect(response_code).to eq 501
|
642
|
-
expect(response_data).to eq 'No
|
642
|
+
expect(response_data).to eq 'No Agent has been set.'
|
643
643
|
end
|
644
644
|
end
|
645
645
|
end
|
646
646
|
|
647
|
-
describe 'PUT /
|
648
|
-
let(:tpl_url) { '/
|
647
|
+
describe 'PUT /agent/url' do
|
648
|
+
let(:tpl_url) { '/agent/url' }
|
649
649
|
|
650
|
-
it 'sets the
|
651
|
-
put url,
|
650
|
+
it 'sets the Agent' do
|
651
|
+
put url, agent.url
|
652
652
|
expect(response_code).to eq 200
|
653
653
|
end
|
654
654
|
|
@@ -663,101 +663,101 @@ describe Cuboid::Rest::Server do
|
|
663
663
|
end
|
664
664
|
end
|
665
665
|
|
666
|
-
describe 'DELETE /
|
667
|
-
let(:tpl_url) { '/
|
666
|
+
describe 'DELETE /agent/url' do
|
667
|
+
let(:tpl_url) { '/agent/url' }
|
668
668
|
|
669
|
-
it 'removes the the
|
670
|
-
put url,
|
669
|
+
it 'removes the the Agent' do
|
670
|
+
put url, agent.url
|
671
671
|
expect(response_code).to eq 200
|
672
672
|
|
673
673
|
delete url
|
674
674
|
expect(response_code).to eq 200
|
675
675
|
|
676
|
-
get url,
|
676
|
+
get url, agent.url
|
677
677
|
expect(response_code).to eq 501
|
678
678
|
end
|
679
679
|
|
680
|
-
context 'when no
|
680
|
+
context 'when no Agent has been set' do
|
681
681
|
it 'returns 501' do
|
682
682
|
delete url
|
683
683
|
expect(response_code).to eq 501
|
684
|
-
expect(response_data).to eq 'No
|
684
|
+
expect(response_data).to eq 'No Agent has been set.'
|
685
685
|
end
|
686
686
|
end
|
687
687
|
end
|
688
688
|
|
689
689
|
describe 'GET /grid' do
|
690
|
-
let(:
|
690
|
+
let(:agent) { Cuboid::Processes::Agents.grid_spawn }
|
691
691
|
let(:tpl_url) { '/grid' }
|
692
692
|
|
693
693
|
it 'returns Grid info' do
|
694
|
-
put '/
|
694
|
+
put '/agent/url', agent.url
|
695
695
|
expect(response_code).to eq 200
|
696
696
|
|
697
697
|
get url
|
698
698
|
expect(response_code).to eq 200
|
699
|
-
expect(response_data.sort).to eq ([
|
699
|
+
expect(response_data.sort).to eq ([agent.url] + agent.node.peers).sort
|
700
700
|
end
|
701
701
|
|
702
|
-
context 'when no
|
702
|
+
context 'when no Agent has been set' do
|
703
703
|
it 'returns 501' do
|
704
704
|
get url
|
705
705
|
expect(response_code).to eq 501
|
706
|
-
expect(response_data).to eq 'No
|
706
|
+
expect(response_data).to eq 'No Agent has been set.'
|
707
707
|
end
|
708
708
|
end
|
709
709
|
end
|
710
710
|
|
711
|
-
describe 'GET /grid/:
|
712
|
-
let(:
|
711
|
+
describe 'GET /grid/:agent' do
|
712
|
+
let(:agent) { Cuboid::Processes::Agents.grid_spawn }
|
713
713
|
let(:tpl_url) { '/grid/%s' }
|
714
714
|
|
715
|
-
it 'returns
|
716
|
-
put '/
|
715
|
+
it 'returns Agent info' do
|
716
|
+
put '/agent/url', agent.url
|
717
717
|
expect(response_code).to eq 200
|
718
718
|
|
719
|
-
@id =
|
719
|
+
@id = agent.url
|
720
720
|
|
721
721
|
get url
|
722
722
|
expect(response_code).to eq 200
|
723
|
-
expect(response_data).to eq
|
723
|
+
expect(response_data).to eq agent.statistics
|
724
724
|
end
|
725
725
|
|
726
|
-
context 'when no
|
726
|
+
context 'when no Agent has been set' do
|
727
727
|
it 'returns 501' do
|
728
728
|
@id = 'localhost:2222'
|
729
729
|
|
730
730
|
get url
|
731
731
|
expect(response_code).to eq 501
|
732
|
-
expect(response_data).to eq 'No
|
732
|
+
expect(response_data).to eq 'No Agent has been set.'
|
733
733
|
end
|
734
734
|
end
|
735
735
|
end
|
736
736
|
|
737
|
-
describe 'DELETE /grid/:
|
738
|
-
let(:
|
737
|
+
describe 'DELETE /grid/:agent' do
|
738
|
+
let(:agent) { Cuboid::Processes::Agents.grid_spawn }
|
739
739
|
let(:tpl_url) { '/grid/%s' }
|
740
740
|
|
741
|
-
it 'unplugs the
|
742
|
-
put '/
|
741
|
+
it 'unplugs the Agent from the Grid' do
|
742
|
+
put '/agent/url', agent.url
|
743
743
|
expect(response_code).to eq 200
|
744
744
|
|
745
|
-
@id =
|
745
|
+
@id = agent.url
|
746
746
|
|
747
|
-
expect(
|
747
|
+
expect(agent.node.grid_member?).to be_truthy
|
748
748
|
|
749
749
|
delete url
|
750
750
|
expect(response_code).to eq 200
|
751
|
-
expect(
|
751
|
+
expect(agent.node.grid_member?).to be_falsey
|
752
752
|
end
|
753
753
|
|
754
|
-
context 'when no
|
754
|
+
context 'when no Agent has been set' do
|
755
755
|
it 'returns 501' do
|
756
756
|
@id = 'localhost:2222'
|
757
757
|
|
758
758
|
delete url
|
759
759
|
expect(response_code).to eq 501
|
760
|
-
expect(response_data).to eq 'No
|
760
|
+
expect(response_data).to eq 'No Agent has been set.'
|
761
761
|
end
|
762
762
|
end
|
763
763
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
describe Cuboid::RPC::Client::
|
5
|
-
subject {
|
4
|
+
describe Cuboid::RPC::Client::Agent do
|
5
|
+
subject { agent_spawn application: "#{fixtures_path}/mock_app.rb" }
|
6
6
|
|
7
7
|
describe '#node' do
|
8
8
|
it 'provides access to the node data' do
|