source: trunk/www/admin/jobagents/list_agents.jsp @ 3190

Last change on this file since 3190 was 3190, checked in by Johan Enell, 16 years ago

Merged log:branches/2.2.2#3116:3186 to trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.4 KB
Line 
1<%-- $Id: list_agents.jsp 3190 2007-03-13 10:05:42Z enell $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.JobAgent"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.Job"
40  import="net.sf.basedb.core.Type"
41  import="net.sf.basedb.core.query.Expressions"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.util.Enumeration"
48  import="net.sf.basedb.clients.web.Base"
49  import="net.sf.basedb.clients.web.PermissionUtil"
50  import="net.sf.basedb.clients.web.ModeInfo"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
53  import="java.util.List"
54  import="java.util.Map"
55  import="java.util.Set"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
59<%!
60  private static final Item itemType = Item.JOBAGENT;
61  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
62%>
63<%
64final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
65final String ID = sc.getId();
66final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
67final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
68
69final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
70final String callback = request.getParameter("callback");
71final String title = mode.generateTitle("job agent", "job agents");
72final DbControl dc = sc.newDbControl();
73ItemResultIterator<JobAgent> agents = null;
74try
75{
76  final ItemQuery<PluginDefinition> pluginQuery = PluginDefinition.getQuery();
77  pluginQuery.include(cc.getInclude());
78  pluginQuery.join(Hql.innerJoin("jobAgentSettings", Item.JOBAGENTSETTINGS.getAlias()));
79  pluginQuery.restrict(Restrictions.eq(Hql.property(Item.JOBAGENTSETTINGS.getAlias(), "jobAgent"), Expressions.parameter("agent")));
80  pluginQuery.order(Orders.asc(Hql.property("name")));
81 
82  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
83  try
84  {
85    final ItemQuery<JobAgent> query = Base.getConfiguredQuery(cc, true, JobAgent.getQuery(), mode);
86    agents = query.iterate(dc);
87  }
88  catch (Throwable t)
89  {
90    cc.setMessage(t.getMessage());
91  }
92  int numListed = 0;
93  %>
94  <base:page title="<%=title==null ? "Job agents" : title%>" type="<%=mode.getPageType()%>">
95  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
96    <script language="JavaScript">
97    var submitPage = 'index.jsp';
98    var formId = 'agents';
99    function newItem()
100    {
101      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
102    }
103    function editItem(itemId)
104    {
105      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
106    }
107    function viewItem(itemId)
108    {
109      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
110    }
111    function itemOnClick(evt, itemId)
112    {
113      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
114    }
115    function deleteItems()
116    {
117      var frm = document.forms[formId];
118      if (Forms.numChecked(frm) == 0)
119      {
120        alert('Please select at least one item in the list');
121        return;
122      }
123      frm.action = submitPage;
124      frm.cmd.value = 'DeleteItems';
125      frm.submit();
126    }
127    function restoreItems()
128    {
129      var frm = document.forms[formId];
130      if (Forms.numChecked(frm) == 0)
131      {
132        alert('Please select at least one item in the list');
133        return;
134      }
135      frm.action = submitPage;
136      frm.cmd.value = 'RestoreItems';
137      frm.submit();
138    }
139    function takeOwnership()
140    {
141      var frm = document.forms[formId];
142      if (Forms.numChecked(frm) == 0)
143      {
144        alert('Please select at least one item in the list');
145        return;
146      }
147      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
148      {
149        frm.action = submitPage;
150        frm.cmd.value = 'TakeOwnershipOfItems';
151        frm.submit();
152      }
153    }
154    function shareItem(itemId)
155    {
156      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareAgents', 500, 400);
157    }
158    function shareItems()
159    {
160      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
161    }
162    function configureColumns()
163    {
164      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
165    }
166    function runPlugin(cmd)
167    {
168      Table.submitToPopup(formId, cmd, 740, 540);
169    }
170    function returnSelected()
171    {
172      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
173      window.close();
174    }
175    function presetOnChange()
176    {
177      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
178    }
179    function controlJobAgents(cmd)
180    {
181      var frm = document.forms[formId];
182      if (Forms.numChecked(frm) == 0)
183      {
184        alert('Please select at least one item in the list');
185        return;
186      }
187      frm.action = submitPage;
188      frm.cmd.value = cmd;
189      frm.submit();
190    }
191    </script>
192  </base:head>
193 
194  <base:body>
195    <%
196    if (cc.getMessage() != null)
197    {
198      %>
199      <div class="error"><%=cc.getMessage()%></div>
200      <%
201      cc.setMessage(null);
202    }
203    %>
204    <tbl:table 
205      id="agents" 
206      clazz="itemlist" 
207      columns="<%=cc.getSetting("columns")%>"
208      sortby="<%=cc.getSortProperty()%>" 
209      direction="<%=cc.getSortDirection()%>"
210      title="<%=title%>"
211      action="index.jsp"
212      sc="<%=sc%>"
213      item="<%=itemType%>"
214      >
215      <tbl:hidden 
216        name="mode" 
217        value="<%=mode.getName()%>" 
218      />
219      <tbl:hidden 
220        name="callback" 
221        value="<%=callback%>" 
222        skip="<%=callback == null%>" 
223      />
224      <tbl:columndef 
225        id="name"
226        property="name"
227        datatype="string"
228        title="Name"
229        sortable="true" 
230        filterable="true"
231        exportable="true"
232        show="always" 
233      />
234      <tbl:columndef 
235        id="externalId"
236        property="externalId"
237        datatype="string"
238        title="External ID"
239        sortable="true"
240        filterable="true"
241        exportable="true"
242      />
243      <tbl:columndef 
244        id="server"
245        property="server"
246        datatype="string"
247        title="Server"
248        sortable="true"
249        filterable="true"
250        exportable="true"
251      />
252      <tbl:columndef 
253        id="port"
254        property="port"
255        datatype="int"
256        title="Port"
257        sortable="true"
258        filterable="true"
259        exportable="true"
260      />
261      <tbl:columndef
262        id="status"
263        title="Status"
264      />
265      <tbl:columndef
266        id="info"
267        title="CPU/Memory"
268      />
269      <tbl:columndef 
270        id="owner"
271        property="owner.name"
272        datatype="string"
273        title="Owner"
274        sortable="true" 
275        filterable="true"
276        exportable="true"
277      />
278      <tbl:columndef 
279        id="description"
280        property="description"
281        datatype="string"
282        title="Description" 
283        sortable="true" 
284        filterable="true" 
285        exportable="true"
286      />
287      <tbl:columndef
288        id="jobs"
289        title="Jobs"
290      />
291      <tbl:columndef
292        id="plugins"
293        title="Plugins"
294      />
295      <tbl:columndef
296        id="permission"
297        title="Permission"
298      />
299      <tbl:toolbar
300        visible="<%=mode.hasToolbar()%>"
301        >
302        <tbl:button 
303          disabled="<%=createPermission ? false : true%>" 
304          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
305          onclick="newItem()" 
306          title="New&hellip;" 
307          tooltip="<%=createPermission ? "Create new job agent" : "You do not have permission to create job agents"%>" 
308        />
309        <tbl:button 
310          image="delete.gif"
311          onclick="deleteItems()" 
312          title="Delete" 
313          tooltip="Delete the selected items" 
314        />
315        <tbl:button 
316          image="restore.gif"
317          onclick="restoreItems()" 
318          title="Restore" 
319          tooltip="Restore the selected (deleted) items"
320        />
321        <tbl:button 
322          image="share.gif"
323          onclick="shareItems()" 
324          title="Share&hellip;" 
325          tooltip="Share the selected items"
326        />
327        <tbl:button 
328          image="take_ownership.png"
329          onclick="takeOwnership()" 
330          title="Take ownership&hellip;"
331          tooltip="Take ownership of the selected items"
332        />
333        <tbl:button 
334          image="columns.gif" 
335          onclick="configureColumns()" 
336          title="Columns&hellip;" 
337          tooltip="Show, hide and re-order columns" 
338        />
339        <tbl:button 
340          image="import.gif" 
341          onclick="runPlugin('ImportItems')" 
342          title="Import&hellip;" 
343          tooltip="Import data" 
344          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
345        />
346        <tbl:button 
347          image="export.gif" 
348          onclick="runPlugin('ExportItems')" 
349          title="Export&hellip;" 
350          tooltip="Export data" 
351          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
352        />
353        <tbl:button 
354          image="runplugin.gif" 
355          onclick="runPlugin('RunListPlugin')" 
356          title="Run plugin&hellip;" 
357          tooltip="Run a plugin" 
358          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
359        />
360        <tbl:button
361          image="pause.png"
362          onclick="controlJobAgents('PauseSelected')"
363          title="Pause"
364          tooltip="Pause the selected job agents"
365        />
366        <tbl:button
367          image="start.png"
368          onclick="controlJobAgents('StartSelected')"
369          title="Start"
370          tooltip="Start the selected job agents"
371        />
372      </tbl:toolbar>
373      <tbl:navigator
374        page="<%=cc.getPage()%>" 
375        rowsperpage="<%=cc.getRowsPerPage()%>" 
376        totalrows="<%=agents == null ? 0 : agents.getTotalCount()%>" 
377        visible="<%=mode.hasNavigator()%>"
378      />
379      <tbl:data>
380        <tbl:columns>
381        <tbl:presetselector 
382          clazz="columnheader"
383          colspan="3"
384          onchange="presetOnChange()"
385        />
386        </tbl:columns>
387
388        <tr>
389          <tbl:header 
390            clazz="index"
391            >&nbsp;</tbl:header>
392          <tbl:header 
393            clazz="check" 
394            visible="<%=mode.hasCheck()%>"
395            ><base:icon 
396              image="check_uncheck.gif" 
397              tooltip="Check/uncheck all" 
398              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
399            /></tbl:header>
400          <tbl:header 
401            clazz="check" 
402            visible="<%=mode.hasRadio()%>"
403            >&nbsp;</tbl:header>
404          <tbl:header 
405            clazz="icons" 
406            visible="<%=mode.hasIcons()%>"
407            >&nbsp;</tbl:header>
408          <tbl:propertyfilter />
409        </tr>
410         
411          <tbl:rows>
412          <%
413          int index = cc.getPage()*cc.getRowsPerPage();
414          int selectedItemId = cc.getId();
415          if (agents != null)
416          {           
417            while (agents.hasNext())
418            {
419              JobAgent item = agents.next();
420              int itemId = item.getId();
421              String openSharePopup = "shareItem("+itemId+")";
422              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
423              boolean writePermission = item.hasPermission(Permission.WRITE);
424              String name = HTML.encodeTags(item.getName());
425              String tooltip = mode.isSelectionMode() ? 
426                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
427              index++;
428              numListed++;
429              %>
430              <tbl:row>
431                <tbl:header 
432                  clazz="index"
433                  ><%=index%></tbl:header>
434                <tbl:header 
435                  clazz="check" 
436                  visible="<%=mode.hasCheck()%>"
437                  ><input 
438                    type="checkbox" 
439                    name="<%=itemId%>" 
440                    value="<%=itemId%>" 
441                    title="<%=name%>" 
442                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
443                  ></tbl:header>
444                <tbl:header 
445                  clazz="check" 
446                  visible="<%=mode.hasRadio()%>"
447                  ><input 
448                    type="radio" 
449                    name="item_id" 
450                    value="<%=itemId%>" 
451                    title="<%=name%>" 
452                    <%=selectedItemId == itemId ? "checked" : ""%>
453                  ></tbl:header>
454                <tbl:header 
455                  clazz="icons" 
456                  visible="<%=mode.hasIcons()%>"
457                  ><base:icon 
458                    image="deleted.gif" 
459                    tooltip="This item has been scheduled for deletion" 
460                    visible="<%=item.isRemoved()%>"
461                  /><base:icon 
462                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
463                    onclick="<%=sharePermission ? openSharePopup : null%>"
464                    tooltip="This item is shared to other users, groups and/or projects" 
465                    visible="<%=item.isShared()%>"
466                  />&nbsp;</tbl:header>
467                <tbl:cell column="name"><div class="link" 
468                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
469                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
470                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
471                <tbl:cell column="server"><%=HTML.encodeTags(item.getServer())%></tbl:cell>
472                <tbl:cell column="port"><%=item.getPort() == null ? "" : item.getPort().toString()%></tbl:cell>
473                <tbl:cell column="status">
474                  <%
475                  Boolean paused = item.getInfo().isPaused();
476                  %>
477                  <%=paused == null ? "<i>- unknown -</i>" : paused == true ? "Paused" : "Running"%>
478                </tbl:cell>
479                <tbl:cell column="info">
480                  CPU usage: <%=item.getCpuUsage() == null ? "<i>- unknown -</i>" : item.getCpuUsage()+"%" %><br>
481                  Total memory: <%=item.getTotalMemory() == null ? "<i>- unknown -</i>" : Values.formatBytes(item.getTotalMemory()) %><br>
482                  Used memory: <%=item.getUsedMemory() == null ? "<i>- unknown -</i>" : Values.formatBytes(item.getUsedMemory()) %>
483                </tbl:cell>
484                <tbl:cell column="jobs">
485                  <%
486                  Set<Integer> jobs = item.getInfo().getJobs();
487                  if (jobs == null || jobs.size() == 0)
488                  {
489                    %>
490                    <i>- none -</i>
491                    <%
492                  }
493                  else
494                  {
495                    String separator = "";
496                    for (int jobId : jobs)
497                    {
498                      try
499                      {
500                        Job job = Job.getById(dc, jobId);
501                        out.write(separator);
502                        if (mode.hasPropertyLink())
503                        {
504                          out.write(Base.getLinkedName(ID, job, false, mode.hasEditLink()) + 
505                            " (" + job.getPercentComplete() + "%)");
506                        }
507                        else
508                        {
509                          out.write(HTML.encodeTags(job.getName()) + 
510                            " (" + job.getPercentComplete() + "%)");
511                        }
512                        separator = ", ";
513                      }
514                      catch (Throwable t)
515                      {
516                        %>
517                        <div class="error"><%=t.getMessage()%></div>
518                        <%
519                      }
520                    }
521                  }
522                  %>
523                </tbl:cell>
524                <tbl:cell column="plugins">
525                  <%
526                  pluginQuery.setParameter("agent", itemId, Type.INT);
527                  try
528                  {
529                    String separator = "";
530                    for (PluginDefinition p : pluginQuery.list(dc))
531                    {
532                      out.write(separator);
533                      if (mode.hasPropertyLink())
534                      {
535                        out.write(Base.getLink(ID, p.getName(), Item.PLUGINDEFINITION, p.getId(), mode.hasEditLink()));
536                      }
537                      else
538                      {
539                        out.write(HTML.encodeTags(p.getName()));
540                      }
541                      separator = ", ";
542                    }
543                  }
544                  catch (Throwable t)
545                  {
546                    %>
547                    <div class="error"><%=t.getMessage()%></div>
548                    <%
549                  }
550                  %>
551                </tbl:cell>
552                <tbl:cell column="owner"
553                  ><base:propertyvalue 
554                    item="<%=item%>" 
555                    property="owner"
556                    enableEditLink="<%=mode.hasEditLink()%>" 
557                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
558                  /></tbl:cell>
559                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
560                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
561              </tbl:row>
562              <%
563              }
564            }
565          %>
566          </tbl:rows>
567      </tbl:data>
568      <%
569      if (numListed == 0)
570      {
571        %>
572        <tbl:panel><%=agents == null || agents.getTotalCount() == 0 ? "No job agents were found" : "No job agents on this page. Please select another page!" %></tbl:panel>
573        <%
574      }
575      else
576      {
577        %>
578        <tbl:navigator
579          page="<%=cc.getPage()%>" 
580          rowsperpage="<%=cc.getRowsPerPage()%>" 
581          totalrows="<%=agents == null ? 0 : agents.getTotalCount()%>" 
582          visible="<%=mode.hasNavigator()%>"
583          locked="true"
584        />
585        <%
586      }
587      %>
588    </tbl:table>
589    <base:buttongroup align="center" clazz="fixedatbottom">
590      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
591      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
592      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
593    </base:buttongroup>
594    <br><br><br>
595  </base:body>
596  </base:page>
597  <%
598}
599finally
600{
601  if (agents != null) agents.close();
602  if (dc != null) dc.close();
603}
604%>
Note: See TracBrowser for help on using the repository browser.