Skip to content

Commit

Permalink
chore: decide what to archive and what to transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardacoppo committed Dec 6, 2024
1 parent c101f33 commit be62e5a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
74 changes: 40 additions & 34 deletions lib/syskit/cli/log_runtime_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/syskit/cli/log_runtime_archive_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit be62e5a

Please sign in to comment.