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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64a837b1b4bccd6e7168fd87d60d4022fa7323a5cc2c28942b046607c733ba87
4
- data.tar.gz: 171353ef8dbc9e0e3cad08d87f1154de66eeaebb9090e8b6141da5f110d30935
3
+ metadata.gz: 710475f0dbd6f248872b6772e83856011d8c8fc59e157d61832b072c56bd33bc
4
+ data.tar.gz: e2c2f7e6beaceffdc163ad1feb59bbbe59471f9789f092fbe1033827f0c0c35f
5
5
  SHA512:
6
- metadata.gz: 36ab4e5211f2a854ec84c67392ca390d36d5e6454c99d6afa655c6d3eda393a6274f0b32a5d5302884098d770f1a306c4a98eba7285e554caa8524d201dea61d
7
- data.tar.gz: 2ceefd56a229375c1ec65f1dbb8741ba5d52df80514c86a58e3f1e26e9949f26b5a44d3699c2165ce326ff37e715b21646c20cc202354679c84704a59d1963e4
6
+ metadata.gz: 914ec2ab3b83c6271ca0ea4af8a863dd96de24d4ebb5dc7b9b8151c28a7a89a757acaaffed5f4b7f6066fa53d66c567e84e82799aee4033ed3ad98d57814e226
7
+ data.tar.gz: 4fa2db1af048c789ebd1778ca854ce7bb86a3a8ea98b24618e1da6fdd56f3204fc1cb693d41ca0a05c3ad4a7d83c7777fc7ca641da33e37166b9c1fbdfcd085c
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ # 0.1.0
2
+
3
+ * `Dispatcher` => `Agent`
4
+ * `Dispatcher#dispatch` => `Agent#spawn`
5
+ * `neighbour` => `peer`
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake', '11.3.0'
3
+ gem 'rake', '13.0.3'
4
4
 
5
5
  group :docs do
6
6
  gem 'yard'
data/README.md CHANGED
@@ -10,10 +10,11 @@ _Cloud_ within a _Cloud_.
10
10
 
11
11
  It offers:
12
12
 
13
- * Load-balancing of _**Instances**_ via a software mesh network (_**Grid**_) of _**Dispatchers**_.
14
- * No need to setup a topology manually, _**Dispatchers**_ will reach
13
+ * Load-balancing of _**Instances**_ via a network (_**Grid**_) of _**Agents**_.
14
+ * No need to setup a topology manually, _**Agents**_ will reach
15
15
  convergence on their own, just point them to an existing _**Grid**_ member.
16
16
  * Scaling up and down can be easily achieved by _plugging_ or _unplugging_ nodes.
17
+ * Horizontal (`default`) and vertical workload distribution strategies available.
17
18
  * Fault tolerant -- one application per process (_**Instance**_).
18
19
  * Self-healing -- keeps an eye out for disappearing and also re-appearing members.
19
20
  * A clean and simple framework for application development.
@@ -57,7 +58,7 @@ framework:
57
58
  * `:restore`
58
59
  * `instance_service_for( Symbol, Class )` -- Adds a custom _**Instance**_ RPC API.
59
60
  * `rest_service_for( Symbol, Module )` -- Hooks-up to the _**REST**_ service to provide a custom REST API.
60
- * `dispatcher_service_for( Symbol, Class )` -- Hooks-up to the _**Dispatcher**_ to provide a custom RPC API.
61
+ * `agent_service_for( Symbol, Class )` -- Hooks-up to the _**Agent**_ to provide a custom RPC API.
61
62
  * `serialize_with( Module )` -- A serializer to be used for:
62
63
  * `#options`
63
64
  * `Report#data`
@@ -83,10 +84,10 @@ This is in order to enforce isolation (_state_, _data_, _fault_) between
83
84
  _**Applications**_, take advantage of _OS_ task management and generally keep
84
85
  things simple.
85
86
 
86
- ### Dispatcher
87
+ ### Agent
87
88
 
88
- A _**Dispatcher**_ is a server which awaits for _**Instance**_ spawn requests
89
- (`dispatch` calls) upon which it spawns and passes the _**Instance**_'s
89
+ A _**Agent**_ is a server which awaits for _**Instance**_ spawn requests
90
+ (`spawn` calls) upon which it spawns and passes the _**Instance**_'s
90
91
  connection info to the client.
91
92
 
92
93
  The client can then proceed to use the _**Instance**_ to run and generally manage
@@ -94,7 +95,7 @@ the contained _**Application**_.
94
95
 
95
96
  #### Grid
96
97
 
97
- A _**Dispatcher**_ _**Grid**_ is a software mesh network of _**Dispatcher**_
98
+ A _**Agent**_ _**Grid**_ is a software mesh network of _**Agent**_
98
99
  servers, aimed towards providing automated _load-balancing_ based on available
99
100
  system resources and each _**Application**_'s provisioning configuration.
100
101
 
@@ -103,11 +104,11 @@ providing any existing _**Grid**_ member upon start-up and the rest will be
103
104
  sorted out automatically.
104
105
 
105
106
  The network is _self-healing_ and will monitor _node_ connectivity, taking steps
106
- to ensure that neither server nor network conditions will disrupt dispatching.
107
+ to ensure that neither server nor network conditions will disrupt spawning.
107
108
 
108
109
  ##### Scalability
109
110
 
110
- _**Dispatchers**_ can be easily _plugged_ to or _unplugged_ from the _**Grid**_
111
+ _**Agents**_ can be easily _plugged_ to or _unplugged_ from the _**Grid**_
111
112
  to scale up or down as necessary.
112
113
 
113
114
  _Plugging_ happens at boot-time and _unplugging_ can take place via the available
@@ -124,12 +125,12 @@ The _**Scheduler**_ is a server which:
124
125
  5. Upon _**Application**_ completion stores report to disk.
125
126
  6. Shuts down the _**Instance**_.
126
127
 
127
- #### Dispatcher
128
+ #### Agent
128
129
 
129
- The _**Scheduler**_ can be configured with a _**Dispatcher**_, upon which case,
130
+ The _**Scheduler**_ can be configured with a _**Agent**_, upon which case,
130
131
  it will use it to spawn _**Instances**_.
131
132
 
132
- If the _**Dispatcher**_ is a _**Grid**_ member then the _**Scheduler**_ will
133
+ If the _**Agent**_ is a _**Grid**_ member then the _**Scheduler**_ will
133
134
  also enjoy _load-balancing_ features.
134
135
 
135
136
  ## APIs
@@ -153,7 +154,7 @@ RPC interface.
153
154
  A REST API is also available, taking advantage of HTTP sessions to make progress
154
155
  tracking easier.
155
156
 
156
- The REST interface is basically a web _**Dispatcher**_ and centralised point of
157
+ The REST interface is basically a web _**Agent**_ and centralised point of
157
158
  management for the rest of the entities.
158
159
 
159
160
  Each _**Application**_ can extend upon this and expose an API via its _**REST**_
data/cuboid.gemspec CHANGED
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.add_dependency 'oj_mimic_json', '1.0.1'
48
48
 
49
49
  # Web server
50
- s.add_dependency 'puma', '5.3.2'
50
+ s.add_dependency 'puma', '5.5.2'
51
51
 
52
52
  s.add_dependency 'rack', '2.2.3'
53
53
  s.add_dependency 'rack-test'
@@ -103,15 +103,15 @@ class Application
103
103
  @max_memory ||= 0
104
104
  end
105
105
 
106
- def provision_disk( ram )
107
- @max_disk = ram
106
+ def provision_disk( disk )
107
+ @max_disk = disk
108
108
  end
109
109
 
110
110
  def max_disk
111
- @max_memory ||= 0
111
+ @max_disk ||= 0
112
112
  end
113
113
 
114
- def instance_service_for(name, service )
114
+ def instance_service_for( name, service )
115
115
  instance_services[name] = service
116
116
  end
117
117
 
@@ -127,12 +127,12 @@ class Application
127
127
  @rest_services ||= {}
128
128
  end
129
129
 
130
- def dispatcher_service_for( name, service )
131
- dispatcher_services[name] = service
130
+ def agent_service_for( name, service )
131
+ agent_services[name] = service
132
132
  end
133
133
 
134
- def dispatcher_services
135
- @dispatcher_services ||= {}
134
+ def agent_services
135
+ @agent_services ||= {}
136
136
  end
137
137
 
138
138
  def handler_for( signal, handler )
@@ -183,8 +183,8 @@ class Application
183
183
  case type
184
184
  when :instance
185
185
  const = :Instances
186
- when :dispatcher
187
- const = :Dispatchers
186
+ when :agent
187
+ const = :Agents
188
188
  when :scheduler
189
189
  const = :Schedulers
190
190
  when :rest
@@ -0,0 +1,54 @@
1
+ module Cuboid::OptionGroups
2
+
3
+ # Holds options for {RPC::Server::Agent} servers.
4
+ #
5
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
6
+ class Agent < Cuboid::OptionGroup
7
+
8
+ STRATEGIES = Set.new([:horizontal, :vertical])
9
+
10
+ # @return [String]
11
+ # URL of a {RPC::Server::Agent}.
12
+ attr_accessor :url
13
+
14
+ # @return [Array<Integer>]
15
+ # Range of ports to use when spawning instances, first entry should be
16
+ # the lowest port number, last the max port number.
17
+ attr_accessor :instance_port_range
18
+
19
+ # @return [String]
20
+ # The URL of a peering {RPC::Server::Agent}, applicable when
21
+ # {RPC::Server::Agent} are connected to each other to form a Grid.
22
+ #
23
+ # @see RPC::Server::Agent::Node
24
+ attr_accessor :peer
25
+
26
+ # @return [Float]
27
+ # How regularly to check for peer statuses.
28
+ attr_accessor :ping_interval
29
+
30
+ # @return [String]
31
+ # Agent name.
32
+ attr_accessor :name
33
+
34
+ attr_accessor :strategy
35
+
36
+ set_defaults(
37
+ strategy: :horizontal,
38
+ ping_interval: 5.0,
39
+ instance_port_range: [1025, 65535]
40
+ )
41
+
42
+ def strategy=( type )
43
+ return @strategy = defaults[:strategy] if !type
44
+
45
+ type = type.to_sym
46
+ if !STRATEGIES.include? type
47
+ fail ArgumentError, "Unknown strategy type: #{type}"
48
+ end
49
+
50
+ @strategy = type
51
+ end
52
+
53
+ end
54
+ end
@@ -70,20 +70,25 @@ class Paths < Cuboid::OptionGroup
70
70
 
71
71
  # @!attribute executables
72
72
  # @return [String]
73
- # System processes (instance, dispatcher, browser, etc.).
73
+ # System processes (instance, agent, browser, etc.).
74
74
 
75
75
  def initialize
76
76
  @root = self.root_path
77
+ FileUtils.mkdir_p home_path
77
78
 
78
- @snapshots = self.config['snapshots'] || @root + 'snapshots/'
79
- @reports = self.config['reports'] || @root + 'reports/'
79
+ @snapshots = self.config['snapshots'] || home_path + 'snapshots/'
80
+ FileUtils.mkdir_p @snapshots
81
+
82
+ @reports = self.config['reports'] || home_path + 'reports/'
83
+ FileUtils.mkdir_p @reports
80
84
 
81
85
  if ENV['CUBOID_LOGDIR'].to_s != ''
82
86
  @logs = "#{ENV['CUBOID_LOGDIR']}/"
83
87
  elsif self.config['logs']
84
88
  @logs = self.config['logs']
85
89
  else
86
- @logs = "#{@root}logs/"
90
+ @logs = "#{home_path}logs/"
91
+ FileUtils.mkdir_p @logs
87
92
  end
88
93
 
89
94
  @lib = @root + 'lib/cuboid/'
@@ -98,6 +103,10 @@ class Paths < Cuboid::OptionGroup
98
103
  tmpdir
99
104
  end
100
105
 
106
+ def home_path
107
+ @home_path ||= "#{ENV['HOME']}/.cuboid/"
108
+ end
109
+
101
110
  def root_path
102
111
  self.class.root_path
103
112
  end
@@ -76,7 +76,7 @@ class Options
76
76
  require_relative 'option_groups'
77
77
 
78
78
  TO_RPC_IGNORE = Set.new([
79
- :instance, :rpc, :dispatcher, :queue, :paths,
79
+ :instance, :rpc, :agent, :queue, :paths,
80
80
  :snapshot, :report, :output, :system
81
81
  ])
82
82
 
@@ -2,28 +2,28 @@ module Cuboid
2
2
  module Processes
3
3
 
4
4
  #
5
- # Helper for managing {RPC::Server::Dispatcher} processes.
5
+ # Helper for managing {RPC::Server::Agent} processes.
6
6
  #
7
7
  # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
8
8
  #
9
- class Dispatchers
9
+ class Agents
10
10
  include Singleton
11
11
  include Utilities
12
12
 
13
- # @return [Array<String>] URLs of all running Dispatchers.
13
+ # @return [Array<String>] URLs of all running Agents.
14
14
  attr_reader :list
15
15
 
16
16
  def initialize
17
17
  @list = []
18
- @dispatcher_connections = {}
18
+ @agent_connections = {}
19
19
  end
20
20
 
21
- # Connects to a Dispatcher by URL.
21
+ # Connects to a Agent by URL.
22
22
  #
23
- # @param [String] url URL of the Dispatcher.
23
+ # @param [String] url URL of the Agent.
24
24
  # @param [Hash] options Options for the RPC client.
25
25
  #
26
- # @return [RPC::Client::Dispatcher]
26
+ # @return [RPC::Client::Agent]
27
27
  def connect( url, options = nil )
28
28
  Arachni::Reactor.global.run_in_thread if !Arachni::Reactor.global.running?
29
29
 
@@ -33,37 +33,51 @@ class Dispatchers
33
33
  end
34
34
 
35
35
  if fresh
36
- @dispatcher_connections[url] = RPC::Client::Dispatcher.new( url, options )
36
+ @agent_connections[url] = RPC::Client::Agent.new( url, options )
37
37
  else
38
- @dispatcher_connections[url] ||= RPC::Client::Dispatcher.new( url, options )
38
+ @agent_connections[url] ||= RPC::Client::Agent.new( url, options )
39
39
  end
40
40
  end
41
41
 
42
- # @param [Block] block Block to pass an RPC client for each Dispatcher.
42
+ # @param [Block] block Block to pass an RPC client for each Agent.
43
43
  def each( &block )
44
44
  @list.each do |url|
45
45
  block.call connect( url )
46
46
  end
47
47
  end
48
48
 
49
- # Spawns a {RPC::Server::Dispatcher} process.
49
+ # Spawns a {RPC::Server::Agent} process.
50
50
  #
51
51
  # @param [Hash] options
52
52
  # To be passed to {Cuboid::Options#set}. Allows `address` instead of
53
53
  # `rpc_server_address` and `port` instead of `rpc_port`.
54
54
  #
55
- # @return [RPC::Client::Dispatcher]
55
+ # @return [RPC::Client::Agent]
56
56
  def spawn( options = {} )
57
+ options = options.dup
57
58
  fork = options.delete(:fork)
58
59
 
60
+ options[:ssl] ||= {
61
+ server: {},
62
+ client: {}
63
+ }
64
+
59
65
  options = {
60
- dispatcher: {
61
- neighbour: options[:neighbour],
66
+ agent: {
67
+ name: options[:name],
68
+ peer: options[:peer],
69
+ strategy: options[:strategy],
62
70
  },
63
71
  rpc: {
64
72
  server_port: options[:port] || Utilities.available_port,
65
73
  server_address: options[:address] || '127.0.0.1',
66
- server_external_address: options[:external_address]
74
+ server_external_address: options[:external_address],
75
+
76
+ ssl_ca: options[:ssl][:ca],
77
+ server_ssl_private_key: options[:ssl][:server][:private_key],
78
+ server_ssl_certificate: options[:ssl][:server][:certificate],
79
+ client_ssl_private_key: options[:ssl][:client][:private_key],
80
+ client_ssl_certificate: options[:ssl][:client][:certificate],
67
81
  },
68
82
  paths: {
69
83
  application: options[:application] || Options.paths.application
@@ -74,11 +88,11 @@ class Dispatchers
74
88
  options[:rpc].delete :server_external_address
75
89
  end
76
90
 
77
- if options[:dispatcher][:neighbour].nil?
78
- options[:dispatcher].delete :neighbour
91
+ if options[:agent][:peer].nil?
92
+ options[:agent].delete :peer
79
93
  end
80
94
 
81
- pid = Manager.spawn( :dispatcher, options: options, fork: fork )
95
+ pid = Manager.spawn( :agent, options: options, fork: fork )
82
96
 
83
97
  url = "#{options[:rpc][:server_address]}:#{options[:rpc][:server_port]}"
84
98
  while sleep( 0.1 )
@@ -96,26 +110,26 @@ class Dispatchers
96
110
 
97
111
  def grid_spawn( options = {} )
98
112
  d = spawn( options )
99
- spawn( options.merge neighbour: d.url )
113
+ spawn( options.merge peer: d.url )
100
114
  end
101
115
 
102
- # @note Will also kill all Instances started by the Dispatcher.
116
+ # @note Will also kill all Instances started by the Agent.
103
117
  #
104
- # @param [String] url URL of the Dispatcher to kill.
118
+ # @param [String] url URL of the Agent to kill.
105
119
  def kill( url )
106
- dispatcher = connect( url )
107
- Manager.kill_many dispatcher.statistics['consumed_pids']
108
- Manager.kill dispatcher.pid
120
+ agent = connect( url )
121
+ Manager.kill_many agent.statistics['consumed_pids']
122
+ Manager.kill agent.pid
109
123
  rescue => e
110
124
  #ap e
111
125
  #ap e.backtrace
112
126
  nil
113
127
  ensure
114
128
  @list.delete( url )
115
- @dispatcher_connections.delete( url )
129
+ @agent_connections.delete( url )
116
130
  end
117
131
 
118
- # Kills all {Dispatchers #list}.
132
+ # Kills all {Agents #list}.
119
133
  def killall
120
134
  @list.dup.each do |url|
121
135
  kill url
@@ -0,0 +1,5 @@
1
+ require Options.paths.lib + 'rpc/server/agent'
2
+
3
+ Arachni::Reactor.global.run do
4
+ RPC::Server::Agent.new
5
+ end
@@ -0,0 +1,23 @@
1
+ # @param (see Cuboid::Processes::Agents#spawn)
2
+ # @return (see Cuboid::Processes::Agents#spawn)
3
+ def agent_spawn( *args )
4
+ Cuboid::Processes::Agents.spawn( *args )
5
+ end
6
+
7
+ # @param (see Cuboid::Processes::Agents#kill)
8
+ # @return (see Cuboid::Processes::Agents#kill)
9
+ def agent_kill( *args )
10
+ Cuboid::Processes::Agents.kill( *args )
11
+ end
12
+
13
+ # @param (see Cuboid::Processes::Agents#killall)
14
+ # @return (see Cuboid::Processes::Agents#killall)
15
+ def agent_killall
16
+ Cuboid::Processes::Agents.killall
17
+ end
18
+
19
+ # @param (see Cuboid::Processes::Agents#connect)
20
+ # @return (see Cuboid::Processes::Agents#connect)
21
+ def agent_connect( *args )
22
+ Cuboid::Processes::Agents.connect( *args )
23
+ end
@@ -10,10 +10,10 @@ def instance_grid_spawn( *args )
10
10
  Cuboid::Processes::Instances.grid_spawn( *args )
11
11
  end
12
12
 
13
- # @param (see Cuboid::Processes::Instances#dispatcher_spawn)
14
- # @return (see Cuboid::Processes::Instances#dispatcher_spawn)
15
- def instance_dispatcher_spawn( *args )
16
- Cuboid::Processes::Instances.dispatcher.spawn( *args )
13
+ # @param (see Cuboid::Processes::Instances#agent_spawn)
14
+ # @return (see Cuboid::Processes::Instances#agent_spawn)
15
+ def instance_agent_spawn( *args )
16
+ Cuboid::Processes::Instances.agent.spawn( *args )
17
17
  end
18
18
 
19
19
  def instance_kill( url )
@@ -1,4 +1,4 @@
1
1
  require_relative 'helpers/processes'
2
- require_relative 'helpers/dispatchers'
2
+ require_relative 'helpers/agents'
3
3
  require_relative 'helpers/instances'
4
4
  require_relative 'helpers/schedulers'
@@ -21,7 +21,7 @@ class Instances
21
21
  #
22
22
  # Connects to a Instance by URL.
23
23
  #
24
- # @param [String] url URL of the Dispatcher.
24
+ # @param [String] url URL of the Agent.
25
25
  # @param [String] token
26
26
  # Authentication token -- only need be provided once.
27
27
  #
@@ -61,16 +61,28 @@ class Instances
61
61
  # @return [RPC::Client::Instance, Integer]
62
62
  # RPC client and PID.
63
63
  def spawn( options = {}, &block )
64
+ options = options.dup
64
65
  token = options.delete(:token) || Utilities.generate_token
65
66
  fork = options.delete(:fork)
66
67
 
67
68
  port_range = options.delete( :port_range )
68
69
 
70
+ options[:ssl] ||= {
71
+ server: {},
72
+ client: {}
73
+ }
74
+
69
75
  options = {
70
76
  rpc: {
71
77
  server_socket: options[:socket],
72
78
  server_port: options[:port] || Utilities.available_port( port_range ),
73
- server_address: options[:address] || '127.0.0.1'
79
+ server_address: options[:address] || '127.0.0.1',
80
+
81
+ ssl_ca: options[:ssl][:ca],
82
+ server_ssl_private_key: options[:ssl][:server][:private_key],
83
+ server_ssl_certificate: options[:ssl][:server][:certificate],
84
+ client_ssl_private_key: options[:ssl][:client][:private_key],
85
+ client_ssl_certificate: options[:ssl][:client][:certificate],
74
86
  },
75
87
  paths: {
76
88
  application: options[:application] || Options.paths.application
@@ -113,10 +125,10 @@ class Instances
113
125
  end
114
126
  end
115
127
 
116
- # Starts {RPC::Server::Dispatcher} grid and returns a high-performance Instance.
128
+ # Starts {RPC::Server::Agent} grid and returns a high-performance Instance.
117
129
  #
118
130
  # @param [Hash] options
119
- # @option options [Integer] :grid_size (3) Amount of Dispatchers to spawn.
131
+ # @option options [Integer] :grid_size (3) Amount of Agents to spawn.
120
132
  #
121
133
  # @return [RPC::Client::Instance]
122
134
  def grid_spawn(options = {} )
@@ -124,23 +136,23 @@ class Instances
124
136
 
125
137
  last_member = nil
126
138
  options[:grid_size].times do |i|
127
- last_member = Dispatchers.spawn(
128
- neighbour: last_member ? last_member.url : last_member,
139
+ last_member = Agents.spawn(
140
+ peer: last_member ? last_member.url : last_member,
129
141
  pipe_id: Utilities.available_port.to_s + Utilities.available_port.to_s
130
142
  )
131
143
  end
132
144
 
133
145
  info = nil
134
- info = last_member.dispatch while !info && sleep( 0.1 )
146
+ info = last_member.spawn while !info && sleep( 0.1 )
135
147
 
136
148
  connect( info['url'], info['token'] )
137
149
  end
138
150
 
139
- # Starts {RPC::Server::Dispatcher} and returns an Instance.
151
+ # Starts {RPC::Server::Agent} and returns an Instance.
140
152
  #
141
153
  # @return [RPC::Client::Instance]
142
- def dispatcher_spawn
143
- info = Dispatchers.spawn.dispatch
154
+ def agent_spawn
155
+ info = Agents.spawn.spawn
144
156
  connect( info['url'], info['token'] )
145
157
  end
146
158
 
@@ -52,16 +52,29 @@ class Schedulers
52
52
  #
53
53
  # @return [RPC::Client::Queue]
54
54
  def spawn( options = {} )
55
+ options = options.dup
55
56
  fork = options.delete(:fork)
56
57
 
58
+ options[:ssl] ||= {
59
+ server: {},
60
+ client: {}
61
+ }
62
+
57
63
  options = {
58
- dispatcher: {
59
- url: options[:dispatcher],
64
+ agent: {
65
+ url: options[:agent],
66
+ strategy: options[:strategy]
60
67
  },
61
68
  rpc: {
62
69
  server_port: options[:port] || Utilities.available_port,
63
70
  server_address: options[:address] || '127.0.0.1',
64
- server_external_address: options[:external_address]
71
+ server_external_address: options[:external_address],
72
+
73
+ ssl_ca: options[:ssl][:ca],
74
+ server_ssl_private_key: options[:ssl][:server][:private_key],
75
+ server_ssl_certificate: options[:ssl][:server][:certificate],
76
+ client_ssl_private_key: options[:ssl][:client][:private_key],
77
+ client_ssl_certificate: options[:ssl][:client][:certificate],
65
78
  },
66
79
  paths: {
67
80
  application: options[:application] || Options.paths.application
@@ -3,11 +3,11 @@ require 'ostruct'
3
3
 
4
4
  lib = Cuboid::Options.paths.lib
5
5
  require lib + 'rpc/client/instance'
6
- require lib + 'rpc/client/dispatcher'
6
+ require lib + 'rpc/client/agent'
7
7
  require lib + 'rpc/client/scheduler'
8
8
 
9
9
  lib = Cuboid::Options.paths.lib + 'processes/'
10
10
  require lib + 'manager'
11
- require lib + 'dispatchers'
11
+ require lib + 'agents'
12
12
  require lib + 'instances'
13
13
  require lib + 'schedulers'
@@ -5,10 +5,10 @@ class Server
5
5
  module InstanceHelpers
6
6
 
7
7
  @@instances = {}
8
- @@dispatchers = {}
8
+ @@agents = {}
9
9
 
10
10
  def get_instance
11
- if dispatcher
11
+ if agent
12
12
  options = {
13
13
  owner: self.class.to_s,
14
14
  helpers: {
@@ -18,7 +18,7 @@ module InstanceHelpers
18
18
  }
19
19
  }
20
20
 
21
- if (info = dispatcher.dispatch( options ))
21
+ if (info = agent.spawn( options ))
22
22
  connect_to_instance( info['url'], info['token'] )
23
23
  end
24
24
  else
@@ -26,24 +26,24 @@ module InstanceHelpers
26
26
  end
27
27
  end
28
28
 
29
- def dispatchers
30
- @@dispatchers.keys
29
+ def agents
30
+ @@agents.keys
31
31
  end
32
32
 
33
- def dispatcher
34
- return if !Options.dispatcher.url
35
- @dispatcher ||= connect_to_dispatcher( Options.dispatcher.url )
33
+ def agent
34
+ return if !Options.agent.url
35
+ @agent ||= connect_to_agent( Options.agent.url )
36
36
  end
37
37
 
38
- def unplug_dispatcher( url )
39
- connect_to_dispatcher( url ).node.unplug
38
+ def unplug_agent( url )
39
+ connect_to_agent( url ).node.unplug
40
40
 
41
- c = @@dispatchers.delete( url )
41
+ c = @@agents.delete( url )
42
42
  c.close if c
43
43
  end
44
44
 
45
- def connect_to_dispatcher( url )
46
- @@dispatchers[url] ||= RPC::Client::Dispatcher.new( url )
45
+ def connect_to_agent( url )
46
+ @@agents[url] ||= RPC::Client::Agent.new( url )
47
47
  end
48
48
 
49
49
  def connect_to_instance( url, token )