1 class CollectionsController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:graph]
3 skip_before_filter :check_user_agreements, :only => [:show_file]
10 @collections = Collection.limit(100).to_hash
11 @links = Link.eager.limit(100).where(head_kind: 'arvados#collection', link_class: 'resources', name: 'wants') |
12 Link.eager.limit(100).where(tail_kind: 'arvados#collection', link_class: 'data_origin')
13 @collections.merge!(Collection.
15 where(uuid: @links.select{|x|x.head_kind=='arvados#collection'}.collect(&:head_uuid) |
16 @links.select{|x|x.tail_kind=='arvados#collection'}.collect(&:tail_uuid)).
19 @collections.each do |uuid, c|
20 ci = (@collection_info[uuid] ||= {uuid: uuid})
21 ci[:created_at] = c.created_at
24 if l.head_kind == 'arvados#collection'
25 c = (@collection_info[l.head_uuid] ||= {uuid: l.head_uuid})
26 if l.link_class == 'resources' and l.name == 'wants'
27 if l.head.respond_to? :created_at
28 c[:created_at] = l.head.created_at
31 if l.owner_uuid == current_user.uuid
32 c[:wanted_by_me] = true
36 if l.tail_kind == 'arvados#collection'
37 c = (@collection_info[l.tail_uuid] ||= {uuid: l.tail_uuid})
38 if l.link_class == 'data_origin'
46 opts = params.merge(arvados_api_token: Thread.current[:arvados_api_token])
47 if r = params[:file].match(/(\.\w+)/)
50 self.response.headers['Content-Type'] =
51 Rack::Mime::MIME_TYPES[ext] || 'application/octet-stream'
52 self.response.headers['Content-Length'] = params[:size] if params[:size]
53 self.response.headers['Content-Disposition'] = params[:disposition] if params[:disposition]
54 self.response_body = FileStreamer.new opts
58 return super if !@object
61 @output2colorindex = {}
62 @sourcedata = {params[:uuid] => {uuid: params[:uuid]}}
69 Job.where(output: @sourcedata.keys).sort_by { |a| a.finished_at || a.created_at }.reverse.each do |job|
70 if !@output2colorindex[job.output]
72 @output2colorindex[job.output] = (colorindex += 1) % 10
73 @provenance << {job: job, output: job.output}
74 @sourcedata.delete job.output
75 @output2job[job.output] = job
76 job.dependencies.each do |new_source_data|
77 unless @output2colorindex[new_source_data]
78 @sourcedata[new_source_data] = {uuid: new_source_data}
85 Link.where(head_uuid: @sourcedata.keys | @output2job.keys).each do |link|
86 if link.link_class == 'resources' and link.name == 'wants'
87 @protected[link.head_uuid] = true
90 Link.where(tail_uuid: @sourcedata.keys).each do |link|
91 if link.link_class == 'data_origin'
92 @sourcedata[link.tail_uuid][:data_origins] ||= []
93 @sourcedata[link.tail_uuid][:data_origins] << [link.name, link.head_kind, link.head_uuid]
96 Collection.where(uuid: @sourcedata.keys).each do |collection|
97 if @sourcedata[collection.uuid]
98 @sourcedata[collection.uuid][:collection] = collection
105 def initialize(opts={})
109 return unless @opts[:uuid] && @opts[:file]
112 'ARVADOS_API_HOST' =>
113 $arvados_api_client.arvados_v1_base.
114 sub(/\/arvados\/v1/, '').
115 sub(/^https?:\/\//, ''),
116 'ARVADOS_API_TOKEN' =>
117 @opts[:arvados_api_token],
118 'ARVADOS_API_HOST_INSECURE' =>
119 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
121 IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
123 while buf = io.read(2**20)
127 Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0