~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to sched/sched_assign.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
//
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
#include "config.h"
 
19
 
 
20
#ifdef _USING_FCGI_
 
21
#include "boinc_fcgi.h"
 
22
#else
 
23
#include <cstdio>
 
24
#endif
17
25
 
18
26
#include <unistd.h>
19
27
 
22
30
#include "backend_lib.h"
23
31
#include "error_numbers.h"
24
32
 
25
 
#include "server_types.h"
26
 
#include "main.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"
29
38
 
30
39
#include "sched_assign.h"
31
40
 
32
 
static int send_assigned_job(
33
 
    ASSIGNMENT& asg, SCHEDULER_REQUEST& request, SCHEDULER_REPLY& reply
34
 
) {
 
41
static int send_assigned_job(ASSIGNMENT& asg) {
35
42
    int retval;
36
43
    DB_WORKUNIT wu;
37
 
    char rtfpath[256], suffix[256], path[256], buf[256];
 
44
    char suffix[256], path[256], buf[256];
 
45
    const char *rtfpath;
38
46
    static bool first=true;
39
47
    static int seqno=0;
40
48
    static R_RSA_PRIVATE_KEY key;
58
66
        return retval;
59
67
    }
60
68
 
61
 
    bavp = get_app_version(request, reply, wu);
 
69
    bavp = get_app_version(wu, false, false);
62
70
    if (!bavp) {
63
71
        log_messages.printf(MSG_CRITICAL,
64
72
            "App version for assigned WU not found\n"
66
74
        return ERR_NOT_FOUND;
67
75
    }
68
76
 
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);
72
80
    if (retval) {
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();
79
87
    DB_RESULT result;
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);
82
90
 
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;
98
106
    }
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
103
111
        );
104
112
    }
105
113
    return 0;
108
116
// Send this host any jobs assigned to it, or to its user/team
109
117
// Return true iff we sent anything
110
118
//
111
 
bool send_assigned_jobs(SCHEDULER_REQUEST& request, SCHEDULER_REPLY& reply) {
 
119
bool send_assigned_jobs() {
112
120
    DB_RESULT result;
113
121
    int retval;
114
122
    char buf[256];
118
126
        ASSIGNMENT& asg = ssp->assignments[i];
119
127
 
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
123
131
            );
124
132
        }
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
132
140
            );
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;
137
145
            }
138
146
            break;
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;
146
154
            }
147
155
            break;
148
156
        case ASSIGN_USER:
149
 
            if (reply.user.id != asg.target_id) continue;
 
157
            if (g_reply->user.id != asg.target_id) continue;
150
158
            if (asg.multi) {
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);
152
160
            } else {
153
161
                sprintf(buf, "where workunitid=%d", asg.workunitid);
154
162
            }
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;
159
167
            }
160
168
            break;
161
169
        case ASSIGN_TEAM:
162
 
            if (reply.team.id != asg.target_id) continue;
 
170
            if (g_reply->team.id != asg.target_id) continue;
163
171
            if (asg.multi) {
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);
165
173
            } else {
166
174
                sprintf(buf, "where workunitid=%d", asg.workunitid);
167
175
            }
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;
172
180
            }
173
181
            break;