FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
Scheduler API for agents. More...
#include "libfossscheduler.h"
#include "libfossdb.h"
#include "fossconfig.h"
#include <stdio.h>
#include <getopt.h>
#include <libgen.h>
#include <glib.h>
Go to the source code of this file.
Functions | |
void | fo_heartbeat () |
Internal function to send a heartbeat to the scheduler along with the number of items processed. More... | |
void | fo_check_agentdb (PGconn *db_conn) |
Checks that the agent is already in the agent table. More... | |
void | fo_scheduler_heart (int i) |
This function must be called by agents to let the scheduler know they are alive and how many items they have processed. More... | |
void | fo_scheduler_connect_conf (int *argc, char **argv, PGconn **db_conn, char **db_conf) |
Establish a connection between an agent and the scheduler. More... | |
void | fo_scheduler_connect (int *argc, char **argv, PGconn **db_conn) |
Establish a connection between an agent and the scheduler. More... | |
void | fo_scheduler_connect_dbMan (int *argc, char **argv, fo_dbManager **dbManager) |
Make a connection from an agent to the scheduler and create a DB manager as well. More... | |
void | fo_scheduler_disconnect (int retcode) |
Disconnect the scheduler connection. More... | |
char * | fo_scheduler_next () |
Get the next data to process from the scheduler. More... | |
char * | fo_scheduler_current () |
Get the last read string from the scheduler. More... | |
void | fo_scheduler_set_special (int option, int value) |
Sets something special about the agent within the scheduler. More... | |
int | fo_scheduler_get_special (int option) |
Gets if a particular special attribute is set in the scheduler. More... | |
int | fo_scheduler_jobId () |
Gets the id of the job that the agent is running. More... | |
int | fo_scheduler_userID () |
Gets the id of the user that created the job that the agent is running. More... | |
int | fo_scheduler_groupID () |
Gets the id of the group that created the job that the agent is running. More... | |
char * | fo_sysconfig (const char *sectionname, const char *variablename) |
gets a system configuration variable from the configuration data. More... | |
Variables | |
volatile gint | items_processed |
The number of items processed by the agent. | |
volatile int | alive |
If the agent has updated with a hearbeat. | |
char | buffer [2048] |
The last thing received from the scheduler. | |
int | valid |
If the information stored in buffer is valid. | |
int | sscheduler |
Whether the agent was started by the scheduler. | |
int | userID |
The id of the user that created the job. | |
int | groupID |
The id of the group of the user that created the job. | |
int | jobId |
The id of the job. | |
char * | module_name = NULL |
The name of the agent. | |
static const char * | sql_check |
static const char * | sql_insert |
fo_conf * | sysconfig = NULL |
char * | sysconfigdir = NULL |
GRegex * | fo_conf_parse |
Regex for parsing. | |
GRegex * | fo_conf_replace |
Regex for replace. | |
int | agent_verbose |
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level for a particular agent. All agents should use this flag for verbose instead of one declared within the agent. This can be set by the scheduler to enable different levels of verbose. More... | |
Scheduler API for agents.
Definition in file libfossscheduler.c.
void fo_check_agentdb | ( | PGconn * | db_conn | ) |
Checks that the agent is already in the agent table.
This uses the VERSION and COMMIT_HASH in the system configuration information to determine if a new agent record needs to be created for this agent in the database.
Definition at line 93 of file libfossscheduler.c.
void fo_heartbeat | ( | ) |
Internal function to send a heartbeat to the scheduler along with the number of items processed.
Definition at line 75 of file libfossscheduler.c.
void fo_scheduler_connect | ( | int * | argc, |
char ** | argv, | ||
PGconn ** | db_conn | ||
) |
Establish a connection between an agent and the scheduler.
Steps taken by this function:
Making a call to this function should be the first thing that an agent does after parsing its command line arguments.
If the database connection passed is NULL, then this will not return a database connection, and will not check the agent's database record.
argc | pointer to the number of arguments passed to the agent |
argv | the command line arguments for the agent |
db_conn | pointer to the location for the database connection |
Definition at line 319 of file libfossscheduler.c.
void fo_scheduler_connect_conf | ( | int * | argc, |
char ** | argv, | ||
PGconn ** | db_conn, | ||
char ** | db_conf | ||
) |
Establish a connection between an agent and the scheduler.
[in] | argc | Command line agrument count |
[in] | argv | Command line agrument vector |
[out] | db_conn | DB Connection |
[out] | db_conf | DB conf file |
Definition at line 169 of file libfossscheduler.c.
void fo_scheduler_connect_dbMan | ( | int * | argc, |
char ** | argv, | ||
fo_dbManager ** | dbManager | ||
) |
Make a connection from an agent to the scheduler and create a DB manager as well.
[out] | dbManager | New DB manager |
Definition at line 329 of file libfossscheduler.c.
char* fo_scheduler_current | ( | ) |
Get the last read string from the scheduler.
Definition at line 458 of file libfossscheduler.c.
void fo_scheduler_disconnect | ( | int | retcode | ) |
Disconnect the scheduler connection.
Making a call to this function should be the last thing that an agent does before exiting. Any error reporting to stdout or stderr will not work after this function has finished execution.
retcode | Return code to the scheduler |
Definition at line 346 of file libfossscheduler.c.
int fo_scheduler_get_special | ( | int | option | ) |
Gets if a particular special attribute is set in the scheduler.
Possible Options:
SPECIAL_NOKILL
: the agent will not be killed if it stops updating statusSPECIAL_EXCLUSIVE
: the agent cannot run simultaneously with any other agentSPECIAL_NOEMAIL
: the scheduler will not send notification emails for this agentSPECIAL_LOCAL
: the agent is required to run on the same machine as the scheduleroption | the relevant option to the get the value of |
Definition at line 490 of file libfossscheduler.c.
int fo_scheduler_groupID | ( | ) |
Gets the id of the group that created the job that the agent is running.
Definition at line 527 of file libfossscheduler.c.
void fo_scheduler_heart | ( | int | i | ) |
This function must be called by agents to let the scheduler know they are alive and how many items they have processed.
i | This is the number of itmes processed since the last call to fo_scheduler_heart() |
Definition at line 152 of file libfossscheduler.c.
int fo_scheduler_jobId | ( | ) |
Gets the id of the job that the agent is running.
Definition at line 507 of file libfossscheduler.c.
char* fo_scheduler_next | ( | ) |
Get the next data to process from the scheduler.
It is the job of the agent to decide how this string is interpreted.
Steps taken by this function:
Definition at line 400 of file libfossscheduler.c.
void fo_scheduler_set_special | ( | int | option, |
int | value | ||
) |
Sets something special about the agent within the scheduler.
Possible Options: SPECIAL_NOKILL
: instruct the scheduler to not kill the agent
option | the option to set |
value | whether to set the option to true or false |
Definition at line 472 of file libfossscheduler.c.
int fo_scheduler_userID | ( | ) |
Gets the id of the user that created the job that the agent is running.
Definition at line 517 of file libfossscheduler.c.
char* fo_sysconfig | ( | const char * | sectionname, |
const char * | variablename | ||
) |
gets a system configuration variable from the configuration data.
This function should be called after fo_scheduler_connect has been called. This is because the configuration data it not loaded until after that.
sectionname | the group of the variable |
variablename | the name of the variable |
Definition at line 542 of file libfossscheduler.c.
int agent_verbose |
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level for a particular agent. All agents should use this flag for verbose instead of one declared within the agent. This can be set by the scheduler to enable different levels of verbose.
Global verbose flags that agents should use instead of specific verbose flags. This is used by the scheduler to turn verbose on a particular agent on during run time. When the verbose flag is turned on by the scheduler the on_verbose function will be called. If nothing needs to be done when verbose is turned on, simply pass NULL to scheduler_connect
Definition at line 64 of file libfossscheduler.c.
|
static |
Check for an agent in DB
Definition at line 39 of file libfossscheduler.c.
|
static |
Insert new agent in DB
Definition at line 44 of file libfossscheduler.c.
fo_conf* sysconfig = NULL |
System configuration settings
Definition at line 49 of file libfossscheduler.c.
char* sysconfigdir = NULL |
System configuration directory
Definition at line 51 of file libfossscheduler.c.