24 define(
"TITLE_ADMIN_SCHEDULER", _(
"Scheduler Administration"));
35 function __construct()
37 $this->Name =
"admin_scheduler";
38 $this->Title = TITLE_ADMIN_SCHEDULER;
39 $this->MenuList =
"Admin::Scheduler";
41 parent::__construct();
51 foreach ($this->operation_array as $key => $value) {
52 $V .=
"<option value='$key'>$value[0]</option>";
63 $job_list_option =
"<option value='0'>scheduler</option>";
65 if (
"stop" === $operation) {
66 return $job_list_option;
69 for ($i = 0; $i <
sizeof($job_array); $i ++) {
70 $job_id = $job_array[$i];
71 $job_list_option .=
"<option value='$job_id'>$job_id</option>";
73 return $job_list_option;
86 $text = _(
"scheduler");
90 $job_type =
"$text $job_id";
94 $text = _(
"Status of the");
95 $operation_text =
"$text $job_type";
98 $text =
"Scheduler checked the job queue";
99 $operation_text = $text;
102 $text = _(
"Configuration information for the agents and hosts reloaded");
103 $operation_text = $text;
106 $text = _(
"Get list of valid agents");
107 $operation_text = $text;
111 $verbose_level = log($level_id + 1, 2);
112 $text1 = _(
"Change the verbosity level of the");
114 $operation_text =
"$text1 $job_type $text2 $verbose_level";
117 $text = _(
"Shutdown Scheduler");
118 $operation_text = $text;
121 $text = _(
"Start Scheduler");
122 $operation_text = $text;
125 $text = _(
"Restart Scheduler");
126 $operation_text = $text;
129 $text = _(
"Restart the");
130 $operation_text =
"$text $job_type";
133 $text = _(
"Pause the");
134 $operation_text =
"$text $job_type";
138 $text1 = _(
"Change the priority of the");
140 $operation_text =
"$text1 $job_type $text2 $priority_id";
143 return $operation_text;
156 if (
"start" === $operation) {
159 $response_from_scheduler, $this->error_info);
162 $response_from_scheduler =
"Warning, the scheduler is running";
165 $this->error_info = null;
167 return $this->error_info;
169 }
else if (
"restarts" === $operation) {
171 return $this->error_info;
173 $commands = $operation;
174 if (! empty($job_id) &&
'scheduler' != $job_id) {
175 $commands .=
" $job_id";
177 if (isset($priority_id)) {
178 $commands .=
" $priority_id";
180 if (! empty($level_id)) {
181 $commands .=
" $level_id";
183 $commands =
trim($commands);
185 $response_from_scheduler, $this->error_info);
186 return $response_from_scheduler . $this->error_info;
196 $command =
"/etc/init.d/fossology restart >/dev/null 2>&1";
198 $command =
"/etc/init.d/fossology start >/dev/null 2>&1";
200 $lastline = system($command, $rc);
202 $this->error_info =
" Failed to start the scheduler, return value is: $rc.";
206 public function Output()
211 $this->operation_array = array
213 "status" => array(_(
"Status"), _(
"Display job or scheduler status.")),
214 "database" => array(_(
"Check job queue"),_(
"Check for new jobs.")),
215 "reload" => array(_(
"Reload"), _(
"Reload fossology.conf.")),
216 "agents" => array(_(
"Agents"), _(
"Show a list of enabled agents.")),
217 "verbose" => array(_(
"Verbose"), _(
"Change the verbosity level of the scheduler or a job.")),
218 "stop" => array(_(
"Shutdown Scheduler"), _(
"Shutdown the scheduler gracefully and stop all background processing. This can take a while for all the agents to quit.")),
221 "restart" => array(_(
"Unpause a job"), _(
"Unpause a job.")),
222 "pause" => array(_(
"Pause a running job"), _(
"Pause a running job.")),
223 "priority" => array(_(
"Priority"), _(
"Change the priority of a job."))
230 if (! empty($operation)) {
233 $priority_id, $level_id);
235 if (empty($this->error_info)) {
236 $text = _(
"successfully");
237 $status_msg .=
"$operation_text $text.";
238 if (! empty($response_from_scheduler)) {
239 $report .=
"<hr style='border-style:dashed'>";
240 $report .= $response_from_scheduler;
244 $status_msg .=
"$operation_text $text.";
245 $report .= $this->error_info;
247 $this->vars[
'message'] = $status_msg . $report;
250 $text = _(
"List of operations:");
253 foreach ($this->operation_array as $value) {
254 $V .=
"<li><b>$value[0]</b>: $value[1]</li>";
259 $text = _(
"Select an operation");
260 $V.=
"<form id='operation_form' method='post'>";
261 $V.=
"<p><li>$text: ";
262 $V.=
"<select name='operation' id='operation' onchange='OperationSwich_Get(\"" 263 .
Traceback_uri() .
"?mod=ajax_admin_scheduler&operation=\"+this.value)'<br />\n";
267 $V.=
"<div id='div_operation'>";
268 $text = _(
"Select the scheduler or a job");
269 $V.=
"$text: <select name='job_list' id='job_list'>";
275 $V.=
"<input type='submit' value='$text' />\n";
279 $choice .=
"<script language='javascript'>\n 280 function OperationSwich_Reply()\n 282 if ((OperationSwich.readyState==4) && (OperationSwich.status==200)) \n 284 document.getElementById('div_operation').innerHTML = OperationSwich.responseText;\n 294 $NewPlugin->Initialize();
GetRunnableJobList()
Get runnable job list, the process is below:
Traceback_uri()
Get the URI without query to this location.
StartScheduler($operation= '')
start the scheduler
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
GetOperationText($operation)
get the related operation text, e.g. the operation text of 'stop' is 'Shutdown Schedule' ...
This is a class for operations on the scheduler from GUI.
JobListOption()
get the job list for the operation 'status'
OperationListOption()
get the operation list
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.
OperationSubmit($operation, $job_id, $priority_id, $level_id)
submit the specified operation
This is the Plugin class. All plugins should:
char * trim(char *ptext)
Trimming whitespace.