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

Last change on this file since 7943 was 7943, checked in by Nicklas Nordborg, 2 years ago

Merged BASE 3.18.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.9 KB
Line 
1<%-- $Id: list_agents.jsp 7943 2021-05-04 12:23:19Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
4  Copyright (C) 2007 Johan Enell, 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.Item"
30  import="net.sf.basedb.core.JobAgent"
31  import="net.sf.basedb.core.ItemQuery"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.ItemResultList"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.Nameable"
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.util.ShareableUtil"
49  import="net.sf.basedb.util.jobagent.JobInfo"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.PermissionUtil"
52  import="net.sf.basedb.clients.web.ModeInfo"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction" 
59  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
60  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
61  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
62  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
63  import="java.util.Iterator"
64  import="java.util.List"
65  import="java.util.Map"
66  import="java.util.Set"
67%>
68<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
69<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
70<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
71<%!
72  private static final Item itemType = Item.JOBAGENT;
73  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
74%>
75<%
76final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
77final String ID = sc.getId();
78final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80
81final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
82final String callback = request.getParameter("callback");
83final String title = mode.generateTitle("job agent", "job agents");
84final DbControl dc = sc.newDbControl();
85ItemResultIterator<JobAgent> agents = null;
86try
87{
88  final ItemQuery<PluginDefinition> pluginQuery = PluginDefinition.getQuery();
89  pluginQuery.include(cc.getInclude());
90  pluginQuery.join(Hql.innerJoin("jobAgentSettings", Item.JOBAGENTSETTINGS.getAlias()));
91  pluginQuery.restrict(Restrictions.eq(Hql.property(Item.JOBAGENTSETTINGS.getAlias(), "jobAgent"), Expressions.parameter("agent")));
92  pluginQuery.order(Orders.asc(Hql.property("name")));
93 
94  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
95  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
96  try
97  {
98    final ItemQuery<JobAgent> query = Base.getConfiguredQuery(dc, cc, jspContext, true, JobAgent.getQuery(), mode);
99    agents = query.iterate(dc);
100  }
101  catch (Throwable t)
102  {
103    cc.setMessage(t.getMessage());
104  }
105  int numListed = 0;
106  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
107  ExtensionsInvoker<ListColumnAction<JobAgent,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
108  %>
109  <base:page title="<%=title==null ? "Job agents" : title%>" type="<%=mode.getPageType()%>" id="list-page">
110  <base:head scripts="table.js,~agents.js" styles="table.css,toolbar.css">
111    <ext:scripts context="<%=jspContext%>" />
112    <ext:stylesheets context="<%=jspContext%>" />
113  </base:head>
114 
115  <base:body>
116    <h1><%=title==null ? "Job agents" : title%></h1>
117    <div class="content">
118    <tbl:table 
119      id="agents" 
120      columns="<%=cc.getSetting("columns")%>"
121      sortby="<%=cc.getSortProperty()%>" 
122      direction="<%=cc.getSortDirection()%>"
123      action="index.jsp"
124      sc="<%=sc%>"
125      item="<%=itemType%>"
126      filterrows="<%=cc.getFilterRows()%>"
127      subclass="fulltable"
128      stickyheaders="name"
129      >
130      <tbl:hidden 
131        name="mode" 
132        value="<%=mode.getName()%>" 
133      />
134      <tbl:hidden 
135        name="callback" 
136        value="<%=callback%>" 
137        skip="<%=callback == null%>" 
138      />
139      <tbl:columndef 
140        id="name"
141        property="name"
142        datatype="string"
143        title="Name"
144        sortable="true" 
145        filterable="true"
146        exportable="true"
147        show="always" 
148      />
149      <tbl:columndef 
150        id="id"
151        clazz="uniquecol"
152        property="id"
153        datatype="int"
154        title="ID"
155        sortable="true"
156        filterable="true"
157        exportable="true"
158      />
159      <tbl:columndef 
160        id="externalId"
161        clazz="uniquecol"
162        property="externalId"
163        datatype="string"
164        title="External ID"
165        sortable="true"
166        filterable="true"
167        exportable="true"
168      />
169      <tbl:columndef 
170        id="server"
171        property="server"
172        datatype="string"
173        title="Server"
174        sortable="true"
175        filterable="true"
176        exportable="true"
177      />
178      <tbl:columndef 
179        id="port"
180        property="port"
181        datatype="int"
182        title="Port"
183        sortable="true"
184        filterable="true"
185        exportable="true"
186      />
187      <tbl:columndef
188        id="status"
189        title="Status"
190      />
191      <tbl:columndef
192        id="info"
193        title="CPU/Memory"
194      />
195      <tbl:columndef 
196        id="owner"
197        property="owner.name"
198        datatype="string"
199        title="Owner"
200        sortable="true" 
201        filterable="true"
202        exportable="true"
203      />
204      <tbl:columndef 
205        id="description"
206        property="description"
207        datatype="string"
208        title="Description" 
209        sortable="true" 
210        filterable="true" 
211        exportable="true"
212      />
213      <tbl:columndef
214        id="jobs"
215        title="Jobs"
216      />
217      <tbl:columndef
218        id="plugins"
219        title="Plugins"
220        property="&plugins(pluginDefinition.name)"
221        datatype="string"
222        filterable="true"
223      />
224      <tbl:columndef
225        id="permission"
226        title="Permission"
227      />
228      <tbl:columndef
229        id="sharedTo"
230        title="Shared to"
231        filterable="true"
232        filterproperty="!sharedTo.name"
233        datatype="string"
234      />
235      <tbl:columndef 
236        id="xt-columns" 
237        extensions="<%=columnsInvoker%>" 
238        jspcontext="<%=jspContext%>" 
239      />
240      <div class="panelgroup bg-filled-50 bottomborder">
241        <tbl:toolbar
242          subclass="bottomborder"
243          visible="<%=mode.hasToolbar()%>"
244          >
245          <tbl:button 
246            id="btnNewItem"
247            disabled="<%=!createPermission%>" 
248            image="new.png" 
249            title="New&hellip;" 
250            tooltip="<%=createPermission ? "Create new job agent" : "You do not have permission to create job agents"%>" 
251          />
252          <tbl:button 
253            id="btnDeleteItems"
254            image="delete.png"
255            title="Delete" 
256            tooltip="Delete the selected items" 
257          />
258          <tbl:button 
259            id="btnRestoreItems"
260            image="restore.png"
261            title="Restore" 
262            tooltip="Restore the selected (deleted) items"
263          />
264          <tbl:button 
265            id="btnShareItems"
266            image="share.png"
267            title="Share&hellip;" 
268            tooltip="Share the selected items"
269          />
270          <tbl:button 
271            id="btnSetOwner"
272            image="take_ownership.png"
273            title="Set owner&hellip;"
274            tooltip="Change owner of the selected items"
275          />
276          <tbl:button 
277            id="btnColumns"
278            image="columns.png" 
279            title="Columns&hellip;" 
280            tooltip="Show, hide and re-order columns" 
281          />
282          <tbl:button 
283            id="btnImport"
284            data-plugin-type="IMPORT"
285            image="import.png" 
286            title="Import&hellip;" 
287            tooltip="Import data" 
288            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
289          />
290          <tbl:button 
291            id="btnExport"
292            data-plugin-type="EXPORT"
293            image="export.png" 
294            title="Export&hellip;" 
295            tooltip="Export data" 
296            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
297          />
298          <tbl:button 
299            id="btnRunPlugin"
300            data-plugin-type="OTHER"
301            image="runplugin.png" 
302            title="Run plugin&hellip;" 
303            tooltip="Run a plugin" 
304            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
305          />
306          <tbl:button
307            id="btnPause"
308            image="pause.png"
309            data-action="PauseSelected"
310            title="Pause"
311            tooltip="Pause the selected job agents"
312          />
313          <tbl:button
314            id="btnStart"
315            image="start.png"
316            data-action="StartSelected"
317            title="Start"
318            tooltip="Start the selected job agents"
319          />
320          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
321            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
322        </tbl:toolbar>
323        <tbl:panel>
324          <tbl:presetselector />
325          <tbl:navigator
326            page="<%=cc.getPage()%>" 
327            rowsperpage="<%=cc.getRowsPerPage()%>" 
328            totalrows="<%=agents == null ? 0 : agents.getTotalCount()%>" 
329            visible="<%=mode.hasNavigator()%>"
330          />
331        </tbl:panel>
332      </div>
333      <tbl:data>
334        <tbl:headers>
335          <tbl:headerrow>
336            <tbl:header clazz="row-index bg-filled-100" />
337            <tbl:columnheaders />
338          </tbl:headerrow>
339          <%
340          int numFilters = cc.getNumPropertyFilters();
341          int numRows = cc.getFilterRows();
342          for (int filterNo = 0; filterNo < numRows; filterNo++)
343          {
344            boolean lastRow = filterNo == numRows-1;
345            %>
346            <tbl:headerrow>
347              <tbl:header subclass="row-index bg-filled-100">
348                <div class="index-<%=mode.getName()%>">
349                  <div class="index"></div>
350                  <div class="check">
351                    <base:icon 
352                      subclass="link table-check"
353                      image="check_uncheck.png" 
354                      tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
355                      visible="<%=lastRow && mode.hasCheck()%>"
356                    />
357                  </div>
358                  <div class="icons">
359                    <base:icon
360                      subclass="link table-filter-row-action"
361                      image="add.png"
362                      tooltip="Add extra filter row"
363                      visible="<%=lastRow%>"
364                    /><base:icon
365                      subclass="link table-filter-row-action"
366                      image="remove.png"
367                      tooltip="Remove this filter row"
368                      visible="<%=numRows > 1 || numFilters > 0 %>"
369                      data-remove-row="<%=filterNo%>"
370                    />
371                  </div>
372                </div>
373              </tbl:header>
374              <tbl:propertyfilter row="<%=filterNo%>" />
375            </tbl:headerrow>
376            <%
377          }
378          %>
379          <tbl:columnsubtitles />
380        </tbl:headers>
381        <tbl:rows>
382          <%
383          if (cc.getMessage() != null)
384          {
385            %>
386            <tbl:panel subclass="bg-filled-50">
387              <div class="messagecontainer error"><%=cc.getMessage()%></div>
388            </tbl:panel>
389            <%
390            cc.setMessage(null);
391          }
392          int index = cc.getPage()*cc.getRowsPerPage();
393          int selectedItemId = cc.getId();
394          if (agents != null)
395          {           
396            while (agents.hasNext())
397            {
398              JobAgent item = agents.next();
399              int itemId = item.getId();
400             
401             
402              boolean deletePermission = item.hasPermission(Permission.DELETE);
403              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
404              boolean writePermission = item.hasPermission(Permission.WRITE);
405              String name = HTML.encodeTags(item.getName());
406              String tooltip = mode.isSelectionMode() ? 
407                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
408              index++;
409              numListed++;
410              %>
411              <tbl:row>
412                <tbl:header clazz="row-index bg-filled-100">
413                  <div class="index-<%=mode.getName()%>">
414                    <div class="index <%=index>999?"index-smaller":""%>"><%=index%></div>
415                    <div class="check">
416                      <base:input
417                        type="checkbox" 
418                        name="<%=itemId%>" 
419                        value="<%=itemId%>" 
420                        title="<%=name%>" 
421                        checked="<%=cc.getSelected().contains(itemId)%>"
422                        visible="<%=mode.hasCheck()%>"
423                      />
424                      <base:input 
425                        type="radio" 
426                        name="item_id" 
427                        value="<%=itemId%>" 
428                        title="<%=name%>" 
429                        checked="<%=selectedItemId == itemId%>"
430                        visible="<%=mode.hasRadio()%>"
431                      />
432                    </div>
433                    <div class="icons">
434                      <base:icon 
435                        image="deleted.png"
436                        id="<%="delete."+itemId %>"
437                        subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
438                        data-item-id="<%=itemId%>"
439                        tooltip="This item has been scheduled for deletion" 
440                        visible="<%=item.isRemoved()%>"
441                      /><base:icon 
442                        image="shared.png" 
443                        id="<%="share."+itemId %>"
444                        subclass="<%=sharePermission ? "table-share-item" : "disabled" %>"
445                        data-item-id="<%=itemId%>"
446                        tooltip="This item is shared to other users, groups and/or projects" 
447                        visible="<%=item.isShared()%>"
448                      />
449                    </div>
450                  </div>
451                </tbl:header>
452                <tbl:cell column="name"><div 
453                  class="link table-item"
454                  data-item-id="<%=itemId%>"
455                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
456                  tabindex="0"
457                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
458                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
459                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
460                <tbl:cell column="server"><%=HTML.encodeTags(item.getServer())%></tbl:cell>
461                <tbl:cell column="port"><%=item.getPort() == null ? "" : item.getPort().toString()%></tbl:cell>
462                <tbl:cell column="status">
463                  <%
464                  Boolean paused = item.getInfo().isPaused();
465                  %>
466                  <%=paused == null ? "<i>- unknown -</i>" : paused == true ? "Paused" : "Running"%>
467                </tbl:cell>
468                <tbl:cell column="info">
469                  CPU usage: <%=item.getCpuUsage() == null ? "<i>- unknown -</i>" : item.getCpuUsage()+"%" %><br>
470                  Total memory: <%=item.getTotalMemory() == null ? "<i>- unknown -</i>" : Values.formatBytes(item.getTotalMemory()) %><br>
471                  Used memory: <%=item.getUsedMemory() == null ? "<i>- unknown -</i>" : Values.formatBytes(item.getUsedMemory()) %>
472                </tbl:cell>
473                <tbl:cell column="jobs">
474                  <%
475                  Set<JobInfo> jobs = item.getInfo().getJobInfo();
476                  if (jobs == null)
477                  {
478                    %>
479                    Unknown
480                    <%
481                  }
482                  else if (jobs.size() == 0)
483                  {
484                    %>
485                    <i>- none -</i>
486                    <%
487                  }
488                  else
489                  {
490                    String separator = "";
491                    for (JobInfo jobInfo : jobs)
492                    {
493                      try
494                      {
495                        Job job = Job.getById(dc, jobInfo.getJobId());
496                        int percent = job.getPercentComplete();
497                        Job.ExecutionTime estimated = job.getEstimatedExecutionTime();
498                        out.write(separator);
499                        if (mode.hasPropertyLink())
500                        {
501                          out.write(Base.getLinkedName(ID, job, false, mode.hasEditLink()));
502                        }
503                        else
504                        {
505                          out.write(HTML.encodeTags(job.getName()));
506                        }
507                        out.write(" (");
508                        if (percent != -1) out.write(percent + "%, ");
509                        out.write(estimated.name());
510                        out.write(")");
511                        separator = ", ";
512                      }
513                      catch (Throwable t)
514                      {
515                        %>
516                        <div class="error"><%=t.getMessage()%></div>
517                        <%
518                      }
519                    }
520                  }
521                  %>
522                </tbl:cell>
523                <tbl:cell column="plugins">
524                  <%
525                  pluginQuery.setParameter("agent", itemId, Type.INT);
526                  try
527                  {
528                    String separator = "";
529                    for (PluginDefinition p : pluginQuery.list(dc))
530                    {
531                      out.write(separator);
532                      if (mode.hasPropertyLink())
533                      {
534                        out.write(Base.getLink(ID, p.getName(), Item.PLUGINDEFINITION, p.getId(), mode.hasEditLink()));
535                      }
536                      else
537                      {
538                        out.write(HTML.encodeTags(p.getName()));
539                      }
540                      separator = ", ";
541                    }
542                  }
543                  catch (Throwable t)
544                  {
545                    %>
546                    <div class="error"><%=t.getMessage()%></div>
547                    <%
548                  }
549                  %>
550                </tbl:cell>
551                <tbl:cell column="owner"
552                  ><base:propertyvalue 
553                    item="<%=item%>" 
554                    property="owner"
555                    enableEditLink="<%=mode.hasEditLink()%>" 
556                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
557                  /></tbl:cell>
558                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
559                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
560                <tbl:cell column="sharedTo">
561                  <%
562                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
563                  while(sharees.hasNext())
564                  {
565                    Nameable n = sharees.next();
566                    if (mode.hasPropertyLink())
567                    {
568                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
569                    }
570                    else
571                    {
572                      out.write(HTML.encodeTags(n.getName()));
573                    }
574                    out.write(sharees.hasNext() ? ", " : "");
575                  }
576                  %>
577                </tbl:cell>
578                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
579                  <tbl:cell column="xt-columns" />
580                </tbl:xt-cells>
581              </tbl:row>
582              <%
583              }
584            }
585          if (numListed == 0)
586          {
587            %>
588            <tbl:panel subclass="bg-filled-50">
589              <div class="messagecontainer note">
590              <%=agents == null || agents.getTotalCount() == 0 ? "No job agents were found" : "No job agents on this page. Please select another page!" %>
591              </div>
592            </tbl:panel>
593            <%
594          }
595          %>
596        </tbl:rows>
597      </tbl:data>
598    </tbl:table>
599    </div>
600   
601    <base:buttongroup subclass="dialogbuttons">
602      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
603      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
604      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
605    </base:buttongroup>
606   
607  </base:body>
608  </base:page>
609  <%
610}
611finally
612{
613  if (agents != null) agents.close();
614  if (dc != null) dc.close();
615}
616%>
Note: See TracBrowser for help on using the repository browser.