1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class PipelineInstance < ArvadosBase
8 attr_accessor :pipeline_template
10 def self.goes_in_projects?
14 def friendly_link_name lookup=nil
15 pipeline_name = self.name
16 if pipeline_name.nil? or pipeline_name.empty?
17 template = if lookup and lookup[self.pipeline_template_uuid]
18 lookup[self.pipeline_template_uuid]
20 PipelineTemplate.find?(self.pipeline_template_uuid) if self.pipeline_template_uuid
34 PipelineTemplate.find(pipeline_template_uuid).name
40 def update_job_parameters(new_params)
41 self.components[:steps].each_with_index do |step, i|
42 step[:params].each do |param|
43 if new_params.has_key?(new_param_name = "#{i}/#{param[:name]}") or
44 new_params.has_key?(new_param_name = "#{step[:name]}/#{param[:name]}") or
45 new_params.has_key?(new_param_name = param[:name])
47 %w(hash data_locator).collect(&:to_sym).each do |ptype|
48 param_type = ptype if param.has_key? ptype
50 param[param_type] = new_params[new_param_name]
56 def editable_attributes
57 %w(name description components)
60 def attribute_editable?(name, ever=nil)
61 if name.to_s == "components"
62 (ever or %w(New Ready).include?(state)) and super
68 def attributes_for_display
69 super.reject { |k,v| k == 'components' }
76 def component_input_title(component_name, input_name)
77 component = components[component_name]
78 return nil if component.nil?
79 param_info = component[:script_parameters].andand[input_name.to_sym]
80 if param_info.is_a?(Hash) and param_info[:title]
83 "\"#{input_name.to_s}\" parameter for #{component[:script]} script in #{component_name} component"
87 def textile_attributes
92 components_map { |cspec| cspec[:job][:uuid] rescue nil }
96 components_map { |cspec| cspec[:job][:log] rescue nil }
100 components_map { |cspec| cspec[:job][:uuid] rescue nil }
103 def stderr_log_object_uuids
104 result = job_uuids.values.compact
108 def stderr_log_query(limit=nil)
111 where(event_type: "stderr",
112 object_uuid: stderr_log_object_uuids).
113 order("created_at DESC")
115 query = query.limit(limit)
120 def stderr_log_lines(limit=2000)
121 stderr_log_query(limit).results.reverse.
122 flat_map { |log| log.properties[:text].split("\n") rescue [] }
125 def has_readable_logs?
126 log_pdhs, log_uuids = job_log_ids.values.compact.partition do |loc_s|
127 Keep::Locator.parse(loc_s)
130 Collection.where(portable_data_hash: log_pdhs).limit(1).with_count("none").results.any?
132 elsif log_uuids.any? and
133 Collection.where(uuid: log_uuids).limit(1).with_count("none").results.any?
136 stderr_log_query(1).results.any?
140 def work_unit(label=nil)
141 PipelineInstanceWorkUnit.new(self, label || self.name, self.uuid)
145 arvados_api_client.api "pipeline_instances/#{self.uuid}/", "cancel", {"cascade" => true}
151 Hash[components.map { |cname, cspec| [cname, yield(cspec)] }]