cuboid 0.0.3alpha → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile +1 -1
  4. data/README.md +14 -13
  5. data/cuboid.gemspec +1 -1
  6. data/lib/cuboid/application.rb +10 -10
  7. data/lib/cuboid/option_groups/agent.rb +54 -0
  8. data/lib/cuboid/option_groups/paths.rb +13 -4
  9. data/lib/cuboid/options.rb +1 -1
  10. data/lib/cuboid/processes/{dispatchers.rb → agents.rb} +40 -26
  11. data/lib/cuboid/processes/executables/agent.rb +5 -0
  12. data/lib/cuboid/processes/helpers/agents.rb +23 -0
  13. data/lib/cuboid/processes/helpers/instances.rb +4 -4
  14. data/lib/cuboid/processes/helpers.rb +1 -1
  15. data/lib/cuboid/processes/instances.rb +22 -10
  16. data/lib/cuboid/processes/schedulers.rb +16 -3
  17. data/lib/cuboid/processes.rb +2 -2
  18. data/lib/cuboid/rest/server/instance_helpers.rb +13 -13
  19. data/lib/cuboid/rest/server/routes/dispatcher.rb +11 -11
  20. data/lib/cuboid/rest/server/routes/grid.rb +8 -8
  21. data/lib/cuboid/rest/server/routes/instances.rb +1 -1
  22. data/lib/cuboid/rest/server.rb +5 -5
  23. data/lib/cuboid/rpc/client/{dispatcher.rb → agent.rb} +4 -4
  24. data/lib/cuboid/rpc/client/instance.rb +2 -2
  25. data/lib/cuboid/rpc/client.rb +1 -1
  26. data/lib/cuboid/rpc/server/agent/node.rb +247 -0
  27. data/lib/cuboid/rpc/server/{dispatcher → agent}/service.rb +13 -13
  28. data/lib/cuboid/rpc/server/{dispatcher.rb → agent.rb} +62 -32
  29. data/lib/cuboid/rpc/server/application_wrapper.rb +5 -4
  30. data/lib/cuboid/rpc/server/instance.rb +4 -4
  31. data/lib/cuboid/rpc/server/scheduler.rb +13 -12
  32. data/lib/version +1 -1
  33. data/spec/cuboid/option_groups/dispatcher_spec.rb +2 -2
  34. data/spec/cuboid/option_groups/paths_spec.rb +6 -3
  35. data/spec/cuboid/rest/server_spec.rb +45 -45
  36. data/spec/cuboid/rpc/client/dispatcher_spec.rb +2 -2
  37. data/spec/cuboid/rpc/server/dispatcher/node_spec.rb +65 -65
  38. data/spec/cuboid/rpc/server/dispatcher/service_spec.rb +16 -16
  39. data/spec/cuboid/rpc/server/dispatcher_spec.rb +187 -72
  40. data/spec/cuboid/rpc/server/scheduler_spec.rb +8 -8
  41. data/spec/support/fixtures/executables/node.rb +3 -3
  42. data/spec/support/fixtures/mock_app/test_service.rb +8 -8
  43. data/spec/support/fixtures/mock_app.rb +1 -1
  44. data/spec/support/fixtures/services/echo.rb +6 -6
  45. data/spec/support/helpers/resets.rb +1 -1
  46. data/spec/support/lib/web_server_client.rb +2 -2
  47. data/spec/support/lib/web_server_dispatcher.rb +1 -1
  48. metadata +18 -58
  49. data/lib/cuboid/option_groups/dispatcher.rb +0 -38
  50. data/lib/cuboid/processes/executables/dispatcher.rb +0 -5
  51. data/lib/cuboid/processes/helpers/dispatchers.rb +0 -23
  52. data/lib/cuboid/rpc/server/dispatcher/node.rb +0 -247
  53. data/spec/support/logs/Dispatcher - 51489-29703.log +0 -6
  54. data/spec/support/logs/Scheduler - 51474-42556.log +0 -3
  55. data/spec/support/logs/Scheduler - 51477-63074.log +0 -6
  56. data/spec/support/logs/Scheduler - 51496-16039.log +0 -3
  57. data/spec/support/logs/Scheduler - 51499-40309.log +0 -6
  58. data/spec/support/logs/Scheduler - 51521-54983.log +0 -4
  59. data/spec/support/logs/Scheduler - 51533-50145.log +0 -1
  60. data/spec/support/logs/Scheduler - 51537-26476.log +0 -3
  61. data/spec/support/logs/Scheduler - 51541-33347.log +0 -6
  62. data/spec/support/logs/Scheduler - 51556-5765.log +0 -3
  63. data/spec/support/logs/Scheduler - 51559-22349.log +0 -6
  64. data/spec/support/logs/Scheduler - 51567-20476.log +0 -3
  65. data/spec/support/logs/Scheduler - 51570-37548.log +0 -6
  66. data/spec/support/logs/Scheduler - 52668-26175.log +0 -3
  67. data/spec/support/reports/3480c2e4463df854d3457b247e3ba679.crf +0 -0
  68. data/spec/support/reports/45958408cb49a7f3391a973e05bf673b.crf +0 -0
  69. data/spec/support/reports/62a7f8d6c8914bb086e7e5f8c418d974.crf +0 -0
  70. data/spec/support/reports/6363927e13ec27b5cbd973b86bd8e52c.crf +0 -0
  71. data/spec/support/reports/b68f94be3aa96d0c27477dcfe1e25143.crf +0 -0
  72. data/spec/support/reports/bbb7496056393de17e72855a63d3acfb.crf +0 -0
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
- require "#{Cuboid::Options.paths.lib}/rpc/server/dispatcher"
2
+ require "#{Cuboid::Options.paths.lib}/rpc/server/agent"
3
3
 
4
- describe Cuboid::RPC::Server::Dispatcher::Node do
4
+ describe Cuboid::RPC::Server::Agent::Node do
5
5
 
6
6
  def get_node( port = available_port )
7
7
  Cuboid::Options.rpc.server_port = port
@@ -25,7 +25,7 @@ describe Cuboid::RPC::Server::Dispatcher::Node do
25
25
 
26
26
  before( :each ) do
27
27
  options.paths.executables = "#{fixtures_path}executables/"
28
- options.dispatcher.ping_interval = 0.5
28
+ options.agent.ping_interval = 0.5
29
29
  end
30
30
  after( :each ) do
31
31
  Cuboid::Processes::Manager.killall
@@ -35,9 +35,9 @@ describe Cuboid::RPC::Server::Dispatcher::Node do
35
35
  let(:options) { Cuboid::Options }
36
36
 
37
37
  describe '#grid_member?' do
38
- context 'when the dispatcher is a grid member' do
38
+ context 'when the agent is a grid member' do
39
39
  it 'should return true' do
40
- options.dispatcher.neighbour = subject.url
40
+ options.agent.peer = subject.url
41
41
 
42
42
  c = get_node
43
43
  sleep 0.5
@@ -46,68 +46,68 @@ describe Cuboid::RPC::Server::Dispatcher::Node do
46
46
  end
47
47
  end
48
48
 
49
- context 'when the dispatcher is not a grid member' do
49
+ context 'when the agent is not a grid member' do
50
50
  it 'should return false' do
51
51
  expect(subject.grid_member?).to be_falsey
52
52
  end
53
53
  end
54
54
  end
55
55
 
56
- context 'when a previously unreachable neighbour comes back to life' do
57
- it 'gets re-added to the neighbours list' do
56
+ context 'when a previously unreachable peer comes back to life' do
57
+ it 'gets re-added to the peers list' do
58
58
  port = available_port
59
- subject.add_neighbour( '127.0.0.1:' + port.to_s )
59
+ subject.add_peer( '127.0.0.1:' + port.to_s )
60
60
 
61
61
  sleep 3
62
- expect(subject.neighbours).to be_empty
62
+ expect(subject.peers).to be_empty
63
63
 
64
64
  c = get_node( port )
65
65
 
66
66
  sleep 0.5
67
- expect(subject.neighbours).to eq([c.url])
68
- expect(c.neighbours).to eq([subject.url])
67
+ expect(subject.peers).to eq([c.url])
68
+ expect(c.peers).to eq([subject.url])
69
69
  end
70
70
  end
71
71
 
72
- context 'when a neighbour becomes unreachable' do
72
+ context 'when a peer becomes unreachable' do
73
73
  it 'is removed' do
74
74
  c = get_node
75
75
 
76
- subject.add_neighbour( c.url )
76
+ subject.add_peer( c.url )
77
77
  sleep 0.5
78
78
 
79
- expect(c.neighbours).to eq([subject.url])
80
- expect(subject.neighbours).to eq([c.url])
79
+ expect(c.peers).to eq([subject.url])
80
+ expect(subject.peers).to eq([c.url])
81
81
 
82
82
  subject.shutdown rescue break while sleep 0.1
83
83
  sleep 0.5
84
84
 
85
- expect(c.neighbours).to be_empty
85
+ expect(c.peers).to be_empty
86
86
  end
87
87
  end
88
88
 
89
- context 'when initialised with a neighbour' do
90
- it 'adds that neighbour and reach convergence' do
91
- options.dispatcher.neighbour = subject.url
89
+ context 'when initialised with a peer' do
90
+ it 'adds that peer and reach convergence' do
91
+ options.agent.peer = subject.url
92
92
 
93
93
  c = get_node
94
94
  sleep 0.5
95
- expect(c.neighbours).to eq([subject.url])
96
- expect(subject.neighbours).to eq([c.url])
95
+ expect(c.peers).to eq([subject.url])
96
+ expect(subject.peers).to eq([c.url])
97
97
 
98
98
  d = get_node
99
99
  sleep 0.5
100
- expect(d.neighbours.sort).to eq([subject.url, c.url].sort)
101
- expect(c.neighbours.sort).to eq([subject.url, d.url].sort)
102
- expect(subject.neighbours.sort).to eq([c.url, d.url].sort)
100
+ expect(d.peers.sort).to eq([subject.url, c.url].sort)
101
+ expect(c.peers.sort).to eq([subject.url, d.url].sort)
102
+ expect(subject.peers.sort).to eq([c.url, d.url].sort)
103
103
 
104
- options.dispatcher.neighbour = d.url
104
+ options.agent.peer = d.url
105
105
  e = get_node
106
106
  sleep 0.5
107
- expect(e.neighbours.sort).to eq([subject.url, c.url, d.url].sort)
108
- expect(d.neighbours.sort).to eq([subject.url, c.url, e.url].sort)
109
- expect(c.neighbours.sort).to eq([subject.url, d.url, e.url].sort)
110
- expect(subject.neighbours.sort).to eq([c.url, d.url, e.url].sort)
107
+ expect(e.peers.sort).to eq([subject.url, c.url, d.url].sort)
108
+ expect(d.peers.sort).to eq([subject.url, c.url, e.url].sort)
109
+ expect(c.peers.sort).to eq([subject.url, d.url, e.url].sort)
110
+ expect(subject.peers.sort).to eq([c.url, d.url, e.url].sort)
111
111
  end
112
112
  end
113
113
 
@@ -115,75 +115,75 @@ describe Cuboid::RPC::Server::Dispatcher::Node do
115
115
  it 'removes itself from the Grid' do
116
116
  c = get_node
117
117
 
118
- subject.add_neighbour( c.url )
118
+ subject.add_peer( c.url )
119
119
  sleep 0.5
120
- expect(c.neighbours).to eq([subject.url])
120
+ expect(c.peers).to eq([subject.url])
121
121
 
122
122
  c.unplug
123
123
 
124
- expect(c.neighbours).to be_empty
124
+ expect(c.peers).to be_empty
125
125
  expect(c.grid_member?).to be_falsey
126
126
  end
127
127
  end
128
128
 
129
- describe '#add_neighbour' do
129
+ describe '#add_peer' do
130
130
  before(:each) do
131
- subject.add_neighbour( other.url )
131
+ subject.add_peer( other.url )
132
132
  sleep 0.5
133
133
  end
134
134
 
135
135
  let( :other ) { get_node }
136
136
 
137
- it 'adds a neighbour' do
138
- expect(subject.neighbours).to eq([other.url])
139
- expect(other.neighbours).to eq([subject.url])
137
+ it 'adds a peer' do
138
+ expect(subject.peers).to eq([other.url])
139
+ expect(other.peers).to eq([subject.url])
140
140
  end
141
141
 
142
142
  context 'when propagate is set to true' do
143
- it 'announces the new neighbour to the existing neighbours' do
143
+ it 'announces the new peer to the existing peers' do
144
144
  n = get_node
145
- subject.add_neighbour( n.url, true )
145
+ subject.add_peer( n.url, true )
146
146
  sleep 0.5
147
147
 
148
- expect(subject.neighbours.sort).to eq([other.url, n.url].sort)
149
- expect(other.neighbours.sort).to eq([subject.url, n.url].sort)
148
+ expect(subject.peers.sort).to eq([other.url, n.url].sort)
149
+ expect(other.peers.sort).to eq([subject.url, n.url].sort)
150
150
 
151
151
  c = get_node
152
- n.add_neighbour( c.url, true )
152
+ n.add_peer( c.url, true )
153
153
  sleep 0.5
154
154
 
155
- expect(subject.neighbours.sort).to eq([other.url, n.url, c.url].sort)
156
- expect(other.neighbours.sort).to eq([subject.url, n.url, c.url].sort)
157
- expect(c.neighbours.sort).to eq([subject.url, n.url, other.url].sort)
155
+ expect(subject.peers.sort).to eq([other.url, n.url, c.url].sort)
156
+ expect(other.peers.sort).to eq([subject.url, n.url, c.url].sort)
157
+ expect(c.peers.sort).to eq([subject.url, n.url, other.url].sort)
158
158
 
159
159
  d = get_node
160
- d.add_neighbour( c.url, true )
160
+ d.add_peer( c.url, true )
161
161
  sleep 0.5
162
162
 
163
- expect(subject.neighbours.sort).to eq([d.url, other.url, n.url, c.url].sort)
164
- expect(other.neighbours.sort).to eq([d.url, subject.url, n.url, c.url].sort)
165
- expect(c.neighbours.sort).to eq([d.url, subject.url, n.url, other.url].sort)
166
- expect(d.neighbours.sort).to eq([c.url, subject.url, n.url, other.url].sort)
163
+ expect(subject.peers.sort).to eq([d.url, other.url, n.url, c.url].sort)
164
+ expect(other.peers.sort).to eq([d.url, subject.url, n.url, c.url].sort)
165
+ expect(c.peers.sort).to eq([d.url, subject.url, n.url, other.url].sort)
166
+ expect(d.peers.sort).to eq([c.url, subject.url, n.url, other.url].sort)
167
167
  end
168
168
  end
169
169
  end
170
170
 
171
- describe '#neighbours' do
172
- it 'returns an array of neighbours' do
173
- expect(subject.neighbours.is_a?( Array )).to be_truthy
171
+ describe '#peers' do
172
+ it 'returns an array of peers' do
173
+ expect(subject.peers.is_a?( Array )).to be_truthy
174
174
  end
175
175
  end
176
176
 
177
- describe '#neighbours_with_info' do
178
- it 'returns all neighbours accompanied by their node info' do
179
- subject.add_neighbour( get_node.url )
177
+ describe '#peers_with_info' do
178
+ it 'returns all peers accompanied by their node info' do
179
+ subject.add_peer( get_node.url )
180
180
  sleep 0.5
181
181
 
182
- expect(subject.neighbours).to be_any
183
- expect(subject.neighbours_with_info.size).to eq (subject.neighbours.size)
182
+ expect(subject.peers).to be_any
183
+ expect(subject.peers_with_info.size).to eq (subject.peers.size)
184
184
 
185
185
  keys = subject.info.keys.sort
186
- subject.neighbours_with_info.each do |i|
186
+ subject.peers_with_info.each do |i|
187
187
  expect(i.keys.sort).to eq(keys)
188
188
  end
189
189
  end
@@ -191,18 +191,18 @@ describe Cuboid::RPC::Server::Dispatcher::Node do
191
191
 
192
192
  describe '#info' do
193
193
  it 'returns node info' do
194
- options.dispatcher.name = 'blah'
194
+ options.agent.name = 'blah'
195
195
 
196
196
  c = get_node
197
- subject.add_neighbour( c.url )
197
+ subject.add_peer( c.url )
198
198
  sleep 0.5
199
199
 
200
200
  info = subject.info
201
201
 
202
202
  expect(info['url']).to eq(subject.url)
203
- expect(info['neighbours']).to eq(subject.neighbours)
204
- expect(info['unreachable_neighbours']).to be_empty
205
- expect(info['name']).to eq(options.dispatcher.name)
203
+ expect(info['peers']).to eq(subject.peers)
204
+ expect(info['unreachable_peers']).to be_empty
205
+ expect(info['name']).to eq(options.agent.name)
206
206
  end
207
207
 
208
208
  context 'when OptionGroups::RPC#server_external_address has been set' do
@@ -1,36 +1,36 @@
1
1
  require 'spec_helper'
2
- require "#{Cuboid::Options.paths.lib}/rpc/server/dispatcher"
2
+ require "#{Cuboid::Options.paths.lib}/rpc/server/agent"
3
3
 
4
- describe Cuboid::RPC::Server::Dispatcher::Service do
4
+ describe Cuboid::RPC::Server::Agent::Service do
5
5
  before( :each ) do
6
6
  Cuboid::Options.paths.services = "#{fixtures_path}services/"
7
7
  Cuboid::Options.system.max_slots = 10
8
8
  end
9
9
  let(:instance_count) { 3 }
10
- let(:dispatcher) { dispatcher_spawn application: "#{fixtures_path}/mock_app.rb" }
11
- let(:subject) { dispatcher.test_service }
10
+ let(:agent) { agent_spawn application: "#{fixtures_path}/mock_app.rb" }
11
+ let(:subject) { agent.test_service }
12
12
 
13
- describe '#dispatcher' do
14
- it 'provides access to the parent Dispatcher' do
15
- expect(subject.test_dispatcher).to be_truthy
13
+ describe '#agent' do
14
+ it 'provides access to the parent Agent' do
15
+ expect(subject.test_agent).to be_truthy
16
16
  end
17
17
  end
18
18
 
19
19
  describe '#opts' do
20
- it 'provides access to the Dispatcher\'s options' do
20
+ it 'provides access to the Agent\'s options' do
21
21
  expect(subject.test_opts).to be_truthy
22
22
  end
23
23
  end
24
24
 
25
25
  describe '#node' do
26
- it 'provides access to the Dispatcher\'s node' do
26
+ it 'provides access to the Agent\'s node' do
27
27
  expect(subject.test_node).to be_truthy
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#instances' do
32
32
  before(:each) do
33
- instance_count.times { dispatcher.dispatch }
33
+ instance_count.times { agent.spawn }
34
34
  end
35
35
 
36
36
  it 'provides access to the running instances' do
@@ -40,7 +40,7 @@ describe Cuboid::RPC::Server::Dispatcher::Service do
40
40
 
41
41
  describe '#map_instances' do
42
42
  before(:each) do
43
- instance_count.times { dispatcher.dispatch }
43
+ instance_count.times { agent.spawn }
44
44
  end
45
45
 
46
46
  it 'asynchronously maps all running instances' do
@@ -52,7 +52,7 @@ describe Cuboid::RPC::Server::Dispatcher::Service do
52
52
 
53
53
  describe '#each_instance' do
54
54
  before(:each) do
55
- instance_count.times { dispatcher.dispatch }
55
+ instance_count.times { agent.spawn }
56
56
  end
57
57
 
58
58
  it 'asynchronously iterates over all running instances' do
@@ -92,15 +92,15 @@ describe Cuboid::RPC::Server::Dispatcher::Service do
92
92
  end
93
93
  end
94
94
 
95
- describe '#connect_to_dispatcher' do
96
- it 'connects to the a dispatcher by url' do
97
- expect(subject.test_connect_to_dispatcher( dispatcher.url )).to be_truthy
95
+ describe '#connect_to_agent' do
96
+ it 'connects to the a agent by url' do
97
+ expect(subject.test_connect_to_agent( agent.url )).to be_truthy
98
98
  end
99
99
  end
100
100
 
101
101
  describe '#connect_to_instance' do
102
102
  it 'connects to an instance' do
103
- dispatcher.dispatch
103
+ agent.spawn
104
104
  instance = subject.instances.first
105
105
 
106
106
  expect(subject.test_connect_to_instance( instance )).to be_falsey