cantemo-portal-agent 1.0.9 → 1.1.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/exe/cantemo-portal-agent +8 -6
  3. data/lib/cantemo/portal/agent/WatchFolderUtility/foreman.rb +59 -0
  4. data/lib/cantemo/portal/agent/cli/commands/watch_folders-working.rb +237 -0
  5. data/lib/cantemo/portal/agent/cli/commands/watch_folders.rb +63 -0
  6. data/lib/cantemo/portal/agent/version.rb +1 -1
  7. data/lib/envoi/aspera/watch_service/client.rb +397 -0
  8. data/lib/envoi/aspera/watch_service/snapshot.rb +11 -0
  9. data/lib/envoi/aspera/watch_service/subscription.rb +0 -0
  10. data/lib/envoi/aspera/watch_service/watch_folder.rb +322 -0
  11. data/lib/envoi/mam/agent/cli/commands/cantemo-agent.rb +62 -0
  12. data/lib/envoi/mam/agent/cli/commands/cantemo-watch_folders.rb +41 -0
  13. data/lib/envoi/mam/agent/cli/commands/cantemo.rb +5 -0
  14. data/lib/envoi/mam/agent/cli/commands/iconik.rb +21 -11
  15. data/lib/envoi/mam/agent/cli/commands/mediasilo.rb +1 -1
  16. data/lib/envoi/mam/agent/cli/commands/vidispine.rb +7 -4
  17. data/lib/envoi/mam/agent/cli/commands/wiredrive.rb +15 -2
  18. data/lib/envoi/mam/agent/cli/commands.rb +4 -4
  19. data/lib/envoi/mam/agent/cli.rb +3 -3
  20. data/lib/envoi/mam/agent/transfer_client/aspera.rb +145 -7
  21. data/lib/envoi/mam/agent/version.rb +1 -1
  22. data/lib/envoi/mam/agent/watch_folder_utility/foreman.rb +76 -0
  23. data/lib/envoi/mam/agent.rb +6 -1
  24. data/lib/envoi/mam/cantemo/agent/watch_folder_handler-working.rb +111 -0
  25. data/lib/envoi/mam/cantemo/agent/watch_folder_handler.rb +176 -0
  26. data/lib/envoi/mam/cantemo/agent/watch_folder_handler_aspera.rb +112 -0
  27. data/lib/envoi/mam/cantemo/agent.rb +288 -0
  28. data/lib/envoi/mam/iconik/agent.rb +15 -3
  29. data/lib/envoi/mam/vidispine/agent.rb +6 -1
  30. data/lib/envoi/watch_folder_utility/watch_folder/handler/listen.rb +189 -0
  31. metadata +48 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54171a0f3c7ff03ad9ea8411d2f0df91ce7b352a
4
- data.tar.gz: 7ca1ab0d8df364f79e19c29c31f315245b797217
3
+ metadata.gz: e52bfb1fe0a32298dab4b64bf2aca6f18fe0f6ab
4
+ data.tar.gz: 3d442e6e485752b2dba2c7bcdaef210dd9398163
5
5
  SHA512:
6
- metadata.gz: 953df856aa882c921ec522d1bea9664fb72f8545af8f488c62b10a9f0d47b11a0dab564c6b1b61399243887263c39cf28777599860f1d4449a625e5c2d7d0450
7
- data.tar.gz: ae7adea3924f9f89d70d00c5a8c07be688eb0a04498557ad078c761d5e68a4b0d82d3f9c97c19fa00bbaaa70c049a83bc1134022976f0e00afb471ec3a2176ce
6
+ metadata.gz: 9bd60ea14fba7a17e322228e074e948165aebb750a264e035cf2728d68d8690158674754040ffd5e1dcf26dd4a2d89df69259b138d52f802798999b8d63f6060
7
+ data.tar.gz: 9db178a801b0656b6a3e737cc904a46ec21ac2d0bc1d30380ed1ff85daa0e753ea1e66aec7309f7f32f9512000ce59f97171e569a2f4a7117e66e830550dff76
@@ -1,17 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ARGV.unshift 'vidispine'
4
3
  should_retry = true
5
4
 
6
5
  begin
7
6
  require 'envoi/mam/agent/cli'
8
7
 
9
- Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS.clear
10
- Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS.concat [
11
- "./cantemo-portal-agent-config.json",
12
- "~/cantemo-portal-agent-config.json",
8
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.clear
9
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.concat [
10
+ './cantemo-portal-agent-config.json',
11
+ '~/cantemo-portal-agent-config.json',
12
+ './.cantemo-portal-agent-config.json',
13
+ '~/.cantemo-portal-agent-config.json',
13
14
  ]
14
- require 'envoi/mam/agent/cli/commands/vidispine'
15
+
16
+ require 'envoi/mam/agent/cli/commands/cantemo'
15
17
  rescue LoadError => e
16
18
  lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../lib', __FILE__)
17
19
  $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exist?(lib_path)
@@ -0,0 +1,59 @@
1
+ require 'envoi/mam/cantemo/agent'
2
+ require 'envoi/aspera/watch_service/watch_folder'
3
+
4
+ module Cantemo
5
+ module Portal
6
+ class Agent
7
+ class WatchFolderUtility
8
+ class Foreman
9
+
10
+ def self.initialize_watch_folder(watch_folder_def)
11
+ case (watch_folder_def['handler'] || '').downcase.gsub(/[-_ ]/, '')
12
+ when 'asperawatch'
13
+ wf_class = Envoi::Aspera::WatchService::WatchFolder
14
+ end
15
+ wf_class.new(watch_folder_def)
16
+ end
17
+
18
+ def self.process_watch_folder_def(watch_folder_def)
19
+ initialize_watch_folder(watch_folder_def)
20
+ end
21
+
22
+ def self.process_watch_folder_defs(watch_folder_defs)
23
+ if watch_folder_defs.is_a?(Array)
24
+ watch_folder_defs.map { |watch_folder_def| process_watch_folder_def(watch_folder_def) }
25
+ elsif watch_folder_defs.is_a?(Hash)
26
+ watch_folder_defs.map do |name, watch_folder_def|
27
+ watch_folder_def['path'] ||= name; process_watch_folder_def(watch_folder_def)
28
+ end
29
+ else
30
+ raise "Unhandled format: #{watch_folder_defs.class.name}"
31
+ end
32
+ end
33
+
34
+ def self.poll_watch_folder(watch_folder, &block)
35
+ watch_folder.poll(&block)
36
+ end
37
+
38
+ def self.poll_watch_folders(watch_folders, &block)
39
+ watch_folders.each { |watch_folder| poll_watch_folder(watch_folder, &block) }
40
+ end
41
+
42
+ def self.run_once(watch_folders, &block)
43
+ poll_watch_folders(watch_folders, &block)
44
+ end
45
+
46
+ # Foreman
47
+ end
48
+
49
+ # WatchFolderUtility
50
+ end
51
+
52
+ # Agent
53
+ end
54
+
55
+ # Mam
56
+ end
57
+
58
+ # Envoi
59
+ end
@@ -0,0 +1,237 @@
1
+ #!/usr/bin/env ruby
2
+ lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../../lib', __FILE__)
3
+ $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exists?(lib_path)
4
+
5
+ require 'rubygems'
6
+ require 'optparse'
7
+ require 'open3'
8
+ require 'pp'
9
+
10
+ require 'envoi/mam/agent/cli'
11
+ require 'envoi/mam/cantemo/agent'
12
+ require 'envoi/aspera/watch_service/watch_folder'
13
+
14
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.clear
15
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.concat [
16
+ './cantemo-portal-agent-config.json',
17
+ '~/cantemo-portal-agent-config.json',
18
+ './.cantemo-portal-agent-config.json',
19
+ '~/.cantemo-portal-agent-config.json',
20
+ ]
21
+ default_config_file_paths = Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS
22
+
23
+ aspera_ascp_paths = Envoi::Mam::Agent::TransferClient::Aspera::ASCP_PATHS
24
+ default_aspera_ascp_path = aspera_ascp_paths.find { |v| File.exist? v } || aspera_ascp_paths.first
25
+
26
+ current_command = ARGV.shift
27
+ ARGV << 'run' if ARGV.empty?
28
+ # ARGV << '--help' if ARGV.empty?
29
+
30
+ @args = {
31
+ :config_file_path => default_config_file_paths,
32
+ :default_ascp_path => default_aspera_ascp_path,
33
+ :dry_run => false,
34
+ :operation => :upload,
35
+ :preserve_path => true,
36
+ :transfer_type => '',
37
+ }
38
+ def args; @args end
39
+
40
+ op = OptionParser.new
41
+ op.on('-c', '--config-file-path FILEPATH', 'The path to the configuration file.',
42
+ "Default Path(s): #{args[:config_file_path]}") { |v| args[:config_file_path] = v }
43
+ op.on('-b', '--[no-]background', 'Tells the application to run in the background.') { |v| args[:daemonize] = v }
44
+ op.on('--help', 'Show this message.') { puts op; exit }
45
+ op.load
46
+ op.parse!
47
+
48
+ config_file_path = args[:config_file_path]
49
+ args[:config_file_path].map! { |v| File.expand_path(v) } if config_file_path.is_a?(Array)
50
+
51
+ control_command_present = %w(start stop restart run zap killall status).include? ARGV.first
52
+
53
+ daemonize = control_command_present || begin
54
+ _d = args[:daemonize]
55
+ end
56
+
57
+
58
+ # puts "#{__FILE__}:#{__LINE__ } #{args}"
59
+ # next_command = ARGV.shift
60
+ # puts "COMMAND: #{next_command}"
61
+
62
+
63
+ module Envoi
64
+
65
+ module WatchFolderUtility
66
+
67
+ class WatchFolder
68
+
69
+ class State
70
+ attr_accessor :known_path_map
71
+ attr_accessor :details
72
+
73
+ def initialize
74
+ @known_path_map = {}
75
+ @details = {}
76
+ end
77
+
78
+ end
79
+
80
+ class Worker
81
+
82
+ attr_accessor :name, :definition, :state, :client, :watcher,
83
+ :previous_poll_time, :last_poll_time
84
+
85
+ def initialize(definition, state = nil, client = nil)
86
+ @definition = definition
87
+ @state = state || State.new
88
+ @client = @watcher = client || Client.new
89
+
90
+ process_definition(definition)
91
+ end
92
+
93
+ end
94
+
95
+ class Foreman
96
+
97
+ attr_accessor :watch_folder_defs
98
+
99
+ AWF = Envoi::Aspera::WatchService::WatchFolder
100
+
101
+ def initialize(args = { })
102
+ initialize_logger(args)
103
+
104
+ @agent = Envoi::Mam::Cantemo::Agent.load_from_config_file(args)
105
+ @config = agent.config
106
+ cantemo_config = config[:cantemo] || config['cantemo']
107
+ @watch_folder_defs = cantemo_config[:watch_folders] || cantemo_config['watch_folders']
108
+
109
+ @ignored_file_paths_by_watch_folder = Hash.new { |h, k| h[k] = [] }
110
+
111
+ @watch_folders = process_watch_folder_defs
112
+ end
113
+
114
+ def process_watch_folder_def(watch_folder_def)
115
+ # @TODO TYPE CHECK
116
+ AWF.process_watch_folder_def(watch_folder_def)
117
+ end
118
+
119
+ def process_watch_folder_defs(watch_folder_defs = @watch_folder_defs)
120
+ watch_folder_defs.map { |wfd| process_watch_folder_def(wfd) }
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+
131
+ class Watcher
132
+
133
+ AWF = Envoi::Aspera::WatchService::WatchFolder
134
+
135
+ attr_accessor :logger, :agent, :config, :watch_folders
136
+
137
+ def initialize(args = { })
138
+ initialize_logger(args)
139
+
140
+ @agent = Envoi::Mam::Cantemo::Agent.load_from_config_file(args)
141
+ @config = agent.config
142
+ cantemo_config = config[:cantemo] || config['cantemo']
143
+ watch_folder_defs = cantemo_config[:watch_folders] || cantemo_config['watch_folders']
144
+
145
+ @ignored_file_paths_by_watch_folder = Hash.new { |h, k| h[k] = [] }
146
+
147
+ @watch_folders = AWF.process_watch_folder_defs(watch_folder_defs)
148
+ pp watch_folders
149
+ end
150
+
151
+ def initialize_logger(args = { })
152
+ @logger = args[:logger] ||= Logger.new(args[:log_to] || STDOUT)
153
+ log_level = args[:log_level]
154
+ if log_level
155
+ @logger.level = log_level
156
+ args[:logger] = @logger
157
+ end
158
+ @logger
159
+ end
160
+
161
+ def add_to_ignore(wf, file)
162
+ @ignored_file_paths_by_watch_folder[wf] << file.path
163
+ end
164
+
165
+ def process_file(watch_folder, full_file_path, storage_id = nil, quarantine_directory_path = nil)
166
+ return unless storage_id
167
+
168
+ if agent.upload(file_path: full_file_path, storage_id: storage_id)
169
+ FileUtils.rm full_file_path
170
+ else
171
+ FileUtils.mv full_file_path, quarantine_directory_path
172
+ end
173
+ end
174
+
175
+ def process_watch_folder(wf)
176
+ storage_id = wf.definition['upload_to_storage_id'] || wf.definition['storage_id']
177
+ quarantine_directory_path = wf.definition['quarantine_path']
178
+ exclude = wf.definition['exclude']
179
+ min_stable_poll_count = wf.definition['stable_poll_count'] || 3
180
+
181
+ maps = wf.state.details[:maps]
182
+ stable_paths = maps[:stable]
183
+ ignored_files = @ignored_file_paths_by_watch_folder[wf]
184
+ stable_paths.each do |fp, file|
185
+ if exclude
186
+ next if ignored_files.include?(file.path)
187
+ if [*exclude].find { |ep| File.fnmatch(ep, file.path) }
188
+ logger.debug { "Adding File to Ignore Cache: '#{file.path}'"}
189
+ ignored_files << file.path
190
+ next
191
+ end
192
+ end
193
+
194
+ full_file_path = File.join(wf.path, file.path)
195
+
196
+ # pp file
197
+ # puts file_path
198
+ stable_poll_count = file[:stable_poll_count]
199
+
200
+ if stable_poll_count && stable_poll_count > min_stable_poll_count
201
+ if storage_id
202
+ if agent.upload(file_path: full_file_path, storage_id: storage_id)
203
+ FileUtils.rm full_file_path
204
+ else
205
+ FileUtils.mv full_file_path, quarantine_directory_path
206
+ end
207
+ end
208
+
209
+ end
210
+ end
211
+
212
+ # process_watch_folder
213
+ end
214
+
215
+ def run
216
+ # AWF.run_once(watch_folders) { |wf| pp wf }
217
+ AWF.run(watch_folders) { |wf| process_watch_folder(wf) }
218
+ end
219
+
220
+ def run_once
221
+ AWF.run_once(watch_folders) { |wf| process_watch_folder(wf) }
222
+ end
223
+
224
+ def self.run(args)
225
+ w = self.new(args)
226
+ w.run
227
+ end
228
+
229
+ def self.run_as_daemon(args)
230
+ # ARGV.unshift 'run' unless %w(start stop restart run zap killall status).include? ARGV.first
231
+ require 'daemons'
232
+ Daemons.run_proc('cantemo-portal-agent-watch-folders') { self.run(args) }
233
+ end
234
+
235
+ end
236
+
237
+ # daemonize ? Watcher.run_as_daemon(args) : Watcher.run(args)
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../../lib', __FILE__)
3
+ $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exists?(lib_path)
4
+
5
+ require 'rubygems'
6
+ require 'optparse'
7
+ require 'open3'
8
+ require 'pp'
9
+
10
+ require 'envoi/mam/agent/cli'
11
+ require 'envoi/mam/cantemo/agent'
12
+ # require 'envoi/aspera/watch_service/watch_folder'
13
+ require 'envoi/mam/cantemo/agent/watch_folder_handler'
14
+
15
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.clear
16
+ Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS.concat [
17
+ './cantemo-portal-agent-config.json',
18
+ '~/cantemo-portal-agent-config.json',
19
+ './.cantemo-portal-agent-config.json',
20
+ '~/.cantemo-portal-agent-config.json',
21
+ ]
22
+ default_config_file_paths = Envoi::Mam::Agent::CLI::CONFIG_FILE_PATHS
23
+
24
+ # aspera_ascp_paths = Envoi::Mam::Agent::TransferClient::Aspera::ASCP_PATHS
25
+ # default_aspera_ascp_path = aspera_ascp_paths.find { |v| File.exist? v } || aspera_ascp_paths.first
26
+
27
+ current_command = ARGV.shift
28
+ ARGV << 'run' if ARGV.empty?
29
+ # ARGV << '--help' if ARGV.empty?
30
+
31
+ @args = {
32
+ :config_file_path => default_config_file_paths,
33
+ :dry_run => false,
34
+ :operation => :upload,
35
+ :preserve_path => true,
36
+ :transfer_type => '',
37
+ }
38
+ def args; @args end
39
+
40
+ op = OptionParser.new
41
+ op.on('-c', '--config-file-path FILEPATH', 'The path to the configuration file.',
42
+ "Default Path(s): #{args[:config_file_path]}") { |v| args[:config_file_path] = v }
43
+ op.on('-b', '--[no-]background', 'Tells the application to run in the background.') { |v| args[:daemonize] = v }
44
+ op.on('-v', '--version', 'Output the version and exit.') { puts "Version #{Cantemo::Portal::Agent::VERSION}"; exit }
45
+ op.on('--help', 'Show this message.') { puts op; exit }
46
+ op.load
47
+ op.parse!
48
+
49
+ config_file_path = args[:config_file_path]
50
+ args[:config_file_path].map! { |v| File.expand_path(v) } if config_file_path.is_a?(Array)
51
+
52
+ control_command_present = %w(start stop restart run zap killall status).include? ARGV.first
53
+
54
+ daemonize = control_command_present || begin
55
+ _d = args[:daemonize]
56
+ end
57
+
58
+ # puts "#{__FILE__}:#{__LINE__ } #{args}"
59
+ # next_command = ARGV.shift
60
+ # puts "COMMAND: #{next_command}"
61
+
62
+ class Watcher < Envoi::Mam::Cantemo::Agent::WatchFolderHandler; end
63
+ daemonize ? Watcher.run_as_daemon(args) : Watcher.run(args)
@@ -1,7 +1,7 @@
1
1
  module Cantemo
2
2
  module Portal
3
3
  class Agent
4
- VERSION = '1.0.9'.freeze
4
+ VERSION = '1.1.0'.freeze
5
5
  end
6
6
  end
7
7
  end