10 namespace Fossology\Lib\Dao;
22 const ARS_TABLE_SUFFIX =
"_ars";
34 $this->logger = $logger;
37 public function arsTableExists($agentName)
42 public function createArsTable($agentName)
46 $this->
dbManager->queryOnce(
"CREATE TABLE ".$tableName.
"() INHERITS(ars_master);
47 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_agent_fk_fkc FOREIGN KEY (agent_fk) REFERENCES agent(agent_pk);
48 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_upload_fk_fkc FOREIGN KEY (upload_fk) REFERENCES upload(upload_pk) ON DELETE CASCADE", __METHOD__);
51 public function writeArsRecord($agentName,$agentId,$uploadId,$arsId=0,$success=
false,$status=
"")
56 $successDb = $this->
dbManager->booleanToDb($success);
57 $parms = array($successDb, $arsId);
59 $stmt = __METHOD__.
".$arsTableName";
61 if (!empty($status)) {
64 $statusClause =
", ars_status = $".count($parms);
72 ars_endtime=now() $statusClause
77 "INSERT INTO $arsTableName(agent_fk,upload_fk)
78 VALUES ($1,$2) RETURNING ars_pk",
79 array($agentId, $uploadId),
80 __METHOD__.
".update.".$arsTableName);
82 return $row[
'ars_pk'];
89 public function getCurrentAgentId($agentName, $agentDesc=
"", $agentRev=
"")
92 "SELECT agent_pk FROM agent WHERE agent_name = $1 order by agent_ts desc limit 1",
93 array($agentName), __METHOD__.
"select"
98 "INSERT INTO agent(agent_name,agent_desc,agent_rev) VALUES ($1,$2,$3) RETURNING agent_pk",
99 array($agentName, $agentDesc, $agentRev), __METHOD__.
"insert"
101 return false !== $row ? intval($row[
'agent_pk']) : -1;
104 return intval($row[
'agent_pk']);
124 public function agentARSList($tableName, $uploadId, $limit = 1, $agentId = 0, $agentSuccess =
true)
127 if (!$this->
dbManager->existsTable($tableName)) {
131 $arguments = array($uploadId);
132 $statementName = __METHOD__ . $tableName;
133 $sql =
"SELECT * FROM $tableName, agent WHERE agent_pk=agent_fk AND upload_fk=$1 AND agent_enabled";
135 $arguments[] = $agentId;
136 $sql .=
' AND agent_fk=$'.count($arguments);
137 $statementName .=
".agent";
140 $sql .=
" AND ars_success";
141 $statementName .=
".suc";
143 $sql .=
" ORDER BY agent_ts DESC";
145 $arguments[] = $limit;
146 $sql .=
' limit $'.count($arguments);
147 $statementName .=
".lim";
149 $this->
dbManager->prepare($statementName,$sql);
150 $result = $this->
dbManager->execute($statementName, $arguments);
151 $resultArray = $this->
dbManager->fetchAll($result);
167 $listOfAllJobs = $this->
agentARSList($arsTableName, $uploadId, 0, 0,
false);
169 $listOfRunningAgents = array();
171 if ($listOfAllJobs !==
false) {
172 foreach ($listOfAllJobs as $job) {
173 if ($job [
'ars_success'] === $this->
dbManager->booleanToDb(
true)) {
176 $listOfRunningAgents[] = intval($job[
'agent_fk']);
179 return $listOfRunningAgents;
182 public function getLatestAgentResultForUpload($uploadId, $agentNames)
184 $latestScannerProxy = new \Fossology\Lib\Proxy\LatestScannerProxy($uploadId, $agentNames,
"latest_scanner$uploadId");
186 return $latestScannerProxy->getNameToIdMap();
195 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev from agent WHERE agent_enabled AND agent_name=$1 "
196 .
"ORDER BY agent_pk DESC LIMIT 1", array($agentName));
207 $stmt = __METHOD__ .
".getAgent.$agentName";
209 $sql =
"SELECT agent_pk,agent_rev,agent_name FROM agent LEFT JOIN " . $this->
getArsTableName($agentName) .
" ON agent_fk=agent_pk "
210 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success "
211 .
"ORDER BY agent_pk DESC");
212 $res = $this->
dbManager->execute($stmt, array($uploadId, $agentName));
214 while ($row = $this->
dbManager->fetchArray($res)) {
228 $stmt = __METHOD__ .
".getAgent.$scannerName";
230 $sql =
"SELECT agent_pk AS agent_id,agent_rev,agent_name "
231 .
"FROM agent LEFT JOIN $scannerName" . self::ARS_TABLE_SUFFIX .
" ON agent_fk=agent_pk "
232 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success "
233 .
"ORDER BY agent_id DESC");
234 $res = $this->
dbManager->execute($stmt, array($uploadId, $scannerName));
235 $agents = $this->
dbManager->fetchAll($res);
246 return new AgentRef(intval($row[
'agent_pk']), $row[
'agent_name'], $row[
'agent_rev']);
255 return $agentName . self::ARS_TABLE_SUFFIX;
265 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev, agent_desc FROM agent "
266 .
"WHERE agent_enabled AND agent_name=$1 ORDER BY agent_pk DESC LIMIT 1", array($agentName),__METHOD__.
'.get');
267 $this->
dbManager->getSingleRow(
"UPDATE agent SET agent_rev=agent_rev||'.'||substr(md5(agent_ts::text),0,6) "
268 .
"WHERE agent_pk=$1",array($row[
'agent_pk']),__METHOD__.
'.upd');
269 unset($row[
'agent_pk']);
270 $this->
dbManager->insertTableRow(
'agent',$row);
281 $row = $this->
dbManager->getSingleRow(
"SELECT agent_name FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
282 return ($row===
false)?
false:$row[
'agent_name'];
291 $row = $this->
dbManager->getSingleRow(
"SELECT agent_rev FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
292 return ($row===
false)?
false:$row[
'agent_rev'];
getArsTableName($agentName)
__construct(DbManager $dbManager, Logger $logger)
getCurrentAgentRef($agentName)
agentARSList($tableName, $uploadId, $limit=1, $agentId=0, $agentSuccess=true)
The purpose of this function is to return an array of _ars records for an agent so that the latest ag...
renewCurrentAgent($agentName)
getSuccessfulAgentRuns($agentName, $uploadId)
getSuccessfulAgentEntries($scannerName, $uploadId)
getRunningAgentIds($uploadId, $agentName)
Returns the list of running or failed agent_pk s. Before latest successful run.
fo_dbManager * dbManager
fo_dbManager object