cantemo-portal-agent 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edd73213f17ac2ccac314ef21efd8ee07e68bd77
4
- data.tar.gz: f31df7db4af1f985a4f53a870b278c5f0c94b5f9
3
+ metadata.gz: 65d5d27c1b9a329675a2f56b9a1fbd2e12a0f6eb
4
+ data.tar.gz: 535b93e6dbd17809b3fa48c3b4d5b2cd4df1ab0d
5
5
  SHA512:
6
- metadata.gz: 1baaacd2944586fd81f65f7f4e58fb978ed7e641481d064fd3d76378478a93d1c13575fea5ba676fe8d6bd714a9e7fd8a9e0fa8fa722ad22729db331f62cf7c9
7
- data.tar.gz: 294f8ee74c1aaad3f5053c1cc8c1338c08c0a45147529aeac48956cd52bb9f65af45c3ee0ce8fc36d8a06f6ad67c0162b76f321d6912791da58a967b3e71af3f
6
+ metadata.gz: b626b4dd6e2f3b54a708213ccb41442513ea2606ce4ae603030a2b577f6d42d02e8681371bf6dc262e433a816bdda96d14e5e76499c3397e5373afa30492b0ed
7
+ data.tar.gz: d0b2c5ba1d5a5d5fde11308928bc1cd89ccd5c1dc106123284b6179db8504b156fa57474e94a5082c167173d1f25b3b06de2e3349ff517f01c5fd80c256dfa95
@@ -11,6 +11,7 @@ require 'envoi/mam/agent/cli'
11
11
  require 'envoi/mam/cantemo/agent'
12
12
  require 'envoi/mam/cantemo/agent/watch_folder_manager'
13
13
 
14
+
14
15
  Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.clear
15
16
  Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.concat [
16
17
  './cantemo-portal-agent-config.json',
@@ -45,15 +46,27 @@ op.on_tail('--help', 'Show this message.') { puts op; exit }
45
46
  op.load
46
47
  op.parse!
47
48
 
49
+ command = (ARGV.first || 'run').downcase
50
+ if command == 'help'
51
+ puts op
52
+ exit
53
+ end
54
+
48
55
  config_file_path = args[:config_file_path]
49
56
  args[:config_file_path].map! { |v| File.expand_path(v) } if config_file_path.is_a?(Array)
50
57
 
51
- command = ARGV.first
52
58
  daemon_control_command_present = command && begin
53
59
  command = command.dup.downcase if command
54
- %w(start stop restart run zap killall status).include?(command)
60
+ %w(start stop restart zap killall status).include?(command)
61
+ end
62
+
63
+ if command == 'run'
64
+ Envoi::Mam::Cantemo::Agent::WatchFolderManager.run(args)
65
+ exit
55
66
  end
56
67
 
68
+
69
+
57
70
  if command
58
71
  case command
59
72
  when 'install'
@@ -73,10 +86,69 @@ should_daemonize = (daemon_control_command_present && %w(start restart).include?
73
86
  # puts "COMMAND: #{next_command}"
74
87
  #
75
88
  #
89
+ #
90
+
91
+ module Application
92
+
93
+ module OS
94
+ def OS.windows?
95
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
96
+ end
97
+
98
+ def OS.mac?
99
+ (/darwin/ =~ RUBY_PLATFORM) != nil
100
+ end
101
+
102
+ def OS.unix?
103
+ !OS.windows?
104
+ end
105
+
106
+ def OS.linux?
107
+ OS.unix? and not OS.mac?
108
+ end
109
+ end
110
+
111
+ class ProcessManager
112
+
113
+ end
114
+
115
+ if OS.windows?
116
+ require 'win32/daemon'
117
+ class Watcher < Win32::Daemon
118
+
119
+ def service_init
120
+
121
+ end
122
+
123
+ def service_main(*args)
124
+ @WatchFolderManager = Envoi::Mam::Cantemo::Agent::WatchFolderManager.run(args)
125
+ end
126
+
127
+ def service_stop
128
+ @WatchFolderManager.stop
129
+ end
130
+
131
+ end
132
+ else
133
+ class Watcher < Envoi::Mam::Cantemo::Agent::WatchFolderManager; end
134
+ end
135
+
136
+
137
+ def run_in_background(args)
138
+
139
+ end
140
+
141
+ def run_in_foreground(args)
142
+ Watcher.run(args)
143
+ end
144
+
145
+ def run(args)
146
+
147
+ end
148
+
149
+ end
150
+
76
151
 
77
- class Watcher < Envoi::Mam::Cantemo::Agent::WatchFolderManager; end
78
- # daemonize ? Watcher.run_as_daemon(args, { force: true }) : Watcher.run(args)
79
- # daemon_control_command_present ? Watcher.run_as_daemon(args) : Watcher.run(args)
80
152
  begin
81
153
  Watcher.run_with_process_manager(args)
82
154
  rescue => e
@@ -1,7 +1,7 @@
1
1
  module Cantemo
2
2
  module Portal
3
3
  class Agent
4
- VERSION = '1.2.7'.freeze
4
+ VERSION = '1.2.8'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,68 +1,10 @@
1
1
  require 'envoi/mam/agent/transfer_client'
2
2
  require 'asperalm/fasp/local'
3
3
 
4
-
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
-
58
4
  module Asperalm
59
-
60
5
  class Log
61
-
62
6
  def logger=(new_logger) @logger = new_logger end
63
-
64
7
  end
65
-
66
8
  end
67
9
 
68
10
 
@@ -77,12 +19,12 @@ module Envoi
77
19
  DEFAULT_ASCP_ARGS = '-v -k3 --overwrite=diff -P 33001'
78
20
 
79
21
  ASCP_PATHS = [
80
- '/usr/local/bin/ascp',
81
- '/usr/bin/ascp',
82
- '/Library/Aspera/bin/ascp',
83
- '~/Applications/Aspera CLI/bin/ascp',
84
- '~/Applications/Aspera Connect.app/Contents/Resources/ascp',
85
- '/Applications/Aspera Connect.app/Contents/Resources/ascp'
22
+ '/usr/local/bin/ascp',
23
+ '/usr/bin/ascp',
24
+ '/Library/Aspera/bin/ascp',
25
+ '~/Applications/Aspera CLI/bin/ascp',
26
+ '~/Applications/Aspera Connect.app/Contents/Resources/ascp',
27
+ '/Applications/Aspera Connect.app/Contents/Resources/ascp'
86
28
  ]
87
29
  ASCP_PATHS.map { |v| File.expand_path(v) }
88
30
 
@@ -117,12 +59,11 @@ module Envoi
117
59
 
118
60
  aspera_token = config['aspera_transfer_token'] || config['aspera_token'] || config['token'] || config['transfer_token']
119
61
  if aspera_username && aspera_password && (aspera_token.nil? || aspera_token.empty?)
120
- _token_string = %(Basic #{["#{aspera_username}:#{aspera_password}"]
62
+ aspera_token = %(Basic #{["#{aspera_username}:#{aspera_password}"]
121
63
  .pack('m')
122
64
  .delete("\r\n")})
123
- aspera_token = _token_string
124
- aspera_password = nil
125
65
  aspera_username = 'xfer'
66
+ aspera_password = nil
126
67
  end
127
68
 
128
69
  # @ascp_path = config['ascp_path'] || default_ascp_path
@@ -175,7 +116,7 @@ module Envoi
175
116
 
176
117
  aspera_token = config['aspera_transfer_token'] || config['aspera_token'] || config['token'] || config['transfer_token']
177
118
  if aspera_username && aspera_password && (aspera_token.nil? || aspera_token.empty?)
178
- _token_string = %(Basic #{["#{aspera_username}:#{aspera_password}"]
119
+ aspera_token = %(Basic #{["#{aspera_username}:#{aspera_password}"]
179
120
  .pack('m')
180
121
  .delete("\r\n")})
181
122
  aspera_username = 'xfer'
@@ -2,8 +2,6 @@ require 'cantemo/portal/api/client'
2
2
  require 'envoi/mam/agent/transfer_client/aspera'
3
3
  require 'envoi/mam/agent/transfer_client/s3'
4
4
 
5
- require 'vidispine/api/utilities'
6
-
7
5
  module Envoi
8
6
 
9
7
  module Mam
@@ -14,7 +12,7 @@ module Envoi
14
12
 
15
13
  DEFAULT_SHAPE_TAG = 'original'
16
14
  DEFAULT_DESTINATION_PATH = '.'
17
- DEFAULT_PRESERVE_FILE_PATH = true
15
+ DEFAULT_PRESERVE_FILE_PATH = false
18
16
 
19
17
  attr_accessor :default_aspera_ascp_args,
20
18
  :default_aspera_ascp_path,
@@ -139,9 +137,8 @@ module Envoi
139
137
  # @option args [String] :transfer_type ('')
140
138
  # @option args [Boolean] :import_file (true)
141
139
  # @option args [Boolean] :preserve_path (storage_config['preserve_path'] || default_preserve_path)
142
- # @return [Hash]
143
- #
144
140
  #
141
+ # @return [Hash]
145
142
  def upload(args = {})
146
143
  _response = {}
147
144
 
@@ -257,6 +254,7 @@ module Envoi
257
254
  #
258
255
  # @return [Hash{ :success->Boolean, :file_create_response->{}, :import_response->{} }]
259
256
  def import_file(args = {})
257
+ logger.debug { "Agent - Import File - Args: #{args}"}
260
258
  _response = args[:response_object] || {}
261
259
 
262
260
  file_path = args[:file_path]
@@ -310,11 +308,12 @@ module Envoi
310
308
  file_id: file_id,
311
309
  storage_path_map: { '/' => storage_id }
312
310
  }
313
- item_add_args.merge(item_add_args_in) if item_add_args_in.is_a?(Hash)
311
+ item_add_args.merge!(item_add_args_in) if item_add_args_in.is_a?(Hash)
314
312
 
315
313
  item_add_options = { }
316
314
  item_add_options.merge!(item_add_options_in) if item_add_options_in.is_a?(Hash)
317
315
 
316
+ logger.debug { "Executing Item Add/Import. ARGS: #{item_add_args} OPTS: #{item_add_options}" }
318
317
  item_shape_import_response = api_client.item_add_using_file_path(item_add_args, item_add_options)
319
318
  end
320
319
  _response[:import_response] = item_shape_import_response
@@ -27,6 +27,7 @@ module Envoi::Mam::Cantemo
27
27
 
28
28
  class WatchFolderManager
29
29
 
30
+
30
31
  class MultiIO
31
32
  def initialize(*targets)
32
33
  @targets = targets
@@ -46,6 +47,20 @@ module Envoi::Mam::Cantemo
46
47
 
47
48
  end
48
49
 
50
+ class MultiLogger
51
+ attr_accessor :targets
52
+
53
+ def initialize(*targets)
54
+ @targets = targets
55
+ end
56
+
57
+ %w(log debug info warn error fatal unknown level=).each do |m|
58
+ define_method(m) do |*args, &block|
59
+ @targets.map { |t| t.send(m, *args, &block) }
60
+ end
61
+ end
62
+ end
63
+
49
64
  # AWF = Envoi::Aspera::WatchService::WatchFolder # Aspera Watch Folder
50
65
  LWF = Envoi::WatchFolderUtility::WatchFolder::Handler::Listen # Listen Watch Folder
51
66
 
@@ -56,8 +71,7 @@ module Envoi::Mam::Cantemo
56
71
  def initialize(args = {})
57
72
  initialize_logger(args)
58
73
 
59
- logger.debug { 'Initializing Agent Watch Folder Manager.' }
60
-
74
+ logger.info { 'Initializing Agent Watch Folder Manager.' }
61
75
  args[:default_preserve_file_path] = args.fetch(:default_preserve_file_path, false)
62
76
 
63
77
  @config = Envoi::Mam::Cantemo::Agent.load_config_from_file(args)
@@ -94,23 +108,18 @@ module Envoi::Mam::Cantemo
94
108
  end
95
109
 
96
110
  def initialize_logger(args = {})
97
- @logger = args[:logger] ||= begin
98
- _log_to = MultiIO.new(STDOUT)
111
+ @logger = MultiLogger.new(Logger.new(STDOUT))
112
+
113
+ _logger = args[:logger] ||= begin
99
114
  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
115
+ log_age = args.fetch(:log_age, 'daily')
104
116
 
105
- log_level = args[:log_level] ||= Logger::INFO
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
112
- @logger.level = log_level
117
+ log_to ? Logger.new(log_to, log_age) : nil
113
118
  end
119
+ @logger.targets << _logger if _logger
120
+
121
+ log_level = args[:log_level] ||= Logger::INFO
122
+ @logger.level = log_level if log_level
114
123
  @logger
115
124
  end
116
125
 
@@ -138,9 +147,9 @@ module Envoi::Mam::Cantemo
138
147
  logging = watch_folder_def['logging'] || watch_folder_def
139
148
  log_to = logging['log_to']
140
149
  log_level = logging['log_level']
141
- args_out[:log_to] ||= log_to if log_to && !log_to.empty?
142
- args_out[:log_level] ||= log_level if log_level && !log_level.empty?
143
- args_out[:logger] ||= logger.dup unless log_to
150
+ # args_out[:log_to] = log_to if log_to && !log_to.empty?
151
+ # args_out[:log_level] = log_level if log_level && !log_level.empty?
152
+ args_out[:logger] = logger # unless log_to
144
153
  args_out[:default_agent] = default_agent
145
154
  args_out[:default_agent_class] = default_agent_class
146
155
  args_out[:definition] = watch_folder_def
@@ -208,6 +217,7 @@ module Envoi::Mam::Cantemo
208
217
  }
209
218
  upload_args.merge!(watch_folder_upload_args) if watch_folder_upload_args.is_a?(Hash)
210
219
 
220
+ logger.debug { "Executing Upload. #{upload_args}" }
211
221
  _response = agent.upload(upload_args)
212
222
  _response = { success: _response } if _response == true || _response == false
213
223
 
@@ -253,7 +263,8 @@ module Envoi::Mam::Cantemo
253
263
  end
254
264
 
255
265
  # This should be part of the watch folder but it is here to track active processors globally
256
- def process_watch_folder_stable_files(wf, stable_files)
266
+ def process_watch_folder_stable_files(wf)
267
+ stable_files = wf.stable_files
257
268
  active_processors = @processors_by_watch_folder[wf]
258
269
  maximum_active_processors = wf.definition['maximum_active_processors']
259
270
 
@@ -325,19 +336,20 @@ module Envoi::Mam::Cantemo
325
336
  end
326
337
 
327
338
  stable_files_by_watch_folder.each do |watch_folder, stable_files|
328
- process_watch_folder_stable_files(watch_folder, stable_files)
339
+ process_watch_folder_stable_files(watch_folder)
329
340
  end
330
341
  end
331
342
 
332
343
  # The main execution method
333
344
  def run
345
+ @should_run = true
346
+
334
347
  # AWF.run_once(watch_folders) { |wf| pp wf }
335
348
  # AWF.run(watch_folders) { |wf| process_watch_folder(wf) }
336
-
337
349
  logger.info { 'Running...' }
338
350
  watch_folders.map { |wf| wf.respond_to?(:run) ? wf.run : logger.debug { "Skip run for #{wf}" } }
339
351
  logger.debug { 'Initial Run Complete.' }
340
- loop do
352
+ while(@should_run) do
341
353
  begin
342
354
  poll
343
355
  sleep 1
@@ -346,19 +358,27 @@ module Envoi::Mam::Cantemo
346
358
  break
347
359
  end
348
360
  end
349
- logger.info { 'Exiting...' }
350
361
  rescue => e
351
362
  logger.debug { "EXCEPTION #{e.message} \n#{e.backtrace.join("\n")}\n" }
352
363
  logger.error { "An error occurred. #{e.message}" }
353
364
  raise e
354
365
  ensure
355
- watch_folders.each { |wf| wf.stop if wf.respond_to?(:stop) }
366
+ stop
367
+ logger.info { 'Exiting...' }
356
368
  end
357
369
 
358
370
  def run_once
359
371
  # AWF.run_once(watch_folders) { |wf| process_watch_folder(wf) }
360
372
  end
361
373
 
374
+ def stop
375
+ if @should_run
376
+ @should_run = false
377
+ logger.info { "Stopping..." }
378
+ watch_folders.each { |wf| wf.stop if wf.respond_to?(:stop) }
379
+ end
380
+ end
381
+
362
382
  # Converts hash keys to symbols
363
383
  #
364
384
  # @param [Hash] value hash
@@ -20,17 +20,6 @@ module Envoi
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
-
34
23
  def initialize(args = { })
35
24
  initialize_logger(args)
36
25
  @definition = args[:definition].dup
@@ -59,23 +48,24 @@ module Envoi
59
48
  end
60
49
 
61
50
  def initialize_logger(args = {})
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
-
70
- log_level = args[:log_level] ||= Logger::INFO
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
77
- @logger.level = log_level
78
- end
51
+ @logger = args[:logger]
52
+ # @logger = args[:logger] ||= begin
53
+ # _log_to = MultiIO.new(STDOUT)
54
+ # log_to = args[:log_to]
55
+ # log_age = args[:log_age] || 'daily'
56
+ # _log_to.add_target(File.open(log_to, 'a')) if log_to
57
+ # _logger = Logger.new(_log_to, log_age)
58
+ # end
59
+ #
60
+ # log_level = args[:log_level] ||= Logger::INFO
61
+ # if log_level
62
+ # if log_level.is_a?(String)
63
+ # log_level.downcase!
64
+ # _log_level = %w(fatal error warn info debug).find { |v| v == log_level }
65
+ # log_level = _log_level ? Logger::Severity.const_get(_log_level.to_sym.upcase) : Logger::INFO
66
+ # end
67
+ # @logger.level = log_level
68
+ # end
79
69
  @logger
80
70
  end
81
71
 
@@ -309,7 +299,7 @@ module Envoi
309
299
  watch_folder_def.delete('import_options')
310
300
 
311
301
  watch_folder_def['upload_args'] = upload_args
312
- logger.debug { "Parameter 'upload/import arguments' initialized." }
302
+ logger.debug { "Parameter 'upload/import arguments' initialized. #{upload_args}" }
313
303
 
314
304
  maximum_active_processors = watch_folder_def['maximum_active_processors']
315
305
  if maximum_active_processors.nil?
@@ -356,12 +346,11 @@ module Envoi
356
346
 
357
347
  def process_stable_files
358
348
  active_processors = @processors_by_watch_folder[wf]
359
- maximum_active_processors = wf.definition['maximum_active_processors']
349
+ maximum_active_processors = definition['maximum_active_processors']
360
350
 
361
- includes = wf.definition['includes']
362
- excludes = wf.definition['excludes']
351
+ includes = definition['includes']
352
+ excludes = definition['excludes']
363
353
 
364
- ignored_file_paths = wf.ignored_file_paths if wf.respond_to?(:ingored_file_paths)
365
354
  unless ignored_file_paths
366
355
  ignored_file_paths = @ignored_file_paths_by_watch_folder[wf]
367
356
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cantemo-portal-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Whitson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2019-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asperalm