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)
45 $this->
dbManager->queryOnce(
"CREATE TABLE ".$tableName.
"() INHERITS(ars_master);
46 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_agent_fk_fkc FOREIGN KEY (agent_fk) REFERENCES agent(agent_pk);
47 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_upload_fk_fkc FOREIGN KEY (upload_fk) REFERENCES upload(upload_pk) ON DELETE CASCADE", __METHOD__);
50 public function writeArsRecord($agentName,$agentId,$uploadId,$arsId=0,$success=
false,$status=
"")
55 $successDb = $this->
dbManager->booleanToDb($success);
56 $parms = array($successDb, $arsId);
58 $stmt = __METHOD__.
".$arsTableName";
60 if (!empty($status)) {
63 $statusClause =
", ars_status = $".count($parms);
71 ars_endtime=now() $statusClause
76 "INSERT INTO $arsTableName(agent_fk,upload_fk)
77 VALUES ($1,$2) RETURNING ars_pk",
78 array($agentId, $uploadId),
79 __METHOD__.
".update.".$arsTableName);
81 return $row[
'ars_pk'];
88 public function getCurrentAgentId($agentName, $agentDesc=
"", $agentRev=
"")
91 "SELECT agent_pk FROM agent WHERE agent_name = $1 order by agent_ts desc limit 1",
92 array($agentName), __METHOD__.
"select"
97 "INSERT INTO agent(agent_name,agent_desc,agent_rev) VALUES ($1,$2,$3) RETURNING agent_pk",
98 array($agentName, $agentDesc, $agentRev), __METHOD__.
"insert"
100 return false !== $row ? intval($row[
'agent_pk']) : -1;
103 return intval($row[
'agent_pk']);
123 public function agentARSList($tableName, $uploadId, $limit = 1, $agentId = 0, $agentSuccess =
true)
126 if (!$this->
dbManager->existsTable($tableName)) {
130 $arguments = array($uploadId);
131 $statementName = __METHOD__ . $tableName;
132 $sql =
"SELECT * FROM $tableName, agent WHERE agent_pk=agent_fk AND upload_fk=$1 AND agent_enabled";
134 $arguments[] = $agentId;
135 $sql .=
' AND agent_fk=$'.count($arguments);
136 $statementName .=
".agent";
139 $sql .=
" AND ars_success";
140 $statementName .=
".suc";
142 $sql .=
" ORDER BY agent_ts DESC";
144 $arguments[] = $limit;
145 $sql .=
' limit $'.count($arguments);
146 $statementName .=
".lim";
148 $this->
dbManager->prepare($statementName,$sql);
149 $result = $this->
dbManager->execute($statementName, $arguments);
150 $resultArray = $this->
dbManager->fetchAll($result);
165 $listOfAllJobs = $this->
agentARSList($arsTableName, $uploadId, 0, 0,
false);
167 $listOfRunningAgents = array();
169 if ($listOfAllJobs !==
false) {
170 foreach ($listOfAllJobs as $job) {
171 if ($job [
'ars_success'] === $this->
dbManager->booleanToDb(
true)) {
174 $listOfRunningAgents[] = intval($job[
'agent_fk']);
177 return $listOfRunningAgents;
180 public function getLatestAgentResultForUpload($uploadId, $agentNames)
182 $latestScannerProxy = new \Fossology\Lib\Proxy\LatestScannerProxy($uploadId, $agentNames,
"latest_scanner$uploadId");
184 return $latestScannerProxy->getNameToIdMap();
193 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev from agent WHERE agent_enabled AND agent_name=$1 "
194 .
"ORDER BY agent_pk DESC LIMIT 1", array($agentName));
205 $stmt = __METHOD__ .
".getAgent.$agentName";
207 $sql =
"SELECT agent_pk,agent_rev,agent_name FROM agent LEFT JOIN " . $this->
getArsTableName($agentName) .
" ON agent_fk=agent_pk "
208 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success "
209 .
"ORDER BY agent_pk DESC");
210 $res = $this->
dbManager->execute($stmt, array($uploadId, $agentName));
212 while ($row = $this->
dbManager->fetchArray($res)) {
226 $stmt = __METHOD__ .
".getAgent.$scannerName";
228 $sql =
"SELECT agent_pk AS agent_id,agent_rev,agent_name "
229 .
"FROM agent LEFT JOIN $scannerName" . self::ARS_TABLE_SUFFIX .
" ON agent_fk=agent_pk "
230 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success "
231 .
"ORDER BY agent_id DESC");
232 $res = $this->
dbManager->execute($stmt, array($uploadId, $scannerName));
233 $agents = $this->
dbManager->fetchAll($res);
244 return new AgentRef(intval($row[
'agent_pk']), $row[
'agent_name'], $row[
'agent_rev']);
253 return $agentName . self::ARS_TABLE_SUFFIX;
263 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev, agent_desc FROM agent "
264 .
"WHERE agent_enabled AND agent_name=$1 ORDER BY agent_pk DESC LIMIT 1", array($agentName),__METHOD__.
'.get');
265 $this->
dbManager->getSingleRow(
"UPDATE agent SET agent_rev=agent_rev||'.'||substr(md5(agent_ts::text),0,6) "
266 .
"WHERE agent_pk=$1",array($row[
'agent_pk']),__METHOD__.
'.upd');
267 unset($row[
'agent_pk']);
268 $this->
dbManager->insertTableRow(
'agent',$row);
279 $row = $this->
dbManager->getSingleRow(
"SELECT agent_name FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
280 return ($row===
false)?
false:$row[
'agent_name'];
289 $row = $this->
dbManager->getSingleRow(
"SELECT agent_rev FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
290 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