rest-ftp-daemon 0.502.2 → 1.0.1

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: 573b07519ccc821dbdf7538ebe9ec88ea2708733
4
- data.tar.gz: 5acfd25ef2fed2fa3b6f6528135dd63d9e0e3856
3
+ metadata.gz: a5e2703802ed5c64bd834898aa2e689a03e7db00
4
+ data.tar.gz: bd4dd0c7f81f402269e088c66d25fefa54b44da1
5
5
  SHA512:
6
- metadata.gz: 89b157d7ad8a49171d7510199095b7f14890b4cc63c8e9d6e12b9a215975dd8cca10138e51e77f3aed792a21baaefbb9e81db2a57b50a1b007dbfa95f619a296
7
- data.tar.gz: 8c87f9dda89e8f628936422abc34b8d05a56e55c2136f69939b412c36b5921ad4b328b8e1b258249d434fd8bd0c83ec7efdc9737545d1bc1480b60e7bb46f016
6
+ metadata.gz: 912d7b5bf50aef05ca5627d18602a5403bfb3fe6ee3ac6e2ff3d7d0da24cf8ed8bcd23a9deaf9f27338563ba8da1e7589632eaa6475c595c0c7b7f42b9fec19e
7
+ data.tar.gz: 68e8fdc3ad403729d459a497762032baf56e8634e6b198b7492f5343c897198b358a6f3736a0f7e5ac3cfc6db4d13ab47ad26f5a9bec4ce915376a0d6349ca3d
data/.dockerignore ADDED
@@ -0,0 +1,7 @@
1
+ pkg/
2
+ DOC/
3
+ tmp/
4
+ .bundle/
5
+ .git/
6
+ log/
7
+ .idea/
data/Dockerfile CHANGED
@@ -1,21 +1,32 @@
1
1
  # Docker headers
2
2
  FROM ruby:2.3.0-slim
3
3
  MAINTAINER Bruno MEDICI <rest-ftp-daemon@bmconseil.com>
4
+
5
+
6
+ # Environment
4
7
  ENV LANG=C.UTF-8
8
+ ENV INSTALL_PATH /app/
9
+ ENV app /app/
5
10
 
6
11
 
7
12
  # Install packages, and first app gem for caching history only
8
13
  RUN apt-get update && apt-get install -y build-essential git --fix-missing --no-install-recommends
9
- RUN gem install rest-ftp-daemon -v 0.400.0 --no-rdoc --no-ri
14
+ RUN gem install bundler --no-rdoc --no-ri
15
+
10
16
 
17
+ # Change to INSTALL_PATH and install base packages
18
+ WORKDIR $INSTALL_PATH
19
+ ADD Gemfile $INSTALL_PATH
20
+ ADD Gemfile.lock $INSTALL_PATH
21
+ ADD rest-ftp-daemon.gemspec $INSTALL_PATH
22
+ RUN bundle install --system --without="development test" -j4
11
23
 
12
- # Retry a gem install to get newer releases, if Gemfile.lock changed
13
- ADD Gemfile.lock /dev/null
14
- RUN gem install rest-ftp-daemon --no-rdoc --no-ri
15
- # RUN rest-ftp-daemon -v
24
+
25
+ # Install app code
26
+ RUN mkdir -p $INSTALL_PATH
27
+ ADD . $INSTALL_PATH
16
28
 
17
29
 
18
30
  # App run
19
31
  EXPOSE 3000
20
- CMD ["/usr/local/bundle/bin/rest-ftp-daemon", "-p", "3000", "-d", "start"]
21
-
32
+ CMD ["bin/rest-ftp-daemon", "-p", "3000", "-f", "start"]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-ftp-daemon (0.502.2)
4
+ rest-ftp-daemon (1.0.1)
5
5
  activesupport (~> 4.2)
6
6
  api-auth
7
7
  aws-sdk-resources (~> 2)
@@ -38,17 +38,17 @@ GEM
38
38
  public_suffix (~> 2.0, >= 2.0.2)
39
39
  api-auth (2.0.1)
40
40
  ast (2.3.0)
41
- aws-sdk-core (2.6.28)
41
+ aws-sdk-core (2.6.32)
42
42
  aws-sigv4 (~> 1.0)
43
43
  jmespath (~> 1.0)
44
- aws-sdk-resources (2.6.28)
45
- aws-sdk-core (= 2.6.28)
44
+ aws-sdk-resources (2.6.32)
45
+ aws-sdk-core (= 2.6.32)
46
46
  aws-sigv4 (1.0.0)
47
47
  axiom-types (0.1.1)
48
48
  descendants_tracker (~> 0.0.4)
49
49
  ice_nine (~> 0.11.0)
50
50
  thread_safe (~> 0.3, >= 0.3.1)
51
- bmc-daemon-lib (0.5.2)
51
+ bmc-daemon-lib (0.5.3)
52
52
  chamber (~> 2.9.1)
53
53
  builder (3.2.2)
54
54
  chamber (2.9.1)
@@ -85,7 +85,7 @@ GEM
85
85
  grape-entity (0.6.0)
86
86
  activesupport
87
87
  multi_json (>= 1.3.2)
88
- grape-swagger (0.25.1)
88
+ grape-swagger (0.25.2)
89
89
  grape (>= 0.12.0)
90
90
  grape-swagger-entity (0.1.5)
91
91
  grape-entity
@@ -111,7 +111,7 @@ GEM
111
111
  json (1.8.3)
112
112
  method_source (0.8.2)
113
113
  mime-types (2.99.3)
114
- minitest (5.9.1)
114
+ minitest (5.10.1)
115
115
  multi_json (1.12.1)
116
116
  multi_xml (0.5.5)
117
117
  mustermann (0.4.0)
@@ -123,7 +123,7 @@ GEM
123
123
  net-ssh (3.2.0)
124
124
  netrc (0.11.0)
125
125
  newrelic_rpm (3.17.1.326)
126
- parser (2.3.3.0)
126
+ parser (2.3.3.1)
127
127
  ast (~> 2.2)
128
128
  powerpack (0.1.1)
129
129
  pry (0.10.4)
@@ -136,7 +136,7 @@ GEM
136
136
  rack (>= 0.4)
137
137
  rainbow (2.1.0)
138
138
  rake (11.3.0)
139
- representable (3.0.1)
139
+ representable (3.0.2)
140
140
  declarative (~> 0.0.5)
141
141
  uber (>= 0.0.15, < 0.2.0)
142
142
  rest-client (1.8.0)
@@ -158,7 +158,7 @@ GEM
158
158
  diff-lcs (>= 1.2.0, < 2.0)
159
159
  rspec-support (~> 3.5.0)
160
160
  rspec-support (3.5.0)
161
- rubocop (0.45.0)
161
+ rubocop (0.46.0)
162
162
  parser (>= 2.3.1.1, < 3.0)
163
163
  powerpack (~> 0.1)
164
164
  rainbow (>= 1.99.1, < 3.0)
@@ -15,12 +15,15 @@ require_relative "shared/patch_array"
15
15
  require_relative "shared/patch_haml"
16
16
  require_relative "shared/patch_file"
17
17
 
18
- # Project's libs
19
- require_relative "rest-ftp-daemon/constants"
20
- require_relative "rest-ftp-daemon/exceptions"
18
+ # Helpers
21
19
  require_relative "rest-ftp-daemon/helpers/common"
22
20
  require_relative "rest-ftp-daemon/helpers/views"
23
21
  require_relative "rest-ftp-daemon/helpers/api"
22
+ require_relative "rest-ftp-daemon/helpers/transfer"
23
+
24
+ # Project's libs
25
+ require_relative "rest-ftp-daemon/constants"
26
+ require_relative "rest-ftp-daemon/exceptions"
24
27
  require_relative "rest-ftp-daemon/metrics"
25
28
  require_relative "rest-ftp-daemon/paginate"
26
29
  require_relative "rest-ftp-daemon/uri"
@@ -0,0 +1,122 @@
1
+ module RestFtpDaemon
2
+ module TransferHelpers
3
+
4
+ def remote_upload source, target
5
+ # Method assertions
6
+ raise RestFtpDaemon::AssertionFailed, "remote_upload/remote" if @remote.nil?
7
+ raise RestFtpDaemon::AssertionFailed, "remote_upload/source" if source.nil?
8
+ raise RestFtpDaemon::AssertionFailed, "remote_upload/target" if target.nil?
9
+
10
+ # Use source filename if target path provided none (typically with multiple sources)
11
+ log_info "remote_upload temp[#{@tempfile}] source[#{source.path}] target[#{target.path}]"
12
+ set_info INFO_SOURCE_CURRENT, source.name
13
+
14
+ # Remove any existing version if present, or check if it's there
15
+ if @overwrite
16
+ @remote.remove! target
17
+ elsif (size = @remote.size_if_exists(target)) # won't be triggered when NIL or 0 is returned
18
+ log_debug "remote_upload file exists ! (#{format_bytes size, 'B'})"
19
+ raise RestFtpDaemon::TargetFileExists
20
+ end
21
+
22
+ # Start transfer
23
+ transfer_started_at = Time.now
24
+ @last_notify_at = transfer_started_at
25
+
26
+ # Start the transfer, update job status after each block transfer
27
+ set_status JOB_STATUS_UPLOADING
28
+ @remote.upload source, target, @tempfile do |transferred, name|
29
+ # Update transfer statistics
30
+ update_progress transferred, name
31
+ end
32
+
33
+ # Compute final bitrate
34
+ global_transfer_bitrate = get_bitrate @transfer_total, (Time.now - transfer_started_at)
35
+ set_info INFO_TRANFER_BITRATE, global_transfer_bitrate.round(0)
36
+
37
+ # Done
38
+ set_info INFO_SOURCE_CURRENT, nil
39
+ end
40
+
41
+ def update_progress transferred, name = ""
42
+ # Update counters
43
+ @transfer_sent += transferred
44
+ set_info INFO_TRANFER_SENT, @transfer_sent
45
+
46
+ # Update job info
47
+ percent0 = (100.0 * @transfer_sent / @transfer_total).round(0)
48
+ set_info INFO_TRANFER_PROGRESS, percent0
49
+
50
+ # Update bitrates
51
+ @current_bitrate = running_bitrate @transfer_sent
52
+ set_info INFO_TRANFER_BITRATE, @current_bitrate.round(0)
53
+
54
+ # What's current time ?
55
+ now = Time.now
56
+
57
+ # Notify if requested
58
+ progress_notify now, percent0, name
59
+
60
+ # Touch my worker status
61
+ touch_job
62
+ end
63
+
64
+ private
65
+
66
+ def progress_notify now, percent0, name
67
+ # No delay provided ?
68
+ return if @config[:notify_after].nil?
69
+
70
+ # Still too early to notify again ?
71
+ how_long_ago = (now.to_f - @last_notify_at.to_f)
72
+ return unless how_long_ago > @config[:notify_after]
73
+
74
+ # # Update bitrates
75
+ # @current_bitrate = running_bitrate @transfer_sent
76
+ # set_info INFO_TRANFER_BITRATE, @current_bitrate.round(0)
77
+
78
+ # Log progress
79
+ stack = [
80
+ "#{percent0} %",
81
+ format_bytes(@transfer_sent, "B"),
82
+ format_bytes(@current_bitrate.round(0), "bps")
83
+ ]
84
+ stack2 = stack.map { |txt| ("%#{LOG_PIPE_LEN.to_i}s" % txt) }.join("\t")
85
+ log_info "progress #{stack2} \t#{name}"
86
+
87
+ # Prepare and send notification
88
+ client_notify :progress, status: {
89
+ progress: percent0,
90
+ transfer_sent: @transfer_sent,
91
+ transfer_total: @transfer_total,
92
+ transfer_bitrate: @current_bitrate.round(0),
93
+ transfer_current: name,
94
+ }
95
+
96
+ # Remember when we last did it
97
+ @last_notify_at = now
98
+ end
99
+
100
+ def get_bitrate delta_data, delta_time
101
+ return nil if delta_time.nil? || delta_time.zero?
102
+ 8 * delta_data.to_f.to_f / delta_time
103
+ end
104
+
105
+ def running_bitrate current_data
106
+ return if @last_time.nil?
107
+
108
+ # Compute deltas
109
+ @last_data ||= 0
110
+ delta_data = current_data - @last_data
111
+ delta_time = Time.now - @last_time
112
+
113
+ # Update counters
114
+ @last_time = Time.now
115
+ @last_data = current_data
116
+
117
+ # Return bitrate
118
+ get_bitrate delta_data, delta_time
119
+ end
120
+
121
+ end
122
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RestFtpDaemon
4
4
  class JobTransfer < Job
5
+ include TransferHelpers
5
6
 
6
7
  protected
7
8
 
@@ -111,126 +112,8 @@ module RestFtpDaemon
111
112
  RestFtpDaemon::Counters.instance.add :data, :transferred, @transfer_total
112
113
  end
113
114
 
114
- def remote_upload source, target
115
- # Method assertions
116
- raise RestFtpDaemon::AssertionFailed, "remote_upload/remote" if @remote.nil?
117
- raise RestFtpDaemon::AssertionFailed, "remote_upload/source" if source.nil?
118
- raise RestFtpDaemon::AssertionFailed, "remote_upload/target" if target.nil?
119
-
120
- # Use source filename if target path provided none (typically with multiple sources)
121
- log_info "remote_upload temp[#{@tempfile}] source[#{source.path}] target[#{target.path}]"
122
- set_info INFO_SOURCE_CURRENT, source.name
123
-
124
- # Remove any existing version if present, or check if it's there
125
- if @overwrite
126
- @remote.remove! target
127
- elsif (size = @remote.size_if_exists(target)) # won't be triggered when NIL or 0 is returned
128
- log_debug "remote_upload file exists ! (#{format_bytes size, 'B'})"
129
- raise RestFtpDaemon::TargetFileExists
130
- end
131
-
132
- # Start transfer
133
- transfer_started_at = Time.now
134
- @last_notify_at = transfer_started_at
135
-
136
- # Start the transfer, update job status after each block transfer
137
- set_status JOB_STATUS_UPLOADING
138
- @remote.upload source, target, @tempfile do |transferred, name|
139
- # Update transfer statistics
140
- update_progress transferred, name
141
- end
142
-
143
- # Compute final bitrate
144
- global_transfer_bitrate = get_bitrate @transfer_total, (Time.now - transfer_started_at)
145
- set_info INFO_TRANFER_BITRATE, global_transfer_bitrate.round(0)
146
-
147
- # Done
148
- set_info INFO_SOURCE_CURRENT, nil
149
- end
150
-
151
- def update_progress transferred, name = ""
152
- # Update counters
153
- @transfer_sent += transferred
154
- set_info INFO_TRANFER_SENT, @transfer_sent
155
-
156
- # Update job info
157
- percent0 = (100.0 * @transfer_sent / @transfer_total).round(0)
158
- set_info INFO_TRANFER_PROGRESS, percent0
159
-
160
- # Update bitrates
161
- @current_bitrate = running_bitrate @transfer_sent
162
- set_info INFO_TRANFER_BITRATE, @current_bitrate.round(0)
163
-
164
- # What's current time ?
165
- now = Time.now
166
-
167
- # Notify if requested
168
- progress_notify now, percent0, name
169
-
170
- # Touch my worker status
171
- touch_job
172
- end
173
-
174
- private
175
-
176
- def progress_notify now, percent0, name
177
- # No delay provided ?
178
- return if @config[:notify_after].nil?
179
-
180
- # Still too early to notify again ?
181
- how_long_ago = (now.to_f - @last_notify_at.to_f)
182
- return unless how_long_ago > @config[:notify_after]
183
-
184
- # # Update bitrates
185
- # @current_bitrate = running_bitrate @transfer_sent
186
- # set_info INFO_TRANFER_BITRATE, @current_bitrate.round(0)
187
-
188
- # Log progress
189
- stack = [
190
- "#{percent0} %",
191
- format_bytes(@transfer_sent, "B"),
192
- format_bytes(@current_bitrate.round(0), "bps")
193
- ]
194
- stack2 = stack.map { |txt| ("%#{LOG_PIPE_LEN.to_i}s" % txt) }.join("\t")
195
- log_info "progress #{stack2} \t#{name}"
196
-
197
- # Prepare and send notification
198
- client_notify :progress, status: {
199
- progress: percent0,
200
- transfer_sent: @transfer_sent,
201
- transfer_total: @transfer_total,
202
- transfer_bitrate: @current_bitrate.round(0),
203
- transfer_current: name,
204
- }
205
-
206
- # Remember when we last did it
207
- @last_notify_at = now
208
- end
209
-
210
- def get_bitrate delta_data, delta_time
211
- return nil if delta_time.nil? || delta_time.zero?
212
- 8 * delta_data.to_f.to_f / delta_time
213
- end
214
-
215
- def running_bitrate current_data
216
- return if @last_time.nil?
217
-
218
- # Compute deltas
219
- @last_data ||= 0
220
- delta_data = current_data - @last_data
221
- delta_time = Time.now - @last_time
222
-
223
- # Update counters
224
- @last_time = Time.now
225
- @last_data = current_data
226
-
227
- # Return bitrate
228
- get_bitrate delta_data, delta_time
229
- end
230
- end
231
-
232
115
  # NewRelic instrumentation
233
116
  # add_transaction_tracer :prepare, category: :task
234
117
  # add_transaction_tracer :run, category: :task
235
-
118
+ end
236
119
  end
@@ -1,18 +1,19 @@
1
- DOCKER_REPO = "bmedici/rest-ftp-daemon"
1
+ DOCKER_REPO = "bmconseil/rest-ftp-daemon"
2
2
 
3
3
  desc "Build docker image from latest tag"
4
4
 
5
5
  task :dockerize => [] do
6
6
  version = `git describe --tags`.strip
7
+ version += "-dev"
7
8
 
8
9
  puts
9
10
  puts "* build [#{version}]"
11
+ # sh "docker build --build-arg GEM_VERSION=#{version} . -t '#{DOCKER_REPO}:#{version}' -t '#{DOCKER_REPO}:latest'"
10
12
  sh "docker build . -t '#{DOCKER_REPO}:#{version}' -t '#{DOCKER_REPO}:latest'"
11
13
 
12
14
  puts
13
- puts "* push to: [#{DOCKER_REPO}]"
15
+ puts "* push to [#{DOCKER_REPO}]"
14
16
  sh "docker push #{DOCKER_REPO}:#{version}"
15
17
  sh "docker push #{DOCKER_REPO}:latest"
16
-
17
18
  puts
18
19
  end
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  # Project version
5
- spec.version = "0.502.2"
5
+ spec.version = "1.0.1"
6
6
 
7
7
  # Project description
8
8
  spec.name = "rest-ftp-daemon"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-ftp-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.502.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-29 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -411,6 +411,7 @@ extensions: []
411
411
  extra_rdoc_files: []
412
412
  files:
413
413
  - ".codeclimate.yml"
414
+ - ".dockerignore"
414
415
  - ".gitignore"
415
416
  - ".rspec"
416
417
  - ".rubocop.yml"
@@ -439,6 +440,7 @@ files:
439
440
  - lib/rest-ftp-daemon/exceptions.rb
440
441
  - lib/rest-ftp-daemon/helpers/api.rb
441
442
  - lib/rest-ftp-daemon/helpers/common.rb
443
+ - lib/rest-ftp-daemon/helpers/transfer.rb
442
444
  - lib/rest-ftp-daemon/helpers/views.rb
443
445
  - lib/rest-ftp-daemon/initialize.rb
444
446
  - lib/rest-ftp-daemon/job.rb