vmpooler 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd60a55d3a131c27874348c38051f1955e668df4
4
- data.tar.gz: 2a5793546f767b4470b2c5380e6630539003808f
3
+ metadata.gz: 13821cbed5546dca2c06d551c7085619f011cc1b
4
+ data.tar.gz: d3c6dea081a11077cf42c8951b01c72ebf8ef420
5
5
  SHA512:
6
- metadata.gz: 29a1374e8f4b5d26f31747764b58a191e9f232195ba5ae397c1f25f752724c6c0466d3bf579e4e87992f24ab7de830ed3c12d1242581ba4b27ac20c5f3af3cea
7
- data.tar.gz: 90ca0afcb191e9c956fe30bd11e568e9a9d040a8410833556f44e10d5ab6d960c1a7dcc9e4b77c171fb4e327ca3c30b411a67a6ff35e8013c7a2c4a54a0109a9
6
+ metadata.gz: c1fdfe8601ff5922b6de1630428a30e155fa6d3db5e1e1b75ad68b5368f6724382f495ce1d2e13af8a2db5243bc26d3e0519b059ac7c0bdce657d37d49aed707
7
+ data.tar.gz: cd19df2ac6912d190528a5c24ae24fe253303437e3bdf4c038b75276a64aac7e8f6fd82fd7dc149bf509be5d981b74a48e8fa6b939559128109ca29a0c908dea
@@ -1,11 +1,20 @@
1
1
  module Vmpooler
2
2
  class API
3
3
  class Dashboard < Sinatra::Base
4
+
5
+ helpers do
6
+ include Vmpooler::API::Helpers
7
+ end
8
+
4
9
  # handle to the App's configuration information
5
10
  def config
6
11
  @config ||= Vmpooler::API.settings.config
7
12
  end
8
13
 
14
+ def backend
15
+ Vmpooler::API.settings.redis
16
+ end
17
+
9
18
  # configuration setting for server hosting graph URLs to view
10
19
  def graph_server
11
20
  return @graph_server if @graph_server
@@ -53,10 +62,13 @@ module Vmpooler
53
62
  content_type :json
54
63
  result = {}
55
64
 
56
- Vmpooler::API.settings.config[:pools].each do |pool|
65
+ pools = Vmpooler::API.settings.config[:pools]
66
+ ready_hash = get_list_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
67
+
68
+ pools.each do |pool|
57
69
  result[pool['name']] ||= {}
58
70
  result[pool['name']]['size'] = pool['size']
59
- result[pool['name']]['ready'] = Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])
71
+ result[pool['name']]['ready'] = ready_hash[pool['name']]
60
72
  end
61
73
 
62
74
  if params[:history]
@@ -91,9 +103,9 @@ module Vmpooler
91
103
  rescue
92
104
  end
93
105
  else
94
- Vmpooler::API.settings.config[:pools].each do |pool|
106
+ pools.each do |pool|
95
107
  result[pool['name']] ||= {}
96
- result[pool['name']]['history'] = [Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])]
108
+ result[pool['name']]['history'] = [ready_hash[pool['name']]]
97
109
  end
98
110
  end
99
111
  end
@@ -104,8 +116,11 @@ module Vmpooler
104
116
  content_type :json
105
117
  result = {}
106
118
 
107
- Vmpooler::API.settings.config[:pools].each do |pool|
108
- running = Vmpooler::API.settings.redis.scard('vmpooler__running__' + pool['name'])
119
+ pools = Vmpooler::API.settings.config[:pools]
120
+ running_hash = get_list_across_pools_redis_scard(pools, 'vmpooler__running__', backend)
121
+
122
+ pools.each do |pool|
123
+ running = running_hash[pool['name']]
109
124
  pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
110
125
  result[pool['major']] ||= {}
111
126
  result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
@@ -151,6 +151,53 @@ module Vmpooler
151
151
  backend.hvals("vmpooler__#{task}__" + date_str).map(&:to_f)
152
152
  end
153
153
 
154
+ # Takes the pools and a key to run scard on
155
+ # returns an integer for the total count
156
+ def get_total_across_pools_redis_scard(pools, key, backend)
157
+ # using pipelined is much faster than querying each of the pools and adding them
158
+ # as we get the result.
159
+ res = backend.pipelined do
160
+ pools.each do |pool|
161
+ backend.scard(key + pool['name'])
162
+ end
163
+ end
164
+ res.inject(0){ |m, x| m+x }.to_i
165
+ end
166
+
167
+ # Takes the pools and a key to run scard on
168
+ # returns a hash with each pool name as key and the value being the count as integer
169
+ def get_list_across_pools_redis_scard(pools, key, backend)
170
+ # using pipelined is much faster than querying each of the pools and adding them
171
+ # as we get the result.
172
+ temp_hash = {}
173
+ res = backend.pipelined do
174
+ pools.each do |pool|
175
+ backend.scard(key + pool['name'])
176
+ end
177
+ end
178
+ pools.each_with_index do |pool, i|
179
+ temp_hash[pool['name']] = res[i].to_i
180
+ end
181
+ temp_hash
182
+ end
183
+
184
+ # Takes the pools and a key to run hget on
185
+ # returns a hash with each pool name as key and the value as string
186
+ def get_list_across_pools_redis_hget(pools, key, backend)
187
+ # using pipelined is much faster than querying each of the pools and adding them
188
+ # as we get the result.
189
+ temp_hash = {}
190
+ res = backend.pipelined do
191
+ pools.each do |pool|
192
+ backend.hget(key, pool['name'])
193
+ end
194
+ end
195
+ pools.each_with_index do |pool, i|
196
+ temp_hash[pool['name']] = res[i].to_s
197
+ end
198
+ temp_hash
199
+ end
200
+
154
201
  def get_capacity_metrics(pools, backend)
155
202
  capacity = {
156
203
  current: 0,
@@ -159,12 +206,11 @@ module Vmpooler
159
206
  }
160
207
 
161
208
  pools.each do |pool|
162
- pool['capacity'] = backend.scard('vmpooler__ready__' + pool['name']).to_i
163
-
164
- capacity[:current] += pool['capacity']
165
209
  capacity[:total] += pool['size'].to_i
166
210
  end
167
211
 
212
+ capacity[:current] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
213
+
168
214
  if capacity[:total] > 0
169
215
  capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1)
170
216
  end
@@ -183,12 +229,10 @@ module Vmpooler
183
229
  total: 0
184
230
  }
185
231
 
186
- pools.each do |pool|
187
- queue[:pending] += backend.scard('vmpooler__pending__' + pool['name']).to_i
188
- queue[:ready] += backend.scard('vmpooler__ready__' + pool['name']).to_i
189
- queue[:running] += backend.scard('vmpooler__running__' + pool['name']).to_i
190
- queue[:completed] += backend.scard('vmpooler__completed__' + pool['name']).to_i
191
- end
232
+ queue[:pending] = get_total_across_pools_redis_scard(pools,'vmpooler__pending__', backend)
233
+ queue[:ready] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
234
+ queue[:running] = get_total_across_pools_redis_scard(pools, 'vmpooler__running__', backend)
235
+ queue[:completed] = get_total_across_pools_redis_scard(pools, 'vmpooler__completed__', backend)
192
236
 
193
237
  queue[:cloning] = backend.get('vmpooler__tasks__clone').to_i
194
238
  queue[:booting] = queue[:pending].to_i - queue[:cloning].to_i
@@ -305,13 +305,18 @@ module Vmpooler
305
305
 
306
306
  # Check for empty pools
307
307
  result[:pools] = {} unless views and not views.include?("pools")
308
+ ready_hash = get_list_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
309
+ running_hash = get_list_across_pools_redis_scard(pools, 'vmpooler__running__', backend)
310
+ pending_hash = get_list_across_pools_redis_scard(pools, 'vmpooler__pending__', backend)
311
+ lastBoot_hash = get_list_across_pools_redis_hget(pools, 'vmpooler__lastboot', backend)
312
+
308
313
  pools.each do |pool|
309
314
  # REMIND: move this out of the API and into the back-end
310
- ready = backend.scard('vmpooler__ready__' + pool['name']).to_i
311
- running = backend.scard('vmpooler__running__' + pool['name']).to_i
312
- pending = backend.scard('vmpooler__pending__' + pool['name']).to_i
315
+ ready = ready_hash[pool['name']]
316
+ running = running_hash[pool['name']]
317
+ pending = pending_hash[pool['name']]
313
318
  max = pool['size']
314
- lastBoot = backend.hget('vmpooler__lastboot',pool['name']).to_s
319
+ lastBoot = lastBoot_hash[pool['name']]
315
320
  aka = pool['alias']
316
321
 
317
322
  result[:pools][pool['name']] = {
@@ -382,14 +387,9 @@ module Vmpooler
382
387
 
383
388
  end
384
389
 
385
- # using pipelined is much faster than querying each of the pools
386
- res = backend.pipelined do
387
- poolscopy.each do |pool|
388
- backend.scard('vmpooler__ready__' + pool['name'])
389
- end
390
- end
390
+ ready_hash = get_list_across_pools_redis_scard(poolscopy, 'vmpooler__ready__', backend)
391
391
 
392
- res.each_with_index { |ready, i| result[:pools][poolscopy[i]['name']][:ready] = ready }
392
+ ready_hash.each { |k, v| result[:pools][k][:ready] = v }
393
393
 
394
394
  JSON.pretty_generate(Hash[result.sort_by { |k, _v| k }])
395
395
  end
@@ -401,15 +401,7 @@ module Vmpooler
401
401
  running: 0,
402
402
  }
403
403
 
404
- # using pipelined is much faster than querying each of the pools and adding them
405
- # as we get the result.
406
- res = backend.pipelined do
407
- pools.each do |pool|
408
- backend.scard('vmpooler__running__' + pool['name'])
409
- end
410
- end
411
-
412
- queue[:running] = res.inject(0){ |m, x| m+x }
404
+ queue[:running] = get_total_across_pools_redis_scard(pools, 'vmpooler__running__', backend)
413
405
 
414
406
  JSON.pretty_generate(queue)
415
407
  end
@@ -1,3 +1,3 @@
1
1
  module Vmpooler
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmpooler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-24 00:00:00.000000000 Z
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pickup