uricp 0.0.13 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +20 -23
- data/Jenkinsfile +113 -0
- data/README.md +2 -2
- data/Rakefile +26 -31
- data/bionic/Dockerfile +20 -0
- data/centos7/Dockerfile +18 -0
- data/features/step_definitions/orbit_steps.rb +19 -13
- data/features/step_definitions/uricp_steps.rb +8 -4
- data/focal/Dockerfile +21 -0
- data/lib/segment_upload.rb +20 -22
- data/lib/uricp.rb +3 -29
- data/lib/uricp/curl_primitives.rb +31 -33
- data/lib/uricp/orbit_auth.rb +23 -27
- data/lib/uricp/segmenter.rb +12 -16
- data/lib/uricp/strategy/cache_common.rb +11 -11
- data/lib/uricp/strategy/cached_get.rb +14 -20
- data/lib/uricp/strategy/cleaner.rb +2 -8
- data/lib/uricp/strategy/common.rb +27 -19
- data/lib/uricp/strategy/local_convert.rb +10 -17
- data/lib/uricp/strategy/local_link.rb +10 -8
- data/lib/uricp/strategy/piped_cache.rb +7 -13
- data/lib/uricp/strategy/piped_cache_convert.rb +14 -18
- data/lib/uricp/strategy/piped_compress.rb +3 -8
- data/lib/uricp/strategy/piped_decompress.rb +7 -11
- data/lib/uricp/strategy/piped_local_compress.rb +0 -4
- data/lib/uricp/strategy/piped_local_decompress.rb +10 -16
- data/lib/uricp/strategy/piped_local_get.rb +0 -5
- data/lib/uricp/strategy/piped_local_put.rb +3 -9
- data/lib/uricp/strategy/piped_rbd_get.rb +46 -0
- data/lib/uricp/strategy/piped_remote_get.rb +20 -20
- data/lib/uricp/strategy/rbd_remote_put.rb +36 -0
- data/lib/uricp/strategy/rbd_sweeper.rb +22 -0
- data/lib/uricp/strategy/remote_put.rb +11 -17
- data/lib/uricp/strategy/segmented_remote_put.rb +16 -28
- data/lib/uricp/strategy/sweeper.rb +2 -8
- data/lib/uricp/uri_strategy.rb +14 -13
- data/lib/uricp/version.rb +4 -2
- data/uricp.gemspec +3 -4
- data/xenial/Dockerfile +20 -0
- metadata +39 -51
- data/Dockerfile_centos6.6 +0 -39
- data/Dockerfile_centos7 +0 -39
- data/Dockerfile_trusty-ruby193 +0 -32
- data/README.rdoc +0 -23
- data/spec/something_spec.rb +0 -5
@@ -1,14 +1,11 @@
|
|
1
1
|
module Uricp::Strategy
|
2
|
-
|
3
2
|
class PipedLocalPut
|
4
|
-
|
5
3
|
include Uricp::Strategy::Common
|
6
4
|
|
7
5
|
def appropriate?
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
return proposal if to.scheme == 'file' &&
|
7
|
+
from.scheme == 'pipe'
|
8
|
+
|
12
9
|
debug "#{self.class.name}: not appropriate"
|
13
10
|
false
|
14
11
|
end
|
@@ -22,8 +19,5 @@ module Uricp::Strategy
|
|
22
19
|
@proposed_options['from_uri'] = @proposed_options['to_uri']
|
23
20
|
self
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
|
-
|
28
23
|
end
|
29
|
-
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Uricp::Strategy
|
3
|
+
class PipedRbdGet
|
4
|
+
include Uricp::Strategy::Common
|
5
|
+
include Methadone::SH
|
6
|
+
|
7
|
+
def appropriate?
|
8
|
+
case from.scheme
|
9
|
+
when 'rbd'
|
10
|
+
return proposal unless sequence_complete? || snap_in_progress?
|
11
|
+
end
|
12
|
+
debug "#{self.class.name}: not appropriate"
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def command
|
17
|
+
"rbd snap create --id #{rbd_id} '#{rbd_snap_target(from)}' && " \
|
18
|
+
"rbd export --no-progress --id #{rbd_id} '#{rbd_snap_target(from)}' - |"
|
19
|
+
end
|
20
|
+
|
21
|
+
def proposal
|
22
|
+
@proposed_options = options.dup
|
23
|
+
@proposed_options['rbd_snapshot'] = rbd_snap_target(from)
|
24
|
+
@proposed_options['from_uri'] = PIPE_URI
|
25
|
+
@proposed_options.delete('cache')
|
26
|
+
@proposed_options.delete('cache_name')
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
RBD_SNAPSHOT = 'uricp_snap'.freeze
|
31
|
+
|
32
|
+
def rbd_snap_target(uri)
|
33
|
+
"#{rbd_target(uri)}@#{RBD_SNAPSHOT}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def snap_in_progress?
|
37
|
+
return false if dry_run?
|
38
|
+
|
39
|
+
result = false
|
40
|
+
sh "rbd snap ls --id #{rbd_id} --format json #{rbd_target(from)}" do |stdout|
|
41
|
+
result = JSON.parse(stdout).any? { |x| x['name'] == RBD_SNAPSHOT }
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
module Uricp::Strategy
|
3
|
-
|
4
3
|
class PipedRemoteGet
|
5
|
-
|
6
4
|
include Uricp::Strategy::Common
|
7
5
|
|
8
6
|
def appropriate?
|
@@ -10,33 +8,35 @@ module Uricp::Strategy
|
|
10
8
|
when 'http', 'https'
|
11
9
|
return proposal unless sequence_complete?
|
12
10
|
else
|
13
|
-
|
14
|
-
|
11
|
+
debug "#{self.class.name}: not appropriate"
|
12
|
+
false
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
alias
|
16
|
+
alias command curl_download_to_pipe
|
19
17
|
|
20
18
|
def proposal
|
21
19
|
@proposed_options = options.dup
|
22
20
|
@proposed_options['from_uri'] = PIPE_URI
|
23
21
|
if conversion_required?
|
24
22
|
@proposed_options['source-format'] = format_peek
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
if @proposed_options['source-format'] == @proposed_options['target-format']
|
24
|
+
@proposed_options.delete('source-format')
|
25
|
+
@proposed_options.delete('target-format')
|
26
|
+
end
|
29
27
|
end
|
30
28
|
if options['max-cache'] &&
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
size_peek.to_i > options['max-cache'].to_i
|
30
|
+
@proposed_options.delete('cache')
|
31
|
+
@proposed_options.delete('cache_name')
|
32
|
+
@proposed_options.delete('max-cache')
|
35
33
|
end
|
36
34
|
self
|
37
35
|
end
|
38
36
|
|
39
37
|
def format_peek
|
38
|
+
return options['target-format'] || 'raw' if dry_run?
|
39
|
+
|
40
40
|
options['from_uri'].open(headers) do |u|
|
41
41
|
encoding(u)
|
42
42
|
end
|
@@ -48,14 +48,16 @@ module Uricp::Strategy
|
|
48
48
|
raise
|
49
49
|
end
|
50
50
|
rescue SocketError => e
|
51
|
-
raise SocketError, options['from_uri'].to_s+
|
51
|
+
raise SocketError, options['from_uri'].to_s + ' inaccessible: ' + e.message
|
52
52
|
end
|
53
53
|
|
54
54
|
def size_peek
|
55
|
-
|
55
|
+
return options['max-cache'] if dry_run?
|
56
|
+
|
57
|
+
size_headers = headers
|
56
58
|
size_headers['Range'] = 'bytes=0-0'
|
57
59
|
options['from_uri'].open(headers) do |u|
|
58
|
-
|
60
|
+
match = %r{bytes\s+(\d+)-(\d+)/(\d+|\*)}i.match(u.meta['content-range'])
|
59
61
|
match && match[3].to_i
|
60
62
|
end
|
61
63
|
rescue OpenURI::HTTPError => e
|
@@ -66,15 +68,13 @@ module Uricp::Strategy
|
|
66
68
|
raise
|
67
69
|
end
|
68
70
|
rescue SocketError => e
|
69
|
-
raise SocketError, options['from_uri'].to_s+
|
71
|
+
raise SocketError, options['from_uri'].to_s + ' inaccessible: ' + e.message
|
70
72
|
end
|
71
73
|
|
72
74
|
def headers
|
73
|
-
headers={'Range' => 'bytes=0-7'}
|
75
|
+
headers = { 'Range' => 'bytes=0-7' }
|
74
76
|
headers['X-Auth-Token'] = options['authenticator'].call if http_authentication?
|
75
77
|
headers
|
76
78
|
end
|
77
|
-
|
78
79
|
end
|
79
|
-
|
80
80
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Uricp::Strategy
|
2
|
+
class RbdRemotePut
|
3
|
+
include Uricp::Strategy::Common
|
4
|
+
|
5
|
+
def appropriate?
|
6
|
+
if compression_required? || conversion_required?
|
7
|
+
debug "#{self.class.name}: not ready to upload"
|
8
|
+
return false
|
9
|
+
end
|
10
|
+
case from.scheme
|
11
|
+
when 'pipe', 'file'
|
12
|
+
return proposal if to.scheme == 'rbd'
|
13
|
+
end
|
14
|
+
debug "#{self.class.name}: not appropriate"
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def command
|
19
|
+
"rbd import --no-progress --id #{rbd_id} #{data_source} '#{rbd_target(to)}';"
|
20
|
+
end
|
21
|
+
|
22
|
+
def proposal
|
23
|
+
@proposed_options = options.dup
|
24
|
+
@proposed_options['from_uri'] = to
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def data_source
|
29
|
+
if from.scheme == 'pipe'
|
30
|
+
'-'
|
31
|
+
else
|
32
|
+
"'#{from.path}'"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Uricp::Strategy
|
2
|
+
class RbdSweeper
|
3
|
+
include Uricp::Strategy::Common
|
4
|
+
|
5
|
+
def appropriate?
|
6
|
+
return proposal if options['rbd_snapshot'] && sequence_complete?
|
7
|
+
|
8
|
+
debug "#{self.class.name}: not appropriate"
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def command
|
13
|
+
"rbd snap rm --id #{rbd_id} '#{options['rbd_snapshot']}';"
|
14
|
+
end
|
15
|
+
|
16
|
+
def proposal
|
17
|
+
@proposed_options = options.dup
|
18
|
+
@proposed_options.delete('rbd_snapshot')
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,26 +1,22 @@
|
|
1
1
|
module Uricp::Strategy
|
2
|
-
|
3
2
|
class RemotePut
|
4
|
-
|
5
3
|
include Uricp::Strategy::Common
|
6
4
|
|
7
5
|
def appropriate?
|
8
6
|
if compression_required? || conversion_required?
|
9
7
|
debug "#{self.class.name}: not ready to upload"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
debug "#{self.class.name}: not appropriate"
|
8
|
+
return false
|
9
|
+
end
|
10
|
+
case to.scheme
|
11
|
+
when 'http', 'https'
|
12
|
+
case from.scheme
|
13
|
+
when 'file', 'pipe'
|
14
|
+
return proposal if http_authentication?
|
15
|
+
|
16
|
+
unsupported_transfer
|
17
|
+
end
|
23
18
|
end
|
19
|
+
debug "#{self.class.name}: not appropriate"
|
24
20
|
false
|
25
21
|
end
|
26
22
|
|
@@ -41,7 +37,5 @@ module Uricp::Strategy
|
|
41
37
|
from.path
|
42
38
|
end
|
43
39
|
end
|
44
|
-
|
45
40
|
end
|
46
|
-
|
47
41
|
end
|
@@ -1,35 +1,29 @@
|
|
1
1
|
module Uricp::Strategy
|
2
|
-
|
3
2
|
class SegmentedRemotePut
|
4
|
-
|
5
3
|
include Uricp::Strategy::Common
|
6
4
|
|
7
5
|
def appropriate?
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
when 'file', 'pipe'
|
16
|
-
if http_authentication?
|
17
|
-
return proposal
|
18
|
-
else
|
19
|
-
unsupported_transfer
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
debug "#{self.class.name}: not appropriate"
|
24
|
-
end
|
25
|
-
else
|
26
|
-
debug "#{self.class.name}: no segmentation requested"
|
6
|
+
unless segmented?
|
7
|
+
debug "#{self.class.name}: not appropriate"
|
8
|
+
return false
|
9
|
+
end
|
10
|
+
if compression_required? || conversion_required?
|
11
|
+
debug "#{self.class.name}: not ready to upload"
|
12
|
+
return false
|
27
13
|
end
|
14
|
+
case to.scheme
|
15
|
+
when 'http', 'https'
|
16
|
+
case from.scheme
|
17
|
+
when 'file', 'pipe'
|
18
|
+
return proposal if http_authentication?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
unsupported_transfer
|
28
22
|
false
|
29
23
|
end
|
30
24
|
|
31
25
|
def command
|
32
|
-
"segment_upload --segment-size '#{options['segment-size']}' #{source_details} #{to
|
26
|
+
"segment_upload --segment-size '#{options['segment-size']}' #{source_details} #{to};"
|
33
27
|
end
|
34
28
|
|
35
29
|
def proposal
|
@@ -42,11 +36,5 @@ module Uricp::Strategy
|
|
42
36
|
def source_details
|
43
37
|
"--from #{from.path}" unless from.scheme == 'pipe'
|
44
38
|
end
|
45
|
-
|
46
|
-
def segmented?
|
47
|
-
options['segment-size']
|
48
|
-
end
|
49
|
-
|
50
39
|
end
|
51
|
-
|
52
40
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
module Uricp::Strategy
|
2
|
-
|
3
2
|
class Sweeper
|
4
|
-
|
5
3
|
include Uricp::Strategy::Common
|
6
4
|
|
7
5
|
def appropriate?
|
8
|
-
if options['sweep'] && sequence_complete?
|
9
|
-
|
10
|
-
end
|
6
|
+
return proposal if options['sweep'] && sequence_complete?
|
7
|
+
|
11
8
|
debug "#{self.class.name}: not appropriate"
|
12
9
|
false
|
13
10
|
end
|
@@ -21,8 +18,5 @@ module Uricp::Strategy
|
|
21
18
|
@proposed_options.delete('sweep')
|
22
19
|
self
|
23
20
|
end
|
24
|
-
|
25
21
|
end
|
26
|
-
|
27
22
|
end
|
28
|
-
|
data/lib/uricp/uri_strategy.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
3
|
module Uricp
|
4
|
-
|
5
4
|
class UriStrategy
|
6
|
-
|
7
5
|
include Methadone::CLILogging
|
8
6
|
|
9
7
|
def self.choose_strategy(options)
|
10
|
-
current = options.reject {|k,
|
8
|
+
current = options.reject { |k, _v| k.is_a? Symbol }
|
11
9
|
strategy_list = []
|
12
|
-
while STRATEGIES.detect {|klass| @strategy = klass.new(current).appropriate? }
|
13
|
-
|
10
|
+
while STRATEGIES.detect { |klass| @strategy = klass.new(current).appropriate? }
|
11
|
+
debug "#{name}: Selected strategy #{@strategy.class.name}"
|
14
12
|
strategy_list << @strategy
|
15
|
-
|
13
|
+
current = @strategy.proposed_options
|
14
|
+
end
|
15
|
+
if incomplete_strategy?(strategy_list)
|
16
|
+
raise Uricp::UnsupportedURLtype, "Unsupported transfer from #{options['from_uri']} to #{options['to_uri']}"
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
strategy_list
|
19
20
|
end
|
20
21
|
|
@@ -22,12 +23,11 @@ module Uricp
|
|
22
23
|
list.empty?
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
#This is an ordered list from the most specific to the most general
|
26
|
+
# This is an ordered list from the most specific to the most general
|
28
27
|
STRATEGIES = [
|
29
28
|
Strategy::CachedGet,
|
30
29
|
Strategy::PipedRemoteGet,
|
30
|
+
Strategy::PipedRbdGet,
|
31
31
|
Strategy::PipedCacheConvert,
|
32
32
|
Strategy::PipedCache,
|
33
33
|
Strategy::PipedLocalDecompress,
|
@@ -35,14 +35,15 @@ module Uricp
|
|
35
35
|
Strategy::LocalConvert,
|
36
36
|
Strategy::LocalLink,
|
37
37
|
Strategy::PipedCompress,
|
38
|
+
Strategy::RbdRemotePut,
|
38
39
|
Strategy::SegmentedRemotePut,
|
39
40
|
Strategy::RemotePut,
|
40
41
|
Strategy::PipedLocalCompress,
|
41
42
|
Strategy::PipedLocalGet,
|
42
43
|
Strategy::PipedLocalPut,
|
43
44
|
Strategy::Cleaner,
|
44
|
-
Strategy::
|
45
|
-
|
46
|
-
|
45
|
+
Strategy::RbdSweeper,
|
46
|
+
Strategy::Sweeper
|
47
|
+
].freeze
|
47
48
|
end
|
48
49
|
end
|
data/lib/uricp/version.rb
CHANGED