orchestrator 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +158 -0
  3. data/README.md +13 -0
  4. data/Rakefile +7 -0
  5. data/app/controllers/orchestrator/api/dependencies_controller.rb +109 -0
  6. data/app/controllers/orchestrator/api/modules_controller.rb +183 -0
  7. data/app/controllers/orchestrator/api/systems_controller.rb +294 -0
  8. data/app/controllers/orchestrator/api/zones_controller.rb +62 -0
  9. data/app/controllers/orchestrator/api_controller.rb +13 -0
  10. data/app/controllers/orchestrator/base.rb +59 -0
  11. data/app/controllers/orchestrator/persistence_controller.rb +29 -0
  12. data/app/models/orchestrator/access_log.rb +35 -0
  13. data/app/models/orchestrator/control_system.rb +160 -0
  14. data/app/models/orchestrator/dependency.rb +87 -0
  15. data/app/models/orchestrator/mod/by_dependency/map.js +6 -0
  16. data/app/models/orchestrator/mod/by_module_type/map.js +6 -0
  17. data/app/models/orchestrator/module.rb +127 -0
  18. data/app/models/orchestrator/sys/by_modules/map.js +9 -0
  19. data/app/models/orchestrator/sys/by_zones/map.js +9 -0
  20. data/app/models/orchestrator/zone.rb +47 -0
  21. data/app/models/orchestrator/zone/all/map.js +6 -0
  22. data/config/routes.rb +43 -0
  23. data/lib/generators/module/USAGE +8 -0
  24. data/lib/generators/module/module_generator.rb +52 -0
  25. data/lib/orchestrator.rb +52 -0
  26. data/lib/orchestrator/control.rb +303 -0
  27. data/lib/orchestrator/core/mixin.rb +123 -0
  28. data/lib/orchestrator/core/module_manager.rb +258 -0
  29. data/lib/orchestrator/core/request_proxy.rb +109 -0
  30. data/lib/orchestrator/core/requests_proxy.rb +47 -0
  31. data/lib/orchestrator/core/schedule_proxy.rb +49 -0
  32. data/lib/orchestrator/core/system_proxy.rb +153 -0
  33. data/lib/orchestrator/datagram_server.rb +114 -0
  34. data/lib/orchestrator/dependency_manager.rb +131 -0
  35. data/lib/orchestrator/device/command_queue.rb +213 -0
  36. data/lib/orchestrator/device/manager.rb +83 -0
  37. data/lib/orchestrator/device/mixin.rb +35 -0
  38. data/lib/orchestrator/device/processor.rb +441 -0
  39. data/lib/orchestrator/device/transport_makebreak.rb +221 -0
  40. data/lib/orchestrator/device/transport_tcp.rb +139 -0
  41. data/lib/orchestrator/device/transport_udp.rb +89 -0
  42. data/lib/orchestrator/engine.rb +70 -0
  43. data/lib/orchestrator/errors.rb +23 -0
  44. data/lib/orchestrator/logger.rb +115 -0
  45. data/lib/orchestrator/logic/manager.rb +18 -0
  46. data/lib/orchestrator/logic/mixin.rb +11 -0
  47. data/lib/orchestrator/service/manager.rb +63 -0
  48. data/lib/orchestrator/service/mixin.rb +56 -0
  49. data/lib/orchestrator/service/transport_http.rb +55 -0
  50. data/lib/orchestrator/status.rb +229 -0
  51. data/lib/orchestrator/system.rb +108 -0
  52. data/lib/orchestrator/utilities/constants.rb +41 -0
  53. data/lib/orchestrator/utilities/transcoder.rb +57 -0
  54. data/lib/orchestrator/version.rb +3 -0
  55. data/lib/orchestrator/websocket_manager.rb +425 -0
  56. data/orchestrator.gemspec +35 -0
  57. data/spec/orchestrator/queue_spec.rb +200 -0
  58. metadata +271 -0
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'orchestrator/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'orchestrator'
7
+ s.version = Orchestrator::VERSION
8
+ s.authors = ['Stephen von Takach']
9
+ s.email = ['steve@advancedcontrol.com.au']
10
+ s.license = 'CC BY-NC-SA'
11
+ s.homepage = 'https://github.com/advancedcontrol/engine'
12
+ s.summary = 'A distributed system for building automation'
13
+ s.description = 'A building and Internet of Things automation system'
14
+
15
+ s.add_dependency 'rake'
16
+ s.add_dependency 'rails'
17
+ s.add_dependency 'libuv' # High performance IO reactor for ruby
18
+ s.add_dependency 'uv-rays' # Evented networking library
19
+ s.add_dependency 'addressable' # IP address utilities
20
+ s.add_dependency 'systemu' # MAC address utilities
21
+ s.add_dependency 'algorithms' # Priority queue
22
+ s.add_dependency 'couchbase-id' # ID generation
23
+ s.add_dependency 'elasticsearch' # Searchable model indexes
24
+ s.add_dependency 'co-elastic-query' # Query builder
25
+
26
+ s.add_development_dependency 'rspec' # Testing framework
27
+ s.add_development_dependency 'yard' # Comment based documentation generation
28
+
29
+
30
+ s.files = Dir["{lib,app,config}/**/*"] + %w(Rakefile orchestrator.gemspec README.md LICENSE.md)
31
+ s.test_files = Dir['spec/**/*']
32
+ s.extra_rdoc_files = ['README.md']
33
+
34
+ s.require_paths = ['lib']
35
+ end
@@ -0,0 +1,200 @@
1
+ require 'rails'
2
+ require 'orchestrator'
3
+
4
+ describe "command queue" do
5
+ @loop = ::Libuv::Loop.default
6
+
7
+ # Uses promises to pause shifts until any timers
8
+ # have been resolved
9
+ it "should queue and shift until waiting" do
10
+ count = 0
11
+ log = []
12
+ queue = ::Orchestrator::Device::CommandQueue.new(@loop, proc { |cmd|
13
+ count += 1
14
+ if count % 2 == 1
15
+ defer = @loop.defer
16
+ @loop.next_tick do
17
+ log << cmd[:name]
18
+ defer.resolve(true)
19
+ end
20
+ defer.promise
21
+ else
22
+ log << cmd[:name]
23
+ end
24
+ })
25
+
26
+ @loop.run do
27
+ queue.push({name: :first}, 50)
28
+ queue.push({name: :second}, 50)
29
+ @loop.next_tick do
30
+ queue.push({name: :third, wait: true}, 50)
31
+ @loop.next_tick do
32
+ queue.push({name: :fourth}, 50)
33
+ @loop.next_tick do
34
+ @loop.next_tick do
35
+ @loop.stop
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ expect(log).to eq([:first, :second, :third])
43
+ end
44
+
45
+ it "should continue processing after waiting" do
46
+ count = 0
47
+ log = []
48
+ queue = ::Orchestrator::Device::CommandQueue.new(@loop, proc { |cmd|
49
+ count += 1
50
+ if count == 3
51
+ log << cmd[:name]
52
+ queue.shift
53
+ else
54
+ defer = @loop.defer
55
+ @loop.next_tick do
56
+ log << cmd[:name]
57
+ defer.resolve(true)
58
+ end
59
+ defer.promise
60
+ end
61
+ })
62
+
63
+ @loop.run do
64
+ queue.push({name: :first}, 50)
65
+ queue.push({name: :second}, 50)
66
+ @loop.next_tick do
67
+ queue.push({name: :third, wait: true}, 50)
68
+ @loop.next_tick do
69
+ queue.push({name: :fourth}, 50)
70
+ @loop.next_tick do
71
+ @loop.next_tick do
72
+ @loop.stop
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ expect(log).to eq([:first, :second, :third, :fourth])
80
+ end
81
+
82
+ it "should work with anonymous commands" do
83
+ count = 0
84
+ log = []
85
+ queue = ::Orchestrator::Device::CommandQueue.new(@loop, proc { |cmd|
86
+ count += 1
87
+ if count == 3
88
+ log << cmd[:data]
89
+ queue.shift
90
+ else
91
+ defer = @loop.defer
92
+ @loop.next_tick do
93
+ log << cmd[:data]
94
+ defer.resolve(true)
95
+ end
96
+ defer.promise
97
+ end
98
+ })
99
+
100
+ @loop.run do
101
+ queue.push({data: :first}, 50)
102
+ queue.push({data: :second}, 50)
103
+ @loop.next_tick do
104
+ queue.push({data: :third, wait: true}, 50)
105
+ @loop.next_tick do
106
+ queue.push({data: :fourth}, 50)
107
+ @loop.next_tick do
108
+ @loop.next_tick do
109
+ @loop.stop
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ expect(log).to eq([:first, :second, :third, :fourth])
117
+ end
118
+
119
+ it "should save named commands when offline" do
120
+ log = []
121
+ queue = ::Orchestrator::Device::CommandQueue.new(@loop, proc { |cmd|
122
+ defer = @loop.defer
123
+ @loop.next_tick do
124
+ log << cmd[:data]
125
+ defer.resolve(true)
126
+ end
127
+ defer.promise
128
+ })
129
+
130
+ @loop.run do
131
+ dummy_defer = @loop.defer
132
+
133
+ queue.push({name: :first, wait: true, data: :first}, 50)
134
+ queue.push({data: :second, defer: dummy_defer}, 50)
135
+ queue.push({name: :third, data: :third}, 50)
136
+ queue.push({data: :fourth, defer: dummy_defer}, 50)
137
+
138
+ queue.offline
139
+
140
+ @loop.next_tick do
141
+ queue.online
142
+
143
+ @loop.next_tick do
144
+ @loop.next_tick do
145
+ @loop.next_tick do
146
+ @loop.next_tick do
147
+ @loop.next_tick do
148
+ @loop.stop
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ expect(log).to eq([:first, :third])
158
+ end
159
+
160
+ it "should save no commands if cleared" do
161
+ log = []
162
+ queue = ::Orchestrator::Device::CommandQueue.new(@loop, proc { |cmd|
163
+ defer = @loop.defer
164
+ @loop.next_tick do
165
+ log << cmd[:data]
166
+ defer.resolve(true)
167
+ end
168
+ defer.promise
169
+ })
170
+
171
+ @loop.run do
172
+ dummy_defer = @loop.defer
173
+
174
+ queue.push({name: :first, defer: dummy_defer, wait: true, data: :first}, 50)
175
+ queue.push({data: :second, defer: dummy_defer}, 50)
176
+ queue.push({name: :third, defer: dummy_defer, data: :third}, 50)
177
+ queue.push({data: :fourth, defer: dummy_defer}, 50)
178
+
179
+ queue.offline(:clear)
180
+
181
+ @loop.next_tick do
182
+ queue.online
183
+
184
+ @loop.next_tick do
185
+ @loop.next_tick do
186
+ @loop.next_tick do
187
+ @loop.next_tick do
188
+ @loop.next_tick do
189
+ @loop.stop
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ expect(log).to eq([:first])
199
+ end
200
+ end
metadata ADDED
@@ -0,0 +1,271 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orchestrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stephen von Takach
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: libuv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: uv-rays
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: systemu
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: algorithms
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: couchbase-id
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: elasticsearch
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: co-elastic-query
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: A building and Internet of Things automation system
182
+ email:
183
+ - steve@advancedcontrol.com.au
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files:
187
+ - README.md
188
+ files:
189
+ - LICENSE.md
190
+ - README.md
191
+ - Rakefile
192
+ - app/controllers/orchestrator/api/dependencies_controller.rb
193
+ - app/controllers/orchestrator/api/modules_controller.rb
194
+ - app/controllers/orchestrator/api/systems_controller.rb
195
+ - app/controllers/orchestrator/api/zones_controller.rb
196
+ - app/controllers/orchestrator/api_controller.rb
197
+ - app/controllers/orchestrator/base.rb
198
+ - app/controllers/orchestrator/persistence_controller.rb
199
+ - app/models/orchestrator/access_log.rb
200
+ - app/models/orchestrator/control_system.rb
201
+ - app/models/orchestrator/dependency.rb
202
+ - app/models/orchestrator/mod/by_dependency/map.js
203
+ - app/models/orchestrator/mod/by_module_type/map.js
204
+ - app/models/orchestrator/module.rb
205
+ - app/models/orchestrator/sys/by_modules/map.js
206
+ - app/models/orchestrator/sys/by_zones/map.js
207
+ - app/models/orchestrator/zone.rb
208
+ - app/models/orchestrator/zone/all/map.js
209
+ - config/routes.rb
210
+ - lib/generators/module/USAGE
211
+ - lib/generators/module/module_generator.rb
212
+ - lib/orchestrator.rb
213
+ - lib/orchestrator/control.rb
214
+ - lib/orchestrator/core/mixin.rb
215
+ - lib/orchestrator/core/module_manager.rb
216
+ - lib/orchestrator/core/request_proxy.rb
217
+ - lib/orchestrator/core/requests_proxy.rb
218
+ - lib/orchestrator/core/schedule_proxy.rb
219
+ - lib/orchestrator/core/system_proxy.rb
220
+ - lib/orchestrator/datagram_server.rb
221
+ - lib/orchestrator/dependency_manager.rb
222
+ - lib/orchestrator/device/command_queue.rb
223
+ - lib/orchestrator/device/manager.rb
224
+ - lib/orchestrator/device/mixin.rb
225
+ - lib/orchestrator/device/processor.rb
226
+ - lib/orchestrator/device/transport_makebreak.rb
227
+ - lib/orchestrator/device/transport_tcp.rb
228
+ - lib/orchestrator/device/transport_udp.rb
229
+ - lib/orchestrator/engine.rb
230
+ - lib/orchestrator/errors.rb
231
+ - lib/orchestrator/logger.rb
232
+ - lib/orchestrator/logic/manager.rb
233
+ - lib/orchestrator/logic/mixin.rb
234
+ - lib/orchestrator/service/manager.rb
235
+ - lib/orchestrator/service/mixin.rb
236
+ - lib/orchestrator/service/transport_http.rb
237
+ - lib/orchestrator/status.rb
238
+ - lib/orchestrator/system.rb
239
+ - lib/orchestrator/utilities/constants.rb
240
+ - lib/orchestrator/utilities/transcoder.rb
241
+ - lib/orchestrator/version.rb
242
+ - lib/orchestrator/websocket_manager.rb
243
+ - orchestrator.gemspec
244
+ - spec/orchestrator/queue_spec.rb
245
+ homepage: https://github.com/advancedcontrol/engine
246
+ licenses:
247
+ - CC BY-NC-SA
248
+ metadata: {}
249
+ post_install_message:
250
+ rdoc_options: []
251
+ require_paths:
252
+ - lib
253
+ required_ruby_version: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ required_rubygems_version: !ruby/object:Gem::Requirement
259
+ requirements:
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ version: '0'
263
+ requirements: []
264
+ rubyforge_project:
265
+ rubygems_version: 2.2.2
266
+ signing_key:
267
+ specification_version: 4
268
+ summary: A distributed system for building automation
269
+ test_files:
270
+ - spec/orchestrator/queue_spec.rb
271
+ has_rdoc: