cuboid 0.0.0 → 0.0.1alpha

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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db5d6348cba47291af1506eda7d15f9e0bb215d02d3f586391f57c8e18728c8c
4
- data.tar.gz: 202f146996c35458cb047aeb6ea1b5bba64a0b553a3e7d3d317fea2d8970200c
3
+ metadata.gz: b40773cee8ae1dcd306b0d5e1832f0b9948116f0098fedf1e3f5d6b89e8f7fe4
4
+ data.tar.gz: 38d5ef49a0329bb16788467653875820994c604d6ac20128e95af8b26811d7eb
5
5
  SHA512:
6
- metadata.gz: 9f1a80f285c1cb7be6330048f69e6a070f85cead9ddf15a22a463fa5831679a97ef801b6b27b6d9740a41098a0d1a0c73aa6d507222c6cb53b3d878b05dad660
7
- data.tar.gz: 6ca864801895355a080dfeaf28736196cabcb3e8bf3922934c16ad0e2a8520ac8ab9bcaf0be9075002d90d9a423648435d5cab3aca097f0b924dc73fdfa56aa1
6
+ metadata.gz: 7a83686aa22ee70f5bcdb9ee597c7dcc3f00fcbc511ad337980b725dfc47e0e94ff5089e73d26835a25777b389c79d9294c1ec4a7584d9ca18341a193a258d48
7
+ data.tar.gz: f9eb78ace44e7754f91543a9738443a8c15fe7fdac558a96aaf7290da5fa3cf35f570b49b82a51b5de2fd78e56781b80de9496eedf4632a8eedf8e8b360d3d0a
data/CHANGELOG.md ADDED
File without changes
data/Gemfile CHANGED
@@ -1,8 +1,23 @@
1
- # frozen_string_literal: true
1
+ source 'https://rubygems.org'
2
2
 
3
- source "https://rubygems.org"
3
+ gem 'rake', '11.3.0'
4
4
 
5
- # Specify your gem's dependencies in cuboid.gemspec
6
- gemspec
5
+ group :docs do
6
+ gem 'yard'
7
+ gem 'redcarpet'
8
+ end
9
+
10
+ group :spec do
11
+ gem 'simplecov', require: false, group: :test
12
+
13
+ gem 'typhoeus'
14
+ gem 'rspec'
15
+ gem 'faker'
16
+ end
7
17
 
8
- gem "rake", "~> 13.0"
18
+ group :prof do
19
+ gem 'benchmark-ips'
20
+ gem 'memory_profiler'
21
+ end
22
+
23
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ # License
2
+
3
+ Copyright (c) 2021 Tasos Laskos \<tasos.laskos@gmail.com\>.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,35 +1,174 @@
1
- # Cuboid
1
+ # Cuboid Framework -- a decentralized distributed framework in Ruby.
2
+
3
+ ## Summary
4
+
5
+ The Cuboid Framework offers the possibility of easily creating decentralized and
6
+ distributed applications in Ruby.
7
+
8
+ In hipper terms, you can very easily setup your own specialized _Cloud_ or
9
+ _Cloud_ within a _Cloud_.
10
+
11
+ It offers:
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
15
+ convergence on their own, just point them to an existing _**Grid**_ member.
16
+ * Scaling up and down can be easily achieved by _plugging_ or _unplugging_ nodes.
17
+ * Fault tolerant -- one application per process (_**Instance**_).
18
+ * Self-healing -- keeps an eye out for disappearing and also re-appearing members.
19
+ * A clean and simple framework for application development.
20
+ * Basically, Ruby -- and all the libraries and extensions that come with it.
21
+ * Events (_pause_, _resume_, _abort_, _suspend_, _restore_).
22
+ * Suspend to disk is a cinch by automatically creating a _**snapshot**_
23
+ of the runtime environment of the application and storing it to disk
24
+ for later restoration of state and data.
25
+ * Also allows for running job transfers.
26
+ * Management of Instances via RPC or REST APIs.
27
+ * Aside from what **Cuboid** uses, custom serializers can be specified for
28
+ application related objects.
29
+ * Developer freedom.
30
+ * Apart from keeping _Data_ and _State_ separate not many other rules to follow.
31
+ * Only if interested in _suspensions_ and can also be left to the last minute
32
+ if necessary -- in cases of Ractor enforced isolation for example.
33
+
34
+ ## Entities
35
+
36
+ ### Application
37
+
38
+ A Ruby `class` which inherits from `Cuboid::Application` and complies with a few
39
+ simple specifications; at the least, a `#run` method, serving as the execution
40
+ entry point.
2
41
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cuboid`. To experiment with that code, run `bin/console` for an interactive prompt.
42
+ The application can use the following methods to better take advantage of the
43
+ framework:
4
44
 
5
- TODO: Delete this and the text above, and describe your gem
45
+ * `#validate_options( options )` -- Validates _**Application**_ options.
46
+ * `#provision_cores( Fixnum )` -- Specifies the maximum amount of cores the
47
+ _**Application**_ will be using.
48
+ * `#provision_memory( Fixnum )` -- Specifies the maximum amount of RAM the
49
+ _**Application**_ will be using.
50
+ * `#provision_disk( Fixnum )` -- Specifies the maximum amount of disk space the
51
+ _**Application**_ will be using.
52
+ * `#handler_for( Symbol, Symbol )` -- Specifies methods to handle the following events:
53
+ * `:pause`
54
+ * `:resume`
55
+ * `:abort`
56
+ * `:suspend`
57
+ * `:restore`
58
+ * `instance_service_for( Symbol, Class )` -- Adds a custom _**Instance**_ RPC API.
59
+ * `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
+ * `serialize_with( Module )` -- A serializer to be used for:
62
+ * `#options`
63
+ * `Report#data`
64
+ * `Runtime` `Snapshot`
6
65
 
7
- ## Installation
66
+ Access is also available to:
8
67
 
9
- Add this line to your application's Gemfile:
68
+ * `#options` -- Passed options.
69
+ * `#runtime` -- The _**Application**_'s `Runtime` environment, as a way to
70
+ store and access _state_ and _data_. Upon receiving a _suspend_ event, the
71
+ `Runtime` will be stored to disk as a `Snapshot` for later restoration.
72
+ * `Runtime#state` -- State accessor.
73
+ * `Runtime#data` -- Data accessor.
74
+ * `#report( data )` -- Stores given `data`, to be included in a later generated
75
+ `Report` and accessed via `Report#data`.
10
76
 
11
- ```ruby
12
- gem 'cuboid'
13
- ```
77
+ ### Instance
14
78
 
15
- And then execute:
79
+ An _**Instance**_ is a process container for a **Cuboid** _**Application**_;
80
+ **Cuboid** is application-centric and follows the one process-per-application principle.
16
81
 
17
- $ bundle install
82
+ This is in order to enforce isolation (_state_, _data_, _fault_) between
83
+ _**Applications**_, take advantage of _OS_ task management and generally keep
84
+ things simple.
18
85
 
19
- Or install it yourself as:
86
+ ### Dispatcher
20
87
 
21
- $ gem install cuboid
88
+ A _**Dispatcher**_ is a server which awaits for _**Instance**_ spawn requests
89
+ (`dispatch` calls) upon which it spawns and passes the _**Instance**_'s
90
+ connection info to the client.
22
91
 
23
- ## Usage
92
+ The client can then proceed to use the _**Instance**_ to run and generally manage
93
+ the contained _**Application**_.
24
94
 
25
- TODO: Write usage instructions here
95
+ #### Grid
26
96
 
27
- ## Development
97
+ A _**Dispatcher**_ _**Grid**_ is a software mesh network of _**Dispatcher**_
98
+ servers, aimed towards providing automated _load-balancing_ based on available
99
+ system resources and each _**Application**_'s provisioning configuration.
28
100
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+ No _topology_ needs to be specified, the only configuration necessary is
102
+ providing any existing _**Grid**_ member upon start-up and the rest will be
103
+ sorted out automatically.
30
104
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
105
+ The network is _self-healing_ and will monitor _node_ connectivity, taking steps
106
+ to ensure that neither server nor network conditions will disrupt dispatching.
32
107
 
33
- ## Contributing
108
+ ##### Scalability
34
109
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cuboid.
110
+ _**Dispatchers**_ can be easily _plugged_ to or _unplugged_ from the _**Grid**_
111
+ to scale up or down as necessary.
112
+
113
+ _Plugging_ happens at boot-time and _unplugging_ can take place via the available
114
+ _APIs_.
115
+
116
+ ### Scheduler
117
+
118
+ The _**Scheduler**_ is a server which:
119
+
120
+ 1. Accepts _**Application**_ options.
121
+ 2. Stores them in a queue.
122
+ 3. Pops options and passes them to spawned _**Instances**_.
123
+ 4. Monitors _**Instance**_ progress.
124
+ 5. Upon _**Application**_ completion stores report to disk.
125
+ 6. Shuts down the _**Instance**_.
126
+
127
+ #### Dispatcher
128
+
129
+ The _**Scheduler**_ can be configured with a _**Dispatcher**_, upon which case,
130
+ it will use it to spawn _**Instances**_.
131
+
132
+ If the _**Dispatcher**_ is a _**Grid**_ member then the _**Scheduler**_ will
133
+ also enjoy _load-balancing_ features.
134
+
135
+ ## APIs
136
+
137
+ ### Local
138
+
139
+ Local access can call upon via the `Cuboid::Application` API and the API defined by the
140
+ _**Application**_ itself.
141
+
142
+ ### RPC
143
+
144
+ A simple RPC is employed, specs for 3rd party implementations can be found at:
145
+
146
+ https://github.com/Arachni/arachni-rpc/wiki
147
+
148
+ Each _**Application**_ can extend upon this and expose an API via its _**Instance**_'s
149
+ RPC interface.
150
+
151
+ ### REST
152
+
153
+ A REST API is also available, taking advantage of HTTP sessions to make progress
154
+ tracking easier.
155
+
156
+ The REST interface is basically a web _**Dispatcher**_ and centralised point of
157
+ management for the rest of the entities.
158
+
159
+ Each _**Application**_ can extend upon this and expose an API via its _**REST**_
160
+ service's interface.
161
+
162
+ ## Examples
163
+
164
+ See `examples/`.
165
+
166
+ ### MyApp
167
+
168
+ Tutorial application going over different APIs and **Cuboid** _**Application**_
169
+ options and specification.
170
+
171
+
172
+ ## License
173
+
174
+ Please see the _LICENSE.md_ file.
data/Rakefile CHANGED
@@ -1,4 +1,57 @@
1
- # frozen_string_literal: true
1
+ =begin
2
+ Copyright 2020 Alex Douckas <alexdouckas@gmail.com>, Tasos Laskos <tasos.laskos@gmail.com>
2
3
 
3
- require "bundler/gem_tasks"
4
- task default: %i[]
4
+ This file is part of the Engine Framework project and is subject to
5
+ redistribution and commercial restrictions. Please see the Engine Framework
6
+ web site for more information on licensing and terms of use.
7
+ =end
8
+
9
+ require File.expand_path(File.dirname(__FILE__)) + '/lib/cuboid'
10
+
11
+ begin
12
+ require 'rspec'
13
+ require 'rspec/core/rake_task'
14
+
15
+ namespace :spec do
16
+
17
+ desc 'Run core library tests.'
18
+ RSpec::Core::RakeTask.new( :core ) do |t|
19
+ t.pattern = FileList[ 'spec/cuboid/**/*_spec.rb' ]
20
+ end
21
+
22
+ desc 'Run plugin tests.'
23
+ RSpec::Core::RakeTask.new( :plugins ) do |t|
24
+ t.pattern = FileList[ 'spec/components/plugins/**/*_spec.rb' ]
25
+ end
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new
29
+ rescue LoadError
30
+ puts 'If you want to run the tests please install rspec first:'
31
+ puts ' gem install rspec'
32
+ end
33
+
34
+ desc 'Generate docs.'
35
+ task :docs do
36
+ outdir = "../cuboid-docs"
37
+ sh "rm -rf #{outdir}"
38
+ sh "mkdir -p #{outdir}"
39
+
40
+ sh "yardoc -o #{outdir}"
41
+
42
+ sh "rm -rf .yardoc"
43
+ end
44
+
45
+ desc 'Remove reporter and log files.'
46
+ task :clean do
47
+ files = %w(error.log *.crf *.csf *.yaml *.json *.marshal *.gem pkg/*.gem
48
+ reports/*.crf snapshots/*.csf logs/*.log spec/support/logs/*.log
49
+ spec/support/reports/*.crf spec/support/snapshots/*.csf
50
+ ).map { |file| Dir.glob( file ) }.flatten
51
+
52
+ next if files.empty?
53
+
54
+ puts 'Removing:'
55
+ files.each { |file| puts " * #{file}" }
56
+ FileUtils.rm files
57
+ end
data/config/paths.yml ADDED
@@ -0,0 +1,15 @@
1
+ # Sets default locations for writing different kinds of files.
2
+ #
3
+ # * '~' will be expanded to $HOME.
4
+ # * Directories will be created if they don't already exist.
5
+
6
+ # Error and RPC logs.
7
+ logs:
8
+ # Default directory for scan snapshots generated by RPC Instances.
9
+ snapshots:
10
+ # Default report location for the RPC Scheduler.
11
+ reports:
12
+ # Directory for temporary files -- like for excess workload that's been
13
+ # offloaded to disk etc.
14
+ # Will default to the OS temporary directory.
15
+ tmpdir:
data/cuboid.gemspec CHANGED
@@ -1,31 +1,69 @@
1
- # frozen_string_literal: true
1
+ # coding: utf-8
2
2
 
3
- require_relative "lib/cuboid/version"
3
+ Gem::Specification.new do |s|
4
+ require_relative File.expand_path( File.dirname( __FILE__ ) ) + '/lib/cuboid/version'
4
5
 
5
- Gem::Specification.new do |spec|
6
- spec.name = "cuboid"
7
- spec.version = Cuboid::VERSION
8
- spec.authors = ["Tasos Laskos"]
9
- spec.email = ["tasos.laskos@gmail.com"]
6
+ s.name = 'cuboid'
7
+ s.version = Cuboid::VERSION
8
+ s.date = Time.now.strftime( '%Y-%m-%d' )
9
+ s.summary = 'An application-centric, decentralised and distributed computing solution. '
10
10
 
11
- spec.summary = "Placeholder"
12
- spec.homepage = "http://placeholder.com"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
11
+ s.homepage = 'https://github.com/qadron/cuboid'
12
+ s.email = 'tasos.laskos@gmail.com'
13
+ s.authors = [ 'Tasos Laskos' ]
14
+ s.licenses = ['All rights reserved.']
14
15
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
+ s.files += Dir.glob( 'config/**/**' )
17
+ s.files += Dir.glob( 'lib/**/**' )
18
+ s.files += Dir.glob( 'logs/**/**' )
19
+ s.files += Dir.glob( 'components/**/**' )
20
+ s.files += Dir.glob( 'spec/**/**' )
21
+ s.files += %w(Gemfile Rakefile cuboid.gemspec)
22
+ s.test_files = Dir.glob( 'spec/**/**' )
16
23
 
17
- # Specify which files should be added to the gem when it is released.
18
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
21
- end
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
24
+ s.extra_rdoc_files = %w(README.md LICENSE.md CHANGELOG.md)
25
25
 
26
- # Uncomment to register a new dependency of your gem
27
- # spec.add_dependency "example-gem", "~> 1.0"
26
+ s.rdoc_options = [ '--charset=UTF-8' ]
27
+
28
+ s.add_dependency 'awesome_print', '1.6.1'
29
+
30
+ # Don't specify version, messes with the packages since they always grab the
31
+ # latest one.
32
+ s.add_dependency 'bundler'
33
+
34
+ s.add_dependency 'concurrent-ruby', '1.1.8'
35
+ s.add_dependency 'concurrent-ruby-ext', '1.1.8'
36
+
37
+ # For compressing/decompressing system state archives.
38
+ s.add_dependency 'rubyzip', '1.2.2'
39
+
40
+ s.add_dependency 'childprocess', '0.8.0'
41
+
42
+ # RPC serialization.
43
+ s.add_dependency 'msgpack', '1.1.0'
44
+
45
+ # Optimized JSON.
46
+ s.add_dependency 'oj', '3.11.5'
47
+ s.add_dependency 'oj_mimic_json', '1.0.1'
48
+
49
+ # Web server
50
+ s.add_dependency 'puma', '3.10.0'
51
+
52
+ s.add_dependency 'rack', '2.2.3'
53
+ s.add_dependency 'rack-test'
54
+
55
+ # REST API
56
+ s.add_dependency 'sinatra', '2.1.0'
57
+ s.add_dependency 'sinatra-contrib', '2.1.0'
58
+
59
+ # RPC client/server implementation.
60
+ s.add_dependency 'arachni-rpc', '~> 0.2.1.4'
61
+
62
+ s.add_dependency 'vmstat', '2.3.0'
63
+ s.add_dependency 'sys-proctable', '1.1.5'
64
+
65
+ s.description = <<DESCRIPTION
66
+ An application-centric, decentralised and distributed computing solution.
67
+ DESCRIPTION
28
68
 
29
- # For more information and examples about making a new gem, checkout our
30
- # guide at: https://bundler.io/guides/creating_gem.html
31
69
  end
data/lib/cuboid.rb CHANGED
@@ -1,8 +1,100 @@
1
- # frozen_string_literal: true
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'tmpdir'
2
4
 
3
- require_relative "cuboid/version"
5
+ require 'oj'
6
+ require 'oj_mimic_json'
7
+
8
+ require_relative 'cuboid/version'
9
+
10
+ require 'concurrent'
11
+ require 'pp'
12
+ require 'ap'
13
+
14
+ def ap( obj )
15
+ super obj, raw: true
16
+ end
4
17
 
5
18
  module Cuboid
6
- class Error < StandardError; end
7
- # Your code goes here...
19
+
20
+ class <<self
21
+
22
+ # Runs a minor GC to collect young, short-lived objects.
23
+ #
24
+ # Generally called after analysis operations that generate a lot of
25
+ # new temporary objects.
26
+ def collect_young_objects
27
+ # GC.start( full_mark: false )
28
+ end
29
+
30
+ def null_device
31
+ Gem.win_platform? ? 'NUL' : '/dev/null'
32
+ end
33
+
34
+ # @return [Bool]
35
+ def windows?
36
+ Gem.win_platform?
37
+ end
38
+
39
+ # @return [Bool]
40
+ def linux?
41
+ @is_linux ||= RbConfig::CONFIG['host_os'] =~ /linux/
42
+ end
43
+
44
+ # @return [Bool]
45
+ def mac?
46
+ @is_mac ||= RbConfig::CONFIG['host_os'] =~ /darwin|mac os/i
47
+ end
48
+
49
+ # @return [Bool]
50
+ # `true` if the `CUBOID_PROFILE` env variable is set,
51
+ # `false` otherwise.
52
+ def profile?
53
+ !!ENV['CUBOID_PROFILE']
54
+ end
55
+
56
+ if Cuboid.windows?
57
+ require 'find'
58
+ require 'fileutils'
59
+ require 'Win32API'
60
+ require 'win32ole'
61
+
62
+ def get_long_win32_filename( short_name )
63
+ short_name = short_name.dup
64
+ max_path = 1024
65
+ long_name = ' ' * max_path
66
+
67
+ lfn_size = Win32API.new(
68
+ "kernel32",
69
+ "GetLongPathName",
70
+ ['P','P','L'],
71
+ 'L'
72
+ ).call( short_name, long_name, max_path )
73
+
74
+ (1..max_path).include?( lfn_size ) ?
75
+ long_name[0..lfn_size-1] : short_name
76
+ end
77
+ else
78
+ def get_long_win32_filename( short_name )
79
+ short_name
80
+ end
81
+ end
82
+ end
83
+
8
84
  end
85
+
86
+ require_relative 'cuboid/banner'
87
+ require_relative 'cuboid/ui/output_interface'
88
+
89
+ # If there's no UI driving us then there's no output interface.
90
+ # Chances are that someone is using Engine as a Ruby lib so there's no
91
+ # need for a functional output interface, so provide non-functional one.
92
+ #
93
+ # However, functional or not, the system does depend on one being available.
94
+ if !Cuboid::UI.constants.include?(:Output)
95
+ require_relative 'cuboid/ui/output'
96
+ end
97
+
98
+ require_relative 'cuboid/application'
99
+
100
+ Cuboid::UI::OutputInterface.initialize