pho 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/CHANGES +9 -0
  2. data/Rakefile +2 -1
  3. data/bin/talis_store +263 -0
  4. data/doc/rdoc/classes/Pho.html +3 -21
  5. data/doc/rdoc/classes/Pho/Analyzers.html +22 -0
  6. data/doc/rdoc/classes/Pho/DatatypeProperty.html +42 -10
  7. data/doc/rdoc/classes/Pho/Etags.html +102 -30
  8. data/doc/rdoc/classes/Pho/Facet/Results.html +81 -7
  9. data/doc/rdoc/classes/Pho/Facet/Term.html +13 -2
  10. data/doc/rdoc/classes/Pho/FieldPredicateMap.html +233 -30
  11. data/doc/rdoc/classes/Pho/FieldWeighting.html +38 -10
  12. data/doc/rdoc/classes/Pho/Job.html +488 -9
  13. data/doc/rdoc/classes/Pho/JobUpdate.html +141 -0
  14. data/doc/rdoc/classes/Pho/Jobs.html +538 -0
  15. data/doc/rdoc/classes/Pho/Namespaces.html +33 -2
  16. data/doc/rdoc/classes/Pho/QueryProfile.html +162 -20
  17. data/doc/rdoc/classes/Pho/RDFCollection.html +200 -60
  18. data/doc/rdoc/classes/Pho/Snapshot.html +162 -36
  19. data/doc/rdoc/classes/Pho/Status.html +59 -8
  20. data/doc/rdoc/classes/Pho/Store.html +589 -253
  21. data/doc/rdoc/created.rid +1 -1
  22. data/doc/rdoc/files/CHANGES.html +24 -1
  23. data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +1 -1
  24. data/doc/rdoc/files/lib/pho/job_rb.html +1 -1
  25. data/doc/rdoc/files/lib/pho/snapshot_rb.html +2 -1
  26. data/doc/rdoc/files/lib/pho/status_rb.html +1 -1
  27. data/doc/rdoc/files/lib/pho/store_rb.html +1 -1
  28. data/doc/rdoc/files/lib/pho_rb.html +2 -1
  29. data/doc/rdoc/fr_class_index.html +2 -0
  30. data/doc/rdoc/fr_method_index.html +85 -68
  31. data/lib/pho.rb +18 -10
  32. data/lib/pho/field_predicate_map.rb +6 -1
  33. data/lib/pho/job.rb +326 -6
  34. data/lib/pho/snapshot.rb +46 -19
  35. data/lib/pho/store.rb +22 -56
  36. data/tests/tc_job.rb +262 -0
  37. data/tests/tc_jobcontrol.rb +159 -12
  38. data/tests/tc_snapshots.rb +57 -28
  39. data/tests/ts_pho.rb +1 -0
  40. metadata +9 -110
  41. data/doc/rdoc/classes/Pho/DatatypeProperty.src/M000034.html +0 -21
  42. data/doc/rdoc/classes/Pho/DatatypeProperty.src/M000035.html +0 -29
  43. data/doc/rdoc/classes/Pho/Etags.src/M000088.html +0 -23
  44. data/doc/rdoc/classes/Pho/Etags.src/M000089.html +0 -28
  45. data/doc/rdoc/classes/Pho/Etags.src/M000090.html +0 -21
  46. data/doc/rdoc/classes/Pho/Etags.src/M000091.html +0 -18
  47. data/doc/rdoc/classes/Pho/Etags.src/M000092.html +0 -18
  48. data/doc/rdoc/classes/Pho/Etags.src/M000093.html +0 -18
  49. data/doc/rdoc/classes/Pho/Facet/Results.src/M000001.html +0 -20
  50. data/doc/rdoc/classes/Pho/Facet/Results.src/M000002.html +0 -27
  51. data/doc/rdoc/classes/Pho/Facet/Results.src/M000003.html +0 -54
  52. data/doc/rdoc/classes/Pho/Facet/Term.src/M000004.html +0 -20
  53. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000005.html +0 -38
  54. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000006.html +0 -28
  55. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000007.html +0 -20
  56. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000008.html +0 -18
  57. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000009.html +0 -23
  58. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000010.html +0 -23
  59. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000011.html +0 -18
  60. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000012.html +0 -18
  61. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000013.html +0 -18
  62. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000014.html +0 -18
  63. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000015.html +0 -18
  64. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000016.html +0 -21
  65. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000017.html +0 -21
  66. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000018.html +0 -38
  67. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000019.html +0 -18
  68. data/doc/rdoc/classes/Pho/FieldWeighting.src/M000075.html +0 -20
  69. data/doc/rdoc/classes/Pho/FieldWeighting.src/M000076.html +0 -26
  70. data/doc/rdoc/classes/Pho/Job.src/M000074.html +0 -21
  71. data/doc/rdoc/classes/Pho/QueryProfile.src/M000024.html +0 -39
  72. data/doc/rdoc/classes/Pho/QueryProfile.src/M000025.html +0 -24
  73. data/doc/rdoc/classes/Pho/QueryProfile.src/M000026.html +0 -20
  74. data/doc/rdoc/classes/Pho/QueryProfile.src/M000027.html +0 -18
  75. data/doc/rdoc/classes/Pho/QueryProfile.src/M000028.html +0 -18
  76. data/doc/rdoc/classes/Pho/QueryProfile.src/M000029.html +0 -21
  77. data/doc/rdoc/classes/Pho/QueryProfile.src/M000030.html +0 -18
  78. data/doc/rdoc/classes/Pho/QueryProfile.src/M000031.html +0 -18
  79. data/doc/rdoc/classes/Pho/QueryProfile.src/M000032.html +0 -38
  80. data/doc/rdoc/classes/Pho/QueryProfile.src/M000033.html +0 -18
  81. data/doc/rdoc/classes/Pho/RDFCollection.src/M000077.html +0 -23
  82. data/doc/rdoc/classes/Pho/RDFCollection.src/M000078.html +0 -22
  83. data/doc/rdoc/classes/Pho/RDFCollection.src/M000079.html +0 -24
  84. data/doc/rdoc/classes/Pho/RDFCollection.src/M000080.html +0 -23
  85. data/doc/rdoc/classes/Pho/RDFCollection.src/M000081.html +0 -18
  86. data/doc/rdoc/classes/Pho/RDFCollection.src/M000082.html +0 -22
  87. data/doc/rdoc/classes/Pho/RDFCollection.src/M000083.html +0 -22
  88. data/doc/rdoc/classes/Pho/RDFCollection.src/M000084.html +0 -26
  89. data/doc/rdoc/classes/Pho/RDFCollection.src/M000085.html +0 -23
  90. data/doc/rdoc/classes/Pho/RDFCollection.src/M000086.html +0 -18
  91. data/doc/rdoc/classes/Pho/RDFCollection.src/M000087.html +0 -18
  92. data/doc/rdoc/classes/Pho/Snapshot.src/M000070.html +0 -31
  93. data/doc/rdoc/classes/Pho/Snapshot.src/M000071.html +0 -21
  94. data/doc/rdoc/classes/Pho/Snapshot.src/M000072.html +0 -18
  95. data/doc/rdoc/classes/Pho/Snapshot.src/M000073.html +0 -37
  96. data/doc/rdoc/classes/Pho/Status.src/M000020.html +0 -20
  97. data/doc/rdoc/classes/Pho/Status.src/M000021.html +0 -31
  98. data/doc/rdoc/classes/Pho/Status.src/M000022.html +0 -18
  99. data/doc/rdoc/classes/Pho/Status.src/M000023.html +0 -18
  100. data/doc/rdoc/classes/Pho/Store.src/M000036.html +0 -22
  101. data/doc/rdoc/classes/Pho/Store.src/M000037.html +0 -18
  102. data/doc/rdoc/classes/Pho/Store.src/M000038.html +0 -25
  103. data/doc/rdoc/classes/Pho/Store.src/M000039.html +0 -20
  104. data/doc/rdoc/classes/Pho/Store.src/M000040.html +0 -20
  105. data/doc/rdoc/classes/Pho/Store.src/M000041.html +0 -28
  106. data/doc/rdoc/classes/Pho/Store.src/M000042.html +0 -23
  107. data/doc/rdoc/classes/Pho/Store.src/M000043.html +0 -18
  108. data/doc/rdoc/classes/Pho/Store.src/M000044.html +0 -18
  109. data/doc/rdoc/classes/Pho/Store.src/M000045.html +0 -18
  110. data/doc/rdoc/classes/Pho/Store.src/M000046.html +0 -18
  111. data/doc/rdoc/classes/Pho/Store.src/M000047.html +0 -23
  112. data/doc/rdoc/classes/Pho/Store.src/M000048.html +0 -22
  113. data/doc/rdoc/classes/Pho/Store.src/M000049.html +0 -26
  114. data/doc/rdoc/classes/Pho/Store.src/M000050.html +0 -24
  115. data/doc/rdoc/classes/Pho/Store.src/M000051.html +0 -20
  116. data/doc/rdoc/classes/Pho/Store.src/M000052.html +0 -20
  117. data/doc/rdoc/classes/Pho/Store.src/M000053.html +0 -25
  118. data/doc/rdoc/classes/Pho/Store.src/M000054.html +0 -20
  119. data/doc/rdoc/classes/Pho/Store.src/M000055.html +0 -30
  120. data/doc/rdoc/classes/Pho/Store.src/M000056.html +0 -21
  121. data/doc/rdoc/classes/Pho/Store.src/M000057.html +0 -23
  122. data/doc/rdoc/classes/Pho/Store.src/M000058.html +0 -28
  123. data/doc/rdoc/classes/Pho/Store.src/M000059.html +0 -18
  124. data/doc/rdoc/classes/Pho/Store.src/M000060.html +0 -18
  125. data/doc/rdoc/classes/Pho/Store.src/M000061.html +0 -18
  126. data/doc/rdoc/classes/Pho/Store.src/M000062.html +0 -31
  127. data/doc/rdoc/classes/Pho/Store.src/M000063.html +0 -21
  128. data/doc/rdoc/classes/Pho/Store.src/M000064.html +0 -20
  129. data/doc/rdoc/classes/Pho/Store.src/M000065.html +0 -20
  130. data/doc/rdoc/classes/Pho/Store.src/M000066.html +0 -20
  131. data/doc/rdoc/classes/Pho/Store.src/M000067.html +0 -20
  132. data/doc/rdoc/classes/Pho/Store.src/M000068.html +0 -20
  133. data/doc/rdoc/classes/Pho/Store.src/M000069.html +0 -20
@@ -1,6 +1,7 @@
1
1
  module Pho
2
2
 
3
3
  require 'digest/md5'
4
+ require 'tmpdir'
4
5
 
5
6
  #In the Talis Platform a "snapshot" is an backup of the contents of a Store
6
7
  #
@@ -23,35 +24,61 @@ module Pho
23
24
 
24
25
  #Units for Size, e.g. KB
25
26
  attr_reader :units
26
-
27
- #Class method to parse the HTML response from API, e.g. as produced by the Store.get_snapshots method
28
- #and create a new Snapshot object. At the moment the Platform only supports single snapshot.
29
- #
30
- #If the response was an error, then an exception will be thrown
27
+
28
+ #Date when snapshot was taken
29
+ attr_reader :date
30
+
31
+ # Read snapshot data from the given store
31
32
  #
32
- # resp:: HTTP response generated by the Store.get_snapshots method
33
- def Snapshot.parse(resp)
33
+ # store:: reference to a Store object
34
+ def Snapshot.read_from_store(store)
35
+ resp = store.get_snapshots()
36
+
34
37
  if (resp.status > 200)
35
38
  raise "Response was not successful. Status code was: #{resp.status}"
36
39
  end
37
40
  content = resp.content
38
41
 
39
- snapshot_url = content.match("<a href=\"(http://api.talis.com/stores/\.+/snapshots/\.+tar)\">\.+</a>")[1]
42
+ return parse(store.storeuri, content)
43
+ end
44
+
45
+ #Class method to parse the RDF response from the API, e.g. as produced by the Store.get_snapshots method
46
+ #and create a new Snapshot object. At the moment the Platform only supports single snapshot.
47
+ #
48
+ #If the response was an error, then an exception will be thrown
49
+ #
50
+ # storeuri:: URI of the store
51
+ # content:: response from the API
52
+ def Snapshot.parse(storeuri, content)
53
+
54
+ doc = REXML::Document.new(content)
55
+ root = doc.root
56
+
57
+ store = REXML::XPath.first(root, "//*[@rdf:about='#{storeuri}']", Pho::Namespaces::MAPPING )
58
+ snapshot = REXML::XPath.first(store, "bf:snapshot", Pho::Namespaces::MAPPING)
59
+ snapshot_url = snapshot.attributes["rdf:resource"]
60
+ snapshot_el = REXML::XPath.first(root, "//*[@rdf:about='#{snapshot_url}']", Pho::Namespaces::MAPPING )
40
61
 
41
- metadata = Regexp.new("<a href=\"(http://api.talis.com/stores/\.+/snapshots/\.+tar\.md5)\">\.+</a>\n\s+\-\s+([0-9]+) ([a-zA-Z]+)", "m")
42
- snapshot_md5_url = metadata.match(content)[1]
43
- snapshot_size = metadata.match(content)[2]
44
- snapshot_units = metadata.match(content)[3]
62
+ el = REXML::XPath.first(snapshot_el, "bf:md5", Pho::Namespaces::MAPPING)
63
+ snapshot_md5_url = el.attributes["rdf:resource"]
64
+
65
+ el = REXML::XPath.first(snapshot_el, "bf:filesize", Pho::Namespaces::MAPPING)
66
+ snapshot_size = el.text.split(" ")[0]
67
+ snapshot_units = el.text.split(" ")[1]
68
+
69
+ el = REXML::XPath.first(snapshot_el, "dc:date", Pho::Namespaces::MAPPING)
70
+ snapshot_date = el.text
45
71
 
46
- return Snapshot.new(snapshot_url, snapshot_md5_url, snapshot_size, snapshot_units)
72
+ return Snapshot.new(snapshot_url, snapshot_md5_url, snapshot_size, snapshot_units, snapshot_date)
47
73
 
48
74
  end
49
75
 
50
- def initialize(url, md5_url, size, units)
76
+ def initialize(url, md5_url, size, units, date)
51
77
  @url = url
52
78
  @md5_url = md5_url
53
79
  @size = size
54
80
  @units = units
81
+ @date = date
55
82
  end
56
83
 
57
84
 
@@ -64,11 +91,11 @@ module Pho
64
91
  # the download and compare it against the published value. If they don't match then a RuntimeError will
65
92
  # be raised
66
93
  #
94
+ # store:: the store to backup
67
95
  # dir:: directory in which snapshot will be stored
68
- # client:: specify a preconfigured client, e.g. to configure proxy servers, etc
69
- def download(dir, client=HTTPClient.new())
96
+ def backup(store, dir=Dir.tmpdir)
70
97
 
71
- published_md5 = read_md5(client)
98
+ published_md5 = read_md5(store.client)
72
99
 
73
100
  digest = Digest::MD5.new()
74
101
 
@@ -77,7 +104,7 @@ module Pho
77
104
 
78
105
  #FIXME: this is not efficient as the snapshot may be very large and this
79
106
  #will just read all of the data into memory
80
- content = client.get_content(@url)
107
+ content = store.client.get_content(@url)
81
108
  file.print(content)
82
109
  digest << content
83
110
 
@@ -90,5 +117,5 @@ module Pho
90
117
  end
91
118
 
92
119
  end
93
-
120
+
94
121
  end
@@ -6,9 +6,6 @@ module Pho
6
6
  # Changesets
7
7
  # Multisparql
8
8
  #
9
- # Listing jobs
10
- # Retrieving single job
11
- #
12
9
  # Conditional deletions
13
10
  # If-Modified-Since support
14
11
  # Robustness in uri fetching
@@ -177,12 +174,14 @@ module Pho
177
174
  #
178
175
  # query:: the SPARQL query
179
176
  # format:: the preferred response format
180
- def sparql(query, format)
177
+ def sparql(query, format=nil)
181
178
  u = self.build_uri("/services/sparql")
182
179
  params = {}
183
180
  params["query"] = query
184
181
  headers = {}
185
- headers["Accept"] = format
182
+ if format != nil
183
+ headers["Accept"] = format
184
+ end
186
185
  response = @client.get(u, params, headers)
187
186
  end
188
187
 
@@ -334,62 +333,29 @@ module Pho
334
333
  #############
335
334
  # JOBS
336
335
  #############
337
-
338
- # Construct an RDF/XML document containing a job request for submitting to the Platform.
339
- #
340
- # t:: a Time object, specifying the time at which the request should be carried out
341
- # joburi:: the URI for the JobType that should be created
342
- # label:: a label for this job.
343
- def build_job_request(t, joburi, label)
344
- time = t.strftime("%Y-%m-%dT%H:%M:%SZ")
345
- data = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
346
- data << " xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" "
347
- data << " xmlns:bf=\"http://schemas.talis.com/2006/bigfoot/configuration#\"> "
348
- data << " <bf:JobRequest>"
349
- data << " <rdfs:label>#{label}</rdfs:label>"
350
- data << " <bf:jobType rdf:resource=\"#{joburi}\"/>"
351
- data << " <bf:startTime>#{time}</bf:startTime>"
352
- data << " </bf:JobRequest>"
353
- data << "</rdf:RDF>"
354
- return data
355
- end
356
336
 
357
- def reset(t=Time.now)
358
- return submit_job(JOB_RESET, "Reset my store", t)
359
- end
337
+ #Retrieve metadata about a single job. Use Job.read_from_store as a convenience function
338
+ #which will return a fully-populated Job object
339
+ #
340
+ #uri:: the uri of the job to retrieve
341
+ def get_job(uri)
342
+ u = self.build_uri(uri)
343
+ response = @client.get(u, nil, ACCEPT_RDF)
344
+ return response
345
+ end
360
346
 
361
- def reindex(t=Time.now)
362
- return submit_job(JOB_REINDEX, "Reindex my store", t)
347
+ #Retrieve metadata about the Scheduled Jobs Collection from the store
348
+ def get_jobs()
349
+ u = self.build_uri("/jobs")
350
+ response = @client.get(u, nil, ACCEPT_RDF)
351
+ return response
363
352
  end
364
353
 
365
- def snapshot(t=Time.now)
366
- return submit_job(JOB_SNAPSHOT, "Snapshot my store", t)
367
- end
368
-
369
- #Restore this store from a previously generated Snapshot
370
- #The Platform can restore from any snapshot that is web-accessible
354
+ #Submit a job to the platform.
371
355
  #
372
- #snapshot_url:: the URL of the snapshot
373
- def restore(snapshot_url, t=Time.now)
374
- time = t.strftime("%Y-%m-%dT%H:%M:%SZ")
375
- data = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
376
- data << " xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" "
377
- data << " xmlns:bf=\"http://schemas.talis.com/2006/bigfoot/configuration#\"> "
378
- data << " <bf:JobRequest>"
379
- data << " <rdfs:label>Restore my store</rdfs:label>"
380
- data << " <bf:jobType rdf:resource=\"#{Pho::JOB_RESTORE}\"/>"
381
- data << " <bf:snapshotUri rdf:resource=\"#{snapshot_url}\"/>"
382
- data << " <bf:startTime>#{time}</bf:startTime>"
383
- data << " </bf:JobRequest>"
384
- data << "</rdf:RDF>"
385
- u = build_uri("/jobs")
386
- response = @client.post(u, data, RDF_XML )
387
- return response
388
- end
389
-
390
- def submit_job(joburi, label, t=Time.now)
356
+ #data:: RDF/XML representing the job request. See methods on Jobs class
357
+ def submit_job(data)
391
358
  u = build_uri("/jobs")
392
- data = build_job_request(t, joburi, label)
393
359
  response = @client.post(u, data, RDF_XML )
394
360
  return response
395
361
  end
@@ -410,7 +376,7 @@ module Pho
410
376
  # a Snapshot object
411
377
  def get_snapshots()
412
378
  u = build_uri("/snapshots")
413
- response = @client.get(u, nil, nil)
379
+ response = @client.get(u, nil, ACCEPT_RDF)
414
380
  return response
415
381
  end
416
382
 
@@ -0,0 +1,262 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+
7
+ class JobTest < Test::Unit::TestCase
8
+
9
+ JOB_COLLECTION = <<-EOL
10
+ <rdf:RDF
11
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
12
+ xmlns:j.0="http://schemas.talis.com/2005/dir/schema#"
13
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#" >
14
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs">
15
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#ScheduledJobCollection"/>
16
+ <j.1:job rdf:resource="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed"/>
17
+ <j.0:etag>"7f27f79a-13ee-4234-9291-f400fd296a0b"</j.0:etag>
18
+ </rdf:Description>
19
+ </rdf:RDF>
20
+ EOL
21
+
22
+ JOB = <<-EOL
23
+ <rdf:RDF
24
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
25
+ xmlns:j.0="http://purl.org/dc/terms/"
26
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#"
27
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
28
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed">
29
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#ResetDataJob"/>
30
+ <rdfs:label>Reset Store Job</rdfs:label>
31
+ <j.0:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:30:19Z</j.0:created>
32
+ <j.1:startTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:00Z</j.1:startTime>
33
+ </rdf:Description>
34
+ </rdf:RDF>
35
+ EOL
36
+
37
+ RESTORE_JOB = <<-EOL
38
+ <rdf:RDF
39
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
40
+ xmlns:j.0="http://purl.org/dc/terms/"
41
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#"
42
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
43
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed">
44
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#RestoreJob"/>
45
+ <j.1:snapshotUri rdf:resource="http://www.example.org/snapshot.tar"/>
46
+ <rdfs:label>Restore Store Job</rdfs:label>
47
+ <j.0:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:30:19Z</j.0:created>
48
+ <j.1:startTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:00Z</j.1:startTime>
49
+ </rdf:Description>
50
+ </rdf:RDF>
51
+ EOL
52
+
53
+ RUNNING_JOB = <<-EOL
54
+ <rdf:RDF
55
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
56
+ xmlns:j.0="http://purl.org/dc/terms/"
57
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#"
58
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
59
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed">
60
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#ResetDataJob"/>
61
+ <rdfs:label>Reset Store Job</rdfs:label>
62
+ <j.0:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:30:19Z</j.0:created>
63
+ <j.1:startTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:00Z</j.1:startTime>
64
+ <j.1:actualStartTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:12Z</j.1:actualStartTime>
65
+ <j.1:startMessage>ResetDataTask starting</j.1:startMessage>
66
+ <j.1:progressUpdate rdf:resource="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed/867fd0df-e127-4e17-03b-376af409f2a6"/>
67
+ </rdf:Description>
68
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed/867fd0df-e127-4e17-03b-376af409f2a6">
69
+ <j.1:progressUpdateMessage>Reset Data job running for store.</j.1:progressUpdateMessage>
70
+ <j.1:progressUpdateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:15Z</j.1:progressUpdateTime>
71
+ </rdf:Description>
72
+ </rdf:RDF>
73
+ EOL
74
+
75
+ #originally had mismatched uris
76
+ SUCCESSFUL_JOB = <<-EOL
77
+ <rdf:RDF
78
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
79
+ xmlns:j.0="http://purl.org/dc/terms/"
80
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#"
81
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
82
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed">
83
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#ResetDataJob"/>
84
+ <rdfs:label>Reset Store Job</rdfs:label>
85
+ <j.0:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:30:19Z</j.0:created>
86
+ <j.1:startTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:00Z</j.1:startTime>
87
+ <j.1:actualStartTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:12Z</j.1:actualStartTime>
88
+ <j.1:startMessage>ResetDataTask starting</j.1:startMessage>
89
+ <j.1:progressUpdate rdf:resource="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed/867fd0df-e127-4e17-03b-376af409f2a6"/>
90
+ <j.1:endTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:40Z</j.1:endTime>
91
+ <j.1:completionMessage>Reset store Complete.</j.1:completionMessage>
92
+ <j.1:completionStatus rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#success"/>
93
+ </rdf:Description>
94
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed/867fd0df-e127-4e17-03b-376af409f2a6">
95
+ <j.1:progressUpdateMessage>Reset Data job running for store.</j.1:progressUpdateMessage>
96
+ <j.1:progressUpdateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T16:35:15Z</j.1:progressUpdateTime>
97
+ </rdf:Description>
98
+ </rdf:RDF>
99
+ EOL
100
+
101
+ #no snapshot_uri?
102
+ ABORTED_JOB = <<-EOL
103
+ <rdf:RDF
104
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
105
+ xmlns:j.0="http://purl.org/dc/terms/"
106
+ xmlns:j.1="http://schemas.talis.com/2006/bigfoot/configuration#"
107
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
108
+ <rdf:Description rdf:about="http://api.talis.com/stores/testing/jobs/dbd51dfd-dd17-4bf1-a7d0-4a651587de14">
109
+ <rdf:type rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#RestoreJob"/>
110
+ <rdfs:label>Restore Snapshot Job</rdfs:label>
111
+ <j.0:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T17:02:19Z</j.0:created>
112
+ <j.1:startTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T17:02:19Z</j.1:startTime>
113
+ <j.1:actualStartTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T17:03:12Z</j.1:actualStartTime>
114
+ <j.1:startMessage>Restore store task starting using snapshot http://i-dont-exist.com/20080801105153.tar</j.1:startMessage>
115
+ <j.1:endTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2009-01-30T17:03:13Z</j.1:endTime>
116
+ <j.1:completionStatus rdf:resource="http://schemas.talis.com/2006/bigfoot/configuration#aborted"/>
117
+ <j.1:completionMessage>Unable to retrieve snapshot: http://i-dont-exist.com/20080801105153.tar Status code returned was: 404</j.1:completionMessage>
118
+ </rdf:Description>
119
+ </rdf:RDF>
120
+ EOL
121
+
122
+ def test_read_from_store()
123
+ mc = mock()
124
+ mc.expects(:set_auth)
125
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed",
126
+ anything, {"Accept" => "application/rdf+xml"}).returns(
127
+ HTTP::Message.new_response(JOB) )
128
+
129
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
130
+ job = Pho::Job.read_from_store("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", store);
131
+ assert_not_nil(job)
132
+ assert_equal("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", job.uri)
133
+ assert_equal("Reset Store Job", job.label)
134
+ assert_equal(Pho::Jobs::RESET, job.type)
135
+ assert_equal("2009-01-30T16:30:19Z", job.created)
136
+ assert_equal("2009-01-30T16:35:00Z", job.start_time)
137
+ end
138
+
139
+ def test_read_restore_job_from_store()
140
+ mc = mock()
141
+ mc.expects(:set_auth)
142
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed",
143
+ anything, {"Accept" => "application/rdf+xml"}).returns(
144
+ HTTP::Message.new_response(RESTORE_JOB) )
145
+
146
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
147
+ job = Pho::Job.read_from_store("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", store);
148
+ assert_not_nil(job)
149
+ assert_equal("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", job.uri)
150
+ assert_equal("Restore Store Job", job.label)
151
+ assert_equal(Pho::Jobs::RESTORE, job.type)
152
+ assert_equal("2009-01-30T16:30:19Z", job.created)
153
+ assert_equal("2009-01-30T16:35:00Z", job.start_time)
154
+ assert_equal("http://www.example.org/snapshot.tar", job.snapshot_uri)
155
+
156
+ end
157
+
158
+ def test_read_running_job()
159
+ mc = mock()
160
+ mc.expects(:set_auth)
161
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed",
162
+ anything, {"Accept" => "application/rdf+xml"}).returns(
163
+ HTTP::Message.new_response(RUNNING_JOB) )
164
+
165
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
166
+ job = Pho::Job.read_from_store("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", store);
167
+ assert_not_nil(job)
168
+ assert_equal("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", job.uri)
169
+ assert_equal("Reset Store Job", job.label)
170
+ assert_equal(Pho::Jobs::RESET, job.type)
171
+ assert_equal("2009-01-30T16:30:19Z", job.created)
172
+ assert_equal("2009-01-30T16:35:00Z", job.start_time)
173
+ assert_equal("2009-01-30T16:35:12Z", job.actual_start_time)
174
+ assert_equal(true, job.started?)
175
+ assert_equal("ResetDataTask starting", job.start_message)
176
+
177
+ progress_updates = job.progress_updates
178
+ assert_not_nil(progress_updates)
179
+ assert_equal(1, progress_updates.size)
180
+
181
+ update = progress_updates[0]
182
+ assert_equal("2009-01-30T16:35:15Z", update.time)
183
+ assert_equal("Reset Data job running for store.", update.message)
184
+
185
+ assert_equal(false, job.completed?)
186
+ assert_equal(false, job.successful?)
187
+ assert_equal(true, job.running?)
188
+ end
189
+
190
+ def test_read_successful_job()
191
+ mc = mock()
192
+ mc.expects(:set_auth)
193
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed",
194
+ anything, {"Accept" => "application/rdf+xml"}).returns(
195
+ HTTP::Message.new_response(SUCCESSFUL_JOB) )
196
+
197
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
198
+ job = Pho::Job.read_from_store("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", store);
199
+ assert_not_nil(job)
200
+ assert_equal("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", job.uri)
201
+ assert_equal("Reset Store Job", job.label)
202
+ assert_equal(Pho::Jobs::RESET, job.type)
203
+ assert_equal("2009-01-30T16:30:19Z", job.created)
204
+ assert_equal("2009-01-30T16:35:00Z", job.start_time)
205
+ assert_equal("2009-01-30T16:35:12Z", job.actual_start_time)
206
+ assert_equal(true, job.started?)
207
+ assert_equal("ResetDataTask starting", job.start_message)
208
+
209
+ progress_updates = job.progress_updates
210
+ assert_not_nil(progress_updates)
211
+ assert_equal(1, progress_updates.size)
212
+
213
+ update = progress_updates[0]
214
+ assert_equal("2009-01-30T16:35:15Z", update.time)
215
+ assert_equal("Reset Data job running for store.", update.message)
216
+ assert_equal("2009-01-30T16:35:40Z", job.end_time)
217
+ assert_equal(true, job.completed?)
218
+ assert_equal(true, job.successful?)
219
+ assert_equal(false, job.running?)
220
+ end
221
+
222
+
223
+ def test_read_aborted_job()
224
+ mc = mock()
225
+ mc.expects(:set_auth)
226
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs/dbd51dfd-dd17-4bf1-a7d0-4a651587de14",
227
+ anything, {"Accept" => "application/rdf+xml"}).returns(
228
+ HTTP::Message.new_response(ABORTED_JOB) )
229
+
230
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
231
+ job = Pho::Job.read_from_store("http://api.talis.com/stores/testing/jobs/dbd51dfd-dd17-4bf1-a7d0-4a651587de14", store);
232
+ assert_not_nil(job)
233
+ assert_equal("http://api.talis.com/stores/testing/jobs/dbd51dfd-dd17-4bf1-a7d0-4a651587de14", job.uri)
234
+ assert_equal("Restore Snapshot Job", job.label)
235
+ assert_equal(Pho::Jobs::RESTORE, job.type)
236
+ assert_equal("2009-01-30T17:02:19Z", job.created)
237
+ assert_equal("2009-01-30T17:02:19Z", job.start_time)
238
+ assert_equal("2009-01-30T17:03:12Z", job.actual_start_time)
239
+ assert_equal("2009-01-30T17:03:13Z", job.end_time)
240
+ assert_equal(true, job.started?)
241
+ assert_equal("Restore store task starting using snapshot http://i-dont-exist.com/20080801105153.tar", job.start_message)
242
+ assert_equal("Unable to retrieve snapshot: http://i-dont-exist.com/20080801105153.tar Status code returned was: 404", job.completion_message)
243
+ assert_equal(0, job.progress_updates.size)
244
+ assert_equal(true, job.completed?)
245
+ assert_equal(false, job.successful?)
246
+ assert_equal(false, job.running?)
247
+ end
248
+
249
+ def test_read_jobs()
250
+ mc = mock()
251
+ mc.expects(:set_auth)
252
+ mc.expects(:get).with("http://api.talis.com/stores/testing/jobs", anything, {"Accept" => "application/rdf+xml"}).returns(
253
+ HTTP::Message.new_response(JOB_COLLECTION))
254
+
255
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
256
+ jobs = Pho::Jobs.read_from_store(store)
257
+ assert_not_nil(jobs)
258
+ assert_equal(1, jobs.size)
259
+ assert_equal("http://api.talis.com/stores/testing/jobs/4d63b413-8819-49f2-8936-a819359b06ed", jobs[0])
260
+
261
+ end
262
+ end