rabbit_swift 0.3.0 → 0.3.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: 804ffd4e738e1d57034cb48fb80a41af300bd32f
4
- data.tar.gz: 746ea1d0eeecfeb9c604d03dd02550a67af51f81
3
+ metadata.gz: 39963e45fd183eca61bb3ab443a8ef18c396424c
4
+ data.tar.gz: 50a027e4738e68276e808ac6e8f4a47d96450253
5
5
  SHA512:
6
- metadata.gz: bb14f293bc65e9657de5223d91f17c00aa4897d9636893190f2651e67750b602f9ddeff8d11b817f24b719e8fc47a2fe85eafe66428efbc567f36e63f81f2c9a
7
- data.tar.gz: 7cb7cc62070f02818aff6fdea47b35b5b881e1db07fa495812cdeb5a1c04fe907fac68071d83f1b5d32897ea324d9b6f9529d8c5da6b1968fcbcdab7b001c4ba
6
+ metadata.gz: f1644fae715b829e70220ac574243ec3ed3f49aa7eba2dcf678e3ad6f0c053f0d5ace0b1e05e00e649d2c5251667e11613ea7974570d61c6296a12105185d77a
7
+ data.tar.gz: f5a03d16eff1ffb8e9b8aade26fa3712ac81cfa313fa0a00eb9f1ba023a18c15f6ffc2098e41add1e914c8790731452e6ba9d56f32932946f12f3996930766a8
data/README.md CHANGED
@@ -47,6 +47,17 @@ Or install it yourself as:
47
47
  end
48
48
 
49
49
  ### Support Static Large Object
50
+
51
+ #### When object size 5BG over. Auto change mode SLO
52
+ rabbit_swift_client.upload(token, dest_url, 5GB_under_file.zip) --> normal upload
53
+ rabbit_swift_client.upload(token, dest_url, 5GB_over_file.zip) --> static large object upload
54
+
55
+ #### SLO Flow
56
+ 1. split File
57
+ 2. upload split files
58
+ 3. upload manifest file
59
+
60
+ #### SLO Client
50
61
  bundle exec ruby -I./lib bin/slo_client.rb -s ~/Downloads/test.zip -d /test -c ../chino/conf/conf.json -l 100MB
51
62
 
52
63
  ## Contributing
data/RELEASE.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # リリース履歴
2
2
 
3
+ ## 0.3.1
4
+
5
+ (2015/02/15)
6
+
7
+ Static Large Object (α3)
8
+ Auto SLO Mode
9
+
3
10
  ## 0.3.0
4
11
 
5
12
  (2015/02/15)
data/bin/slo_client.rb CHANGED
@@ -5,6 +5,7 @@ require 'rabbit_swift'
5
5
  #ruby -I./lib/ this.rb
6
6
  #bundle exec ruby -I./lib bin/slo_client.rb -s ~/Downloads/test.zip -d /test -c ../chino/conf/conf.json -l 1048576
7
7
  #bundle exec ruby -I./lib bin/slo_client.rb -s ~/Downloads/test.zip -d /test -c ../chino/conf/conf.json -l 100MB
8
+ #bundle exec ruby -I./lib bin/slo_client.rb -s ~/MBA_Grahics/mba2/1423672249367.jpg -d /test -c ../chino/conf/conf.json -l 100KB
8
9
 
9
10
  =begin
10
11
  -c conf.json
@@ -25,73 +26,24 @@ Version = '1.0.0'
25
26
  src_path = nil
26
27
  dest_path = nil
27
28
  conf_path = nil
28
- limit_file_size = nil
29
+ slo_option = {}
30
+ swift_conf_json = {}
29
31
  opt.on('-s SRC_PATH', 'src_file_path') {|v| src_path = v}
30
32
  opt.on('-d DEST_PATH', 'dest_path') {|v| dest_path = v}
31
33
  opt.on('-c CONF_PATH', 'conf_path') {|v| conf_path = v}
32
- opt.on('-l LIMIT_BYTE', 'limit_file_size') {|v| limit_file_size = v}
34
+ opt.on('-l LIMIT_BYTE', 'limit_file_size') {|v| slo_option['limit_file_size'] = v}
33
35
  opt.parse!(ARGV)
34
36
 
35
37
 
36
- class Slo_client
37
-
38
- attr_accessor :src_path, :dest_path, :conf_path, :swift, :token, :limit_file_size, :original_dest_path
39
-
40
- def initialize(src_path, dest_path, conf_path, send_timeout: 7200, limit_file_size: RabbitSwift::LargeObject::StaticLargeObject::LIMIT_FILE_SIZE)
41
- @src_path = src_path
42
- @dest_path = dest_path
43
- @original_dest_path = dest_path
44
- @conf_path = conf_path
45
- @limit_file_size = limit_file_size
46
- File.open conf_path do |file|
47
- conf = JSON.load(file.read)
48
- @swift = conf['swift']
49
-
50
- if @dest_path =~ /^\//
51
- @dest_path = @swift['endPoint'] + dest_path
52
- end
53
- end
54
-
55
- @swift['send_timeout'] = send_timeout
56
- end
57
-
58
- def upload
59
- slo = RabbitSwift::LargeObject::StaticLargeObject.new(src_path, dest_path, limit_file_size: @limit_file_size)
60
-
61
- # (指定されたファイルサイズ単位で)ファイルを分割する
62
- rabbit_file_split = slo.split
63
- # JSONマニフェストファイルをつくる
64
- manifest_json = slo.create_manifest_list(rabbit_file_split.file_list)
65
- puts manifest_json
66
-
67
- rabbit_swift_client = RabbitSwift::Client.new(@swift)
68
- @token = rabbit_swift_client.get_token
69
- puts 'token -> ' + token
70
-
71
- #ファイルを全てアップロード(with etag)
72
- rabbit_file_split.file_list.each do |file_path|
73
- status = rabbit_swift_client.upload(token, dest_path, file_path)
74
- puts file_path
75
- puts 'http_status -> ' + status.to_s
76
- if (status == RabbitSwift::Client::UPLOAD_SUCCESS_HTTP_STATUS_CODE)
77
- puts 'upload OK'
78
- else
79
- puts 'upload NG'
80
- return
81
- end
82
- end
83
-
84
- puts "dest_path->" + dest_path
85
- #マニフェストをアップロード
86
- rabbit_swift_client.upload_manifest(token, dest_path, @original_dest_path, @src_path, manifest_json)
87
-
88
- #分割したファイルを削除
89
- rabbit_file_split.delete_all
38
+ File.open conf_path do |file|
39
+ conf = JSON.load(file.read)
40
+ swift_conf_json = conf['swift']
90
41
 
42
+ if dest_path =~ /^\//
43
+ dest_path = swift_conf_json['endPoint'] + dest_path
91
44
  end
92
-
93
45
  end
94
46
 
47
+ rabbit_swift_client = RabbitSwift::Client.new(swift_conf_json)
95
48
 
96
- slo = Slo_client.new(src_path,dest_path,conf_path, limit_file_size: limit_file_size)
97
- slo.upload
49
+ RabbitSwift::LargeObject::Slo_client.new(rabbit_swift_client, src_path, dest_path, slo_option).upload
data/lib/rabbit_swift.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rabbit_swift/version"
2
2
  require "rabbit_swift/client"
3
3
  require "rabbit_swift/large_object/static_large_object"
4
-
4
+ require "rabbit_swift/large_object/slo_client"
5
5
  module RabbitSwift
6
6
  # Your code goes here...
7
7
  end
@@ -14,6 +14,8 @@ module RabbitSwift
14
14
  HEAD_SUCCESS_HTTP_STATUS_CODE = 204
15
15
  DELETE_SUCCESS_HTTP_STATUS_CODE = 204
16
16
 
17
+ @token = nil
18
+
17
19
  def initialize(opt)
18
20
  @auth_url = opt['auth_url']
19
21
  @tenantName = opt['tenantName']
@@ -29,6 +31,7 @@ module RabbitSwift
29
31
 
30
32
  #curl -i 'https://********.jp/v2.0/tokens' -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"auth": {"tenantName": "1234567", "passwordCredentials": {"username": "1234567", "password": "************"}}}'
31
33
  def get_token
34
+ return @token if !@token.nil?
32
35
  body = build_auth_json
33
36
 
34
37
  http_client = HTTPClient.new
@@ -36,7 +39,7 @@ module RabbitSwift
36
39
  response = http_client.post_content(@auth_url, body, 'Content-Type' => 'application/json')
37
40
  response_json_body = JSON.load(response)
38
41
 
39
- response_json_body['access']['token']['id']
42
+ @token = response_json_body['access']['token']['id']
40
43
  end
41
44
 
42
45
  def head(token, url)
@@ -141,9 +144,18 @@ module RabbitSwift
141
144
  end
142
145
  else
143
146
  p auth_header
144
- File.open(file_path) do |file|
145
- @res = http_client.put(URI.parse(URI.encode(target_url)), file, auth_header)
147
+
148
+ if LargeObject::StaticLargeObject.is_over_default_limit_object_size(File.size(file_path))
149
+ #Auto SLO Mode
150
+ p File.size(file_path)
151
+ puts '------ Over limit object size! change Static Large Object Mode. ------- '
152
+ LargeObject::Slo_client.new(self, input_file_path, end_point).upload
153
+ else
154
+ File.open(file_path) do |file|
155
+ @res = http_client.put(URI.parse(URI.encode(target_url)), file, auth_header)
156
+ end
146
157
  end
158
+
147
159
  end
148
160
 
149
161
  #p @res
@@ -0,0 +1,60 @@
1
+ require 'rabbit_swift'
2
+
3
+ module RabbitSwift::LargeObject
4
+ class Slo_client
5
+
6
+ attr_accessor :rabbit_swift_client, :src_path, :dest_path, :original_dest_path, :slo_option
7
+
8
+ def initialize(rabbit_swift_client, src_path, dest_path, slo_option = {})
9
+ @rabbit_swift_client = rabbit_swift_client
10
+ @src_path = src_path
11
+ @dest_path = dest_path
12
+ #TODO かなり無理があるので改修必要
13
+ @original_dest_path = dest_path.sub(/https:\/\/.*\/v1\/.*\//, '/')
14
+
15
+
16
+ @slo_option = slo_option
17
+ end
18
+
19
+ def upload
20
+ if @slo_option.has_key?('limit_file_size')
21
+ slo = RabbitSwift::LargeObject::StaticLargeObject.new(src_path, dest_path, limit_file_size: @slo_option['limit_file_size'])
22
+ else
23
+ slo = RabbitSwift::LargeObject::StaticLargeObject.new(src_path, dest_path)
24
+ end
25
+ # (指定されたファイルサイズ単位で)ファイルを分割する
26
+ rabbit_file_split = slo.split
27
+ # JSONマニフェストファイルをつくる
28
+ manifest_json = slo.create_manifest_list(rabbit_file_split.file_list)
29
+ puts manifest_json
30
+
31
+ token = rabbit_swift_client.get_token
32
+
33
+ #TODO with etag
34
+ #ファイルを全てアップロード
35
+ rabbit_file_split.file_list.each do |file_path|
36
+ status = rabbit_swift_client.upload(token, dest_path, file_path)
37
+ puts file_path
38
+ puts 'http_status -> ' + status.to_s
39
+ if (status == RabbitSwift::Client::UPLOAD_SUCCESS_HTTP_STATUS_CODE)
40
+ puts 'upload OK'
41
+ else
42
+ puts 'upload NG'
43
+ return
44
+ end
45
+ end
46
+
47
+ puts "dest_path->" + dest_path
48
+ #マニフェストをアップロード
49
+ rabbit_swift_client.upload_manifest(token, dest_path, @original_dest_path, @src_path, manifest_json)
50
+
51
+ #分割したファイルを削除
52
+ rabbit_file_split.delete_all
53
+
54
+ end
55
+
56
+ end
57
+
58
+
59
+
60
+ end
@@ -43,7 +43,7 @@ module RabbitSwift::LargeObject
43
43
  end
44
44
 
45
45
  def self.is_over_default_limit_object_size(file_size)
46
- LIMIT_FILE_SIZE > file_size
46
+ LIMIT_FILE_SIZE < file_size
47
47
  end
48
48
 
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module RabbitSwift
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_swift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AKB428
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,6 +99,7 @@ files:
99
99
  - lib/rabbit_swift/account/.gitkeep
100
100
  - lib/rabbit_swift/client.rb
101
101
  - lib/rabbit_swift/container/.gitkeep
102
+ - lib/rabbit_swift/large_object/slo_client.rb
102
103
  - lib/rabbit_swift/large_object/static_large_object.rb
103
104
  - lib/rabbit_swift/object/delete.rb
104
105
  - lib/rabbit_swift/object/head.rb