1 class Arvados::V1::CollectionsController < ApplicationController
3 if resource_attrs[:uuid] and (loc = Locator.parse(resource_attrs[:uuid]))
4 resource_attrs[:portable_data_hash] = loc.to_s
5 resource_attrs.delete :uuid
10 def find_object_by_uuid
11 if loc = Locator.parse(params[:id])
13 if c = Collection.readable_by(*@read_users).where({ portable_data_hash: loc.to_s }).limit(1).first
15 uuid: c.portable_data_hash,
16 portable_data_hash: c.portable_data_hash,
17 manifest_text: c.manifest_text,
19 data_size: c.data_size
29 sign_manifests(@object[:manifest_text])
30 if @object.is_a? Collection
31 render json: @object.as_api_response
38 sign_manifests(*@objects.map { |c| c[:manifest_text] })
42 def script_param_edges(visited, sp)
46 script_param_edges(visited, v)
50 script_param_edges(visited, v)
54 if loc = Locator.parse(sp)
55 search_edges(visited, loc.to_s, :search_up)
60 def search_edges(visited, uuid, direction)
61 if uuid.nil? or uuid.empty? or visited[uuid]
65 if loc = Locator.parse(uuid)
67 return if visited[loc.to_s]
70 logger.debug "visiting #{uuid}"
73 # uuid is a portable_data_hash
74 if c = Collection.readable_by(*@read_users).where(portable_data_hash: loc.to_s).limit(1).first
76 portable_data_hash: c.portable_data_hash,
78 data_size: c.data_size
82 if direction == :search_up
83 # Search upstream for jobs where this locator is the output of some job
84 Job.readable_by(*@read_users).where(output: loc.to_s).each do |job|
85 search_edges(visited, job.uuid, :search_up)
88 Job.readable_by(*@read_users).where(log: loc.to_s).each do |job|
89 search_edges(visited, job.uuid, :search_up)
91 elsif direction == :search_down
92 if loc.to_s == "d41d8cd98f00b204e9800998ecf8427e+0"
93 # Special case, don't follow the empty collection.
97 # Search downstream for jobs where this locator is in script_parameters
98 Job.readable_by(*@read_users).where(["jobs.script_parameters like ?", "%#{loc.to_s}%"]).each do |job|
99 search_edges(visited, job.uuid, :search_down)
103 # uuid is a regular Arvados UUID
104 rsc = ArvadosModel::resource_class_for_uuid uuid
106 Job.readable_by(*@read_users).where(uuid: uuid).each do |job|
107 visited[uuid] = job.as_api_response
108 if direction == :search_up
109 # Follow upstream collections referenced in the script parameters
110 script_param_edges(visited, job.script_parameters)
111 elsif direction == :search_down
112 # Follow downstream job output
113 search_edges(visited, job.output, direction)
116 elsif rsc == Collection
117 if c = Collection.readable_by(*@read_users).where(uuid: uuid).limit(1).first
118 search_edges(visited, c.portable_data_hash, direction)
119 visited[c.portable_data_hash] = c.as_api_response
122 rsc.where(uuid: uuid).each do |r|
123 visited[uuid] = r.as_api_response
128 if direction == :search_up
129 # Search for provenance links pointing to the current uuid
130 Link.readable_by(*@read_users).
131 where(head_uuid: uuid, link_class: "provenance").
133 visited[link.uuid] = link.as_api_response
134 search_edges(visited, link.tail_uuid, direction)
136 elsif direction == :search_down
137 # Search for provenance links emanating from the current uuid
138 Link.readable_by(current_user).
139 where(tail_uuid: uuid, link_class: "provenance").
141 visited[link.uuid] = link.as_api_response
142 search_edges(visited, link.head_uuid, direction)
149 search_edges(visited, @object[:uuid] || @object[:portable_data_hash], :search_up)
155 search_edges(visited, @object[:uuid] || @object[:portable_data_hash], :search_down)
162 if action_name == 'index'
163 # Omit manifest_text from index results unless expressly selected.
164 @select ||= model_class.api_accessible_attributes(:user).
165 map { |attr_spec| attr_spec.first.to_s } - ["manifest_text"]
170 def sign_manifests(*manifests)
171 if current_api_client_authorization
173 key: Rails.configuration.blob_signing_key,
174 api_token: current_api_client_authorization.api_token,
175 ttl: Rails.configuration.blob_signing_ttl,
177 manifests.each do |text|
178 Collection.munge_manifest_locators(text) do |loc|
179 Blob.sign_locator(loc.to_s, signing_opts)