2
Copyright (C) 2003 by Sean David Fleming
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
The GNU GPL can also be found at http://www.gnu.org
35
/* top level data structure */
36
extern struct sysenv_pak sysenv;
38
/* the essential aim of the job structure is simply to establish a link between
39
input/ouput file pairs (local <-> remote) so that jobs can be tracked/updated.
40
NB: Place each remotely executed job in its own directory ( job1 job2 etc ) and give
41
the user an option to copy ALL files in that directory back to the local machine
42
(by default copy only the output file) This way we get addition data
43
such as e density and anything else copied back if desired ... possible refinements
44
include a list of all files with size and type that user can check/uncheck as
45
transaction transfers ... binary files may be a problem */
65
/**********************/
66
/* free job structure */
67
/**********************/
68
void job_free(struct job_pak *job)
70
g_free(job->local_dir);
71
g_free(job->local_input);
72
g_free(job->local_output);
73
g_free(job->remote_dir);
74
g_free(job->remote_input);
75
g_free(job->remote_output);
79
/******************************/
80
/* initialize a job structure */
81
/******************************/
82
gpointer job_setup(const gchar *name, struct model_pak *model)
87
job = g_malloc(sizeof(struct job_pak));
89
/* use this to give unique job names (within cwd of an ssh session) */
90
/* since the cwd is date/time based we wont get overwrites */
93
job->local_dir = NULL;
94
job->local_input = NULL;
95
job->local_output = NULL;
96
job->remote_dir = NULL;
97
job->remote_input = NULL;
98
job->remote_output = NULL;
100
if (g_ascii_strncasecmp("gulp", name, 4) == 0)
101
job->type = JOB_GULP;
106
job->local_dir = g_strdup(sysenv.cwd);
107
job->local_input = g_strdup(model->gulp.temp_file);
108
job->local_output = g_strdup(model->gulp.out_file);
110
/* FIXME - filename is not the full path name ... which strictly it should be */
111
/* however - job->local_input is expected to contain only the filename (without */
112
/* the path) by the subsequent job_start() call */
113
write_gulp(job->local_input, model);
118
printf("Error: unknown job type: %s\n", name);
126
/********************************/
127
/* begin the execution of a job */
128
/********************************/
129
#define DEBUG_JOB_START 1
130
void job_start(gpointer host, gpointer data)
133
struct job_pak *job = data;
135
/* assign host to job, and initialize */
137
job->remote_dir = g_strdup(host_cwd(host));
139
/* build full path remote names */
140
job->remote_input = g_build_filename(job->remote_dir, job->local_input, NULL);
141
job->remote_output = g_build_filename(job->remote_dir, job->local_output, NULL);
143
/* convert local names to full path names */
144
tmp = g_build_filename(job->local_dir, job->local_input, NULL);
145
g_free(job->local_input);
146
job->local_input = tmp;
148
tmp = g_build_filename(job->local_dir, job->local_output, NULL);
149
g_free(job->local_output);
150
job->local_output = tmp;
153
printf("local dir: %s\n", job->local_dir);
154
printf("local inp: %s\n", job->local_input);
155
printf("local out: %s\n", job->local_output);
156
printf("remote dir: %s\n", job->remote_dir);
157
printf("remote inp: %s\n", job->remote_input);
158
printf("remote out: %s\n", job->remote_output);
161
host_file_write(host, job->local_input, job->remote_input);
164
/* TODO - execute ... bg or queued ... on remote host */
169
/***************************/
170
/* create a new job object */
171
/***************************/
172
gint job_new(const gchar *name, struct model_pak *model)
174
gpointer host, service, job;
176
if (!sysenv.host_list)
178
printf("No active connections.\n");
181
host = sysenv.host_list->data;
183
service = host_service_get(host, name);
186
printf("Unknown service: %s.\n", name);
190
if (!host_service_available(service))
192
printf("Service: %s not available on active host.\n", name);
196
printf("Requesting service: %s on host %s\n", name, host_name(host));
198
job = job_setup(name, model);
200
/* TODO - put elsewhere (some sort of scheduler decides the host part?) */
201
job_start(host, job);
204
/* TODO - this'll get placed in job cleanup when jobs are actually run */
211
/********************************/
212
/* check on the status of a job */
213
/********************************/
214
void job_status_get(gpointer data)
216
struct job_pak *job = data;
218
g_assert(job != NULL);
220
/* TODO - more than one way of doing this ... eg could have qstat for queued jobs */
221
/* etc ... scanning output is more portable ... but wont determine if a job has crashed */
223
/* could record the last time the output file had new stuff added ... */
225
/* get output file */
226
host_file_read(job->host, job->local_output, job->remote_output);
233
/************************************/
234
/* eg use to kill/stop/restart jobs */
235
/************************************/
236
void job_status_set()