rest-ftp-daemon 0.435.2 → 0.501.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +35 -29
  3. data/config.ru +1 -1
  4. data/defaults.yml +16 -12
  5. data/lib/rest-ftp-daemon.rb +1 -0
  6. data/lib/rest-ftp-daemon/api/config.rb +1 -2
  7. data/lib/rest-ftp-daemon/api/dashboard.rb +6 -4
  8. data/lib/rest-ftp-daemon/api/debug.rb +6 -5
  9. data/lib/rest-ftp-daemon/api/jobs.rb +1 -1
  10. data/lib/rest-ftp-daemon/api/root.rb +11 -10
  11. data/lib/rest-ftp-daemon/api/status.rb +1 -1
  12. data/lib/rest-ftp-daemon/constants.rb +12 -3
  13. data/lib/rest-ftp-daemon/counters.rb +1 -1
  14. data/lib/rest-ftp-daemon/entities/job.rb +1 -5
  15. data/lib/rest-ftp-daemon/entities/location.rb +4 -3
  16. data/lib/rest-ftp-daemon/entities/options.rb +1 -1
  17. data/lib/rest-ftp-daemon/exceptions.rb +1 -1
  18. data/lib/rest-ftp-daemon/helpers/api.rb +1 -1
  19. data/lib/rest-ftp-daemon/helpers/common.rb +1 -1
  20. data/lib/rest-ftp-daemon/helpers/views.rb +29 -10
  21. data/lib/rest-ftp-daemon/initialize.rb +1 -1
  22. data/lib/rest-ftp-daemon/job.rb +11 -13
  23. data/lib/rest-ftp-daemon/job_queue.rb +9 -10
  24. data/lib/rest-ftp-daemon/jobs/dummy.rb +1 -1
  25. data/lib/rest-ftp-daemon/jobs/errors.rb +13 -15
  26. data/lib/rest-ftp-daemon/jobs/transfer.rb +15 -15
  27. data/lib/rest-ftp-daemon/jobs/video.rb +7 -7
  28. data/lib/rest-ftp-daemon/launcher.rb +1 -1
  29. data/lib/rest-ftp-daemon/location.rb +91 -67
  30. data/lib/rest-ftp-daemon/metrics.rb +2 -2
  31. data/lib/rest-ftp-daemon/notification.rb +1 -1
  32. data/lib/rest-ftp-daemon/paginate.rb +1 -1
  33. data/lib/rest-ftp-daemon/remote/base.rb +8 -3
  34. data/lib/rest-ftp-daemon/remote/ftp.rb +18 -18
  35. data/lib/rest-ftp-daemon/remote/s3.rb +100 -41
  36. data/lib/rest-ftp-daemon/remote/sftp.rb +15 -15
  37. data/lib/rest-ftp-daemon/static/css/main.css +34 -4
  38. data/lib/rest-ftp-daemon/uri.rb +1 -1
  39. data/lib/rest-ftp-daemon/views/dashboard.haml +1 -1
  40. data/lib/rest-ftp-daemon/views/dashboard_counters.haml +1 -1
  41. data/lib/rest-ftp-daemon/views/dashboard_footer.haml +1 -1
  42. data/lib/rest-ftp-daemon/views/dashboard_header.haml +1 -1
  43. data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +1 -2
  44. data/lib/rest-ftp-daemon/views/dashboard_rates.haml +1 -1
  45. data/lib/rest-ftp-daemon/views/dashboard_table.haml +8 -5
  46. data/lib/rest-ftp-daemon/views/dashboard_tokens.haml +1 -1
  47. data/lib/rest-ftp-daemon/views/dashboard_workers.haml +1 -1
  48. data/lib/rest-ftp-daemon/worker_pool.rb +2 -2
  49. data/lib/rest-ftp-daemon/workers/conchita.rb +1 -1
  50. data/lib/rest-ftp-daemon/workers/reporter.rb +1 -1
  51. data/lib/rest-ftp-daemon/workers/transfer.rb +3 -3
  52. data/lib/rest-ftp-daemon/workers/worker.rb +1 -1
  53. data/lib/shared/patch_file.rb +5 -0
  54. data/rest-ftp-daemon.gemspec +2 -2
  55. data/spec/spec_helper.rb +2 -1
  56. data/spec/support/request_helpers.rb +1 -1
  57. metadata +6 -5
@@ -29,7 +29,7 @@ module RestFtpDaemon
29
29
  def do_work
30
30
  # Guess source files from disk
31
31
  set_status JOB_STATUS_TRANSFORMING
32
- sources = @source_loc.scan_files
32
+ sources = @source_loc.local_files
33
33
  raise RestFtpDaemon::SourceNotFound if sources.empty?
34
34
 
35
35
  # Add the source file name if none found in the target path
@@ -38,8 +38,9 @@ module RestFtpDaemon
38
38
  log_info "JobVideo.work target_final.path [#{target_final.path}]"
39
39
 
40
40
  # Ensure target directory exists
41
- log_info "JobVideo.work mkdir_p [#{@target_loc.dir}]"
42
- FileUtils.mkdir_p @target_loc.dir
41
+ t_dir = @target_loc.filedir
42
+ log_info "JobVideo.work mkdir_p [#{t_dir}]"
43
+ FileUtils.mkdir_p t_dir
43
44
 
44
45
  # Do the work, for each file
45
46
  set_info INFO_SOURCE_CURRENT, @source_loc.name
@@ -81,10 +82,10 @@ module RestFtpDaemon
81
82
  log_info "JobVideo.ffmpeg_command [#{FFMPEG.ffmpeg_binary}] [#{source.name}] > [#{target.name}]", options
82
83
 
83
84
  # Build command
84
- movie.transcode(target.path, options) do |ffmpeg_progress|
85
+ movie.transcode(target.filepath, options) do |ffmpeg_progress|
85
86
  # set_info :work, :ffmpeg_progress, ffmpeg_progress
86
87
  set_info INFO_TRANFER_PROGRESS, (100.0 * ffmpeg_progress).round(1)
87
- log_debug "progress #{ffmpeg_progress}"
88
+ log_info "progress #{ffmpeg_progress}"
88
89
  end
89
90
  end
90
91
 
@@ -117,7 +118,6 @@ module RestFtpDaemon
117
118
  end
118
119
  end
119
120
 
120
-
121
121
  # require "stringio"
122
122
  # def capture_stderr
123
123
  # real_stderr, $stderr = $stderr, StringIO.new
@@ -125,4 +125,4 @@ end
125
125
  # $stderr.string
126
126
  # ensure
127
127
  # $stderr = real_stderr
128
- # end
128
+ # end
@@ -24,4 +24,4 @@ module RestFtpDaemon
24
24
  end
25
25
 
26
26
  end
27
- end
27
+ end
@@ -8,8 +8,9 @@ module RestFtpDaemon
8
8
  # Accessors
9
9
  attr_accessor :name
10
10
 
11
- attr_reader :original
11
+ attr_reader :url
12
12
  attr_reader :uri
13
+ attr_reader :tokens
13
14
  attr_reader :scheme
14
15
  attr_reader :dir
15
16
 
@@ -22,37 +23,34 @@ module RestFtpDaemon
22
23
  delegate :scheme, :host, :port, :user, :password, :to_s,
23
24
  to: :uri
24
25
 
25
- def initialize original
26
- unless original.is_a? String
27
- raise RestFtpDaemon::AssertionFailed, "location/original/string: #{original.inspect}"
28
- end
26
+ def initialize url
27
+ # Check parameters
28
+ # unless url.is_a? String
29
+ # raise RestFtpDaemon::AssertionFailed, "location/init/string: #{url.inspect}"
30
+ # end
31
+ debug nil
29
32
 
30
- # Strip spaces before/after, copying original "path" at the same time
31
- @original = original
32
- location_uri = original.strip
33
+ @url = url
34
+ debug :url, url
35
+ @tokens = []
33
36
 
34
- # Replace tokens, fix scheme for local paths
35
- resolve_tokens! location_uri
36
- fix_scheme! location_uri
37
+ # Detect tokens in string
38
+ @tokens = detect_tokens(url)
39
+ debug :tokens, @tokens.inspect
37
40
 
38
- # Ensure result does not contain tokens after replacement
39
- detected_tokens = detect_tokens(location_uri)
40
- unless detected_tokens.empty?
41
- raise RestFtpDaemon::JobUnresolvedTokens, 'unresolved tokens: ' + detected_tokens.join(' ')
42
- end
41
+ # First resolve tokens
42
+ resolve_tokens! url
43
+
44
+ # Build URI from parameters
45
+ build_uri url
46
+
47
+ # Extract dir and name
48
+ build_dir_name
43
49
 
44
- # Parse URL and do specific initializations
45
- parse_url location_uri
50
+ # Specific initializations
46
51
  case @uri
47
- when URI::FILE then init_file
48
52
  when URI::S3 then init_aws # Match AWS URL with BUCKET.s3.amazonaws.com
49
53
  end
50
-
51
- # Check that scheme is supported
52
- unless @uri.scheme
53
- raise RestFtpDaemon::SchemeUnsupported, url
54
- # raise RestFtpDaemon::SchemeUnsupported, @uri
55
- end
56
54
  end
57
55
 
58
56
  def is? kind
@@ -60,13 +58,18 @@ module RestFtpDaemon
60
58
  end
61
59
 
62
60
  def path
63
- return @name if @dir.nil?
64
- File.join(@dir.to_s, @name.to_s)
61
+ File.join(@dir.to_s, name.to_s)
62
+ end
63
+
64
+ def filedir
65
+ "/#{@dir}"
66
+ end
67
+ def filepath
68
+ "/#{path}"
65
69
  end
66
- alias :to_s :path
67
70
 
68
- def scan_files
69
- Dir.glob(path).collect do |file|
71
+ def local_files
72
+ Dir.glob("/#{path}").collect do |file|
70
73
  next unless File.readable? file
71
74
  next unless File.file? file
72
75
  # Create a new location object
@@ -76,15 +79,19 @@ module RestFtpDaemon
76
79
 
77
80
  def size
78
81
  return unless uri.is_a? URI::FILE
79
- local_fil_path = path
80
- return unless File.exist? local_fil_path
81
- return File.size local_fil_path
82
+ local_file_path = filepath
83
+ return unless File.exist? local_file_path
84
+ return File.size local_file_path
82
85
  end
83
86
 
84
87
  def generate_temp_name!
85
88
  @name = "#{@name}.temp-#{identifier(JOB_TEMPFILE_LEN)}"
86
89
  end
87
90
 
91
+ # def scheme? condition
92
+ # return @uri.scheme == condition
93
+ # end
94
+
88
95
  private
89
96
 
90
97
  def tokenize item
@@ -92,6 +99,28 @@ module RestFtpDaemon
92
99
  "[#{item}]"
93
100
  end
94
101
 
102
+ def build_uri url
103
+ # Fix scheme if URL as none
104
+ url.gsub! /^\/(.*)/, 'file:/\1'
105
+
106
+ # Parse that URL
107
+ @uri = URI.parse url # rescue nil
108
+ raise RestFtpDaemon::LocationParseError, location_path unless @uri
109
+
110
+ # Remove unnecessary double slahes
111
+ @uri.path.gsub!(/\/+/, '/')
112
+
113
+ # Check we finally have a scheme
114
+ debug :scheme, @uri.scheme
115
+ debug :path, @uri.path
116
+ debug :host, @uri.host
117
+ debug :to_s, @uri.to_s
118
+
119
+ # Raise if still no scheme #FIXME
120
+ raise RestFtpDaemon::SchemeUnsupported, url unless @uri.scheme
121
+ # raise RestFtpDaemon::LocationParseError, base unless @uri
122
+ end
123
+
95
124
  def resolve_tokens! path
96
125
  # Gther endpoints, and copy path string to alter it later
97
126
  endpoints = BmcDaemonLib::Conf[:endpoints]
@@ -107,39 +136,21 @@ module RestFtpDaemon
107
136
  next if to.to_s.empty?
108
137
  path.gsub! tokenize(from), to
109
138
  end
110
- end
111
-
112
- def fix_scheme! path
113
- # path.gsub!(/^\/(.*)/, 'file:///\1')
114
- path.gsub! /^\/(.*)/, 'file:/\1'
115
- end
116
-
117
- def parse_url path
118
- # Parse that URL
119
- @uri = URI.parse path # rescue nil
120
- raise RestFtpDaemon::LocationParseError, location_path unless @uri
121
-
122
- # Path cleanup
123
- cleaned = @uri.path.clone
124
-
125
- # remove_leading_slashes
126
- cleaned.gsub! /^\//, ''
127
-
128
- # remove_multiple_slashes
129
- cleaned.gsub! /([^:])\/\//, '\1/'
130
139
 
131
- # Store URL parts
132
- @dir = extract_dirname cleaned
133
- @name = extract_filename cleaned
140
+ # Ensure result does not contain tokens after replacement
141
+ detected = detect_tokens(path)
142
+ unless detected.empty?
143
+ raise RestFtpDaemon::JobUnresolvedTokens, 'unresolved tokens: ' + detected.join(' ')
144
+ end
134
145
  end
135
146
 
136
- # def init_username
137
- # @uri.user ||= "anonymous"
138
- # end
147
+ def build_dir_name
148
+ # Store URL parts (remove leading slashes in dir)
149
+ @dir = extract_dirname(@uri.path).gsub(/^\//, '')
150
+ @name = extract_filename(@uri.path)
139
151
 
140
- def init_file
141
- # Dir is absolute
142
- @dir = File.join('/', @dir.to_s)
152
+ debug :dir, dir
153
+ debug :name, name
143
154
  end
144
155
 
145
156
  def init_aws
@@ -156,9 +167,6 @@ module RestFtpDaemon
156
167
  # Credentials from config
157
168
  @aws_id = Conf.at(:credentials, @uri.host, :id)
158
169
  @aws_secret = Conf.at(:credentials, @uri.host, :secret)
159
-
160
- # Clear @dir
161
- @dir = nil
162
170
  end
163
171
 
164
172
  def extract_filename path
@@ -174,8 +182,24 @@ module RestFtpDaemon
174
182
  end
175
183
 
176
184
  def detect_tokens item
177
- item.scan /\[[^\[\]]*\]/
185
+ # item.scan /\[([^\[\]]*)\]/
186
+ item.scan(/\[([^\[\]]*)\]/).map(&:first)
187
+ end
188
+
189
+ def debug var, val = nil
190
+ # Read conf if not already cached
191
+ @debug ||= Conf.at(:debug, :location)
192
+
193
+ # Skip if no debug requeste
194
+ return unless @debug
195
+
196
+ # Dump line
197
+ if var.nil?
198
+ printf("|%s \n", "-"*100)
199
+ else
200
+ printf("| %-15s: %s \n", var, val)
201
+ end
178
202
  end
179
203
 
180
204
  end
181
- end
205
+ end
@@ -27,7 +27,7 @@ module RestFtpDaemon
27
27
  # Init
28
28
  counts = {}
29
29
 
30
- RestFtpDaemon::WorkerPool.instance.worker_variables.group_by do |wid, vars|
30
+ WorkerPool.instance.worker_variables.group_by do |wid, vars|
31
31
  vars[:status]
32
32
  end.each do |status, workers|
33
33
  counts[status] = workers.count
@@ -38,4 +38,4 @@ module RestFtpDaemon
38
38
  end
39
39
 
40
40
  end
41
- end
41
+ end
@@ -111,4 +111,4 @@ module RestFtpDaemon
111
111
  end
112
112
 
113
113
  end
114
- end
114
+ end
@@ -64,4 +64,4 @@ module RestFtpDaemon
64
64
  end
65
65
 
66
66
  end
67
- end
67
+ end
@@ -3,6 +3,7 @@ module RestFtpDaemon
3
3
  module Remote
4
4
  class RemoteBase
5
5
  include BmcDaemonLib::LoggerHelper
6
+ include CommonHelpers
6
7
 
7
8
  # Class options
8
9
  attr_reader :log_prefix
@@ -25,12 +26,16 @@ module RestFtpDaemon
25
26
  log_pipe :transfer
26
27
 
27
28
  # Annnounce object
28
- log_info "RemoteBase.initialize debug[#{debug}] target[#{target.path}] "
29
+ log_info "initialize debug[#{debug}] target[#{target.path}] "
29
30
 
30
31
  # Prepare real object
31
32
  prepare
32
33
  end
33
34
 
35
+ def size_if_exists target
36
+ false
37
+ end
38
+
34
39
  def prepare
35
40
  end
36
41
 
@@ -53,7 +58,7 @@ module RestFtpDaemon
53
58
  end
54
59
 
55
60
  def close
56
- log_debug "RemoteBase.close"
61
+ log_debug "close"
57
62
 
58
63
  # Debug mode ?
59
64
  return unless @debug
@@ -85,4 +90,4 @@ module RestFtpDaemon
85
90
 
86
91
  end
87
92
  end
88
- end
93
+ end
@@ -10,6 +10,8 @@ module RestFtpDaemon
10
10
  attr_reader :ftp
11
11
 
12
12
  def prepare
13
+ super
14
+
13
15
  # Create FTP object
14
16
  if @ftpes
15
17
  prepare_ftpes
@@ -19,11 +21,8 @@ module RestFtpDaemon
19
21
  @ftp.passive = true
20
22
  @ftp.debug_mode = @debug
21
23
 
22
- # Config
23
- @chunk_size = JOB_FTP_CHUNKMB.to_i * 1024
24
-
25
24
  # Announce object
26
- log_debug "RemoteFTP.prepare chunk_size:#{@chunk_size}"
25
+ log_debug "prepare chunk_size:#{format_bytes(JOB_FTP_CHUNKMB, "B")}"
27
26
  end
28
27
 
29
28
  def connect
@@ -34,9 +33,9 @@ module RestFtpDaemon
34
33
  @ftp.login @target.user, @target.password
35
34
  end
36
35
 
37
- def present? target
38
- size = @ftp.size target.path
39
- log_debug "RemoteFTP.present? [#{target.name}]"
36
+ def size_if_exists target
37
+ size = @ftp.size target.filepath
38
+ log_debug "size_if_exists [#{target.name}]"
40
39
 
41
40
  rescue Net::FTPPermError
42
41
  return false
@@ -45,15 +44,15 @@ module RestFtpDaemon
45
44
  end
46
45
 
47
46
  def remove! target
48
- @ftp.delete target.path
47
+ @ftp.delete target.filepath
49
48
  rescue Net::FTPPermError
50
- log_debug "RemoteFTP.remove! [#{target.name}] not found"
49
+ log_debug "remove! [#{target.name}] not found"
51
50
  else
52
- log_debug "RemoteFTP.remove! [#{target.name}] removed"
51
+ log_debug "remove! [#{target.name}] removed"
53
52
  end
54
53
 
55
54
  def mkdir directory
56
- log_debug "RemoteFTP.mkdir [#{directory}]"
55
+ log_debug "mkdir [#{directory}]"
57
56
  @ftp.mkdir directory
58
57
 
59
58
  rescue StandardError => ex
@@ -63,7 +62,7 @@ module RestFtpDaemon
63
62
  def chdir_or_create thedir, mkdir = true
64
63
  # Init, extract my parent name and my own name
65
64
  parent, current = split_path(thedir)
66
- log_debug "RemoteFTP.chdir_or_create mkdir[#{mkdir}] dir[#{thedir}] parent[#{parent}] current[#{current}]"
65
+ log_debug "chdir_or_create mkdir[#{mkdir}] dir[#{thedir}] parent[#{parent}] current[#{current}]"
67
66
 
68
67
  # Access this directory
69
68
  begin
@@ -104,21 +103,22 @@ module RestFtpDaemon
104
103
  end
105
104
 
106
105
  # Move to the directory
107
- log_debug "RemoteFTP.upload chdir [#{dest.dir}]"
108
- @ftp.chdir "/#{dest.dir}"
106
+ log_debug "upload chdir [#{dest.filedir}]"
107
+ @ftp.chdir dest.filedir
109
108
 
110
109
  # Do the transfer
111
- log_debug "RemoteFTP.upload putbinaryfile [#{dest.name}]"
112
- @ftp.putbinaryfile source.path, dest.name, @chunk_size do |data|
110
+ log_debug "upload putbinaryfile [#{source.filepath}] [#{dest.name}]"
111
+ @ftp.putbinaryfile source.filepath, dest.name, JOB_FTP_CHUNKMB do |data|
113
112
  # Update job status after this block transfer
114
113
  yield data.bytesize, dest.name
115
114
  end
116
115
 
117
116
  # Move the file back to its original name
118
117
  if use_temp_name
119
- log_debug "RemoteFTP.upload rename [#{dest.name}] > [#{target.name}]"
118
+ log_debug "upload rename [#{dest.name}] > [#{target.name}]"
120
119
  @ftp.rename dest.name, target.name
121
120
  end
121
+
122
122
  end
123
123
 
124
124
  def close
@@ -147,4 +147,4 @@ module RestFtpDaemon
147
147
 
148
148
  end
149
149
  end
150
- end
150
+ end