13 define(
"TITLE_ADMIN_SCHEDULER", _(
"Scheduler Administration"));
22 public $operation_array;
26 $this->Name =
"admin_scheduler";
27 $this->Title = TITLE_ADMIN_SCHEDULER;
28 $this->MenuList =
"Admin::Scheduler";
30 $this->operation_array = array
32 "status" => array(_(
"Status"), _(
"Display job or scheduler status.")),
33 "database" => array(_(
"Check job queue"),_(
"Check for new jobs.")),
34 "reload" => array(_(
"Reload"), _(
"Reload fossology.conf.")),
35 "agents" => array(_(
"Agents"), _(
"Show a list of enabled agents.")),
36 "verbose" => array(_(
"Verbose"), _(
"Change the verbosity level of the scheduler or a job.")),
37 "stop" => array(_(
"Shutdown Scheduler"), _(
"Shutdown the scheduler gracefully and stop all background processing. This can take a while for all the agents to quit.")),
40 "restart" => array(_(
"Unpause a job"), _(
"Unpause a job.")),
41 "pause" => array(_(
"Pause a running job"), _(
"Pause a running job.")),
42 "priority" => array(_(
"Priority"), _(
"Change the priority of a job."))
44 parent::__construct();
54 foreach ($this->operation_array as $key => $value) {
55 $V .=
"<option value='$key'>$value[0]</option>";
66 $job_list_option =
"<option value='0'>scheduler</option>";
68 if (
"stop" === $operation) {
69 return $job_list_option;
72 if (!empty($job_array)) {
73 foreach ($job_array as $job_id) {
74 $job_list_option .=
"<option value='$job_id'>$job_id</option>";
77 return $job_list_option;
90 $text = _(
"scheduler");
94 $job_type =
"$text $job_id";
98 $text = _(
"Status of the");
99 $operation_text =
"$text $job_type";
102 $text =
"Scheduler checked the job queue";
103 $operation_text = $text;
106 $text = _(
"Configuration information for the agents and hosts reloaded");
107 $operation_text = $text;
110 $text = _(
"Get list of valid agents");
111 $operation_text = $text;
115 $verbose_level = log($level_id + 1, 2);
116 $text1 = _(
"Change the verbosity level of the");
118 $operation_text =
"$text1 $job_type $text2 $verbose_level";
121 $text = _(
"Shutdown Scheduler");
122 $operation_text = $text;
125 $text = _(
"Start Scheduler");
126 $operation_text = $text;
129 $text = _(
"Restart Scheduler");
130 $operation_text = $text;
133 $text = _(
"Restart the");
134 $operation_text =
"$text $job_type";
137 $text = _(
"Pause the");
138 $operation_text =
"$text $job_type";
142 $text1 = _(
"Change the priority of the");
144 $operation_text =
"$text1 $job_type $text2 $priority_id";
147 return $operation_text;
160 if (
"start" === $operation) {
163 $response_from_scheduler, $this->error_info);
166 $response_from_scheduler =
"Warning, the scheduler is running";
169 $this->error_info =
null;
171 return $this->error_info;
173 }
else if (
"restarts" === $operation) {
175 return $this->error_info;
177 $commands = $operation;
178 if (! empty($job_id) &&
'scheduler' != $job_id) {
179 $commands .=
" $job_id";
181 if (isset($priority_id)) {
182 $commands .=
" $priority_id";
184 if (! empty($level_id)) {
185 $commands .=
" $level_id";
187 $commands =
trim($commands);
189 $response_from_scheduler, $this->error_info);
190 return $response_from_scheduler . $this->error_info;
200 $command =
"/etc/init.d/fossology restart >/dev/null 2>&1";
202 $command =
"/etc/init.d/fossology start >/dev/null 2>&1";
204 $lastline = system($command, $rc);
206 $this->error_info =
" Failed to start the scheduler, return value is: $rc.";
219 if (! empty($operation)) {
222 $priority_id, $level_id);
224 if (empty($this->error_info)) {
225 $text = _(
"successfully");
226 $status_msg .=
"$operation_text $text.";
227 if (! empty($response_from_scheduler)) {
228 $report .=
"<hr style='border-style:dashed'>";
229 $report .= $response_from_scheduler;
233 $status_msg .=
"$operation_text $text.";
234 $report .= $this->error_info;
236 $this->vars[
'message'] = $status_msg . $report;
239 $text = _(
"List of operations:");
242 foreach ($this->operation_array as $value) {
243 $V .=
"<li><b>$value[0]</b>: $value[1]</li>";
248 $text = _(
"Select an operation");
249 $V.=
"<form id='operation_form' method='post'>";
250 $V.=
"<p><li>$text: ";
251 $V.=
"<select name='operation' id='operation' onchange='OperationSwich_Get(\""
252 .
Traceback_uri() .
"?mod=ajax_admin_scheduler&operation=\"+this.value)'<br />\n";
256 $V.=
"<div id='div_operation'>";
257 $text = _(
"Select the scheduler or a job");
258 $V.=
"$text: <select name='job_list' id='job_list'>";
264 $V.=
"<input type='submit' value='$text' />\n";
268 $choice .=
"<script language='javascript'>\n
269 function OperationSwich_Reply()\n
271 if ((OperationSwich.readyState==4) && (OperationSwich.status==200)) \n
273 document.getElementById('div_operation').innerHTML = OperationSwich.responseText;\n
283 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
This is a class for operations on the scheduler from GUI.
OperationListOption()
get the operation list
Output()
This function is called when user output is requested. This function is responsible for content....
__construct()
base constructor. Most plugins will just use this
StartScheduler($operation='')
start the scheduler
OperationSubmit($operation, $job_id, $priority_id, $level_id)
submit the specified operation
JobListOption()
get the job list for the operation 'status'
GetOperationText($operation)
get the related operation text, e.g. the operation text of 'stop' is 'Shutdown Schedule'
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
GetRunnableJobList()
Get runnable job list, the process is below:
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.