+require "arvados/keep"
+
class PipelineInstance < ArvadosBase
attr_accessor :pipeline_template
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
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
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)
+ end
+
+ private
+
+ def components_map
+ Hash[components.map { |cname, cspec| [cname, yield(cspec)] }]
+ end
end