liri 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -2
- data/.simplecov +8 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +27 -15
- data/bash_script_examples.sh +1 -0
- data/dummy-app/.gitignore +12 -0
- data/dummy-app/.rspec +3 -0
- data/dummy-app/.ruby-gemset +1 -0
- data/dummy-app/.ruby-version +1 -0
- data/dummy-app/CODE_OF_CONDUCT.md +84 -0
- data/dummy-app/Gemfile +10 -0
- data/dummy-app/Gemfile.lock +35 -0
- data/dummy-app/LICENSE.txt +21 -0
- data/dummy-app/README.md +43 -0
- data/dummy-app/Rakefile +8 -0
- data/dummy-app/bin/console +15 -0
- data/dummy-app/bin/setup +8 -0
- data/dummy-app/dummy-app.gemspec +39 -0
- data/dummy-app/lib/dummy/app/version.rb +7 -0
- data/dummy-app/lib/dummy/app.rb +10 -0
- data/dummy-app/spec/dummy/app_spec.rb +11 -0
- data/dummy-app/spec/spec_helper.rb +15 -0
- data/exe/liri +9 -4
- data/lib/agent/agent.rb +90 -50
- data/lib/agent/runner.rb +1 -3
- data/lib/all_libraries.rb +4 -2
- data/lib/common/benchmarking.rb +5 -10
- data/lib/common/log.rb +12 -6
- data/lib/common/manager_data.rb +30 -0
- data/lib/common/progressbar.rb +29 -0
- data/lib/common/setup.rb +103 -0
- data/lib/common/source_code.rb +22 -12
- data/lib/common/tests_result.rb +115 -0
- data/lib/common/unit_test/rspec.rb +15 -23
- data/lib/liri.rb +22 -35
- data/lib/manager/manager.rb +163 -98
- data/lib/task.rb +2 -2
- data/liri.gemspec +8 -0
- data/spec_credentials.yml.example +4 -0
- data/template/liri-config.yml +4 -2
- metadata +54 -4
- data/lib/manager/setup.rb +0 -70
- data/lib/manager/test_result.rb +0 -38
data/lib/agent/agent.rb
CHANGED
@@ -11,16 +11,19 @@ module Liri
|
|
11
11
|
class << self
|
12
12
|
# Inicia la ejecución del Agent
|
13
13
|
# @param stop [Boolean] el valor true es para que no se ejecute infinitamente el método en el test unitario.
|
14
|
-
def run(stop = false)
|
15
|
-
Liri.
|
14
|
+
def run(work_folder_path, stop = false)
|
15
|
+
setup_manager = Liri.set_setup(work_folder_path)
|
16
|
+
agent_folder_path = setup_manager.agent_folder_path
|
16
17
|
|
17
|
-
Liri.set_logger(
|
18
|
+
Liri.set_logger(setup_manager.logs_folder_path, 'liri-agent.log')
|
18
19
|
Liri.logger.info("Proceso Agent iniciado")
|
19
|
-
|
20
|
+
Liri.logger.info("Presione Ctrl + c para terminar el proceso Agent manualmente\n", true)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
decompressed_source_code_path = File.join(agent_folder_path, '/', Common::SourceCode::DECOMPRESSED_FOLDER_NAME)
|
23
|
+
source_code = Common::SourceCode.new(decompressed_source_code_path, agent_folder_path, Liri.compression_class, Liri.unit_test_class)
|
24
|
+
runner = Agent::Runner.new(Liri.unit_test_class, source_code.decompressed_file_folder_path)
|
25
|
+
tests_result = Common::TestsResult.new(agent_folder_path)
|
26
|
+
agent = Agent.new(Liri.udp_port, Liri.tcp_port, source_code, runner, tests_result, agent_folder_path)
|
24
27
|
threads = []
|
25
28
|
threads << agent.start_server_socket_to_process_manager_connection_request # Esperar y procesar la petición de conexión del Manager
|
26
29
|
|
@@ -32,15 +35,20 @@ module Liri
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
def initialize(udp_port, tcp_port, source_code, runner)
|
38
|
+
def initialize(udp_port, tcp_port, source_code, runner, tests_result, agent_folder_path)
|
36
39
|
@udp_port = udp_port
|
37
40
|
@udp_socket = UDPSocket.new
|
38
41
|
@tcp_port = tcp_port
|
39
42
|
|
40
43
|
@source_code = source_code
|
41
44
|
@runner = runner
|
45
|
+
@tests_result = tests_result
|
46
|
+
|
47
|
+
@all_tests = {}
|
42
48
|
|
43
49
|
@managers = {}
|
50
|
+
|
51
|
+
@agent_folder_path = agent_folder_path
|
44
52
|
end
|
45
53
|
|
46
54
|
# Inicia un servidor udp que se mantiene en espera de la primera petición de conexión del Manager
|
@@ -62,48 +70,51 @@ module Liri
|
|
62
70
|
loop do
|
63
71
|
@manager_request = @udp_socket.recvfrom(1024)
|
64
72
|
manager_ip_address = @manager_request.last.last
|
65
|
-
|
66
|
-
process_manager_connection_request(manager_ip_address,
|
73
|
+
manager_data = get_manager_data(JSON.parse(@manager_request.first))
|
74
|
+
process_manager_connection_request(manager_ip_address, manager_data)
|
67
75
|
end
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
71
79
|
# Inicia un cliente tcp para responder a la petición broadcast del Manager para que éste sepa donde enviar las pruebas
|
72
|
-
def start_client_socket_to_process_tests(manager_ip_address)
|
80
|
+
def start_client_socket_to_process_tests(manager_ip_address, manager_data)
|
73
81
|
tcp_socket = TCPSocket.open(manager_ip_address, @tcp_port)
|
74
82
|
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
agent_ip_address = tcp_socket.addr[2]
|
84
|
+
|
85
|
+
tcp_socket.puts({ msg: 'Listo' }) # Se envía un mensaje inicial al Manager
|
86
|
+
|
87
|
+
Liri.logger.info("Se inicia una conexión para procesar pruebas con el Manager: #{manager_ip_address} en el puerto TCP: #{@tcp_port}")
|
88
|
+
Liri.logger.info("\nConexión iniciada con el Manager: #{manager_ip_address}", true)
|
89
|
+
|
90
|
+
response = JSON.parse(tcp_socket.gets)
|
91
|
+
return unless response['exist_tests']
|
78
92
|
|
79
|
-
|
80
|
-
puts "\nConexión iniciada con el Manager: #{manager_ip_address}"
|
93
|
+
get_source_code(manager_ip_address, manager_data)
|
81
94
|
|
82
|
-
# Se procesan las pruebas
|
95
|
+
# Se procesan las pruebas enviadas por el Manager
|
83
96
|
while line = tcp_socket.gets
|
84
97
|
response = line.chop
|
85
98
|
break if response == 'exit'
|
86
99
|
|
87
|
-
|
88
|
-
|
89
|
-
Liri.logger.debug(tests)
|
100
|
+
tests_batch = JSON.parse(response)
|
101
|
+
tests = get_tests(tests_batch, manager_ip_address)
|
90
102
|
|
91
|
-
|
103
|
+
raw_tests_result = @runner.run_tests(tests)
|
92
104
|
|
93
|
-
|
94
|
-
|
95
|
-
|
105
|
+
tests_batch_number = tests_batch['tests_batch_number']
|
106
|
+
tests_result_file_name = @tests_result.build_file_name(agent_ip_address, tests_batch_number)
|
107
|
+
tests_result_file_path = @tests_result.save(tests_result_file_name, raw_tests_result)
|
96
108
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
tcp_socket.print(json_tests_result) # Este no logra enviar toda la información, porque? en cambio el cliente recibe un json grande sin problemas
|
109
|
+
send_tests_results_file(manager_ip_address, manager_data, tests_result_file_path)
|
110
|
+
result = { tests_batch_number: tests_batch_number, tests_result_file_name: tests_result_file_name, tests_batch_keys_size: tests_batch['tests_batch_keys'].size}
|
111
|
+
tcp_socket.puts(result.to_json) # Envía el número de lote y el nombre del archivo de resultados.
|
101
112
|
end
|
102
113
|
|
103
114
|
tcp_socket.close
|
104
|
-
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address}")
|
115
|
+
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address} en el puerto TCP: #{@tcp_port}")
|
105
116
|
|
106
|
-
Liri.
|
117
|
+
Liri.clean_folder_content(@agent_folder_path)
|
107
118
|
|
108
119
|
start_client_to_close_manager_server(manager_ip_address, 'Conexión Terminada')
|
109
120
|
unregister_manager(manager_ip_address)
|
@@ -112,11 +123,11 @@ module Liri
|
|
112
123
|
rescue Errno::ECONNRESET => e
|
113
124
|
tcp_socket.close
|
114
125
|
Liri.logger.error("Exception(#{e}) Conexión cerrada en el puerto TCP #{@tcp_port}")
|
115
|
-
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address}")
|
126
|
+
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address} en el puerto TCP: #{@tcp_port}")
|
116
127
|
unregister_manager(manager_ip_address)
|
117
128
|
rescue Errno::ECONNREFUSED => e
|
118
129
|
Liri.logger.error("Exception(#{e}) Conexión rechazada en el puerto TCP #{@tcp_port}")
|
119
|
-
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address}")
|
130
|
+
Liri.logger.info("Se termina la conexión con el Manager #{manager_ip_address} en el puerto TCP: #{@tcp_port}")
|
120
131
|
unregister_manager(manager_ip_address)
|
121
132
|
end
|
122
133
|
|
@@ -125,15 +136,15 @@ module Liri
|
|
125
136
|
# Inserta el ip recibido dentro del hash si es que ya no existe en el hash
|
126
137
|
# Nota: Se requieren imprimir datos para saber el estado de la aplicación, sería muy útil usar algo para logear
|
127
138
|
# estas cosas en los diferentes niveles, debug, info, etc.
|
128
|
-
def process_manager_connection_request(manager_ip_address,
|
139
|
+
def process_manager_connection_request(manager_ip_address, manager_data)
|
129
140
|
unless registered_manager?(manager_ip_address)
|
130
141
|
register_manager(manager_ip_address)
|
131
142
|
Liri.logger.info("Petición broadcast UDP recibida del Manager: #{manager_ip_address} en el puerto UDP: #{@udp_port}")
|
132
|
-
if
|
133
|
-
start_client_socket_to_process_tests(manager_ip_address)
|
134
|
-
else
|
135
|
-
unregister_manager(manager_ip_address)
|
136
|
-
end
|
143
|
+
#if get_source_code(manager_ip_address, manager_data)
|
144
|
+
start_client_socket_to_process_tests(manager_ip_address, manager_data)
|
145
|
+
#else
|
146
|
+
#unregister_manager(manager_ip_address)
|
147
|
+
#end
|
137
148
|
end
|
138
149
|
end
|
139
150
|
|
@@ -141,27 +152,28 @@ module Liri
|
|
141
152
|
# Esta conexión permitirá al Manager cerrar sus hilos pendientes con servidores TCP en espera y terminar el proceso
|
142
153
|
def start_client_to_close_manager_server(manager_ip_address, msg)
|
143
154
|
tcp_socket = TCPSocket.open(manager_ip_address, @tcp_port)
|
144
|
-
Liri.logger.info("Se termina cualquier proceso pendiente con el Manager #{manager_ip_address}")
|
145
|
-
tcp_socket.print({msg: msg}.to_json)
|
155
|
+
Liri.logger.info("Se termina cualquier proceso pendiente con el Manager #{manager_ip_address} en el puerto TCP: #{@tcp_port}")
|
156
|
+
tcp_socket.print({ msg: msg }.to_json)
|
146
157
|
tcp_socket.close
|
147
158
|
end
|
148
159
|
|
149
|
-
def
|
150
|
-
#
|
160
|
+
def get_source_code(manager_ip_address, manager_data)
|
161
|
+
#puts "#{manager_data.to_h}"
|
151
162
|
puts ''
|
152
|
-
Liri::Common::Benchmarking.start(start_msg: "Obteniendo código fuente. Espere... ") do
|
163
|
+
Liri::Common::Benchmarking.start(start_msg: "Obteniendo código fuente. Espere... ", stdout: true) do
|
153
164
|
puts ''
|
154
|
-
Net::SCP.start(manager_ip_address, user, :
|
155
|
-
scp.download!(
|
165
|
+
Net::SCP.start(manager_ip_address, manager_data.user, password: manager_data.password) do |scp|
|
166
|
+
scp.download!(manager_data.compressed_file_path, @source_code.compressed_file_folder_path)
|
156
167
|
end
|
157
168
|
end
|
158
169
|
puts ''
|
159
170
|
|
160
|
-
downloaded_file_name =
|
171
|
+
downloaded_file_name = manager_data.compressed_file_path.split('/').last
|
161
172
|
downloaded_file_path = File.join(@source_code.compressed_file_folder_path, '/', downloaded_file_name)
|
162
173
|
|
163
|
-
Liri::Common::Benchmarking.start(start_msg: "Descomprimiendo código fuente. Espere... ") do
|
174
|
+
Liri::Common::Benchmarking.start(start_msg: "Descomprimiendo código fuente. Espere... ", stdout: true) do
|
164
175
|
@source_code.decompress_file(downloaded_file_path)
|
176
|
+
@all_tests = @source_code.all_tests
|
165
177
|
end
|
166
178
|
puts ''
|
167
179
|
|
@@ -180,19 +192,19 @@ module Liri
|
|
180
192
|
# Se setea la versión de ruby y el gemset para el código fuente descomprimido
|
181
193
|
# Se especifica el Gemfile del cual se van a instalar los requerimientos
|
182
194
|
# Esto se hace porque por defecto se usa la versión de Ruby de Liri y su Gemset y por ello hay que cambiarlos explicitamente aquí
|
183
|
-
Liri::Common::Benchmarking.start(start_msg: "Ejecutando bundle install. Espere... ", end_msg: "Ejecución de bundle install. Duración: ") do
|
195
|
+
Liri::Common::Benchmarking.start(start_msg: "Ejecutando bundle install. Espere... ", end_msg: "Ejecución de bundle install. Duración: ", stdout: true) do
|
184
196
|
puts ''
|
185
197
|
system("bash -lc 'rvm use #{Liri.current_folder_ruby_and_gemset}; BUNDLE_GEMFILE=Gemfile bundle install'")
|
186
198
|
end
|
187
199
|
puts ''
|
188
200
|
|
189
|
-
Liri::Common::Benchmarking.start(start_msg: "Ejecutando rake db:migrate RAILS_ENV=test. Espere... ", end_msg: "Ejecución de rake db:migrate RAILS_ENV=test. Duración: ") do
|
201
|
+
Liri::Common::Benchmarking.start(start_msg: "Ejecutando rake db:migrate RAILS_ENV=test. Espere... ", end_msg: "Ejecución de rake db:migrate RAILS_ENV=test. Duración: ", stdout: true) do
|
190
202
|
puts ''
|
191
203
|
system("bash -lc 'rvm use #{Liri.current_folder_ruby_and_gemset}; rake db:migrate RAILS_ENV=test'")
|
192
204
|
end
|
193
205
|
puts ''
|
194
206
|
|
195
|
-
#Liri::Common::Benchmarking.start(start_msg: "Ejecutando rake db:migrate:reset RAILS_ENV=test. Espere... ", end_msg: "Ejecución de rake db:migrate:reset RAILS_ENV=test. Duración: ") do
|
207
|
+
#Liri::Common::Benchmarking.start(start_msg: "Ejecutando rake db:migrate:reset RAILS_ENV=test. Espere... ", end_msg: "Ejecución de rake db:migrate:reset RAILS_ENV=test. Duración: ", stdout: true) do
|
196
208
|
# puts ''
|
197
209
|
# system("bash -lc 'rvm use #{Liri.current_folder_ruby_and_gemset}; rake db:migrate:reset RAILS_ENV=test'")
|
198
210
|
#end
|
@@ -220,6 +232,34 @@ module Liri
|
|
220
232
|
false
|
221
233
|
end
|
222
234
|
|
235
|
+
def get_manager_data(manager_data_hash)
|
236
|
+
Common::ManagerData.new(
|
237
|
+
folder_path: manager_data_hash['folder_path'],
|
238
|
+
compressed_file_path: manager_data_hash['compressed_file_path'],
|
239
|
+
user: manager_data_hash['user'],
|
240
|
+
password: manager_data_hash['password']
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
def send_tests_results_file(manager_ip_address, manager_data, tests_result_file_path)
|
245
|
+
puts ''
|
246
|
+
Liri::Common::Benchmarking.start(start_msg: "Enviando archivo de resultados. Espere... ", stdout: true) do
|
247
|
+
Net::SCP.start(manager_ip_address, manager_data.user, password: manager_data.password) do |scp|
|
248
|
+
scp.upload!(tests_result_file_path, manager_data.folder_path)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
puts ''
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_tests(tests_batch, manager_ip_address)
|
255
|
+
# Se convierte "[5, 9, 13, 1]" a un arreglo [5, 9, 13, 1]
|
256
|
+
tests_keys = tests_batch['tests_batch_keys']
|
257
|
+
Liri.logger.debug("Claves de pruebas recibidas del Manager #{manager_ip_address}: #{tests_keys}")
|
258
|
+
# Se buscan obtienen los tests que coincidan con las claves recibidas de @all_tests = {1=>"spec/hash_spec.rb:2", 2=>"spec/hash_spec.rb:13", 3=>"spec/hash_spec.rb:24", ..., 29=>"spec/liri_spec.rb:62"}
|
259
|
+
# Se retorna un arreglo con los tests a ejecutar ["spec/liri_spec.rb:4", "spec/hash_spec.rb:5", "spec/hash_spec.rb:59", ..., "spec/hash_spec.rb:37"]
|
260
|
+
tests_keys.map { |test_key| @all_tests[test_key] }
|
261
|
+
end
|
262
|
+
|
223
263
|
def registered_manager?(manager_ip_address)
|
224
264
|
@managers[manager_ip_address]
|
225
265
|
end
|
data/lib/agent/runner.rb
CHANGED
data/lib/all_libraries.rb
CHANGED
@@ -20,11 +20,13 @@ require 'agent/runner'
|
|
20
20
|
|
21
21
|
require 'common/benchmarking'
|
22
22
|
require 'common/log'
|
23
|
+
require 'common/manager_data'
|
24
|
+
require 'common/progressbar'
|
25
|
+
require 'common/setup'
|
23
26
|
require 'common/source_code'
|
24
27
|
require 'common/compressor/zip'
|
25
28
|
require 'common/unit_test/rspec'
|
29
|
+
require 'common/tests_result'
|
26
30
|
|
27
31
|
require 'manager/manager'
|
28
|
-
require 'manager/setup'
|
29
32
|
require 'manager/credential'
|
30
|
-
require 'manager/test_result'
|
data/lib/common/benchmarking.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# Este módulo se encarga de medir el tiempo de ejecución de algunos bloques de código
|
7
7
|
|
8
8
|
require 'benchmark'
|
9
|
-
require 'i18n' #
|
9
|
+
require 'i18n' # requerimiento de la gema to_duration
|
10
10
|
require 'to_duration'
|
11
11
|
|
12
12
|
# Se configura la ubicación del archivo de internacionalización de la gema to_duration
|
@@ -17,18 +17,13 @@ module Liri
|
|
17
17
|
module Common
|
18
18
|
module Benchmarking
|
19
19
|
class << self
|
20
|
-
def start(start_msg: nil, end_msg: 'Duración: ')
|
21
|
-
|
20
|
+
def start(start_msg: nil, end_msg: 'Duración: ', stdout: true)
|
21
|
+
Liri.logger.info(start_msg, stdout)
|
22
22
|
seconds = Benchmark.realtime do
|
23
23
|
yield
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def print_result(msg, seconds)
|
31
|
-
print "#{msg}#{seconds.to_duration}"
|
25
|
+
Liri.logger.info("#{end_msg}#{seconds.to_duration}", stdout)
|
26
|
+
seconds
|
32
27
|
end
|
33
28
|
end
|
34
29
|
end
|
data/lib/common/log.rb
CHANGED
@@ -26,32 +26,38 @@ module Liri
|
|
26
26
|
create_file_logger
|
27
27
|
end
|
28
28
|
|
29
|
-
def debug(text)
|
29
|
+
def debug(text, stdout = false)
|
30
|
+
puts(text) if stdout
|
30
31
|
@stdout_logger.debug(text) if @stdout
|
31
32
|
@file_logger.debug(text)
|
32
33
|
end
|
33
34
|
|
34
|
-
def info(text)
|
35
|
+
def info(text, stdout = false)
|
36
|
+
puts(text) if stdout
|
35
37
|
@stdout_logger.info(text) if @stdout
|
36
38
|
@file_logger.info(text)
|
37
39
|
end
|
38
40
|
|
39
|
-
def warn(text)
|
41
|
+
def warn(text, stdout = false)
|
42
|
+
puts(text) if stdout
|
40
43
|
@stdout_logger.warn(text) if @stdout
|
41
44
|
@file_logger.warn(text)
|
42
45
|
end
|
43
46
|
|
44
|
-
def error(text)
|
47
|
+
def error(text, stdout = false)
|
48
|
+
puts(text) if stdout
|
45
49
|
@stdout_logger.error(text) if @stdout
|
46
50
|
@file_logger.error(text)
|
47
51
|
end
|
48
52
|
|
49
|
-
def fatal(text)
|
53
|
+
def fatal(text, stdout = false)
|
54
|
+
puts(text) if stdout
|
50
55
|
@stdout_logger.fatal(text) if @stdout
|
51
56
|
@file_logger.fatal(text)
|
52
57
|
end
|
53
58
|
|
54
|
-
def unknown(text)
|
59
|
+
def unknown(text, stdout = false)
|
60
|
+
puts(text) if stdout
|
55
61
|
@stdout_logger.unknown(text) if @stdout
|
56
62
|
@file_logger.unknown(text)
|
57
63
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# = manager_data.rb
|
2
|
+
#
|
3
|
+
# @author Rodrigo Fernández
|
4
|
+
#
|
5
|
+
# == Clase ManagerData
|
6
|
+
|
7
|
+
module Liri
|
8
|
+
module Common
|
9
|
+
# Esta clase guarda los datos del Manager
|
10
|
+
class ManagerData
|
11
|
+
attr_accessor :folder_path, :compressed_file_path, :user, :password
|
12
|
+
|
13
|
+
def initialize(folder_path:, compressed_file_path:, user:, password:)
|
14
|
+
@folder_path = folder_path
|
15
|
+
@compressed_file_path = compressed_file_path
|
16
|
+
@user = user
|
17
|
+
@password = password
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_h
|
21
|
+
{
|
22
|
+
folder_path: @folder_path,
|
23
|
+
compressed_file_path: @compressed_file_path,
|
24
|
+
user: @user,
|
25
|
+
password: @password
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# = progressbar.rb
|
2
|
+
#
|
3
|
+
# @author Rodrigo Fernández
|
4
|
+
#
|
5
|
+
# == Módulo Progressbar
|
6
|
+
# Este módulo se encarga de mostrar una barra de progreso
|
7
|
+
|
8
|
+
require 'ruby-progressbar'
|
9
|
+
|
10
|
+
module Liri
|
11
|
+
module Common
|
12
|
+
module Progressbar
|
13
|
+
class << self
|
14
|
+
def start(params = {})
|
15
|
+
@compressing = true
|
16
|
+
progressbar = ProgressBar.create(params)
|
17
|
+
Thread.new do
|
18
|
+
while @compressing
|
19
|
+
progressbar.increment
|
20
|
+
sleep(0.1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
yield
|
24
|
+
@compressing = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/common/setup.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
=begin
|
2
|
+
Este modulo se encarga de manejar la configuración
|
3
|
+
=end
|
4
|
+
require 'yaml'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Liri
|
8
|
+
module Common
|
9
|
+
class Setup
|
10
|
+
SETUP_FOLDER_NAME = 'liri'
|
11
|
+
SETUP_FILE_NAME = 'liri-config.yml'
|
12
|
+
TEMPLATE_PATH = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'template/liri-config.yml')
|
13
|
+
LOGS_FOLDER_NAME = 'logs'
|
14
|
+
MANAGER_FOLDER_NAME = 'manager'
|
15
|
+
AGENT_FOLDER_NAME = 'agent'
|
16
|
+
|
17
|
+
attr_reader :setup_folder_path, :setup_file_path, :logs_folder_path, :manager_folder_path, :agent_folder_path
|
18
|
+
|
19
|
+
def initialize(destination_folder_path)
|
20
|
+
@setup_folder_path = File.join(destination_folder_path, '/', SETUP_FOLDER_NAME)
|
21
|
+
@setup_file_path = File.join(@setup_folder_path, '/', SETUP_FILE_NAME)
|
22
|
+
@logs_folder_path = File.join(@setup_folder_path, '/', LOGS_FOLDER_NAME)
|
23
|
+
@manager_folder_path = File.join(@setup_folder_path, '/', MANAGER_FOLDER_NAME)
|
24
|
+
@agent_folder_path = File.join(@setup_folder_path, '/', AGENT_FOLDER_NAME)
|
25
|
+
end
|
26
|
+
|
27
|
+
def init
|
28
|
+
create_folder(@setup_folder_path)
|
29
|
+
create_folder(@logs_folder_path)
|
30
|
+
create_folder(@manager_folder_path)
|
31
|
+
create_folder(@agent_folder_path)
|
32
|
+
create_setup_file
|
33
|
+
end
|
34
|
+
|
35
|
+
# Retorna los datos del archivo de configuración
|
36
|
+
def load
|
37
|
+
if File.exist?(@setup_file_path)
|
38
|
+
data = YAML.load(File.read(@setup_file_path))
|
39
|
+
JSON.parse(data.to_json, object_class: OpenStruct)
|
40
|
+
else
|
41
|
+
raise Liri::FileNotFoundError.new(@setup_file_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set(value, *keys)
|
46
|
+
data = YAML.load(File.read(@setup_file_path))
|
47
|
+
keys = keys.first
|
48
|
+
aux = data
|
49
|
+
keys.each_with_index do |key, index|
|
50
|
+
if (keys[index + 1])
|
51
|
+
aux = data[key]
|
52
|
+
else
|
53
|
+
aux[key] = value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
File.open(@setup_file_path, 'w') { |f| f.write data.to_yaml }
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_folder(folder_path)
|
60
|
+
if Dir.exist?(folder_path)
|
61
|
+
false
|
62
|
+
else
|
63
|
+
Dir.mkdir(folder_path)
|
64
|
+
Dir.exist?(folder_path) ? true : false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_setup_folder
|
69
|
+
if Dir.exist?(@setup_folder_path)
|
70
|
+
FileUtils.rm_rf(@setup_folder_path)
|
71
|
+
Dir.exist?(@setup_folder_path) ? false : true
|
72
|
+
else
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Crea un archivo de configuración en la raiz del proyecto desde un template
|
78
|
+
def create_setup_file
|
79
|
+
if File.exist?(@setup_file_path)
|
80
|
+
false
|
81
|
+
else
|
82
|
+
File.open(@setup_file_path, 'w') do |output_file|
|
83
|
+
File.foreach(TEMPLATE_PATH) do |input_line|
|
84
|
+
output_file.write(input_line)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
File.exist?(@setup_file_path) ? true : false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Borra el archivo de configuración
|
93
|
+
def delete_setup_file
|
94
|
+
if File.exist?(@setup_file_path)
|
95
|
+
File.delete(@setup_file_path)
|
96
|
+
File.exist?(@setup_file_path) ? false : true
|
97
|
+
else
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/common/source_code.rb
CHANGED
@@ -5,23 +5,23 @@
|
|
5
5
|
module Liri
|
6
6
|
module Common
|
7
7
|
class SourceCode
|
8
|
-
FOLDER_PATH = Dir.pwd
|
9
|
-
FOLDER_NAME = FOLDER_PATH.split('/').last
|
10
8
|
DECOMPRESSED_FOLDER_NAME = 'decompressed'
|
11
|
-
attr_reader :compressed_file_folder_path, :compressed_file_path, :decompressed_file_folder_path
|
9
|
+
attr_reader :folder_path, :compressed_file_folder_path, :compressed_file_path, :decompressed_file_folder_path
|
12
10
|
|
13
|
-
def initialize(compressed_file_folder_path, compression_class, unit_test_class)
|
11
|
+
def initialize(folder_path, compressed_file_folder_path, compression_class, unit_test_class)
|
12
|
+
@folder_path = folder_path
|
13
|
+
@folder_name = @folder_path.split('/').last
|
14
14
|
@compressed_file_folder_path = compressed_file_folder_path
|
15
15
|
@decompressed_file_folder_path = File.join(@compressed_file_folder_path, '/', DECOMPRESSED_FOLDER_NAME)
|
16
|
-
@compressed_file_path = File.join(@compressed_file_folder_path, '/', "#{
|
16
|
+
@compressed_file_path = File.join(@compressed_file_folder_path, '/', "#{@folder_name}.zip")
|
17
17
|
# Inicializa un compresor acorde a compression_class, la siguiente línea en realidad hace lo siguiente:
|
18
18
|
# @compressor = Liri::Common::Compressor::Zip.new(input_dir, output_file)
|
19
19
|
# compression_class en este caso es Zip pero podría ser otro si existiera la implementación, por ejemplo Rar
|
20
|
-
@compressor = Object.const_get(compression_class).new(
|
20
|
+
@compressor = Object.const_get(compression_class).new(@folder_path, @compressed_file_path)
|
21
21
|
# Inicializa un ejecutor de pruebas acorde a unit_test_class, la siguiente línea en realidad hace lo siguiente:
|
22
22
|
# @unit_test = Liri::Common::UnitTest::Rspec.new(source_code_folder_path)
|
23
23
|
# unit_test_class en este caso es Rspec pero podría ser otro si existiera la implementación, por ejemplo UnitTest
|
24
|
-
@unit_test = Object.const_get(unit_test_class).new(
|
24
|
+
@unit_test = Object.const_get(unit_test_class).new(@folder_path)
|
25
25
|
end
|
26
26
|
|
27
27
|
def compress_folder
|
@@ -29,7 +29,12 @@ module Liri
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def decompress_file(compressed_file_path = @compressed_file_path)
|
32
|
-
|
32
|
+
if File.exist?(compressed_file_path)
|
33
|
+
@compressor.decompress(compressed_file_path, @decompressed_file_folder_path)
|
34
|
+
Dir.exist?(@decompressed_file_folder_path) ? true : false
|
35
|
+
else
|
36
|
+
raise FileNotFoundError, compressed_file_path
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
def delete_compressed_file
|
@@ -41,12 +46,17 @@ module Liri
|
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
|
-
def
|
45
|
-
@
|
49
|
+
def delete_decompressed_file_folder_path
|
50
|
+
if Dir.exist?(@decompressed_file_folder_path)
|
51
|
+
FileUtils.rm_rf(@decompressed_file_folder_path)
|
52
|
+
Dir.exist?(@decompressed_file_folder_path) ? false : true
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
46
56
|
end
|
47
57
|
|
48
|
-
def
|
49
|
-
|
58
|
+
def all_tests
|
59
|
+
@unit_test.all_tests
|
50
60
|
end
|
51
61
|
end
|
52
62
|
end
|