triglav-agent 1.0.0.pre2 → 1.0.0.rc1

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docs/Triglav.html +1 -1
  4. data/docs/Triglav/Agent.html +2 -2
  5. data/docs/Triglav/Agent/ApiClient.html +82 -20
  6. data/docs/Triglav/Agent/ApiClient/AuthenticationError.html +1 -1
  7. data/docs/Triglav/Agent/ApiClient/ConnectionError.html +1 -1
  8. data/docs/Triglav/Agent/ApiClient/Error.html +1 -1
  9. data/docs/Triglav/Agent/Base.html +1 -1
  10. data/docs/Triglav/Agent/Base/CLI.html +21 -19
  11. data/docs/Triglav/Agent/Base/Connection.html +92 -6
  12. data/docs/Triglav/Agent/Base/Monitor.html +1 -1
  13. data/docs/Triglav/Agent/Base/Processor.html +22 -30
  14. data/docs/Triglav/Agent/Base/Setting.html +65 -63
  15. data/docs/Triglav/Agent/Base/Worker.html +1 -1
  16. data/docs/Triglav/Agent/Configuration.html +1 -1
  17. data/docs/Triglav/Agent/Error.html +1 -1
  18. data/docs/Triglav/Agent/HashUtil.html +1 -1
  19. data/docs/Triglav/Agent/LogFormatter.html +1 -1
  20. data/docs/Triglav/Agent/Logger.html +1 -1
  21. data/docs/Triglav/Agent/StorageFile.html +1 -1
  22. data/docs/Triglav/Agent/Timer.html +1 -1
  23. data/docs/Triglav/Agent/TooManyError.html +1 -1
  24. data/docs/_index.html +1 -1
  25. data/docs/file.LICENSE.html +2 -2
  26. data/docs/file.README.html +1 -1
  27. data/docs/index.html +1 -1
  28. data/docs/method_list.html +50 -34
  29. data/docs/top-level-namespace.html +1 -1
  30. data/lib/triglav/agent.rb +1 -0
  31. data/lib/triglav/agent/base/cli.rb +4 -2
  32. data/lib/triglav/agent/base/processor.rb +4 -1
  33. data/lib/triglav/agent/base/setting.rb +4 -2
  34. data/lib/triglav/agent/base/worker.rb +7 -0
  35. data/lib/triglav/agent/status.rb +68 -0
  36. data/lib/triglav/agent/storage_file.rb +20 -0
  37. data/lib/triglav/agent/version.rb +1 -1
  38. data/triglav-agent.gemspec +2 -2
  39. metadata +5 -4
@@ -277,7 +277,7 @@
277
277
  </div>
278
278
 
279
279
  <div id="footer">
280
- Generated on Thu Feb 23 23:20:33 2017 by
280
+ Generated on Wed Mar 8 23:12:38 2017 by
281
281
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
282
282
  0.9.5 (ruby-2.3.2).
283
283
  </div>
@@ -1120,7 +1120,7 @@
1120
1120
  </div>
1121
1121
 
1122
1122
  <div id="footer">
1123
- Generated on Thu Feb 23 23:20:34 2017 by
1123
+ Generated on Wed Mar 8 23:12:39 2017 by
1124
1124
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1125
1125
  0.9.5 (ruby-2.3.2).
1126
1126
  </div>
@@ -414,7 +414,7 @@
414
414
  </div>
415
415
 
416
416
  <div id="footer">
417
- Generated on Thu Feb 23 23:20:33 2017 by
417
+ Generated on Wed Mar 8 23:12:38 2017 by
418
418
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
419
419
  0.9.5 (ruby-2.3.2).
420
420
  </div>
@@ -124,7 +124,7 @@
124
124
  </div>
125
125
 
126
126
  <div id="footer">
127
- Generated on Thu Feb 23 23:20:33 2017 by
127
+ Generated on Wed Mar 8 23:12:38 2017 by
128
128
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
129
129
  0.9.5 (ruby-2.3.2).
130
130
  </div>
data/docs/_index.html CHANGED
@@ -325,7 +325,7 @@
325
325
  </div>
326
326
 
327
327
  <div id="footer">
328
- Generated on Thu Feb 23 23:20:32 2017 by
328
+ Generated on Wed Mar 8 23:12:38 2017 by
329
329
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
330
330
  0.9.5 (ruby-2.3.2).
331
331
  </div>
@@ -59,10 +59,10 @@
59
59
 
60
60
  <iframe id="search_frame" src="file_list.html"></iframe>
61
61
 
62
- <div id="content"><div id='filecontents'>The MIT License (MIT)<br/><br/>Copyright (c) 2016 sonots<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy<br/>of this software and associated documentation files (the &quot;Software&quot;), to deal<br/>in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br/>copies of the Software, and to permit persons to whom the Software is<br/>furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in<br/>all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br/>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br/>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br/>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br/>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br/>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br/>THE SOFTWARE.</div></div>
62
+ <div id="content"><div id='filecontents'>The MIT License (MIT)<br/><br/>Copyright (c) 2016 Triglav Team<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy<br/>of this software and associated documentation files (the &quot;Software&quot;), to deal<br/>in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br/>copies of the Software, and to permit persons to whom the Software is<br/>furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in<br/>all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br/>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br/>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br/>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br/>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br/>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br/>THE SOFTWARE.</div></div>
63
63
 
64
64
  <div id="footer">
65
- Generated on Thu Feb 23 23:20:33 2017 by
65
+ Generated on Wed Mar 8 23:12:38 2017 by
66
66
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
67
67
  0.9.5 (ruby-2.3.2).
68
68
  </div>
@@ -127,7 +127,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
127
127
  </div></div>
128
128
 
129
129
  <div id="footer">
130
- Generated on Thu Feb 23 23:20:33 2017 by
130
+ Generated on Wed Mar 8 23:12:38 2017 by
131
131
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
132
  0.9.5 (ruby-2.3.2).
133
133
  </div>
data/docs/index.html CHANGED
@@ -127,7 +127,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
127
127
  </div></div>
128
128
 
129
129
  <div id="footer">
130
- Generated on Thu Feb 23 23:20:33 2017 by
130
+ Generated on Wed Mar 8 23:12:38 2017 by
131
131
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
132
  0.9.5 (ruby-2.3.2).
133
133
  </div>
@@ -108,6 +108,22 @@
108
108
  </li>
109
109
 
110
110
 
111
+ <li class="odd ">
112
+ <div class="item">
113
+ <span class='object_link'><a href="Triglav/Agent/ApiClient.html#close-instance_method" title="Triglav::Agent::ApiClient#close (method)">#close</a></span>
114
+ <small>Triglav::Agent::ApiClient</small>
115
+ </div>
116
+ </li>
117
+
118
+
119
+ <li class="even ">
120
+ <div class="item">
121
+ <span class='object_link'><a href="Triglav/Agent/Base/Connection.html#close-instance_method" title="Triglav::Agent::Base::Connection#close (method)">#close</a></span>
122
+ <small>Triglav::Agent::Base::Connection</small>
123
+ </div>
124
+ </li>
125
+
126
+
111
127
  <li class="odd ">
112
128
  <div class="item">
113
129
  <span class='object_link'><a href="Triglav/Agent/Base/Setting.html#config_file-instance_method" title="Triglav::Agent::Base::Setting#config_file (method)">#config_file</a></span>
@@ -222,24 +238,24 @@
222
238
 
223
239
  <li class="odd ">
224
240
  <div class="item">
225
- <span class='object_link'><a href="Triglav/Agent/Base/Setting.html#initialize-instance_method" title="Triglav::Agent::Base::Setting#initialize (method)">#initialize</a></span>
226
- <small>Triglav::Agent::Base::Setting</small>
241
+ <span class='object_link'><a href="Triglav/Agent/Logger.html#initialize-instance_method" title="Triglav::Agent::Logger#initialize (method)">#initialize</a></span>
242
+ <small>Triglav::Agent::Logger</small>
227
243
  </div>
228
244
  </li>
229
245
 
230
246
 
231
247
  <li class="even ">
232
248
  <div class="item">
233
- <span class='object_link'><a href="Triglav/Agent/Base/Processor.html#initialize-instance_method" title="Triglav::Agent::Base::Processor#initialize (method)">#initialize</a></span>
234
- <small>Triglav::Agent::Base::Processor</small>
249
+ <span class='object_link'><a href="Triglav/Agent/LogFormatter.html#initialize-instance_method" title="Triglav::Agent::LogFormatter#initialize (method)">#initialize</a></span>
250
+ <small>Triglav::Agent::LogFormatter</small>
235
251
  </div>
236
252
  </li>
237
253
 
238
254
 
239
255
  <li class="odd ">
240
256
  <div class="item">
241
- <span class='object_link'><a href="Triglav/Agent/Base/Connection.html#initialize-instance_method" title="Triglav::Agent::Base::Connection#initialize (method)">#initialize</a></span>
242
- <small>Triglav::Agent::Base::Connection</small>
257
+ <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#initialize-instance_method" title="Triglav::Agent::Base::Worker#initialize (method)">#initialize</a></span>
258
+ <small>Triglav::Agent::Base::Worker</small>
243
259
  </div>
244
260
  </li>
245
261
 
@@ -254,48 +270,48 @@
254
270
 
255
271
  <li class="odd ">
256
272
  <div class="item">
257
- <span class='object_link'><a href="Triglav/Agent/ApiClient.html#initialize-instance_method" title="Triglav::Agent::ApiClient#initialize (method)">#initialize</a></span>
258
- <small>Triglav::Agent::ApiClient</small>
273
+ <span class='object_link'><a href="Triglav/Agent/Base/Monitor.html#initialize-instance_method" title="Triglav::Agent::Base::Monitor#initialize (method)">#initialize</a></span>
274
+ <small>Triglav::Agent::Base::Monitor</small>
259
275
  </div>
260
276
  </li>
261
277
 
262
278
 
263
279
  <li class="even ">
264
280
  <div class="item">
265
- <span class='object_link'><a href="Triglav/Agent/LogFormatter.html#initialize-instance_method" title="Triglav::Agent::LogFormatter#initialize (method)">#initialize</a></span>
266
- <small>Triglav::Agent::LogFormatter</small>
281
+ <span class='object_link'><a href="Triglav/Agent/Timer.html#initialize-instance_method" title="Triglav::Agent::Timer#initialize (method)">#initialize</a></span>
282
+ <small>Triglav::Agent::Timer</small>
267
283
  </div>
268
284
  </li>
269
285
 
270
286
 
271
287
  <li class="odd ">
272
288
  <div class="item">
273
- <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#initialize-instance_method" title="Triglav::Agent::Base::Worker#initialize (method)">#initialize</a></span>
274
- <small>Triglav::Agent::Base::Worker</small>
289
+ <span class='object_link'><a href="Triglav/Agent/Base/Setting.html#initialize-instance_method" title="Triglav::Agent::Base::Setting#initialize (method)">#initialize</a></span>
290
+ <small>Triglav::Agent::Base::Setting</small>
275
291
  </div>
276
292
  </li>
277
293
 
278
294
 
279
295
  <li class="even ">
280
296
  <div class="item">
281
- <span class='object_link'><a href="Triglav/Agent/Timer.html#initialize-instance_method" title="Triglav::Agent::Timer#initialize (method)">#initialize</a></span>
282
- <small>Triglav::Agent::Timer</small>
297
+ <span class='object_link'><a href="Triglav/Agent/Base/Connection.html#initialize-instance_method" title="Triglav::Agent::Base::Connection#initialize (method)">#initialize</a></span>
298
+ <small>Triglav::Agent::Base::Connection</small>
283
299
  </div>
284
300
  </li>
285
301
 
286
302
 
287
303
  <li class="odd ">
288
304
  <div class="item">
289
- <span class='object_link'><a href="Triglav/Agent/Base/Monitor.html#initialize-instance_method" title="Triglav::Agent::Base::Monitor#initialize (method)">#initialize</a></span>
290
- <small>Triglav::Agent::Base::Monitor</small>
305
+ <span class='object_link'><a href="Triglav/Agent/ApiClient.html#initialize-instance_method" title="Triglav::Agent::ApiClient#initialize (method)">#initialize</a></span>
306
+ <small>Triglav::Agent::ApiClient</small>
291
307
  </div>
292
308
  </li>
293
309
 
294
310
 
295
311
  <li class="even ">
296
312
  <div class="item">
297
- <span class='object_link'><a href="Triglav/Agent/Logger.html#initialize-instance_method" title="Triglav::Agent::Logger#initialize (method)">#initialize</a></span>
298
- <small>Triglav::Agent::Logger</small>
313
+ <span class='object_link'><a href="Triglav/Agent/Base/Processor.html#initialize-instance_method" title="Triglav::Agent::Base::Processor#initialize (method)">#initialize</a></span>
314
+ <small>Triglav::Agent::Base::Processor</small>
299
315
  </div>
300
316
  </li>
301
317
 
@@ -310,7 +326,7 @@
310
326
 
311
327
  <li class="even ">
312
328
  <div class="item">
313
- <span class='object_link'><a href="Triglav/Agent/StorageFile.html#load-class_method" title="Triglav::Agent::StorageFile.load (method)">load</a></span>
329
+ <span class='object_link'><a href="Triglav/Agent/StorageFile.html#load-instance_method" title="Triglav::Agent::StorageFile#load (method)">#load</a></span>
314
330
  <small>Triglav::Agent::StorageFile</small>
315
331
  </div>
316
332
  </li>
@@ -318,7 +334,7 @@
318
334
 
319
335
  <li class="odd ">
320
336
  <div class="item">
321
- <span class='object_link'><a href="Triglav/Agent/StorageFile.html#load-instance_method" title="Triglav::Agent::StorageFile#load (method)">#load</a></span>
337
+ <span class='object_link'><a href="Triglav/Agent/StorageFile.html#load-class_method" title="Triglav::Agent::StorageFile.load (method)">load</a></span>
322
338
  <small>Triglav::Agent::StorageFile</small>
323
339
  </div>
324
340
  </li>
@@ -414,24 +430,24 @@
414
430
 
415
431
  <li class="odd ">
416
432
  <div class="item">
417
- <span class='object_link'><a href="Triglav/Agent/Base/Processor.html#process-instance_method" title="Triglav::Agent::Base::Processor#process (method)">#process</a></span>
418
- <small>Triglav::Agent::Base::Processor</small>
433
+ <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#process-instance_method" title="Triglav::Agent::Base::Worker#process (method)">#process</a></span>
434
+ <small>Triglav::Agent::Base::Worker</small>
419
435
  </div>
420
436
  </li>
421
437
 
422
438
 
423
439
  <li class="even ">
424
440
  <div class="item">
425
- <span class='object_link'><a href="Triglav/Agent/Base/Monitor.html#process-instance_method" title="Triglav::Agent::Base::Monitor#process (method)">#process</a></span>
426
- <small>Triglav::Agent::Base::Monitor</small>
441
+ <span class='object_link'><a href="Triglav/Agent/Base/Processor.html#process-instance_method" title="Triglav::Agent::Base::Processor#process (method)">#process</a></span>
442
+ <small>Triglav::Agent::Base::Processor</small>
427
443
  </div>
428
444
  </li>
429
445
 
430
446
 
431
447
  <li class="odd ">
432
448
  <div class="item">
433
- <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#process-instance_method" title="Triglav::Agent::Base::Worker#process (method)">#process</a></span>
434
- <small>Triglav::Agent::Base::Worker</small>
449
+ <span class='object_link'><a href="Triglav/Agent/Base/Monitor.html#process-instance_method" title="Triglav::Agent::Base::Monitor#process (method)">#process</a></span>
450
+ <small>Triglav::Agent::Base::Monitor</small>
435
451
  </div>
436
452
  </li>
437
453
 
@@ -454,16 +470,16 @@
454
470
 
455
471
  <li class="even ">
456
472
  <div class="item">
457
- <span class='object_link'><a href="Triglav/Agent/Base/Setting.html#reload-instance_method" title="Triglav::Agent::Base::Setting#reload (method)">#reload</a></span>
458
- <small>Triglav::Agent::Base::Setting</small>
473
+ <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#reload-instance_method" title="Triglav::Agent::Base::Worker#reload (method)">#reload</a></span>
474
+ <small>Triglav::Agent::Base::Worker</small>
459
475
  </div>
460
476
  </li>
461
477
 
462
478
 
463
479
  <li class="odd ">
464
480
  <div class="item">
465
- <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#reload-instance_method" title="Triglav::Agent::Base::Worker#reload (method)">#reload</a></span>
466
- <small>Triglav::Agent::Base::Worker</small>
481
+ <span class='object_link'><a href="Triglav/Agent/Base/Setting.html#reload-instance_method" title="Triglav::Agent::Base::Setting#reload (method)">#reload</a></span>
482
+ <small>Triglav::Agent::Base::Setting</small>
467
483
  </div>
468
484
  </li>
469
485
 
@@ -574,16 +590,16 @@
574
590
 
575
591
  <li class="odd ">
576
592
  <div class="item">
577
- <span class='object_link'><a href="Triglav/Agent/Timer.html#stop-instance_method" title="Triglav::Agent::Timer#stop (method)">#stop</a></span>
578
- <small>Triglav::Agent::Timer</small>
593
+ <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#stop-instance_method" title="Triglav::Agent::Base::Worker#stop (method)">#stop</a></span>
594
+ <small>Triglav::Agent::Base::Worker</small>
579
595
  </div>
580
596
  </li>
581
597
 
582
598
 
583
599
  <li class="even ">
584
600
  <div class="item">
585
- <span class='object_link'><a href="Triglav/Agent/Base/Worker.html#stop-instance_method" title="Triglav::Agent::Base::Worker#stop (method)">#stop</a></span>
586
- <small>Triglav::Agent::Base::Worker</small>
601
+ <span class='object_link'><a href="Triglav/Agent/Timer.html#stop-instance_method" title="Triglav::Agent::Timer#stop (method)">#stop</a></span>
602
+ <small>Triglav::Agent::Timer</small>
587
603
  </div>
588
604
  </li>
589
605
 
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Thu Feb 23 23:20:33 2017 by
105
+ Generated on Wed Mar 8 23:12:38 2017 by
106
106
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.5 (ruby-2.3.2).
108
108
  </div>
data/lib/triglav/agent.rb CHANGED
@@ -9,6 +9,7 @@ require 'triglav/agent/error'
9
9
  require 'triglav/agent/hash_util'
10
10
  require 'triglav/agent/logger'
11
11
  require 'triglav/agent/storage_file'
12
+ require 'triglav/agent/status'
12
13
  require 'triglav/agent/timer'
13
14
  require 'triglav/agent/version'
14
15
 
@@ -7,8 +7,10 @@ module Triglav::Agent
7
7
  module Base
8
8
  # A base class for cli option parser
9
9
  #
10
- # This base class usually should be enough for agent plugins, but
11
- # you can override this class and configure with Configuration#cli_classe=
10
+ # You usually do not need to customize this class, but if you want to
11
+ # implement your original, configure
12
+ #
13
+ # Triglav::Agent::Configuration.cli_class =
12
14
  class CLI
13
15
  def run
14
16
  opts, _ = parse_options(ARGV)
@@ -1,5 +1,6 @@
1
1
  require 'parallel'
2
2
  require 'connection_pool'
3
+ require 'triglav/agent/status'
3
4
 
4
5
  module Triglav::Agent
5
6
  module Base
@@ -32,7 +33,7 @@ module Triglav::Agent
32
33
  events = nil
33
34
  begin
34
35
  @connection_pool.with do |connection|
35
- monitor = monitor_class.new(connection, resource)
36
+ monitor = monitor_class.new(connection, resource_uri_prefix, resource)
36
37
  monitor.process do |_events|
37
38
  events = _events
38
39
  $logger.info { "send_messages:#{events.map(&:to_hash).to_json}" }
@@ -69,6 +70,8 @@ module Triglav::Agent
69
70
  @api_client_pool = ConnectionPool.new(connection_pool_opts) {
70
71
  ApiClient.new # renew connection
71
72
  }
73
+ resource_uris = resources.map {|resource| resource.uri.to_sym }
74
+ Status.select_resource_uris!(resource_uri_prefix, resource_uris)
72
75
  @mutex = Mutex.new
73
76
  end
74
77
 
@@ -7,8 +7,10 @@ module Triglav::Agent
7
7
  module Base
8
8
  # A base class represents settings coming from config.yml and cli options
9
9
  #
10
- # This base class usually should be enough for agent plugins, but
11
- # you can override this class and configure with Configuration#setting_class=
10
+ # You usually do not need to customize this class, but if you want to
11
+ # implement your original, configure
12
+ #
13
+ # Triglav::Agent::Configuration.setting_class =
12
14
  class Setting
13
15
  attr_reader :cli_options
14
16
 
@@ -1,4 +1,5 @@
1
1
  require 'triglav/agent/timer'
2
+ require 'triglav/agent/status'
2
3
 
3
4
  module Triglav::Agent
4
5
  module Base
@@ -12,12 +13,14 @@ module Triglav::Agent
12
13
  # serverengine interface
13
14
  def initialize
14
15
  @timer = Timer.new
16
+ reload_status
15
17
  end
16
18
 
17
19
  # serverengine interface
18
20
  def reload
19
21
  $logger.info { "Worker#reload worker_id:#{worker_id}" }
20
22
  $setting.reload
23
+ reload_status
21
24
  end
22
25
 
23
26
  # serverengine interface
@@ -71,6 +74,10 @@ module Triglav::Agent
71
74
 
72
75
  private
73
76
 
77
+ def reload_status
78
+ Triglav::Agent::Status.select_resource_uri_prefixes!(resource_uri_prefixes)
79
+ end
80
+
74
81
  def processor_class
75
82
  Configuration.processor_class
76
83
  end
@@ -0,0 +1,68 @@
1
+ require_relative 'storage_file'
2
+ require 'set'
3
+
4
+ module Triglav::Agent
5
+ class Status
6
+ attr_accessor :path
7
+ attr_reader :resource_uri_prefix, :resource_uri
8
+
9
+ VERSION = :v1
10
+
11
+ def initialize(resource_uri_prefix, resource_uri)
12
+ @path = $setting.status_file
13
+ @resource_uri_prefix = resource_uri_prefix.to_sym
14
+ @resource_uri = resource_uri.to_sym
15
+ @parents = [VERSION, @resource_uri_prefix, @resource_uri]
16
+ end
17
+
18
+ # set(val)
19
+ # set(key, val)
20
+ # set(key1, key2, val)
21
+ # set([key], val)
22
+ # set([key1, key2], val)
23
+ def set(*args)
24
+ val = args.pop
25
+ keys = args.flatten
26
+ StorageFile.set(path, [*@parents, *keys], val)
27
+ end
28
+
29
+ # setnx(val)
30
+ # setnx(key, val)
31
+ # setnx(key1, key2, val)
32
+ # setnx([key], val)
33
+ # setnx([key1, key2], val)
34
+ def setnx(*args)
35
+ val = args.pop
36
+ keys = args.flatten
37
+ StorageFile.setnx(path, [*@parents, *keys], val)
38
+ end
39
+
40
+ # getsetnx(val)
41
+ # getsetnx(key, val)
42
+ # getsetnx(key1, key2, val)
43
+ # getsetnx([key], val)
44
+ # getsetnx([key1, key2], val)
45
+ def getsetnx(*args)
46
+ val = args.pop
47
+ keys = args.flatten
48
+ StorageFile.getsetnx(path, [*@parents, *keys], val)
49
+ end
50
+
51
+ # get(key)
52
+ # get(key1, key2)
53
+ # get([key])
54
+ # get([key1, key2])
55
+ def get(*args)
56
+ keys = (args || []).flatten
57
+ StorageFile.get(path, [*@parents, *keys])
58
+ end
59
+
60
+ def self.select_resource_uri_prefixes!(resource_uri_prefixes)
61
+ Triglav::Agent::StorageFile.select!($setting.status_file, [VERSION], resource_uri_prefixes.map(&:to_sym))
62
+ end
63
+
64
+ def self.select_resource_uris!(resource_uri_prefix, resource_uris)
65
+ Triglav::Agent::StorageFile.select!($setting.status_file, [VERSION, resource_uri_prefix.to_sym], resource_uris.map(&:to_sym))
66
+ end
67
+ end
68
+ end