Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
78c753e
chore: use app.log_dir
wvmcastro Sep 5, 2024
ff58314
chore: move log transfer to log_runtime_archive
eduardacoppo Dec 4, 2024
593289e
test: add tests for transfer and watch_transfer
eduardacoppo Dec 5, 2024
6739824
chore: general fixes and variable renaming
eduardacoppo Dec 6, 2024
daf2442
chore: fix rubocop offenses
eduardacoppo Dec 9, 2024
3d19f54
feat: can_deploy_all method in profile assertions
kapeps Dec 17, 2024
d0d9c60
fix: flatten and splat the actions arguments instead of creating the …
kapeps Dec 18, 2024
c321268
fix: Moving the FTPUpload to syskit/runtime/remote/server diretory
DeboraTahara Dec 18, 2024
7ff3ef1
fix: refactoring the process_dataset_transfer to use the FTPUpload
DeboraTahara Dec 18, 2024
6b0d92a
chore: avoid re-resolving a query in dynamic port bindings if the cur…
kapeps Dec 16, 2024
5bd512b
chore: Reorganize files
DeboraTahara Dec 23, 2024
a2daf26
fix: Create FTPParameters struct
DeboraTahara Dec 23, 2024
7e1f84c
fix: Change the spawn_server path required
DeboraTahara Dec 23, 2024
499e343
Merge pull request #447 from kapeps/can_deploy_all
doudou Dec 23, 2024
48a0de0
Merge pull request #446 from kapeps/dynamic_port_binding_opt
doudou Dec 26, 2024
d1f4cb6
fix: Refactor the process_root_folder_transfer
DeboraTahara Dec 26, 2024
fc4836c
fix: Reorganizing files
DeboraTahara Jan 3, 2025
fbded71
fix: Creating unit tests for FTP
DeboraTahara Jan 3, 2025
9bebe99
chore: minor fixes and rubocop fixes
eduardacoppo Jan 6, 2025
f9281aa
fix: convert data_dir to string
eduardacoppo Jan 7, 2025
62c3d8c
chore: minor fixes and changes
eduardacoppo Jan 7, 2025
f3810bc
fix: creates dataset folder(s) if it does not exist
eduardacoppo Jan 8, 2025
5ee86c3
chore: fix rubocop offenses
eduardacoppo Jan 8, 2025
d34f644
fix: rewrite and fix tests, minor fixes and cleanup
eduardacoppo Jan 8, 2025
e5ac3da
fix: re-add function and fix tests
eduardacoppo Jan 8, 2025
0ae91df
fix: add error to rescue
eduardacoppo Jan 9, 2025
01db22c
chore: rename test to make it clearer
eduardacoppo Jan 9, 2025
05b29c0
chore: add comment explaining why last log is not transfered
eduardacoppo Jan 9, 2025
d6e0a5e
chore: remove unnecessary code
eduardacoppo Jan 9, 2025
252f19a
chore: raise ArgumentError if data_dir is not convertible
eduardacoppo Jan 9, 2025
c417757
chore: fix rubocop offenses and respond_to arg
eduardacoppo Jan 9, 2025
55f31bf
fix: fix transfer_server test
eduardacoppo Jan 9, 2025
04145ba
fix: add root as optional argument
eduardacoppo Jan 10, 2025
0bf635c
chore: fix rubocop offenses
eduardacoppo Jan 10, 2025
3ced9dc
chore: rescue specific error
eduardacoppo Jan 13, 2025
31ba782
fix: specify rate in mbps and convert to bps when needed
eduardacoppo Jan 13, 2025
6095238
chore: ensure path exists before opening file
eduardacoppo Jan 13, 2025
da4102a
chore: remove unnecessary variable
eduardacoppo Jan 13, 2025
ef78abd
chore: change function name, document target_dir
eduardacoppo Jan 13, 2025
1ab11c9
Merge pull request #448 from tidewise/copy_logs
jhonasiv Jan 14, 2025
4608166
fix: pick the server returned by call_create_server instead of horrib…
doudou Jan 27, 2025
ed689b1
fix: add missing @server.join on test teardown
doudou Jan 27, 2025
1c96bbb
chore: make explicit the update of the FTP server port in tests
doudou Jan 27, 2025
c987d46
fix: report FTP transfer results in the various transfer-related methods
doudou Jan 27, 2025
2dc81d7
fix: set nonzero max_upload_rate in FTP transfer tests
doudou Jan 27, 2025
adf0af3
fix: delete source files after a successful transfer
doudou Jan 27, 2025
64bb0f6
feat: log the transfering results when transfering datasets
kapeps Jan 27, 2025
eea0130
chore: comment log_transfer_result method
kapeps Jan 27, 2025
2b305dc
fix: rubocop grievances
kapeps Jan 27, 2025
942d2ae
Merge pull request #454 from rock-core/fix-ftp-transfer
doudou Jan 28, 2025
b212df5
fix: implement v2 protocol support for master device instances
doudou Dec 5, 2024
d12db61
fix: make sure Qt lets Ruby threads being executed
doudou Dec 14, 2024
7700a3e
fix: improve responsiveness by resolving tasks asynchronously
doudou Dec 14, 2024
a0ad12a
fix: implement an incremental method to update active deployments
doudou Dec 14, 2024
444170d
fix: filtering of loggers if hiding them is enabled
doudou Dec 14, 2024
5c1614f
chore: display fatal error messages explaining why a component ends u…
doudou Dec 14, 2024
b4b64d3
fix: do not load orogen models when creating remote task context handles
doudou Dec 14, 2024
6d0a7c7
chore: implement Telemetry::Async::NameService
doudou Dec 14, 2024
1dbeb46
feat: replace the task resolution code in Telemetry::UI::RuntimeState…
doudou Dec 19, 2024
41ab798
feat: enable v2 protocol extensions in 'telemetry ui'
doudou Dec 19, 2024
57454e9
fix: Qt's timer.start is in milliseconds, no seconds
doudou Dec 19, 2024
acb527d
fix: disable Vizkit's global shortcut
doudou Dec 19, 2024
291acff
fix: do not keep backward compatibility on the v2 interface
doudou Dec 19, 2024
6caa5af
fix: reactivity of the ruby threads
doudou Dec 30, 2024
6cdce39
fix: the hide loggers checkbox does not need to trigger an update any…
doudou Dec 19, 2024
cb0c659
feat: start implementing a replacement for Orocos::Async::TaskContext…
doudou Dec 19, 2024
d59b524
fix: Orocos's async yields object names in the on_*_reachable hooks
doudou Dec 22, 2024
265e3ab
fix: job selection in the telemetry UI
doudou Dec 22, 2024
8394ea2
feat: implement just enough of the orocos'rb Async interface for the …
doudou Dec 22, 2024
098cfcd
chore: refactor Async::NameService for clarity
doudou Dec 23, 2024
c7c4747
fix: log transfer/transfer_server CLI commands
kapeps Jan 24, 2025
b48bed7
fix: linting and unit tests
kapeps Jan 24, 2025
98a82eb
chore: include unit test to verify if transfer actually transfers files
kapeps Jan 24, 2025
62217ff
fix: use port 0, updating the server params when the port is selected
kapeps Jan 27, 2025
8482e73
fix: include max upload rate mbps when testing watch_transfer
kapeps Jan 28, 2025
a8bb04e
Merge pull request #449 from rock-core/telemetry-v2
doudou Jan 28, 2025
ccf4e69
Merge pull request #450 from rock-core/new_async_implementation
doudou Jan 28, 2025
22be3a3
feat: create Telemetry::Async::OutputReader
doudou Dec 23, 2024
20d1e65
feat: make TaskContext and its interface types usable as keys in hashes
doudou Dec 26, 2024
60769c9
fix: make on_reachable return a disposable that deregisters the callback
doudou Dec 26, 2024
c52d2cd
feat: implement Async::PortReadManager
doudou Dec 27, 2024
c81e904
fix: disable type export in 'telemetry ui'
doudou Dec 27, 2024
284e133
feat: add API to remove callbacks from PortReadManager
doudou Dec 30, 2024
d740e21
feat: use PortReadManager to read data for ports
doudou Dec 30, 2024
f9cbf36
chore: setup the separate test:telemetry target
doudou Dec 30, 2024
845f321
fix: working Async along with the task inspector
doudou Dec 30, 2024
cf58297
feat: implement sub ports
doudou Dec 30, 2024
dca435a
chore: use the time after the first read to initialize next_time
doudou Dec 30, 2024
e210801
fix: reset @current_state to nil in dispose
doudou Dec 30, 2024
b07323d
chore define PortReadManager::Poller#to_s for better debugging
doudou Dec 30, 2024
2ff67e9
fix: use ThreadPoolExecutor instead of CachedThreadPool
doudou Dec 30, 2024
1d07885
chore: make OutputPortSubfield appear as a vizkit-compatible output port
doudou Dec 30, 2024
de8ddee
chore: initialize new callbacks with the last read value
doudou Dec 30, 2024
19ba3bd
fix: unit test flexmock not mocking full result
kapeps Jan 29, 2025
8426192
chore: copy plan marks when applying merge group
wvmcastro Dec 5, 2024
f13fc9f
Merge pull request #451 from rock-core/telemetry_v2_port_read
doudou Jan 29, 2025
b963637
Merge pull request #443 from rock-core/copy-merged-task-plan-marks
wvmcastro Jan 29, 2025
93faaf8
Merge pull request #457 from rock-core/fix_log_runtime_main
kapeps Jan 29, 2025
1bd166f
Merge pull request #455 from rock-core/log_transfering_results
kapeps Jan 30, 2025
53dbaba
feat: generalize ensure free space to be able to take any directory a…
kapeps Jan 27, 2025
60ac4d1
feat: ensure_free_space and watch cli commands
kapeps Jan 27, 2025
79cf599
feat: chose directories and files based on modification time when ens…
kapeps Jan 29, 2025
bda9655
chore: break ensure free space if desired free space was reached
kapeps Jan 29, 2025
ce08879
fix: pass max archive size as argument instead of class initializatio…
kapeps Jan 30, 2025
70220e0
feat: allow early deployment at network generation
wvmcastro Dec 12, 2024
6409d34
chore: create conf to toggle early deployments at network gen
wvmcastro Dec 12, 2024
e775e71
refactor: early_deploy as member of NetworkGeneration
wvmcastro Dec 16, 2024
be6aa8c
chore: decide whether merge contexts with non nil agents
wvmcastro Dec 17, 2024
1dc015f
fix: propagate validate_deployed_network flag
wvmcastro Feb 3, 2025
6427629
doc: early_deploy and validate_deployed_network flags
wvmcastro Feb 3, 2025
ff5c9ad
fix(test): misleading test name
wvmcastro Jan 7, 2025
68b614f
chore(test): rewrite test for early_deploy compatibility
wvmcastro Jan 7, 2025
056fbe7
refactor: rubocop grievances
wvmcastro Jan 7, 2025
ecfc211
chore: split may_merge_task_context?
wvmcastro Jan 31, 2025
ed07cbc
Merge pull request #456 from rock-core/cli_ensure_free_space
kapeps Feb 4, 2025
9a677cd
refactor: follow estabilished pattern
wvmcastro Feb 4, 2025
3b5becb
Update lib/syskit/exceptions.rb
wvmcastro Feb 4, 2025
be24850
doc: remove deprecated return description
wvmcastro Feb 4, 2025
12711c6
fix: rubocop grievances
kapeps Feb 5, 2025
fd136cb
Merge pull request #458 from rock-core/refactor_max_size
kapeps Feb 6, 2025
8e4ffd3
fix(test): actually checking for execution agent existence
wvmcastro Feb 7, 2025
83371b8
chore: toggle solver's merge_when_identical_agents at engine level
wvmcastro Feb 7, 2025
e346f95
fix: when early_deploying all tasks should have deployments
wvmcastro Feb 7, 2025
735afa0
refactor: verify_all_tasks_deployed as class method
wvmcastro Feb 5, 2025
bd5abba
chore: verify tasks deployment only at the end of network generation
wvmcastro Feb 7, 2025
b860fe9
test: do not merge when just one task has an execution agent
wvmcastro Feb 5, 2025
0e4d2e5
chore: pass validate_deployed_network as generate argument
wvmcastro Feb 7, 2025
9619635
chore: use early deploy FF as default value
wvmcastro Feb 7, 2025
d726d8e
chore: simplify logic
wvmcastro Feb 7, 2025
415fa60
refactor: move common code to helper file
wvmcastro Feb 11, 2025
c400fa2
chore: enhance ConflictingDeploymentAllocation exception
wvmcastro Feb 11, 2025
a781647
chore: remove useless cop disable
wvmcastro Feb 11, 2025
628a4c6
chore: change ConflictingDeploymentAllocation error message
wvmcastro Feb 13, 2025
ff8569b
style: use refute instead of assert !
wvmcastro Feb 13, 2025
d249ded
Merge branch 'transition-to-runkit' into fix-variable
wvmcastro Feb 13, 2025
3329572
feat: use recommend_init flag to apply init policy
eduardacoppo Feb 6, 2025
9e043a9
chore: fix rubocop offense by moving code
eduardacoppo Feb 6, 2025
af7d128
test: add tests for init policy
eduardacoppo Feb 6, 2025
329b77f
fix/chore: policy for data readers and exported ports
eduardacoppo Feb 7, 2025
7214e0b
test: add tests and update existing ones
eduardacoppo Feb 7, 2025
0dd9f6c
chore: rewrite tests to call init_policy
eduardacoppo Feb 10, 2025
ae5f29f
chore: remove unneccessary code in models/port and tests
eduardacoppo Feb 13, 2025
7ab7ee8
fix: do not override existing init flag
eduardacoppo Feb 13, 2025
945bf58
fix/test: allow policy merge and add tests for this
eduardacoppo Feb 13, 2025
b8903e3
fix: do not merge if no init policy
eduardacoppo Feb 14, 2025
4769d85
Update lib/syskit/exceptions.rb
wvmcastro Feb 14, 2025
d98e6f1
Merge pull request #436 from rock-core/fix-variable
wvmcastro Feb 14, 2025
6aa3c8d
Update lib/syskit/exceptions.rb
wvmcastro Feb 14, 2025
9ede775
fix: register task -> agent association at initialization
wvmcastro Feb 14, 2025
5b5f65e
test: fix merge test
eduardacoppo Feb 17, 2025
4782df8
Merge pull request #459 from tidewise/init_policy_defaults_to_true
jhonasiv Feb 17, 2025
5a67eda
Revert "feat: init policy defaults to true"
jhonasiv Feb 17, 2025
b52d778
Merge pull request #461 from rock-core/revert-459-init_policy_default…
jhonasiv Feb 17, 2025
bce3e99
feat: use recommend_init flag to apply init policy
eduardacoppo Feb 6, 2025
febeac9
chore: fix rubocop offense by moving code
eduardacoppo Feb 6, 2025
de361f0
test: add tests for init policy
eduardacoppo Feb 6, 2025
33d1154
fix/chore: policy for data readers and exported ports
eduardacoppo Feb 7, 2025
51cae2d
test: add tests and update existing ones
eduardacoppo Feb 7, 2025
138c34b
chore: rewrite tests to call init_policy
eduardacoppo Feb 10, 2025
43ea219
chore: remove unneccessary code in models/port and tests
eduardacoppo Feb 13, 2025
d67f483
fix: do not override existing init flag
eduardacoppo Feb 13, 2025
2fd848d
fix/test: allow policy merge and add tests for this
eduardacoppo Feb 13, 2025
b2cd8e3
fix: do not merge if no init policy
eduardacoppo Feb 14, 2025
179f280
fix: fix merge test
eduardacoppo Feb 17, 2025
411e3ef
chore: warn in case it could not find unmanaged task
kapeps Feb 17, 2025
adb6d33
Merge pull request #445 from rock-core/early-deploy-on-generation
wvmcastro Feb 18, 2025
1b1a6a9
refactor: name_service_get_all_tasks loop
kapeps Feb 18, 2025
643622a
fix: assign merge to policy and fix priority
eduardacoppo Feb 21, 2025
d3860c6
chore: fix rubocop offense
eduardacoppo Feb 21, 2025
d84f110
fix: transfer server and transfer client
kapeps Feb 21, 2025
f31f410
refactor: log_runtime_archive be compatible with ruby 2.5.5
kapeps Feb 21, 2025
1104abe
fix: rubocop grievance
kapeps Feb 24, 2025
f28f627
fix/test: fix policy handling in tests
eduardacoppo Feb 21, 2025
65ebfcc
Merge pull request #465 from rock-core/fix_log_transfer_server
kapeps Feb 24, 2025
b97f865
Merge pull request #460 from rock-core/warn_if_not_found
kapeps Feb 24, 2025
85baa6d
Merge pull request #462 from tidewise/init_policy_defaults_to_true
doudou Feb 25, 2025
5df6b65
feat: add fine-grained policy merge
eduardacoppo Feb 18, 2025
7489a90
test: add tests and update existing
eduardacoppo Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ Lint/MissingSuper:
- 'lib/syskit/robot/master_device_instance.rb'
- 'lib/syskit/robot/slave_device_instance.rb'
- 'lib/syskit/telemetry/agent/server.rb'
- 'lib/syskit/telemetry/ui/name_service.rb'
- 'lib/syskit/test/stub_network.rb'

# Offense count: 2
Expand Down
44 changes: 35 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,46 @@ def minitest_set_options(test_task, name)
test_task.options = "#{TESTOPTS} #{minitest_args} -- --simplecov-name=#{name}"
end

Rake::TestTask.new("test:core") do |t|
def core(early_deploy: false)
s = ":no-early-deploy"
if early_deploy
s = ":early-deploy"
early_deploy_setup = ["test/features/early_deploy.rb"]
end

Rake::TestTask.new("test:core#{s}") do |t|
t.libs << "."
t.libs << "lib"
minitest_set_options(t, "core")
test_files = FileList["test/**/test_*.rb", *early_deploy_setup]
test_files = test_files
.exclude("test/ros/**/*.rb")
.exclude("test/gui/**/*.rb")
.exclude("test/live/**/*.rb")
.exclude("test/telemetry/**/*.rb")
t.test_files = test_files
t.warning = false
end
end

Rake::TestTask.new("test:telemetry") do |t|
t.libs << "."
t.libs << "lib"
minitest_set_options(t, "core")
test_files = FileList["test/**/test_*.rb"]
test_files = test_files
.exclude("test/ros/**/*.rb")
.exclude("test/gui/**/*.rb")
.exclude("test/live/**/*.rb")
t.test_files = test_files
minitest_set_options(t, "telemetry")
t.test_files = FileList["test/telemetry/**/test_*.rb"]
t.warning = false
end

desc "Run separate tests that require a live syskit instance"
task "test:live" do
tests = Dir.enum_for(:glob, "test/live/test_*.rb").to_a
unless system(File.join("test", "live", "run"), *tests)
$stderr.puts "live tests failed"
exit 1
end
end

desc "run gui-only tests"
Rake::TestTask.new("test:gui") do |t|
t.libs << "."
t.libs << "lib"
Expand All @@ -57,7 +77,13 @@ Rake::TestTask.new("test:gui") do |t|
t.warning = false
end

task "test" => ["test:gui", "test:core", "test:live"]
core early_deploy: true
core
desc "Run core library tests, excluding GUI and live tests"
task "test:core" => ["test:core:no-early-deploy", "test:core:early-deploy"]

desc "Run all tests"
task "test" => ["test:gui", "test:core", "test:live", "test:telemetry"]

task "rubocop" do
raise "rubocop failed" unless system(ENV["RUBOCOP_CMD"] || "rubocop")
Expand Down
3 changes: 2 additions & 1 deletion lib/syskit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module ProcessManagers
require "syskit/roby_app/log_transfer_server"
require "syskit/process_managers/process_base"
require "syskit/process_managers/status"
require "syskit/process_managers/remote/server/log_upload_state"
require "syskit/roby_app/log_transfer_server/log_upload_state"
require "syskit/process_managers/remote/protocol"
require "syskit/process_managers/remote/loader"
require "syskit/process_managers/remote/manager"
Expand Down Expand Up @@ -127,6 +127,7 @@ module ProcessManagers
require "syskit/actual_data_flow_graph"
require "syskit/data_flow"
require "syskit/connection_graphs"
require "syskit/network_generation_exception_helpers"
require "syskit/exceptions"
require "syskit/network_generation"
require "syskit/runtime"
Expand Down
1 change: 1 addition & 0 deletions lib/syskit/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "logger"
require "utilrb/logger"
require "syskit/network_generation_exception_helpers"
require "syskit/exceptions"
require "facets/string/snakecase"

Expand Down
160 changes: 144 additions & 16 deletions lib/syskit/cli/log_runtime_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "archive/tar/minitar"
require "sys/filesystem"
require "syskit/roby_app/log_transfer_server/ftp_upload"

module Syskit
module CLI
Expand All @@ -17,16 +18,40 @@ class CompressionFailed < RuntimeError; end
class LogRuntimeArchive
DEFAULT_MAX_ARCHIVE_SIZE = 10_000_000_000 # 10G

FTPParameters = Struct.new(:host, :port, :certificate, :user, :password,
:implicit_ftps, :max_upload_rate,
keyword_init: true)

# Initializes the LogRuntimeArchive
#
# @param [Pathname] root_dir the logs directory
# @param [Pathname] target_dir the path to store the file in the archive,
# should be nil in transfer mode, as the logs will be transferred directly
# to the ftp server @see process_root_folder_transfer
# @param [Logger] logger the log structure
def initialize(
root_dir, target_dir,
logger: LogRuntimeArchive.null_logger,
max_archive_size: DEFAULT_MAX_ARCHIVE_SIZE
root_dir, target_dir: nil,
logger: LogRuntimeArchive.null_logger
)
@last_archive_index = {}
@logger = logger
@root_dir = root_dir
@target_dir = target_dir
@max_archive_size = max_archive_size
end

# Iterate over all datasets in a Roby log root folder and transfer them
# through FTP server
#
# @param [Params] server_params the FTP server parameters
# @return [Array<TransferDatasetResult>]
def process_root_folder_transfer(server_params)
candidates = self.class.find_all_dataset_folders(@root_dir)
running = candidates.last
candidates.map do |child|
process_dataset_transfer(
child, server_params, @root_dir, full: child != running
)
end
end

# Iterate over all datasets in a Roby log root folder and archive them
Expand All @@ -37,11 +62,14 @@ def initialize(
# @param [Pathname] root_dir the log root folder
# @param [Pathname] target_dir the folder in which to save the
# archived datasets
def process_root_folder
# @param [Integer] max_archive_size the max size of the archive
def process_root_folder(max_archive_size: DEFAULT_MAX_ARCHIVE_SIZE)
candidates = self.class.find_all_dataset_folders(@root_dir)
running = candidates.last
candidates.each do |child|
process_dataset(child, full: child != running)
process_dataset(
child, max_archive_size: max_archive_size, full: child != running
)
end
end

Expand All @@ -54,48 +82,55 @@ def process_root_folder
# bytes, at which the archiver starts deleting the oldest log files
# @param [integer] free_space_delete_until: post-deletion free space in bytes,
# at which the archiver stops deleting the oldest log files
def ensure_free_space(free_space_low_limit, free_space_delete_until)
#
# @return [Boolean] true if successfully ensured free space, meaning there is
# the required free space, false if deleting the files in this directory was
# not enough to free up the required space
def ensure_free_space(
free_space_low_limit, free_space_delete_until, directory: @target_dir
)
if free_space_low_limit > free_space_delete_until
raise ArgumentError,
"cannot erase files: freed limit is smaller than " \
"low limit space."
end

stat = Sys::Filesystem.stat(@target_dir)
stat = Sys::Filesystem.stat(directory)
available_space = stat.bytes_available

return if available_space > free_space_low_limit
return true if available_space > free_space_low_limit

until available_space >= free_space_delete_until
files = @target_dir.each_child.select(&:file?)
files = directory.each_child.select(&:file?)
if files.empty?
Roby.warn "Cannot erase files: the folder is empty but the " \
"available space is smaller than the threshold."
break
return false
end

removed_file = files.min
removed_file = files.min_by(&:mtime)
size_removed_file = removed_file.size
removed_file.unlink
available_space += size_removed_file
end
true
end

def process_dataset(child, full:)
def process_dataset(child, full:, max_archive_size: DEFAULT_MAX_ARCHIVE_SIZE)
use_existing = true
loop do
open_archive_for(
child.basename.to_s, use_existing: use_existing
) do |io|
if io.tell > @max_archive_size
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
max_size: max_archive_size
)
return if dataset_complete
end
Expand All @@ -104,6 +139,99 @@ def process_dataset(child, full:)
end
end

def process_dataset_transfer(child, server, root, full:)
self.class.transfer_dataset(
child, server, root, full: full, logger: @logger
)
end

TransferDatasetResult = Struct.new(
:complete, :transfer_results, keyword_init: true
) do
def success?
transfer_results.all?(&:success?)
end

def failures
transfer_results.find_all { !_1.success? }
end
end

# Transfer the given dataset
def self.transfer_dataset(
dataset_path, server, root,
full:, logger: null_logger
)
logger.info(
"Transfering dataset #{dataset_path} in " \
"#{full ? 'full' : 'partial'} mode"
)
candidates = each_file_from_path(dataset_path).to_a

complete, candidates =
if full
archive_filter_candidates_full(candidates)
else
archive_filter_candidates_partial(candidates)
end

transfer_results = candidates.map do |child_path|
result = transfer_file(child_path, server, root)
child_path.unlink if result.success?

result
end

result = TransferDatasetResult.new(
complete: complete, transfer_results: transfer_results
)
log_transfer_results(dataset_path, result, logger: logger)
end

# Logs the transfer dataset results
#
# @param [String] the dataset path
# @param [TransferDatasetResult] the transfer dataset result
# @param [Logger] optional logger, if unfilled will use null logger
#
# @result [TransferDatasetResult] the received transfer dataset result
def self.log_transfer_results(dataset_path, result, logger: null_logger)
failed_results = result[:transfer_results].reject(&:success)

if failed_results.empty?
logger.info(
"Transfering of " \
"#{result[:complete] ? 'complete' : 'incomplete'} " \
"#{dataset_path} finished"
)
else
failed_results.each do |failed_result|
failed_message =
if failed_result.message
"with message : #{failed_result.message}"
end
logger.info(
"Failed on file #{failed_result.file} #{failed_message}"
)
end
end

result
end

# Transfer a file to the central log server via FTP
#
# @return [LogUploadState:Result]
def self.transfer_file(file, server, root)
ftp = RobyApp::LogTransferServer::FTPUpload.new(
server.host, server.port, server.certificate, server.user,
server.password, file,
max_upload_rate: server.max_upload_rate || Float::INFINITY,
implicit_ftps: server.implicit_ftps
)
ftp.open_and_transfer(root: root)
end

# Create or open an archive
#
# The method will find an archive to open or create, do it and
Expand Down Expand Up @@ -158,7 +286,7 @@ def self.find_all_dataset_folders(root_dir)
child if (child / "info.yml").file?
end

candidates.compact.sort_by { _1.basename.to_s }
candidates.compact.sort_by { |a| a.basename.to_s }
end

# Safely add an entry into an archive, compressing it with zstd
Expand Down
Loading