24 use Symfony\Component\HttpFoundation\JsonResponse;
26 define(
"TITLE_AJAXSHOWJOBS", _(
"ShowJobs"));
36 const MAX_LOG_OUTPUT = 32768;
52 $this->Name =
"ajaxShowJobs";
53 $this->Title = TITLE_AJAXSHOWJOBS;
57 $this->OutputType =
'JSON';
58 $this->OutputToStdout =
true;
61 $this->showJobsDao = $container->get(
'dao.show_jobs');
62 $this->userDao = $container->get(
'dao.user');
63 $this->clearingDao = $container->get(
'dao.clearing');
64 $this->
dbManager = $container->get(
'db.manager');
66 parent::__construct();
71 if ($this->
State != PLUGIN_STATE_READY) {
75 if (empty($uploadId)) {
88 $job_pk1 = $JobsInfo1[
"job"][
"job_pk"];
89 $job_pk2 = $JobsInfo2[
"job"][
"job_pk"];
91 return $job_pk2 - $job_pk1;
102 $fields=array(
'jq_pk'=>
'jq_pk',
103 'job_pk'=>
'jq_job_fk',
104 'Job Name'=>
'job_name',
105 'Agent Name'=>
'jq_type',
106 'Priority'=>
'job_priority',
108 'jq_runonpfile'=>
'jq_runonpfile',
109 'Queued'=>
'job_queued',
110 'Started'=>
'jq_starttime',
111 'Ended'=>
'jq_endtime',
112 'Elapsed HH:MM:SS'=>
'elapsed',
113 'Status'=>
'jq_end_bits',
114 'Items processed'=>
'jq_itemsprocessed',
115 'Submitter'=>
'job_user_fk',
116 'Upload'=>
'job_upload_fk',
120 $row = $this->showJobsDao->getDataForASingleJob($job_pk);
123 foreach ($fields as $labelKey=>$field) {
130 if (! empty($row[$field])) {
134 case 'jq_itemsprocessed':
135 $value = number_format($row[$field]);
141 if (!empty($row[
'job_upload_fk'])) {
142 $value =
"<a href='$uri" . $row[
'job_upload_fk'] .
"'>" . htmlentities($row[$field]) .
"</a>".
" (" . _(
"Click to view jobs for this upload") .
")";
145 $back =
"(" . _(
"Click to return to Show Jobs") .
")";
146 $value =
"<a href='$uri2'>$row[$field] $back</a>";
149 case 'job_upload_fk':
150 if (!empty($row[$field])) {
151 $browse =
Traceback_uri() .
"?mod=browse&upload=" . htmlentities($row[$field]);
152 $value =
"<a href='$browse'>" . htmlentities($row[$field]) .
"</a>".
" (" . _(
"Click to browse upload") .
")";
156 if (empty($row[$field]) || $row[$field] ==
'removed' || !file_exists($row[$field])) {
159 if (filesize($row[$field]) > self::MAX_LOG_OUTPUT) {
160 $value =
"<pre>" .file_get_contents($row[$field],
false,
null,-1,self::MAX_LOG_OUTPUT).
"</pre>"
161 .
'<a href="'.
Traceback_uri() .
'?mod=download&log=' . $row[
'jq_pk'] .
'">Download full log</a>';
163 $value =
"<pre>" . file_get_contents($row[$field]).
"</pre>";
167 if (!empty($row[$field])) {
168 $value = $this->userDao->getUserName($row[$field]);
172 $jq_args_temp = $row[$field];
173 $jq_args_show = $jq_args_temp;
174 if (! empty($jq_args_temp)) {
175 $pos = strpos($jq_args_temp,
' SVN ');
177 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
179 $pos = strpos($jq_args_temp,
' CVS ');
181 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
183 $pos = strpos($jq_args_temp,
' Git ');
185 $jq_args_show = substr($jq_args_temp, 0, $pos + 4);
187 $value = $jq_args_show;
191 if (array_key_exists($field, $row)) {
192 $value = htmlentities($row[$field]);
196 $table[] = array(
'DT_RowId' => $i++,
200 $tableData = array_values($table);
201 return new JsonResponse(array(
'sEcho' => intval($_GET[
'sEcho']),
202 'aaData' => $tableData,
203 'iTotalRecords' => count($tableData),
204 'iTotalDisplayRecords' => count($tableData)));
216 if (count($jobData) == 0) {
217 return array(
'showJobsData' =>
"There are no jobs to display");
220 foreach ($jobData as $jobId => $jobs) {
222 'jobId' => $jobs[
'job'][
'job_pk'],
223 'jobName' => $jobs[
'job'][
'job_name'],
224 'jobQueue' => $jobs[
'jobqueue']
226 foreach ($jobArr[
'jobQueue'] as $key => $singleJobQueue) {
228 if (! empty($jobArr[
'jobQueue'][$key][
'jq_starttime'])) {
230 $jobArr[
'jobQueue'][$key][
'jq_starttime']);
232 if (! empty($jobArr[
'jobQueue'][$key][
'jq_endtime'])) {
234 $jobArr[
'jobQueue'][$key][
'jq_endtime']) ;
237 if (! empty($singleJobQueue[
"jq_endtime"])) {
238 $numSecs = strtotime($singleJobQueue[
'jq_endtime']) -
239 strtotime($singleJobQueue[
'jq_starttime']);
240 $numSecs = ($numSecs == 0) ? 1 : $numSecs;
242 $numSecs = time() - strtotime($singleJobQueue[
'jq_starttime']);
245 $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec = 0;
246 if ($singleJobQueue[
'jq_starttime']) {
247 $itemsPerSec = $this->showJobsDao->getNumItemsPerSec(
248 $singleJobQueue[
'jq_itemsprocessed'], $numSecs);
249 $jobArr[
'jobQueue'][$key][
'itemsPerSec'] = $itemsPerSec;
251 if (empty($singleJobQueue[
'jq_endtime'])) {
252 $jobArr[
'jobQueue'][$key][
'eta'] = $this->showJobsDao->getEstimatedTime(
253 $singleJobQueue[
'jq_job_fk'], $singleJobQueue[
'jq_type'],
254 $itemsPerSec, $jobs[
'job'][
'job_upload_fk']);
255 if ($singleJobQueue[
'jq_type'] ===
'monkbulk' ||
256 $singleJobQueue[
'jq_type'] ===
'deciderjob') {
257 $noOfMonkBulk = $this->showJobsDao->getItemsProcessedForDecider(
258 'decider', $singleJobQueue[
'jq_job_fk']);
259 if (! empty($noOfMonkBulk)) {
260 $totalCountOfMb = $this->clearingDao->getPreviousBulkIds(
264 if (! empty($totalCountOfMb)) {
265 $jobArr[
'jobQueue'][$key][
'isNoOfMonkBulk'] = $noOfMonkBulk[0] .
266 "/" . $totalCountOfMb;
273 $jobArr[
'jobQueue'][$key][
'isInProgress'] = ($singleJobQueue[
'jq_end_bits'] ==
275 $jobArr[
'jobQueue'][$key][
'isReady'] = ($singleJobQueue[
'jq_end_bits'] ==
279 if ($this->showJobsDao->isJobIdPresentInReportGen($singleJobQueue[
'jq_job_fk'])) {
280 switch ($singleJobQueue[
'jq_type']) {
282 $reportName =
"ReadMeOss";
285 $reportName =
"SPDX2 report";
288 $reportName =
"SPDX2 tag/value report";
291 $reportName =
"SPDX2 CSV report";
294 $reportName =
"SPDX3 JSON-LD report";
297 $reportName =
"SPDX3 JSON report";
300 $reportName =
"SPDX3 RDF report";
303 $reportName =
"SPDX3 tag/value report";
306 $reportName =
"DEP5 copyright file";
309 $reportName =
"uploaded SPDX2 report";
311 case 'unifiedreport':
312 $reportName =
"Unified Report";
315 $reportName =
"Clixml Report";
318 $reportName =
"CycloneDX json Report";
320 case 'decisionexporter':
321 $reportName =
"FOSSology Decisions";
325 $jobArr[
'jobQueue'][$key][
'download'] = $reportName;
327 if (! empty($jobs[
'upload'])) {
329 'uploadName' => $jobs[
'upload'][
'upload_filename'],
330 'uploadId' => $jobs[
'upload'][
'upload_pk'],
331 'uploadDesc' => $jobs[
'upload'][
'upload_desc'],
332 'uploadItem' => empty($jobs[
'uploadtree']) ? -1 : $jobs[
'uploadtree'][
'uploadtree_pk'],
333 'uploadEta' => $this->showJobsDao->getEstimatedTime($jobs[
'job'][
'job_pk'],
'', 0, $jobs[
'upload'][
'upload_pk'])
338 $returnData[] = array(
340 'upload' => $uploadArr,
353 foreach ($job[
'jobqueue'] as $jobqueueRec) {
354 if ($jobqueueRec[
'jq_end_bits'] === 0) {
369 if ($jobqueueRec[
'jq_end_bits'] > 1) {
371 }
else if (! empty($jobqueueRec[
'jq_starttime']) &&
372 empty($jobqueueRec[
'jq_endtime'])) {
373 return 'jobScheduled';
374 }
else if (!empty($jobqueueRec[
'jq_starttime']) && !empty($jobqueueRec[
'jq_endtime'])) {
375 return 'jobFinished';
396 if (! empty($jobqueueRec[
'jq_endtext'])) {
397 $status .=
"$jobqueueRec[jq_endtext]";
400 if (! strstr($status,
"Success") && ! strstr($status,
"Fail") &&
401 $jobqueueRec[
"jq_end_bits"]) {
403 if ($jobqueueRec[
"jq_end_bits"] == 0x1) {
404 $status .= _(
"Success");
405 }
else if ($jobqueueRec[
"jq_end_bits"] == 0x2) {
406 $status .= _(
"Failure");
407 }
else if ($jobqueueRec[
"jq_end_bits"] == 0x4) {
408 $status .= _(
"Nonfatal");
424 $uri =
"?mod=showjobs";
425 if (!empty($allusers) && $allusers > 0) {
426 $uri .=
"&allusers=$allusers";
429 $uri .=
"&upload=$uploadPk";
432 if (empty($allusers)) {
437 $upload_pks = array($uploadPk);
438 list($jobs, $totalPages) = $this->showJobsDao->uploads2Jobs($upload_pks, $page);
440 list($jobs, $totalPages) = $this->showJobsDao->myJobs($allusers, $page);
442 $jobsInfo = $this->showJobsDao->getJobInfo($jobs);
443 usort($jobsInfo, array($this,
"compareJobsInfo"));
445 $pagination = ($totalPages > 0 ?
MenuPage($page, $totalPages, $uri) :
"");
448 return new JsonResponse(
450 'showJobsData' => $showJobData,
451 'pagination' => $pagination
457 if ($this->
State != PLUGIN_STATE_READY) {
460 $output = $this->jsonContent();
461 if (!$this->OutputToStdout) {
467 protected function jsonContent()
473 if (! empty($uploadPk)) {
474 return $this->
getJobs($uploadPk);
477 case "showSingleJob":
484 $NewPlugin =
new AjaxShowJobs();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
Provide data for jobs table.
isUnfinishedJob($job)
Are there any unfinished jobqueues in this job?
__construct()
base constructor. Most plugins will just use this
getJobs($uploadPk)
get data of all jobs using uploadpk
Output()
This function is called when user output is requested. This function is responsible for content....
getGeekyScanDetailsForJob($job_pk)
Returns geeky scan details about the jobqueue item.
getClass($jobqueueRec)
array $jobqueueRec get the jobqueue row color
compareJobsInfo($JobsInfo1, $JobsInfo2)
Sort compare function to order $JobsInfo by job_pk.
getShowJobsForEachJob($jobData, $forApi=false)
Returns an upload job status in array for API or browser.
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
jobqueueStatus($jobqueueRec)
Get the status of a jobqueue item If the job isn't known to the scheduler, then report the status bas...
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object
list_t type structure used to keep various lists. (e.g. there are multiple lists).