14 #include "libfossscheduler.h"
15 #include "libfossdb.h"
37 int should_connect_to_db = 1;
42 WHERE agent_name = '%s' AND agent_rev='%s.%s'";
46 INSERT INTO agent (agent_name, agent_rev, agent_desc) \
47 VALUES ('%s', '%s.%s', '%s')";
96 PGresult* db_result = NULL;
102 db_result = PQexec(
db_conn, db_sql);
103 if (PQresultStatus(db_result) != PGRES_TUPLES_OK)
105 fprintf(stderr,
"FATAL %s.%d: unable to check agent table: %s",
106 __FILE__, __LINE__, PQresultErrorMessage(db_result));
114 if (PQntuples(db_result) != 1)
123 db_result = PQexec(
db_conn, db_sql);
124 if (PQresultStatus(db_result) != PGRES_COMMAND_OK)
126 fprintf(stderr,
"FATAL %s.%d: unable to insert into agent table: %s",
127 __FILE__, __LINE__, PQresultErrorMessage(db_result));
173 GError* error = NULL;
174 GOptionContext* parsed;
176 char fname[FILENAME_MAX + 1];
178 char* db_config = NULL;
179 char* db_error = NULL;
182 GOptionEntry options[] =
184 {
"config",
'c', 0, G_OPTION_ARG_STRING, &
sysconfigdir,
""},
185 {
"userID", 0, 0, G_OPTION_ARG_INT, &
userID,
""},
186 {
"groupID", 0, 0, G_OPTION_ARG_INT, &
groupID,
""},
187 {
"scheduler_start", 0, 0, G_OPTION_ARG_NONE, &
sscheduler,
""},
188 {
"jobId", 0, 0, G_OPTION_ARG_INT, &
jobId,
""},
205 LOG_WARNING(
"fo_scheduler_connect() has already been called.");
210 if (getenv(
"FO_SYSCONFDIR"))
214 parsed = g_option_context_new(
"");
215 g_option_context_add_main_entries(parsed, options, NULL);
216 g_option_context_set_ignore_unknown_options(parsed, TRUE);
217 g_option_context_set_help_enabled(parsed, FALSE);
218 g_option_context_parse(parsed, argc, &argv, NULL);
219 g_option_context_free(parsed);
224 snprintf(fname, FILENAME_MAX,
"%s/%s",
sysconfigdir,
"fossology.conf");
228 fprintf(stderr,
"FATAL %s.%d: unable to open system configuration: %s\n",
229 __FILE__, __LINE__, error->message);
233 snprintf(fname, FILENAME_MAX,
"%s/mods-enabled/%s/VERSION",
239 fprintf(stderr,
"FATAL %s.%d: unable to open VERSION configuration: %s\n",
240 __FILE__, __LINE__, error->message);
247 fprintf(stderr,
"FATAL %s.%d: unable to join configuration files: %s\n",
248 __FILE__, __LINE__, error->message);
257 if (
db_conn && should_connect_to_db)
259 db_config = g_strdup_printf(
"%s/Db.conf",
sysconfigdir);
262 *db_conf = db_config;
267 fprintf(stderr,
"FATAL %s.%d: unable to open database connection: %s\n",
268 __FILE__, __LINE__, db_error);
282 fprintf(stdout,
"VERSION: %s\n",
284 else fprintf(stdout,
"VERSION: unknown\n");
285 fprintf(stdout,
"\nOK\n");
333 PGconn* dbConnection;
335 *
dbManager = fo_dbManager_new_withConf(dbConnection, dbConf);
354 fprintf(stdout,
"\nBYE %d\n", retcode);
409 printf(
"\nNOTE: received %s\n",
buffer);
410 if (strncmp(
buffer,
"CLOSE", 5) == 0)
412 if (strncmp(
buffer,
"END", 3) == 0)
414 fprintf(stdout,
"\nOK\n");
420 else if (strncmp(
buffer,
"VERBOSE", 7) == 0)
426 else if (strncmp(
buffer,
"VERSION", 7) == 0)
429 fprintf(stdout,
"VERSION: %s\n",
431 else fprintf(stdout,
"VERSION: unknown\n");
475 fprintf(stdout,
"SPECIAL: %d %d\n", option, value);
495 fprintf(stdout,
"GETSPECIAL: %d\n", option);
498 if (fscanf(stdin,
"VALUE: %d\n", &value) != 1)
545 GError* error = NULL;
559 g_clear_error(&error);
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
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,...
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.
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.
FOSSology library to read config file.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
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...
int groupID
The id of the group of the user that created the job.
void fo_heartbeat()
Internal function to send a heartbeat to the scheduler along with the number of items processed.
volatile int alive
If the agent has updated with a hearbeat.
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.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int jobId
The id of the job.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
int fo_scheduler_get_special(int option)
Gets if a particular special attribute is set in the scheduler.
static const char * sql_insert
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.
char * module_name
The name of the agent.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
static const char * sql_check
Default: connect to DB unless explicitly disabled.
char * fo_scheduler_current()
Get the last read string from the scheduler.
GRegex * fo_conf_parse
Regex for parsing.
int fo_scheduler_jobId()
Gets the id of the job that the agent is running.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
int sscheduler
Whether the agent was started by the scheduler.
GRegex * fo_conf_replace
Regex for replace.
int userID
The id of the user that created the job.
void fo_scheduler_connect_conf(int *argc, char **argv, PGconn **db_conn, char **db_conf)
Establish a connection between an agent and the scheduler.
void fo_check_agentdb(PGconn *db_conn)
Checks that the agent is already in the agent table.
int valid
If the information stored in buffer is valid.
char buffer[2048]
The last thing received from the scheduler.
fo_dbManager * dbManager
fo_dbManager object
PGconn * db_conn
The connection to Database.
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...