cantemo-portal-agent 1.2.6 → 1.2.7
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edd73213f17ac2ccac314ef21efd8ee07e68bd77
|
4
|
+
data.tar.gz: f31df7db4af1f985a4f53a870b278c5f0c94b5f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1baaacd2944586fd81f65f7f4e58fb978ed7e641481d064fd3d76378478a93d1c13575fea5ba676fe8d6bd714a9e7fd8a9e0fa8fa722ad22729db331f62cf7c9
|
7
|
+
data.tar.gz: 294f8ee74c1aaad3f5053c1cc8c1338c08c0a45147529aeac48956cd52bb9f65af45c3ee0ce8fc36d8a06f6ad67c0162b76f321d6912791da58a967b3e71af3f
|
@@ -3,58 +3,69 @@ require 'asperalm/fasp/local'
|
|
3
3
|
|
4
4
|
|
5
5
|
|
6
|
+
# module Asperalm
|
7
|
+
# module Fasp
|
8
|
+
# module InstallationExtensions
|
9
|
+
#
|
10
|
+
# PRODUCTS = {
|
11
|
+
# unix: {
|
12
|
+
# :aspera_cli_local => {
|
13
|
+
# :expected=>'Aspera CLI',
|
14
|
+
# :exe_ext=>'',
|
15
|
+
# :app_root=>File.join(Dir.home,'.aspera','cli'),
|
16
|
+
# :run_root=>File.join(Dir.home,'.aspera','cli'),
|
17
|
+
# :sub_bin=>'bin',
|
18
|
+
# :sub_keys=>'etc',
|
19
|
+
# :dsa=>'asperaweb_id_dsa.openssh'
|
20
|
+
# }
|
21
|
+
# }
|
22
|
+
# }
|
23
|
+
#
|
24
|
+
# def find_missing_products(os_type, common_places)
|
25
|
+
# missing_products = []
|
26
|
+
# case os_type
|
27
|
+
# when :unix
|
28
|
+
# extended_products = PRODUCTS[os_type] || { }
|
29
|
+
# extended_products.each do |product_name, product|
|
30
|
+
# product_found = common_places.find do |cp|
|
31
|
+
# cp[:expected] == product[:expected] && cp[:app_root] == product[:app_root]
|
32
|
+
# end
|
33
|
+
# missing_products.push product unless product_found
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# missing_products
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def add_missing_products(os_type, common_places)
|
40
|
+
# missing_products = find_missing_products(os_type, common_places)
|
41
|
+
# common_places.concat missing_products unless missing_products.empty?
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def product_locations
|
45
|
+
# common_places = super
|
46
|
+
# add_missing_products(OpenApplication.current_os_type, common_places)
|
47
|
+
# common_places
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# class Installation
|
53
|
+
# include InstallationExtensions
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
|
6
58
|
module Asperalm
|
7
|
-
module Fasp
|
8
|
-
module InstallationExtensions
|
9
|
-
|
10
|
-
PRODUCTS = {
|
11
|
-
unix: {
|
12
|
-
:aspera_cli_local => {
|
13
|
-
:expected=>'Aspera CLI',
|
14
|
-
:exe_ext=>'',
|
15
|
-
:app_root=>File.join(Dir.home,'.aspera','cli'),
|
16
|
-
:run_root=>File.join(Dir.home,'.aspera','cli'),
|
17
|
-
:sub_bin=>'bin',
|
18
|
-
:sub_keys=>'etc',
|
19
|
-
:dsa=>'asperaweb_id_dsa.openssh'
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
def find_missing_products(os_type, common_places)
|
25
|
-
missing_products = []
|
26
|
-
case os_type
|
27
|
-
when :unix
|
28
|
-
extended_products = PRODUCTS[os_type] || { }
|
29
|
-
extended_products.each do |product_name, product|
|
30
|
-
product_found = common_places.find do |cp|
|
31
|
-
cp[:expected] == product[:expected] && cp[:app_root] == product[:app_root]
|
32
|
-
end
|
33
|
-
missing_products.push product unless product_found
|
34
|
-
end
|
35
|
-
end
|
36
|
-
missing_products
|
37
|
-
end
|
38
59
|
|
39
|
-
|
40
|
-
missing_products = find_missing_products(os_type, common_places)
|
41
|
-
common_places.concat missing_products unless missing_products.empty?
|
42
|
-
end
|
60
|
+
class Log
|
43
61
|
|
44
|
-
|
45
|
-
common_places = super
|
46
|
-
add_missing_products(OpenApplication.current_os_type, common_places)
|
47
|
-
common_places
|
48
|
-
end
|
62
|
+
def logger=(new_logger) @logger = new_logger end
|
49
63
|
|
50
|
-
end
|
51
|
-
|
52
|
-
class Installation
|
53
|
-
include InstallationExtensions
|
54
|
-
end
|
55
64
|
end
|
65
|
+
|
56
66
|
end
|
57
67
|
|
68
|
+
|
58
69
|
module Envoi
|
59
70
|
module Mam
|
60
71
|
class Agent
|
@@ -122,7 +133,9 @@ module Envoi
|
|
122
133
|
env_vars['ASPERA_SCP_PASS'] = aspera_password if aspera_password
|
123
134
|
# env_vars['ASPERA_SCP_TOKEN'] = aspera_token if aspera_token
|
124
135
|
|
125
|
-
ascp_args = config['ascp_args'] ||
|
136
|
+
ascp_args = config['ascp_args'] ||
|
137
|
+
default_ascp_args ||
|
138
|
+
(agent.respond_to?(:default_ascp_args) ? agent.default_ascp_args : '')
|
126
139
|
|
127
140
|
tags = config['tags'] ||= { }
|
128
141
|
aspera_tags = tags['aspera'] ||= { }
|
@@ -220,7 +233,8 @@ module Envoi
|
|
220
233
|
def transfer_using_asperala(config, mode, source_path, destination_path)
|
221
234
|
args_out = build_asperala_transfer_args(config, mode, source_path, destination_path)
|
222
235
|
@fasp ||= Asperalm::Fasp::Local.instance
|
223
|
-
Asperalm::Log.instance.
|
236
|
+
Asperalm::Log.instance.logger = logger
|
237
|
+
# Asperalm::Log.instance.level = :debug #logger.level
|
224
238
|
@fasp.start_transfer_with_args_env(args_out, {})
|
225
239
|
{ success: true }
|
226
240
|
end
|
@@ -27,6 +27,25 @@ module Envoi::Mam::Cantemo
|
|
27
27
|
|
28
28
|
class WatchFolderManager
|
29
29
|
|
30
|
+
class MultiIO
|
31
|
+
def initialize(*targets)
|
32
|
+
@targets = targets
|
33
|
+
end
|
34
|
+
|
35
|
+
def write(*args)
|
36
|
+
@targets.each {|t| t.write(*args)}
|
37
|
+
end
|
38
|
+
|
39
|
+
def close
|
40
|
+
@targets.each(&:close)
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_target(*target)
|
44
|
+
@targets.concat target
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
30
49
|
# AWF = Envoi::Aspera::WatchService::WatchFolder # Aspera Watch Folder
|
31
50
|
LWF = Envoi::WatchFolderUtility::WatchFolder::Handler::Listen # Listen Watch Folder
|
32
51
|
|
@@ -45,39 +64,51 @@ module Envoi::Mam::Cantemo
|
|
45
64
|
initialize_logger_from_config
|
46
65
|
args[:logger] = @logger
|
47
66
|
|
48
|
-
|
67
|
+
@ignored_file_paths_by_watch_folder = Hash.new { |h, k| h[k] = [] }
|
68
|
+
@ignored_file_paths_lock = Mutex.new
|
69
|
+
|
70
|
+
@threaded = args.fetch(:threaded, config.fetch(:threaded, config.fetch('threaded', true)))
|
71
|
+
|
72
|
+
@default_maximum_active_processors = DEFAULT_WATCH_FOLDER_PROCESSOR_LIMIT
|
73
|
+
@processors_by_watch_folder = Hash.new { |h, k| h[k] = {} }
|
74
|
+
|
75
|
+
@watch_folder_defs = config[:watch_folders] || config['watch_folders']
|
49
76
|
|
50
77
|
@default_agent_class = Envoi::Mam::Cantemo::Agent
|
51
78
|
|
79
|
+
cantemo_config = config[:cantemo] || config['cantemo']
|
52
80
|
if cantemo_config
|
53
81
|
logger.debug { 'Initializing Default Cantemo Portal Agent.' }
|
54
82
|
@default_agent = @default_agent_class.new(args.merge({ config: cantemo_config }))
|
55
83
|
logger.debug { 'Default Cantemo Portal Agent Initialized.' }
|
56
84
|
@default_storages = @default_agent.agent_config_storages
|
85
|
+
|
86
|
+
if !@watch_folder_defs
|
87
|
+
@watch_folder_defs = cantemo_config[:watch_folders] || cantemo_config['watch_folders']
|
88
|
+
end
|
57
89
|
else
|
58
90
|
@default_agent = nil
|
59
91
|
end
|
60
92
|
|
61
|
-
@watch_folder_defs = config[:watch_folders] || config['watch_folders']
|
62
|
-
if !@watch_folder_defs && cantemo_config
|
63
|
-
@watch_folder_defs = cantemo_config[:watch_folders] || cantemo_config['watch_folders']
|
64
|
-
end
|
65
|
-
|
66
|
-
@ignored_file_paths_by_watch_folder = Hash.new { |h, k| h[k] = [] }
|
67
|
-
@ignored_file_paths_lock = Mutex.new
|
68
|
-
|
69
|
-
@threaded = args.fetch(:threaded, config.fetch(:threaded, config.fetch('threaded', true)))
|
70
|
-
|
71
|
-
@default_maximum_active_processors = DEFAULT_WATCH_FOLDER_PROCESSOR_LIMIT
|
72
|
-
@processors_by_watch_folder = Hash.new { |h, k| h[k] = {} }
|
73
|
-
|
74
93
|
process_watch_folder_defs
|
75
94
|
end
|
76
95
|
|
77
96
|
def initialize_logger(args = {})
|
78
|
-
@logger = args[:logger] ||=
|
97
|
+
@logger = args[:logger] ||= begin
|
98
|
+
_log_to = MultiIO.new(STDOUT)
|
99
|
+
log_to = args[:log_to]
|
100
|
+
log_age = args[:log_age] || 'daily'
|
101
|
+
_log_to.add_target(File.open(log_to, 'a')) if log_to
|
102
|
+
_logger = Logger.new(_log_to, log_age)
|
103
|
+
end
|
104
|
+
|
79
105
|
log_level = args[:log_level] ||= Logger::INFO
|
80
106
|
if log_level
|
107
|
+
if log_level.is_a?(String)
|
108
|
+
log_level.downcase!
|
109
|
+
_log_level = %w(fatal error warn info debug).find { |v| v == log_level }
|
110
|
+
log_level = _log_level ? Logger::Severity.const_get(_log_level.to_sym.upcase) : Logger::INFO
|
111
|
+
end
|
81
112
|
@logger.level = log_level
|
82
113
|
end
|
83
114
|
@logger
|
@@ -85,13 +116,7 @@ module Envoi::Mam::Cantemo
|
|
85
116
|
|
86
117
|
def initialize_logger_from_config(_config = @config)
|
87
118
|
logger_args = { }
|
88
|
-
log_to = _config[
|
89
|
-
logger_args[:log_to] = log_to if log_to
|
90
|
-
log_level = _config['log_level']
|
91
|
-
if log_level
|
92
|
-
_log_level = ['fatal', 'error', 'warn', 'info', 'debug'].find { |v| v = log_level.downcase }
|
93
|
-
logger_args[:log_level] = _log_level.upcase if _log_level
|
94
|
-
end
|
119
|
+
[ :log_to, :log_level, :log_age ].each { |k| v = _config[k] || _config[k.to_s]; logger_args[k] = v if v }
|
95
120
|
initialize_logger(logger_args) unless logger_args.empty?
|
96
121
|
end
|
97
122
|
|
@@ -227,6 +252,7 @@ module Envoi::Mam::Cantemo
|
|
227
252
|
end
|
228
253
|
end
|
229
254
|
|
255
|
+
# This should be part of the watch folder but it is here to track active processors globally
|
230
256
|
def process_watch_folder_stable_files(wf, stable_files)
|
231
257
|
active_processors = @processors_by_watch_folder[wf]
|
232
258
|
maximum_active_processors = wf.definition['maximum_active_processors']
|
@@ -269,7 +295,6 @@ module Envoi::Mam::Cantemo
|
|
269
295
|
begin
|
270
296
|
process_file(file)
|
271
297
|
rescue => e
|
272
|
-
logger.error { "Exception '#{e.message}' in thread for `` `#{file.path}`. " }
|
273
298
|
logger.error { "Exception '#{e.message}' in thread for `#{wf.name || wf.paths}` `#{file.path}`. " }
|
274
299
|
raise e
|
275
300
|
ensure
|
@@ -13,13 +13,24 @@ module Envoi
|
|
13
13
|
|
14
14
|
attr_accessor :logger, :definition, :agent, :handler
|
15
15
|
|
16
|
-
attr_accessor :processors
|
16
|
+
attr_accessor :processors, :active_processors
|
17
17
|
|
18
18
|
attr_accessor :last_poll_time,
|
19
19
|
:min_stable_poll_count,
|
20
20
|
:min_stable_time,
|
21
21
|
:poll_interval
|
22
22
|
|
23
|
+
|
24
|
+
class MultiIO
|
25
|
+
def initialize(*targets) @targets = targets end
|
26
|
+
|
27
|
+
def write(*args) @targets.each {|t| t.write(*args)} end
|
28
|
+
|
29
|
+
def close; @targets.each(&:close) end
|
30
|
+
|
31
|
+
def add_target(*target) @targets.concat target end
|
32
|
+
end
|
33
|
+
|
23
34
|
def initialize(args = { })
|
24
35
|
initialize_logger(args)
|
25
36
|
@definition = args[:definition].dup
|
@@ -48,11 +59,22 @@ module Envoi
|
|
48
59
|
end
|
49
60
|
|
50
61
|
def initialize_logger(args = {})
|
51
|
-
@logger = args[:logger] ||=
|
62
|
+
@logger = args[:logger] ||= begin
|
63
|
+
_log_to = MultiIO.new(STDOUT)
|
64
|
+
log_to = args[:log_to]
|
65
|
+
log_age = args[:log_age] || 'daily'
|
66
|
+
_log_to.add_target(File.open(log_to, 'a')) if log_to
|
67
|
+
_logger = Logger.new(_log_to, log_age)
|
68
|
+
end
|
69
|
+
|
52
70
|
log_level = args[:log_level] ||= Logger::INFO
|
53
71
|
if log_level
|
72
|
+
if log_level.is_a?(String)
|
73
|
+
log_level.downcase!
|
74
|
+
_log_level = %w(fatal error warn info debug).find { |v| v == log_level }
|
75
|
+
log_level = _log_level ? Logger::Severity.const_get(_log_level.to_sym.upcase) : Logger::INFO
|
76
|
+
end
|
54
77
|
@logger.level = log_level
|
55
|
-
args[:logger] = @logger
|
56
78
|
end
|
57
79
|
@logger
|
58
80
|
end
|
@@ -61,7 +83,7 @@ module Envoi
|
|
61
83
|
|
62
84
|
@agent ||= begin
|
63
85
|
logger.debug { "Initializing Agent. #{@default_agent_class} #{args}" }
|
64
|
-
_agent = @default_agent_class.new(config: args)
|
86
|
+
_agent = @default_agent_class.new(config: args, logger: logger, default_preserve_file_path: false)
|
65
87
|
logger.debug { "Agent Instance created." }
|
66
88
|
_agent
|
67
89
|
end
|
@@ -105,12 +127,7 @@ module Envoi
|
|
105
127
|
|
106
128
|
def initialize_handler(watch_folder_def = @definition)
|
107
129
|
args_out = {}
|
108
|
-
|
109
|
-
log_to = logging['log_to']
|
110
|
-
log_level = logging['log_level']
|
111
|
-
args_out[:log_to] ||= log_to if log_to && !log_to.empty?
|
112
|
-
args_out[:log_level] ||= log_level if log_level && !log_level.empty?
|
113
|
-
args_out[:logger] ||= logger.dup unless log_to
|
130
|
+
args_out[:logger] ||= logger.dup
|
114
131
|
args_out[:definition] = watch_folder_def
|
115
132
|
|
116
133
|
handler_class = @default_handler_class
|
@@ -337,6 +354,67 @@ module Envoi
|
|
337
354
|
handler.stable_files
|
338
355
|
end
|
339
356
|
|
357
|
+
def process_stable_files
|
358
|
+
active_processors = @processors_by_watch_folder[wf]
|
359
|
+
maximum_active_processors = wf.definition['maximum_active_processors']
|
360
|
+
|
361
|
+
includes = wf.definition['includes']
|
362
|
+
excludes = wf.definition['excludes']
|
363
|
+
|
364
|
+
ignored_file_paths = wf.ignored_file_paths if wf.respond_to?(:ingored_file_paths)
|
365
|
+
unless ignored_file_paths
|
366
|
+
ignored_file_paths = @ignored_file_paths_by_watch_folder[wf]
|
367
|
+
end
|
368
|
+
|
369
|
+
stable_files.each do |file|
|
370
|
+
file.watch_folder ||= wf
|
371
|
+
next if file.respond_to?(:ignore?) ? file.ignore? : ignored_file_paths.include?(file.path)
|
372
|
+
next if file.processing || file.processed
|
373
|
+
|
374
|
+
if includes && !includes.empty?
|
375
|
+
should_include = find_in_patterns(includes, file)
|
376
|
+
unless should_include
|
377
|
+
add_to_ignore(file)
|
378
|
+
next
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
should_exclude = find_in_patterns(excludes, file)
|
383
|
+
if should_exclude
|
384
|
+
add_to_ignore(file)
|
385
|
+
next
|
386
|
+
end
|
387
|
+
|
388
|
+
if @threaded
|
389
|
+
active_processors.keep_if { |k, v| k.processing }
|
390
|
+
if active_processors.length >= maximum_active_processors
|
391
|
+
logger.debug { "Maximum number of active processors reached for watch folder. #{wf.name || wf.paths}" }
|
392
|
+
break
|
393
|
+
end
|
394
|
+
t = Thread.new(file) do |file|
|
395
|
+
wf = file.watch_folder
|
396
|
+
begin
|
397
|
+
process_file(file)
|
398
|
+
rescue => e
|
399
|
+
logger.error { "Exception '#{e.message}' in thread for `#{wf.name || wf.paths}` `#{file.path}`. " }
|
400
|
+
raise e
|
401
|
+
ensure
|
402
|
+
file.processing = false rescue nil
|
403
|
+
end
|
404
|
+
end
|
405
|
+
t.join
|
406
|
+
active_processors[file] = t if file.processing
|
407
|
+
else
|
408
|
+
process_file(file)
|
409
|
+
end
|
410
|
+
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def process_stable_file(file)
|
415
|
+
|
416
|
+
end
|
417
|
+
|
340
418
|
# Converts hash keys to symbols
|
341
419
|
#
|
342
420
|
# @param [Hash] value hash
|