forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_work.C
187 lines (178 loc) · 5.59 KB
/
create_work.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// The contents of this file are subject to the BOINC Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://boinc.berkeley.edu/license_1.0.txt
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
// create_work
// -appname name
// -wu_name name
// -wu_template filename
// -result_template filename
// -redundancy n
// -db_name x
// -db_passwd x
// -upload_url x
// -download_url x
// -download_dir x
// -rsc_fpops n
// -rsc_iops n
// -rsc_memory n
// -rsc_disk n
// -keyfile path
// -delay_bound x
// -sequence n
// infile1 infile2 ...
//
// Create a workunit and results.
// Input files must be in the download dir.
// template-doc is an XML WU description file, with the following macros:
// INFILEn gets replaced by the name of input file n
// MD5n gets replaced by the MD5 checksum of input file n
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "boinc_db.h"
#include "crypt.h"
#include "backend_lib.h"
int main(int argc, char** argv) {
DB_APP app;
DB_WORKUNIT wu;
int retval;
char wu_template[MAX_BLOB_SIZE];
char wu_template_file[256], result_template_file[256];
char keyfile[256];
char** infiles = NULL;
int i, ninfiles, redundancy, sequence=0;
R_RSA_PRIVATE_KEY key;
char download_dir[256], db_name[256], db_passwd[256];
char upload_url[256], download_url[256];
char buf[256];
strcpy(result_template_file, "");
strcpy(app.name, "");
strcpy(db_passwd, "");
strcpy(keyfile, "");
redundancy = 1;
i = 1;
ninfiles = 0;
wu.clear();
while (i < argc) {
if (!strcmp(argv[i], "-appname")) {
strcpy(app.name, argv[++i]);
} else if (!strcmp(argv[i], "-db_name")) {
strcpy(db_name, argv[++i]);
} else if (!strcmp(argv[i], "-db_passwd")) {
strcpy(db_passwd, argv[++i]);
} else if (!strcmp(argv[i], "-upload_url")) {
strcpy(upload_url, argv[++i]);
} else if (!strcmp(argv[i], "-download_url")) {
strcpy(download_url, argv[++i]);
} else if (!strcmp(argv[i], "-download_dir")) {
strcpy(download_dir, argv[++i]);
} else if (!strcmp(argv[i], "-wu_name")) {
strcpy(wu.name, argv[++i]);
} else if (!strcmp(argv[i], "-wu_template")) {
strcpy(wu_template_file, argv[++i]);
} else if (!strcmp(argv[i], "-result_template")) {
strcpy(result_template_file, argv[++i]);
} else if (!strcmp(argv[i], "-redundancy")) {
redundancy = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_fpops")) {
wu.rsc_fpops = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_iops")) {
wu.rsc_iops = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_memory")) {
wu.rsc_memory = atof(argv[++i]);
} else if (!strcmp(argv[i], "-rsc_disk")) {
wu.rsc_disk = atof(argv[++i]);
} else if (!strcmp(argv[i], "-keyfile")) {
strcpy(keyfile, argv[++i]);
} else if (!strcmp(argv[i], "-delay_bound")) {
wu.delay_bound = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-sequence")) {
sequence = atoi(argv[++i]);
} else {
infiles = argv+i;
ninfiles = argc - i;
break;
}
i++;
}
if (
!strlen(app.name)
|| !strlen(wu.name)
|| !strlen(wu_template_file )
|| !strlen(result_template_file)
|| wu.delay_bound==0
) {
fprintf(stderr, "create_work: bad cmdline\n");
exit(1);
}
if (boinc_db_open(db_name, db_passwd)) {
fprintf(stderr, "create_work: error opening database.\n" );
exit(0);
}
sprintf(buf, "where name='%s'", app.name);
retval = app.lookup(buf);
if (retval) {
fprintf(stderr, "create_work: app not found\n");
exit(1);
}
//fprintf(stderr, "wu_template = %s\n", wu_template);
retval = read_filename(wu_template_file, wu_template);
if (retval) {
fprintf(stderr, "create_work: can't open WU template\n");
exit(1);
}
wu.appid = app.id;
wu.timeout_check_time = time(0) + wu.delay_bound;
retval = read_key_file(keyfile, key);
if (retval) {
fprintf(stderr, "create_work: can't read key");
exit(1);
}
if (sequence) {
retval = create_sequence_group(
wu,
wu_template,
result_template_file,
redundancy,
download_dir,
infiles,
ninfiles,
key,
upload_url,
download_url,
sequence
);
} else {
retval = create_work(
wu,
wu_template,
result_template_file,
redundancy,
download_dir,
infiles,
ninfiles,
key,
upload_url,
download_url
);
if (retval) fprintf(stderr, "create_work: %d\n", retval);
}
boinc_db_close();
}