prometheus-splash 0.5.3 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -1
- data/README.md +58 -60
- data/bin/splash +3 -0
- data/config/splash.yml +110 -11
- data/lib/splash/backends.rb +7 -0
- data/lib/splash/backends/file.rb +36 -0
- data/lib/splash/backends/redis.rb +44 -1
- data/lib/splash/cli.rb +11 -4
- data/lib/splash/cli/commands.rb +136 -9
- data/lib/splash/cli/config.rb +9 -1
- data/lib/splash/cli/daemon.rb +49 -2
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +116 -47
- data/lib/splash/cli/process.rb +121 -52
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/transfers.rb +213 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +111 -23
- data/lib/splash/config.rb +174 -23
- data/lib/splash/config/flush.rb +9 -1
- data/lib/splash/config/sanitycheck.rb +7 -2
- data/lib/splash/config/service.rb +8 -1
- data/lib/splash/config/setup.rb +8 -3
- data/lib/splash/constants.rb +37 -8
- data/lib/splash/daemon.rb +5 -1
- data/lib/splash/daemon/controller.rb +31 -11
- data/lib/splash/daemon/metrics.rb +29 -14
- data/lib/splash/daemon/orchestrator.rb +114 -35
- data/lib/splash/daemon/orchestrator/grammar.rb +40 -5
- data/lib/splash/daemon/orchestrator/hooks.rb +10 -0
- data/lib/splash/dependencies.rb +18 -1
- data/lib/splash/exiter.rb +14 -0
- data/lib/splash/helpers.rb +88 -46
- data/lib/splash/loggers.rb +30 -4
- data/lib/splash/loggers/cli.rb +18 -11
- data/lib/splash/loggers/daemon.rb +14 -3
- data/lib/splash/loggers/dual.rb +14 -1
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +105 -20
- data/lib/splash/processes.rb +104 -21
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transfers.rb +229 -0
- data/lib/splash/transports.rb +9 -0
- data/lib/splash/transports/rabbitmq.rb +33 -4
- data/lib/splash/webadmin.rb +122 -0
- data/lib/splash/webadmin/api/routes/commands.rb +28 -0
- data/lib/splash/webadmin/api/routes/config.rb +10 -0
- data/lib/splash/webadmin/api/routes/init.rb +2 -0
- data/lib/splash/webadmin/api/routes/logs.rb +59 -0
- data/lib/splash/webadmin/api/routes/process.rb +60 -0
- data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
- data/lib/splash/webadmin/main.rb +27 -0
- data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
- data/lib/splash/webadmin/portal/controllers/home.rb +31 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
- data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/proxy.rb +36 -0
- data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
- data/lib/splash/webadmin/portal/controllers/sequences.rb +7 -0
- data/lib/splash/webadmin/portal/init.rb +11 -0
- data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
- data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
- data/lib/splash/webadmin/portal/views/commands.slim +49 -0
- data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
- data/lib/splash/webadmin/portal/views/home.slim +123 -0
- data/lib/splash/webadmin/portal/views/layout.slim +43 -0
- data/lib/splash/webadmin/portal/views/logs.slim +32 -0
- data/lib/splash/webadmin/portal/views/nav.slim +17 -0
- data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
- data/lib/splash/webadmin/portal/views/processes.slim +29 -0
- data/lib/splash/webadmin/portal/views/proxy.slim +16 -0
- data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
- data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
- data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
- data/prometheus-splash.gemspec +11 -2
- data/spec/helpers_spec.rb +119 -0
- metadata +191 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60d3aa2e635dbea8022a1804e9886e495648ce777db2293442ae3a16bae7e25a
|
4
|
+
data.tar.gz: 14912be5e4171daae1ee7706f98ac7974c43a96d56e7daa58a1e9a40d46b60ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66a48e63fd8940c6343113511e1ad91531037013a042a79348a755de74e6447a791854fa2ec82461c38695370402e30790ac7660fd75c0cc82c0f5ef788701d
|
7
|
+
data.tar.gz: 9d59657c45219e31af8a6c85fc137925ee03ccecc7a98e62848ba28540ec2e39df674fcd391b51334c4bc1252de487a5a55110a286707fee9a38e54bf85a3cfc
|
data/CHANGELOG.md
CHANGED
@@ -124,4 +124,34 @@
|
|
124
124
|
### FEATURE
|
125
125
|
|
126
126
|
* processes monitoring #23
|
127
|
-
|
127
|
+
|
128
|
+
## V 0.6.0 2020/10/10
|
129
|
+
|
130
|
+
### FEATURE
|
131
|
+
|
132
|
+
* read only WebAdmin (Major update)
|
133
|
+
* API REST
|
134
|
+
* refactoring
|
135
|
+
|
136
|
+
## V 0.7.0
|
137
|
+
|
138
|
+
### FEATURE
|
139
|
+
|
140
|
+
* sequences
|
141
|
+
* API sequences
|
142
|
+
* UI sequences
|
143
|
+
* Transfers
|
144
|
+
* API Transfers
|
145
|
+
* UI Transfers
|
146
|
+
|
147
|
+
## V 0.8.0
|
148
|
+
|
149
|
+
### FEATURE
|
150
|
+
* orchestrator rebuild
|
151
|
+
* reshash config and reset + grammar and Cli
|
152
|
+
* refacto config
|
153
|
+
|
154
|
+
## V0.8.1
|
155
|
+
|
156
|
+
### FEATURE
|
157
|
+
* #55 historisation for reports for all
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ SPLASH is **Supervision with Prometheus of Logs and Asynchronous tasks orchestra
|
|
9
9
|
* Web : http://www.ultragreen.net
|
10
10
|
* Github : https://github.com/Ultragreen/prometheus-splash
|
11
11
|
* Rubygems : https://rubygems.org/gems/prometheus-splash
|
12
|
-
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.
|
12
|
+
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.8.1
|
13
13
|
|
14
14
|
Prometheus Logs and Batchs supervision over PushGateway
|
15
15
|
|
@@ -65,10 +65,12 @@ As root or with rvmsudo, if you use RVM.
|
|
65
65
|
# splash config setup
|
66
66
|
Splash -> setup :
|
67
67
|
* Installing Configuration file : /etc/splash.yml : [OK]
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
👍 Splash Initialisation
|
69
|
+
👍 Installing template file : /etc/splash_execution_report.tpl
|
70
|
+
👍 Creating/Checking pid file path : /var/run/splash
|
71
|
+
👍 Creating/Checking trace file path : /var/run/spla
|
72
|
+
|
73
|
+
*NOTE : you can just type 'splash' withou any arguments, for the first setup because, Splash come with an automatic recovery mode, when configuration file is missing, run at the very beginnning of his the execution*
|
72
74
|
|
73
75
|
*WARNING : if you have already configured Splash, running this command without --preserve flag, RESET the Splash Configuration.*
|
74
76
|
|
@@ -121,7 +123,7 @@ For file/folders if problems is detected, it could be such as :
|
|
121
123
|
run :
|
122
124
|
|
123
125
|
$ splash config version
|
124
|
-
Splash version : 0.0
|
126
|
+
Splash version : 0.6.0, Author : Romain GEORGES <gems@ultragreen.net>
|
125
127
|
Ultragreen (c) 2020 BSD-2-Clause
|
126
128
|
|
127
129
|
|
@@ -652,74 +654,70 @@ TODO
|
|
652
654
|
|
653
655
|
defined in the lib/splash/constants.rb
|
654
656
|
|
655
|
-
```ruby
|
656
657
|
|
657
|
-
|
658
|
-
|
658
|
+
|
659
|
+
# the only one non-overridable by the configuration
|
660
|
+
CONFIG_FILE = "/etc/splash.yml"
|
659
661
|
|
660
662
|
|
661
|
-
TRACE_PATH="/var/run/splash"
|
663
|
+
TRACE_PATH="/var/run/splash"
|
662
664
|
|
663
|
-
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
664
|
-
DAEMON_PROCESS_NAME="Splash : daemon."
|
665
|
-
DAEMON_PID_PATH="/var/run"
|
666
|
-
DAEMON_PID_FILE="splash.pid"
|
667
|
-
DAEMON_STDOUT_TRACE="stdout.txt"
|
668
|
-
DAEMON_STDERR_TRACE="stderr.txt"
|
665
|
+
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
666
|
+
DAEMON_PROCESS_NAME="Splash : daemon."
|
667
|
+
DAEMON_PID_PATH="/var/run"
|
668
|
+
DAEMON_PID_FILE="splash.pid"
|
669
|
+
DAEMON_STDOUT_TRACE="stdout.txt"
|
670
|
+
DAEMON_STDERR_TRACE="stderr.txt"
|
669
671
|
|
670
|
-
AUTHOR="Romain GEORGES"
|
671
|
-
EMAIL = "gems@ultragreen.net"
|
672
|
-
COPYRIGHT="Ultragreen (c) 2020"
|
673
|
-
LICENSE="BSD-2-Clause"
|
672
|
+
AUTHOR="Romain GEORGES"
|
673
|
+
EMAIL = "gems@ultragreen.net"
|
674
|
+
COPYRIGHT="Ultragreen (c) 2020"
|
675
|
+
LICENSE="BSD-2-Clause"
|
674
676
|
|
675
|
-
PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
|
676
|
-
PROMETHEUS_PUSHGATEWAY_PORT = "9091"
|
677
|
+
PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
|
678
|
+
PROMETHEUS_PUSHGATEWAY_PORT = "9091"
|
677
679
|
|
678
|
-
EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
|
679
|
-
EXECUTION_TEMPLATE_TOKENS_LIST = [:end_date,:start_date,:cmd_name,:cmd_line,:stdout,:stderr,:desc,:status,:exec_time]
|
680
|
+
EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
|
681
|
+
EXECUTION_TEMPLATE_TOKENS_LIST = [:end_date,:start_date,:cmd_name,:cmd_line,:stdout,:stderr,:desc,:status,:exec_time]
|
680
682
|
|
681
|
-
BACKENDS_STRUCT = { :list => [:file,:redis],
|
683
|
+
BACKENDS_STRUCT = { :list => [:file,:redis],
|
682
684
|
:stores => { :execution_trace => { :type => :file, :path => "/var/run/splash" }}}
|
683
|
-
TRANSPORTS_STRUCT = { :list => [:rabbitmq],
|
685
|
+
TRANSPORTS_STRUCT = { :list => [:rabbitmq],
|
684
686
|
:active => :rabbitmq,
|
685
687
|
:rabbitmq => { :url => 'amqp://localhost/'} }
|
686
688
|
|
687
|
-
```
|
688
|
-
|
689
689
|
|
690
690
|
#### Splash CLI return code significations
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
```
|
722
|
-
}
|
691
|
+
|
692
|
+
|
693
|
+
# context execution
|
694
|
+
:not_root => {:message => "This operation need to be run as root (use sudo or rvmsudo)", :code => 10},
|
695
|
+
:options_incompatibility => {:message => "Options incompatibility", :code => 40},
|
696
|
+
:service_dependence_missing => {:message => "Splash Service dependence missing", :code => 60},
|
697
|
+
|
698
|
+
# config
|
699
|
+
:specific_config_required => {:message => "Specific configuration required", :code => 30},
|
700
|
+
:splash_setup_error => {:message => "Splash Setup terminated unsuccessfully", :code => 25},
|
701
|
+
:splash_setup_success => {:message => "Splash Setup terminated successfully", :code => 0},
|
702
|
+
:splash_sanitycheck_error => {:message => "Splash Sanitycheck terminated unsuccessfully", :code => 20},
|
703
|
+
:splash_sanitycheck_success => {:message => "Splash Sanitycheck terminated successfully", :code => 0},
|
704
|
+
:configuration_error => {:message => "Splash Configuration Error", :code => 50},
|
705
|
+
|
706
|
+
|
707
|
+
# global
|
708
|
+
:quiet_exit => {:code => 0},
|
709
|
+
|
710
|
+
# events
|
711
|
+
:interrupt => {:message => "Splash user operation interrupted", :code => 33},
|
712
|
+
|
713
|
+
# request
|
714
|
+
:not_found => {:message => "Object not found", :code => 44},
|
715
|
+
:already_exist => {:message => "Object already exist", :code => 48},
|
716
|
+
|
717
|
+
# daemon
|
718
|
+
:status_ok => {:message => "Status OK", :code => 0},
|
719
|
+
:status_ko => {:message => "Status KO", :code => 31}
|
720
|
+
|
723
721
|
|
724
722
|
### In the Futur ?
|
725
723
|
|
data/bin/splash
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
+
# major include
|
4
5
|
require 'splash/dependencies'
|
5
6
|
require 'splash/cli'
|
6
7
|
|
@@ -13,6 +14,7 @@ include Splash::Exiter
|
|
13
14
|
include Splash::Loggers
|
14
15
|
include Splash::Config
|
15
16
|
|
17
|
+
# auto setup
|
16
18
|
unless verify_file(name: CONFIG_FILE, mode: "644", owner: user_root, group: group_root).empty? then
|
17
19
|
puts 'Splash need reconfiguration : Auto setup launch'
|
18
20
|
|
@@ -26,4 +28,5 @@ unless verify_file(name: CONFIG_FILE, mode: "644", owner: user_root, group: grou
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
31
|
+
# running Thor
|
29
32
|
CLI.start(ARGV)
|
data/config/splash.yml
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
:splash:
|
3
3
|
|
4
4
|
### Main Configuration
|
5
|
+
:paths:
|
6
|
+
:pid_path: /var/run/splash
|
7
|
+
:trace_path: /var/run/splash/traces
|
5
8
|
:loggers:
|
6
9
|
:level: :info
|
7
10
|
:daemon:
|
@@ -23,6 +26,16 @@
|
|
23
26
|
# :port: 6379
|
24
27
|
# #:auth: "mykey"
|
25
28
|
# :base: 1
|
29
|
+
:transfers_trace:
|
30
|
+
:type: :file
|
31
|
+
:path: /var/run/splash/transfers
|
32
|
+
:logs_trace:
|
33
|
+
:type: :file
|
34
|
+
:path: /var/run/splash/logs
|
35
|
+
:process_trace:
|
36
|
+
:type: :file
|
37
|
+
:path: /var/run/splash/process
|
38
|
+
|
26
39
|
:transports:
|
27
40
|
:active: :rabbitmq
|
28
41
|
:rabbitmq:
|
@@ -39,20 +52,26 @@
|
|
39
52
|
:procmon_scheduling:
|
40
53
|
:every: 20s
|
41
54
|
:process_name: "Splash : daemon."
|
42
|
-
:paths:
|
43
|
-
:pid_path: /var/run/splash
|
44
|
-
:trace_path: /var/run/splash/traces
|
45
55
|
:files:
|
46
56
|
:stdout_trace: stdout.txt
|
47
57
|
:stderr_trace: stderr.txt
|
48
58
|
:pid_file: splash.pid
|
49
59
|
:prometheus:
|
50
|
-
:pushgateway:
|
51
|
-
|
52
|
-
|
60
|
+
:pushgateway: 'http://localhost:9091'
|
61
|
+
:url: 'http://localhost:9090'
|
62
|
+
:alertmanager: 'http://localhost:9093'
|
63
|
+
:webadmin:
|
64
|
+
:port: 9234
|
65
|
+
:ip: 127.0.0.1
|
66
|
+
:proxy: false
|
67
|
+
:process_name: "Splash : WebAdmin."
|
68
|
+
:files:
|
69
|
+
:stdout_trace: stdout_webadmin.txt
|
70
|
+
:stderr_trace: stderr_webadmin.txt
|
71
|
+
:pid_file: splash_webadmin.pid
|
53
72
|
|
54
73
|
|
55
|
-
### configuration of commands and scheduling
|
74
|
+
### Sample configuration of commands and scheduling
|
56
75
|
:commands:
|
57
76
|
:id_root:
|
58
77
|
:desc: run id command on root
|
@@ -104,16 +123,96 @@
|
|
104
123
|
:on_success: :echo3
|
105
124
|
|
106
125
|
|
107
|
-
### configuration of monitored logs
|
126
|
+
### Sample configuration of monitored logs
|
108
127
|
:logs:
|
109
|
-
- :
|
128
|
+
- :label: :log_app_1
|
129
|
+
:log: /tmp/test
|
110
130
|
:pattern: ERROR
|
111
|
-
|
131
|
+
:retention:
|
132
|
+
:hours: 5
|
133
|
+
- :label: :log_app_2
|
134
|
+
:log: /tmp/test2
|
112
135
|
:pattern: ERROR
|
113
|
-
|
136
|
+
:retention:
|
137
|
+
:hours: 5
|
114
138
|
|
115
139
|
### configuration of monitored processes
|
116
140
|
:processes:
|
117
141
|
- :process: cron
|
118
142
|
:patterns:
|
119
143
|
- cron
|
144
|
+
:retention:
|
145
|
+
:hours: 5
|
146
|
+
|
147
|
+
|
148
|
+
###
|
149
|
+
## Sample configuration of executions sequences
|
150
|
+
:sequences:
|
151
|
+
:sample_remote_sequence:
|
152
|
+
:definition:
|
153
|
+
- :step: execute echo2 on omicron
|
154
|
+
:command: :echo2
|
155
|
+
:on_host: omicron
|
156
|
+
- :step: run locally echo3
|
157
|
+
:command: :echo3
|
158
|
+
:trace: false
|
159
|
+
:sample_local_sequence:
|
160
|
+
:definition:
|
161
|
+
- :step: run locally pwd without callback
|
162
|
+
:command: :pwd
|
163
|
+
:callback: false
|
164
|
+
- :step: run locally echo3 without Prometheus notifications
|
165
|
+
:command: :echo3
|
166
|
+
:notify: false
|
167
|
+
:sample_local_failed_sequence:
|
168
|
+
:options:
|
169
|
+
:continue: false
|
170
|
+
:definition:
|
171
|
+
- :step: run false_test locally without callback
|
172
|
+
:command: :false_test
|
173
|
+
:callback: false
|
174
|
+
- :step: considere this as inefective
|
175
|
+
:command: :echo3
|
176
|
+
:sample_local_full_sequence:
|
177
|
+
:options:
|
178
|
+
:continue: true
|
179
|
+
:definition:
|
180
|
+
- :step: run false_test locally without callback
|
181
|
+
:command: :false_test
|
182
|
+
:callback: false
|
183
|
+
:trace: false
|
184
|
+
- :step: considere this as inefective
|
185
|
+
:command: :pwd
|
186
|
+
:sample_scheduled_sequence:
|
187
|
+
:schedule:
|
188
|
+
:every: 1m
|
189
|
+
:options:
|
190
|
+
:continue: true
|
191
|
+
:definition:
|
192
|
+
- :step: exec echo3
|
193
|
+
:command: :echo3
|
194
|
+
|
195
|
+
### Transfers
|
196
|
+
:transfers:
|
197
|
+
- :name: :transfer_text
|
198
|
+
:desc: "List of text files"
|
199
|
+
:pattern: '*.txt'
|
200
|
+
:backup: true
|
201
|
+
:type: :push
|
202
|
+
:retention:
|
203
|
+
:hours: 1
|
204
|
+
:local:
|
205
|
+
:path: /tmp/transferts
|
206
|
+
:user: root
|
207
|
+
:remote:
|
208
|
+
:user: root
|
209
|
+
:host: localhost
|
210
|
+
:path: /tmp/
|
211
|
+
:post:
|
212
|
+
:remote_command: 'ls'
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
###
|
data/lib/splash/backends.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/backends/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
# base Splash Module
|
4
5
|
module Splash
|
6
|
+
|
7
|
+
# generic backends module
|
5
8
|
module Backends
|
6
9
|
include Splash::Config
|
7
10
|
include Splash::Constants
|
8
11
|
|
12
|
+
# factory for backend
|
13
|
+
# @param [Symbol] store the name of the store actually in [:execution_trace]
|
14
|
+
# @return [Splash::Backends::<Type>|Hash] with type in [:redis,:file] or Exiter case :configuration_error
|
9
15
|
def get_backend(store)
|
16
|
+
splash_exit case: :configuration_error, more: "backend definition failure" if get_config[:backends][:stores][store].nil?
|
10
17
|
backend = get_config[:backends][:stores][store][:type].to_s
|
11
18
|
aclass = "Splash::Backends::#{backend.capitalize}"
|
12
19
|
begin
|
data/lib/splash/backends/file.rb
CHANGED
@@ -1,50 +1,86 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash Module
|
2
4
|
module Splash
|
5
|
+
# generic backends module
|
3
6
|
module Backends
|
7
|
+
|
8
|
+
# File backend definition
|
4
9
|
class File
|
5
10
|
include Splash::Config
|
6
11
|
include Splash::Exiter
|
7
12
|
include Splash::Helpers
|
8
13
|
include Splash::Loggers
|
9
14
|
|
15
|
+
# Constructor
|
16
|
+
# @param [Symbol] store name in [:execution_trace] actually (see config and constants )
|
17
|
+
# @return [Splash::Backends::File] a File backend
|
10
18
|
def initialize(store)
|
11
19
|
@config = get_config[:backends][:stores][store]
|
12
20
|
@path = @config[:path]
|
13
21
|
ensure_backend
|
14
22
|
end
|
15
23
|
|
24
|
+
# return the list of find records in backend for a specific pattern
|
25
|
+
# @param [String] pattern shell regexp
|
26
|
+
# @return [Array] list of record
|
16
27
|
def list(pattern='*')
|
17
28
|
pattern = suffix_trace(pattern)
|
18
29
|
return Dir.glob("#{@path}/#{pattern}").map{|item| ::File.basename(item,".trace") }
|
19
30
|
end
|
20
31
|
|
32
|
+
|
33
|
+
# return value of queried record
|
34
|
+
# @param [Hash] options
|
35
|
+
# @option options [Symbol] :key the name of the record
|
36
|
+
# @return [String] content value of record
|
21
37
|
def get(options)
|
22
38
|
return ::File.readlines("#{@path}/#{suffix_trace(options[:key])}").join
|
23
39
|
end
|
24
40
|
|
41
|
+
# defined and store value for specified key
|
42
|
+
# @param [Hash] options
|
43
|
+
# @option options [Symbol] :key the name of the record
|
44
|
+
# @option options [Symbol] :value the content value of the record
|
45
|
+
# @return [String] content value of record
|
25
46
|
def put(options)
|
26
47
|
::File.open("#{@path}/#{suffix_trace(options[:key])}", 'w') { |file|
|
27
48
|
file.write options[:value]
|
28
49
|
}
|
29
50
|
end
|
30
51
|
|
52
|
+
# delete a specific record
|
53
|
+
# @param [Hash] options
|
54
|
+
# @option options [Symbol] :key the name of the record
|
55
|
+
# @return [Boolean] status of the operation
|
31
56
|
def del(options)
|
32
57
|
::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
33
58
|
end
|
34
59
|
|
60
|
+
# verifiy a specific record existance
|
61
|
+
# @param [Hash] options
|
62
|
+
# @option options [Symbol] :key the name of the record
|
63
|
+
# @return [Boolean] presence of the record
|
35
64
|
def exist?(options)
|
36
65
|
return ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
|
37
66
|
end
|
38
67
|
|
68
|
+
# flush all records in backend
|
39
69
|
def flush
|
40
70
|
Dir.glob("#{@path}/*.trace").each { |file| ::File.delete(file)}
|
41
71
|
end
|
42
72
|
|
43
73
|
private
|
74
|
+
|
75
|
+
# File backend specific method for suffixing record name with .trace for filename
|
76
|
+
# @param [String] astring
|
77
|
+
# @return [String] suffixed string
|
44
78
|
def suffix_trace(astring)
|
45
79
|
return "#{astring}.trace"
|
46
80
|
end
|
47
81
|
|
82
|
+
# File backend specific method to test backend, correcting if requiered, spool path checking
|
83
|
+
# @return [True|Hash] Exiter case :configuration_error if failing to correct backend
|
48
84
|
def ensure_backend
|
49
85
|
unless verify_folder(name: @config[:path], mode: "644", owner: get_config.user_root, group: get_config.group_root).empty? then
|
50
86
|
get_logger.warn "File Backend folder : #{@config[:path]} is missing"
|