3 class Arvados::V1::CollectionsController < ApplicationController
7 if resource_attrs[:uuid] and (loc = Keep::Locator.parse(resource_attrs[:uuid]))
8 resource_attrs[:portable_data_hash] = loc.to_s
9 resource_attrs.delete :uuid
14 def find_objects_for_index
15 if params[:include_trash] || ['destroy', 'trash'].include?(action_name)
16 @objects = Collection.unscoped.readable_by(*@read_users)
21 def find_object_by_uuid
22 if loc = Keep::Locator.parse(params[:id])
24 if c = Collection.readable_by(*@read_users).where({ portable_data_hash: loc.to_s }).limit(1).first
26 uuid: c.portable_data_hash,
27 portable_data_hash: c.portable_data_hash,
28 manifest_text: c.signed_manifest_text,
38 if @object.is_a? Collection
39 # Omit unsigned_manifest_text
40 @select ||= model_class.selectable_attributes - ["unsigned_manifest_text"]
48 if !@object.is_trashed
49 @object.update_attributes!(trash_at: db_current_time)
51 earliest_delete = (@object.trash_at +
52 Rails.configuration.blob_signature_ttl.seconds)
53 if @object.delete_at > earliest_delete
54 @object.update_attributes!(delete_at: earliest_delete)
60 if !@object.is_trashed
61 @object.update_attributes!(trash_at: db_current_time)
66 def find_collections(visited, sp, &b)
69 sp.class.columns.each do |c|
70 find_collections(visited, sp[c.name.to_sym], &b) if c.name != "log"
74 find_collections(visited, v, &b)
78 find_collections(visited, v, &b)
81 if m = /[a-f0-9]{32}\+\d+/.match(sp)
83 elsif m = Collection.uuid_regex.match(sp)
89 def search_edges(visited, uuid, direction)
90 if uuid.nil? or uuid.empty? or visited[uuid]
94 if loc = Keep::Locator.parse(uuid)
96 return if visited[loc.to_s]
99 logger.debug "visiting #{uuid}"
102 # uuid is a portable_data_hash
103 collections = Collection.readable_by(*@read_users).where(portable_data_hash: loc.to_s)
104 c = collections.limit(2).all
106 visited[loc.to_s] = c[0]
108 name = collections.limit(1).where("name <> ''").first
110 visited[loc.to_s] = {
111 portable_data_hash: c[0].portable_data_hash,
112 name: "#{name.name} + #{collections.count-1} more"
115 visited[loc.to_s] = {
116 portable_data_hash: c[0].portable_data_hash,
122 if direction == :search_up
123 # Search upstream for jobs where this locator is the output of some job
124 Job.readable_by(*@read_users).where(output: loc.to_s).each do |job|
125 search_edges(visited, job.uuid, :search_up)
128 Job.readable_by(*@read_users).where(log: loc.to_s).each do |job|
129 search_edges(visited, job.uuid, :search_up)
131 elsif direction == :search_down
132 if loc.to_s == "d41d8cd98f00b204e9800998ecf8427e+0"
133 # Special case, don't follow the empty collection.
137 # Search downstream for jobs where this locator is in script_parameters
138 Job.readable_by(*@read_users).where(["jobs.script_parameters like ?", "%#{loc.to_s}%"]).each do |job|
139 search_edges(visited, job.uuid, :search_down)
142 Job.readable_by(*@read_users).where(["jobs.docker_image_locator = ?", "#{loc.to_s}"]).each do |job|
143 search_edges(visited, job.uuid, :search_down)
147 # uuid is a regular Arvados UUID
148 rsc = ArvadosModel::resource_class_for_uuid uuid
150 Job.readable_by(*@read_users).where(uuid: uuid).each do |job|
151 visited[uuid] = job.as_api_response
152 if direction == :search_up
153 # Follow upstream collections referenced in the script parameters
154 find_collections(visited, job) do |hash, col_uuid|
155 search_edges(visited, hash, :search_up) if hash
156 search_edges(visited, col_uuid, :search_up) if col_uuid
158 elsif direction == :search_down
159 # Follow downstream job output
160 search_edges(visited, job.output, direction)
163 elsif rsc == Collection
164 if c = Collection.readable_by(*@read_users).where(uuid: uuid).limit(1).first
165 search_edges(visited, c.portable_data_hash, direction)
166 visited[c.portable_data_hash] = c.as_api_response
169 rsc.where(uuid: uuid).each do |r|
170 visited[uuid] = r.as_api_response
175 if direction == :search_up
176 # Search for provenance links pointing to the current uuid
177 Link.readable_by(*@read_users).
178 where(head_uuid: uuid, link_class: "provenance").
180 visited[link.uuid] = link.as_api_response
181 search_edges(visited, link.tail_uuid, direction)
183 elsif direction == :search_down
184 # Search for provenance links emanating from the current uuid
185 Link.readable_by(current_user).
186 where(tail_uuid: uuid, link_class: "provenance").
188 visited[link.uuid] = link.as_api_response
189 search_edges(visited, link.head_uuid, direction)
196 search_edges(visited, @object[:portable_data_hash], :search_up)
197 search_edges(visited, @object[:uuid], :search_up)
203 search_edges(visited, @object[:uuid], :search_down)
204 search_edges(visited, @object[:portable_data_hash], :search_down)
210 def load_limit_offset_order_params *args
212 if action_name == 'index'
213 # Omit manifest_text and unsigned_manifest_text from index results unless expressly selected.
214 @select ||= model_class.selectable_attributes - ["manifest_text", "unsigned_manifest_text"]