Merge branch 'master' into 6057-public-projects-page
[arvados.git] / apps / workbench / app / views / pipeline_instances / _running_component.html.erb
1 <% current_job = pj[:job] if pj[:job] != {} and pj[:job][:uuid] %>
2 <div class="panel panel-default">
3   <div class="panel-heading">
4     <div class="container-fluid">
5       <div class="row-fluid">
6         <%# column offset 0 %>
7         <div class="col-md-3" style="word-break:break-all;">
8           <h4 class="panel-title">
9             <a data-toggle="collapse" href="#collapse<%= i %>">
10               <%= pj[:name] %> <span class="caret"></span>
11             </a>
12           </h4>
13         </div>
14
15         <%# column offset 3 %>
16         <div class="col-md-2 pipeline-instance-spacing">
17           <%= pj[:progress_bar] %>
18         </div>
19
20         <% if current_job %>
21           <%# column offset 5 %>
22           <% if current_job[:state] != "Queued" %>
23           <div class="col-md-3">
24             <% if current_job[:started_at] %>
25               <% walltime = ((if current_job[:finished_at] then current_job[:finished_at] else Time.now() end) - current_job[:started_at]) %>
26               <% cputime = tasks.map { |task|
27                    if task.started_at and task.job_uuid == current_job[:uuid]
28                      (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
29                    else
30                      0
31                    end
32                  }.reduce(:+) || 0 %>
33               <%= render_runtime(walltime, false, false) %>
34               <% if cputime > 0 %> / <%= render_runtime(cputime, false, false) %> (<%= (cputime/walltime).round(1) %>&Cross;)<% end %>
35             <% end %>
36           </div>
37           <% end %>
38
39           <% if current_job[:state] == "Queued" %>
40             <%# column offset 5 %>
41             <div class="col-md-6">
42               <% queuetime = Time.now - Time.parse(current_job[:created_at].to_s) %>
43               Queued for <%= render_runtime(queuetime, true) %>.
44               <% begin %>
45                 <% if current_job[:queue_position] == 0 %>
46                   This job is next in the queue to run.
47                 <% elsif current_job[:queue_position] == 1 %>
48                   There is 1 job in the queue ahead of this one.
49                 <% elsif current_job[:queue_position] %>
50                   There are <%= current_job[:queue_position] %> jobs in the queue ahead of this one.
51                 <% end %>
52               <% rescue %>
53               <% end %>
54             </div>
55           <% elsif current_job[:state] == "Running" %>
56             <%# column offset 8 %>
57             <div class="col-md-3">
58               <span class="task-summary-status">
59                 <%= current_job[:tasks_summary][:done] %>&nbsp;<%= "task".pluralize(current_job[:tasks_summary][:done]) %> done,
60                 <%= current_job[:tasks_summary][:failed] %>&nbsp;failed,
61                 <%= current_job[:tasks_summary][:running] %>&nbsp;running,
62                 <%= current_job[:tasks_summary][:todo] %>&nbsp;pending
63               </span>
64             </div>
65           <% elsif current_job[:state].in? ["Complete", "Failed", "Cancelled"] %>
66             <%# column offset 8 %>
67             <div class="col-md-4 text-overflow-ellipsis">
68               <% if pj[:output_uuid] %>
69                 <%= link_to_arvados_object_if_readable(pj[:output_uuid], 'Output data not available', friendly_name: true) %>
70               <% elsif current_job[:output] %>
71                 <%= link_to_arvados_object_if_readable(current_job[:output], 'Output data not available', link_text: "Output of #{pj[:name]}") %>
72               <% else %>
73                 No output.
74               <% end %>
75             </div>
76           <% end %>
77
78           <% if current_job[:state].in? ["Queued", "Running"] and @object.editable? %>
79             <%# column offset 11 %>
80             <div class="col-md-1 pipeline-instance-spacing">
81               <%= form_tag "/jobs/#{current_job[:uuid]}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %>
82                 <%= hidden_field_tag :return_to, url_for(@object) %>
83                 <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
84               <% end %>
85             </div>
86           <% end %>
87         <% end %>
88       </div>
89     </div>
90   </div>
91
92   <div id="collapse<%= i %>" class="panel-collapse collapse <%= if expanded then 'in' end %>">
93     <div class="panel-body">
94       <div class="container">
95         <% current_component = (if current_job then current_job else pj end) %>
96         <div class="row">
97           <div class="col-md-6">
98             <table>
99               <% # link to repo tree/file only if the repo is readable
100                  # and the commit is a sha1...
101                  repo =
102                  (/^[0-9a-f]{40}$/ =~ current_component[:script_version] and
103                  Repository.where(name: current_component[:repository]).first)
104
105                  # ...and the api server provides an http:// or https:// url
106                  repo = nil unless repo.andand.http_fetch_url
107                  %>
108               <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic].each do |k| %>
109                 <tr>
110                   <td style="padding-right: 1em">
111                     <%= k.to_s %>:
112                   </td>
113                   <td>
114                     <% if current_component[k].nil? %>
115                       (none)
116                     <% elsif repo and k == :repository %>
117                       <%= link_to current_component[k], show_repository_tree_path(id: repo.uuid, commit: current_component[:script_version], path: '/') %>
118                     <% elsif repo and k == :script %>
119                       <%= link_to current_component[k], show_repository_blob_path(id: repo.uuid, commit: current_component[:script_version], path: 'crunch_scripts/'+current_component[:script]) %>
120                     <% elsif repo and k == :script_version %>
121                       <%= link_to current_component[k], show_repository_commit_path(id: repo.uuid, commit: current_component[:script_version]) %>
122                     <% else %>
123                       <%= current_component[k] %>
124                     <% end %>
125                   </td>
126                 </tr>
127               <% end %>
128               <% if current_component[:runtime_constraints].andand[:docker_image] and current_component[:docker_image_locator] %>
129                 <tr>
130                   <td style="padding-right: 1em">
131                     docker_image:
132                   </td>
133                   <td>
134                     <%= current_component[:runtime_constraints][:docker_image] %>
135                   </td>
136                 </tr>
137                 <tr>
138                   <td style="padding-right: 1em">
139                     docker_image_locator:
140                   </td>
141                   <td>
142                     <%= link_to_arvados_object_if_readable(current_component[:docker_image_locator],
143                       current_component[:docker_image_locator], friendly_name: true) %>
144                   </td>
145                 </tr>
146               <% else %>
147                 <tr>
148                   <td style="padding-right: 1em">
149                     docker_image:
150                   </td>
151                   <td>
152                     Not run in Docker
153                   </td>
154                 </tr>
155               <% end %>
156             </table>
157           </div>
158           <div class="col-md-5">
159             <table>
160               <% [:uuid, :modified_by_user_uuid, :priority, :created_at, :started_at, :finished_at].each do |k| %>
161                 <tr>
162                   <td style="padding-right: 1em">
163                     <%= k.to_s %>:
164                   </td>
165                   <td>
166                     <% if k == :uuid %>
167                       <%= link_to_arvados_object_if_readable(current_component[k], current_component[k], link_text: current_component[k]) %>
168                     <% elsif k.to_s.end_with? 'uuid' %>
169                       <%= link_to_arvados_object_if_readable(current_component[k], current_component[k], friendly_name: true) %>
170                     <% elsif k.to_s.end_with? '_at' %>
171                       <%= render_localized_date(current_component[k]) %>
172                     <% else %>
173                       <%= current_component[k] %>
174                     <% end %>
175                   </td>
176                 </tr>
177               <% end %>
178             </table>
179           </div>
180         </div>
181         <div class="row">
182           <div class="col-md-6">
183             <p>script_parameters:</p>
184             <pre><%= JSON.pretty_generate(current_component[:script_parameters]) rescue nil %></pre>
185           </div>
186         </div>
187       </div>
188     </div>
189   </div>
190 </div>