let pipeline_invocation#active be a regular attribute
[arvados.git] / app / models / pipeline_invocation.rb
index 626f5eb5cd66f7a08ad7f8d4a590fa0020947e5f..c355056d348b7a9d69290b7cfa3f09f579206f7e 100644 (file)
@@ -4,16 +4,23 @@ class PipelineInvocation < OrvosModel
   include CommonApiTemplate
   serialize :components, Hash
   belongs_to :pipeline, :foreign_key => :pipeline_uuid, :primary_key => :uuid
+  attr_accessor :pipeline
 
   before_validation :bootstrap_components
   before_validation :update_success
 
   api_accessible :superuser, :extend => :common do |t|
     t.add :pipeline_uuid
+    t.add :pipeline, :if => :pipeline
     t.add :name
     t.add :components
     t.add :success
     t.add :active
+    t.add :dependencies
+  end
+
+  def dependencies
+    dependency_search(self.components).keys
   end
 
   def progress_table
@@ -23,10 +30,17 @@ class PipelineInvocation < OrvosModel
       components['steps'].collect do |step|
         nrow += 1
         row = [nrow, step['name']]
-        if step['output_data_locator']
-          row << 1.0
+        if step['complete'] and step['complete'] != 0
+          if step['output_data_locator']
+            row << 1.0
+          else
+            row << 0.0
+          end
         else
           row << 0.0
+          if step['failed']
+            self.success = false
+          end
         end
         row << (step['warehousejob']['id'] rescue nil)
         row << (step['warehousejob']['revision'] rescue nil)
@@ -57,4 +71,28 @@ class PipelineInvocation < OrvosModel
       self.success = true
     end
   end
+
+  def dependency_search(haystack)
+    if haystack.is_a? String
+      if (re = haystack.match /^([0-9a-f]{32}(\+[^,]+)*)+/)
+        {re[1] => true}
+      else
+        {}
+      end
+    elsif haystack.is_a? Array
+      deps = {}
+      haystack.each do |value|
+        deps.merge! dependency_search(value)
+      end
+      deps
+    elsif haystack.respond_to? :keys
+      deps = {}
+      haystack.each do |key, value|
+        deps.merge! dependency_search(value)
+      end
+      deps
+    else
+      {}
+    end
+  end
 end