prometheus-splash 0.5.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +58 -60
- data/bin/splash +3 -0
- data/config/splash.yml +106 -10
- 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 +16 -4
- data/lib/splash/cli/commands.rb +12 -5
- 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 +21 -13
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/transfers.rb +206 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +26 -4
- data/lib/splash/config.rb +184 -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 +41 -10
- data/lib/splash/daemon.rb +5 -1
- data/lib/splash/daemon/controller.rb +31 -11
- data/lib/splash/daemon/metrics.rb +47 -22
- data/lib/splash/daemon/orchestrator.rb +141 -36
- data/lib/splash/daemon/orchestrator/grammar.rb +40 -5
- data/lib/splash/daemon/orchestrator/hooks.rb +10 -0
- data/lib/splash/dependencies.rb +19 -0
- data/lib/splash/exiter.rb +14 -0
- data/lib/splash/helpers.rb +93 -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 +16 -5
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transfers.rb +224 -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 +12 -3
- data/spec/helpers_spec.rb +119 -0
- metadata +196 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8cc49d7a0a733b08a9f744a2ac14b5196b69fc229fcd77c9c635dd9e6c61e8
|
4
|
+
data.tar.gz: c839f4d20b88880a458e92de5b2d10f7d58788645fb7b03c0c8e63d403f5ec78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d1314705d22d1da16a62b265c0a9967b3fa2cd049db1dd25af3631b144b7872da48a84d1c62d36cc9fa650cb398ab4beaba9523d46f79bde52f3b6382b586e3
|
7
|
+
data.tar.gz: d8d637a2ea309860d988952f87c63b906c1b4c350dfa5327f12f84ddc0cd352c3ca4b7112ac2f180b890d2acc3553db2caaa0abda3fc1a77a0eccf88d6c44f85
|
data/CHANGELOG.md
CHANGED
@@ -112,3 +112,41 @@
|
|
112
112
|
* Ansible Splash role logrotate copytruncate for splash logs
|
113
113
|
* Prometheus Registry mismatch=> cumulative metrics on each groups #42
|
114
114
|
* logger Dual level conservation #43
|
115
|
+
|
116
|
+
## V 0.5.2 2020/04/18
|
117
|
+
|
118
|
+
### FIX
|
119
|
+
|
120
|
+
* dual logger daemon shutdown foreground error
|
121
|
+
|
122
|
+
## V 0.5.3 2020/04/18
|
123
|
+
|
124
|
+
### FEATURE
|
125
|
+
|
126
|
+
* processes monitoring #23
|
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
|
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.0
|
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,10 @@
|
|
23
26
|
# :port: 6379
|
24
27
|
# #:auth: "mykey"
|
25
28
|
# :base: 1
|
29
|
+
:transferts_trace:
|
30
|
+
:type: :file
|
31
|
+
:path: /var/run/splash/transferts
|
32
|
+
|
26
33
|
:transports:
|
27
34
|
:active: :rabbitmq
|
28
35
|
:rabbitmq:
|
@@ -35,22 +42,30 @@
|
|
35
42
|
:logmon_scheduling:
|
36
43
|
:every: 20s
|
37
44
|
:metrics_scheduling:
|
45
|
+
:every: 15s
|
46
|
+
:procmon_scheduling:
|
38
47
|
:every: 20s
|
39
48
|
:process_name: "Splash : daemon."
|
40
|
-
:paths:
|
41
|
-
:pid_path: /var/run/splash
|
42
|
-
:trace_path: /var/run/splash/traces
|
43
49
|
:files:
|
44
50
|
:stdout_trace: stdout.txt
|
45
51
|
:stderr_trace: stderr.txt
|
46
52
|
:pid_file: splash.pid
|
47
53
|
:prometheus:
|
48
|
-
:pushgateway:
|
49
|
-
|
50
|
-
|
54
|
+
:pushgateway: 'http://localhost:9091'
|
55
|
+
:url: 'http://localhost:9090'
|
56
|
+
:alertmanager: 'http://localhost:9093'
|
57
|
+
:webadmin:
|
58
|
+
:port: 9234
|
59
|
+
:ip: 127.0.0.1
|
60
|
+
:proxy: false
|
61
|
+
:process_name: "Splash : WebAdmin."
|
62
|
+
:files:
|
63
|
+
:stdout_trace: stdout_webadmin.txt
|
64
|
+
:stderr_trace: stderr_webadmin.txt
|
65
|
+
:pid_file: splash_webadmin.pid
|
51
66
|
|
52
67
|
|
53
|
-
### configuration of commands and scheduling
|
68
|
+
### Sample configuration of commands and scheduling
|
54
69
|
:commands:
|
55
70
|
:id_root:
|
56
71
|
:desc: run id command on root
|
@@ -102,9 +117,90 @@
|
|
102
117
|
:on_success: :echo3
|
103
118
|
|
104
119
|
|
105
|
-
### configuration of monitored logs
|
120
|
+
### Sample configuration of monitored logs
|
106
121
|
:logs:
|
107
|
-
- :
|
122
|
+
- :label: :log_app_1
|
123
|
+
:log: /tmp/test
|
108
124
|
:pattern: ERROR
|
109
|
-
- :
|
125
|
+
- :label: :log_app_2
|
126
|
+
:log: /tmp/test2
|
110
127
|
:pattern: ERROR
|
128
|
+
|
129
|
+
### configuration of monitored processes
|
130
|
+
:processes:
|
131
|
+
- :process: cron
|
132
|
+
:patterns:
|
133
|
+
- cron
|
134
|
+
|
135
|
+
|
136
|
+
###
|
137
|
+
## Sample configuration of executions sequences
|
138
|
+
:sequences:
|
139
|
+
:sample_remote_sequence:
|
140
|
+
:definition:
|
141
|
+
- :step: execute echo2 on omicron
|
142
|
+
:command: :echo2
|
143
|
+
:on_host: omicron
|
144
|
+
- :step: run locally echo3
|
145
|
+
:command: :echo3
|
146
|
+
:trace: false
|
147
|
+
:sample_local_sequence:
|
148
|
+
:definition:
|
149
|
+
- :step: run locally pwd without callback
|
150
|
+
:command: :pwd
|
151
|
+
:callback: false
|
152
|
+
- :step: run locally echo3 without Prometheus notifications
|
153
|
+
:command: :echo3
|
154
|
+
:notify: false
|
155
|
+
:sample_local_failed_sequence:
|
156
|
+
:options:
|
157
|
+
:continue: false
|
158
|
+
:definition:
|
159
|
+
- :step: run false_test locally without callback
|
160
|
+
:command: :false_test
|
161
|
+
:callback: false
|
162
|
+
- :step: considere this as inefective
|
163
|
+
:command: :echo3
|
164
|
+
:sample_local_full_sequence:
|
165
|
+
:options:
|
166
|
+
:continue: true
|
167
|
+
:definition:
|
168
|
+
- :step: run false_test locally without callback
|
169
|
+
:command: :false_test
|
170
|
+
:callback: false
|
171
|
+
:trace: false
|
172
|
+
- :step: considere this as inefective
|
173
|
+
:command: :pwd
|
174
|
+
:sample_scheduled_sequence:
|
175
|
+
:schedule:
|
176
|
+
:every: 1m
|
177
|
+
:options:
|
178
|
+
:continue: true
|
179
|
+
:definition:
|
180
|
+
- :step: exec echo3
|
181
|
+
:command: :echo3
|
182
|
+
|
183
|
+
### Transfers
|
184
|
+
:transfers:
|
185
|
+
- :name: :transfer_text
|
186
|
+
:desc: "List of text files"
|
187
|
+
:pattern: '*.txt'
|
188
|
+
:backup: true
|
189
|
+
:type: :push
|
190
|
+
:retention:
|
191
|
+
:hours: 1
|
192
|
+
:local:
|
193
|
+
:path: /tmp/transferts
|
194
|
+
:user: root
|
195
|
+
:remote:
|
196
|
+
:user: root
|
197
|
+
:host: localhost
|
198
|
+
:path: /tmp/
|
199
|
+
:post:
|
200
|
+
:remote_command: 'ls'
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
###
|
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"
|