26 #include "libfossscheduler.h" 27 #include "libfossdb.h" 53 WHERE agent_name = '%s' AND agent_rev='%s.%s'";
57 INSERT INTO agent (agent_name, agent_rev, agent_desc) \ 58 VALUES ('%s', '%s.%s', '%s')";
91 fprintf(stdout,
"HEART: %d %d\n", processed,
alive);
107 PGresult* db_result = NULL;
113 db_result = PQexec(db_conn, db_sql);
114 if (PQresultStatus(db_result) != PGRES_TUPLES_OK)
116 fprintf(stderr,
"FATAL %s.%d: unable to check agent table: %s",
117 __FILE__, __LINE__, PQresultErrorMessage(db_result));
125 if (PQntuples(db_result) != 1)
134 db_result = PQexec(db_conn, db_sql);
135 if (PQresultStatus(db_result) != PGRES_COMMAND_OK)
137 fprintf(stderr,
"FATAL %s.%d: unable to insert into agent table: %s",
138 __FILE__, __LINE__, PQresultErrorMessage(db_result));
184 GError* error = NULL;
185 GOptionContext* parsed;
187 char fname[FILENAME_MAX + 1];
189 char* db_config = NULL;
190 char* db_error = NULL;
193 GOptionEntry options[] =
195 {
"config",
'c', 0, G_OPTION_ARG_STRING, &
sysconfigdir,
""},
196 {
"userID", 0, 0, G_OPTION_ARG_INT, &
userID,
""},
197 {
"groupID", 0, 0, G_OPTION_ARG_INT, &
groupID,
""},
198 {
"scheduler_start", 0, 0, G_OPTION_ARG_NONE, &
sscheduler,
""},
199 {
"jobId", 0, 0, G_OPTION_ARG_INT, &
jobId,
""},
214 if (sysconfig != NULL)
216 LOG_WARNING(
"fo_scheduler_connect() has already been called.");
221 if (getenv(
"FO_SYSCONFDIR"))
225 parsed = g_option_context_new(
"");
226 g_option_context_add_main_entries(parsed, options, NULL);
227 g_option_context_set_ignore_unknown_options(parsed, TRUE);
228 g_option_context_set_help_enabled(parsed, FALSE);
229 g_option_context_parse(parsed, argc, &argv, NULL);
230 g_option_context_free(parsed);
235 snprintf(fname, FILENAME_MAX,
"%s/%s",
sysconfigdir,
"fossology.conf");
239 fprintf(stderr,
"FATAL %s.%d: unable to open system configuration: %s\n",
240 __FILE__, __LINE__, error->message);
244 snprintf(fname, FILENAME_MAX,
"%s/mods-enabled/%s/VERSION",
250 fprintf(stderr,
"FATAL %s.%d: unable to open VERSION configuration: %s\n",
251 __FILE__, __LINE__, error->message);
258 fprintf(stderr,
"FATAL %s.%d: unable to join configuration files: %s\n",
259 __FILE__, __LINE__, error->message);
270 db_config = g_strdup_printf(
"%s/Db.conf",
sysconfigdir);
273 *db_conf = db_config;
278 fprintf(stderr,
"FATAL %s.%d: unable to open database connection: %s\n",
279 __FILE__, __LINE__, db_error);
293 fprintf(stdout,
"VERSION: %s\n",
295 else fprintf(stdout,
"VERSION: unknown\n");
296 fprintf(stdout,
"\nOK\n");
344 PGconn* dbConnection;
346 *dbManager = fo_dbManager_new_withConf(dbConnection, dbConf);
365 fprintf(stdout,
"\nBYE %d\n", retcode);
420 printf(
"\nNOTE: received %s\n",
buffer);
421 if (strncmp(
buffer,
"CLOSE", 5) == 0)
423 if (strncmp(
buffer,
"END", 3) == 0)
425 fprintf(stdout,
"\nOK\n");
431 else if (strncmp(
buffer,
"VERBOSE", 7) == 0)
437 else if (strncmp(
buffer,
"VERSION", 7) == 0)
440 fprintf(stdout,
"VERSION: %s\n",
442 else fprintf(stdout,
"VERSION: unknown\n");
486 fprintf(stdout,
"SPECIAL: %d %d\n", option, value);
506 fprintf(stdout,
"GETSPECIAL: %d\n", option);
509 if (fscanf(stdin,
"VALUE: %d\n", &value) != 1)
556 GError* error = NULL;
570 g_clear_error(&error);
void fo_config_join(fo_conf *dst, fo_conf *src, GError **error)
Takes all groups and key from a fo_conf and adds them to another.
volatile int alive
If the agent has updated with a hearbeat.
FOSSology library to read config file.
void fo_heartbeat()
Internal function to send a heartbeat to the scheduler along with the number of items processed...
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
int userID
The id of the user that created the job.
int valid
If the information stored in buffer is valid.
char * fo_scheduler_current()
Get the last read string from the scheduler.
void fo_scheduler_connect_conf(int *argc, char **argv, PGconn **db_conn, char **db_conf)
Establish a connection between an agent and the scheduler.
int jobId
The id of the job.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
int sscheduler
Whether the agent was started by the scheduler.
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.
static const char * sql_insert
volatile gint items_processed
The number of items processed by the agent.
void fo_scheduler_set_special(int option, int value)
Sets something special about the agent within the scheduler.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
int fo_config_has_key(fo_conf *conf, char *group, char *key)
Checks if the a specific group in the currently parsed configuration file has a specific key...
GRegex * fo_conf_parse
Regex for parsing.
GRegex * fo_conf_replace
Regex for replace.
int fo_scheduler_get_special(int option)
Gets if a particular special attribute is set in the scheduler.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
static const char * sql_check
int groupID
The id of the group of the user that created the job.
char buffer[2048]
The last thing received from the scheduler.
fo_dbManager * dbManager
fo_dbManager object
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. ...
int fo_scheduler_jobId()
Gets the id of the job that the agent is running.
char * module_name
The name of the agent.
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
PGconn * db_conn
The connection to Database.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
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 th...
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
void fo_check_agentdb(PGconn *db_conn)
Checks that the agent is already in the agent table.
FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk)
Has this pfile or uploadtree_pk already been bucket processed? This only works if the bucket has been...
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.