diff --git a/lib/syskit/cli/log_runtime_archive.rb b/lib/syskit/cli/log_runtime_archive.rb index 6ba025189..69cf4d8ca 100644 --- a/lib/syskit/cli/log_runtime_archive.rb +++ b/lib/syskit/cli/log_runtime_archive.rb @@ -40,30 +40,25 @@ def initialize( # archived datasets def process_root_folder candidates = self.class.find_all_dataset_folders(@root_dir) - running = candidates.last - candidates.each do |child| - process_dataset(child, full: child != running) + archive = processing_candidates(candidates) + running = archive.last + archive.each do |child| + process_archiving(child, full: child != running) end end - # Transfer logs from a process server to the main computer server + # Creates a TCP socket and decide which logs to transfer # # @param [Pathname] src_dir the log folder on the process server # @param [Params] server_params the FTP server parameters: # { host, port, certificate, user, password } - def process_transfer(src_dir, server_params) - host = server_params[:host] - port = server_params[:port] - socket = - begin TCPSocket.new(host, port) - rescue Errno::ECONNREFUSED => e - raise e.class, "cannot contact process server at " \ - "'#{host}:#{port}': #{e.message}" - end - socket.write(ProcessManagers::Remote::COMMAND_LOG_UPLOAD_FILE) + def process_file_transfer(src_dir, server_params) + socket = self.class.create_tcp_socket(server_params[:host], + server_params[:port]) candidates = self.class.find_all_dataset_folders(src_dir) - candidates.each do |child| + transfer = processing_candidates(candidates) + transfer.each do |child| Marshal.dump([server_params, Pathname(child)], socket) end end @@ -104,26 +99,20 @@ def ensure_free_space(free_space_low_limit, free_space_delete_until) end end - def process_dataset(child, full:) - use_existing = true - loop do - open_archive_for( - child.basename.to_s, use_existing: use_existing - ) do |io| - if io.tell > @max_archive_size - use_existing = false - break - end - - dataset_complete = self.class.archive_dataset( - io, child, - logger: @logger, full: full, - max_size: @max_archive_size - ) - return if dataset_complete - end + def processing_candidates(candidates) + candidates.select do |child| + self.class.enough_space?(child, @max_archive_size) + end + end - use_existing = false + def process_archiving(child, full:) + open_archive_for(child.basename.to_s) do |io| + dataset_complete = self.class.archive_dataset( + io, child, + logger: @logger, full: full, + max_size: @max_archive_size + ) + return if dataset_complete end end @@ -170,6 +159,23 @@ def find_last_archive_index(basename) end end + def self.create_tcp_socket(host, port) + socket = + begin TCPSocket.new(host, port) + rescue Errno::ECONNREFUSED => e + raise e.class, "cannot contact process server at " \ + "'#{host}:#{port}': #{e.message}" + end + socket.write(ProcessManagers::Remote::COMMAND_LOG_UPLOAD_FILE) + socket + end + + def self.enough_space?(child, max_archive_size) + open_archive_for(child.basename.to_s) do |io| + io.tell < max_archive_size + end + end + # Find all dataset-looking folders within a root log folder def self.find_all_dataset_folders(root_dir) candidates = root_dir.enum_for(:each_entry).map do |child| diff --git a/lib/syskit/cli/log_runtime_archive_main.rb b/lib/syskit/cli/log_runtime_archive_main.rb index 84fa4a49d..1e272523b 100644 --- a/lib/syskit/cli/log_runtime_archive_main.rb +++ b/lib/syskit/cli/log_runtime_archive_main.rb @@ -88,7 +88,7 @@ def transfer(src_dir, tgt_dir, server_params) tgt_dir = validate_directory_exists(tgt_dir) archiver = make_archiver(src_dir, tgt_dir) - archiver.process_transfer(src_dir, server_params) + archiver.process_file_transfer(src_dir, server_params) end desc "transfer_server", "creates the log transfer FTP server \