FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
job.h
1 /* **************************************************************
2 Copyright (C) 2010-2013 Hewlett-Packard Development Company, L.P.
3 Copyright (C) 2015 Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 ************************************************************** */
18 
19 #ifndef JOB_H_INCLUDE
20 #define JOB_H_INCLUDE
21 
22 /* local includes */
23 #include <logging.h>
24 
25 /* std library includes */
26 #include <stdio.h>
27 #include <event.h>
28 #include <libpq-fe.h>
29 
30 /* glib includes */
31 #include <glib.h>
32 
33 /* ************************************************************************** */
34 /* **** Data Types ********************************************************** */
35 /* ************************************************************************** */
36 
37 #define JOB_STATUS_TYPES(apply) \
38  apply(NOT_AVAILABLE) \
39  \
40  apply(CHECKEDOUT) \
41  \
42  apply(STARTED) \
43  \
44  apply(COMPLETE) \
45  \
46  apply(RESTART) \
47  \
48  apply(FAILED) \
49  \
50  apply(PAUSED)
51 
52 #define SELECT_ENUM(passed) JB_##passed,
53 typedef enum { JOB_STATUS_TYPES(SELECT_ENUM) } job_status;
54 #undef SELECT_ENUM
55 
56 extern const char* job_status_strings[];
57 
61 typedef struct
62 {
63  /* associated agent information */
64  char* agent_type;
65  char* required_host;
66  GList* running_agents;
67  GList* finished_agents;
68  GList* failed_agents;
70 
71  /* information for data manipulation */
72  job_status status;
73  gchar* data;
74  gchar *jq_cmd_args;
75  PGresult* db_result;
76  GMutex* lock;
77  uint32_t idx;
78 
79  /* information about job status */
80  gchar* message;
81  int32_t priority;
82  int32_t verbose;
83  int32_t parent_id;
84  int32_t id;
85  int32_t user_id;
86  int32_t group_id;
87 } job_t;
88 
89 /* ************************************************************************** */
90 /* **** Constructor Destructor ********************************************** */
91 /* ************************************************************************** */
92 
93 job_t* job_init(GTree* job_list, GSequence* job_queue, char* type, char* host,
94  int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args);
95 void job_destroy(job_t* job);
96 
97 /* ************************************************************************** */
98 /* **** Functions and events ************************************************ */
99 /* ************************************************************************** */
100 
101 void job_verbose_event (scheduler_t* scheduler, job_t* j);
102 void job_status_event (scheduler_t* scheduler, arg_int* params);
103 void job_pause_event (scheduler_t* scheduler, arg_int* params);
104 void job_restart_event (scheduler_t* scheduler, arg_int* params);
105 void job_priority_event(scheduler_t* scheduler, arg_int* params);
106 void job_fail_event (scheduler_t* scheduler, job_t* job);
107 
108 void job_add_agent(job_t* job, void* a);
109 void job_remove_agent(job_t* job, GTree* job_list, void* a);
110 void job_finish_agent(job_t* job, void* a);
111 void job_fail_agent(job_t* job, void* a);
112 void job_set_data(scheduler_t* scheduler, job_t* job, char* data, int sql);
113 void job_update(scheduler_t* scheduler, job_t* job);
114 
115 gboolean job_is_open(scheduler_t* scheduler, job_t* job);
116 gchar* job_next(job_t* job);
117 log_t* job_log(job_t* job);
118 
119 /* ************************************************************************** */
120 /* **** Job list Functions ************************************************** */
121 /* ************************************************************************** */
122 
123 job_t* next_job(GSequence* job_queue);
124 job_t* peek_job(GSequence* job_queue);
125 uint32_t active_jobs(GTree* job_list);
126 
127 #endif /* JOB_H_INCLUDE */
void job_verbose_event(scheduler_t *scheduler, job_t *job)
Definition: job.c:255
GMutex * lock
Lock to maintain data integrity.
Definition: job.h:76
int job_is_open(scheduler_t *scheduler, job_t *job)
Tests to see if there is still data available for this job.
Definition: job.c:581
int32_t user_id
The id of the user that created the job.
Definition: job.h:85
void job_fail_agent(job_t *job, void *agent)
Definition: job.c:504
void job_pause_event(scheduler_t *scheduler, arg_int *params)
Event to pause a job.
Definition: job.c:323
Definition: logging.h:45
gchar * jq_cmd_args
Command line arguments for this job.
Definition: job.h:74
int32_t verbose
The verbose level for all of the agents in this job.
Definition: job.h:82
int32_t priority
Importance of the job, maps directory to unix priority.
Definition: job.h:81
PGresult * db_result
Results from the sql query (if any)
Definition: job.h:75
Log related operations.
void job_set_data(scheduler_t *scheduler, job_t *job, char *data, int sql)
Definition: job.c:522
char * required_host
If not NULL, this job must run on a specific host machine.
Definition: job.h:65
log_t * job_log(job_t *job)
Definition: job.c:648
char * job_next(job_t *job)
Definition: job.c:621
uint32_t active_jobs(GTree *job_list)
Gets the number of jobs that are not paused.
Definition: job.c:731
void job_destroy(job_t *job)
Definition: job.c:212
void job_remove_agent(job_t *job, GTree *job_list, void *agent)
Definition: job.c:460
job_t * peek_job(GSequence *job_queue)
Gets the job that is at the top of the queue if there is one.
Definition: job.c:712
void job_restart_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:353
void job_update(scheduler_t *scheduler, job_t *job)
Definition: job.c:542
GList * running_agents
The list of agents assigned to this job that are still working.
Definition: job.h:66
#define SELECT_ENUM(passed)
Definition: agent.h:76
char * agent_type
The type of agent used to analyze the data.
Definition: job.h:64
job_t * next_job(GSequence *job_queue)
Gets the next job from the job queue.
Definition: job.c:692
void job_add_agent(job_t *job, void *agent)
Adds a new agent to the jobs list of agents.
Definition: job.c:445
void job_finish_agent(job_t *job, void *agent)
Definition: job.c:489
int32_t parent_id
The identifier for the parent of this job (its queue id)
Definition: job.h:83
GList * finished_agents
The list of agents that have completed their tasks.
Definition: job.h:67
gchar * data
The data associated with this job (jq_args)
Definition: job.h:73
int32_t group_id
The id of the group that created the job.
Definition: job.h:86
Event handling operations.
gchar * message
Message that will be sent with job notification email.
Definition: job.h:80
The job structure.
Definition: job.h:61
log_t * log
The log to print any agent logging messages to.
Definition: job.h:69
Definition: event.h:56
void job_priority_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:396
void job_status_event(scheduler_t *scheduler, arg_int *params)
Event to get the status of the scheduler or a specific job.
Definition: job.c:277
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.
Definition: job.c:175
job_status status
The current status for the job.
Definition: job.h:72
uint32_t idx
The current index into the sql results.
Definition: job.h:77
void job_fail_event(scheduler_t *scheduler, job_t *job)
Events that causes a job to be marked a failed.
Definition: job.c:417
GList * failed_agents
The list of agents that failed while working.
Definition: job.h:68
int32_t id
The identifier for this job.
Definition: job.h:84