[ARVADOS] created: b3b64d046641ccc39e4f4d6fab85a8b831732d51

Git user git at public.curoverse.com
Mon Jun 13 23:11:17 EDT 2016


        at  b3b64d046641ccc39e4f4d6fab85a8b831732d51 (commit)


commit b3b64d046641ccc39e4f4d6fab85a8b831732d51
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 13 23:10:51 2016 -0400

    9372: container display

diff --git a/apps/workbench/app/controllers/container_requests_controller.rb b/apps/workbench/app/controllers/container_requests_controller.rb
index 94cc513..ea26801 100644
--- a/apps/workbench/app/controllers/container_requests_controller.rb
+++ b/apps/workbench/app/controllers/container_requests_controller.rb
@@ -1,2 +1,9 @@
 class ContainerRequestsController < ApplicationController
+  def show_pane_list
+    %w(Status Log Advanced)
+  end
+
+  def cancel
+    @object.update_attributes! priority: 0
+  end
 end
diff --git a/apps/workbench/app/controllers/containers_controller.rb b/apps/workbench/app/controllers/containers_controller.rb
index 57c2700..86582df 100644
--- a/apps/workbench/app/controllers/containers_controller.rb
+++ b/apps/workbench/app/controllers/containers_controller.rb
@@ -1,2 +1,5 @@
 class ContainersController < ApplicationController
+  def show_pane_list
+    %w(Status Log Advanced)
+  end
 end
diff --git a/apps/workbench/app/models/container_request.rb b/apps/workbench/app/models/container_request.rb
index 73609c5..b41cec9 100644
--- a/apps/workbench/app/models/container_request.rb
+++ b/apps/workbench/app/models/container_request.rb
@@ -1,3 +1,9 @@
 class ContainerRequest < ArvadosBase
+  def cancel
+    arvados_api_client.api "container_requests/#{self.uuid}/", "cancel", {}
+  end
 
+  def work_unit(label=nil)
+    ContainerWorkUnit.new(self, label)
+  end
 end
diff --git a/apps/workbench/app/models/container_work_unit.rb b/apps/workbench/app/models/container_work_unit.rb
index e235619..9796ef8 100644
--- a/apps/workbench/app/models/container_work_unit.rb
+++ b/apps/workbench/app/models/container_work_unit.rb
@@ -1,53 +1,132 @@
 class ContainerWorkUnit < ProxyWorkUnit
+  attr_accessor :related
+
+  def initialize proxied, label
+    super
+    if @proxied.is_a?(ContainerRequest)
+      container_uuid = get(:container_uuid)
+      if container_uuid
+        @related = Container.where(uuid: container_uuid).first rescue nil
+      end
+    end
+  end
+
   def children
     return self.my_children if self.my_children
 
     items = []
 
-    crs = {}
-    reqs = ContainerRequest.where(requesting_container_uuid: uuid).results
-    reqs.each { |cr| crs[cr.container_uuid] = cr.name }
+    if @proxied.is_a?(Container)
+      crs = {}
+      reqs = ContainerRequest.where(requesting_container_uuid: uuid).results
+      reqs.each { |cr| crs[cr.container_uuid] = cr.name }
+
+      containers = Container.where(uuid: crs.keys).results
+      containers.each do |c|
+        items << c.work_unit(crs[c.uuid] || 'this container')
+      end
 
-    containers = Container.where(uuid: crs.keys).results
-    containers.each do |c|
-      items << c.work_unit(crs[c.uuid])
+      self.my_children = items
+    else
+      container_uuid = get(:container_uuid)
+      if container_uuid
+        reqs = ContainerRequest.where(requesting_container_uuid: container_uuid).results
+        reqs.each do |cr|
+          items << cr.work_unit(cr.name || 'this container')
+        end
+      end
     end
 
     self.my_children = items
   end
 
+  def title
+    "container"
+  end
+
+  def can_cancel?
+    @proxied.is_a?(ContainerRequest) && state_label.in?(["Queued", "Locked", "Running"])
+  end
+
+  def container_uuid
+    get(:container_uuid)
+  end
+
+  # For the following properties, use value from the @related container if exists
+  # This applies to a ContainerRequest in Committed or Final state with container_uuid
+
+  def started_at
+    t = get_combined(:started_at)
+    t = Time.parse(t) if (t.is_a? String)
+    t
+  end
+
+  def modified_at
+    t = get_combined(:modified_at)
+    t = Time.parse(t) if (t.is_a? String)
+    t
+  end
+
+  def finished_at
+    t = get_combined(:finished_at)
+    t = Time.parse(t) if (t.is_a? String)
+    t
+  end
+
+  def state_label
+    get_combined(:state)
+  end
+
   def docker_image
-    get(:container_image)
+    get_combined(:container_image)
   end
 
   def runtime_constraints
-    get(:runtime_constraints)
+    get_combined(:runtime_constraints)
   end
 
   def priority
-    get(:priority)
+    get_combined(:priority)
   end
 
   def log_collection
-    get(:log)
+    get_combined(:log)
   end
 
   def outputs
     items = []
-    items << get(:output) if get(:output)
+    items << get_combined(:output) if get_combined(:output)
     items
   end
 
-  def uri
-    uuid = get(:uuid)
-    "/containers/#{uuid}"
+  def command
+    get_combined(:command)
   end
 
-  def title
-    "container"
+  def cwd
+    get_combined(:cwd)
   end
 
-  def can_cancel?
-    true
+  def environment
+    env = get_combined(:environment)
+    env = nil if env.andand.empty?
+    env
+  end
+
+  def mounts
+    mnt = get_combined(:mounts)
+    mnt = nil if mnt.andand.empty?
+    mnt
+  end
+
+  def output_path
+    get_combined(:output_path)
+  end
+
+  # End combined propeties
+
+  protected
+  def get_combined key
+    get(key, @related) || get(key, @proxied)
   end
 end
diff --git a/apps/workbench/app/models/job_work_unit.rb b/apps/workbench/app/models/job_work_unit.rb
index a3f13f3..42a39fc 100644
--- a/apps/workbench/app/models/job_work_unit.rb
+++ b/apps/workbench/app/models/job_work_unit.rb
@@ -81,11 +81,6 @@ class JobWorkUnit < ProxyWorkUnit
     state_label.in? ["Queued", "Running"]
   end
 
-  def uri
-    uuid = get(:uuid)
-    "/jobs/#{uuid}"
-  end
-
   def title
     "job"
   end
diff --git a/apps/workbench/app/models/pipeline_instance_work_unit.rb b/apps/workbench/app/models/pipeline_instance_work_unit.rb
index 889fa1a..7c62393 100644
--- a/apps/workbench/app/models/pipeline_instance_work_unit.rb
+++ b/apps/workbench/app/models/pipeline_instance_work_unit.rb
@@ -43,11 +43,6 @@ class PipelineInstanceWorkUnit < ProxyWorkUnit
     items
   end
 
-  def uri
-    uuid = get(:uuid)
-    "/pipeline_instances/#{uuid}"
-  end
-
   def title
     "pipeline"
   end
diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb
index b0f754a..9167337 100644
--- a/apps/workbench/app/models/proxy_work_unit.rb
+++ b/apps/workbench/app/models/proxy_work_unit.rb
@@ -57,7 +57,7 @@ class ProxyWorkUnit < WorkUnit
   end
 
   def state_bootstrap_class
-    state = get(:state)
+    state = state_label
     case state
     when 'Complete'
       'success'
@@ -71,7 +71,7 @@ class ProxyWorkUnit < WorkUnit
   end
 
   def success?
-    state = get(:state)
+    state = state_label
     if state == 'Complete'
       true
     elsif state == 'Failed' or state == 'Cancelled'
@@ -129,7 +129,7 @@ class ProxyWorkUnit < WorkUnit
   end
 
   def progress
-    state = get(:state)
+    state = state_label
     if state == 'Complete'
       return 1.0
     elsif state == 'Failed' or state == 'Cancelled'
@@ -322,13 +322,18 @@ class ProxyWorkUnit < WorkUnit
     resp
   end
 
+  def uri
+    uuid = get(:uuid)
+    "/#{@proxied.class.table_name}/#{uuid}"
+  end
+
   protected
 
-  def get key
-    if @proxied.respond_to? key
-      @proxied.send(key)
-    elsif @proxied.is_a?(Hash)
-      @proxied[key]
+  def get key, obj=@proxied
+    if obj.respond_to? key
+      obj.send(key)
+    elsif obj.is_a?(Hash)
+      obj[key]
     end
   end
 end
diff --git a/apps/workbench/app/models/work_unit.rb b/apps/workbench/app/models/work_unit.rb
index 5bac42b..1c2d02f 100644
--- a/apps/workbench/app/models/work_unit.rb
+++ b/apps/workbench/app/models/work_unit.rb
@@ -155,4 +155,28 @@ class WorkUnit
   def is_failed?
     # is this work unit in failed state?
   end
+
+  def command
+    # command to execute
+  end
+
+  def cwd
+    # initial workind directory
+  end
+
+  def environment
+    # environment variables
+  end
+
+  def mounts
+    # mounts
+  end
+
+  def output_path
+    # path to a directory or file to save output
+  end
+
+  def container_uuid
+    # container_uuid of a container_request
+  end
 end
diff --git a/apps/workbench/app/views/container_requests/_show_status.html.erb b/apps/workbench/app/views/container_requests/_show_status.html.erb
new file mode 100644
index 0000000..d6d8c67
--- /dev/null
+++ b/apps/workbench/app/views/container_requests/_show_status.html.erb
@@ -0,0 +1 @@
+<%= render(partial: 'work_unit/show_status', locals: {current_obj: @object, name: @object[:name] || 'this container'}) %>
diff --git a/apps/workbench/app/views/containers/_show_status.html.erb b/apps/workbench/app/views/containers/_show_status.html.erb
new file mode 100644
index 0000000..00a5592
--- /dev/null
+++ b/apps/workbench/app/views/containers/_show_status.html.erb
@@ -0,0 +1,17 @@
+<%= render(partial: 'work_unit/show_status', locals: {current_obj: @object, name: @object[:name] || 'this container'}) %>
+
+<div class="panel panel-default">
+  <div class="panel-heading">
+    <span class="panel-title">Container requests</span>
+  </div>
+  <div class="panel-body">
+    <% crs = ContainerRequest.order("created_at desc").filter([["container_uuid", "=", @object.uuid]]) %>
+    <% crs.each do |cr| %>
+      <div>
+        <%= link_to_if_arvados_object cr, friendly_name: true %>
+        created at
+        <%= render_localized_date(cr.created_at) %>.
+      </div>
+    <% end %>
+  </div>
+</div>
diff --git a/apps/workbench/app/views/jobs/_show_status.html.erb b/apps/workbench/app/views/jobs/_show_status.html.erb
index 8d54b20..6b1ea03 100644
--- a/apps/workbench/app/views/jobs/_show_status.html.erb
+++ b/apps/workbench/app/views/jobs/_show_status.html.erb
@@ -1,15 +1,4 @@
-<div class="arv-log-refresh-control"
-     data-load-throttle="15000"
-     ></div>
-<%=
-   pj = {}
-   pj[:job] = @object
-   pj[:name] = @object[:name] || "this job"
-   pj[:progress_bar] = render(partial: "job_progress",
-                              locals: {:j => @object })
-   tasks = JobTask.filter([['job_uuid', '=', @object.uuid]]).results
-   render(partial: 'work_unit/show_component', locals: {wu: @object.work_unit(@object[:name] || "this job")})
-%>
+<%= render(partial: 'work_unit/show_status', locals: {current_obj: @object, name: @object[:name] || 'this job'}) %>
 
 <div class="panel panel-default">
   <div class="panel-heading">
diff --git a/apps/workbench/app/views/work_unit/_component_detail.html.erb b/apps/workbench/app/views/work_unit/_component_detail.html.erb
index 19c7f22..ba9d3ce 100644
--- a/apps/workbench/app/views/work_unit/_component_detail.html.erb
+++ b/apps/workbench/app/views/work_unit/_component_detail.html.erb
@@ -5,7 +5,7 @@
               No <%= current_obj.title %> has been submitted yet.
             <% else %>
             <table>
-              <% keys = [:uuid, :modified_by_user_uuid, :created_at, :started_at, :finished_at, :priority] %>
+              <% keys = [:uuid, :modified_by_user_uuid, :created_at, :started_at, :finished_at, :container_uuid, :priority] %>
               <% keys << :outputs if @object.uuid == current_obj.uuid %>
               <% keys.each do |k| %>
                 <% val = current_obj.send(k) if current_obj.respond_to?(k) %>
@@ -50,7 +50,8 @@
                  # ...and the api server provides an http:// or https:// url
                  repo = nil unless repo.andand.http_fetch_url
                  %>
-              <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic].each do |k| %>
+              <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic,
+                  :command, :cwd, :environment, :mounts, :output_path].each do |k| %>
                 <% val = current_obj.send(k) if current_obj.respond_to?(k) %>
                 <% if val %>
                 <tr>
@@ -89,6 +90,16 @@
                       current_obj.docker_image, friendly_name: true) %>
                   </td>
                 </tr>
+              <% elsif current_obj.docker_image %>
+                <tr>
+                  <td style="padding-right: 1em">
+                    docker_image_locator:
+                  </td>
+                  <td>
+                    <%= link_to_arvados_object_if_readable(current_obj.docker_image,
+                      current_obj.docker_image, friendly_name: true) %>
+                  </td>
+                </tr>
               <% end %>
             </table>
           </div>
diff --git a/apps/workbench/app/views/work_unit/_show_status.html.erb b/apps/workbench/app/views/work_unit/_show_status.html.erb
new file mode 100644
index 0000000..0c1e80e
--- /dev/null
+++ b/apps/workbench/app/views/work_unit/_show_status.html.erb
@@ -0,0 +1,6 @@
+<div class="arv-log-refresh-control"
+     data-load-throttle="15000"
+     ></div>
+<%=
+   render(partial: 'work_unit/show_component', locals: {wu: current_obj.work_unit(name)})
+%>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index fc72ea2..4161484 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -19,7 +19,9 @@ ArvadosWorkbench::Application.routes.draw do
   resources :api_client_authorizations
   resources :virtual_machines
   resources :containers
-  resources :container_requests
+  resources :container_requests do
+    post 'cancel', :on => :member
+  end
   get '/virtual_machines/:id/webshell/:login' => 'virtual_machines#webshell', :as => :webshell_virtual_machine
   resources :authorized_keys
   resources :job_tasks
diff --git a/apps/workbench/test/unit/work_unit_test.rb b/apps/workbench/test/unit/work_unit_test.rb
index db38b8e..c737982 100644
--- a/apps/workbench/test/unit/work_unit_test.rb
+++ b/apps/workbench/test/unit/work_unit_test.rb
@@ -11,6 +11,7 @@ class WorkUnitTest < ActiveSupport::TestCase
     [PipelineInstance, 'has_component_with_completed_jobs', nil, 3, "Complete", true, 1.0],
     [PipelineInstance, 'pipeline_with_tagged_collection_input', "pwu", 1, "Ready", nil, 0.0],
     [Container, 'requester', 'cwu', 1, "Complete", true, 1.0],
+    [ContainerRequest, 'cr_for_requester', 'cwu', 1, "Complete", true, 1.0],
   ].each do |type, fixture, label, num_children, state, success, progress|
     test "children of #{fixture}" do
       use_token 'active'
diff --git a/services/api/test/fixtures/container_requests.yml b/services/api/test/fixtures/container_requests.yml
index 371db4a..76c2fdc 100644
--- a/services/api/test/fixtures/container_requests.yml
+++ b/services/api/test/fixtures/container_requests.yml
@@ -94,3 +94,19 @@ cr_for_requester:
   command: ["echo", "hello"]
   container_uuid: zzzzz-dz642-requestercntnr1
   requesting_container_uuid: zzzzz-dz642-requestingcntnr
+
+cr_for_requester2:
+  uuid: zzzzz-xvhdp-cr4requestercn2
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  name: requester_cr2
+  state: Final
+  priority: 1
+  created_at: 2016-01-11 11:11:11.111111111 Z
+  updated_at: 2016-01-11 11:11:11.111111111 Z
+  modified_at: 2016-01-11 11:11:11.111111111 Z
+  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  container_image: test
+  cwd: test
+  output_path: test
+  command: ["echo", "hello"]
+  requesting_container_uuid: zzzzz-dz642-requestercntnr1

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list