FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ScanJobProxy.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014, 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Proxy;
9 
12 
18 {
19  const ARS_TABLE_SUFFIX = "_ars";
20 
22  private $agentDao;
24  private $uploadId;
26  private $successfulScanners = array();
27 
32  function __construct(AgentDao $agentDao, $uploadId)
33  {
34  $this->agentDao = $agentDao;
35  $this->uploadId = $uploadId;
36  }
37 
38  public function getSuccessfulAgents()
39  {
40  $successfulAgents = array();
41  foreach ($this->successfulScanners as $scanAgents) {
42  $successfulAgents = array_merge($successfulAgents, $scanAgents);
43  }
44  return $successfulAgents;
45  }
46 
47  public function getLatestSuccessfulAgentIds()
48  {
49  $agentIds = array();
50  foreach ($this->successfulScanners as $agentName=>$scanAgents) {
51  $agentRef = $scanAgents[0];
52  $agentIds[$agentName] = $agentRef->getAgentId();
53  }
54  return $agentIds;
55  }
56 
57  public function createAgentStatus($scannerAgents)
58  {
59  $scannerVars = array();
60  foreach ($scannerAgents as $agentName) {
61  $agentHasArsTable = $this->agentDao->arsTableExists($agentName);
62  if (empty($agentHasArsTable)) {
63  continue;
64  }
65  $scannerVars[] = $this->scanAgentStatus($agentName);
66  }
67  return $scannerVars;
68  }
69 
70  public function getAgentMap()
71  {
72  $agentMap = array();
73  foreach ($this->getSuccessfulAgents() as $agent) {
74  $agentMap[$agent->getAgentId()] = $agent->getAgentName() . " " . $agent->getAgentRevision();
75  }
76  return $agentMap;
77  }
78 
84  protected function scanAgentStatus($agentName)
85  {
86  $successfulAgents = $this->agentDao->getSuccessfulAgentEntries($agentName,$this->uploadId);
87  $vars['successfulAgents'] = $successfulAgents;
88  $vars['uploadId'] = $this->uploadId;
89  $vars['agentName'] = $agentName;
90 
91  if (!count($successfulAgents)) {
92  $vars['isAgentRunning'] = count($this->agentDao->getRunningAgentIds($this->uploadId, $agentName)) > 0;
93  return $vars;
94  }
95 
96  $latestSuccessfulAgent = $successfulAgents[0];
97  $currentAgentRef = $this->agentDao->getCurrentAgentRef($agentName);
98  $vars['currentAgentId'] = $currentAgentRef->getAgentId();
99  $vars['currentAgentRev'] = $currentAgentRef->getAgentRevision();
100  if ($currentAgentRef->getAgentId() != $latestSuccessfulAgent['agent_id']) {
101  $runningJobs = $this->agentDao->getRunningAgentIds($this->uploadId, $agentName);
102  $vars['isAgentRunning'] = in_array($currentAgentRef->getAgentId(), $runningJobs);
103  }
104 
105  foreach ($successfulAgents as $agent) {
106  $this->successfulScanners[$agentName][] = new AgentRef($agent['agent_id'], $agentName, $agent['agent_rev']);
107  }
108  return $vars;
109  }
110 }
scanAgentStatus($agentName)
get status var and store successfulAgents
__construct(AgentDao $agentDao, $uploadId)