cuboid 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +13 -13
- data/lib/cuboid/application.rb +10 -10
- data/lib/cuboid/option_groups/{dispatcher.rb → agent.rb} +9 -9
- data/lib/cuboid/option_groups/paths.rb +1 -1
- data/lib/cuboid/options.rb +1 -1
- data/lib/cuboid/processes/{dispatchers.rb → agents.rb} +25 -25
- 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 +9 -9
- data/lib/cuboid/processes/schedulers.rb +2 -2
- 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} +32 -31
- data/lib/cuboid/rpc/server/application_wrapper.rb +1 -1
- data/lib/cuboid/rpc/server/instance.rb +4 -4
- data/lib/cuboid/rpc/server/scheduler.rb +12 -12
- data/lib/version +1 -1
- data/spec/cuboid/option_groups/dispatcher_spec.rb +2 -2
- 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 +95 -95
- 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 +10 -348
- 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 - 1520492-37227.log +0 -6
- data/spec/support/logs/Dispatcher - 1520680-13689.log +0 -6
- data/spec/support/logs/Dispatcher - 1520682-24167.log +0 -6
- data/spec/support/logs/Dispatcher - 1520688-42731.log +0 -6
- data/spec/support/logs/Dispatcher - 1520690-5750.log +0 -10
- data/spec/support/logs/Dispatcher - 1520692-55183.log +0 -10
- data/spec/support/logs/Dispatcher - 1520695-39752.log +0 -10
- data/spec/support/logs/Dispatcher - 1520697-44327.log +0 -10
- data/spec/support/logs/Dispatcher - 1520699-58785.log +0 -10
- data/spec/support/logs/Dispatcher - 1520701-60952.log +0 -10
- data/spec/support/logs/Dispatcher - 1520796-50420.log +0 -6
- data/spec/support/logs/Dispatcher - 1520894-56883.log +0 -6
- data/spec/support/logs/Dispatcher - 1520896-21419.log +0 -6
- data/spec/support/logs/Dispatcher - 1520898-62584.log +0 -6
- data/spec/support/logs/Dispatcher - 1520900-59721.log +0 -6
- data/spec/support/logs/Dispatcher - 1520910-51632.log +0 -6
- data/spec/support/logs/Dispatcher - 1520920-21801.log +0 -6
- data/spec/support/logs/Dispatcher - 1520930-49223.log +0 -6
- data/spec/support/logs/Dispatcher - 1520933-34241.log +0 -6
- data/spec/support/logs/Dispatcher - 1520935-64571.log +0 -6
- data/spec/support/logs/Dispatcher - 1520937-50734.log +0 -6
- data/spec/support/logs/Dispatcher - 1520939-60841.log +0 -6
- data/spec/support/logs/Dispatcher - 1520944-8124.log +0 -6
- data/spec/support/logs/Dispatcher - 1520946-25192.log +0 -16
- data/spec/support/logs/Dispatcher - 1520948-9752.log +0 -14
- data/spec/support/logs/Dispatcher - 1520952-45543.log +0 -10
- data/spec/support/logs/Dispatcher - 1520958-36653.log +0 -16
- data/spec/support/logs/Dispatcher - 1520960-17456.log +0 -14
- data/spec/support/logs/Dispatcher - 1520964-5774.log +0 -10
- data/spec/support/logs/Dispatcher - 1520976-40848.log +0 -16
- data/spec/support/logs/Dispatcher - 1520978-29867.log +0 -14
- data/spec/support/logs/Dispatcher - 1520982-17715.log +0 -10
- data/spec/support/logs/Dispatcher - 1520987-8925.log +0 -16
- data/spec/support/logs/Dispatcher - 1520989-25480.log +0 -14
- data/spec/support/logs/Dispatcher - 1520993-5124.log +0 -10
- data/spec/support/logs/Dispatcher - 1520999-12901.log +0 -16
- data/spec/support/logs/Dispatcher - 1521004-32265.log +0 -14
- data/spec/support/logs/Dispatcher - 1521008-33455.log +0 -10
- data/spec/support/logs/Dispatcher - 1521014-13779.log +0 -6
- data/spec/support/logs/Dispatcher - 1521017-14755.log +0 -6
- data/spec/support/logs/Dispatcher - 1521022-48687.log +0 -6
- data/spec/support/logs/Dispatcher - 1521024-59097.log +0 -6
- data/spec/support/logs/Dispatcher - 1521034-12604.log +0 -6
- data/spec/support/logs/Dispatcher - 1521038-64272.log +0 -6
- data/spec/support/logs/Dispatcher - 1521043-8680.log +0 -6
- data/spec/support/logs/Dispatcher - 1521047-22949.log +0 -6
- data/spec/support/logs/Dispatcher - 1521051-3355.log +0 -6
- data/spec/support/logs/Dispatcher - 1521074-12332.log +0 -6
- data/spec/support/logs/Dispatcher - 1521118-53130.log +0 -16
- data/spec/support/logs/Dispatcher - 1521128-47137.log +0 -14
- data/spec/support/logs/Dispatcher - 1521136-30328.log +0 -10
- data/spec/support/logs/Dispatcher - 1521161-21329.log +0 -16
- data/spec/support/logs/Dispatcher - 1521172-19183.log +0 -14
- data/spec/support/logs/Dispatcher - 1521179-34902.log +0 -10
- data/spec/support/logs/Dispatcher - 1521190-20155.log +0 -16
- data/spec/support/logs/Dispatcher - 1521204-43843.log +0 -14
- data/spec/support/logs/Dispatcher - 1521211-23972.log +0 -10
- data/spec/support/logs/Dispatcher - 1521237-20879.log +0 -10
- data/spec/support/logs/Dispatcher - 1521239-61999.log +0 -10
- data/spec/support/logs/Dispatcher - 1521242-20975.log +0 -16
- data/spec/support/logs/Dispatcher - 1521246-28409.log +0 -14
- data/spec/support/logs/Dispatcher - 1521250-58505.log +0 -10
- data/spec/support/logs/Dispatcher - 1521262-53292.log +0 -6
- data/spec/support/logs/Dispatcher - 1521266-42758.log +0 -6
- data/spec/support/logs/Dispatcher - 1521277-4215.log +0 -6
- data/spec/support/logs/Dispatcher - 1521292-16086.log +0 -6
- data/spec/support/logs/Dispatcher - 1521301-42112.log +0 -6
- data/spec/support/logs/Dispatcher - 1521312-61196.log +0 -6
- data/spec/support/logs/Dispatcher - 1521316-23353.log +0 -6
- data/spec/support/logs/Dispatcher - 1521321-46361.log +0 -6
- data/spec/support/logs/Dispatcher - 1521438-46016.log +0 -6
- data/spec/support/logs/Dispatcher - 1521454-49862.log +0 -6
- data/spec/support/logs/Dispatcher - 1521470-54737.log +0 -6
- data/spec/support/logs/Instance - 1521353-26273.error.log +0 -105
- data/spec/support/logs/Instance - 1521355-56591.error.log +0 -105
- data/spec/support/logs/Instance - 1521363-26218.error.log +0 -105
- data/spec/support/logs/Scheduler - 1520469-35703.log +0 -3
- data/spec/support/logs/Scheduler - 1520473-60524.log +0 -6
- data/spec/support/logs/Scheduler - 1520509-34951.log +0 -3
- data/spec/support/logs/Scheduler - 1520517-31455.log +0 -6
- data/spec/support/logs/Scheduler - 1520529-43808.log +0 -4
- data/spec/support/logs/Scheduler - 1520536-23387.log +0 -1
- data/spec/support/logs/Scheduler - 1520549-48260.log +0 -3
- data/spec/support/logs/Scheduler - 1520563-45636.log +0 -6
- data/spec/support/logs/Scheduler - 1520599-40643.log +0 -3
- data/spec/support/logs/Scheduler - 1520608-54106.log +0 -6
- data/spec/support/logs/Scheduler - 1520629-24722.log +0 -3
- data/spec/support/logs/Scheduler - 1520637-61755.log +0 -6
- data/spec/support/logs/Scheduler - 1520663-17447.log +0 -4
- data/spec/support/logs/Scheduler - 1520671-38282.log +0 -6
- data/spec/support/logs/Scheduler - 1520703-33082.log +0 -1
- data/spec/support/logs/Scheduler - 1520706-22309.log +0 -1
- data/spec/support/logs/Scheduler - 1520709-1816.log +0 -1
- data/spec/support/logs/Scheduler - 1520711-19998.log +0 -1
- data/spec/support/logs/Scheduler - 1520714-47570.log +0 -1
- data/spec/support/logs/Scheduler - 1520723-18521.log +0 -1
- data/spec/support/logs/Scheduler - 1520725-40913.log +0 -3
- data/spec/support/logs/Scheduler - 1520749-45742.log +0 -6
- data/spec/support/logs/Scheduler - 1520759-44350.log +0 -4
- data/spec/support/logs/Scheduler - 1520770-53219.log +0 -1
- data/spec/support/logs/Scheduler - 1520773-54792.log +0 -1
- data/spec/support/logs/Scheduler - 1520777-19636.log +0 -1
- data/spec/support/logs/Scheduler - 1520780-51801.log +0 -1
- data/spec/support/logs/Scheduler - 1520782-9652.log +0 -3
- data/spec/support/logs/Scheduler - 1520786-59472.log +0 -1
- data/spec/support/logs/Scheduler - 1520789-1603.log +0 -1
- data/spec/support/logs/Scheduler - 1520792-35476.log +0 -1
- data/spec/support/logs/Scheduler - 1521410-47324.log +0 -16
- data/spec/support/logs/Scheduler - 1521422-33737.log +0 -6
- data/spec/support/logs/Scheduler - 1521433-36637.log +0 -6
- data/spec/support/logs/Scheduler - 1521440-15066.log +0 -6
- data/spec/support/logs/Scheduler - 1521456-48637.log +0 -3
- data/spec/support/logs/Scheduler - 1521472-54425.log +0 -5
- data/spec/support/logs/Scheduler - 1521496-12923.log +0 -1
- data/spec/support/logs/Scheduler - 1521518-46819.log +0 -1
- data/spec/support/logs/Scheduler - 1521522-21417.log +0 -1
- data/spec/support/logs/Scheduler - 1521525-35088.log +0 -1
- data/spec/support/logs/Scheduler - 1521528-13676.log +0 -1
- data/spec/support/logs/Scheduler - 1521530-48176.log +0 -1
- data/spec/support/logs/Scheduler - 1521532-13207.log +0 -1
- data/spec/support/logs/Scheduler - 1521535-5799.log +0 -3
- data/spec/support/logs/Scheduler - 1521543-62784.log +0 -3
- data/spec/support/logs/Scheduler - 1521551-10263.log +0 -3
- data/spec/support/logs/Scheduler - 1521556-56026.log +0 -3
- data/spec/support/logs/Scheduler - 1521560-14551.log +0 -4
- data/spec/support/logs/Scheduler - 1521573-47584.log +0 -1
- data/spec/support/logs/Scheduler - 1521578-14443.log +0 -4
- data/spec/support/logs/Scheduler - 1521580-60337.log +0 -1
- data/spec/support/logs/Scheduler - 1521583-52039.log +0 -1
- data/spec/support/logs/Scheduler - 1521586-1500.log +0 -16
- data/spec/support/logs/Scheduler - 1521598-61298.log +0 -4
- data/spec/support/logs/Scheduler - 1521602-61490.log +0 -1
- data/spec/support/logs/Scheduler - 1521604-29209.log +0 -1
- data/spec/support/logs/Scheduler - 1521606-47734.log +0 -1
- data/spec/support/logs/Scheduler - 1521612-63269.log +0 -1
- data/spec/support/logs/Scheduler - 1521614-47018.log +0 -3
- data/spec/support/logs/Scheduler - 1521619-32411.log +0 -1
- data/spec/support/logs/Scheduler - 1521621-42861.log +0 -1
- data/spec/support/logs/Scheduler - 1521623-56258.log +0 -1
- data/spec/support/logs/Scheduler - 1521627-9487.log +0 -1
- data/spec/support/logs/Scheduler - 1521630-3345.log +0 -1
- data/spec/support/logs/Scheduler - 1521632-47325.log +0 -1
- data/spec/support/logs/Scheduler - 1521635-22156.log +0 -2
- data/spec/support/logs/error-1520329.log +0 -797
- data/spec/support/logs/output_spec_1520329.log +0 -390
- data/spec/support/reports/003bed585153336c2548d1c60a026a3e.crf +0 -0
- data/spec/support/reports/30e3c7a8c13e9b40a0a443a5e5a4ff94.crf +0 -0
- data/spec/support/reports/31655751a9f0eee91e588bc796985b1e.crf +0 -0
- data/spec/support/reports/40801b7993c0ed919b73242a9c078dde.crf +0 -0
- data/spec/support/reports/4719b89667e92bb80102f4b0bb4c0c75.crf +0 -0
- data/spec/support/reports/4e765a3d2870d2763ea72167bd3db9d6.crf +0 -0
- data/spec/support/reports/61968f732d8ae715c104175e43679915.crf +0 -0
- data/spec/support/reports/63446a8ec637d9991b8c6a1151ae59a9.crf +0 -0
- data/spec/support/reports/737144b18305c7a115ad7964b9bbe41c.crf +0 -0
- data/spec/support/reports/73fe5f7adf905045c3fe4669bdf60d02.crf +0 -0
- data/spec/support/reports/86cd396db9ef97472876f32e57c44ce7.crf +0 -0
- data/spec/support/reports/8a031ac2b2730dfd07a1d1ca870299f2.crf +0 -0
- data/spec/support/reports/8e16ac74484ee5d8cf7073fe22adf787.crf +0 -0
- data/spec/support/reports/8eff857213ab6ff712a0b0e8582855c9.crf +0 -0
- data/spec/support/reports/9e0e6ed8718973b3d4e63bbb7dd1d1c6.crf +0 -0
- data/spec/support/reports/a9c88f967d09cb9c4e8e1180cfb24828.crf +0 -0
- data/spec/support/reports/ba32970a64686e45ec8caa5032f65c2e.crf +0 -0
- data/spec/support/reports/cceb7596659fd619ab4438953cbda78b.crf +0 -0
- data/spec/support/reports/d2e0f4558b605ffd1215e9226815b951.crf +0 -0
- data/spec/support/snapshots/Cuboid 2022-01-24 14_38_16 +0200 8238609e31cedaf1bcb89205f9d42121.csf +0 -0
- data/spec/support/snapshots/Cuboid 2022-01-24 14_38_30 +0200 68690b002e79c7bc9e3aabfcbc7ac5a7.csf +0 -0
- data/spec/support/snapshots/Cuboid 2022-01-24 14_46_39 +0200 6fd3c9491d3e784e18f9c3c0d9deddec.csf +0 -0
- data/spec/support/snapshots/Cuboid 2022-01-24 14_46_44 +0200 c3a012fba59210bc7c169afb0565d5a8.csf +0 -0
- data/spec/support/snapshots/Cuboid 2022-01-24 14_46_46 +0200 e4c1ce35d8e62e6a16f84eccd36b2283.csf +0 -0
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
require "#{Cuboid::Options.paths.lib}/rpc/server/
|
4
|
+
require "#{Cuboid::Options.paths.lib}/rpc/server/agent"
|
5
5
|
|
6
|
-
describe Cuboid::RPC::Server::
|
6
|
+
describe Cuboid::RPC::Server::Agent do
|
7
7
|
before( :each ) do
|
8
8
|
Cuboid::Options.system.max_slots = slots
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:instance_info_keys) { %w(token application pid url owner birthdate helpers now age) }
|
12
12
|
let(:slots) { 3 }
|
13
|
-
let(:subject) {
|
13
|
+
let(:subject) { agent_spawn( application: "#{fixtures_path}/mock_app.rb" ) }
|
14
14
|
|
15
15
|
describe '#alive?' do
|
16
16
|
it 'returns true' do
|
@@ -19,32 +19,32 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#preferred' do
|
22
|
-
context 'when the
|
22
|
+
context 'when the agent is a grid member' do
|
23
23
|
context 'and strategy is' do
|
24
24
|
context :horizontal do
|
25
|
-
it 'returns the URL of least burdened
|
26
|
-
|
27
|
-
|
25
|
+
it 'returns the URL of least burdened Agent' do
|
26
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
27
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
28
28
|
|
29
29
|
expect(subject.preferred( :horizontal )).to eq(subject.url)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context :vertical do
|
34
|
-
it 'returns the URL of most burdened
|
35
|
-
|
36
|
-
d =
|
37
|
-
d.
|
38
|
-
d.
|
34
|
+
it 'returns the URL of most burdened Agent' do
|
35
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
36
|
+
d = agent_spawn( peer: subject.url )
|
37
|
+
d.spawn( load_balance: false )
|
38
|
+
d.spawn( load_balance: false )
|
39
39
|
|
40
40
|
expect(subject.preferred( :vertical )).to eq(d.url)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'default' do
|
45
|
-
it 'returns the URL of least burdened
|
46
|
-
|
47
|
-
|
45
|
+
it 'returns the URL of least burdened Agent' do
|
46
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
47
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
48
48
|
|
49
49
|
expect(subject.preferred).to eq(subject.url)
|
50
50
|
end
|
@@ -52,38 +52,38 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
52
52
|
|
53
53
|
context 'other' do
|
54
54
|
it 'returns :error_unknown_strategy' do
|
55
|
-
|
56
|
-
|
55
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
56
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
57
57
|
|
58
58
|
expect(subject.preferred( :blah )).to eq('error_unknown_strategy')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
context 'and all
|
63
|
+
context 'and all Agents are at max utilization' do
|
64
64
|
before :each do
|
65
|
-
subject.
|
65
|
+
subject.spawn( load_balance: false )
|
66
66
|
end
|
67
67
|
|
68
68
|
let(:slots) { 1 }
|
69
69
|
|
70
70
|
it 'returns nil' do
|
71
|
-
|
72
|
-
|
71
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
72
|
+
agent_spawn( peer: subject.url ).spawn( load_balance: false )
|
73
73
|
|
74
74
|
expect(subject.preferred).to be_nil
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
context 'when the
|
80
|
-
it 'returns the URL of the
|
79
|
+
context 'when the agent is not a grid member' do
|
80
|
+
it 'returns the URL of the Agent' do
|
81
81
|
expect(subject.preferred).to eq(subject.url)
|
82
82
|
end
|
83
83
|
|
84
84
|
context 'and it is at max utilization' do
|
85
85
|
before :each do
|
86
|
-
subject.
|
86
|
+
subject.spawn( load_balance: false )
|
87
87
|
end
|
88
88
|
|
89
89
|
let(:slots) { 1 }
|
@@ -101,20 +101,20 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe '#
|
104
|
+
describe '#spawn' do
|
105
105
|
it 'does not leak Instances' do
|
106
106
|
slots.times do
|
107
|
-
subject.
|
107
|
+
subject.spawn
|
108
108
|
end
|
109
109
|
|
110
110
|
expect(subject.instances.size).to eq(slots)
|
111
111
|
end
|
112
112
|
|
113
|
-
it 'sets OptionGroups::
|
114
|
-
info = subject.
|
113
|
+
it 'sets OptionGroups::Agent#url' do
|
114
|
+
info = subject.spawn
|
115
115
|
instance = instance_connect( info['url'], info['token'] )
|
116
116
|
|
117
|
-
expect(instance.
|
117
|
+
expect(instance.agent_url).to eq subject.url
|
118
118
|
end
|
119
119
|
|
120
120
|
context "when #{Cuboid::OptionGroups::RPC}#server_external_address has been set" do
|
@@ -125,13 +125,13 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
125
125
|
let(:address) { '127.0.0.2' }
|
126
126
|
|
127
127
|
it 'advertises that address' do
|
128
|
-
expect(subject.
|
128
|
+
expect(subject.spawn['url']).to start_with "#{address}:"
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
context 'when not a Grid member' do
|
133
133
|
it 'returns Instance info' do
|
134
|
-
info = subject.
|
134
|
+
info = subject.spawn( owner: 'rspec' )
|
135
135
|
|
136
136
|
%w(token application pid url owner birthdate helpers).each do |k|
|
137
137
|
expect(info[k]).to be_truthy
|
@@ -143,19 +143,19 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
143
143
|
|
144
144
|
it 'assigns an optional owner' do
|
145
145
|
owner = 'blah'
|
146
|
-
expect(subject.
|
146
|
+
expect(subject.spawn( owner: owner )['owner']).to eq(owner)
|
147
147
|
end
|
148
148
|
|
149
149
|
context 'when the there are no available slots' do
|
150
150
|
let(:slots) { 5 }
|
151
151
|
before :each do
|
152
152
|
slots.times do
|
153
|
-
subject.
|
153
|
+
subject.spawn
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'returns nil' do
|
158
|
-
expect(subject.
|
158
|
+
expect(subject.spawn).to be nil
|
159
159
|
end
|
160
160
|
|
161
161
|
context 'and slots are freed' do
|
@@ -173,12 +173,12 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
173
173
|
|
174
174
|
instances = []
|
175
175
|
free.times do
|
176
|
-
instances << subject.
|
176
|
+
instances << subject.spawn
|
177
177
|
end
|
178
178
|
instances.compact!
|
179
179
|
|
180
180
|
expect(instances.size).to eq free
|
181
|
-
expect(subject.
|
181
|
+
expect(subject.spawn).to be nil
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
@@ -189,148 +189,148 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
189
189
|
|
190
190
|
context 'and strategy is' do
|
191
191
|
context :horizontal do
|
192
|
-
it 'provides Instances from the least burdened
|
193
|
-
d1 =
|
192
|
+
it 'provides Instances from the least burdened Agent' do
|
193
|
+
d1 = agent_spawn(
|
194
194
|
address: '127.0.0.1',
|
195
195
|
application: "#{fixtures_path}/mock_app.rb"
|
196
196
|
)
|
197
197
|
|
198
198
|
3.times do
|
199
|
-
d1.
|
199
|
+
d1.spawn( load_balance: false )
|
200
200
|
end
|
201
201
|
|
202
|
-
d2 =
|
202
|
+
d2 = agent_spawn(
|
203
203
|
address: '127.0.0.2',
|
204
|
-
|
204
|
+
peer: d1.url,
|
205
205
|
application: "#{fixtures_path}/mock_app.rb"
|
206
206
|
)
|
207
207
|
|
208
208
|
2.times do
|
209
|
-
d2.
|
209
|
+
d2.spawn( load_balance: false )
|
210
210
|
end
|
211
211
|
|
212
|
-
d3 =
|
212
|
+
d3 = agent_spawn(
|
213
213
|
address: '127.0.0.3',
|
214
|
-
|
214
|
+
peer: d1.url,
|
215
215
|
application: "#{fixtures_path}/mock_app.rb"
|
216
216
|
)
|
217
|
-
d3.
|
217
|
+
d3.spawn( load_balance: false )
|
218
218
|
preferred = d3.url.split( ':' ).first
|
219
219
|
|
220
|
-
expect(d3.
|
221
|
-
expect(%W{127.0.0.3 127.0.0.2}).to include d1.
|
222
|
-
expect(d2.
|
223
|
-
expect(%W{127.0.0.1 127.0.0.3}).to include d3.
|
224
|
-
expect(%W{127.0.0.2 127.0.0.3}).to include d3.
|
225
|
-
expect(%W{127.0.0.2 127.0.0.3}).to include d1.
|
220
|
+
expect(d3.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
|
221
|
+
expect(%W{127.0.0.3 127.0.0.2}).to include d1.spawn['url'].split( ':' ).first
|
222
|
+
expect(d2.spawn(strategy: :horizontal )['url'].split( ':' ).first).to eq(preferred)
|
223
|
+
expect(%W{127.0.0.1 127.0.0.3}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
|
224
|
+
expect(%W{127.0.0.2 127.0.0.3}).to include d3.spawn(strategy: :horizontal )['url'].split( ':' ).first
|
225
|
+
expect(%W{127.0.0.2 127.0.0.3}).to include d1.spawn(strategy: :horizontal )['url'].split( ':' ).first
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
context :vertical do
|
230
|
-
it 'provides Instances from the most burdened
|
231
|
-
d1 =
|
230
|
+
it 'provides Instances from the most burdened Agent' do
|
231
|
+
d1 = agent_spawn(
|
232
232
|
address: '127.0.0.1',
|
233
233
|
application: "#{fixtures_path}/mock_app.rb"
|
234
234
|
)
|
235
235
|
|
236
236
|
3.times do
|
237
|
-
d1.
|
237
|
+
d1.spawn( load_balance: false )
|
238
238
|
end
|
239
239
|
|
240
|
-
d2 =
|
240
|
+
d2 = agent_spawn(
|
241
241
|
address: '127.0.0.2',
|
242
|
-
|
242
|
+
peer: d1.url,
|
243
243
|
application: "#{fixtures_path}/mock_app.rb"
|
244
244
|
)
|
245
245
|
|
246
246
|
2.times do
|
247
|
-
d2.
|
247
|
+
d2.spawn( load_balance: false )
|
248
248
|
end
|
249
249
|
|
250
|
-
d3 =
|
250
|
+
d3 = agent_spawn(
|
251
251
|
address: '127.0.0.3',
|
252
|
-
|
252
|
+
peer: d1.url,
|
253
253
|
application: "#{fixtures_path}/mock_app.rb"
|
254
254
|
)
|
255
|
-
d3.
|
255
|
+
d3.spawn( load_balance: false )
|
256
256
|
|
257
257
|
preferred = d1.url.split( ':' ).first
|
258
|
-
expect(d3.
|
258
|
+
expect(d3.spawn( strategy: :vertical )['url'].split( ':' ).first).to eq(preferred)
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
262
|
context 'default' do
|
263
|
-
it 'provides Instances from the least burdened
|
264
|
-
d1 =
|
263
|
+
it 'provides Instances from the least burdened Agent' do
|
264
|
+
d1 = agent_spawn(
|
265
265
|
address: '127.0.0.1',
|
266
266
|
application: "#{fixtures_path}/mock_app.rb"
|
267
267
|
)
|
268
268
|
|
269
269
|
3.times do
|
270
|
-
d1.
|
270
|
+
d1.spawn( load_balance: false )
|
271
271
|
end
|
272
272
|
|
273
|
-
d2 =
|
273
|
+
d2 = agent_spawn(
|
274
274
|
address: '127.0.0.2',
|
275
|
-
|
275
|
+
peer: d1.url,
|
276
276
|
application: "#{fixtures_path}/mock_app.rb"
|
277
277
|
)
|
278
278
|
|
279
279
|
2.times do
|
280
|
-
d2.
|
280
|
+
d2.spawn( load_balance: false )
|
281
281
|
end
|
282
282
|
|
283
|
-
d3 =
|
283
|
+
d3 = agent_spawn(
|
284
284
|
address: '127.0.0.3',
|
285
|
-
|
285
|
+
peer: d1.url,
|
286
286
|
application: "#{fixtures_path}/mock_app.rb"
|
287
287
|
)
|
288
|
-
d3.
|
288
|
+
d3.spawn( load_balance: false )
|
289
289
|
preferred = d3.url.split( ':' ).first
|
290
290
|
|
291
|
-
expect(d3.
|
292
|
-
expect(%W{127.0.0.3 127.0.0.2}).to include d1.
|
293
|
-
expect(d2.
|
294
|
-
expect(%W{127.0.0.1 127.0.0.3}).to include d3.
|
295
|
-
expect(%W{127.0.0.2 127.0.0.3}).to include d3.
|
296
|
-
expect(%W{127.0.0.2 127.0.0.3}).to include d1.
|
291
|
+
expect(d3.spawn['url'].split( ':' ).first).to eq(preferred)
|
292
|
+
expect(%W{127.0.0.3 127.0.0.2}).to include d1.spawn['url'].split( ':' ).first
|
293
|
+
expect(d2.spawn['url'].split( ':' ).first).to eq(preferred)
|
294
|
+
expect(%W{127.0.0.1 127.0.0.3}).to include d3.spawn['url'].split( ':' ).first
|
295
|
+
expect(%W{127.0.0.2 127.0.0.3}).to include d3.spawn['url'].split( ':' ).first
|
296
|
+
expect(%W{127.0.0.2 127.0.0.3}).to include d1.spawn['url'].split( ':' ).first
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
300
|
context 'other' do
|
301
301
|
it 'returns :error_unknown_strategy' do
|
302
|
-
expect(
|
303
|
-
|
302
|
+
expect(agent_spawn( peer: subject.url ).
|
303
|
+
spawn( strategy: 'blah' )).to eq('error_unknown_strategy')
|
304
304
|
end
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
308
|
context 'when the load-balance option is set to false' do
|
309
|
-
it 'returns an Instance from the requested
|
310
|
-
d1 =
|
309
|
+
it 'returns an Instance from the requested Agent' do
|
310
|
+
d1 = agent_spawn(
|
311
311
|
address: '127.0.0.1',
|
312
312
|
application: "#{fixtures_path}/mock_app.rb"
|
313
313
|
)
|
314
314
|
|
315
|
-
d1.
|
315
|
+
d1.spawn( load_balance: false )
|
316
316
|
|
317
|
-
d2 =
|
317
|
+
d2 = agent_spawn(
|
318
318
|
address: '127.0.0.2',
|
319
|
-
|
319
|
+
peer: d1.url,
|
320
320
|
application: "#{fixtures_path}/mock_app.rb"
|
321
321
|
)
|
322
|
-
d2.
|
322
|
+
d2.spawn( load_balance: false )
|
323
323
|
|
324
|
-
d3 =
|
324
|
+
d3 = agent_spawn(
|
325
325
|
address: '127.0.0.3',
|
326
|
-
|
326
|
+
peer: d1.url,
|
327
327
|
application: "#{fixtures_path}/mock_app.rb"
|
328
328
|
)
|
329
329
|
2.times do
|
330
|
-
d3.
|
330
|
+
d3.spawn( load_balance: false )
|
331
331
|
end
|
332
332
|
|
333
|
-
expect(d3.
|
333
|
+
expect(d3.spawn( load_balance: false )['url'].
|
334
334
|
split( ':' ).first).to eq('127.0.0.3')
|
335
335
|
end
|
336
336
|
end
|
@@ -339,7 +339,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
339
339
|
|
340
340
|
describe '#instance' do
|
341
341
|
it 'returns proc info by PID' do
|
342
|
-
instance = subject.
|
342
|
+
instance = subject.spawn( owner: 'rspec' )
|
343
343
|
info = subject.instance( instance['pid'] )
|
344
344
|
instance_info_keys.each do |k|
|
345
345
|
expect(info[k]).to be_truthy
|
@@ -349,7 +349,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
349
349
|
|
350
350
|
describe '#instances' do
|
351
351
|
it 'returns proc info by PID for all instances' do
|
352
|
-
slots.times { subject.
|
352
|
+
slots.times { subject.spawn( owner: 'rspec' ) }
|
353
353
|
|
354
354
|
subject.instances.each do |instance|
|
355
355
|
instance_info_keys.each do |k|
|
@@ -361,7 +361,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
361
361
|
|
362
362
|
describe '#running_instances' do
|
363
363
|
it 'returns proc info for running instances' do
|
364
|
-
slots.times { subject.
|
364
|
+
slots.times { subject.spawn }
|
365
365
|
|
366
366
|
expect(subject.running_instances.size).to eq(slots)
|
367
367
|
end
|
@@ -369,7 +369,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
369
369
|
|
370
370
|
describe '#finished_instances' do
|
371
371
|
it 'returns proc info for finished instances' do
|
372
|
-
3.times { Cuboid::Processes::Manager.kill subject.
|
372
|
+
3.times { Cuboid::Processes::Manager.kill subject.spawn['pid'] }
|
373
373
|
|
374
374
|
expect(subject.finished_instances.size).to eq(3)
|
375
375
|
end
|
@@ -378,7 +378,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
378
378
|
describe '#utilization' do
|
379
379
|
it 'returns a float signifying the amount of workload' do
|
380
380
|
3.times do
|
381
|
-
subject.
|
381
|
+
subject.spawn
|
382
382
|
end
|
383
383
|
|
384
384
|
expect(subject.utilization).to eq(3 / Float(slots))
|
@@ -387,7 +387,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
387
387
|
|
388
388
|
describe '#statistics' do
|
389
389
|
it 'returns general statistics' do
|
390
|
-
subject.
|
390
|
+
subject.spawn
|
391
391
|
instances = subject.instances
|
392
392
|
Cuboid::Processes::Manager.kill( instances.first['pid'] )
|
393
393
|
|
@@ -406,7 +406,7 @@ describe Cuboid::RPC::Server::Dispatcher do
|
|
406
406
|
|
407
407
|
context 'when there are snapshots' do
|
408
408
|
it 'lists them' do
|
409
|
-
info = subject.
|
409
|
+
info = subject.spawn
|
410
410
|
|
411
411
|
instance = Cuboid::RPC::Client::Instance.new(
|
412
412
|
info['url'], info['token']
|
@@ -52,20 +52,20 @@ describe Cuboid::RPC::Server::Scheduler do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context 'when a
|
56
|
-
subject { Cuboid::Processes::Schedulers.spawn
|
57
|
-
let(:
|
58
|
-
Cuboid::Processes::
|
55
|
+
context 'when a Agent has been set' do
|
56
|
+
subject { Cuboid::Processes::Schedulers.spawn agent: agent.url }
|
57
|
+
let(:agent) do
|
58
|
+
Cuboid::Processes::Agents.spawn( application: "#{fixtures_path}/mock_app.rb" )
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'gets Instances from it' do
|
62
|
-
expect(
|
62
|
+
expect(agent.finished_instances).to be_empty
|
63
63
|
|
64
64
|
subject.push( options )
|
65
65
|
sleep 0.1 while subject.completed.empty?
|
66
66
|
sleep 2
|
67
67
|
|
68
|
-
expect(
|
68
|
+
expect(agent.finished_instances).to be_any
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'sets OptionGroups::Scheduler#url' do
|
@@ -80,7 +80,7 @@ describe Cuboid::RPC::Server::Scheduler do
|
|
80
80
|
it 'does not consume the queue' do
|
81
81
|
subject
|
82
82
|
|
83
|
-
Cuboid::Processes::
|
83
|
+
Cuboid::Processes::Agents.killall
|
84
84
|
sleep 3
|
85
85
|
|
86
86
|
expect(subject.size).to be 0
|
@@ -89,7 +89,7 @@ describe Cuboid::RPC::Server::Scheduler do
|
|
89
89
|
sleep 5
|
90
90
|
|
91
91
|
expect(subject.size).to be 1
|
92
|
-
expect(subject.errors.join("\n")).to include "Failed to contact
|
92
|
+
expect(subject.errors.join("\n")).to include "Failed to contact Agent at: #{agent.url}"
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require Options.paths.lib + 'ui/output'
|
2
|
-
require Options.paths.lib + 'rpc/server/
|
2
|
+
require Options.paths.lib + 'rpc/server/agent'
|
3
3
|
require Options.paths.lib + 'processes/manager'
|
4
4
|
|
5
|
-
class Node < Cuboid::RPC::Server::
|
5
|
+
class Node < Cuboid::RPC::Server::Agent::Node
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@options = Options.instance
|
9
9
|
|
10
10
|
methods.each do |m|
|
11
|
-
next if method( m ).owner != Cuboid::RPC::Server::
|
11
|
+
next if method( m ).owner != Cuboid::RPC::Server::Agent::Node
|
12
12
|
self.class.send :private, m
|
13
13
|
self.class.send :public, m
|
14
14
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require 'cuboid/rpc/server/
|
1
|
+
require 'cuboid/rpc/server/agent'
|
2
2
|
|
3
|
-
class TestService < Cuboid::RPC::Server::
|
3
|
+
class TestService < Cuboid::RPC::Server::Agent::Service
|
4
4
|
|
5
5
|
private :instances
|
6
6
|
public :instances
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def test_agent
|
9
|
+
agent.class == Cuboid::RPC::Server::Agent
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_opts
|
13
|
-
|
13
|
+
agent.instance_eval{ @options } == options
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_node
|
17
|
-
node.class == Cuboid::RPC::Server::
|
17
|
+
node.class == Cuboid::RPC::Server::Agent::Node
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_map_instances( &block )
|
@@ -39,8 +39,8 @@ class TestService < Cuboid::RPC::Server::Dispatcher::Service
|
|
39
39
|
iterator_for( instances ).class == Arachni::Reactor::Iterator
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
|
42
|
+
def test_connect_to_agent( url, &block )
|
43
|
+
connect_to_agent( url ).alive? { |b| block.call b }
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_connect_to_instance( *args, &block )
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class Cuboid::RPC::Server::
|
1
|
+
class Cuboid::RPC::Server::Agent
|
2
2
|
class Service::Echo < Service
|
3
3
|
|
4
4
|
private :instances
|
5
5
|
public :instances
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def test_agent
|
8
|
+
agent.class == Cuboid::RPC::Server::Agent
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_opts
|
12
|
-
|
12
|
+
agent.instance_eval{ @options } == options
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_node
|
@@ -38,8 +38,8 @@ class Service::Echo < Service
|
|
38
38
|
iterator_for( instances ).class == Arachni::Reactor::Iterator
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def test_connect_to_agent( url, &block )
|
42
|
+
connect_to_agent( url ).alive? { |b| block.call b }
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_connect_to_instance( *args, &block )
|
@@ -2,9 +2,9 @@ require 'arachni/rpc'
|
|
2
2
|
|
3
3
|
# @note Needs `ENV['WEB_SERVER_DISPATCHER']` in the format of `host:port`.
|
4
4
|
#
|
5
|
-
# {WebServerManager}-API-compatible client for the {
|
5
|
+
# {WebServerManager}-API-compatible client for the {WebServerAgent}.
|
6
6
|
#
|
7
|
-
# Delegates test webserver creation to the machine running {
|
7
|
+
# Delegates test webserver creation to the machine running {WebServerAgent},
|
8
8
|
# for hosts that lack support for fast servers (like Windows, which can't run
|
9
9
|
# Thin, Puma etc.).
|
10
10
|
#
|
@@ -9,7 +9,7 @@ require 'arachni/rpc'
|
|
9
9
|
# Exposes the {WebServerManager} over RPC.
|
10
10
|
#
|
11
11
|
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
12
|
-
class
|
12
|
+
class WebServerAgent
|
13
13
|
|
14
14
|
def initialize( options = {} )
|
15
15
|
host, port = ENV['WEB_SERVER_DISPATCHER'].split( ':' )
|