cuboid 0.0.0 → 0.0.1alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -0
  3. data/Gemfile +20 -5
  4. data/LICENSE.md +22 -0
  5. data/README.md +158 -19
  6. data/Rakefile +56 -3
  7. data/config/paths.yml +15 -0
  8. data/cuboid.gemspec +61 -23
  9. data/lib/cuboid.rb +96 -4
  10. data/lib/cuboid/application.rb +326 -0
  11. data/lib/cuboid/application/parts/data.rb +18 -0
  12. data/lib/cuboid/application/parts/report.rb +29 -0
  13. data/lib/cuboid/application/parts/state.rb +274 -0
  14. data/lib/cuboid/application/runtime.rb +25 -0
  15. data/lib/cuboid/banner.rb +13 -0
  16. data/lib/cuboid/data.rb +86 -0
  17. data/lib/cuboid/data/application.rb +52 -0
  18. data/lib/cuboid/error.rb +9 -0
  19. data/lib/cuboid/option_group.rb +129 -0
  20. data/lib/cuboid/option_groups.rb +8 -0
  21. data/lib/cuboid/option_groups/datastore.rb +23 -0
  22. data/lib/cuboid/option_groups/dispatcher.rb +38 -0
  23. data/lib/cuboid/option_groups/output.rb +14 -0
  24. data/lib/cuboid/option_groups/paths.rb +184 -0
  25. data/lib/cuboid/option_groups/report.rb +39 -0
  26. data/lib/cuboid/option_groups/rpc.rb +105 -0
  27. data/lib/cuboid/option_groups/scheduler.rb +27 -0
  28. data/lib/cuboid/option_groups/snapshot.rb +13 -0
  29. data/lib/cuboid/option_groups/system.rb +10 -0
  30. data/lib/cuboid/options.rb +254 -0
  31. data/lib/cuboid/processes.rb +13 -0
  32. data/lib/cuboid/processes/dispatchers.rb +140 -0
  33. data/lib/cuboid/processes/executables/base.rb +54 -0
  34. data/lib/cuboid/processes/executables/dispatcher.rb +5 -0
  35. data/lib/cuboid/processes/executables/instance.rb +12 -0
  36. data/lib/cuboid/processes/executables/rest_service.rb +13 -0
  37. data/lib/cuboid/processes/executables/scheduler.rb +5 -0
  38. data/lib/cuboid/processes/helpers.rb +4 -0
  39. data/lib/cuboid/processes/helpers/dispatchers.rb +23 -0
  40. data/lib/cuboid/processes/helpers/instances.rb +39 -0
  41. data/lib/cuboid/processes/helpers/processes.rb +23 -0
  42. data/lib/cuboid/processes/helpers/schedulers.rb +23 -0
  43. data/lib/cuboid/processes/instances.rb +203 -0
  44. data/lib/cuboid/processes/manager.rb +262 -0
  45. data/lib/cuboid/processes/schedulers.rb +128 -0
  46. data/lib/cuboid/report.rb +220 -0
  47. data/lib/cuboid/rest/server.rb +165 -0
  48. data/lib/cuboid/rest/server/instance_helpers.rb +99 -0
  49. data/lib/cuboid/rest/server/routes/dispatcher.rb +41 -0
  50. data/lib/cuboid/rest/server/routes/grid.rb +41 -0
  51. data/lib/cuboid/rest/server/routes/instances.rb +131 -0
  52. data/lib/cuboid/rest/server/routes/scheduler.rb +140 -0
  53. data/lib/cuboid/rpc/client.rb +3 -0
  54. data/lib/cuboid/rpc/client/base.rb +58 -0
  55. data/lib/cuboid/rpc/client/dispatcher.rb +58 -0
  56. data/lib/cuboid/rpc/client/instance.rb +100 -0
  57. data/lib/cuboid/rpc/client/instance/service.rb +37 -0
  58. data/lib/cuboid/rpc/client/scheduler.rb +46 -0
  59. data/lib/cuboid/rpc/serializer.rb +92 -0
  60. data/lib/cuboid/rpc/server/active_options.rb +38 -0
  61. data/lib/cuboid/rpc/server/application_wrapper.rb +138 -0
  62. data/lib/cuboid/rpc/server/base.rb +63 -0
  63. data/lib/cuboid/rpc/server/dispatcher.rb +317 -0
  64. data/lib/cuboid/rpc/server/dispatcher/node.rb +247 -0
  65. data/lib/cuboid/rpc/server/dispatcher/service.rb +145 -0
  66. data/lib/cuboid/rpc/server/instance.rb +338 -0
  67. data/lib/cuboid/rpc/server/output.rb +92 -0
  68. data/lib/cuboid/rpc/server/scheduler.rb +482 -0
  69. data/lib/cuboid/ruby.rb +4 -0
  70. data/lib/cuboid/ruby/array.rb +17 -0
  71. data/lib/cuboid/ruby/hash.rb +41 -0
  72. data/lib/cuboid/ruby/object.rb +32 -0
  73. data/lib/cuboid/snapshot.rb +186 -0
  74. data/lib/cuboid/state.rb +94 -0
  75. data/lib/cuboid/state/application.rb +309 -0
  76. data/lib/cuboid/state/options.rb +27 -0
  77. data/lib/cuboid/support.rb +11 -0
  78. data/lib/cuboid/support/buffer.rb +3 -0
  79. data/lib/cuboid/support/buffer/autoflush.rb +61 -0
  80. data/lib/cuboid/support/buffer/base.rb +91 -0
  81. data/lib/cuboid/support/cache.rb +7 -0
  82. data/lib/cuboid/support/cache/base.rb +226 -0
  83. data/lib/cuboid/support/cache/least_cost_replacement.rb +77 -0
  84. data/lib/cuboid/support/cache/least_recently_pushed.rb +21 -0
  85. data/lib/cuboid/support/cache/least_recently_used.rb +31 -0
  86. data/lib/cuboid/support/cache/preference.rb +31 -0
  87. data/lib/cuboid/support/cache/random_replacement.rb +20 -0
  88. data/lib/cuboid/support/crypto.rb +2 -0
  89. data/lib/cuboid/support/crypto/rsa_aes_cbc.rb +86 -0
  90. data/lib/cuboid/support/database.rb +5 -0
  91. data/lib/cuboid/support/database/base.rb +177 -0
  92. data/lib/cuboid/support/database/categorized_queue.rb +195 -0
  93. data/lib/cuboid/support/database/hash.rb +300 -0
  94. data/lib/cuboid/support/database/queue.rb +149 -0
  95. data/lib/cuboid/support/filter.rb +3 -0
  96. data/lib/cuboid/support/filter/base.rb +110 -0
  97. data/lib/cuboid/support/filter/set.rb +29 -0
  98. data/lib/cuboid/support/glob.rb +27 -0
  99. data/lib/cuboid/support/mixins.rb +8 -0
  100. data/lib/cuboid/support/mixins/observable.rb +99 -0
  101. data/lib/cuboid/support/mixins/parts.rb +20 -0
  102. data/lib/cuboid/support/mixins/profiler.rb +93 -0
  103. data/lib/cuboid/support/mixins/spec_instances.rb +65 -0
  104. data/lib/cuboid/support/mixins/terminal.rb +57 -0
  105. data/lib/cuboid/system.rb +119 -0
  106. data/lib/cuboid/system/platforms.rb +84 -0
  107. data/lib/cuboid/system/platforms/linux.rb +26 -0
  108. data/lib/cuboid/system/platforms/mixins/unix.rb +46 -0
  109. data/lib/cuboid/system/platforms/osx.rb +25 -0
  110. data/lib/cuboid/system/platforms/windows.rb +81 -0
  111. data/lib/cuboid/system/slots.rb +143 -0
  112. data/lib/cuboid/ui/output.rb +52 -0
  113. data/lib/cuboid/ui/output_interface.rb +43 -0
  114. data/lib/cuboid/ui/output_interface/abstract.rb +68 -0
  115. data/lib/cuboid/ui/output_interface/controls.rb +84 -0
  116. data/lib/cuboid/ui/output_interface/error_logging.rb +119 -0
  117. data/lib/cuboid/ui/output_interface/implemented.rb +58 -0
  118. data/lib/cuboid/ui/output_interface/personalization.rb +62 -0
  119. data/lib/cuboid/utilities.rb +155 -0
  120. data/lib/cuboid/version.rb +4 -3
  121. data/lib/version +1 -0
  122. data/logs/placeholder +0 -0
  123. data/spec/cuboid/application/parts/data_spec.rb +12 -0
  124. data/spec/cuboid/application/parts/report_spec.rb +6 -0
  125. data/spec/cuboid/application/parts/state_spec.rb +192 -0
  126. data/spec/cuboid/application/runtime_spec.rb +21 -0
  127. data/spec/cuboid/application_spec.rb +37 -0
  128. data/spec/cuboid/data/application_spec.rb +22 -0
  129. data/spec/cuboid/data_spec.rb +47 -0
  130. data/spec/cuboid/error_spec.rb +23 -0
  131. data/spec/cuboid/option_groups/datastore_spec.rb +54 -0
  132. data/spec/cuboid/option_groups/dispatcher_spec.rb +12 -0
  133. data/spec/cuboid/option_groups/output_spec.rb +11 -0
  134. data/spec/cuboid/option_groups/paths_spec.rb +184 -0
  135. data/spec/cuboid/option_groups/report_spec.rb +26 -0
  136. data/spec/cuboid/option_groups/rpc_spec.rb +53 -0
  137. data/spec/cuboid/option_groups/snapshot_spec.rb +26 -0
  138. data/spec/cuboid/option_groups/system.rb +12 -0
  139. data/spec/cuboid/options_spec.rb +218 -0
  140. data/spec/cuboid/report_spec.rb +221 -0
  141. data/spec/cuboid/rest/server_spec.rb +1205 -0
  142. data/spec/cuboid/rpc/client/base_spec.rb +151 -0
  143. data/spec/cuboid/rpc/client/dispatcher_spec.rb +13 -0
  144. data/spec/cuboid/rpc/client/instance_spec.rb +38 -0
  145. data/spec/cuboid/rpc/server/active_options_spec.rb +21 -0
  146. data/spec/cuboid/rpc/server/base_spec.rb +60 -0
  147. data/spec/cuboid/rpc/server/dispatcher/node_spec.rb +222 -0
  148. data/spec/cuboid/rpc/server/dispatcher/service_spec.rb +112 -0
  149. data/spec/cuboid/rpc/server/dispatcher_spec.rb +317 -0
  150. data/spec/cuboid/rpc/server/instance_spec.rb +307 -0
  151. data/spec/cuboid/rpc/server/output_spec.rb +32 -0
  152. data/spec/cuboid/rpc/server/scheduler_spec.rb +400 -0
  153. data/spec/cuboid/ruby/array_spec.rb +77 -0
  154. data/spec/cuboid/ruby/hash_spec.rb +63 -0
  155. data/spec/cuboid/ruby/object_spec.rb +22 -0
  156. data/spec/cuboid/snapshot_spec.rb +123 -0
  157. data/spec/cuboid/state/application_spec.rb +538 -0
  158. data/spec/cuboid/state/options_spec.rb +37 -0
  159. data/spec/cuboid/state_spec.rb +53 -0
  160. data/spec/cuboid/support/buffer/autoflush_spec.rb +78 -0
  161. data/spec/cuboid/support/buffer/base_spec.rb +193 -0
  162. data/spec/cuboid/support/cache/least_cost_replacement_spec.rb +61 -0
  163. data/spec/cuboid/support/cache/least_recently_pushed_spec.rb +90 -0
  164. data/spec/cuboid/support/cache/least_recently_used_spec.rb +80 -0
  165. data/spec/cuboid/support/cache/preference_spec.rb +37 -0
  166. data/spec/cuboid/support/cache/random_replacement_spec.rb +42 -0
  167. data/spec/cuboid/support/crypto/rsa_aes_cbc_spec.rb +28 -0
  168. data/spec/cuboid/support/database/categorized_queue_spec.rb +327 -0
  169. data/spec/cuboid/support/database/hash_spec.rb +204 -0
  170. data/spec/cuboid/support/database/scheduler_spec.rb +325 -0
  171. data/spec/cuboid/support/filter/set_spec.rb +19 -0
  172. data/spec/cuboid/support/glob_spec.rb +75 -0
  173. data/spec/cuboid/support/mixins/observable_spec.rb +95 -0
  174. data/spec/cuboid/system/platforms/linux_spec.rb +31 -0
  175. data/spec/cuboid/system/platforms/osx_spec.rb +32 -0
  176. data/spec/cuboid/system/platforms/windows_spec.rb +41 -0
  177. data/spec/cuboid/system/slots_spec.rb +202 -0
  178. data/spec/cuboid/system_spec.rb +105 -0
  179. data/spec/cuboid/utilities_spec.rb +131 -0
  180. data/spec/spec_helper.rb +46 -0
  181. data/spec/support/factories/placeholder +0 -0
  182. data/spec/support/factories/scan_report.rb +18 -0
  183. data/spec/support/fixtures/empty/placeholder +0 -0
  184. data/spec/support/fixtures/executables/node.rb +50 -0
  185. data/spec/support/fixtures/mock_app.rb +61 -0
  186. data/spec/support/fixtures/mock_app/test_service.rb +64 -0
  187. data/spec/support/fixtures/services/echo.rb +64 -0
  188. data/spec/support/helpers/framework.rb +3 -0
  189. data/spec/support/helpers/matchers.rb +5 -0
  190. data/spec/support/helpers/misc.rb +3 -0
  191. data/spec/support/helpers/paths.rb +15 -0
  192. data/spec/support/helpers/request_helpers.rb +38 -0
  193. data/spec/support/helpers/requires.rb +8 -0
  194. data/spec/support/helpers/resets.rb +52 -0
  195. data/spec/support/helpers/web_server.rb +15 -0
  196. data/spec/support/lib/factory.rb +107 -0
  197. data/spec/support/lib/web_server_client.rb +41 -0
  198. data/spec/support/lib/web_server_dispatcher.rb +25 -0
  199. data/spec/support/lib/web_server_manager.rb +118 -0
  200. data/spec/support/logs/placeholder +0 -0
  201. data/spec/support/pems/cacert.pem +37 -0
  202. data/spec/support/pems/client/cert.pem +37 -0
  203. data/spec/support/pems/client/foo-cert.pem +39 -0
  204. data/spec/support/pems/client/foo-key.pem +51 -0
  205. data/spec/support/pems/client/key.pem +51 -0
  206. data/spec/support/pems/server/cert.pem +37 -0
  207. data/spec/support/pems/server/key.pem +51 -0
  208. data/spec/support/reports/placeholder +0 -0
  209. data/spec/support/shared/application.rb +10 -0
  210. data/spec/support/shared/component.rb +31 -0
  211. data/spec/support/shared/component/options/base.rb +187 -0
  212. data/spec/support/shared/option_group.rb +98 -0
  213. data/spec/support/shared/support/cache.rb +419 -0
  214. data/spec/support/shared/support/filter.rb +143 -0
  215. data/spec/support/shared/system/platforms/base.rb +25 -0
  216. data/spec/support/shared/system/platforms/mixins/unix.rb +37 -0
  217. data/spec/support/snapshots/placeholder +0 -0
  218. metadata +566 -21
  219. data/.gitignore +0 -8
  220. data/bin/console +0 -15
  221. data/bin/setup +0 -8
@@ -0,0 +1,25 @@
1
+ module Cuboid
2
+ class Application
3
+
4
+ class Runtime
5
+
6
+ def state
7
+ Cuboid::Application.application.state.runtime
8
+ end
9
+
10
+ def state=( d )
11
+ Cuboid::Application.application.state.runtime = d
12
+ end
13
+
14
+ def data
15
+ Cuboid::Application.application.data.runtime
16
+ end
17
+
18
+ def data=( d )
19
+ Cuboid::Application.application.data.runtime = d
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ module Cuboid
5
+
6
+ WEBSITE = 'http://placeholder.com'
7
+
8
+ BANNER =<<EOBANNER
9
+ Cuboid - Ruby Framework v#{VERSION}
10
+ by Placeholder LLC <#{WEBSITE}>
11
+ EOBANNER
12
+
13
+ end
@@ -0,0 +1,86 @@
1
+ module Cuboid
2
+
3
+ # Stores and provides access to the data of the system.
4
+ #
5
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
6
+ class Data
7
+
8
+ # {Data} error namespace.
9
+ #
10
+ # All {Data} errors inherit from and live under it.
11
+ #
12
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
13
+ class Error < Cuboid::Error
14
+ end
15
+
16
+ require_relative 'data/application'
17
+
18
+ class <<self
19
+
20
+ # @return [Framework]
21
+ attr_accessor :application
22
+
23
+ def reset
24
+ @application = Application.new
25
+ end
26
+
27
+ def statistics
28
+ stats = {}
29
+ each do |attribute|
30
+ stats[attribute] = send(attribute).statistics
31
+ end
32
+ stats
33
+ end
34
+
35
+ # @param [String] directory
36
+ # Location of the dump directory.
37
+ # @return [String]
38
+ # Location of the dump directory.
39
+ def dump( directory )
40
+ FileUtils.mkdir_p( directory )
41
+
42
+ each do |name, state|
43
+ state.dump( "#{directory}/#{name}/" )
44
+ end
45
+
46
+ directory
47
+ end
48
+
49
+ # @param [String] directory
50
+ # Location of the dump directory.
51
+ # @return [Data] `self`
52
+ def load( directory )
53
+ each do |name, state|
54
+ send( "#{name}=", state.class.load( "#{directory}/#{name}/" ) )
55
+ end
56
+
57
+ self
58
+ end
59
+
60
+ # Clears all data.
61
+ def clear
62
+ each { |_, state| state.clear }
63
+ self
64
+ end
65
+
66
+ private
67
+
68
+ def each( &block )
69
+ accessors.each do |attr|
70
+ block.call attr, send( attr )
71
+ end
72
+ end
73
+
74
+ def accessors
75
+ instance_variables.map do |ivar|
76
+ attribute = "#{ivar.to_s.gsub('@','')}"
77
+ next if !methods.include?( :"#{attribute}=" )
78
+ attribute.to_sym
79
+ end.compact
80
+ end
81
+
82
+ end
83
+
84
+ reset
85
+ end
86
+ end
@@ -0,0 +1,52 @@
1
+ module Cuboid
2
+ class Data
3
+
4
+ # Data for {Cuboid::Application}.
5
+ #
6
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
7
+ class Application
8
+
9
+ # {Application} error namespace.
10
+ #
11
+ # All {Application} errors inherit from and live under it.
12
+ #
13
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
14
+ class Error < Data::Error
15
+ end
16
+
17
+ attr_accessor :runtime
18
+ attr_accessor :report
19
+
20
+ def statistics
21
+ {
22
+ runtime: !!@runtime,
23
+ report: !!@report
24
+ }
25
+ end
26
+
27
+ def dump( directory )
28
+ FileUtils.mkdir_p( directory )
29
+
30
+ d = Cuboid::Application.serializer.dump( @report )
31
+ IO.binwrite( "#{directory}/report", d )
32
+
33
+ d = Cuboid::Application.serializer.dump( @runtime )
34
+ IO.binwrite( "#{directory}/runtime", d )
35
+ end
36
+
37
+ def self.load( directory )
38
+ application = new
39
+ application.report = Cuboid::Application.serializer.load( IO.binread( "#{directory}/report" ) )
40
+ application.runtime = Cuboid::Application.serializer.load( IO.binread( "#{directory}/runtime" ) )
41
+ application
42
+ end
43
+
44
+ def clear
45
+ @runtime = nil
46
+ @report = nil
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ module Cuboid
2
+
3
+ # It provides a namespace for all system errors.
4
+ #
5
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
6
+ class Error < StandardError
7
+ end
8
+
9
+ end
@@ -0,0 +1,129 @@
1
+ module Cuboid
2
+
3
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
4
+ class OptionGroup
5
+
6
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
7
+ class Error < Options::Error
8
+ end
9
+
10
+ class <<self
11
+
12
+ # @return [Hash]
13
+ # Specified default values for attribute readers.
14
+ def defaults
15
+ @defaults ||= {}
16
+ end
17
+
18
+ # Sets default values for attribute readers, when an attribute reader
19
+ # returns `nil` the default values will be returned instead.
20
+ #
21
+ # @param [Hash] default_values
22
+ # Default values for attributes.
23
+ def set_defaults( default_values )
24
+ defaults.merge! default_values
25
+
26
+ # Set the specified default values as overrides to the attribute
27
+ # readers.
28
+ defaults.each do |ivar, value|
29
+ define_method "#{ivar}=" do |v|
30
+ instance_variable_set( "@#{ivar}".to_sym, v.nil? ? value : v)
31
+ end
32
+ end
33
+
34
+ defaults
35
+ end
36
+
37
+ def inherited( child )
38
+ Options.register_group child
39
+ end
40
+ end
41
+
42
+ def initialize
43
+ defaults.each do |k, v|
44
+ send "#{k}=", v
45
+ end
46
+ end
47
+
48
+ def to_rpc_data
49
+ to_h.my_stringify_keys(false)
50
+ end
51
+
52
+ # @return [Hash]
53
+ # Values for all attribute accessors which aren't the defaults.
54
+ def to_h
55
+ h = {}
56
+ instance_variables.each do |ivar|
57
+ method = normalize_ivar( ivar )
58
+ sym = method.to_sym
59
+ value = instance_variable_get( ivar )
60
+
61
+ next if !respond_to?( "#{method}=" )
62
+
63
+ h[sym] = value
64
+ end
65
+ h
66
+ end
67
+ def to_hash
68
+ to_h
69
+ end
70
+
71
+ # @return [Hash]
72
+ # Hash of errors with the name of the invalid options as the keys.
73
+ #
74
+ # @abstract
75
+ def validate
76
+ {}
77
+ end
78
+
79
+ def ==( other )
80
+ hash == other.hash
81
+ end
82
+
83
+ def hash
84
+ to_h.hash
85
+ end
86
+
87
+ # @param [Hash] options
88
+ # Data to use to update the group's attributes.
89
+ #
90
+ # @return [OptionGroup]
91
+ # `self`
92
+ def update( options )
93
+ options.to_hash.each { |k, v| send( "#{k}=", v ) }
94
+ self
95
+ end
96
+
97
+ # @param [OptionGroup] other
98
+ #
99
+ # @return [OptionGroup]
100
+ # `self`
101
+ def merge( other )
102
+ update( other.to_h )
103
+ end
104
+
105
+ # @return (see .defaults)
106
+ def defaults
107
+ self.class.defaults
108
+ end
109
+
110
+ def self.attr_accessor( *vars )
111
+ attributes.concat( vars )
112
+ super( *vars )
113
+ end
114
+
115
+ def self.attributes
116
+ @attributes ||= []
117
+ end
118
+
119
+ def attributes
120
+ self.class.attributes
121
+ end
122
+
123
+ private
124
+
125
+ def normalize_ivar( ivar )
126
+ ivar.to_s.gsub( '@', '' )
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'option_group'
2
+
3
+ # We need this to be available prior to loading the rest of the groups.
4
+ require_relative 'option_groups/paths'
5
+
6
+ Dir.glob( "#{File.dirname(__FILE__)}/option_groups/*.rb" ).each do |group|
7
+ require group
8
+ end
@@ -0,0 +1,23 @@
1
+ require 'ostruct'
2
+
3
+ module Cuboid::OptionGroups
4
+
5
+ # Generic OpenStruct-based class for general purpose data storage.
6
+ #
7
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
8
+ class Datastore < Cuboid::OptionGroup
9
+
10
+ def initialize
11
+ @source = OpenStruct.new
12
+ end
13
+
14
+ def method_missing( method, *args, &block )
15
+ @source.send( method, *args, &block )
16
+ end
17
+
18
+ def to_h
19
+ @source.marshal_dump
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module Cuboid::OptionGroups
2
+
3
+ # Holds options for {RPC::Server::Dispatcher} servers.
4
+ #
5
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
6
+ class Dispatcher < Cuboid::OptionGroup
7
+
8
+ # @return [String]
9
+ # URL of a {RPC::Server::Dispatcher}.
10
+ attr_accessor :url
11
+
12
+ # @return [Array<Integer>]
13
+ # Range of ports to use when spawning instances, first entry should be
14
+ # the lowest port number, last the max port number.
15
+ attr_accessor :instance_port_range
16
+
17
+ # @return [String]
18
+ # The URL of a neighbouring {RPC::Server::Dispatcher}, applicable when
19
+ # {RPC::Server::Dispatcher} are connected to each other to form a Grid.
20
+ #
21
+ # @see RPC::Server::Dispatcher::Node
22
+ attr_accessor :neighbour
23
+
24
+ # @return [Float]
25
+ # How regularly to check for neighbour statuses.
26
+ attr_accessor :ping_interval
27
+
28
+ # @return [String]
29
+ # Dispatcher name.
30
+ attr_accessor :name
31
+
32
+ set_defaults(
33
+ ping_interval: 5.0,
34
+ instance_port_range: [1025, 65535]
35
+ )
36
+
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module Cuboid::OptionGroups
2
+
3
+ # {Cuboid::UI::Output} options.
4
+ #
5
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
6
+ class Output < Cuboid::OptionGroup
7
+
8
+ # @return [Bool]
9
+ # `true` if the output of the RPC instances should be redirected to a
10
+ # file, `false` otherwise.
11
+ attr_accessor :reroute_to_logfile
12
+
13
+ end
14
+ end
@@ -0,0 +1,184 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ module Cuboid::OptionGroups
5
+
6
+ # Holds paths to the directories of various system components.
7
+ #
8
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
9
+ class Paths < Cuboid::OptionGroup
10
+
11
+ TMPDIR_SUFFIX = 'Cuboid_'
12
+
13
+ [
14
+ :root,
15
+ :logs,
16
+ :reports,
17
+ :executables,
18
+ :services,
19
+ :lib,
20
+ :support,
21
+ :mixins,
22
+ :snapshots
23
+ ].each do |type|
24
+ attr_accessor type
25
+
26
+ define_method "#{type}=" do |path|
27
+ if !path
28
+ return instance_variable_set :"@#{type}", defaults[type]
29
+ end
30
+
31
+ path += '/' if !path.end_with? '/'
32
+
33
+ if !File.directory? path
34
+ raise ArgumentError,
35
+ "#{type.to_s.capitalize} directory does not exist: #{path}"
36
+ end
37
+
38
+ instance_variable_set :"@#{type}", path
39
+ end
40
+ end
41
+
42
+ # @return [String]
43
+ attr_accessor :application
44
+
45
+ # @!attribute root
46
+ # @return [String]
47
+
48
+ # @!attribute lib
49
+ # @return [String]
50
+
51
+ # @!attribute support
52
+ # @return [String]
53
+
54
+ # @!attribute mixins
55
+ # @return [String]
56
+
57
+ # @!attribute components
58
+ # @return [String]
59
+
60
+ # @!attribute services
61
+ # @return [String]
62
+
63
+ # @!attribute reports
64
+ # @return [String]
65
+ # Report storage.
66
+
67
+ # @!attribute snapshots
68
+ # @return [String]
69
+ # Snapshot storage.
70
+
71
+ # @!attribute executables
72
+ # @return [String]
73
+ # System processes (instance, dispatcher, browser, etc.).
74
+
75
+ def initialize
76
+ @root = self.root_path
77
+
78
+ @snapshots = self.config['snapshots'] || @root + 'snapshots/'
79
+ @reports = self.config['reports'] || @root + 'reports/'
80
+
81
+ if ENV['CUBOID_LOGDIR'].to_s != ''
82
+ @logs = "#{ENV['CUBOID_LOGDIR']}/"
83
+ elsif self.config['logs']
84
+ @logs = self.config['logs']
85
+ else
86
+ @logs = "#{@root}logs/"
87
+ end
88
+
89
+ @lib = @root + 'lib/cuboid/'
90
+ @executables = @lib + 'processes/executables/'
91
+ @support = @lib + 'support/'
92
+ @mixins = @support + 'mixins/'
93
+
94
+ instance_variables.each do |iv|
95
+ defaults[iv.to_s.sub( '@', '' ).to_sym] = instance_variable_get( iv )
96
+ end
97
+
98
+ tmpdir
99
+ end
100
+
101
+ def root_path
102
+ self.class.root_path
103
+ end
104
+
105
+ # @return [String]
106
+ # Root path of the engine.
107
+ def self.root_path
108
+ File.expand_path( File.dirname( __FILE__ ) + '/../../..' ) + '/'
109
+ end
110
+
111
+ def os_tmpdir
112
+ return @os_tmpdir if @os_tmpdir
113
+
114
+ if config['tmpdir'].to_s.empty?
115
+ # On MS Windows Dir.tmpdir can return the path with a shortname,
116
+ # better avoid that as it can be insonsistent with other paths.
117
+ @os_tmpdir = Cuboid.get_long_win32_filename( Dir.tmpdir )
118
+ else
119
+ @os_tmpdir = Cuboid.get_long_win32_filename( config['tmpdir'] )
120
+ end
121
+ end
122
+
123
+ def tmpdir
124
+ return @tmpdir if @tmpdir
125
+
126
+ dir = tmp_dir_for( Process.pid )
127
+
128
+ FileUtils.mkdir_p dir
129
+ at_exit do
130
+ FileUtils.rm_rf dir
131
+ end
132
+
133
+ @tmpdir = dir
134
+ end
135
+
136
+ def tmp_dir_for( pid )
137
+ "#{os_tmpdir}/#{TMPDIR_SUFFIX}#{pid}"
138
+ end
139
+
140
+ def config
141
+ self.class.config
142
+ end
143
+
144
+ def self.paths_config_file
145
+ Cuboid.get_long_win32_filename "#{root_path}config/paths.yml"
146
+ end
147
+
148
+ def self.clear_config_cache
149
+ @config = nil
150
+ end
151
+
152
+ def self.config
153
+ return @config if @config
154
+
155
+ if !File.exist?( paths_config_file )
156
+ @config = {}
157
+ else
158
+ @config = YAML.load( IO.read( paths_config_file ) )
159
+ end
160
+
161
+ @config.dup.each do |category, dir|
162
+ if dir.to_s.empty?
163
+ @config.delete( category )
164
+ next
165
+ end
166
+
167
+ dir = Cuboid.get_long_win32_filename( dir )
168
+
169
+ if !Cuboid.windows?
170
+ dir.gsub!( '~', ENV['HOME'] )
171
+ end
172
+
173
+ dir << '/' if !dir.end_with?( '/' )
174
+
175
+ @config[category] = dir
176
+
177
+ FileUtils.mkdir_p dir
178
+ end
179
+
180
+ @config
181
+ end
182
+
183
+ end
184
+ end