cctools
batch_job_internal.h
1 /*
2 Copyright (C) 2017- The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See the file COPYING for details.
5 */
6 
7 #ifndef BATCH_JOB_INTERNAL_H_
8 #define BATCH_JOB_INTERNAL_H_
9 
10 #include <sys/stat.h>
11 
12 #include <limits.h>
13 #include <stdlib.h>
14 
15 #include "batch_job.h"
16 #include "copy_stream.h"
17 #include "create_dir.h"
18 #include "unlink_recursive.h"
19 #include "hash_table.h"
20 #include "itable.h"
21 
22 #define BATCH_JOB_LINE_MAX 8192
23 
25  batch_queue_type_t type;
26  char typestr[128];
27 
28  int (*create) (struct batch_queue *Q);
29  int (*free) (struct batch_queue *Q);
30  int (*port) (struct batch_queue *Q);
31  void (*option_update) (struct batch_queue *Q, const char *what, const char *value); /* called when an option is changed */
32 
33  struct {
34  batch_job_id_t (*submit) (struct batch_queue *Q, const char *command, const char *inputs, const char *outputs, struct jx *env_list, const struct rmsummary *resources);
35  batch_job_id_t (*wait) (struct batch_queue *Q, struct batch_job_info *info, time_t stoptime);
36  int (*remove) (struct batch_queue *Q, batch_job_id_t id);
37  } job;
38 
39  struct {
40  int (*chdir) (struct batch_queue *q, const char *path);
41  int (*getcwd) (struct batch_queue *q, char *buf, size_t size);
42  int (*mkdir) (struct batch_queue *q, const char *path, mode_t mode, int recursive);
43  int (*putfile) (struct batch_queue *q, const char *lpath, const char *rpath);
44  int (*rename) (struct batch_queue *q, const char *lpath, const char *rpath);
45  int (*stat) (struct batch_queue *q, const char *path, struct stat *buf);
46  int (*unlink) (struct batch_queue *q, const char *path);
47  } fs;
48 };
49 
50 struct batch_queue {
51  batch_queue_type_t type;
52 
53  char logfile[PATH_MAX];
54  struct hash_table *options;
55  struct hash_table *features;
56  struct itable *job_table;
57  struct itable *output_table;
58  void *data; /* module user data */
59  const struct batch_queue_module *module;
60 };
61 
62 #define batch_queue_stub_create(name) static int batch_queue_##name##_create (struct batch_queue *Q) { return 0; }
63 #define batch_queue_stub_free(name) static int batch_queue_##name##_free (struct batch_queue *Q) { return 0; }
64 #define batch_queue_stub_port(name) static int batch_queue_##name##_port (struct batch_queue *Q) { return 0; }
65 #define batch_queue_stub_option_update(name) static void batch_queue_##name##_option_update (struct batch_queue *Q, const char *what, const char *value) { return; }
66 
67 #define batch_fs_stub_chdir(name) static int batch_fs_##name##_chdir (struct batch_queue *Q, const char *path) { return chdir(path); }
68 #define batch_fs_stub_getcwd(name) static int batch_fs_##name##_getcwd (struct batch_queue *Q, char *buf, size_t size) { getcwd(buf, size); return 0; }
69 #define batch_fs_stub_mkdir(name) static int batch_fs_##name##_mkdir (struct batch_queue *Q, const char *path, mode_t mode, int recursive) { if (recursive) return create_dir(path, mode); else return mkdir(path, mode); }
70 #define batch_fs_stub_putfile(name) static int batch_fs_##name##_putfile (struct batch_queue *Q, const char *lpath, const char *rpath) { return copy_file_to_file(lpath, rpath); }
71 #define batch_fs_stub_rename(name) static int batch_fs_##name##_rename (struct batch_queue *Q, const char *lpath, const char *rpath) { return create_dir_parents(rpath, 0755) && !rename(lpath, rpath) ? 0 : -1; }
72 #define batch_fs_stub_stat(name) static int batch_fs_##name##_stat (struct batch_queue *Q, const char *path, struct stat *buf) { return stat(path, buf); }
73 #define batch_fs_stub_unlink(name) static int batch_fs_##name##_unlink (struct batch_queue *Q, const char *path) { return unlink_recursive(path); }
74 
75 #endif
76 
77 /* vim: set noexpandtab tabstop=4: */
Definition: batch_job_internal.h:24
Batch job submission.
int64_t batch_job_id_t
An integer type indicating a unique batch job number.
Definition: batch_job.h:28
Create a new directory recursively.
batch_queue_type_t
Indicates which type of batch submission to use.
Definition: batch_job.h:34
Definition: rmsummary.h:26
Definition: batch_job_internal.h:50
A general purpose hash table.
JX value representing any expression type.
Definition: jx.h:117
Describes a batch job when it has completed.
Definition: batch_job.h:58
An integer-indexed hash table.