X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9e2357191ca21631bcb6d8cf7a640d456a1a6cfa..e336e28f4ce9c13aad98d059d2befb505bff365b:/apps/workbench/app/models/pipeline_instance.rb diff --git a/apps/workbench/app/models/pipeline_instance.rb b/apps/workbench/app/models/pipeline_instance.rb index 89acbb0dbb..e9fa04ab6d 100644 --- a/apps/workbench/app/models/pipeline_instance.rb +++ b/apps/workbench/app/models/pipeline_instance.rb @@ -1,3 +1,5 @@ +require "arvados/keep" + class PipelineInstance < ArvadosBase attr_accessor :pipeline_template @@ -5,10 +7,14 @@ class PipelineInstance < ArvadosBase true end - def friendly_link_name + def friendly_link_name lookup=nil pipeline_name = self.name if pipeline_name.nil? or pipeline_name.empty? - template = PipelineTemplate.where(uuid: self.pipeline_template_uuid).first + template = if lookup and lookup[self.pipeline_template_uuid] + lookup[self.pipeline_template_uuid] + else + PipelineTemplate.find?(self.pipeline_template_uuid) if self.pipeline_template_uuid + end if template template.name else @@ -43,10 +49,16 @@ class PipelineInstance < ArvadosBase end end - def attribute_editable? attr, *args - super && (attr.to_sym == :name || attr.to_sym == :description || - (attr.to_sym == :components and - (self.state == 'New' || self.state == 'Ready'))) + def editable_attributes + %w(name description components) + end + + def attribute_editable?(name, ever=nil) + if name.to_s == "components" + (ever or %w(New Ready).include?(state)) and super + else + super + end end def attributes_for_display @@ -71,4 +83,62 @@ class PipelineInstance < ArvadosBase def textile_attributes [ 'description' ] end + + def job_uuids + components_map { |cspec| cspec[:job][:uuid] rescue nil } + end + + def job_log_ids + components_map { |cspec| cspec[:job][:log] rescue nil } + end + + def job_ids + components_map { |cspec| cspec[:job][:uuid] rescue nil } + end + + def stderr_log_object_uuids + result = job_uuids.values.compact + result << uuid + end + + def stderr_log_query(limit=nil) + query = Log. + where(event_type: "stderr", + object_uuid: stderr_log_object_uuids). + order("id DESC") + unless limit.nil? + query = query.limit(limit) + end + query + end + + def stderr_log_lines(limit=2000) + stderr_log_query(limit).results.reverse. + flat_map { |log| log.properties[:text].split("\n") rescue [] } + end + + def has_readable_logs? + log_pdhs, log_uuids = job_log_ids.values.compact.partition do |loc_s| + Keep::Locator.parse(loc_s) + end + if log_pdhs.any? and + Collection.where(portable_data_hash: log_pdhs).limit(1).results.any? + true + elsif log_uuids.any? and + Collection.where(uuid: log_uuids).limit(1).results.any? + true + else + stderr_log_query(1).results.any? + end + end + + def work_unit(label=nil) + PipelineInstanceWorkUnit.new(self, label || self.name, self.uuid) + end + + private + + def components_map + Hash[components.map { |cname, cspec| [cname, yield(cspec)] }] + end end