source: trunk/www/admin/jobagents/view_agent.jsp @ 5941

Last change on this file since 5941 was 5941, checked in by Nicklas Nordborg, 11 years ago

References #1655: GUI improvements

View pages for all items in the Adminstrate menu.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.3 KB
Line 
1<%-- $Id: view_agent.jsp 5941 2012-02-01 13:26:23Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
4  Copyright (C) 2007 Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Job"
35  import="net.sf.basedb.core.JobAgent"
36  import="net.sf.basedb.core.JobAgentSettings"
37  import="net.sf.basedb.util.jobagent.JobAgentInfo"
38  import="net.sf.basedb.util.jobagent.JobInfo"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.ItemQuery"
43  import="net.sf.basedb.core.ItemResultList"
44  import="net.sf.basedb.core.ItemResultIterator"
45  import="net.sf.basedb.core.MultiPermissions"
46  import="net.sf.basedb.core.Group"
47  import="net.sf.basedb.core.Project"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.core.plugin.Plugin"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.PermissionUtil"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.Values"
56  import="net.sf.basedb.util.formatter.Formatter"
57  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
58  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
59  import="net.sf.basedb.clients.web.extensions.JspContext"
60  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
61  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
62  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
63  import="java.util.Map"
64  import="java.util.Set"
65  import="java.util.Date"
66  import="java.util.Collections"
67  import="java.util.List"
68   
69%>
70<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
71<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
72<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
73<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
74<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
75<%!
76  private static final Item itemType = Item.JOBAGENT;
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
78%>
79<%
80final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
81final String ID = sc.getId();
82final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
83final int itemId = cc.getId();
84final float scale = Base.getScale(sc);
85final DbControl dc = sc.newDbControl();
86try
87{
88  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
89  Formatter<Date> dateFormatter = FormatterFactory.getDateTimeFormatter(sc);
90
91  String title = null;
92  JobAgent agent = JobAgent.getById(dc, itemId);
93 
94  JobAgentInfo info = agent.getInfo();
95  Boolean paused = info.isPaused();
96 
97  final boolean writePermission = agent.hasPermission(Permission.WRITE);
98  final boolean deletePermission = agent.hasPermission(Permission.DELETE);
99  final boolean sharePermission = agent.hasPermission(Permission.SET_PERMISSION);
100  final boolean setOwnerPermission = agent.hasPermission(Permission.SET_OWNER);
101  final boolean isOwner = agent.isOwner();
102  final boolean isRemoved = agent.isRemoved();
103  final boolean isUsed = isRemoved && agent.isUsed();
104  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
105  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, agent);
106  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
107  %>
108  <base:page title="<%=title%>">
109  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css,progressbar.css">
110    <ext:scripts context="<%=jspContext%>" />
111    <ext:stylesheets context="<%=jspContext%>" />
112    <script language="JavaScript">
113    function editItem()
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
116    }
117    function shareItem()
118    {
119      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareJobAgent', 600, 400);
120    }
121    function deleteItem()
122    {
123      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
124    }
125    function restoreItem()
126    {
127      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
128    }
129    function deleteItemPermanently()
130    {
131      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
132    }
133    function itemDeleted()
134    {
135      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
136    }
137    function showUsingItems()
138    {
139      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
140    }
141    function setOwner()
142    {
143      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 300);
144    }
145    function configurePlugin(pluginId)
146    {
147      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true, '&plugin_id='+pluginId);
148    }
149    function controlJobAgent(cmd)
150    {
151      location.href = 'index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>';
152    }
153    </script>
154  </base:head>
155  <base:body>
156    <p:path><p:pathelement 
157      title="Job agents" href="<%="index.jsp?ID="+ID%>" 
158      /><p:pathelement title="<%=HTML.encodeTags(agent.getName())%>"
159      /></p:path>
160   
161    <t:tabcontrol 
162      id="main" 
163      subclass="content mastertabcontrol" 
164      active="properties">
165    <t:tab id="properties" title="Properties">
166      <div>
167      <table class="fullform bottomborder">
168      <tr>
169        <th class="itemstatus">
170          <base:icon 
171            image="shared.gif" 
172            visible="<%=agent.isShared()%>"
173            tooltip="This item is shared to other users, groups and/or projects"
174          />
175          <base:icon image="warning.gif"
176            visible="<%=!agent.isShared()%>"
177            tooltip="This item is NOT shared to other users, groups or projects. Only the owner will be able to run jobs on this agent" 
178          />
179          <base:icon 
180            image="deleted.gif"
181            onclick="deleteItemPermanently()"
182            tooltip="This item has been flagged for deletion. Click to delete it now."
183            enabled="<%=deletePermanentlyPermission %>"
184            visible="<%=isRemoved%>" 
185          />
186          <base:icon image="used.gif" 
187            onclick="showUsingItems()"
188            tooltip="This item is used by other items and can't be permanently deleted. Show the items that are using this one"
189            visible="<%=isRemoved && isUsed%>" />
190        </th>
191        <td style="padding: 0px;">
192          <tbl:toolbar subclass="bottomborder">
193            <tbl:button 
194              disabled="<%=writePermission ? false : true%>" 
195              image="edit.gif" 
196              onclick="editItem()" 
197              title="Edit&hellip;" 
198              tooltip="<%=writePermission ? "Edit this job agent" : "You do not have permission to edit this job agent"%>" 
199            />
200            <tbl:button 
201              disabled="<%=deletePermission ? false : true%>" 
202              image="delete.gif" 
203              onclick="deleteItem()" 
204              title="Delete"
205              visible="<%=!agent.isRemoved()%>"
206              tooltip="<%=deletePermission ? "Delete this job agent" : "You do not have permission to delete this job agent"%>" 
207            />
208            <tbl:button 
209              disabled="<%=writePermission ? false : true%>" 
210              image="restore.gif" 
211              onclick="restoreItem()" 
212              title="Restore"
213              visible="<%=agent.isRemoved()%>"
214              tooltip="<%=writePermission ? "Restore this job agent" : "You do not have permission to restore this job agent"%>" 
215            />
216            <tbl:button 
217              disabled="<%=sharePermission ? false : true%>"
218              image="share.gif"
219              onclick="shareItem()" 
220              title="Share&hellip;" 
221              tooltip="<%=sharePermission ? "Share this job agent to other user, groups and projects" : "You do not have permission to share this job agent"%>"
222            />
223            <tbl:button 
224              disabled="<%=setOwnerPermission ? false : true%>"
225              image="take_ownership.png"
226              onclick="setOwner()" 
227              title="Set owner&hellip;"
228              tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
229            />
230            <tbl:button 
231              image="import.gif" 
232              onclick="runPlugin('ImportItem')" 
233              title="Import&hellip;" 
234              tooltip="Import data" 
235              visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
236            />
237            <tbl:button 
238              image="export.gif" 
239              onclick="runPlugin('ExportItem')" 
240              title="Export&hellip;" 
241              tooltip="Export data" 
242              visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
243            />
244            <tbl:button 
245              image="runplugin.gif" 
246              onclick="runPlugin('RunPlugin')" 
247              title="Run plugin&hellip;" 
248              tooltip="Run a plugin" 
249              visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
250            />
251            <tbl:button
252              image="start.png"
253              onclick="controlJobAgent('Start')"
254              title="Start"
255              tooltip="Start the job agent"
256              visible="<%=writePermission && paused != null && paused == true%>"
257            />
258            <tbl:button
259              image="pause.png"
260              onclick="controlJobAgent('Pause')"
261              title="Pause"
262              tooltip="Pause the job agent"
263              visible="<%=writePermission && paused != null && paused == false%>"
264            />
265            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
266              wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
267            <tbl:button
268              image="help.png"
269              onclick="<%="Main.openHelp('" + ID +"', 'jobagent.view.properties')"%>"
270              title="Help&hellip;"
271              tooltip="Get help about this page"
272            />
273          </tbl:toolbar>
274        </td>
275      </tr>
276      <tr>
277        <th>Name</th>
278        <td><%=HTML.encodeTags(agent.getName())%></td>
279      </tr>
280      <tr>
281        <th>External ID</th>
282        <td><%=HTML.encodeTags(agent.getExternalId())%></td>
283      </tr>
284      <tr>
285        <th>Server</th>
286        <td><%=HTML.encodeTags(agent.getServer())%></td>
287      </tr>
288      <tr>
289        <th class="subprompt">- port</th>
290        <td><%=agent.getPort() == null ? "" : agent.getPort().toString()%></td>
291      </tr>
292      <tr>
293        <th>Status</th>
294        <td>
295        <%=paused == null ? "<i>- unknown -</i>" : paused == true ? "Paused" : "Running"%>
296        </td>
297      </tr>
298      <tr>
299        <th class="subprompt">- CPU usage</th>
300        <td><%=info.getCpuUsage() == null ? "" : info.getCpuUsage() + "%"%></td>
301      </tr>
302      <tr>
303        <th class="subprompt">- total memory</th>
304        <td>
305          <%=info.getTotalMemory() == null ? "" : Values.formatBytes(info.getTotalMemory())%>
306        </td>
307      </tr>
308      <tr>
309        <th class="subprompt">- used memory</th>
310        <td>
311          <%=info.getUsedMemory() == null ? "" : Values.formatBytes(info.getUsedMemory())%>
312        </td>
313      </tr>
314      <tr>
315        <th>Owner</th>
316        <td><base:propertyvalue item="<%=agent%>" property="owner" /></td>
317      </tr>
318      <tr>
319        <th>Permissions</th>
320        <td><%=PermissionUtil.getFullPermissionNames(agent)%></td>
321      </tr>
322      <tr>
323        <th>Description</th>
324        <td><%=HTML.niceFormat(agent.getDescription())%></td>
325      </tr>
326      </table>
327      </div>
328      <%
329      if (cc.getMessage() != null)
330      {
331        %>
332        <div class="messagecontainer error"><%=cc.getMessage()%></div>
333        <%
334        cc.setMessage(null);
335      }
336      %>
337      <%
338      ItemQuery<JobAgentSettings> query = agent.getSettings();
339      query.include(Include.ALL);
340      query.order(Orders.asc(Hql.property("pluginDefinition.name")));
341      ItemResultList<JobAgentSettings> plugins = query.list(dc);
342      %>
343      <base:section
344        id="plugins"
345        title="<%="Plugins (" + plugins.size() + ")"%>"
346        context="<%=cc%>"
347        >
348        <%
349        if (plugins.size() == 0)
350        {
351          %>
352          <div class="messagecontainer note">
353          This job agent has no installed plugins (or, you don't have permission to view them).
354          </div>
355          <%
356        }
357        else
358        {
359          %>
360          <tbl:table
361            id="plugins"
362            columns="all"
363            >
364          <tbl:columndef 
365            id="plugin"
366            title="Plugin"
367          />
368          <tbl:columndef 
369            id="trusted"
370            title="Trusted"
371          />
372          <tbl:columndef 
373            id="maxMemory"
374            title="Max memory"
375          />
376          <tbl:columndef 
377            id="priorityBoost"
378            title="Priority boost"
379          />
380          <tbl:columndef
381            id="configure"
382            title=""
383          />
384          <tbl:data>
385            <tbl:headers>
386              <tbl:headerrow>
387                <tbl:columnheaders />
388              </tbl:headerrow>
389            </tbl:headers>
390            <tbl:rows>
391            <%
392            for (JobAgentSettings settings : plugins)
393            {
394              PluginDefinition plugin = null;
395              boolean readPlugin = true;
396              try
397              {
398                plugin = settings.getPluginDefinition();
399              }
400              catch (PermissionDeniedException ex)
401              {
402                readPlugin = false;
403              }
404              Long maxMemory = settings.getEffectiveMaxMemory();
405              %>
406              <tbl:row>
407                <tbl:cell column="plugin"><base:icon 
408                    image="deleted.gif" 
409                    tooltip="This item has been scheduled for deletion" 
410                    visible="<%=plugin != null && plugin.isRemoved()%>"
411                  /><%=Base.getLinkedName(ID, plugin, !readPlugin, true)%></tbl:cell>
412                <tbl:cell column="trusted"><%=settings.isEffectivelyTrusted()%></tbl:cell>
413                <tbl:cell column="maxMemory"><%=maxMemory == null ? "<i>- not specified -</i>" : Values.formatBytes(maxMemory)%></tbl:cell>
414                <tbl:cell column="priorityBoost"><%=settings.getPriorityBoost()%></tbl:cell>
415                <tbl:cell column="configure">
416                <%
417                if (writePermission && plugin != null)
418                {
419                  %>
420                  <base:icon image="runplugin.gif" 
421                    onclick="<%="configurePlugin(" + plugin.getId() + ")"%>"
422                    tooltip="Configure the settings for this plugin on the job agent "/>
423                  <%
424                }
425                %>
426                </tbl:cell>
427              </tbl:row>
428              <%
429            }
430            %>
431            </tbl:rows>
432          </tbl:data>
433          </tbl:table>
434          <%
435        }
436        %>
437      </base:section>
438      <%
439      Set<JobInfo> jobs = agent.getInfo().getJobInfo();
440      %>
441      <base:section
442        id="executingJobs"
443        title="<%="Executing jobs (" + (jobs == null ? "unknown" : jobs.size()) + ")"%>"
444        context="<%=cc%>"
445        >
446        <%
447        if (jobs == null)
448        {
449          %>
450          <div class="messagecontainer note">
451          Could not find information about running jobs from the agent.
452          </div>
453          <%
454        }
455        else if (jobs.size() == 0)
456        {
457          %>
458          <div class="messagecontainer note">
459          No jobs are currently executing on this job agent.
460          </div>
461          <%
462        }
463        else
464        {
465          %>
466          <tbl:table
467            id="jobs"
468            columns="all"
469            >
470            <tbl:columndef 
471              id="job"
472              title="Job"
473            />
474            <tbl:columndef 
475              id="plugin"
476              title="Plugin"
477            />
478            <tbl:columndef 
479              id="slot"
480              title="Used slot"
481            />
482            <tbl:columndef 
483              id="started"
484              title="Started"
485            />
486            <tbl:columndef 
487              id="percentComplete"
488              title="Percent complete"
489            />
490            <tbl:columndef 
491              id="owner"
492              title="Owner"
493            />
494            <tbl:data>
495              <tbl:headers>
496                <tbl:headerrow>
497                  <tbl:columnheaders />
498                </tbl:headerrow>
499              </tbl:headers>
500              <tbl:rows>
501              <%
502              for (JobInfo jobInfo : jobs)
503              {
504                Job job = null;
505                boolean readJob = true;
506                try
507                {
508                  job = Job.getById(dc, jobInfo.getJobId());
509                }
510                catch (Throwable t)
511                {
512                  readJob = false;
513                }
514                %>
515                <tbl:row>
516                  <tbl:cell column="job"><%=Base.getLinkedName(ID, job, !readJob, true) %></tbl:cell>
517                  <tbl:cell column="plugin"><base:propertyvalue item="<%=job%>" property="pluginDefinition"/></tbl:cell>
518                  <tbl:cell column="started"><%=job == null ? "" : dateFormatter.format(job.getStarted())%></tbl:cell>
519                  <tbl:cell column="slot"><%=jobInfo.getSlot() == null ? "" : jobInfo.getSlot().toString()%></tbl:cell>
520                  <tbl:cell column="percentComplete">
521                    <%
522                    if (job != null)
523                    {
524                      %>
525                      <table border=0 cellspacing=0 cellpadding=0>
526                      <tr>
527                      <td width="100">
528                        <table width="100" class="progressbar" border=0 cellspacing=0 cellpadding=0>
529                        <tr>
530                          <%
531                          int percent = job.getPercentComplete();
532                          if (percent > 0) 
533                          {
534                            %>
535                            <td width="<%=percent%>%" class="done">&nbsp;</td>
536                            <% 
537                          }
538                          if (percent == -1)
539                          {
540                            %>
541                            <td width="100%" class="unknown">unknown</td>
542                            <%
543                          }
544                          else if (percent < 100) 
545                          {
546                            %>
547                            <td width="<%=100-percent%>%" class="remain">&nbsp;</td>
548                            <%
549                          }
550                          %>
551                        </tr>
552                        </table>               
553                      </td>
554                      <%if (percent != -1) { %>
555                      <td>&nbsp;<%=percent%>%</td>
556                      <%} %>
557                      </tr>
558                      </table>
559                      <%
560                    }
561                    %>
562                  </tbl:cell>
563                  <tbl:cell column="owner"><base:propertyvalue item="<%=job%>" property="owner" /></tbl:cell>
564                </tbl:row>
565                <%
566              }
567              %>
568              </tbl:rows>
569            </tbl:data>
570          </tbl:table>
571          <%
572        }
573        %>
574      </base:section>
575      <jsp:include page="../../common/anytoany/list_anytoany.jsp">
576        <jsp:param name="ID" value="<%=ID%>" />
577        <jsp:param name="item_type" value="<%=itemType.name()%>" />
578        <jsp:param name="item_id" value="<%=itemId%>" />
579        <jsp:param name="title" value="Other items related to this job agent" />
580      </jsp:include>
581      <jsp:include page="../../common/share/list_share.jsp">
582        <jsp:param name="ID" value="<%=ID%>" />
583        <jsp:param name="item_type" value="<%=itemType.name()%>" />
584        <jsp:param name="item_id" value="<%=itemId%>" />
585        <jsp:param name="title" value="Shared to" />
586      </jsp:include>
587    </t:tab>
588    </t:tabcontrol>
589  </base:body>
590  </base:page>
591  <%
592}
593finally
594{
595  if (dc != null) dc.close();
596}
597
598%>
Note: See TracBrowser for help on using the repository browser.