33 const ARS_TABLE_SUFFIX =
"_ars";
45 $this->logger = $logger;
48 public function arsTableExists($agentName)
53 public function createArsTable($agentName)
57 $this->
dbManager->queryOnce(
"CREATE TABLE ".$tableName.
"() INHERITS(ars_master); 58 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_agent_fk_fkc FOREIGN KEY (agent_fk) REFERENCES agent(agent_pk); 59 ALTER TABLE ONLY ".$tableName.
" ADD CONSTRAINT ".$tableName.
"_upload_fk_fkc FOREIGN KEY (upload_fk) REFERENCES upload(upload_pk) ON DELETE CASCADE", __METHOD__);
62 public function writeArsRecord($agentName,$agentId,$uploadId,$arsId=0,$success=
false,$status=
"")
67 $successDb = $this->
dbManager->booleanToDb($success);
68 $parms = array($successDb, $arsId);
70 $stmt = __METHOD__.
".$arsTableName";
72 if (!empty($status)) {
75 $statusClause =
", ars_status = $".count($parms);
83 ars_endtime=now() $statusClause 88 "INSERT INTO $arsTableName(agent_fk,upload_fk) 89 VALUES ($1,$2) RETURNING ars_pk",
90 array($agentId, $uploadId),
91 __METHOD__.
".update.".$arsTableName);
93 return $row[
'ars_pk'];
100 public function getCurrentAgentId($agentName, $agentDesc=
"", $agentRev=
"")
103 "SELECT agent_pk FROM agent WHERE agent_name = $1 order by agent_ts desc limit 1",
104 array($agentName), __METHOD__.
"select" 107 if ($row ===
false) {
109 "INSERT INTO agent(agent_name,agent_desc,agent_rev) VALUES ($1,$2,$3) RETURNING agent_pk",
110 array($agentName, $agentDesc, $agentRev), __METHOD__.
"insert" 112 return false !== $row ? intval($row[
'agent_pk']) : -1;
115 return intval($row[
'agent_pk']);
135 public function agentARSList($tableName, $uploadId, $limit = 1, $agentId = 0, $agentSuccess =
true)
138 if (!$this->
dbManager->existsTable($tableName)) {
142 $arguments = array($uploadId);
143 $statementName = __METHOD__ . $tableName;
144 $sql =
"SELECT * FROM $tableName, agent WHERE agent_pk=agent_fk AND upload_fk=$1 AND agent_enabled";
146 $arguments[] = $agentId;
147 $sql .=
' AND agent_fk=$'.count($arguments);
148 $statementName .=
".agent";
151 $sql .=
" AND ars_success";
152 $statementName .=
".suc";
154 $sql .=
" ORDER BY agent_ts DESC";
156 $arguments[] = $limit;
157 $sql .=
' limit $'.count($arguments);
158 $statementName .=
".lim";
160 $this->
dbManager->prepare($statementName,$sql);
161 $result = $this->
dbManager->execute($statementName, $arguments);
162 $resultArray = $this->
dbManager->fetchAll($result);
178 $listOfAllJobs = $this->
agentARSList($arsTableName, $uploadId, 0, 0,
false);
180 $listOfRunningAgents = array();
182 if ($listOfAllJobs !==
false) {
183 foreach ($listOfAllJobs as $job) {
184 if ($job [
'ars_success'] === $this->
dbManager->booleanToDb(
true)) {
187 $listOfRunningAgents[] = intval($job[
'agent_fk']);
190 return $listOfRunningAgents;
193 public function getLatestAgentResultForUpload($uploadId, $agentNames)
195 $latestScannerProxy = new \Fossology\Lib\Proxy\LatestScannerProxy($uploadId, $agentNames,
"latest_scanner$uploadId");
197 $agentLatestMap = $latestScannerProxy->getNameToIdMap();
199 return $agentLatestMap;
208 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev from agent WHERE agent_enabled AND agent_name=$1 " 209 .
"ORDER BY agent_pk DESC LIMIT 1", array($agentName));
220 $stmt = __METHOD__ .
".getAgent.$agentName";
222 $sql =
"SELECT agent_pk,agent_rev,agent_name FROM agent LEFT JOIN " . $this->
getArsTableName($agentName) .
" ON agent_fk=agent_pk " 223 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success " 224 .
"ORDER BY agent_pk DESC");
225 $res = $this->
dbManager->execute($stmt, array($uploadId, $agentName));
227 while ($row = $this->
dbManager->fetchArray($res)) {
241 $stmt = __METHOD__ .
".getAgent.$scannerName";
243 $sql =
"SELECT agent_pk AS agent_id,agent_rev,agent_name " 244 .
"FROM agent LEFT JOIN $scannerName" . self::ARS_TABLE_SUFFIX .
" ON agent_fk=agent_pk " 245 .
"WHERE agent_name=$2 AND agent_enabled AND upload_fk=$1 AND ars_success " 246 .
"ORDER BY agent_id DESC");
247 $res = $this->
dbManager->execute($stmt, array($uploadId, $scannerName));
248 $agents = $this->
dbManager->fetchAll($res);
259 return new AgentRef(intval($row[
'agent_pk']), $row[
'agent_name'], $row[
'agent_rev']);
268 return $agentName . self::ARS_TABLE_SUFFIX;
278 $row = $this->
dbManager->getSingleRow(
"SELECT agent_pk, agent_name, agent_rev, agent_desc FROM agent " 279 .
"WHERE agent_enabled AND agent_name=$1 ORDER BY agent_pk DESC LIMIT 1", array($agentName),__METHOD__.
'.get');
280 $this->
dbManager->getSingleRow(
"UPDATE agent SET agent_rev=agent_rev||'.'||substr(md5(agent_ts::text),0,6) " 281 .
"WHERE agent_pk=$1",array($row[
'agent_pk']),__METHOD__.
'.upd');
282 unset($row[
'agent_pk']);
283 $this->
dbManager->insertTableRow(
'agent',$row);
294 $row = $this->
dbManager->getSingleRow(
"SELECT agent_name FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
295 return ($row===
false)?
false:$row[
'agent_name'];
304 $row = $this->
dbManager->getSingleRow(
"SELECT agent_rev FROM agent WHERE agent_enabled AND agent_pk=$1", array($agentId));
305 return ($row===
false)?
false:$row[
'agent_rev'];
renewCurrentAgent($agentName)
getSuccessfulAgentRuns($agentName, $uploadId)
getSuccessfulAgentEntries($scannerName, $uploadId)
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...
getRunningAgentIds($uploadId, $agentName)
Returns the list of running or failed agent_pk s. Before latest successful run.
__construct(DbManager $dbManager, Logger $logger)
fo_dbManager * dbManager
fo_dbManager object
getArsTableName($agentName)
getCurrentAgentRef($agentName)