From c400bf1e7a52d5557c2031bdf2c8de9957425577 Mon Sep 17 00:00:00 2001 From: radhika Date: Mon, 6 Jun 2016 20:28:21 -0400 Subject: [PATCH] 8876: Use JobWorkUnit for pipeline components and cleanup. --- .../app/helpers/application_helper.rb | 4 + apps/workbench/app/models/job_work_unit.rb | 50 +++++- .../app/models/pipeline_instance_work_unit.rb | 10 +- apps/workbench/app/models/proxy_work_unit.rb | 152 +++++++++++------- apps/workbench/app/models/work_unit.rb | 4 - .../app/views/work_unit/_show_child.html.erb | 22 +-- .../views/work_unit/_show_component.html.erb | 59 +------ 7 files changed, 164 insertions(+), 137 deletions(-) diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index 14b1c34d11..a37ecda704 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -498,6 +498,10 @@ module ApplicationHelper raw("#{date}") end + def render_time duration, use_words, round_to_min=true + render_runtime duration, use_words, round_to_min + end + private def is_textile?( object, attr ) is_textile = object.textile_attributes.andand.include?(attr) diff --git a/apps/workbench/app/models/job_work_unit.rb b/apps/workbench/app/models/job_work_unit.rb index 49f490dc3a..a0a7c8796e 100644 --- a/apps/workbench/app/models/job_work_unit.rb +++ b/apps/workbench/app/models/job_work_unit.rb @@ -1,6 +1,6 @@ class JobWorkUnit < ProxyWorkUnit def children - return self.my_children if self.my_children + return @my_children if @my_children # Jobs components items = [] @@ -20,7 +20,7 @@ class JobWorkUnit < ProxyWorkUnit end end - self.my_children = items + @my_children = items end def child_summary @@ -31,8 +31,52 @@ class JobWorkUnit < ProxyWorkUnit end end + def parameters + get(:script_parameters) + end + + def repository + get(:repository) + end + + def script + get(:script) + end + + def script_version + get(:script_version) + end + + def supplied_script_version + get(:supplied_script_version) + end + + def docker_image + get(:docker_image_locator) + end + + def nondeterministic + get(:nondeterministic) + end + + def runtime_constraints + get(:runtime_constraints) + end + + def priority + get(:priority) + end + + def log_collection + get(:log) + end + + def output + get(:output) + end + def can_cancel? - true + state_label.in? ["Queued", "Running"] end def uri diff --git a/apps/workbench/app/models/pipeline_instance_work_unit.rb b/apps/workbench/app/models/pipeline_instance_work_unit.rb index 8285424a29..bc2b3e77a0 100644 --- a/apps/workbench/app/models/pipeline_instance_work_unit.rb +++ b/apps/workbench/app/models/pipeline_instance_work_unit.rb @@ -1,11 +1,11 @@ class PipelineInstanceWorkUnit < ProxyWorkUnit def children - return self.my_children if self.my_children + return @my_children if @my_children items = [] jobs = {} - results = Job.where(uuid: self.proxied.job_ids.values).results + results = Job.where(uuid: @proxied.job_ids.values).results results.each do |j| jobs[j.uuid] = j end @@ -21,15 +21,15 @@ class PipelineInstanceWorkUnit < ProxyWorkUnit items << JobWorkUnit.new(job, name) end else - items << ProxyWorkUnit.new(c, name) + items << JobWorkUnit.new(c, name) end else - self.unreadable_children = true + @unreadable_children = true break end end - self.my_children = items + @my_children = items end def uri diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb index 231145a4b2..0342a403d8 100644 --- a/apps/workbench/app/models/proxy_work_unit.rb +++ b/apps/workbench/app/models/proxy_work_unit.rb @@ -7,12 +7,12 @@ class ProxyWorkUnit < WorkUnit attr_accessor :unreadable_children def initialize proxied, label - self.lbl = label - self.proxied = proxied + @lbl = label + @proxied = proxied end def label - self.lbl + @lbl end def uuid @@ -145,50 +145,6 @@ class ProxyWorkUnit < WorkUnit end end - def parameters - get(:script_parameters) - end - - def repository - get(:repository) - end - - def script - get(:script) - end - - def script_version - get(:script_version) - end - - def supplied_script_version - get(:supplied_script_version) - end - - def docker_image - get(:docker_image_locator) - end - - def nondeterministic - get(:nondeterministic) - end - - def runtime_constraints - get(:runtime_constraints) - end - - def priority - get(:priority) - end - - def log_collection - get(:log) - end - - def output - get(:output) - end - def children [] end @@ -198,7 +154,7 @@ class ProxyWorkUnit < WorkUnit end def has_unreadable_children - self.unreadable_children + @unreadable_children end def readable? @@ -237,8 +193,7 @@ class ProxyWorkUnit < WorkUnit def cputime if state_label != "Queued" if started_at - (runtime_constraints.andand[:min_nodes] || 1) * - ((finished_at || Time.now()) - started_at) + (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at) end end end @@ -273,10 +228,6 @@ class ProxyWorkUnit < WorkUnit state_label == 'Failed' end - def can_be_canceled? - state_label.in? ["Queued", "Running"] and can_cancel? - end - def ran_for_str ran_for = nil if state_label @@ -308,13 +259,98 @@ class ProxyWorkUnit < WorkUnit end end + def show_runtime + runningtime = ApplicationController.helpers.determine_wallclock_runtime(children) + + walltime = 0 + if started_at + walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end + end + + resp = '

' + + if started_at + resp << "This #{title} started at " + resp << ApplicationController.helpers.render_localized_date(started_at) + resp << ". It " + if state_label == 'Complete' + resp << "completed in " + elsif state_label == 'Failed' + resp << "failed after " + else + resp << "has been active for " + end + + if walltime > runningtime + resp << ApplicationController.helpers.render_time(walltime, false) + else + resp << ApplicationController.helpers.render_time(runningtime, false) + end + + if finished_at + resp << " at " + resp << ApplicationController.helpers.render_localized_date(finished_at) + end + resp << "." + else + if state_label + resp << "This #{title} is " + resp << if state_label == 'Running' then 'active' else state_label.downcase end + resp << "." + end + end + + if is_failed? + resp << " Check the Log tab for more detail about why it failed." + end + resp << "

" + + resp << "

" + if state_label + resp << "It " + if state_label == 'Running' + resp << "has run" + else + resp << "ran" + end + resp << " for " + + cpu_time = children.map { |c| + if c.started_at + (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at) + else + 0 + end + }.reduce(:+) || 0 + + resp << ApplicationController.helpers.render_time(runningtime, false) + if (walltime - runningtime) > 0 + resp << "(" + resp << ApplicationController.helpers.render_time(walltime - runningtime, false) + resp << "queued)" + end + if cpu_time == 0 + resp << "." + else + resp << " and used " + resp << ApplicationController.helpers.render_time(cpu_time, false) + resp << " of node allocation time (" + resp << (cpu_time/runningtime).round(1).to_s + resp << "⨯ scaling)." + end + end + resp << "

" + + resp + end + protected def get key - if self.proxied.respond_to? key - self.proxied.send(key) - elsif self.proxied.is_a?(Hash) - self.proxied[key] + if @proxied.respond_to? key + @proxied.send(key) + elsif @proxied.is_a?(Hash) + @proxied[key] end end end diff --git a/apps/workbench/app/models/work_unit.rb b/apps/workbench/app/models/work_unit.rb index 53289530a2..b83847ea92 100644 --- a/apps/workbench/app/models/work_unit.rb +++ b/apps/workbench/app/models/work_unit.rb @@ -156,10 +156,6 @@ class WorkUnit # is this work unit in failed state? end - def can_be_canceled? - # true if work unit is in queued or running states and supports can_cancel? - end - def ran_for_str # display string for how long it has run end diff --git a/apps/workbench/app/views/work_unit/_show_child.html.erb b/apps/workbench/app/views/work_unit/_show_child.html.erb index 70e48cbdcb..b9e758fac6 100644 --- a/apps/workbench/app/views/work_unit/_show_child.html.erb +++ b/apps/workbench/app/views/work_unit/_show_child.html.erb @@ -2,7 +2,6 @@
<% queuetime = current_obj.queuedtime %> <% if queuetime %> - <%# column offset 5 %>
Queued for <%= render_runtime(queuetime, false) %>.
<% elsif current_obj.show_child_summary %> - <%# column offset 8 %>
<%= current_obj.child_summary_str %>
<% elsif current_obj.is_finished? %> - <%# column offset 8 %>
<% if current_obj.output %> <%= link_to_arvados_object_if_readable(current_obj.output, 'Output data not available', link_text: "Output of #{current_obj.label}") %> @@ -58,15 +51,14 @@
<% end %> - <% if current_obj.can_be_canceled? and @object.editable? %> - <%# column offset 11 %> -
+
+ <% if current_obj.can_cancel? and @object.editable? %> <%= form_tag "#{current_obj.uri}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %> <%= hidden_field_tag :return_to, url_for(@object) %> <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-child-button"} %> <% end %> -
<% end %> +
<% end %>
diff --git a/apps/workbench/app/views/work_unit/_show_component.html.erb b/apps/workbench/app/views/work_unit/_show_component.html.erb index 9789934a68..58b8aa861b 100644 --- a/apps/workbench/app/views/work_unit/_show_component.html.erb +++ b/apps/workbench/app/views/work_unit/_show_component.html.erb @@ -8,22 +8,22 @@
+
<% if wu.is_running? and wu.child_summary_str %> -
<%= wu.child_summary_str %> -
<% end %> +
<%= render partial: 'work_unit/progress', locals: {wu: wu} %>
- <% if wu.can_be_canceled? and @object.editable? %> -
+
+ <% if wu.can_cancel? and @object.editable? %> <%= form_tag "#{wu.uri}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %> <%= hidden_field_tag :return_to, url_for(@object) %> <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-obj-button"} %> <% end %> -
- <% end %> + <% end %> +
@@ -38,52 +38,7 @@

<% end %> - <% runningtime = determine_wallclock_runtime(wu.children) %> - <% walltime = 0 %> - <% if wu.started_at %> - <% walltime = if wu.finished_at then (wu.finished_at - wu.started_at) else (Time.now - wu.started_at) end %> - <% end %> - -

- <% active_for_str = wu.started_and_active_for_str %> - <% if active_for_str %> - <%= active_for_str[0] %> - <%= render_localized_date(wu.started_at) %>. - <%= active_for_str[1] %> - <%= if walltime > runningtime - render_runtime(walltime, false) - else - render_runtime(runningtime, false) - end %><% if wu.finished_at %> at <%= render_localized_date(wu.finished_at) %><% end %>. - <% else %> - <% if wu.state_label %> This <%= wu.title %> is <%= if wu.state_label == 'Running' then 'active' else wu.state_label.downcase end %>. <% end %> - <% end %> - - <% if wu.is_failed? %> - Check the Log tab for more detail about why it failed. - <% end %> -

- - <% ran_for_str = wu.ran_for_str %> - <% if ran_for_str %> -

- <%= ran_for_str %> - <% - cputime = wu.children.map { |c| - if c.started_at - (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at) - else - 0 - end - }.reduce(:+) || 0 %> - <%= render_runtime(runningtime, false) %><% if (walltime - runningtime) > 0 %> - (<%= render_runtime(walltime - runningtime, false) %> queued)<% end %><% if cputime == 0 %>.<% else %> - and used - <%= render_runtime(cputime, false) %> - of node allocation time (<%= (cputime/runningtime).round(1) %>⨯ scaling). - <% end %> -

- <% end %> + <%= raw(wu.show_runtime) %> -- 2.30.2