24 use Symfony\Component\DependencyInjection\ContainerBuilder;
26 require_once(dirname(dirname(__FILE__)).
"/common-cli.php");
32 define(
"ALARM_SECS", 30);
111 $this->agentVersion = $version;
113 $this->agentRev = $version.
".".$revision;
114 $this->agentArs = strtolower(
$agentName ) .
"_ars";
117 $GLOBALS[
'processed'] = 0;
118 $GLOBALS[
'alive'] =
false;
125 $this->
dbManager = $container->get(
'db.manager');
126 $this->agentDao =
$container->get(
'dao.agent');
128 $this->agentId = $this->agentDao->getCurrentAgentId($this->agentName, $this->agentDesc, $this->agentRev);
141 $schedulerHandledOpts =
"c:";
142 $schedulerHandledLongOpts = array(
"userID:",
"groupID:",
"jobId:",
"scheduler_start",
'config:');
144 $longOpts = array_merge($schedulerHandledLongOpts, $this->agentSpecifLongOptions);
147 $args = getopt($shortOpts, $longOpts);
151 $this->userId =
$args[
'userID'];
152 $this->groupId =
$args[
'groupID'];
155 unset (
$args[
'jobId']);
156 unset (
$args[
'userID']);
157 unset (
$args[
'groupID']);
164 pcntl_signal(SIGALRM,
function($signo)
189 echo
"HEART: $processed ".($alive ?
'1' :
'0').
"\n";
209 $processed += $newProcessed;
212 pcntl_signal_dispatch();
223 debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
225 throw new \Exception(
'agent fail in '.__FILE__.
':'.__LINE__,$exitvalue);
240 echo
"BYE $exitvalue\n";
251 echo
"VERSION: ".$this->agentVersion.
"\n";
260 if (!$this->agentDao->arsTableExists($this->agentName)) {
261 $this->agentDao->createArsTable($this->agentName);
286 ($line = fgets(STDIN));
287 if (
"CLOSE\n" === $line) {
290 if (
"END\n" === $line) {
316 $uploadId = intval($line);
317 if ($uploadId <= 0) {
321 $arsId = $this->agentDao->writeArsRecord($this->agentName, $this->agentId, $uploadId);
323 print
"cannot insert ars record";
330 print
"Caught exception while processing uploadId=$uploadId: ".$e->getMessage();
331 print $e->getTraceAsString();
335 $this->agentDao->writeArsRecord($this->agentName, $this->agentId, $uploadId, $arsId, $success);
338 print
"agent failed on uploadId=$uploadId";
Structure of an Agent with all required parameters.
scheduler_current()
Read the commands from scheduler.
__construct($agentName, $version, $revision)
run_scheduler_event_loop()
Runs a loop to read commands from scheduler and process them.
static heartbeat_handler($signo)
Function to handle hear beats from the agent and send them to the scheduler from STDOUT.
bail($exitvalue)
Bail the agent, print the stack and disconnect from scheduler.
heartbeat($newProcessed)
Send hear beat to the scheduler.
processUploadId($uploadId)
Given an upload ID, process the items in it.
scheduler_greet()
Greet the scheduler at the beginning of connection.
scheduler_disconnect($exitvalue)
Closes connection from scheduler.
scheduler_connect()
Connect with scheduler and initialize options.
initArsTable()
Initialize ARS table.
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
int jobId
The id of the job.
fo_dbManager * dbManager
fo_dbManager object