FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ScanJobProxy.php
1 <?php
2 /*
3 Copyright (C) 2014, 2015 Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Proxy;
20 
23 
29 {
30  const ARS_TABLE_SUFFIX = "_ars";
31 
33  private $agentDao;
35  private $uploadId;
37  private $successfulScanners = array();
38 
43  function __construct(AgentDao $agentDao, $uploadId)
44  {
45  $this->agentDao = $agentDao;
46  $this->uploadId = $uploadId;
47  }
48 
49  public function getSuccessfulAgents()
50  {
51  $successfulAgents = array();
52  foreach ($this->successfulScanners as $scanAgents) {
53  $successfulAgents = array_merge($successfulAgents, $scanAgents);
54  }
55  return $successfulAgents;
56  }
57 
58  public function getLatestSuccessfulAgentIds()
59  {
60  $agentIds = array();
61  foreach ($this->successfulScanners as $agentName=>$scanAgents) {
62  $agentRef = $scanAgents[0];
63  $agentIds[$agentName] = $agentRef->getAgentId();
64  }
65  return $agentIds;
66  }
67 
68  public function createAgentStatus($scannerAgents)
69  {
70  $scannerVars = array();
71  foreach ($scannerAgents as $agentName) {
72  $agentHasArsTable = $this->agentDao->arsTableExists($agentName);
73  if (empty($agentHasArsTable)) {
74  continue;
75  }
76  $scannerVars[] = $this->scanAgentStatus($agentName);
77  }
78  return $scannerVars;
79  }
80 
81  public function getAgentMap()
82  {
83  $agentMap = array();
84  foreach ($this->getSuccessfulAgents() as $agent) {
85  $agentMap[$agent->getAgentId()] = $agent->getAgentName() . " " . $agent->getAgentRevision();
86  }
87  return $agentMap;
88  }
89 
95  protected function scanAgentStatus($agentName)
96  {
97  $successfulAgents = $this->agentDao->getSuccessfulAgentEntries($agentName,$this->uploadId);
98  $vars['successfulAgents'] = $successfulAgents;
99  $vars['uploadId'] = $this->uploadId;
100  $vars['agentName'] = $agentName;
101 
102  if (!count($successfulAgents)) {
103  $vars['isAgentRunning'] = count($this->agentDao->getRunningAgentIds($this->uploadId, $agentName)) > 0;
104  return $vars;
105  }
106 
107  $latestSuccessfulAgent = $successfulAgents[0];
108  $currentAgentRef = $this->agentDao->getCurrentAgentRef($agentName);
109  $vars['currentAgentId'] = $currentAgentRef->getAgentId();
110  $vars['currentAgentRev'] = $currentAgentRef->getAgentRevision();
111  if ($currentAgentRef->getAgentId() != $latestSuccessfulAgent['agent_id']) {
112  $runningJobs = $this->agentDao->getRunningAgentIds($this->uploadId, $agentName);
113  $vars['isAgentRunning'] = in_array($currentAgentRef->getAgentId(), $runningJobs);
114  }
115 
116  foreach ($successfulAgents as $agent) {
117  $this->successfulScanners[$agentName][] = new AgentRef($agent['agent_id'], $agentName, $agent['agent_rev']);
118  }
119  return $vars;
120  }
121 }
__construct(AgentDao $agentDao, $uploadId)
scanAgentStatus($agentName)
get status var and store successfulAgents