blobsterix 0.0.35 → 0.0.36

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: 549a1162916756237d9df4372dbce37432d2cbb2
4
- data.tar.gz: 85b118a8cb57a4140e922dbae3caf6c768b17cd3
3
+ metadata.gz: 7445c28b6f045636c287259d79540cb33490a6e5
4
+ data.tar.gz: 301c5d44eba26cb07e3cbe0c8ca24598ecf4c0cb
5
5
  SHA512:
6
- metadata.gz: 00f4d1abc5b5b64469090a20b5f6c6d303ba13d361a723961f606e79723fb23eb56755d8f5ee91d548d51f69466beabeab8fd6f01f4042b6ec718f621714a773
7
- data.tar.gz: c79acbb55211463bb151cc0ed731aa85a7673b8c4936842d839a39a28b8cce7656c3efd8e9b6f829daee35897ecf3d9008260cf964b01eb4fab7aaf988dec342
6
+ metadata.gz: 79d8ada8a2a3c8fe79c3f26b5f93fda2b97a36e7e6f09f326fa4e92ac55cec620a2099ee50940a7709b0a127027fcad4535c25b869cab3e04f64ca7a85643079
7
+ data.tar.gz: 0bb50d3e731c1f7868861043c9029155c44f1ac7d0e9c0175a590065b16eeaf0027ac7fc69c1b3fc4d54b02037f2b122b2f704a4d3f2200220cc2912d17ac409
@@ -2,4 +2,6 @@ module Blosterix
2
2
 
3
3
  class BlobsertixTransformationError < StandardError; end
4
4
 
5
+ class BlobsterixStorageError < StandardError; end
6
+
5
7
  end
@@ -7,93 +7,151 @@ module Blobsterix
7
7
  include Blobsterix::Logable
8
8
 
9
9
  def initialize(path)
10
- logger.info "Create FileSystem at #{path}"
11
- @contents = path
12
- FileUtils.mkdir_p(@contents) unless Dir.exist?(@contents)
13
- FileUtils.touch File.join(@contents,".keep")
10
+ @contents_path = path
11
+ @contents = nil
14
12
  end
15
13
 
16
14
  def bucket_exist(bucket="root")
17
- Dir.entries(contents).include?(bucket) and File.directory?(File.join(contents,bucket))
15
+ begin
16
+ Dir.entries(contents).include?(bucket) and File.directory?(File.join(contents,bucket))
17
+ rescue => e
18
+ if e.is_a? ::Blosterix::BlobsterixStorageError
19
+ raise e
20
+ else
21
+ raise ::Blosterix::BlobsterixStorageError.new("Could not check for bucket")
22
+ end
23
+ end
18
24
  end
19
25
 
20
26
  def list(bucket="root", opts={})
21
- if bucket =~ /root/
22
- list_buckets
23
- else
24
- if bucket_exist(bucket)
25
- b = Bucket.new(bucket, time_string_of(bucket))
26
- b.marker = opts[:start_path] if opts[:start_path]
27
- Blobsterix.wait_for(Proc.new {
28
- collect_bucket_entries(bucket, b, opts)
29
- })
30
- b
27
+ begin
28
+ if bucket =~ /root/
29
+ list_buckets
31
30
  else
32
- Nokogiri::XML::Builder.new do |xml|
33
- xml.Error "no such bucket"
31
+ if bucket_exist(bucket)
32
+ b = Bucket.new(bucket, time_string_of(bucket))
33
+ b.marker = opts[:start_path] if opts[:start_path]
34
+ Blobsterix.wait_for(Proc.new {
35
+ collect_bucket_entries(bucket, b, opts)
36
+ })
37
+ b
38
+ else
39
+ Nokogiri::XML::Builder.new do |xml|
40
+ xml.Error "no such bucket"
41
+ end
34
42
  end
35
43
  end
44
+ rescue => e
45
+ if e.is_a? ::Blosterix::BlobsterixStorageError
46
+ raise e
47
+ else
48
+ raise ::Blosterix::BlobsterixStorageError.new("Could not list bucket(s)")
49
+ end
36
50
  end
37
51
  end
38
52
 
39
53
  def get(bucket, key)
40
- if (not File.directory?(contents(bucket, key))) # and bucket_files(bucket).include?(key)
41
- Blobsterix.storage_read(BlobAccess.new(:bucket => bucket, :id => key))
42
- metaData(bucket, key)
43
- else
44
- Blobsterix.storage_read_fail(BlobAccess.new(:bucket => bucket, :id => key))
45
- Blobsterix::Storage::BlobMetaData.new
54
+ begin
55
+ if (not File.directory?(contents(bucket, key))) # and bucket_files(bucket).include?(key)
56
+ Blobsterix.storage_read(BlobAccess.new(:bucket => bucket, :id => key))
57
+ metaData(bucket, key)
58
+ else
59
+ Blobsterix.storage_read_fail(BlobAccess.new(:bucket => bucket, :id => key))
60
+ Blobsterix::Storage::BlobMetaData.new
61
+ end
62
+ rescue => e
63
+ if e.is_a? ::Blosterix::BlobsterixStorageError
64
+ raise e
65
+ else
66
+ raise ::Blosterix::BlobsterixStorageError.new("Could not get bucket entry: #{@contents_path}")
67
+ end
46
68
  end
47
69
  end
48
70
 
49
71
  def put(bucket, key, value, opts={})
50
- Blobsterix.storage_write(BlobAccess.new(:bucket => bucket, :id => key))
72
+ begin
73
+ Blobsterix.storage_write(BlobAccess.new(:bucket => bucket, :id => key))
51
74
 
52
- meta = Blobsterix.wait_for(Proc.new do
53
- result = metaData(bucket, key).write() do |f|
54
- FileUtils.copy_stream(value, f)
55
- end
56
- FileUtils.touch File.join(contents(bucket), ".keep")
57
- result
58
- end)
75
+ meta = Blobsterix.wait_for(Proc.new do
76
+ result = metaData(bucket, key).write() do |f|
77
+ FileUtils.copy_stream(value, f)
78
+ end
79
+ FileUtils.touch File.join(contents(bucket), ".keep")
80
+ result
81
+ end)
59
82
 
60
- value.close if opts[:close_after_write]
83
+ value.close if opts[:close_after_write]
61
84
 
62
- Blobsterix.wait_for(Proc.new {Blobsterix.cache.invalidate(Blobsterix::BlobAccess.new(:bucket => bucket, :id => key))})
85
+ Blobsterix.wait_for(Proc.new {Blobsterix.cache.invalidate(Blobsterix::BlobAccess.new(:bucket => bucket, :id => key))})
63
86
 
64
- meta
87
+ meta
88
+ rescue => e
89
+ if e.is_a? ::Blosterix::BlobsterixStorageError
90
+ raise e
91
+ else
92
+ raise ::Blosterix::BlobsterixStorageError.new("Could not create bucket entry")
93
+ end
94
+ end
65
95
  end
66
96
 
67
97
  def create(bucket)
68
- logger.info "Storage: create bucket #{contents(bucket)}"
69
- FileUtils.mkdir_p(contents(bucket)) unless File.exist?(contents(bucket))
70
- FileUtils.touch File.join(contents(bucket), ".keep")
98
+ begin
99
+ logger.info "Storage: create bucket #{contents(bucket)}"
100
+ FileUtils.mkdir_p(contents(bucket)) unless File.exist?(contents(bucket))
101
+ FileUtils.touch File.join(contents(bucket), ".keep")
71
102
 
72
- Nokogiri::XML::Builder.new do |xml|
73
- end.to_s
103
+ Nokogiri::XML::Builder.new do |xml|
104
+ end.to_s
105
+ rescue => e
106
+ if e.is_a? ::Blosterix::BlobsterixStorageError
107
+ raise e
108
+ else
109
+ raise ::Blosterix::BlobsterixStorageError.new("Could not create bucket")
110
+ end
111
+ end
74
112
  end
75
113
 
76
114
  def delete(bucket)
77
- logger.info "Storage: delete bucket #{contents(bucket)}"
78
- FileUtils.rm_rf(contents(bucket)) if bucket_exist(bucket) && bucket_empty?(bucket)
79
- #Dir.rmdir(contents(bucket)) if bucket_exist(bucket) && bucket_files(bucket).empty?
115
+ begin
116
+ logger.info "Storage: delete bucket #{contents(bucket)}"
117
+ FileUtils.rm_rf(contents(bucket)) if bucket_exist(bucket) && bucket_empty?(bucket)
118
+ rescue => e
119
+ if e.is_a? ::Blosterix::BlobsterixStorageError
120
+ raise e
121
+ else
122
+ raise ::Blosterix::BlobsterixStorageError.new("Could not delete bucket")
123
+ end
124
+ end
80
125
  end
81
126
 
82
127
  def delete_key(bucket, key)
83
- Blobsterix.storage_delete(BlobAccess.new(:bucket => bucket, :id => key))
84
- Blobsterix.wait_for(Proc.new {Blobsterix.cache.invalidate(Blobsterix::BlobAccess.new(:bucket => bucket, :id => key))})
128
+ begin
129
+ Blobsterix.storage_delete(BlobAccess.new(:bucket => bucket, :id => key))
130
+ Blobsterix.wait_for(Proc.new {Blobsterix.cache.invalidate(Blobsterix::BlobAccess.new(:bucket => bucket, :id => key))})
131
+
132
+ metaData(bucket, key).delete # if bucket_files(bucket).include? key
133
+ rescue => e
134
+ if e.is_a? ::Blosterix::BlobsterixStorageError
135
+ raise e
136
+ else
137
+ raise ::Blosterix::BlobsterixStorageError.new("Could not delete bucket key")
138
+ end
139
+ end
140
+ end
85
141
 
86
- metaData(bucket, key).delete # if bucket_files(bucket).include? key
142
+ def name
143
+ @contents_path
87
144
  end
88
145
 
89
146
  private
90
147
  def list_buckets
91
148
  BucketList.new do |l|
92
149
  Dir.entries("#{contents}").each{|dir|
93
- l.buckets << Bucket.new(dir, time_string_of(dir)) if File.directory? File.join("#{contents}",dir) and !(dir =='.' || dir == '..')
150
+ l.buckets << Bucket.new(dir, time_string_of(dir)) if File.directory? File.join("#{contents}",dir) and !(dir =='.' || dir == '..')
94
151
  }
95
152
  end
96
153
  end
154
+
97
155
  def collect_bucket_entries(bucket, b, opts)
98
156
  start_path = map_filename(opts[:start_path].to_s.gsub("/", "\\")) if opts[:start_path]
99
157
  current_obj = Blobsterix::DirectoryList.each_limit(contents(bucket), :limit => 20, :start_path => start_path) do |path, file|
@@ -110,7 +168,9 @@ module Blobsterix
110
168
  b.truncated=true
111
169
  end
112
170
  end
171
+
113
172
  def contents(bucket=nil, key=nil)
173
+ initialize_contents
114
174
  if bucket
115
175
  key ? File.join(@contents, bucket, map_filename(key.gsub("/", "\\"))) : File.join(@contents, bucket)
116
176
  else
@@ -118,6 +178,18 @@ module Blobsterix
118
178
  end
119
179
  end
120
180
 
181
+ def initialize_contents
182
+ return if @contents != nil
183
+ begin
184
+ logger.info "Create FileSystem at #{@contents_path}"
185
+ FileUtils.mkdir_p(@contents_path) unless Dir.exist?(@contents_path)
186
+ FileUtils.touch File.join(@contents_path,".keep")
187
+ @contents = @contents_path
188
+ rescue
189
+ raise ::Blosterix::BlobsterixStorageError.new("Could not connect to FileSystem")
190
+ end
191
+ end
192
+
121
193
  def map_filename(filename)
122
194
  Murmur.map_filename(filename, filename)
123
195
  end
@@ -67,7 +67,7 @@ module Blobsterix
67
67
  end
68
68
 
69
69
  def header()
70
- {"Etag" => etag, "Content-Type" => mimetype, "Last-Modified" => last_modified.strftime("%Y-%m-%dT%H:%M:%S.000Z"), "Cache-Control" => "max-age=#{60*60*24}", "Expires" => (Time.new+(60*60*24)).strftime("%Y-%m-%dT%H:%M:%S.000Z")}
70
+ {"Etag" => etag, "Content-Type" => mimetype, "Last-Modified" => last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT"), "Cache-Control" => "max-age=#{60*60*24}", "Expires" => (Time.new+(60*60*24)).strftime("%a, %d %b %Y %H:%M:%S GMT")}
71
71
  end
72
72
 
73
73
  def valid
@@ -79,24 +79,32 @@ module Blobsterix
79
79
  end
80
80
 
81
81
  def write
82
- if block_given?
83
- delete
84
- FileUtils.mkdir_p(File.dirname(path))
85
- f = File.open(path, "wb")
86
- yield f
87
- f.close
82
+ begin
83
+ if block_given?
84
+ delete
85
+ FileUtils.mkdir_p(File.dirname(path))
86
+ f = File.open(path, "wb")
87
+ yield f
88
+ f.close
89
+ end
90
+ save_meta_file
91
+ self
92
+ rescue
93
+ raise ::Blosterix::BlobsterixStorageError.new("Could not create MetaData entry")
88
94
  end
89
- save_meta_file
90
- self
91
95
  end
92
96
 
93
97
  def open
94
- if block_given?
95
- f = File.open(path, "rb")
96
- yield f
97
- f.close
98
- else
99
- File.open(path, "rb")
98
+ begin
99
+ if block_given?
100
+ f = File.open(path, "rb")
101
+ yield f
102
+ f.close
103
+ else
104
+ File.open(path, "rb")
105
+ end
106
+ rescue
107
+ raise ::Blosterix::BlobsterixStorageError.new("Could not open FilesystemMetaData")
100
108
  end
101
109
  end
102
110
 
@@ -138,8 +146,11 @@ module Blobsterix
138
146
  end
139
147
  def save_meta_file
140
148
  return if not valid
141
-
142
- File.write(meta_path, to_json)
149
+ begin
150
+ File.write(meta_path, to_json)
151
+ rescue
152
+ raise ::Blosterix::BlobsterixStorageError.new("Could not create MetaData entry")
153
+ end
143
154
  end
144
155
  def load_meta_file
145
156
  return if not valid
@@ -25,6 +25,9 @@ module Blobsterix
25
25
  def delete_key(bucket, key)
26
26
  nil
27
27
  end
28
+ def name
29
+ "none"
30
+ end
28
31
  end
29
32
  end
30
33
  end
@@ -102,7 +102,7 @@ module Blobsterix::Transformations
102
102
  logger.debug "Transformation: done #{blob_access} finish connections"
103
103
  running_transformations[blob_access.identifier].each{|fiber|
104
104
  fiber.resume(result)
105
- }
105
+ } if running_transformations[blob_access.identifier] # check if there are pending fibers or if the connection was already closed
106
106
  uncue_transformation(blob_access)
107
107
  end
108
108
 
@@ -118,4 +118,4 @@ module Blobsterix::Transformations
118
118
  trafos.empty? ? nil : trafos[0]
119
119
  end
120
120
  end
121
- end
121
+ end
@@ -1,3 +1,3 @@
1
1
  module Blobsterix
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.36"
3
3
  end
@@ -25,6 +25,9 @@ module Blobsterix
25
25
  def delete_key(bucket, key)
26
26
  nil
27
27
  end
28
+ def name
29
+ "none"
30
+ end
28
31
  end
29
32
  end
30
- end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobsterix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Sudmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -333,3 +333,4 @@ test_files:
333
333
  - spec/lib/storage/cache_spec.rb
334
334
  - spec/lib/storage/file_system_spec.rb
335
335
  - spec/spec_helper.rb
336
+ has_rdoc: