hive-runner 2.0.11 → 2.0.12

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hive_setup +142 -130
  3. data/lib/hive/worker.rb +22 -4
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b5910241ae9d856425265db20202573a23cb604
4
- data.tar.gz: a29e983a1893894f8cf440f3f7bf19b315368354
3
+ metadata.gz: 042debdaacef0d30c5d6b0d28e09d6c58aa0641a
4
+ data.tar.gz: e4084d0a7436469a4ca4c34b3da03fb84e653839
5
5
  SHA512:
6
- metadata.gz: e2d30586bc644793b88ebf52f63f45e7423f2e930e712ef864b108ed458d034a66d5786b19033ad111846b18b47bbf8bad339b377f1bf25cce6248648ecc8ed5
7
- data.tar.gz: 5539bcb9dfd4fa78c75f789f6f8f4cf535cc9332983fb2addfbb1baecb138f521ba66dbd680a8387ae588380cda7d32e29e43e36d14e9e61344824ff46a6caa7
6
+ metadata.gz: e50f6cca84576eeda4b614ee490347a6c6b981f4d0bb4873e9618b86235fd72728c4c6022d433abf779a1855fa2640584754d226108ce593669829219deefe79
7
+ data.tar.gz: 86cbd34195e4bc7b6d6e21a4aa9c3443f6c18d7c3411964b42f5fd7a71bf30e6260e552b13190479e16251c5f8f6c2247648cdfac9c9dd8764fa4a70f74c0d5f
data/bin/hive_setup CHANGED
@@ -11,6 +11,8 @@ if ARGV.length < 1
11
11
  exit 1
12
12
  end
13
13
 
14
+ headless = ARGV.include?("--ni")
15
+
14
16
  dir = File.expand_path('', ARGV[0])
15
17
  if Dir.exists?(dir)
16
18
  if ! Dir["#{dir}/*"].empty?
@@ -34,150 +36,160 @@ def yn question
34
36
  yn =~ /^[yY]/
35
37
  end
36
38
 
37
- # Choose options
38
- opt = ''
39
- mods = []
40
- while opt.upcase != 'X'
41
- table = Terminal::Table.new headings: ['Device', 'Module', 'Source']
42
- mods.each do |mod|
43
- table.add_row [
44
- mod[:device],
45
- mod[:name],
46
- mod.has_key?(:git_account) ?
47
- "git@github.com:#{mod[:git_account]}/#{mod[:name]}" :
48
- "https://rubygems.org/gems/#{mod[:name]}"
49
- ]
50
- end
51
-
52
- puts ''
53
- puts table
54
- puts ''
55
- puts '1) Add module'
56
- puts 'X) Continue'
57
- puts ''
58
- print "> "
59
- opt = STDIN.gets.chomp
60
-
61
- case opt
62
- when '1'
63
- mod = {}
64
- puts ''
65
- print "Module name: "
66
- mod[:device] = STDIN.gets.chomp
67
- mod[:name] = "hive-runner-#{mod[:device]}"
68
- puts ''
69
- if yn "Get '#{mod[:name]}' from Github? "
70
- print "Enter GIT account name: "
71
- mod[:git_account] = STDIN.gets.chomp
39
+ def add_modules
40
+ # Choose options
41
+ opt = ''
42
+ mods = []
43
+ while opt.upcase != 'X'
44
+ table = Terminal::Table.new headings: ['Device', 'Module', 'Source']
45
+ mods.each do |mod|
46
+ table.add_row [
47
+ mod[:device],
48
+ mod[:name],
49
+ mod.has_key?(:git_account) ?
50
+ "git@github.com:#{mod[:git_account]}/#{mod[:name]}" :
51
+ "https://rubygems.org/gems/#{mod[:name]}"
52
+ ]
72
53
  end
73
54
 
74
55
  puts ''
75
- puts "Module '#{mod[:name]}'"
76
- if mod.has_key?(:git_account)
77
- puts " from git@github.com:#{mod[:git_account]}/#{mod[:name]}"
78
- else
79
- puts " from https://rubygems.org/gems/#{mod[:name]}"
80
- end
56
+ puts table
81
57
  puts ''
58
+ puts '1) Add module'
59
+ puts 'X) Continue'
60
+ puts ''
61
+ print "> "
62
+ opt = STDIN.gets.chomp
63
+
64
+ case opt
65
+ when '1'
66
+ mod = {}
67
+ puts ''
68
+ print "Module name: "
69
+ mod[:device] = STDIN.gets.chomp
70
+ mod[:name] = "hive-runner-#{mod[:device]}"
71
+ puts ''
72
+ if yn "Get '#{mod[:name]}' from Github? "
73
+ print "Enter GIT account name: "
74
+ mod[:git_account] = STDIN.gets.chomp
75
+ end
76
+
77
+ puts ''
78
+ puts "Module '#{mod[:name]}'"
79
+ if mod.has_key?(:git_account)
80
+ puts " from git@github.com:#{mod[:git_account]}/#{mod[:name]}"
81
+ else
82
+ puts " from https://rubygems.org/gems/#{mod[:name]}"
83
+ end
84
+ puts ''
82
85
 
83
- if yn "Correct? "
84
- mods << mod
86
+ if yn "Correct? "
87
+ mods << mod
88
+ end
85
89
  end
86
90
  end
91
+
92
+ mods
87
93
  end
88
94
 
89
- FileUtils.mkdir_p("#{dir}/config")
90
- FileUtils.mkdir_p("#{dir}/log")
91
- FileUtils.mkdir_p("#{dir}/pids")
92
- FileUtils.mkdir_p("#{dir}/workspaces")
93
-
94
- File.open("#{dir}/config/settings.yml", 'w') do |f|
95
- f.puts "#{ENV['HIVE_ENVIRONMENT'] || 'test'}:"
96
- f.puts ' daemon_name: HIVE'
97
- f.puts ''
98
- f.puts ' controllers:'
99
- f.puts ' shell:'
100
- f.puts ' # Number of shell workers to allocate'
101
- f.puts ' workers: 5'
102
- f.puts ' # Queue for each shell worker'
103
- f.puts ' queues:'
104
- f.puts ' - bash'
105
- f.puts ' # Number of ports to allocate to each shell worker'
106
- f.puts ' port_range_size: 50'
107
- f.puts ' name_stub: SHELL_WORKER'
108
- mods.each do |m|
109
- f.puts " #{m[:device]}:"
110
- f.puts ' # Number of ports to allocate to each #{m[:device]} worker'
95
+ def setup_hive(dir, mods)
96
+ FileUtils.mkdir_p("#{dir}/config")
97
+ FileUtils.mkdir_p("#{dir}/log")
98
+ FileUtils.mkdir_p("#{dir}/pids")
99
+ FileUtils.mkdir_p("#{dir}/workspaces")
100
+
101
+ File.open("#{dir}/config/settings.yml", 'w') do |f|
102
+ f.puts "#{ENV['HIVE_ENVIRONMENT'] || 'test'}:"
103
+ f.puts ' daemon_name: HIVE'
104
+ f.puts ''
105
+ f.puts ' controllers:'
106
+ f.puts ' shell:'
107
+ f.puts ' # Number of shell workers to allocate'
108
+ f.puts ' workers: 5'
109
+ f.puts ' # Queue for each shell worker'
110
+ f.puts ' queues:'
111
+ f.puts ' - bash'
112
+ f.puts ' # Number of ports to allocate to each shell worker'
111
113
  f.puts ' port_range_size: 50'
112
- f.puts " name_stub: #{m[:device].upcase}_WORKER"
114
+ f.puts ' name_stub: SHELL_WORKER'
115
+ mods.each do |m|
116
+ f.puts " #{m[:device]}:"
117
+ f.puts ' # Number of ports to allocate to each #{m[:device]} worker'
118
+ f.puts ' port_range_size: 50'
119
+ f.puts " name_stub: #{m[:device].upcase}_WORKER"
120
+ end
121
+ f.puts ''
122
+ f.puts ' # Range of ports to be made available to workers'
123
+ f.puts ' ports:'
124
+ f.puts ' minimum: 4000'
125
+ f.puts ' maximum: 5000'
126
+ f.puts ''
127
+ f.puts ' # Logging configuration'
128
+ f.puts ' logging:'
129
+ f.puts " directory: #{dir}/log"
130
+ f.puts " pids: #{dir}/pids"
131
+ f.puts ' main_filename: hive.log'
132
+ f.puts ' main_level: INFO'
133
+ f.puts ' worker_level: INFO'
134
+ f.puts " home: #{dir}/workspaces"
135
+ f.puts ' homes_to_keep: 5'
136
+ f.puts ''
137
+ f.puts ' # Timing configuration'
138
+ f.puts ' timings:'
139
+ f.puts ' worker_loop_interval: 5'
140
+ f.puts ' controller_loop_interval: 5'
141
+ f.puts ''
142
+ f.puts ' # Configuration for various network options'
143
+ f.puts ' network:'
144
+ f.puts ' scheduler: http://localhost:3000'
145
+ f.puts ' #hive_mind: http://localhost:3001'
146
+ f.puts ' # Optional cert paths:'
147
+ f.puts ' # cert: /path/to/certificate.pem'
148
+ f.puts ' # cafile: /path/to/certificate-authorities.pem'
149
+ f.puts ''
150
+ f.puts ' # Configuration for diagnostic plugins'
151
+ f.puts ' diagnostics:'
113
152
  end
114
- f.puts ''
115
- f.puts ' # Range of ports to be made available to workers'
116
- f.puts ' ports:'
117
- f.puts ' minimum: 4000'
118
- f.puts ' maximum: 5000'
119
- f.puts ''
120
- f.puts ' # Logging configuration'
121
- f.puts ' logging:'
122
- f.puts " directory: #{dir}/log"
123
- f.puts " pids: #{dir}/pids"
124
- f.puts ' main_filename: hive.log'
125
- f.puts ' main_level: INFO'
126
- f.puts ' worker_level: INFO'
127
- f.puts " home: #{dir}/workspaces"
128
- f.puts ' homes_to_keep: 5'
129
- f.puts ''
130
- f.puts ' # Timing configuration'
131
- f.puts ' timings:'
132
- f.puts ' worker_loop_interval: 5'
133
- f.puts ' controller_loop_interval: 5'
134
- f.puts ''
135
- f.puts ' # Configuration for various network options'
136
- f.puts ' network:'
137
- f.puts ' scheduler: http://scheduler'
138
- f.puts ' devicedb: http://devicedb'
139
- f.puts ' #hive_mind: http://hive_mind'
140
- f.puts ' # cert: /path/to/certificate.pem'
141
- f.puts ' # cafile: /path/to/certificate-authorities.pem'
142
- f.puts ''
143
- f.puts ' # Configuration for diagnostic plugins'
144
- f.puts ' diagnostics:'
145
- end
146
153
 
147
- File.open("#{dir}/Gemfile", 'w') do |f|
148
- f.puts "source 'https://rubygems.org/'"
149
- f.puts ""
150
- f.puts "gem 'hive-runner'"
151
- mods.each do |m|
152
- source = m.has_key?(:git_account) ? ", git: 'git@github.com:#{m[:git_account]}/#{m[:name]}'" : ''
153
- f.puts "gem '#{m[:name]}'#{source}"
154
+ File.open("#{dir}/Gemfile", 'w') do |f|
155
+ f.puts "source 'https://rubygems.org/'"
156
+ f.puts ""
157
+ f.puts "gem 'hive-runner'"
158
+ mods.each do |m|
159
+ source = m.has_key?(:git_account) ? ", git: 'git@github.com:#{m[:git_account]}/#{m[:name]}'" : ''
160
+ f.puts "gem '#{m[:name]}'#{source}"
161
+ end
154
162
  end
155
- end
156
163
 
157
- print "Executing 'bundle install' ... "
158
- Dir.chdir dir
159
- if system("bundle install > bundle_install.out 2>&1")
160
- print "SUCCESS\n"
161
- File.delete('bundle_install.out')
162
- else
163
- print "FAILED\n"
164
- puts "See #{dir}/bundle_install.out for details"
165
- exit
166
- end
164
+ print "Executing 'bundle install' ... "
165
+ Dir.chdir dir
166
+ if system("bundle install > bundle_install.out 2>&1")
167
+ print "SUCCESS\n"
168
+ File.delete('bundle_install.out')
169
+ else
170
+ print "FAILED\n"
171
+ puts "See #{dir}/bundle_install.out for details"
172
+ exit
173
+ end
167
174
 
168
- puts ''
169
- puts 'Configuration required:'
170
- puts
171
- puts ' * Add to config/settings.yml'
172
- puts ' - scheduler'
173
- puts ' - devicedb'
174
- puts ' - cert'
175
- puts ' - cafile'
176
- if mods.length > 0
177
- puts ' * Configure these modules in config/settings.yml'
178
- mods.each do |m|
179
- puts " - #{m[:device]}"
175
+ puts ''
176
+ puts 'Configuration required:'
177
+ puts
178
+ puts ' * Add to config/settings.yml'
179
+ puts ' - scheduler'
180
+ puts ' - devicedb'
181
+ puts ' - cert'
182
+ puts ' - cafile'
183
+ if mods.length > 0
184
+ puts ' * Configure these modules in config/settings.yml'
185
+ mods.each do |m|
186
+ puts " - #{m[:device]}"
187
+ end
180
188
  end
189
+ puts ' * Add to ~/.bashrc'
190
+ puts " - export HIVE_CONFIG=#{dir}/config"
181
191
  end
182
- puts ' * Add to ~/.bashrc'
183
- puts " - export HIVE_CONFIG=#{dir}/config"
192
+
193
+ mods = []
194
+ mods = add_modules unless headless
195
+ setup_hive(dir, mods)
data/lib/hive/worker.rb CHANGED
@@ -34,9 +34,7 @@ module Hive
34
34
  pem: Chamber.env.network.cert ? Chamber.env.network.cert : nil,
35
35
  ca_file: Chamber.env.network.cafile ? Chamber.env.network.cafile : nil,
36
36
  verify_mode: Chamber.env.network.verify_mode ? Chamber.env.network.verify_mode : nil,
37
- device: {
38
- id: @options['id']
39
- }
37
+ device: hive_mind_device_identifiers
40
38
  )
41
39
  @device_identity = @options['device_identity'] || 'unknown-device'
42
40
  pid = Process.pid
@@ -48,8 +46,11 @@ module Hive
48
46
  )
49
47
  @devicedb_register = true if @devicedb_register.nil?
50
48
 
49
+ # When DeviceDB is dumped in favour of Hive Mind the 'queues' argument
50
+ # will not be passed in and instead be generated by the
51
+ # autogenerated_queues method
51
52
  @queues = @options['queues'].class == Array ? @options['queues'] : []
52
- self.update_queue_log
53
+ self.update_queues
53
54
 
54
55
  @port_allocator = (@options.has_key?('port_allocator') ? @options['port_allocator'] : Hive::PortAllocator.new(ports: []))
55
56
 
@@ -248,6 +249,11 @@ module Hive
248
249
  @device_status = status
249
250
  end
250
251
 
252
+ # List of autogenerated queues for the worker
253
+ def autogenerated_queues
254
+ []
255
+ end
256
+
251
257
  def update_queues
252
258
  if @devicedb_register
253
259
  details = Hive.devicedb('Device').find(@options['id'])
@@ -266,6 +272,13 @@ module Hive
266
272
  @log.warn("Queue list missing from DeviceDB response")
267
273
  end
268
274
  end
275
+
276
+ # Get Queues from Hive Mind
277
+ #@log.debug("Getting queues from Hive Mind")
278
+ #@queues = (autogenerated_queues + @hive_mind.hive_queues(true)).uniq
279
+ #@log.debug("hive queues: #{@hive_mind.hive_queues}")
280
+ #@log.debug("Full list of queues: #{@queues}")
281
+ #update_queue_log
269
282
  end
270
283
 
271
284
  def update_queue_log
@@ -436,5 +449,10 @@ module Hive
436
449
  f.puts "#{Process.pid} #{state}"
437
450
  end
438
451
  end
452
+
453
+ # Parameters for uniquely identifying the device
454
+ def hive_mind_device_identifiers
455
+ { id: @device_id }
456
+ end
439
457
  end
440
458
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Haig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-01 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chamber
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.1.0
145
+ version: 0.1.2
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.1.0
152
+ version: 0.1.2
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: code_cache
155
155
  requirement: !ruby/object:Gem::Requirement