[ARVADOS] updated: 07f2ff368aa089e4f128578c49287d40d84dfcdf
git at public.curoverse.com
git at public.curoverse.com
Wed Aug 12 15:56:43 EDT 2015
Summary of changes:
services/api/script/salvage_collection.rb | 62 +++++++++++++++++--------------
1 file changed, 34 insertions(+), 28 deletions(-)
via 07f2ff368aa089e4f128578c49287d40d84dfcdf (commit)
from 687a5246e161ef1d191264d3b579271bc834223c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 07f2ff368aa089e4f128578c49287d40d84dfcdf
Author: radhika <radhika at curoverse.com>
Date: Wed Aug 12 15:53:03 2015 -0400
6859: updated script to append all locators to newly created manifest text from the original salvaged collection.
diff --git a/services/api/script/salvage_collection.rb b/services/api/script/salvage_collection.rb
index 796fa6e..97eb6a8 100755
--- a/services/api/script/salvage_collection.rb
+++ b/services/api/script/salvage_collection.rb
@@ -34,12 +34,10 @@ uuid, reason = ARGV
require File.dirname(__FILE__) + '/../config/environment'
require 'arvados/keep'
include ApplicationHelper
+require 'tempfile'
def salvage_collection uuid, reason
act_as_system_user do
- root_dir = '/tmp/salvage_uuids'
- Dir.mkdir(root_dir) unless File.exists?(root_dir)
-
src = Collection.find_by_uuid uuid
if !src
puts "No collection found for #{uuid}"
@@ -49,12 +47,7 @@ def salvage_collection uuid, reason
begin
src_manifest_text = src.manifest_text || ''
- # write the manifest_text to a file
- dir = root_dir+"/"+uuid
- Dir.mkdir(dir) unless File.exists?(dir)
- File.write(dir+"/invalid_manifest_text.txt", src_manifest_text)
-
- # also, create another file with the locators from the collection manifest_text
+ # Get all the locators from the original manifest
locators = []
src_manifest_text.each_line do |line|
line.split(' ').each do |word|
@@ -64,28 +57,41 @@ def salvage_collection uuid, reason
end
end
end
+ locators << 'd41d8cd98f00b204e9800998ecf8427e+0' if !locators.any?
+
+ # create new collection using 'arv-put' with original manifest_text as the data
+ temp_file = Tempfile.new('temp')
+ temp_file.write(src.manifest_text)
+
+ created = %x(arv-put --use-filename invalid_manifest_text.txt #{temp_file.path})
+
+ temp_file.close
+ temp_file.unlink
- locators_str = locators.join(' ')
- File.write(dir+"/salvaged_data", locators_str)
-
-=begin
- # create new collection with salvaged data
- dest_manifest_text = ". "
- dest_manifest_text += (src.portable_data_hash + " 0:#{src_manifest_text.length}:invalid_manifest_text.txt\n")
- dest_manifest_text += (". " + locators_str + " 0:#{locators_str.length}:salvaged_data\n")
- dest_name = "Salvaged from " + uuid + ", " + src.portable_data_hash
- dest = Collection.new name: dest_name, manifest_text: dest_manifest_text
- dest.save!
-=end
-
- # create new collection with salvaged data using 'arv keep put'
- created = %x(arv keep put #{dir}/*)
created.rstrip!
match = created.match HasUuid::UUID_REGEX
raise "uuid not found" if !match
- puts "Created salvaged collection for #{uuid} with uuid: #{created} #{match}"
+
+ # update this new collection manifest to reference all locators from the original manifest
+ new_collection = Collection.find_by_uuid created
+
+ new_manifest = new_collection['manifest_text']
+ new_manifest = new_manifest.gsub(/\+A[^+]*/, '')
+ total_size = 0
+ locators.each do |locator|
+ total_size += locator.split('+')[1].to_i
+ end
+ new_manifest += (". #{locators.join(' ')} 0:#{total_size}:salvaged_data\n")
+
+ new_collection.name = "salvaged from #{src.uuid}, #{src.portable_data_hash}"
+ new_collection.manifest_text = new_manifest
+ new_collection.portable_data_hash = Digest::MD5.hexdigest(new_manifest)
+
+ new_collection.save!
+
+ puts "Created collection for salvaged #{uuid} with uuid: #{created} #{match}"
rescue => error
- puts "Error creating salvaged collection for #{uuid}: #{error}"
+ puts "Error creating collection for #{uuid}: #{error}"
return
end
@@ -95,9 +101,9 @@ def salvage_collection uuid, reason
src.manifest_text = ''
src.portable_data_hash = 'd41d8cd98f00b204e9800998ecf8427e+0'
src.save!
- puts "Updated collection #{uuid}"
+ puts "Salvaged collection #{uuid}"
rescue => error
- puts "Error updating source collection #{uuid}: #{error}"
+ puts "Error salvaging collection #{uuid}: #{error}"
end
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list