9767: create a pipeline instance or container request depending on the template selected.
authorradhika <radhika@curoverse.com>
Fri, 19 Aug 2016 21:06:41 +0000 (17:06 -0400)
committerradhika <radhika@curoverse.com>
Fri, 19 Aug 2016 21:06:41 +0000 (17:06 -0400)
apps/workbench/app/controllers/work_units_controller.rb
apps/workbench/app/models/container_work_unit.rb
apps/workbench/app/models/pipeline_instance_work_unit.rb
apps/workbench/app/models/work_unit.rb
apps/workbench/app/views/projects/_show_dashboard.html.erb
apps/workbench/config/routes.rb

index ff69d89fda423d52b63b70b0ef6bf328d2fdd3d3..6cda2e80718bd255c08401288923b65a59fb4cda 100644 (file)
@@ -34,4 +34,82 @@ class WorkUnitsController < ApplicationController
   def next_page_href with_params={}
     @next_page_href
   end
+
+  def create
+    template_uuid = params['work_unit']['template_uuid']
+
+    attrs = {}
+    res = resource_class_for_uuid(template_uuid)
+    if res == PipelineTemplate
+      model_class = PipelineInstance
+      attrs['pipeline_template_uuid'] = template_uuid
+    elsif res == Workflow
+      # workflow json
+      workflow = Workflow.find? template_uuid
+      if workflow.workflow
+        begin
+          wf_json = JSON.dump(YAML::load(workflow.workflow))
+        rescue => e
+          logger.error "Error converting workflow yaml to json: #{e.message}"
+          raise ArgumentError, "Error converting workflow yaml to json: #{e.message}"
+        end
+      end
+
+      model_class = ContainerRequest
+
+      attrs['properties'] = {'template_uuid' => template_uuid}
+      attrs['priority'] = 1
+      attrs['state'] = "Uncommitted"
+
+      # required
+      attrs['command'] = ["arvados-cwl-runner", "--local", "--api=containers", "/var/lib/cwl/workflow.json", "/var/lib/cwl/cwl.input.json"]
+      attrs['container_image'] = "arvados/jobs"
+      attrs['cwd'] = "/var/spool/cwl"
+      attrs['output_path'] = "/var/spool/cwl"
+
+      # mounts
+      mounts = {
+        "/var/lib/cwl/cwl.input.json" => {
+          "kind" => "json",
+          "content" => {}
+        },
+        "stdout" => {
+          "kind" => "file",
+          "path" => "/var/spool/cwl/cwl.output.json"
+        },
+        "/var/spool/cwl" => {
+          "kind" => "collection",
+          "writable" => true
+        }
+      }
+      if wf_json
+        mounts["/var/lib/cwl/workflow.json"] = {
+          "kind" => "json",
+          "content" => {
+            "class" => wf_json
+          }
+        }
+      end
+      attrs['mounts'] = mounts
+
+      # runtime constriants
+      runtime_constraints = {
+        "vcpus" => 1,
+        "ram" => 256000000,
+        "API" => true
+      }
+      attrs['runtime_constraints'] = runtime_constraints
+    else
+      raise ArgumentError, "Unsupported template uuid: #{template_uuid}"
+    end
+
+    attrs['owner_uuid'] = params['work_unit']['owner_uuid']
+    @object ||= model_class.new attrs
+
+    if @object.save
+      redirect_to @object
+    else
+      render_error status: 422
+    end
+  end
 end
index 4f4c915e066ce3d8c2ef4427336e5a71b0b87b2e..1ed182c35f8482e39537e0591c849f8538d5934f 100644 (file)
@@ -142,6 +142,13 @@ class ContainerWorkUnit < ProxyWorkUnit
     end
   end
 
+  def template_uuid
+    properties = get(:properties)
+    if properties
+      properties[:workflow_uuid]
+    end
+  end
+
   # End combined propeties
 
   protected
index 889fa1a7f3cccecf86c53f5cd837ad4f34cb7ca2..dd5685ac3d8082d5a5836896afa310b416e728f2 100644 (file)
@@ -51,4 +51,8 @@ class PipelineInstanceWorkUnit < ProxyWorkUnit
   def title
     "pipeline"
   end
+
+  def template_uuid
+    get(:pipeline_template_uuid)
+  end
 end
index 0d194b88a5f8c70a09a4f6044c0a6f90ab388b07..7373bc242353b99c43f3cd73708e1ce9c7235599 100644 (file)
@@ -195,4 +195,8 @@ class WorkUnit
   def render_log
     # return partial and locals to be rendered
   end
+
+  def template_uuid
+    # return the uuid of this work unit's template, if one exists
+  end
 end
index 0b0b7e853e62c05329add86d7ff6bacd32436ef0..ef947ed4641db5fc43fdfd4610c03c8fbf7370a7 100644 (file)
@@ -8,23 +8,11 @@
               <span>
                 <%= link_to(
                 choose_work_unit_templates_path(
-                  title: 'Choose a process to run:',
+                  title: 'Choose a pipeline or process to run:',
                   action_name: 'Next: choose inputs <i class="fa fa-fw fa-arrow-circle-right"></i>',
-                  action_href: pipeline_instances_path,
+                  action_href: work_units_path,
                   action_method: 'post',
-                  action_data: {'selection_param' => 'pipeline_instance[pipeline_template_uuid]', 'pipeline_instance[owner_uuid]' => current_user.uuid, 'success' => 'redirect-to-created-object'}.to_json),
-                { class: "btn btn-primary btn-xs", remote: true }) do %>
-                  <i class="fa fa-fw fa-gear"></i> Run a process...
-                <% end %>
-              </span>
-              <span>
-                <%= link_to(
-                choose_pipeline_templates_path(
-                  title: 'Choose a pipeline to run:',
-                  action_name: 'Next: choose inputs <i class="fa fa-fw fa-arrow-circle-right"></i>',
-                  action_href: pipeline_instances_path,
-                  action_method: 'post',
-                  action_data: {'selection_param' => 'pipeline_instance[pipeline_template_uuid]', 'pipeline_instance[owner_uuid]' => current_user.uuid, 'success' => 'redirect-to-created-object'}.to_json),
+                  action_data: {'selection_param' => 'work_unit[template_uuid]', 'work_unit[owner_uuid]' => current_user.uuid, 'success' => 'redirect-to-created-object'}.to_json),
                 { class: "btn btn-primary btn-xs", remote: true }) do %>
                   <i class="fa fa-fw fa-gear"></i> Run a pipeline...
                 <% end %>
index bc45a4bddf4ae5bfd0c62aa76afc0b950b7e660e..7f7854864190318171750cb498a0dc7d941156c9 100644 (file)
@@ -15,6 +15,7 @@ ArvadosWorkbench::Application.routes.draw do
   get "star" => 'actions#star', :as => :star
   get "all_processes" => 'work_units#index', :as => :all_processes
   get "choose_work_unit_templates" => 'work_unit_templates#choose', :as => :choose_work_unit_templates
+  resources :work_units
   resources :nodes
   resources :humans
   resources :traits