2002-06-21 06:52:47 +00:00
|
|
|
// The contents of this file are subject to the Mozilla 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://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// 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):
|
|
|
|
//
|
2003-01-02 23:12:05 +00:00
|
|
|
|
2002-11-27 21:31:17 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
2002-06-21 06:52:47 +00:00
|
|
|
#include <stdio.h>
|
2002-07-15 17:12:11 +00:00
|
|
|
#include <time.h>
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2003-01-02 23:12:05 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
#include "client_state.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_types.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "log_flags.h"
|
|
|
|
#include "scheduler_op.h"
|
|
|
|
|
|
|
|
SCHEDULER_OP::SCHEDULER_OP(HTTP_OP_SET* h) {
|
|
|
|
state = SCHEDULER_OP_STATE_IDLE;
|
|
|
|
http_op.http_op_state = HTTP_STATE_IDLE;
|
|
|
|
http_ops = h;
|
|
|
|
}
|
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
// try to get enough work to bring us up to max buffer level
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
|
|
|
int SCHEDULER_OP::init_get_work() {
|
2002-10-14 23:37:41 +00:00
|
|
|
int retval;
|
2002-10-16 23:50:41 +00:00
|
|
|
char err_msg[256];
|
2002-07-15 05:34:32 +00:00
|
|
|
double ns = gstate.work_needed_secs();
|
|
|
|
|
|
|
|
must_get_work = true;
|
|
|
|
project = gstate.next_project(0);
|
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_op_project(ns);
|
|
|
|
if (retval) {
|
2003-03-08 23:48:05 +00:00
|
|
|
sprintf(err_msg, "init_op_project failed, error %d\n", retval);
|
2002-10-16 23:50:41 +00:00
|
|
|
backoff(project, err_msg);
|
2002-11-19 22:57:05 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
} else {
|
2002-11-19 22:57:05 +00:00
|
|
|
project = gstate.next_project_master_pending();
|
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_master_fetch(project);
|
|
|
|
if (retval) {
|
2002-11-26 00:47:57 +00:00
|
|
|
sprintf(err_msg, "init_master_fetch failed, error %d\n", retval);
|
|
|
|
backoff(project, err_msg);
|
|
|
|
}
|
2002-10-14 23:37:41 +00:00
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2002-11-16 00:36:31 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// report results for a particular project.
|
2003-02-26 00:47:57 +00:00
|
|
|
// also get work from that project if below max buffer level
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
|
|
|
int SCHEDULER_OP::init_return_results(PROJECT* p, double ns) {
|
|
|
|
must_get_work = false;
|
|
|
|
project = p;
|
|
|
|
return init_op_project(ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to initiate an RPC to the current project.
|
|
|
|
// If there are multiple schedulers, start with the first one
|
|
|
|
//
|
|
|
|
int SCHEDULER_OP::init_op_project(double ns) {
|
|
|
|
int retval;
|
2003-01-02 23:12:05 +00:00
|
|
|
char err_msg[256];
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("init_op_project: starting op for %s\n", project->master_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if project has no schedulers, skip everything else
|
|
|
|
// and just get its master file.
|
|
|
|
//
|
2003-01-08 23:35:26 +00:00
|
|
|
url_index = 0;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (project->scheduler_urls.size() == 0) {
|
2002-11-26 00:47:57 +00:00
|
|
|
retval = init_master_fetch(project);
|
2003-01-02 23:12:05 +00:00
|
|
|
goto done;
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
|
|
|
retval = gstate.make_scheduler_request(project, ns);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "make_scheduler_request: %d\n", retval);
|
2003-01-02 23:12:05 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
retval = start_rpc();
|
|
|
|
done:
|
|
|
|
if (retval) {
|
|
|
|
sprintf(err_msg,
|
|
|
|
"scheduler init_op_project to %s failed, error %d\n",
|
|
|
|
project->scheduler_urls[url_index].text, retval
|
|
|
|
);
|
|
|
|
backoff(project, err_msg);
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
return retval;
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set a project's min RPC time to something in the future,
|
|
|
|
// based on exponential backoff
|
|
|
|
// TODO: integrate with other backoff sources
|
|
|
|
//
|
|
|
|
int SCHEDULER_OP::set_min_rpc_time(PROJECT* p) {
|
2002-11-27 21:31:17 +00:00
|
|
|
double x;
|
|
|
|
int exp_backoff;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
int n = p->nrpc_failures;
|
|
|
|
if (n > RETRY_CAP) n = RETRY_CAP;
|
2003-01-02 23:12:05 +00:00
|
|
|
|
2002-11-18 23:15:32 +00:00
|
|
|
// we've hit the limit on master_url fetches
|
2003-01-02 23:12:05 +00:00
|
|
|
//
|
|
|
|
if (p->master_fetch_failures >= MASTER_FETCH_RETRY_CAP) {
|
2002-11-19 22:57:05 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("we've hit the limit on master_url fetches\n");
|
|
|
|
}
|
2003-02-14 18:28:24 +00:00
|
|
|
x = exp(drand()*p->master_fetch_failures);
|
|
|
|
exp_backoff = (int) min((int)x,MASTER_FETCH_INTERVAL);
|
2003-01-02 23:12:05 +00:00
|
|
|
} else {
|
|
|
|
x = RETRY_BASE_PERIOD * exp(drand() * n);
|
|
|
|
exp_backoff = (int)max(SCHED_RETRY_DELAY_MIN,min(SCHED_RETRY_DELAY_MAX,(int) x));
|
2002-11-19 22:57:05 +00:00
|
|
|
}
|
2003-02-14 18:28:24 +00:00
|
|
|
p->min_rpc_time = time(0) + exp_backoff;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf(
|
|
|
|
"setting min RPC time for %s to %d seconds from now\n",
|
2002-11-27 21:31:17 +00:00
|
|
|
p->master_url, exp_backoff
|
2002-07-15 05:34:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-16 23:50:41 +00:00
|
|
|
// Back off on the scheduler and output an error msg if needed
|
|
|
|
//
|
2003-03-13 21:49:52 +00:00
|
|
|
void SCHEDULER_OP::backoff(PROJECT* p, char *error_msg ) {
|
|
|
|
show_message(p, error_msg, MSG_ERROR);
|
2002-11-26 00:47:57 +00:00
|
|
|
|
2002-12-02 23:09:45 +00:00
|
|
|
if (p->master_fetch_failures >= MASTER_FETCH_RETRY_CAP) {
|
|
|
|
p->master_url_fetch_pending = true;
|
2002-11-26 00:47:57 +00:00
|
|
|
set_min_rpc_time(p);
|
2003-03-08 23:48:05 +00:00
|
|
|
return;
|
2003-01-02 23:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if nrpc failures a multiple of master_fetch_period,
|
|
|
|
// then set master_url_fetch_pending and initialize again
|
|
|
|
//
|
2002-12-02 23:09:45 +00:00
|
|
|
if (p->nrpc_failures == MASTER_FETCH_PERIOD) {
|
|
|
|
p->master_url_fetch_pending = true;
|
|
|
|
p->min_rpc_time = 0;
|
|
|
|
p->nrpc_failures = 0;
|
|
|
|
p->master_fetch_failures++;
|
2002-11-26 00:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->nrpc_failures++;
|
|
|
|
set_min_rpc_time(p);
|
2002-10-16 23:50:41 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// low-level routine to initiate an RPC
|
2003-01-02 23:12:05 +00:00
|
|
|
// If successful, creates an HTTP_OP that must be polled
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
int SCHEDULER_OP::start_rpc() {
|
|
|
|
FILE *f;
|
2002-07-15 05:34:32 +00:00
|
|
|
int retval;
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(scheduler_url, project->scheduler_urls[url_index].text);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (log_flags.sched_ops) {
|
|
|
|
printf("Sending request to scheduler: %s\n", scheduler_url);
|
|
|
|
}
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
f = fopen(SCHED_OP_REQUEST_FILE, "r");
|
|
|
|
printf("--------- SCHEDULER REQUEST ---------\n");
|
|
|
|
copy_stream(f, stdout);
|
|
|
|
printf("--------- END ---------\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
2002-12-19 00:10:39 +00:00
|
|
|
if (gstate.use_http_proxy) {
|
|
|
|
http_op.use_http_proxy = true;
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(http_op.proxy_server_name, gstate.proxy_server_name);
|
2002-12-09 09:36:40 +00:00
|
|
|
http_op.proxy_server_port = gstate.proxy_server_port;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
retval = http_op.init_post(
|
2002-06-21 06:52:47 +00:00
|
|
|
scheduler_url, SCHED_OP_REQUEST_FILE,
|
|
|
|
SCHED_OP_RESULT_FILE
|
|
|
|
);
|
2002-07-15 05:34:32 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
retval = http_ops->insert(&http_op);
|
|
|
|
if (retval) return retval;
|
2002-06-21 06:52:47 +00:00
|
|
|
project->rpc_seqno++;
|
|
|
|
state = SCHEDULER_OP_STATE_RPC;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// initiate a fetch of a project's master URL file
|
|
|
|
//
|
|
|
|
int SCHEDULER_OP::init_master_fetch(PROJECT* p) {
|
|
|
|
int retval;
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
project = p;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("Fetching master file for %s\n", project->master_url);
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2002-12-19 00:10:39 +00:00
|
|
|
if (gstate.use_http_proxy) {
|
|
|
|
http_op.use_http_proxy = true;
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(http_op.proxy_server_name, gstate.proxy_server_name);
|
2002-12-09 09:36:40 +00:00
|
|
|
http_op.proxy_server_port = gstate.proxy_server_port;
|
|
|
|
}
|
2002-08-07 22:52:10 +00:00
|
|
|
retval = http_op.init_get(project->master_url, MASTER_FILE_NAME, true);
|
2002-07-15 05:34:32 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
retval = http_ops->insert(&http_op);
|
|
|
|
if (retval) return retval;
|
|
|
|
state = SCHEDULER_OP_STATE_GET_MASTER;
|
2002-06-21 06:52:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse a master file.
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
int SCHEDULER_OP::parse_master_file(vector<STRING256> &urls) {
|
2002-06-21 06:52:47 +00:00
|
|
|
char buf[256];
|
|
|
|
STRING256 str;
|
|
|
|
FILE* f;
|
|
|
|
|
|
|
|
f = fopen(MASTER_FILE_NAME, "r");
|
|
|
|
if (!f) {
|
|
|
|
fprintf(stderr, "Can't open master file\n");
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
project->scheduler_urls.clear();
|
|
|
|
while (fgets(buf, 256, f)) {
|
2002-09-22 23:27:14 +00:00
|
|
|
if (parse_str(buf, "<scheduler>", str.text, sizeof(str.text))) {
|
2002-07-15 05:34:32 +00:00
|
|
|
urls.push_back(str);
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-29 04:19:51 +00:00
|
|
|
fclose(f);
|
2002-07-15 05:34:32 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
2002-10-14 05:52:48 +00:00
|
|
|
printf("Parsed master file; got %d scheduler URLs\n", (int)urls.size());
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2002-11-18 23:15:32 +00:00
|
|
|
|
2003-01-02 23:12:05 +00:00
|
|
|
// couldn't find any urls in the master file?
|
|
|
|
//
|
|
|
|
if ((int) urls.size() == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// A master file has just been read.
|
|
|
|
// transfer scheduler urls to project.
|
|
|
|
// Return true if any of them is new
|
|
|
|
//
|
|
|
|
bool SCHEDULER_OP::update_urls(PROJECT& project, vector<STRING256> &urls) {
|
|
|
|
unsigned int i, j;
|
|
|
|
bool found, any_new;
|
|
|
|
|
|
|
|
any_new = false;
|
|
|
|
for (i=0; i<urls.size(); i++) {
|
|
|
|
found = false;
|
|
|
|
for (j=0; j<project.scheduler_urls.size(); j++) {
|
|
|
|
if (!strcmp(urls[i].text, project.scheduler_urls[i].text)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) any_new = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
project.scheduler_urls.clear();
|
|
|
|
for (i=0; i<urls.size(); i++) {
|
|
|
|
project.scheduler_urls.push_back(urls[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return any_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
// poll routine. If an operation is in progress, check for completion
|
|
|
|
//
|
2002-08-22 22:28:51 +00:00
|
|
|
bool SCHEDULER_OP::poll() {
|
2003-01-02 23:12:05 +00:00
|
|
|
int retval, nresults;
|
2002-07-15 05:34:32 +00:00
|
|
|
vector<STRING256> urls;
|
2003-01-02 23:12:05 +00:00
|
|
|
bool changed, scheduler_op_done;
|
2002-08-22 22:28:51 +00:00
|
|
|
bool action = false;
|
2002-12-12 22:55:56 +00:00
|
|
|
char err_msg[256],*err_url;
|
2002-06-21 06:52:47 +00:00
|
|
|
|
|
|
|
switch(state) {
|
|
|
|
case SCHEDULER_OP_STATE_GET_MASTER:
|
2002-07-15 05:34:32 +00:00
|
|
|
// here we're fetching the master file for a project
|
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
if (http_op.http_op_state == HTTP_STATE_DONE) {
|
2002-08-25 07:54:33 +00:00
|
|
|
action = true;
|
2002-07-15 05:34:32 +00:00
|
|
|
project->master_url_fetch_pending = false;
|
2003-02-28 22:39:36 +00:00
|
|
|
gstate.set_client_state_dirty("master URL fetch done");
|
2002-06-21 06:52:47 +00:00
|
|
|
http_ops->remove(&http_op);
|
2002-07-15 05:34:32 +00:00
|
|
|
if (http_op.http_op_retval == 0) {
|
2002-06-21 06:52:47 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf(
|
|
|
|
"Got master file from %s; parsing\n",
|
|
|
|
project->master_url
|
|
|
|
);
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
retval = parse_master_file(urls);
|
2003-01-02 23:12:05 +00:00
|
|
|
if (retval) {
|
|
|
|
// master file parse failed.
|
|
|
|
//
|
|
|
|
project->master_fetch_failures++;
|
|
|
|
backoff(project, "Master file parse failed\n");
|
|
|
|
err_url = project->master_url;
|
|
|
|
} else {
|
|
|
|
// everything succeeded. Clear error counters
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
changed = update_urls(*project, urls);
|
|
|
|
if (changed) {
|
|
|
|
project->min_rpc_time = 0;
|
|
|
|
project->nrpc_failures = 0;
|
2002-11-19 22:57:05 +00:00
|
|
|
project->master_fetch_failures = 0;
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
2003-01-02 23:12:05 +00:00
|
|
|
// master file fetch failed.
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
2003-01-02 23:12:05 +00:00
|
|
|
project->master_fetch_failures++;
|
2002-11-19 22:57:05 +00:00
|
|
|
backoff(project, "Master file fetch failed\n");
|
2002-12-12 22:55:56 +00:00
|
|
|
err_url = project->master_url;
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
|
|
|
|
// If don't have any schedulers for this project,
|
|
|
|
// it may be the wrong URL. notify the user
|
|
|
|
//
|
|
|
|
if (project->scheduler_urls.size() == 0) {
|
|
|
|
sprintf(err_msg,
|
|
|
|
"Could not contact %s. Make sure this is the correct project URL.",
|
|
|
|
err_url
|
|
|
|
);
|
2003-03-06 17:42:49 +00:00
|
|
|
show_message(project, err_msg, MSG_ERROR);
|
2003-02-14 08:22:55 +00:00
|
|
|
project->master_fetch_failures++;
|
|
|
|
backoff(project, err_msg);
|
2003-01-02 23:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if need to read master file for another project
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
project = gstate.next_project_master_pending();
|
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_master_fetch(project);
|
|
|
|
if (retval) {
|
|
|
|
project->master_fetch_failures++;
|
2002-11-26 00:47:57 +00:00
|
|
|
backoff(project, "Master file fetch failed\n");
|
2002-12-12 22:55:56 +00:00
|
|
|
err_url = project->master_url;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
|
|
|
state = SCHEDULER_OP_STATE_IDLE;
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("Scheduler_op: return to idle state\n");
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCHEDULER_OP_STATE_RPC:
|
2003-01-02 23:12:05 +00:00
|
|
|
|
|
|
|
// here we're doing a scheduler RPC
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
|
|
|
scheduler_op_done = false;
|
2002-06-21 06:52:47 +00:00
|
|
|
if (http_op.http_op_state == HTTP_STATE_DONE) {
|
2002-08-25 07:54:33 +00:00
|
|
|
action = true;
|
2002-06-21 06:52:47 +00:00
|
|
|
http_ops->remove(&http_op);
|
2002-07-15 05:34:32 +00:00
|
|
|
if (http_op.http_op_retval) {
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf(
|
|
|
|
"scheduler RPC to %s failed\n",
|
|
|
|
project->scheduler_urls[url_index].text
|
|
|
|
);
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
|
|
|
|
// scheduler RPC failed. Try another scheduler if one exists
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
url_index++;
|
|
|
|
if (url_index < project->scheduler_urls.size()) {
|
|
|
|
start_rpc();
|
|
|
|
} else {
|
2003-01-02 23:12:05 +00:00
|
|
|
backoff(project, "No schedulers responded");
|
2002-07-15 05:34:32 +00:00
|
|
|
if (must_get_work) {
|
|
|
|
project = gstate.next_project(project);
|
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_op_project(gstate.work_needed_secs());
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
|
|
|
scheduler_op_done = true;
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
}
|
2002-11-19 22:57:05 +00:00
|
|
|
else {
|
2002-07-15 05:34:32 +00:00
|
|
|
scheduler_op_done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf(
|
|
|
|
"scheduler RPC to %s succeeded\n",
|
|
|
|
project->scheduler_urls[url_index].text
|
|
|
|
);
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
gstate.handle_scheduler_reply(project, scheduler_url, nresults);
|
|
|
|
|
|
|
|
// if we asked for work and didn't get any,
|
|
|
|
// back off this project
|
|
|
|
//
|
2003-02-12 19:53:46 +00:00
|
|
|
if (must_get_work && nresults==0) {
|
2003-01-02 23:12:05 +00:00
|
|
|
backoff(project, "No work from project\n");
|
|
|
|
} else {
|
|
|
|
project->nrpc_failures = 0;
|
|
|
|
project->min_rpc_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we didn't get all the work we needed,
|
|
|
|
// ask another project for work
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
if (must_get_work) {
|
|
|
|
double x = gstate.work_needed_secs();
|
|
|
|
if (x > 0) {
|
|
|
|
project = gstate.next_project(project);
|
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_op_project(x);
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
|
|
|
scheduler_op_done = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scheduler_op_done = true;
|
|
|
|
}
|
2002-08-26 22:57:17 +00:00
|
|
|
} else {
|
2002-11-19 22:57:05 +00:00
|
|
|
scheduler_op_done = true;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
|
|
|
|
// If no outstanding ops, see if need a master fetch
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
if (scheduler_op_done) {
|
2003-01-02 23:12:05 +00:00
|
|
|
project = gstate.next_project_master_pending();
|
2002-11-19 22:57:05 +00:00
|
|
|
if (project) {
|
2003-01-02 23:12:05 +00:00
|
|
|
retval = init_master_fetch(project);
|
|
|
|
if (retval) {
|
2002-11-26 00:47:57 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("Scheduler op: init_master_fetch failed.\n" );
|
|
|
|
}
|
|
|
|
backoff(project, "Scheduler op: init_master_fetch failed.\n" );
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
} else {
|
2002-11-19 22:57:05 +00:00
|
|
|
state = SCHEDULER_OP_STATE_IDLE;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("Scheduler_op: return to idle state\n");
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2002-08-22 22:28:51 +00:00
|
|
|
return action;
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
SCHEDULER_REPLY::SCHEDULER_REPLY() {
|
2002-09-29 00:32:11 +00:00
|
|
|
global_prefs_xml = 0;
|
|
|
|
project_prefs_xml = 0;
|
2002-07-07 20:39:24 +00:00
|
|
|
code_sign_key = 0;
|
|
|
|
code_sign_key_signature = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCHEDULER_REPLY::~SCHEDULER_REPLY() {
|
2002-09-29 00:32:11 +00:00
|
|
|
if (global_prefs_xml) free(global_prefs_xml);
|
|
|
|
if (project_prefs_xml) free(project_prefs_xml);
|
2002-07-07 20:39:24 +00:00
|
|
|
if (code_sign_key) free(code_sign_key);
|
|
|
|
if (code_sign_key_signature) free(code_sign_key_signature);
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
int SCHEDULER_REPLY::parse(FILE* in) {
|
2002-07-15 05:34:32 +00:00
|
|
|
char buf[256], *p;
|
2002-06-21 06:52:47 +00:00
|
|
|
int retval;
|
2002-08-15 21:21:08 +00:00
|
|
|
|
2003-02-18 23:07:48 +00:00
|
|
|
hostid = 0;
|
|
|
|
host_total_credit = 0;
|
|
|
|
host_expavg_credit = 0;
|
|
|
|
host_create_time = 0;
|
|
|
|
request_delay = 0;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(message, "");
|
|
|
|
strcpy(message_priority, "");
|
|
|
|
strcpy(project_name, "");
|
2002-09-29 00:32:11 +00:00
|
|
|
global_prefs_xml = 0;
|
|
|
|
project_prefs_xml = 0;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(user_name, "");
|
|
|
|
strcpy(team_name, "");
|
2003-02-18 23:07:48 +00:00
|
|
|
user_total_credit = 0;
|
|
|
|
user_expavg_credit = 0;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(host_venue, "");
|
2003-02-18 23:07:48 +00:00
|
|
|
user_create_time = 0;
|
2002-07-07 20:39:24 +00:00
|
|
|
code_sign_key = 0;
|
|
|
|
code_sign_key_signature = 0;
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
p = fgets(buf, 256, in);
|
2003-02-12 19:21:44 +00:00
|
|
|
if (!p) {
|
|
|
|
fprintf(stderr, "SCHEDULER_REPLY::parse(): empty file\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
// First part of content should either be tag (HTTP 1.0) or
|
2002-08-12 21:54:19 +00:00
|
|
|
// hex length of response (HTTP 1.1)
|
2002-08-15 20:50:15 +00:00
|
|
|
if (!match_tag(buf, "<scheduler_reply>")) {
|
2002-06-21 06:52:47 +00:00
|
|
|
fprintf(stderr, "SCHEDULER_REPLY::parse(): bad first tag %s\n", buf);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
while (fgets(buf, 256, in)) {
|
2002-08-12 21:54:19 +00:00
|
|
|
if (match_tag(buf, "<scheduler_reply>")) {
|
|
|
|
// Do nothing
|
2003-02-14 18:28:24 +00:00
|
|
|
} else if (match_tag(buf, "</scheduler_reply>")) return 0;
|
|
|
|
else if (parse_str(buf, "<project_name>", project_name, sizeof(project_name))) continue;
|
|
|
|
else if (parse_str(buf, "<user_name>", user_name, sizeof(user_name))) continue;
|
|
|
|
else if (parse_double(buf, "<user_total_credit>", user_total_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<user_expavg_credit>", user_expavg_credit)) continue;
|
|
|
|
else if (parse_int(buf, "<user_create_time>", (int &)user_create_time)) continue;
|
2003-02-27 19:42:23 +00:00
|
|
|
else if (parse_str(buf, "<team_name>", team_name, sizeof(team_name))) continue;
|
2003-02-14 18:28:24 +00:00
|
|
|
else if (parse_int(buf, "<hostid>", hostid)) continue;
|
|
|
|
else if (parse_double(buf, "<host_total_credit>", host_total_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<host_expavg_credit>", host_expavg_credit)) continue;
|
2003-03-06 00:42:18 +00:00
|
|
|
else if (parse_str(buf, "<host_venue>", host_venue, sizeof(host_venue))) continue;
|
2003-02-14 18:28:24 +00:00
|
|
|
else if (parse_int(buf, "<host_create_time>", (int &)host_create_time)) continue;
|
|
|
|
else if (parse_int(buf, "<request_delay>", request_delay)) continue;
|
|
|
|
else if (match_tag(buf, "<global_preferences>")) {
|
2003-02-11 19:41:08 +00:00
|
|
|
retval = dup_element_contents(
|
2003-02-11 00:52:44 +00:00
|
|
|
in,
|
|
|
|
"</global_preferences>",
|
2003-02-11 19:41:08 +00:00
|
|
|
&global_prefs_xml
|
2003-02-11 00:52:44 +00:00
|
|
|
);
|
2002-09-29 00:32:11 +00:00
|
|
|
if (retval) return ERR_XML_PARSE;
|
|
|
|
} else if (match_tag(buf, "<project_preferences>")) {
|
2003-02-11 19:41:08 +00:00
|
|
|
retval = dup_element_contents(
|
2003-02-11 00:52:44 +00:00
|
|
|
in,
|
|
|
|
"</project_preferences>",
|
2003-02-11 19:41:08 +00:00
|
|
|
&project_prefs_xml
|
2003-02-11 00:52:44 +00:00
|
|
|
);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (retval) return ERR_XML_PARSE;
|
2002-07-07 20:39:24 +00:00
|
|
|
} else if (match_tag(buf, "<code_sign_key>")) {
|
2003-02-11 19:41:08 +00:00
|
|
|
retval = dup_element_contents(
|
2003-02-11 00:52:44 +00:00
|
|
|
in,
|
|
|
|
"</code_sign_key>",
|
2003-02-11 19:41:08 +00:00
|
|
|
&code_sign_key
|
2003-02-11 00:52:44 +00:00
|
|
|
);
|
2002-07-11 01:09:53 +00:00
|
|
|
if (retval) {
|
2002-08-25 07:54:33 +00:00
|
|
|
fprintf(stderr, "error: SCHEDULER_REPLY.parse: xml parsing error\n");
|
2002-07-11 01:09:53 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-08-25 07:54:33 +00:00
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
} else if (match_tag(buf, "<code_sign_key_signature>")) {
|
2003-02-11 19:41:08 +00:00
|
|
|
retval = dup_element_contents(
|
2003-02-11 00:52:44 +00:00
|
|
|
in,
|
|
|
|
"</code_sign_key_signature>",
|
2003-02-11 19:41:08 +00:00
|
|
|
&code_sign_key_signature
|
2003-02-11 00:52:44 +00:00
|
|
|
);
|
2002-07-07 20:39:24 +00:00
|
|
|
if (retval) return ERR_XML_PARSE;
|
2002-06-21 06:52:47 +00:00
|
|
|
} else if (match_tag(buf, "<app>")) {
|
|
|
|
APP app;
|
|
|
|
app.parse(in);
|
|
|
|
apps.push_back(app);
|
|
|
|
} else if (match_tag(buf, "<file_info>")) {
|
|
|
|
FILE_INFO file_info;
|
2002-07-05 05:33:40 +00:00
|
|
|
file_info.parse(in, true);
|
2002-06-21 06:52:47 +00:00
|
|
|
file_infos.push_back(file_info);
|
|
|
|
} else if (match_tag(buf, "<app_version>")) {
|
|
|
|
APP_VERSION av;
|
|
|
|
av.parse(in);
|
|
|
|
app_versions.push_back(av);
|
|
|
|
} else if (match_tag(buf, "<workunit>")) {
|
|
|
|
WORKUNIT wu;
|
|
|
|
wu.parse(in);
|
|
|
|
workunits.push_back(wu);
|
|
|
|
} else if (match_tag(buf, "<result>")) {
|
|
|
|
RESULT result; // make sure this is here so constructor
|
|
|
|
// gets called each time
|
2002-07-05 05:33:40 +00:00
|
|
|
result.parse_server(in);
|
2002-06-21 06:52:47 +00:00
|
|
|
results.push_back(result);
|
|
|
|
} else if (match_tag(buf, "<result_ack>")) {
|
|
|
|
RESULT result;
|
2002-07-05 05:33:40 +00:00
|
|
|
result.parse_ack(in);
|
2002-06-21 06:52:47 +00:00
|
|
|
result_acks.push_back(result);
|
2002-09-22 23:27:14 +00:00
|
|
|
} else if (parse_str(buf, "<message", message, sizeof(message))) {
|
|
|
|
parse_attr(buf, "priority", message_priority, sizeof(message_priority));
|
2002-06-21 06:52:47 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "SCHEDULER_REPLY::parse: unrecognized %s\n", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "SCHEDULER_REPLY::parse: no close tag\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|