X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/69e4d608045afea775b77d1f41afddf0bdfcf5c6..85c625c40ad873d0efac33f8a63c1ee256185e36:/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 83328b9e52..d481f41c7e 100644 --- a/apps/workbench/app/models/pipeline_instance.rb +++ b/apps/workbench/app/models/pipeline_instance.rb @@ -1,3 +1,9 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + +require "arvados/keep" + class PipelineInstance < ArvadosBase attr_accessor :pipeline_template @@ -11,7 +17,7 @@ class PipelineInstance < ArvadosBase template = if lookup and lookup[self.pipeline_template_uuid] lookup[self.pipeline_template_uuid] else - PipelineTemplate.where(uuid: self.pipeline_template_uuid).first + PipelineTemplate.find?(self.pipeline_template_uuid) if self.pipeline_template_uuid end if template template.name @@ -52,7 +58,11 @@ class PipelineInstance < ArvadosBase end def attribute_editable?(name, ever=nil) - (ever or %w(New Ready).include?(state)) and super + if name.to_s == "components" + (ever or %w(New Ready).include?(state)) and super + else + super + end end def attributes_for_display @@ -77,4 +87,67 @@ 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. + with_count('none'). + where(event_type: "stderr", + object_uuid: stderr_log_object_uuids). + order("created_at 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).with_count("none").results.any? + true + elsif log_uuids.any? and + Collection.where(uuid: log_uuids).limit(1).with_count("none").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 + + def cancel + arvados_api_client.api "pipeline_instances/#{self.uuid}/", "cancel", {"cascade" => true} + end + + private + + def components_map + Hash[components.map { |cname, cspec| [cname, yield(cspec)] }] + end end