FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
AjaxAdminScheduler.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2011-2013 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2014 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ***********************************************************/
19 
21 
27 
29 {
30  const NAME = "ajax_admin_scheduler";
32  private $dbManager;
33 
34  function __construct()
35  {
36  parent::__construct(self::NAME, array(
37  self::TITLE => _("URL"),
38  self::PERMISSION => Auth::PERM_WRITE
39  ));
40 
41  $this->dbManager = $this->getObject('db.manager');
42  }
43 
48  protected function handle(Request $request)
49  {
50  $V = '';
51  $operation = $request->get('operation');
52  $vars['jobOptions'] = $this->jobListOption($operation);
53  $vars['operation'] = $operation;
54  $vars['priorityList'] = $this->priorityListOption();
55  $content = $this->renderer->loadTemplate('ajax-admin-scheduler.html.twig')->render($vars);
56 
57  if ('pause' == $operation || 'restart' == $operation ||
58  'status' == $operation || 'priority' == $operation) {
59  $V = $content;
60  } else if ('verbose' == $operation) {
61  $verbose_list_option = $this->verboseListOption();
62  $text2 = _("Select a verbosity level");
63  $V = $content .
64  "<br>$text2: <select name='level_list' id='level_list'>$verbose_list_option</select>";
65  } else if ('agents' == $operation) {
67  $dbManager = $this->getObject('db.manager');
68  $dbManager->prepare($stmt = __METHOD__ . '.getAgents',
69  'SELECT MAX(agent_pk) agent_id, agent_name FROM agent WHERE agent_enabled GROUP BY agent_name');
70  $res = $dbManager->execute($stmt);
71  $V = '<ul>';
72  while ($row = $dbManager->fetchArray($res)) {
73  $V .= "<li>$row[agent_name]</li>";
74  }
75  $V .= '</ul>';
76  $dbManager->freeResult($res);
77  }
78  return new Response($V, Response::HTTP_OK, array('content-type'=>'text/htm')); // not 'text/html' while console-logging
79  }
80 
86  function jobListOption($type)
87  {
88  if (empty($type)) {
89  return array();
90  }
91 
92  $job_array = array();
93  if ('status' == $type || 'verbose' == $type || 'priority' == $type) {
94  $job_array = GetRunnableJobList();
95  if ('priority' != $type) {
96  $job_array[0] = "scheduler";
97  }
98  }
99  if ('pause' == $type) {
100  $job_array = GetJobList("Started");
101  }
102  if ('restart' == $type) {
103  $job_array = GetJobList("Paused");
104  }
105  return $job_array;
106  }
107 
112  function verboseListOption()
113  {
114  $verbose_list_option = "";
115  $min = 1;
116  $max = 3;
117  for ($i = $min; $i <= $max; $i++) {
118  $bitmask= (1<<$i) - 1;
119  $verbose_list_option .= "<option value='$bitmask'>$i</option>";
120  }
121  return $verbose_list_option;
122  }
123 
129  {
130  $min = -20;
131  $max = 20;
132  $priority_list = array();
133  for ($i = $min; $i <= $max; $i++) {
134  $priority_list[$i]=$i;
135  }
136  return $priority_list;
137  }
138 }
139 
140 register_plugin(new AjaxAdminScheduler());
GetRunnableJobList()
Get runnable job list, the process is below:
verboseListOption()
get the verbose list: if the value of verbose is 1, set verbose as 1
GetJobList($status)
Gets the list of jobqueue records with the requested $status.
Definition: common-job.php:246
jobListOption($type)
get the job list for the specified operation
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
priorityListOption()
get the priority list for setting, -20..20