aspera-cli 4.29.1 → 4.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +8 -1
- data/README.md +2 -0
- data/TODO.md +4 -5
- data/bin/asession +2 -2
- data/docs/README.md +616 -86
- data/docs/test-mcp-with-ai.md +4 -0
- data/lib/aspera/agent/base.rb +62 -6
- data/lib/aspera/agent/factory.rb +127 -20
- data/lib/aspera/ascp/data_repository.rb +71 -0
- data/lib/aspera/ascp/installation.rb +16 -11
- data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
- data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
- data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
- data/lib/aspera/ascp/log_analyzer.rb +43 -18
- data/lib/aspera/ascp/log_locations.rb +2 -2
- data/lib/aspera/assert.rb +8 -0
- data/lib/aspera/bundle_registry.rb +528 -0
- data/lib/aspera/cli/argument.rb +110 -0
- data/lib/aspera/cli/bool_value.rb +41 -0
- data/lib/aspera/cli/bootstrapper.rb +31 -24
- data/lib/aspera/cli/command/mount.rb +53 -0
- data/lib/aspera/cli/command/registry.rb +434 -0
- data/lib/aspera/cli/command.rb +95 -0
- data/lib/aspera/cli/command_line.rb +91 -91
- data/lib/aspera/cli/complete.rb +22 -0
- data/lib/aspera/cli/completion_actions.rb +28 -26
- data/lib/aspera/cli/context.rb +29 -6
- data/lib/aspera/cli/error.rb +39 -0
- data/lib/aspera/cli/extended_value.rb +25 -4
- data/lib/aspera/cli/formatter.rb +8 -8
- data/lib/aspera/cli/hints.rb +17 -52
- data/lib/aspera/cli/http.rb +17 -12
- data/lib/aspera/cli/mailer.rb +7 -24
- data/lib/aspera/cli/mcp/tool.rb +10 -2
- data/lib/aspera/cli/option/declarator.rb +80 -0
- data/lib/aspera/cli/option/registry.rb +74 -0
- data/lib/aspera/cli/option/source.rb +38 -0
- data/lib/aspera/cli/option/type.rb +37 -0
- data/lib/aspera/cli/option/value.rb +376 -0
- data/lib/aspera/cli/option.rb +78 -0
- data/lib/aspera/cli/options.schema.yaml +28 -783
- data/lib/aspera/cli/parser.rb +73 -41
- data/lib/aspera/cli/plugins/base.rb +122 -42
- data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
- data/lib/aspera/cli/plugins/config.rb +101 -167
- data/lib/aspera/cli/plugins/factory.rb +139 -43
- data/lib/aspera/cli/plugins/mcp.rb +61 -54
- data/lib/aspera/cli/plugins/oauth.rb +19 -6
- data/lib/aspera/cli/poll.rb +14 -20
- data/lib/aspera/cli/preset_actions.rb +11 -3
- data/lib/aspera/cli/preset_manager.rb +16 -6
- data/lib/aspera/cli/result.rb +2 -2
- data/lib/aspera/cli/runner.rb +71 -99
- data/lib/aspera/cli/secret_finder.rb +1 -1
- data/lib/aspera/cli/security.rb +102 -4
- data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
- data/lib/aspera/cli/vault_manager.rb +3 -3
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/cli/wizard.rb +9 -3
- data/lib/aspera/coverage.rb +1 -2
- data/lib/aspera/line_logger.rb +35 -6
- data/lib/aspera/log.rb +3 -2
- data/lib/aspera/oauth/client/base.rb +19 -1
- data/lib/aspera/oauth/client/factory.rb +1 -7
- data/lib/aspera/plugin.schema.yaml +178 -0
- data/lib/aspera/plugins/alee/api.rb +25 -0
- data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
- data/lib/aspera/plugins/alee/plugin.yaml +3 -0
- data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
- data/lib/aspera/plugins/aoc/api.rb +783 -0
- data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
- data/lib/aspera/plugins/aoc/graphql.rb +45 -0
- data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
- data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
- data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
- data/lib/aspera/plugins/ats/api.rb +51 -0
- data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
- data/lib/aspera/plugins/ats/plugin.yaml +6 -0
- data/lib/aspera/plugins/connect/agent.rb +199 -0
- data/lib/aspera/plugins/connect/plugin.yaml +11 -0
- data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
- data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
- data/lib/aspera/plugins/console/plugin.yaml +8 -0
- data/lib/aspera/plugins/cos/api.rb +114 -0
- data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
- data/lib/aspera/plugins/cos/plugin.yaml +9 -0
- data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
- data/lib/aspera/plugins/desktop/agent.rb +165 -0
- data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
- data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
- data/lib/aspera/plugins/direct/agent.rb +518 -0
- data/lib/aspera/plugins/direct/plugin.yaml +11 -0
- data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
- data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
- data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
- data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
- data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
- data/lib/aspera/plugins/faspex5/api.rb +269 -0
- data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
- data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
- data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
- data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
- data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
- data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
- data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
- data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
- data/lib/aspera/plugins/httpgw/agent.rb +126 -0
- data/lib/aspera/plugins/httpgw/api.rb +411 -0
- data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
- data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
- data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
- data/lib/aspera/plugins/node/agent.rb +184 -0
- data/lib/aspera/plugins/node/api.rb +699 -0
- data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
- data/lib/aspera/plugins/node/emulator.rb +774 -0
- data/lib/aspera/plugins/node/plugin.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
- data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
- data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
- data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
- data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
- data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
- data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
- data/lib/aspera/plugins/preview/file_types.rb +121 -0
- data/lib/aspera/plugins/preview/generator.rb +350 -0
- data/lib/aspera/plugins/preview/plugin.yaml +12 -0
- data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
- data/lib/aspera/plugins/preview/utils.rb +213 -0
- data/lib/aspera/plugins/server/ascmd.rb +374 -0
- data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
- data/lib/aspera/plugins/server/plugin.yaml +9 -0
- data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
- data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
- data/lib/aspera/plugins/shares/plugin.yaml +10 -0
- data/lib/aspera/plugins/shares/shares_web.rb +97 -0
- data/lib/aspera/plugins/transferd/agent.rb +258 -0
- data/lib/aspera/plugins/transferd/api.rb +180 -0
- data/lib/aspera/plugins/transferd/client.rb +67 -0
- data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
- data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
- data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
- data/lib/aspera/plugins/transferd/product.rb +146 -0
- data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
- data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
- data/lib/aspera/plugins/transferd/service.rb +617 -0
- data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
- data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
- data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
- data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
- data/lib/aspera/plugins/xfer/helper.rb +19 -0
- data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
- data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
- data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
- data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
- data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
- data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
- data/lib/aspera/products/cli_v3.rb +34 -0
- data/lib/aspera/products/connect.rb +1 -1
- data/lib/aspera/products/drive.rb +29 -0
- data/lib/aspera/products/hsts.rb +34 -0
- data/lib/aspera/products/transferd.rb +25 -3
- data/lib/aspera/products.rb +54 -0
- data/lib/aspera/prompt.rb +184 -0
- data/lib/aspera/proxy_auto_config.rb +3 -3
- data/lib/aspera/rest/aspera_errors.rb +4 -38
- data/lib/aspera/rest/error_analyzer.rb +6 -2
- data/lib/aspera/rest/list.rb +4 -5
- data/lib/aspera/schema/reader.rb +15 -0
- data/lib/aspera/schema/registry.rb +239 -45
- data/lib/aspera/schema/validator.rb +63 -17
- data/lib/aspera/sealed_hash.rb +4 -0
- data/lib/aspera/secret/hider.rb +159 -24
- data/lib/aspera/secret/reference.rb +8 -0
- data/lib/aspera/secret/resolver.rb +8 -4
- data/lib/aspera/secret/store/base.rb +10 -9
- data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
- data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
- data/lib/aspera/secret/store/keeper.rb +2 -2
- data/lib/aspera/secret/store/macos_security.rb +2 -3
- data/lib/aspera/secret/store/one_password_api.rb +2 -2
- data/lib/aspera/secret/store/one_password_cli.rb +3 -3
- data/lib/aspera/secret/store/secret_service.rb +2 -2
- data/lib/aspera/ssl.rb +3 -3
- data/lib/aspera/standard_input.rb +20 -0
- data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
- data/lib/aspera/sync/database.rb +7 -0
- data/lib/aspera/sync/log_parser.rb +138 -0
- data/lib/aspera/sync/operations.rb +59 -34
- data/lib/aspera/transfer/command_line_builder.rb +248 -0
- data/lib/aspera/transfer/command_line_converter.rb +37 -0
- data/lib/aspera/transfer/faux_file.rb +2 -2
- data/lib/aspera/transfer/parameters.rb +9 -10
- data/lib/aspera/transfer/spec.rb +28 -1
- data/lib/aspera/transfer/spec.schema.yaml +30 -5
- data/lib/aspera/units/decimal.rb +1 -1
- data/lib/aspera/units/timestamp.rb +84 -0
- data/lib/aspera/uri_reader.rb +2 -2
- data/lib/aspera/web_auth/paste.rb +2 -2
- data/lib/aspera/web_server_simple.rb +10 -4
- data.tar.gz.sig +0 -0
- metadata +137 -80
- metadata.gz.sig +0 -0
- data/lib/aspera/agent/connect.rb +0 -188
- data/lib/aspera/agent/desktop.rb +0 -154
- data/lib/aspera/agent/direct.rb +0 -496
- data/lib/aspera/agent/httpgw.rb +0 -100
- data/lib/aspera/agent/node.rb +0 -166
- data/lib/aspera/agent/transferd.rb +0 -341
- data/lib/aspera/api/alee.rb +0 -19
- data/lib/aspera/api/aoc.rb +0 -776
- data/lib/aspera/api/ats.rb +0 -49
- data/lib/aspera/api/cos_node.rb +0 -107
- data/lib/aspera/api/faspex.rb +0 -258
- data/lib/aspera/api/httpgw.rb +0 -409
- data/lib/aspera/api/node.rb +0 -684
- data/lib/aspera/ascmd.rb +0 -248
- data/lib/aspera/cli/ascp_actions.rb +0 -113
- data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
- data/lib/aspera/cli/async_transfer_store.rb +0 -129
- data/lib/aspera/cli/command_registry.rb +0 -371
- data/lib/aspera/cli/command_spec.rb +0 -273
- data/lib/aspera/cli/option_declarator.rb +0 -74
- data/lib/aspera/cli/option_registry.rb +0 -72
- data/lib/aspera/cli/option_types.rb +0 -120
- data/lib/aspera/cli/option_value.rb +0 -345
- data/lib/aspera/cli/prompt.rb +0 -186
- data/lib/aspera/cli/sync_actions.rb +0 -181
- data/lib/aspera/cli/transfer_actions.rb +0 -98
- data/lib/aspera/cli/transfer_agent.rb +0 -348
- data/lib/aspera/command_line_builder.rb +0 -244
- data/lib/aspera/command_line_converter.rb +0 -35
- data/lib/aspera/data_repository.rb +0 -69
- data/lib/aspera/faspex_gw.rb +0 -172
- data/lib/aspera/faspex_postproc.rb +0 -237
- data/lib/aspera/graphql.rb +0 -41
- data/lib/aspera/node_emulator.rb +0 -758
- data/lib/aspera/oauth/client/shares_web.rb +0 -94
- data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
- data/lib/aspera/preview/file_types.rb +0 -119
- data/lib/aspera/preview/generator.rb +0 -345
- data/lib/aspera/preview/utils.rb +0 -211
- data/lib/aspera/products/other.rb +0 -92
- data/lib/aspera/products/transferd_service.rb +0 -610
- /data/lib/aspera/{data → ascp/data}/1 +0 -0
- /data/lib/aspera/{data → ascp/data}/2 +0 -0
- /data/lib/aspera/{data → ascp/data}/3 +0 -0
- /data/lib/aspera/{data → ascp/data}/4 +0 -0
- /data/lib/aspera/{data → ascp/data}/5 +0 -0
- /data/lib/aspera/{data → ascp/data}/6 +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
- /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
- /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
- /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
- /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
- /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
- /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
- /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: Options of bundle xfer
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
description: Schema definitions of the options of bundle `xfer`
|
|
6
|
+
license:
|
|
7
|
+
name: Apache-2.0
|
|
8
|
+
identifier: Apache-2.0
|
|
9
|
+
paths: {}
|
|
10
|
+
components:
|
|
11
|
+
schemas:
|
|
12
|
+
AscpLogsOptions:
|
|
13
|
+
type: object
|
|
14
|
+
description: Analysis of `ascp` log files (`config ascp logs`).
|
|
15
|
+
additionalProperties: false
|
|
16
|
+
properties:
|
|
17
|
+
period:
|
|
18
|
+
type: integer
|
|
19
|
+
description: Snapshot period, in minutes.
|
|
20
|
+
default: 1
|
|
21
|
+
zero_bytes:
|
|
22
|
+
type: boolean
|
|
23
|
+
description: Include sessions without transferred bytes.
|
|
24
|
+
default: false
|
|
25
|
+
mtu:
|
|
26
|
+
type: integer
|
|
27
|
+
description: MTU, when not found in logs.
|
|
28
|
+
resolve:
|
|
29
|
+
type: boolean
|
|
30
|
+
description: Resolve peer addresses to host names.
|
|
31
|
+
default: false
|
|
32
|
+
timezone:
|
|
33
|
+
type: string
|
|
34
|
+
description: Time zone of the log lines (`UTC` or `+HH:MM`), to read a log from another time zone. Default is the local time zone.
|
|
35
|
+
health_minutes:
|
|
36
|
+
type: integer
|
|
37
|
+
description: Window in minutes to report transfer errors and low efficiency.
|
|
38
|
+
default: 60
|
|
39
|
+
remote_max_size:
|
|
40
|
+
type: integer
|
|
41
|
+
description: Maximum total size in bytes of the log files read from a server (`server logs`).
|
|
42
|
+
default: 536870912
|
|
43
|
+
thresholds:
|
|
44
|
+
type: object
|
|
45
|
+
description: Diagnostic thresholds.
|
|
46
|
+
additionalProperties: false
|
|
47
|
+
properties:
|
|
48
|
+
efficiency:
|
|
49
|
+
type: number
|
|
50
|
+
description: Minimum efficiency percentage below which a warning is emitted.
|
|
51
|
+
default: 90.0
|
|
52
|
+
control_loss_percent:
|
|
53
|
+
type: number
|
|
54
|
+
description: Minimum percentage of lost control messages to trigger a warning.
|
|
55
|
+
default: 5.0
|
|
56
|
+
control_loss_sent:
|
|
57
|
+
type: integer
|
|
58
|
+
description: Minimum number of control messages sent before checking control loss.
|
|
59
|
+
default: 10
|
|
60
|
+
retry_window:
|
|
61
|
+
type: integer
|
|
62
|
+
description: Maximum interval in seconds between sessions to link a retry.
|
|
63
|
+
default: 3600
|
|
64
|
+
last_error_window:
|
|
65
|
+
type: integer
|
|
66
|
+
description: Window in seconds before exit to attribute the last logged error.
|
|
67
|
+
default: 60
|
|
68
|
+
rate_decline_ratio:
|
|
69
|
+
type: number
|
|
70
|
+
description: Ratio of second half rate to first half rate below which rate decline is diagnosed.
|
|
71
|
+
default: 0.7
|
|
72
|
+
rate_decline_min_samples:
|
|
73
|
+
type: integer
|
|
74
|
+
description: Minimum number of samples to evaluate rate decline.
|
|
75
|
+
default: 10
|
|
76
|
+
rate_decline_delay:
|
|
77
|
+
type: integer
|
|
78
|
+
description: Delay in seconds after session start before evaluating rate decline samples.
|
|
79
|
+
default: 20
|
|
80
|
+
rate_decline_end_fraction:
|
|
81
|
+
type: number
|
|
82
|
+
description: Fraction of samples to discard from the end of a session when evaluating rate decline.
|
|
83
|
+
default: 0.1
|
|
84
|
+
license_expiry_days:
|
|
85
|
+
type: integer
|
|
86
|
+
description: Number of days before the expiry of the license of ascp (or less, if already expired) at which a warning is emitted.
|
|
87
|
+
default: 30
|
|
88
|
+
small_files_min_count:
|
|
89
|
+
type: integer
|
|
90
|
+
description: Minimum number of transferred files to check for the small-files diagnostic.
|
|
91
|
+
default: 100
|
|
92
|
+
small_files_max_mean:
|
|
93
|
+
type: integer
|
|
94
|
+
description: Maximum mean file size in bytes below which the small-files diagnostic is emitted.
|
|
95
|
+
default: 1000000
|
|
96
|
+
small_mtu_max:
|
|
97
|
+
type: integer
|
|
98
|
+
description: Path MTU in bytes below which the small-MTU diagnostic is emitted (ascp measures 1492, 1006, 508 or 296).
|
|
99
|
+
default: 1400
|
|
100
|
+
TransferAgentOptions:
|
|
101
|
+
description: >-
|
|
102
|
+
Transfer agent selector and agent-specific parameters.
|
|
103
|
+
Set `agent` to select the agent type (default: `direct`).
|
|
104
|
+
Remaining keys are passed to the selected agent.
|
|
105
|
+
# Variants: entries of the extension point `agent`, added when the schema is read (see `Schema::Registry#add_variants`)
|
|
106
|
+
x-cli-variants:
|
|
107
|
+
point: agent
|
|
108
|
+
value: name
|
|
109
|
+
schema: options_schema
|
|
110
|
+
suffix: AgentOptions
|
|
111
|
+
unique: short
|
|
112
|
+
discriminator:
|
|
113
|
+
propertyName: agent
|
|
114
|
+
# Keys common to all agents. The parameters of the variant selected by `agent` are evaluated by it, other keys are refused.
|
|
115
|
+
# Variants do not state `additionalProperties`: `false` would refuse the keys of this node, `true` would accept any key.
|
|
116
|
+
properties:
|
|
117
|
+
agent:
|
|
118
|
+
type: string
|
|
119
|
+
description: Name of the transfer agent.
|
|
120
|
+
default: direct
|
|
121
|
+
asynchronous:
|
|
122
|
+
type: boolean
|
|
123
|
+
description: Return after the start of the transfer, with the identifier of the job, instead of waiting for its end (see `config agents jobs`).
|
|
124
|
+
default: false
|
|
125
|
+
unevaluatedProperties: false
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../sync/operations'
|
|
7
|
+
require_relative '../../assert'
|
|
8
|
+
require_relative '../../environment'
|
|
9
|
+
require_relative '../../standard_input'
|
|
10
|
+
require 'pathname'
|
|
11
|
+
|
|
12
|
+
module Aspera
|
|
13
|
+
module Plugins
|
|
14
|
+
module Xfer
|
|
15
|
+
# Helpers shared by plugins that expose Aspera Sync (async) operations.
|
|
16
|
+
# Provides DSL registration, argument-to-sync-info conversion, and action methods.
|
|
17
|
+
module SyncActions
|
|
18
|
+
# Translate state id (int) to string
|
|
19
|
+
STATE_STR = (['Nil'] +
|
|
20
|
+
(1..18).map { |i| "P(#{i})" } +
|
|
21
|
+
%w[Syncd Error Confl Pconf] +
|
|
22
|
+
(23..24).map { |i| "P(#{i})" }).freeze
|
|
23
|
+
# Positional arguments of sync transfer commands (push/pull/bidi): the positional `path` is the local folder (push, bidi)
|
|
24
|
+
# or the remote path (pull), so it is not declared as a local path here (the local side is checked when the transfer starts).
|
|
25
|
+
PATH_AND_INFO_ARGS = [{name: :path, complete: :folder, access: :none}, {name: :sync_info, type: Hash, mandatory: false, default: {}}].freeze
|
|
26
|
+
# Positional arguments of sync admin commands: the positional `path` is always the local database folder, read to show its state.
|
|
27
|
+
ADMIN_PATH_AND_INFO_ARGS = [{name: :path, complete: :folder, access: :read}, {name: :sync_info, type: Hash, mandatory: false, default: {}}].freeze
|
|
28
|
+
# Argument of `sync logs`: the async log files to analyze, read locally (default: the local async log)
|
|
29
|
+
SYNC_LOG_ARGS = [{
|
|
30
|
+
name: :paths,
|
|
31
|
+
description: 'async log files (gzip supported), folders, or `-` for standard input (default: the local async log)',
|
|
32
|
+
multiple: true,
|
|
33
|
+
mandatory: false,
|
|
34
|
+
complete: :file,
|
|
35
|
+
access: :read,
|
|
36
|
+
stdin: true
|
|
37
|
+
}].freeze
|
|
38
|
+
# When a plugin class includes SyncActions, register the :sql option
|
|
39
|
+
# in that class's DSL registry so Base#initialize auto-declares it,
|
|
40
|
+
# and add the class-level DSL methods of ClassMethods.
|
|
41
|
+
class << self
|
|
42
|
+
def included(base)
|
|
43
|
+
# Raw SQL appended to the queries of the admin commands: executes code (e.g. `VACUUM INTO` writes a file), allowed at level `low` only
|
|
44
|
+
base.option(:sql, description: 'SQL suffix appended to sqlite3 queries for admin subcommands (e.g. WHERE clause)', security: :low)
|
|
45
|
+
base.extend(ClassMethods)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Class-level DSL methods added to the plugin class that includes SyncActions.
|
|
50
|
+
module ClassMethods
|
|
51
|
+
# DSL class method: declare the `sync admin` node and its 7 leaf commands.
|
|
52
|
+
# @param parent [Symbol, Array<Symbol>] path relative to current scope, e.g. :admin
|
|
53
|
+
def sync_admin_commands(parent)
|
|
54
|
+
commands_under(parent, description: 'Manage sync database (admin operations)') do
|
|
55
|
+
command(
|
|
56
|
+
:find, description: 'Find sync database files', arguments: [{name: :path, complete: :folder, access: :read}],
|
|
57
|
+
action: lambda do |path:, **|
|
|
58
|
+
dbs = readable_db_files(path)
|
|
59
|
+
Cli::Result::ObjectList.new(dbs.keys.map { |n| {name: n, path: dbs[n]} })
|
|
60
|
+
end
|
|
61
|
+
)
|
|
62
|
+
command(
|
|
63
|
+
:status, description: 'Show sync session status', arguments: ADMIN_PATH_AND_INFO_ARGS,
|
|
64
|
+
action: ->(path:, sync_info: {}, **) { Cli::Result::SingleObject.new(Sync::Operations.admin_status(admin_sync_info(path: path, sync_info: sync_info))) }
|
|
65
|
+
)
|
|
66
|
+
command(
|
|
67
|
+
:meta, description: 'Show sync session metadata', arguments: ADMIN_PATH_AND_INFO_ARGS,
|
|
68
|
+
action: lambda do |path:, sync_info: {}, **|
|
|
69
|
+
require_relative '../../sync/database'
|
|
70
|
+
Cli::Result::SingleObject.new(db_from_args(path: path, sync_info: sync_info).meta(options.get_option(:sql)))
|
|
71
|
+
end
|
|
72
|
+
)
|
|
73
|
+
command(
|
|
74
|
+
:counters, description: 'Show sync counters', arguments: ADMIN_PATH_AND_INFO_ARGS,
|
|
75
|
+
action: lambda do |path:, sync_info: {}, **|
|
|
76
|
+
require_relative '../../sync/database'
|
|
77
|
+
Cli::Result::SingleObject.new(db_from_args(path: path, sync_info: sync_info).counters(options.get_option(:sql)))
|
|
78
|
+
end
|
|
79
|
+
)
|
|
80
|
+
command(:file_info, description: 'Show per-file sync state', arguments: ADMIN_PATH_AND_INFO_ARGS, action: :action_sync_admin_file_info)
|
|
81
|
+
command(
|
|
82
|
+
:overview, description: 'Show sync database overview', arguments: ADMIN_PATH_AND_INFO_ARGS,
|
|
83
|
+
action: lambda do |path:, sync_info: {}, **|
|
|
84
|
+
require_relative '../../sync/database'
|
|
85
|
+
Cli::Result::ObjectList.new(db_from_args(path: path, sync_info: sync_info).overview, fields: %w[table name type])
|
|
86
|
+
end
|
|
87
|
+
)
|
|
88
|
+
command(
|
|
89
|
+
:query, description: 'Execute a raw SQL query', arguments: ADMIN_PATH_AND_INFO_ARGS,
|
|
90
|
+
action: lambda do |path:, sync_info: {}, **|
|
|
91
|
+
require_relative '../../sync/database'
|
|
92
|
+
Cli::Result.auto(db_from_args(path: path, sync_info: sync_info).execute(options.get_option(:sql, mandatory: true)))
|
|
93
|
+
end
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# DSL class method: declare the `sync logs` command (analysis of async log files).
|
|
99
|
+
# @param name [Symbol, Array<Symbol>] command path relative to current scope, e.g. :logs
|
|
100
|
+
def sync_logs_command(name)
|
|
101
|
+
command(name, description: 'Analyze async log files: conflicts, errors, and session lifecycle', arguments: SYNC_LOG_ARGS, action: :action_sync_logs)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Convert path + sync_info to internal `sync_info` format.
|
|
106
|
+
# The resulting sync_info has `args` format only if it contains one of the `sessions` or `instance` keys.
|
|
107
|
+
# It has the `conf` format (default) otherwise.
|
|
108
|
+
# If the `conf` format is detected, then both `local` and `remote` keys are set.
|
|
109
|
+
# @param path [String] local/remote path
|
|
110
|
+
# @param sync_info [Hash] extra sync info (may be empty)
|
|
111
|
+
# @param direction [Symbol,NilClass] one of DIRECTIONS, or nil for admin commands
|
|
112
|
+
# @return [Hash] sync info
|
|
113
|
+
def async_info_from_args(path:, sync_info: {}, direction: nil)
|
|
114
|
+
# is the positional path a remote path ?
|
|
115
|
+
path_is_remote = direction.eql?(:pull)
|
|
116
|
+
if sync_info.key?('sessions') || sync_info.key?('instance')
|
|
117
|
+
# `args`
|
|
118
|
+
sync_info['sessions'] ||= [{}]
|
|
119
|
+
Aspera.assert(sync_info['sessions'].length == 1, 'Only one session is supported', type: Cli::BadArgument)
|
|
120
|
+
session = sync_info['sessions'].first
|
|
121
|
+
dir_key = path_is_remote ? 'remote_dir' : 'local_dir'
|
|
122
|
+
Aspera.assert(!session.key?(dir_key), type: Cli::BadArgument) { "Parameter #{dir_key} shall not be in sync_info" }
|
|
123
|
+
session[dir_key] = path
|
|
124
|
+
if direction
|
|
125
|
+
dir_key = path_is_remote ? 'local_dir' : 'remote_dir'
|
|
126
|
+
Aspera.assert(!session.key?(dir_key), type: Cli::BadArgument) { "Parameter #{dir_key} shall not be in sync_info" }
|
|
127
|
+
session[dir_key] = transfer.destination_folder(path_is_remote ? Aspera::Transfer::Spec::DIRECTION_RECEIVE : Aspera::Transfer::Spec::DIRECTION_SEND)
|
|
128
|
+
local_remote = %w[local remote].map { |i| session["#{i}_dir"] }
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
# `conf`
|
|
132
|
+
session = sync_info
|
|
133
|
+
dir_key = path_is_remote ? 'remote' : 'local'
|
|
134
|
+
session[dir_key] ||= {}
|
|
135
|
+
Aspera.assert(!session[dir_key].key?('path'), type: Cli::BadArgument) { "Parameter #{dir_key}.path shall not be in sync_info" }
|
|
136
|
+
session[dir_key]['path'] = path
|
|
137
|
+
if direction
|
|
138
|
+
dir_key = path_is_remote ? 'local' : 'remote'
|
|
139
|
+
session[dir_key] ||= {}
|
|
140
|
+
Aspera.assert(!session[dir_key].key?('path'), type: Cli::BadArgument) { "Parameter #{dir_key}.path shall not be in sync_info" }
|
|
141
|
+
session[dir_key]['path'] = transfer.destination_folder(path_is_remote ? Aspera::Transfer::Spec::DIRECTION_RECEIVE : Aspera::Transfer::Spec::DIRECTION_SEND)
|
|
142
|
+
local_remote = %w[local remote].map { |i| session[i]['path'] }
|
|
143
|
+
end
|
|
144
|
+
# `conf` is quiet by default
|
|
145
|
+
session['quiet'] = false if !session.key?('quiet') && Environment.terminal?
|
|
146
|
+
end
|
|
147
|
+
if direction
|
|
148
|
+
Aspera.assert(!session.key?('direction'), type: Cli::BadArgument) { 'direction shall not be in sync_info' }
|
|
149
|
+
session['direction'] = direction.to_s
|
|
150
|
+
# generate name if not provided by user
|
|
151
|
+
if !session.key?('name')
|
|
152
|
+
safe_char = Environment.instance.safe_filename_character
|
|
153
|
+
# from async man page:
|
|
154
|
+
# -N : can contain only ASCII alphanumeric, hyphen, and underscore characters
|
|
155
|
+
session['name'] = Environment.instance.sanitized_filename(
|
|
156
|
+
([direction.to_s] + local_remote).map do |value|
|
|
157
|
+
Pathname(value).each_filename.to_a.last(2).join(safe_char)
|
|
158
|
+
end.join(safe_char).gsub(/[^A-Za-z0-9_-]/, safe_char)
|
|
159
|
+
)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
sync_info
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Sync info of an admin command, which reads the database of the session (directly, or by `asyncadmin`).
|
|
166
|
+
# The database is in the folder given by the argument `path`, or by `sync_info` (`local_db_dir`): that folder is checked against the security level,
|
|
167
|
+
# as the argument (`access: :read`), and so is the database file of the session when it is named (a name can contain `..`, a folder can be a symbolic link).
|
|
168
|
+
# @param path [String] local path, checked against the security level
|
|
169
|
+
# @param sync_info [Hash] extra sync info (may be empty)
|
|
170
|
+
# @return [Hash] sync info
|
|
171
|
+
def admin_sync_info(path:, sync_info:)
|
|
172
|
+
sync_info = async_info_from_args(path: path, sync_info: sync_info)
|
|
173
|
+
security = Cli::Security.instance
|
|
174
|
+
security.readable_path(Sync::Operations.local_db_folder(sync_info))
|
|
175
|
+
security.readable_path(Sync::Operations.session_db_path(sync_info)) unless Sync::Operations.session_name(sync_info).nil?
|
|
176
|
+
sync_info
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Database files of the sync sessions in a folder, that can be read at the security level
|
|
180
|
+
# (the folder of the databases, of a session, or a database file can be a symbolic link).
|
|
181
|
+
# @param local_db_dir [String] folder of the databases, checked against the security level
|
|
182
|
+
# @return [Hash{String => String}] name of session => database file
|
|
183
|
+
def readable_db_files(local_db_dir)
|
|
184
|
+
security = Cli::Security.instance
|
|
185
|
+
Sync::Operations.list_db_files(security.readable_path(local_db_dir)).select { |_, file| security.readable_path?(file) }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Provide database object from path + sync_info for admin ops
|
|
189
|
+
# @param path [String] local path
|
|
190
|
+
# @param sync_info [Hash] extra sync info (may be empty)
|
|
191
|
+
def db_from_args(path:, sync_info: {})
|
|
192
|
+
sync_info = admin_sync_info(path: path, sync_info: sync_info)
|
|
193
|
+
session = sync_info.key?('sessions') ? sync_info['sessions'].first : sync_info
|
|
194
|
+
# if name not provided, check in db folder if there is only one name
|
|
195
|
+
if !session.key?('name')
|
|
196
|
+
local_db_dir = Sync::Operations.local_db_folder(sync_info)
|
|
197
|
+
dbs = readable_db_files(local_db_dir)
|
|
198
|
+
Aspera.assert(dbs.length == 1, type: Cli::BadArgument) { "#{dbs.length} session found in #{local_db_dir}, please provide a name" }
|
|
199
|
+
session['name'] = dbs.keys.first
|
|
200
|
+
end
|
|
201
|
+
Sync::Database.new(Sync::Operations.session_db_file(sync_info))
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def action_sync_admin_file_info(path:, sync_info: {}, **)
|
|
205
|
+
require_relative '../../sync/database'
|
|
206
|
+
result = db_from_args(path: path, sync_info: sync_info).file_info(options.get_option(:sql))
|
|
207
|
+
result.each do |r|
|
|
208
|
+
r['sstate'] = SyncActions::STATE_STR[r['state']] if r['state']
|
|
209
|
+
end
|
|
210
|
+
Cli::Result::ObjectList.new(result, fields: %w[sstate record_id f_meta_path message])
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Analyze async log files: the notable events (conflicts, errors, session lifecycle).
|
|
214
|
+
# @param paths [Array<String, StandardInput>, nil] log files, folders, or the standard input (`-`); already checked against the security level (`access: :read`).
|
|
215
|
+
# When not given, the local async log is read (also checked against the security level).
|
|
216
|
+
def action_sync_logs(paths: nil, **)
|
|
217
|
+
require_relative '../../sync/log_parser'
|
|
218
|
+
files =
|
|
219
|
+
if paths.nil? || paths.empty?
|
|
220
|
+
default = Sync::LogParser.default_log_paths.map { |path| Cli::Security.instance.readable_path(path) }
|
|
221
|
+
Aspera.assert(!default.empty?, type: Cli::BadArgument) { "No async log found at the default location (#{Sync::LogParser.default_location_hint}); give a path" }
|
|
222
|
+
default
|
|
223
|
+
else
|
|
224
|
+
paths
|
|
225
|
+
end
|
|
226
|
+
files.each do |file|
|
|
227
|
+
Aspera.assert(file.is_a?(StandardInput) || File.exist?(file), type: Cli::BadArgument) { "No such file or folder: #{file}" }
|
|
228
|
+
end
|
|
229
|
+
Cli::Result::ObjectList.new(Sync::LogParser.notable_events(files, readable: Cli::Security.instance.method(:readable_path?)), fields: Sync::LogParser::FIELDS)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Execute a sync transfer for a given direction.
|
|
233
|
+
# @param direction [Symbol] one of Sync::Operations::DIRECTIONS (:push, :pull, :bidi)
|
|
234
|
+
# @param path [String] local or remote path (depends on direction)
|
|
235
|
+
# @param sync_info [Hash] extra sync configuration (may be empty)
|
|
236
|
+
# @param block [Proc, nil] block to generate transfer spec; receives (direction, local_dir, remote_dir)
|
|
237
|
+
def run_sync_transfer(direction, path:, sync_info: {}, &block)
|
|
238
|
+
# Not a transfer of `TransferAgent`: the sync session runs the local `async` program on a local folder, so it is refused at level `high`,
|
|
239
|
+
# as an agent that runs on the local host (see `Cli::Security` and `TransferAgent`).
|
|
240
|
+
Cli::Security.instance.check_level(:medium, 'sync (local async)')
|
|
241
|
+
transfer.assert_no_dry_run
|
|
242
|
+
Sync::Operations.start(
|
|
243
|
+
async_info_from_args(path: path, sync_info: sync_info, direction: direction),
|
|
244
|
+
transfer.user_transfer_spec,
|
|
245
|
+
agent_options: transfer.sync_agent_options,
|
|
246
|
+
&block
|
|
247
|
+
)
|
|
248
|
+
Cli::Result::Success.new
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'async_transfer_store'
|
|
7
|
+
require_relative '../../agent/factory'
|
|
8
|
+
require_relative '../../log'
|
|
9
|
+
require_relative '../../assert'
|
|
10
|
+
|
|
11
|
+
module Aspera
|
|
12
|
+
module Plugins
|
|
13
|
+
module Xfer
|
|
14
|
+
# Mounted on plugin config (manifest `mounts`): async transfer management actions.
|
|
15
|
+
# Exposes three sub-commands under `config agents jobs` (`config transfer` is a deprecated alias):
|
|
16
|
+
# status <job_id> Re-query a running/completed transfer
|
|
17
|
+
# list List all persisted async transfer entries (jobs not ended are re-queried)
|
|
18
|
+
# cleanup Remove completed/failed/cancelled entries
|
|
19
|
+
#
|
|
20
|
+
# Architecture:
|
|
21
|
+
# - remote-daemon agents (desktop, node, connect, transferd): transfer_id + agent_params
|
|
22
|
+
# are persisted in AsyncTransferStore (without secrets, taken from current options);
|
|
23
|
+
# status is re-queried via Agent::Xxx.transfer_status
|
|
24
|
+
# - direct agent: transfers live in Ruby threads - store is the agent's @sessions;
|
|
25
|
+
# status is not persistable across process restarts (returns an informational message)
|
|
26
|
+
# A status `unknown` (agent not reachable, missing secret, agent of another process...) does not replace the saved status.
|
|
27
|
+
module TransferActions
|
|
28
|
+
# Statuses after which a job does not change: its agent is not queried again
|
|
29
|
+
TERMINAL_STATUSES = %w[completed failed cancelled].freeze
|
|
30
|
+
# Fields of the result of a previous query that a new status replaces, also when it does not have them
|
|
31
|
+
QUERY_FIELDS = %w[error error_code note].freeze
|
|
32
|
+
# Columns of `list`
|
|
33
|
+
LIST_FIELDS = %w[job_id agent_type status started_at ended_at bytes_transferred transfer_id].freeze
|
|
34
|
+
# Jobs of `list` whose agent is queried at the same time: an agent that does not answer costs its call timeout once per batch, not once per job
|
|
35
|
+
MAX_PARALLEL_QUERIES = 10
|
|
36
|
+
private_constant :TERMINAL_STATUSES, :QUERY_FIELDS, :LIST_FIELDS, :MAX_PARALLEL_QUERIES
|
|
37
|
+
|
|
38
|
+
# Re-query the status of a single async transfer job.
|
|
39
|
+
# When its agent gives no status, the saved state is shown, with the reason (`error` or `note`).
|
|
40
|
+
# @param job_id [String] UUID returned at submission time
|
|
41
|
+
def action_agents_jobs_status(job_id:, **)
|
|
42
|
+
store = async_transfer_store
|
|
43
|
+
entry = store.read(job_id)
|
|
44
|
+
Aspera.assert(!entry.nil?, type: Cli::BadArgument) { "Unknown job_id: #{job_id}" }
|
|
45
|
+
entry, not_refreshed = refresh_job(store, entry)
|
|
46
|
+
Cli::Result::SingleObject.new(entry.merge(not_refreshed || {}))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# List async transfer jobs: the jobs not ended are re-queried as with `status`, else their saved state is shown, with a warning.
|
|
50
|
+
# Their agents are queried in parallel, by batches of `MAX_PARALLEL_QUERIES`.
|
|
51
|
+
def action_agents_jobs_list(**)
|
|
52
|
+
store = async_transfer_store
|
|
53
|
+
entries = store.list
|
|
54
|
+
live_statuses = query_live_statuses(entries.reject { |entry| ended?(entry) }.map { |entry| query_entry(store, entry) })
|
|
55
|
+
# Job identifiers by reason of a status not refreshed: one warning for each reason
|
|
56
|
+
not_refreshed_jobs = Hash.new { |hash, reason| hash[reason] = [] }
|
|
57
|
+
rows = entries.map do |entry|
|
|
58
|
+
next entry if ended?(entry)
|
|
59
|
+
entry, not_refreshed = apply_live_status(store, entry, live_statuses[entry['job_id']])
|
|
60
|
+
not_refreshed_jobs[not_refreshed['error']].push(entry['job_id']) if not_refreshed&.key?('error')
|
|
61
|
+
entry
|
|
62
|
+
end
|
|
63
|
+
not_refreshed_jobs.each { |reason, job_ids| Log.log.warn { "Status not refreshed for job #{job_ids.join(', ')}: #{reason}" } }
|
|
64
|
+
Cli::Result::ObjectList.new(rows, fields: LIST_FIELDS)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Delete completed, failed, and cancelled entries from the store.
|
|
68
|
+
def action_agents_jobs_cleanup(**)
|
|
69
|
+
store = async_transfer_store
|
|
70
|
+
deleted = store.list
|
|
71
|
+
.select { |e| TERMINAL_STATUSES.include?(e['status']) }
|
|
72
|
+
.map do |e|
|
|
73
|
+
store.delete(e['job_id'])
|
|
74
|
+
e['job_id']
|
|
75
|
+
end
|
|
76
|
+
Cli::Result::Status.new("Deleted #{deleted.size} completed transfer(s)#{": #{deleted.join(', ')}" unless deleted.empty?}")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
# Status of a job from its agent, if not ended: saved when the agent gives it
|
|
82
|
+
# @param store [AsyncTransferStore] Store of the jobs
|
|
83
|
+
# @param entry [Hash] Saved entry of the job
|
|
84
|
+
# @return [Array(Hash, Hash)] The entry, refreshed if the agent gave a status; and if it did not: the reason (`error` or `note` of the agent, can be empty), else `nil`
|
|
85
|
+
def refresh_job(store, entry)
|
|
86
|
+
return [entry, nil] if ended?(entry)
|
|
87
|
+
apply_live_status(store, entry, query_live_status(query_entry(store, entry)))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @param entry [Hash] Saved entry of a job
|
|
91
|
+
# @return [Boolean] `true` if the job does not change: its agent is not queried again
|
|
92
|
+
def ended?(entry) = TERMINAL_STATUSES.include?(entry['status'])
|
|
93
|
+
|
|
94
|
+
# @param store [AsyncTransferStore] Store of the jobs
|
|
95
|
+
# @param entry [Hash] Saved entry of the job
|
|
96
|
+
# @return [Hash] The entry with the parameters of its agent for a query, not saved: secrets of the current options, reference of an in-process agent
|
|
97
|
+
def query_entry(store, entry)
|
|
98
|
+
# Secrets are not persisted: take them from current transfer options (e.g. `--transfer`), for the same agent type
|
|
99
|
+
agent_params = current_agent_params(entry['agent_type']).merge(entry['agent_params'] || {})
|
|
100
|
+
# Inject the in-process agent reference (direct/httpgw) if still alive in this process.
|
|
101
|
+
ref = store.agent_ref(entry['job_id'])
|
|
102
|
+
agent_params['_agent_ref'] = ref if ref
|
|
103
|
+
entry.merge('agent_params' => agent_params)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Save the status given by the agent of a job
|
|
107
|
+
# @param store [AsyncTransferStore] Store of the jobs
|
|
108
|
+
# @param entry [Hash] Saved entry of the job
|
|
109
|
+
# @param live [Hash, nil] Status given by the agent, `nil`: the agent could not be queried
|
|
110
|
+
# @return [Array(Hash, Hash)] See `refresh_job`
|
|
111
|
+
def apply_live_status(store, entry, live)
|
|
112
|
+
# No status from the agent: the saved one is kept
|
|
113
|
+
return [entry, (live || {}).slice(*QUERY_FIELDS)] if live.nil? || live['status'].eql?('unknown')
|
|
114
|
+
entry = entry.except(*QUERY_FIELDS).merge(live)
|
|
115
|
+
store.write(entry['job_id'], entry)
|
|
116
|
+
[entry, nil]
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Query the agents of several jobs, `MAX_PARALLEL_QUERIES` at the same time.
|
|
120
|
+
# Only the calls to the agents are in threads: the classes of the agents are loaded before, the store is written after.
|
|
121
|
+
# @param entries [Array<Hash>] Entries of jobs, see `query_entry`
|
|
122
|
+
# @return [Hash{String => Hash, nil}] Status of each job, by `job_id`, see `query_live_status`
|
|
123
|
+
def query_live_statuses(entries)
|
|
124
|
+
agent_classes = entries.map { |entry| entry['agent_type'] }.uniq.to_h { |agent_type| [agent_type, agent_class_of(agent_type)] }
|
|
125
|
+
entries.each_slice(MAX_PARALLEL_QUERIES).each_with_object({}) do |batch, statuses|
|
|
126
|
+
batch
|
|
127
|
+
.map { |entry| Thread.new { [entry['job_id'], query_live_status(entry, agent_classes[entry['agent_type']])] } }
|
|
128
|
+
.each { |thread| statuses.store(*thread.value) }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# @param agent_type [String] Agent of a job
|
|
133
|
+
# @return [Class, StandardError] Class of the agent: the file of the entry of its bundle, or the error that prevents loading it
|
|
134
|
+
def agent_class_of(agent_type)
|
|
135
|
+
Aspera::Agent::Factory.instance.agent_class(agent_type)
|
|
136
|
+
rescue StandardError => e
|
|
137
|
+
e
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# @param agent_type [String] agent of the async transfer
|
|
141
|
+
# @return [Hash] agent parameters from current transfer options (e.g. `--transfer`), if for the same agent type
|
|
142
|
+
def current_agent_params(agent_type)
|
|
143
|
+
current = context.transfer.transfer_options
|
|
144
|
+
return {} unless (current['agent'] || 'direct').to_s.eql?(agent_type)
|
|
145
|
+
current.except('agent', 'asynchronous')
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Lazy accessor - requires context.persistency (available in all Base sub-classes).
|
|
149
|
+
# Delegate to the TransferAgent's store so that the in-memory agent-ref
|
|
150
|
+
# registry is shared between the two components in the same process.
|
|
151
|
+
def async_transfer_store
|
|
152
|
+
context.transfer.async_store
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Delegate to the appropriate agent class method.
|
|
156
|
+
# All agent types are supported:
|
|
157
|
+
# - in-process agents (direct, httpgw): re-queryable while the same process lives
|
|
158
|
+
# (e.g. MCP mode); '_agent_ref' in agent_params points to the live instance.
|
|
159
|
+
# When the process has restarted, '_agent_ref' is nil and transfer_status returns
|
|
160
|
+
# {'status' => 'unknown'} — which is the correct and safe answer.
|
|
161
|
+
# - daemon agents (node, desktop, connect, transferd): re-query via their REST/IPC API.
|
|
162
|
+
# @param entry [Hash] Entry of the job, see `query_entry`
|
|
163
|
+
# @param agent_class [Class, StandardError, nil] Class of its agent, see `agent_class_of`; `nil`: loaded here
|
|
164
|
+
# @return [Hash, nil] Status given by the agent, `nil`: it could not be queried (warning)
|
|
165
|
+
def query_live_status(entry, agent_class = nil)
|
|
166
|
+
agent_class ||= agent_class_of(entry['agent_type'])
|
|
167
|
+
raise agent_class if agent_class.is_a?(StandardError)
|
|
168
|
+
agent_class.transfer_status(entry['transfer_id'], entry['agent_params'] || {})
|
|
169
|
+
rescue StandardError => e
|
|
170
|
+
Log.log.warn { "Could not re-query #{entry['agent_type']} agent for job #{entry['job_id']}: #{e}" }
|
|
171
|
+
nil
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|