duracloud-client 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -1
  3. data/lib/duracloud.rb +5 -1
  4. data/lib/duracloud/cli.rb +29 -107
  5. data/lib/duracloud/command_options.rb +120 -0
  6. data/lib/duracloud/commands.rb +40 -0
  7. data/lib/duracloud/commands/command.rb +6 -2
  8. data/lib/duracloud/commands/count.rb +15 -0
  9. data/lib/duracloud/commands/download_manifest.rb +0 -2
  10. data/lib/duracloud/commands/find.rb +16 -0
  11. data/lib/duracloud/commands/find_item.rb +16 -0
  12. data/lib/duracloud/commands/find_items.rb +22 -0
  13. data/lib/duracloud/commands/find_missing_items.rb +15 -0
  14. data/lib/duracloud/commands/find_space.rb +12 -0
  15. data/lib/duracloud/commands/get_storage_report.rb +16 -0
  16. data/lib/duracloud/commands/get_storage_report_for_all_spaces.rb +12 -0
  17. data/lib/duracloud/commands/get_storage_report_for_space.rb +10 -0
  18. data/lib/duracloud/commands/get_storage_report_for_store.rb +10 -0
  19. data/lib/duracloud/commands/list_content_ids.rb +11 -0
  20. data/lib/duracloud/commands/list_items.rb +17 -0
  21. data/lib/duracloud/commands/sync.rb +0 -2
  22. data/lib/duracloud/commands/validate.rb +2 -3
  23. data/lib/duracloud/content.rb +12 -3
  24. data/lib/duracloud/fast_sync_validation.rb +42 -0
  25. data/lib/duracloud/rest_methods.rb +15 -0
  26. data/lib/duracloud/storage_report.rb +33 -0
  27. data/lib/duracloud/storage_reports.rb +52 -0
  28. data/lib/duracloud/sync_validation.rb +122 -39
  29. data/lib/duracloud/version.rb +1 -1
  30. data/spec/unit/cli_spec.rb +59 -15
  31. data/spec/unit/client_spec.rb +24 -0
  32. data/spec/unit/content_spec.rb +17 -7
  33. data/spec/unit/storage_report_spec.rb +15 -0
  34. data/spec/unit/storage_reports_spec.rb +45 -0
  35. metadata +23 -3
  36. data/lib/duracloud/commands/get_properties.rb +0 -27
@@ -1,3 +1,3 @@
1
1
  module Duracloud
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -3,39 +3,83 @@ module Duracloud
3
3
 
4
4
  subject { described_class.new(**opts) }
5
5
 
6
- describe "properties" do
7
- let(:opts) { {space_id: "foo", content_id: "bar"} }
8
- let(:command) { "properties" }
6
+ describe "find item" do
7
+ let(:opts) { {command: "find", space_id: "foo", content_id: "bar"} }
9
8
  specify {
10
- expect(Commands::GetProperties).to receive(:call).with(subject) { nil }
11
- subject.execute(command)
9
+ expect(Commands::FindItem).to receive(:call).with(subject) { nil }
10
+ subject.execute
11
+ }
12
+ end
13
+
14
+ describe "find space" do
15
+ let(:opts) { {command: "find", space_id: "foo"} }
16
+ specify {
17
+ expect(Commands::FindSpace).to receive(:call).with(subject) { nil }
18
+ subject.execute
19
+ }
20
+ end
21
+
22
+ describe "find items" do
23
+ let(:opts) { {command: "find", space_id: "foo", infile: "/foo/bar"} }
24
+ specify {
25
+ expect(Commands::FindItems).to receive(:call).with(subject) { nil }
26
+ subject.execute
27
+ }
28
+ end
29
+
30
+ describe "count" do
31
+ let(:opts) { {command: "count", space_id: "foo"} }
32
+ specify {
33
+ expect(Commands::Count).to receive(:call).with(subject) { nil }
34
+ subject.execute
12
35
  }
13
36
  end
14
37
 
15
38
  describe "sync" do
16
- let(:opts) { {space_id: "foo", content_id: "bar", infile: "foo/bar"} }
17
- let(:command) { "sync" }
39
+ let(:opts) { {command: "sync", space_id: "foo", content_id: "bar", infile: "foo/bar"} }
18
40
  specify {
19
41
  expect(Commands::Sync).to receive(:call).with(subject) { nil }
20
- subject.execute(command)
42
+ subject.execute
21
43
  }
22
44
  end
23
45
 
24
46
  describe "validate" do
25
- let(:opts) { {space_id: "foo", content_dir: "/tmp"} }
26
- let(:command) { "validate" }
47
+ let(:opts) { {command: "validate", space_id: "foo", content_dir: "/tmp"} }
27
48
  specify {
28
49
  expect(Commands::Validate).to receive(:call).with(subject) { nil }
29
- subject.execute(command)
50
+ subject.execute
30
51
  }
31
52
  end
32
53
 
33
- describe "manifest" do
34
- let(:opts) { {space_id: "foo"} }
35
- let(:command) { "manifest" }
54
+ describe "download_manifest" do
55
+ let(:opts) { {command: "download_manifest", space_id: "foo"} }
36
56
  specify {
37
57
  expect(Commands::DownloadManifest).to receive(:call).with(subject) { nil }
38
- subject.execute(command)
58
+ subject.execute
59
+ }
60
+ end
61
+
62
+ describe "get_storage_report" do
63
+ let(:opts) { {command: "get_storage_report", space_id: "foo"} }
64
+ specify {
65
+ expect(Commands::GetStorageReport).to receive(:call).with(subject) { nil }
66
+ subject.execute
67
+ }
68
+ end
69
+
70
+ describe "list content ids" do
71
+ let(:opts) { {command: "list_content_ids", space_id: "foo"} }
72
+ specify {
73
+ expect(Commands::ListContentIds).to receive(:call).with(subject) { nil }
74
+ subject.execute
75
+ }
76
+ end
77
+
78
+ describe "list items" do
79
+ let(:opts) { {command: "list_items", space_id: "foo"} }
80
+ specify {
81
+ expect(Commands::ListItems).to receive(:call).with(subject) { nil }
82
+ subject.execute
39
83
  }
40
84
  end
41
85
 
@@ -329,5 +329,29 @@ module Duracloud
329
329
  .to raise_error(NotImplementedError)
330
330
  }
331
331
  end
332
+
333
+ describe "get_storage_reports_by_space" do
334
+ specify {
335
+ stub = stub_request(:get, "https://example.com/durastore/report/space/foo")
336
+ subject.get_storage_reports_by_space("foo")
337
+ expect(stub).to have_been_requested
338
+ }
339
+ end
340
+
341
+ describe "get_storage_reports_by_store" do
342
+ specify {
343
+ stub = stub_request(:get, "https://example.com/durastore/report/store")
344
+ subject.get_storage_reports_by_store
345
+ expect(stub).to have_been_requested
346
+ }
347
+ end
348
+
349
+ describe "get_storage_reports_for_all_spaces_in_a_store" do
350
+ specify {
351
+ stub = stub_request(:get, "https://example.com/durastore/report/store/1499400000000")
352
+ subject.get_storage_reports_for_all_spaces_in_a_store(1499400000000)
353
+ expect(stub).to have_been_requested
354
+ }
355
+ end
332
356
  end
333
357
  end
@@ -221,11 +221,13 @@ module Duracloud
221
221
  end
222
222
 
223
223
  describe "#copy" do
224
- subject { Content.new(space_id: "foo", content_id: "bar") }
224
+ subject { Content.new(space_id: "foo", content_id: "bar", md5: "08a008a01d498c404b0c30852b39d3b8") }
225
225
  let(:target) { "https://example.com/durastore/spam/eggs" }
226
226
  before do
227
227
  stub_request(:put, target)
228
228
  .with(headers: {'x-dura-meta-copy-source'=>'foo/bar'})
229
+ .to_return(status: 201,
230
+ headers: {'Content-MD5'=>'08a008a01d498c404b0c30852b39d3b8'})
229
231
  stub_request(:head, target).to_return(status: 404)
230
232
  stub_request(:head, "#{target}.dura-manifest").to_return(status: 404)
231
233
  end
@@ -237,6 +239,8 @@ module Duracloud
237
239
  target = "https://example.com/durastore/foo/eggs"
238
240
  stub1 = stub_request(:put, target)
239
241
  .with(headers: {'x-dura-meta-copy-source'=>'foo/bar'})
242
+ .to_return(status: 201,
243
+ headers: {'Content-MD5'=>'08a008a01d498c404b0c30852b39d3b8'})
240
244
  stub2 = stub_request(:head, target).to_return(status: 404)
241
245
  stub3 = stub_request(:head, "#{target}.dura-manifest").to_return(status: 404)
242
246
  copied = subject.copy(content_id: "eggs")
@@ -264,20 +268,21 @@ module Duracloud
264
268
 
265
269
  describe "#move" do
266
270
  let(:target) { "https://example.com/durastore/spam/eggs" }
267
- subject { Content.new(space_id: "foo", content_id: "bar") }
271
+ subject { Content.new(space_id: "foo", content_id: "bar", md5: '08a008a01d498c404b0c30852b39d3b8') }
268
272
  describe "when copy succeeds" do
269
273
  it "deletes the source" do
274
+ allow(described_class)
275
+ .to receive(:exist?)
276
+ .with(space_id: "spam", content_id: "eggs", store_id: nil) { false }
270
277
  stub1 = stub_request(:put, target)
271
278
  .with(headers: {'x-dura-meta-copy-source'=>'foo/bar'})
272
- stub2 = stub_request(:head, target).to_return(status: 404)
273
- stub2a = stub_request(:head, "#{target}.dura-manifest").to_return(status: 404)
274
- stub3 = stub_request(:delete, "https://example.com/durastore/foo/bar")
279
+ .to_return(status: 201,
280
+ headers: {'Content-MD5'=>'08a008a01d498c404b0c30852b39d3b8'})
281
+ stub2 = stub_request(:delete, "https://example.com/durastore/foo/bar")
275
282
  moved = subject.move(space_id: "spam", content_id: "eggs")
276
283
  expect(moved).to be_a(Content)
277
284
  expect(stub1).to have_been_requested
278
285
  expect(stub2).to have_been_requested
279
- expect(stub2a).to have_been_requested
280
- expect(stub3).to have_been_requested
281
286
  end
282
287
  end
283
288
  describe "when copy fails" do
@@ -289,8 +294,13 @@ module Duracloud
289
294
  end
290
295
  describe "when target exists" do
291
296
  before do
297
+ allow(described_class)
298
+ .to receive(:exist?)
299
+ .with(space_id: "spam", content_id: "eggs", store_id: nil) { true }
292
300
  stub_request(:put, target)
293
301
  .with(headers: {'x-dura-meta-copy-source'=>'foo/bar'})
302
+ .to_return(status: 201,
303
+ headers: {'Content-MD5'=>'08a008a01d498c404b0c30852b39d3b8'})
294
304
  stub_request(:delete, "https://example.com/durastore/foo/bar")
295
305
  stub_request(:head, target).to_return(status: 200)
296
306
  allow(Content).to receive(:exist?).with(space_id: "spam", content_id: "eggs") { true }
@@ -0,0 +1,15 @@
1
+ module Duracloud
2
+ RSpec.describe StorageReport do
3
+
4
+ subject { described_class.new("timestamp"=>1312588800000,"accountId"=>"account1","spaceId"=>"space1","storeId"=>"store1","byteCount"=>1000,"objectCount"=>10) }
5
+
6
+ its(:space_id) { is_expected.to eq "space1" }
7
+ its(:store_id) { is_expected.to eq "store1" }
8
+ its(:account_id) { is_expected.to eq "account1" }
9
+ its(:byte_count) { is_expected.to eq 1000 }
10
+ its(:object_count) { is_expected.to eq 10 }
11
+ its(:timestamp) { is_expected.to eq 1312588800000 }
12
+ its(:time) { is_expected.to eq Time.at(1312588800000 / 1000.0) }
13
+
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ module Duracloud
2
+ RSpec.describe StorageReports do
3
+
4
+ describe ".by_space" do
5
+ subject { described_class.by_space("foo") }
6
+ specify {
7
+ stub_request(:get, "https://example.com/durastore/report/space/foo")
8
+ .to_return(body: '[
9
+ {"timestamp":1312588800000,"accountId":"<account-id>","spaceId":"<space-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
10
+ {"timestamp":1315008000000,"accountId":"<account-id>","spaceId":"<space-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
11
+ {"timestamp":1315526400000,"accountId":"<account-id>","spaceId":"<space-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10}
12
+ ]')
13
+ expect(subject.map(&:timestamp)).to eq [ 1312588800000, 1315008000000, 1315526400000 ]
14
+ }
15
+ end
16
+
17
+ describe ".by_store" do
18
+ subject { described_class.by_store }
19
+ specify {
20
+ stub_request(:get, "https://example.com/durastore/report/store")
21
+ .to_return(body: '[
22
+ {"timestamp":1312588800000,"accountId":"<account-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
23
+ {"timestamp":1315008000000,"accountId":"<account-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
24
+ {"timestamp":1315526400000,"accountId":"<account-id>","storeId":"<store-id>","byteCount":1000,"objectCount":10}
25
+ ]')
26
+ expect(subject.map(&:timestamp)).to eq [ 1312588800000, 1315008000000, 1315526400000 ]
27
+ }
28
+ end
29
+
30
+ describe ".for_all_spaces_in_a_store" do
31
+ subject { described_class.for_all_spaces_in_a_store(1499400000000) }
32
+ specify {
33
+ stub_request(:get, "https://example.com/durastore/report/store/1499400000000")
34
+ .to_return(body: '[
35
+ {"timestamp":1312588800000,"accountId":"<account-id>","spaceId":"<space-id-1>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
36
+ {"timestamp":1315008000000,"accountId":"<account-id>","spaceId":"<space-id-2>","storeId":"<store-id>","byteCount":1000,"objectCount":10},
37
+ {"timestamp":1315526400000,"accountId":"<account-id>","spaceId":"<space-id-3>","storeId":"<store-id>","byteCount":1000,"objectCount":10}
38
+ ]')
39
+ expect(subject.map(&:timestamp)).to eq [ 1312588800000, 1315008000000, 1315526400000 ]
40
+ }
41
+ end
42
+
43
+
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duracloud-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -169,9 +169,22 @@ files:
169
169
  - lib/duracloud/chunked_content.rb
170
170
  - lib/duracloud/cli.rb
171
171
  - lib/duracloud/client.rb
172
+ - lib/duracloud/command_options.rb
173
+ - lib/duracloud/commands.rb
172
174
  - lib/duracloud/commands/command.rb
175
+ - lib/duracloud/commands/count.rb
173
176
  - lib/duracloud/commands/download_manifest.rb
174
- - lib/duracloud/commands/get_properties.rb
177
+ - lib/duracloud/commands/find.rb
178
+ - lib/duracloud/commands/find_item.rb
179
+ - lib/duracloud/commands/find_items.rb
180
+ - lib/duracloud/commands/find_missing_items.rb
181
+ - lib/duracloud/commands/find_space.rb
182
+ - lib/duracloud/commands/get_storage_report.rb
183
+ - lib/duracloud/commands/get_storage_report_for_all_spaces.rb
184
+ - lib/duracloud/commands/get_storage_report_for_space.rb
185
+ - lib/duracloud/commands/get_storage_report_for_store.rb
186
+ - lib/duracloud/commands/list_content_ids.rb
187
+ - lib/duracloud/commands/list_items.rb
175
188
  - lib/duracloud/commands/sync.rb
176
189
  - lib/duracloud/commands/validate.rb
177
190
  - lib/duracloud/configuration.rb
@@ -181,6 +194,7 @@ files:
181
194
  - lib/duracloud/durastore_request.rb
182
195
  - lib/duracloud/error.rb
183
196
  - lib/duracloud/error_handler.rb
197
+ - lib/duracloud/fast_sync_validation.rb
184
198
  - lib/duracloud/manifest.rb
185
199
  - lib/duracloud/properties.rb
186
200
  - lib/duracloud/request.rb
@@ -188,6 +202,8 @@ files:
188
202
  - lib/duracloud/rest_methods.rb
189
203
  - lib/duracloud/space.rb
190
204
  - lib/duracloud/space_acls.rb
205
+ - lib/duracloud/storage_report.rb
206
+ - lib/duracloud/storage_reports.rb
191
207
  - lib/duracloud/store.rb
192
208
  - lib/duracloud/sync_validation.rb
193
209
  - lib/duracloud/tsv.rb
@@ -209,6 +225,8 @@ files:
209
225
  - spec/unit/properties_spec.rb
210
226
  - spec/unit/space_acls_spec.rb
211
227
  - spec/unit/space_spec.rb
228
+ - spec/unit/storage_report_spec.rb
229
+ - spec/unit/storage_reports_spec.rb
212
230
  - spec/unit/store_spec.rb
213
231
  homepage: https://github.com/duracloud/duracloud-ruby-client
214
232
  licenses:
@@ -252,4 +270,6 @@ test_files:
252
270
  - spec/unit/properties_spec.rb
253
271
  - spec/unit/space_acls_spec.rb
254
272
  - spec/unit/space_spec.rb
273
+ - spec/unit/storage_report_spec.rb
274
+ - spec/unit/storage_reports_spec.rb
255
275
  - spec/unit/store_spec.rb
@@ -1,27 +0,0 @@
1
- require_relative "command"
2
-
3
- module Duracloud::Commands
4
- class GetProperties < Command
5
-
6
- def call
7
- proplist = content_id ? content_properties : space_properties
8
- puts proplist
9
- end
10
-
11
- private
12
-
13
- def content_properties
14
- content = Duracloud::Content.find(space_id: space_id, store_id: store_id, content_id: content_id, md5: md5)
15
- proplist = content.properties.map { |k, v| "#{k}: #{v}" }
16
- proplist << "MD5: #{content.md5}"
17
- proplist << "Size: #{content.size} (#{content.human_size})"
18
- proplist << "Chunked?: #{content.chunked?}"
19
- end
20
-
21
- def space_properties
22
- space = Duracloud::Space.find(space_id, store_id)
23
- space.properties.map { |k, v| "#{k}: #{v}" }
24
- end
25
-
26
- end
27
- end