35 define(
"TITLE_AJAXSHOWJOBS", _(
"ShowJobs"));
45 const MAX_LOG_OUTPUT = 32768;
59 function __construct()
61 $this->Name =
"ajaxShowJobs";
62 $this->Title = TITLE_AJAXSHOWJOBS;
66 $this->OutputType =
'JSON';
67 $this->OutputToStdout =
true;
70 $this->showJobsDao = $container->get(
'dao.show_jobs');
71 $this->userDao = $container->get(
'dao.user');
72 $this->clearingDao = $container->get(
'dao.clearing');
73 $this->
dbManager = $container->get(
'db.manager');
75 parent::__construct();
80 if ($this->
State != PLUGIN_STATE_READY) {
84 if (empty($uploadId)) {
97 $job_pk1 = $JobsInfo1[
"job"][
"job_pk"];
98 $job_pk2 = $JobsInfo2[
"job"][
"job_pk"];
100 return $job_pk2 - $job_pk1;
111 $fields=array(
'jq_pk'=>
'jq_pk',
112 'job_pk'=>
'jq_job_fk',
113 'Job Name'=>
'job_name',
114 'Agent Name'=>
'jq_type',
115 'Priority'=>
'job_priority',
117 'jq_runonpfile'=>
'jq_runonpfile',
118 'Queued'=>
'job_queued',
119 'Started'=>
'jq_starttime',
120 'Ended'=>
'jq_endtime',
121 'Elapsed HH:MM:SS'=>
'elapsed',
122 'Status'=>
'jq_end_bits',
123 'Items processed'=>
'jq_itemsprocessed',
124 'Submitter'=>
'job_user_fk',
125 'Upload'=>
'job_upload_fk',
129 $row = $this->showJobsDao->getDataForASingleJob($job_pk);
132 foreach ($fields as $labelKey=>$field) {
141 case 'jq_itemsprocessed':
142 $value = number_format($row[$field]);
148 if (!empty($row[
'job_upload_fk'])) {
149 $value =
"<a href='$uri" . $row[
'job_upload_fk'] .
"'>" . htmlentities($row[$field]) .
"</a>".
" (" . _(
"Click to view jobs for this upload") .
")";
152 $back =
"(" . _(
"Click to return to Show Jobs") .
")";
153 $value =
"<a href='$uri2'>$row[$field] $back</a>";
156 case 'job_upload_fk':
157 if (!empty($row[$field])) {
158 $browse =
Traceback_uri() .
"?mod=browse&upload=" . htmlentities($row[$field]);
159 $value =
"<a href='$browse'>" . htmlentities($row[$field]) .
"</a>".
" (" . _(
"Click to browse upload") .
")";
163 if (empty($row[$field]) || $row[$field] ==
'removed' || !file_exists($row[$field])) {
166 if (filesize($row[$field]) > self::MAX_LOG_OUTPUT) {
167 $value =
"<pre>" .file_get_contents($row[$field],
false,null,-1,self::MAX_LOG_OUTPUT).
"</pre>" 168 .
'<a href="'.
Traceback_uri() .
'?mod=download&log=' . $row[
'jq_pk'] .
'">Download full log</a>';
170 $value =
"<pre>" . file_get_contents($row[$field]).
"</pre>";
174 if (!empty($row[$field])) {
175 $value = $this->userDao->getUserName($row[$field]);
179 $jq_args_temp = $row[$field];
180 $jq_args_show = $jq_args_temp;
181 if (! empty($jq_args_temp)) {
182 $pos = strpos($jq_args_temp,
' SVN ');
184 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
186 $pos = strpos($jq_args_temp,
' CVS ');
188 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
190 $pos = strpos($jq_args_temp,
' Git ');
192 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
194 $value = $jq_args_show;
198 if (array_key_exists($field, $row)) {
199 $value = htmlentities($row[$field]);
203 $table[] = array(
'DT_RowId' => $i++,
207 $tableData = array_values($table);
208 return new JsonResponse(array(
'sEcho' => intval($_GET[
'sEcho']),
209 'aaData' => $tableData,
210 'iTotalRecords' => count($tableData),
211 'iTotalDisplayRecords' => count($tableData)));
222 if (count($jobData) == 0) {
223 return array(
'showJobsData' =>
"There are no jobs to display");
226 foreach ($jobData as $jobId => $jobs) {
228 'jobId' => $jobs[
'job'][
'job_pk'],
229 'jobName' => $jobs[
'job'][
'job_name'],
230 'jobQueue' => $jobs[
'jobqueue']
232 foreach ($jobArr[
'jobQueue'] as $key => $singleJobQueue) {
233 $jobArr[
'jobQueue'][$key][
'jq_starttime'] =
Convert2BrowserTime($jobArr[
'jobQueue'][$key][
'jq_starttime']);
234 $jobArr[
'jobQueue'][$key][
'jq_endtime'] =
Convert2BrowserTime($jobArr[
'jobQueue'][$key][
'jq_endtime']) ;
235 if (! empty($singleJobQueue[
"jq_endtime"])) {
236 $numSecs = strtotime($singleJobQueue[
'jq_endtime']) -
237 strtotime($singleJobQueue[
'jq_starttime']);
238 $numSecs = ($numSecs == 0) ? 1 : $numSecs;
240 $numSecs = time() - strtotime($singleJobQueue[
'jq_starttime']);
243 $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec = 0;
244 if ($singleJobQueue[
'jq_starttime']) {
245 $itemsPerSec = $this->showJobsDao->getNumItemsPerSec(
246 $singleJobQueue[
'jq_itemsprocessed'], $numSecs);
247 $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec;
249 if (empty($singleJobQueue[
'jq_endtime'])) {
250 $jobArr[
'jobQueue'][$key][
'eta'] = $this->showJobsDao->getEstimatedTime(
251 $singleJobQueue[
'jq_job_fk'], $singleJobQueue[
'jq_type'],
252 $itemsPerSec, $jobs[
'job'][
'job_upload_fk']);
253 if ($singleJobQueue[
'jq_type'] ===
'monkbulk' ||
254 $singleJobQueue[
'jq_type'] ===
'deciderjob') {
255 $noOfMonkBulk = $this->showJobsDao->getItemsProcessedForDecider(
256 'decider', $singleJobQueue[
'jq_job_fk']);
257 if (! empty($noOfMonkBulk)) {
258 $totalCountOfMb = $this->clearingDao->getPreviousBulkIds(
262 if (! empty($totalCountOfMb)) {
263 $jobArr[
'jobQueue'][$key][
'isNoOfMonkBulk'] = $noOfMonkBulk[0] .
264 "/" . $totalCountOfMb;
271 $jobArr[
'jobQueue'][$key][
'isInProgress'] = ($singleJobQueue[
'jq_end_bits'] ==
273 $jobArr[
'jobQueue'][$key][
'isReady'] = ($singleJobQueue[
'jq_end_bits'] ==
276 switch ($singleJobQueue[
'jq_type']) {
278 $jobArr[
'jobQueue'][$key][
'download'] =
"ReadMeOss";
281 $jobArr[
'jobQueue'][$key][
'download'] =
"SPDX2 report";
284 $jobArr[
'jobQueue'][$key][
'download'] =
"SPDX2 tag/value report";
287 $jobArr[
'jobQueue'][$key][
'download'] =
"DEP5 copyright file";
290 $jobArr[
'jobQueue'][$key][
'download'] =
"uploaded SPDX2 report";
292 case 'unifiedreport':
293 $jobArr[
'jobQueue'][$key][
'download'] =
"Unified Report";
296 $jobArr[
'jobQueue'][$key][
'download'] =
"";
299 if (! empty($jobs[
'upload'])) {
301 'uploadName' => $jobs[
'upload'][
'upload_filename'],
302 'uploadId' => $jobs[
'upload'][
'upload_pk'],
303 'uploadDesc' => $jobs[
'upload'][
'upload_desc'],
304 'uploadItem' => empty($jobs[
'uploadtree']) ? -1 : $jobs[
'uploadtree'][
'uploadtree_pk'],
305 'uploadEta' => $this->showJobsDao->getEstimatedTime($jobs[
'job'][
'job_pk'],
'', 0, $jobs[
'upload'][
'upload_pk'])
310 $returnData[] = array(
312 'upload' => $uploadArr,
325 foreach ($job[
'jobqueue'] as $jobqueueRec) {
326 if ($jobqueueRec[
'jq_end_bits'] === 0) {
341 if ($jobqueueRec[
'jq_end_bits'] > 1) {
343 }
else if (! empty($jobqueueRec[
'jq_starttime']) &&
344 empty($jobqueueRec[
'jq_endtime'])) {
345 return 'jobScheduled';
346 }
else if (!empty($jobqueueRec[
'jq_starttime']) && !empty($jobqueueRec[
'jq_endtime'])) {
347 return 'jobFinished';
368 if (! empty($jobqueueRec[
'jq_endtext'])) {
369 $status .=
"$jobqueueRec[jq_endtext]";
372 if (! strstr($status,
"Success") && ! strstr($status,
"Fail") &&
373 $jobqueueRec[
"jq_end_bits"]) {
375 if ($jobqueueRec[
"jq_end_bits"] == 0x1) {
376 $status .= _(
"Success");
377 }
else if ($jobqueueRec[
"jq_end_bits"] == 0x2) {
378 $status .= _(
"Failure");
379 }
else if ($jobqueueRec[
"jq_end_bits"] == 0x4) {
380 $status .= _(
"Nonfatal");
396 $uri =
"?mod=showjobs";
397 if (!empty($allusers) && $allusers > 0) {
398 $uri .=
"&allusers=$allusers";
401 $uri .=
"&upload=$uploadPk";
404 if (empty($allusers)) {
409 $upload_pks = array($uploadPk);
410 list($jobs, $totalPages) = $this->showJobsDao->uploads2Jobs($upload_pks, $page);
412 list($jobs, $totalPages) = $this->showJobsDao->myJobs($allusers, $page);
414 $jobsInfo = $this->showJobsDao->getJobInfo($jobs);
415 usort($jobsInfo, array($this,
"compareJobsInfo"));
417 $pagination = ($totalPages > 1 ?
MenuPage($page, $totalPages, $uri) :
"");
420 return new JsonResponse(
422 'showJobsData' => $showJobData,
423 'pagination' => $pagination
427 public function Output()
429 if ($this->
State != PLUGIN_STATE_READY) {
432 $output = $this->jsonContent();
433 if (!$this->OutputToStdout) {
439 protected function jsonContent()
445 if (! empty($uploadPk)) {
446 return $this->
getJobs($uploadPk);
449 case "showSingleJob":
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
getClass($jobqueueRec)
array $jobqueueRec get the jobqueue row color
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
isUnfinishedJob($job)
Are there any unfinished jobqueues in this job?
getJobs($uploadPk)
get data of all jobs using uploadpk
compareJobsInfo($JobsInfo1, $JobsInfo2)
Sort compare function to order $JobsInfo by job_pk.
jobqueueStatus($jobqueueRec)
Get the status of a jobqueue item If the job isn't known to the scheduler, then report the status bas...
getShowJobsForEachJob($jobData)
Returns an upload job status in array.
getGeekyScanDetailsForJob($job_pk)
Returns geeky scan details about the jobqueue item.
Provide data for jobs table.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
fo_dbManager * dbManager
fo_dbManager object
This is the Plugin class. All plugins should:
list_t type structure used to keep various lists. (e.g. there are multiple lists).
static getGroupId()
Get the current user's group id.