22
30
#include "backend_lib.h"
23
31
#include "error_numbers.h"
25
#include "server_types.h"
33
#include "sched_main.h"
27
34
#include "sched_msgs.h"
28
35
#include "sched_send.h"
36
#include "sched_version.h"
37
#include "sched_types.h"
30
39
#include "sched_assign.h"
32
static int send_assigned_job(
33
ASSIGNMENT& asg, SCHEDULER_REQUEST& request, SCHEDULER_REPLY& reply
41
static int send_assigned_job(ASSIGNMENT& asg) {
37
char rtfpath[256], suffix[256], path[256], buf[256];
44
char suffix[256], path[256], buf[256];
38
46
static bool first=true;
39
47
static int seqno=0;
40
48
static R_RSA_PRIVATE_KEY key;
66
74
return ERR_NOT_FOUND;
69
sprintf(rtfpath, "../%s", wu.result_template_file);
77
rtfpath = config.project_path("%s", wu.result_template_file);
70
78
sprintf(suffix, "%d_%d_%d", getpid(), (int)time(0), seqno++);
71
retval = create_result(wu, rtfpath, suffix, key, config, 0, 0);
79
retval = create_result(wu, (char *)rtfpath, suffix, key, config, 0, 0);
73
81
log_messages.printf(MSG_CRITICAL,
74
82
"[WU#%d %s] create_result() %d\n", wu.id, wu.name, retval
78
86
int result_id = boinc_db.insert_id();
80
88
retval = result.lookup_id(result_id);
81
add_result_to_reply(result, wu, request, reply, bavp);
89
add_result_to_reply(result, wu, bavp, false);
83
91
// if this is a one-job assignment, fill in assignment.resultid
84
92
// so that it doesn't get sent again
97
105
asg.resultid = result_id;
99
107
if (config.debug_assignment) {
100
log_messages.printf(MSG_DEBUG,
101
"[WU#%d] [RESULT#%d] [HOST#%d] send assignment %d\n",
102
wu.id, result_id, reply.host.id, asg.id
108
log_messages.printf(MSG_NORMAL,
109
"[assign] [WU#%d] [RESULT#%d] [HOST#%d] send assignment %d\n",
110
wu.id, result_id, g_reply->host.id, asg.id
118
126
ASSIGNMENT& asg = ssp->assignments[i];
120
128
if (config.debug_assignment) {
121
log_messages.printf(MSG_DEBUG,
122
"processing assignment type %d\n", asg.target_type
129
log_messages.printf(MSG_NORMAL,
130
"[assign] processing assignment type %d\n", asg.target_type
125
133
// see if this assignment applies to this host
128
136
switch (asg.target_type) {
129
137
case ASSIGN_NONE:
130
138
sprintf(buf, "where hostid=%d and workunitid=%d",
131
reply.host.id, asg.workunitid
139
g_reply->host.id, asg.workunitid
133
141
retval = result.lookup(buf);
134
142
if (retval == ERR_DB_NOT_FOUND) {
135
retval = send_assigned_job(asg, request, reply);
143
retval = send_assigned_job(asg);
136
144
if (!retval) sent_something = true;
139
147
case ASSIGN_HOST:
140
if (reply.host.id != asg.target_id) continue;
148
if (g_reply->host.id != asg.target_id) continue;
141
149
sprintf(buf, "where workunitid=%d", asg.workunitid);
142
150
retval = result.lookup(buf);
143
151
if (retval == ERR_DB_NOT_FOUND) {
144
retval = send_assigned_job(asg, request, reply);
152
retval = send_assigned_job(asg);
145
153
if (!retval) sent_something = true;
148
156
case ASSIGN_USER:
149
if (reply.user.id != asg.target_id) continue;
157
if (g_reply->user.id != asg.target_id) continue;
151
sprintf(buf, "where workunitid=%d and hostid=%d", asg.workunitid, reply.host.id);
159
sprintf(buf, "where workunitid=%d and hostid=%d", asg.workunitid, g_reply->host.id);
153
161
sprintf(buf, "where workunitid=%d", asg.workunitid);
155
163
retval = result.lookup(buf);
156
164
if (retval == ERR_DB_NOT_FOUND) {
157
retval = send_assigned_job(asg, request, reply);
165
retval = send_assigned_job(asg);
158
166
if (!retval) sent_something = true;
161
169
case ASSIGN_TEAM:
162
if (reply.team.id != asg.target_id) continue;
170
if (g_reply->team.id != asg.target_id) continue;
164
sprintf(buf, "where workunitid=%d and hostid=%d", asg.workunitid, reply.host.id);
172
sprintf(buf, "where workunitid=%d and hostid=%d", asg.workunitid, g_reply->host.id);
166
174
sprintf(buf, "where workunitid=%d", asg.workunitid);
168
176
retval = result.lookup(buf);
169
177
if (retval == ERR_DB_NOT_FOUND) {
170
retval = send_assigned_job(asg, request, reply);
178
retval = send_assigned_job(asg);
171
179
if (!retval) sent_something = true;