28 #include <scheduler.h> 59 void create_pipe(
int* int_dst,
int* int_src, FILE** file_dst, FILE** file_src)
66 if(int_dst) *int_dst = a_to_b[0];
67 if(int_src) *int_src = a_to_b[1];
69 if(file_dst) *file_dst = fdopen(a_to_b[0],
"r");
70 if(file_src) *file_src = fdopen(a_to_b[1],
"w");
89 char* name =
"copyright";
96 FO_ASSERT_PTR_NOT_NULL_FATAL(ma);
97 FO_ASSERT_STRING_EQUAL(ma->
name,
"copyright");
98 FO_ASSERT_STRING_EQUAL(ma->
raw_cmd,
"copyright --scheduler_start");
99 FO_ASSERT_EQUAL(ma->
max_run, max);
100 FO_ASSERT_EQUAL(ma->
special, spc);
101 FO_ASSERT_PTR_NULL(ma->
version);
102 FO_ASSERT_TRUE(ma->
valid);
126 ma = g_tree_lookup(scheduler->
meta_agents,
"name");
127 FO_ASSERT_EQUAL(g_tree_nnodes(scheduler->
meta_agents), 1);
128 FO_ASSERT_PTR_NOT_NULL(ma);
129 FO_ASSERT_STRING_EQUAL(ma->
name,
"name");
130 FO_ASSERT_STRING_EQUAL(ma->
raw_cmd,
"cmd --scheduler_start");
131 FO_ASSERT_EQUAL(ma->
max_run, 11);
132 FO_ASSERT_EQUAL(ma->
special, 1);
133 FO_ASSERT_PTR_NULL(ma->
version);
134 FO_ASSERT_TRUE(ma->
valid);
191 fagent.
owner = &fjob;
192 fagent.
status = AG_CREATED;
201 pid_set = g_new0(
int, 2);
202 pid_set[0] = fagent.
pid;
207 a1 = g_tree_lookup(scheduler->
agents, &fagent.
pid);
209 FO_ASSERT_EQUAL(fagent.
status, AG_CREATED);
210 FO_ASSERT_PTR_NULL(a1);
214 fclose(fagent.
write);
239 static int32_t id_gen = -1;
247 for(iter = scheduler->
host_queue; iter != NULL; iter = iter->next)
249 host = (
host_t*)iter->data;
251 host->
name, id_gen--, 0, 0, 0, 0, NULL);
255 fagent->
owner = fjob;
256 fagent->
status = AG_CREATED;
261 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
264 FO_ASSERT_PTR_NOT_NULL(ag);
265 FO_ASSERT_PTR_NOT_NULL(gl);
266 FO_ASSERT_EQUAL(fagent->
status, AG_SPAWNED);
267 FO_ASSERT_PTR_EQUAL(ag, gl->
data);
270 FO_ASSERT_EQUAL(fagent->
status, AG_PAUSED);
272 FO_ASSERT_EQUAL(fagent->
status, AG_RUNNING);
278 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
280 FO_ASSERT_PTR_NOT_NULL(ag);
281 FO_ASSERT_EQUAL(fagent->
status, AG_PAUSED);
285 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
287 FO_ASSERT_PTR_NOT_NULL(ag);
288 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
292 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
293 FO_ASSERT_PTR_NOT_NULL(ag);
294 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
296 pid_set = g_new0(
int, 2);
297 pid_set[0] = fagent->
pid;
303 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
305 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
306 FO_ASSERT_PTR_NULL(ag);
322 static int32_t id_gen = -1;
330 for(iter = scheduler->
host_queue; iter != NULL; iter = iter->next)
332 host = (
host_t*)iter->data;
334 host->
name, id_gen--, 0, 0, 0, 0, NULL);
336 FO_ASSERT_PTR_NOT_NULL(fagent);
356 CU_TestInfo tests_meta_agent[] =
364 CU_TestInfo tests_agent[] =
void scheduler_close_event(scheduler_t *scheduler, void *killed)
Sets the closing flag and possibly kills all currently running agents.
meta_agent_t * meta_agent_init(char *name, char *cmd, int max, int spc)
Creates a new meta agent.
GTree * meta_agents
List of all meta agents available to the scheduler.
int add_meta_agent(GTree *meta_agents, char *name, char *cmd, int max, int spc)
void create_pipe(int *int_dst, int *int_src, FILE **file_dst, FILE **file_src)
Creates 2 pipes and initialize parameters.
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
void agent_death_event(scheduler_t *scheduler, pid_t *pid)
GList * host_queue
Round-robin queue for choosing which host use next.
GSequence * job_queue
heap of jobs that still need to be started
void agent_fail_event(scheduler_t *scheduler, agent_t *agent)
Fails an agent.
char * name
The name of the host, used to store host internally to scheduler.
int to_parent
file identifier to print to the parent (child stdout)
GTree * job_list
List of jobs that have been created.
agent_t * agent_init(scheduler_t *scheduler, host_t *host, job_t *job)
Allocate and spawn a new agent.
void agent_ready_event(scheduler_t *scheduler, agent_t *agent)
Event created when an agent is ready for more data.
uint8_t return_code
what was returned by the agent when it disconnected
FILE * write
FILE* that abstracts the use of the to_child socket.
agent_status status
the state of execution the agent is currently in
void test_agent_init()
Test for agent_init()
void test_agent_death_event()
Test for agent_death_event()
void test_add_meta_agent()
Test for add_meta_agent()
void agent_create_event(scheduler_t *scheduler, agent_t *agent)
Event created when a new agent has been created.
GList * running_agents
The list of agents assigned to this job that are still working.
void scheduler_agent_config(scheduler_t *scheduler)
Loads a particular agents configuration file.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
void test_meta_agent_init()
Test for meta_agent_init()
void agent_unpause(agent_t *agent)
void agent_pause(agent_t *agent)
GTree * agents
List of any currently running agents.
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
int from_child
file identifier to read from child
void agent_update_event(scheduler_t *scheduler, void *unused)
pid_t pid
the pid of the process this agent is running in
Header file with agent related operations.
void scheduler_config_event(scheduler_t *scheduler, void *unused)
Load both the fossology configuration and all the agent configurations.
void test_agent_create_event()
Test for agent_create_event()
job_t * job_init(GTree *job_list, GSequence *job_queue, char *type, char *host, int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args)
Create a new job.
gchar * data
the data that has been sent to the agent for analysis
job_status status
The current status for the job.
GList * failed_agents
The list of agents that failed while working.
job_t * owner
the job that this agent is assigned to
int32_t id
The identifier for this job.