2002-04-30 22:22:54 +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-02-24 21:25:16 +00:00
|
|
|
// High-level logic for communicating with scheduling servers,
|
2002-07-15 05:34:32 +00:00
|
|
|
// and for merging the result of a scheduler RPC into the client state
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-08-20 00:30:13 +00:00
|
|
|
// Note: code for actually doing a scheduler RPC is in scheduler_op.C
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
2002-09-11 18:28:36 +00:00
|
|
|
#include "windows_cpp.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "file_names.h"
|
2002-08-22 21:47:19 +00:00
|
|
|
#include "filesys.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-02-24 21:25:16 +00:00
|
|
|
#include "util.h"
|
2003-02-21 01:38:16 +00:00
|
|
|
|
2003-02-24 21:25:16 +00:00
|
|
|
#include "log_flags.h"
|
2003-02-21 01:38:16 +00:00
|
|
|
#include "account.h"
|
2002-05-17 22:33:57 +00:00
|
|
|
#include "message.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "scheduler_op.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
// quantities like avg CPU time decay by a factor of e every week
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
2003-02-24 21:25:16 +00:00
|
|
|
#define EXP_DECAY_RATE (1./(SECONDS_PER_DAY*7))
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// estimate the days of work remaining
|
2002-06-06 23:43:05 +00:00
|
|
|
//
|
2003-02-26 00:47:57 +00:00
|
|
|
double CLIENT_STATE::current_work_buf_days() {
|
2002-06-06 23:43:05 +00:00
|
|
|
unsigned int i;
|
2002-07-15 05:34:32 +00:00
|
|
|
RESULT* rp;
|
2002-06-06 23:43:05 +00:00
|
|
|
double seconds_remaining=0;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2002-07-15 05:34:32 +00:00
|
|
|
rp = results[i];
|
2002-10-15 18:09:16 +00:00
|
|
|
// Don't count result if we've already computed it
|
|
|
|
if (rp->state >= RESULT_COMPUTE_DONE) continue;
|
2002-08-05 00:29:34 +00:00
|
|
|
// TODO: subtract time already finished for WUs in progress
|
2003-05-21 23:23:42 +00:00
|
|
|
seconds_remaining += estimate_cpu_time(*rp->wup);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-02-24 21:25:16 +00:00
|
|
|
return (seconds_remaining / SECONDS_PER_DAY);
|
2002-06-06 23:43:05 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
// seconds of work needed to come up to the max buffer level
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
|
|
|
double CLIENT_STATE::work_needed_secs() {
|
2003-02-26 00:47:57 +00:00
|
|
|
double x = current_work_buf_days();
|
|
|
|
if (x > global_prefs.work_buf_max_days) return 0;
|
2003-02-26 01:04:42 +00:00
|
|
|
return (global_prefs.work_buf_max_days - x)*SECONDS_PER_DAY;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// update exponentially-averaged CPU times of all projects
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void CLIENT_STATE::update_avg_cpu(PROJECT* p) {
|
2002-07-15 05:34:32 +00:00
|
|
|
time_t now = time(0);
|
2002-04-30 22:22:54 +00:00
|
|
|
double deltat = now - p->exp_avg_mod_time;
|
|
|
|
if (deltat > 0) {
|
|
|
|
if (p->exp_avg_cpu != 0) {
|
|
|
|
p->exp_avg_cpu *= exp(deltat*EXP_DECAY_RATE);
|
|
|
|
}
|
|
|
|
p->exp_avg_mod_time = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// find a project that needs its master file parsed
|
2002-11-18 23:15:32 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* CLIENT_STATE::next_project_master_pending() {
|
|
|
|
unsigned int i;
|
|
|
|
PROJECT* p;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->min_rpc_time > now ) continue;
|
|
|
|
if (p->master_url_fetch_pending) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-13 23:02:45 +00:00
|
|
|
// find a project that needs to contact its scheduling server
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::next_project_sched_rpc_pending() {
|
|
|
|
unsigned int i;
|
2003-02-14 08:22:55 +00:00
|
|
|
time_t now = time(0);
|
2003-02-13 23:02:45 +00:00
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
2003-02-14 08:22:55 +00:00
|
|
|
if (projects[i]->min_rpc_time > now) continue;
|
2003-02-13 23:02:45 +00:00
|
|
|
if (projects[i]->sched_rpc_pending) {
|
|
|
|
return projects[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// return the next project after "old", in debt order,
|
|
|
|
// that is eligible for a scheduler RPC
|
2002-11-18 23:15:32 +00:00
|
|
|
// It excludes projects that have (p->master_url_fetch_pending) set to true.
|
|
|
|
// Such projects will be returned by next_project_master_pending routine.
|
2003-02-13 23:02:45 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* CLIENT_STATE::next_project(PROJECT* old) {
|
|
|
|
PROJECT* p, *pbest;
|
|
|
|
int best = 999;
|
|
|
|
time_t now = time(0);
|
|
|
|
unsigned int i;
|
|
|
|
pbest = 0;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
2003-02-28 22:39:36 +00:00
|
|
|
if (p->master_url_fetch_pending) continue;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (p->min_rpc_time > now ) continue;
|
|
|
|
if (old && p->debt_order <= old->debt_order) continue;
|
|
|
|
if (p->debt_order < best) {
|
|
|
|
pbest = p;
|
|
|
|
best = p->debt_order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pbest;
|
|
|
|
}
|
|
|
|
|
2002-08-28 21:50:51 +00:00
|
|
|
// Compute the "resource debt" of each project.
|
|
|
|
// This is used to determine what project we will focus on next,
|
|
|
|
// based on the user-specified resource share.
|
|
|
|
// TODO: this counts only CPU time. Should reflect disk/network usage too.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
void CLIENT_STATE::compute_resource_debts() {
|
|
|
|
unsigned int i, j;
|
2003-06-10 05:33:39 +00:00
|
|
|
PROJECT* p, *pbest=NULL;
|
2002-07-15 05:34:32 +00:00
|
|
|
double best;
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
update_avg_cpu(p);
|
|
|
|
if (p->exp_avg_cpu == 0) {
|
|
|
|
p->resource_debt = p->resource_share;
|
|
|
|
} else {
|
|
|
|
p->resource_debt = p->resource_share/p->exp_avg_cpu;
|
|
|
|
}
|
|
|
|
p->debt_order = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put in decreasing order. Should use qsort or some stdlib thang
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
best = -2;
|
|
|
|
for (j=0; j<projects.size(); j++) {
|
|
|
|
p = projects[j];
|
|
|
|
if (p->debt_order >= 0) continue;
|
|
|
|
if (p->resource_debt > best) {
|
|
|
|
best = p->resource_debt;
|
|
|
|
pbest = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pbest->debt_order = i;
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Prepare the scheduler request. This writes the request in XML to a
|
|
|
|
// file (SCHED_OP_REQUEST_FILE) which is later sent to the scheduling
|
|
|
|
// server
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
int CLIENT_STATE::make_scheduler_request(PROJECT* p, double work_req) {
|
2002-06-21 00:22:59 +00:00
|
|
|
FILE* f = fopen(SCHED_OP_REQUEST_FILE, "wb");
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
RESULT* rp;
|
2003-03-08 23:48:05 +00:00
|
|
|
int retval;
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
fprintf(f,
|
|
|
|
"<scheduler_request>\n"
|
|
|
|
" <authenticator>%s</authenticator>\n"
|
|
|
|
" <hostid>%d</hostid>\n"
|
|
|
|
" <rpc_seqno>%d</rpc_seqno>\n"
|
|
|
|
" <platform_name>%s</platform_name>\n"
|
2002-12-01 06:14:28 +00:00
|
|
|
" <core_client_major_version>%d</core_client_major_version>\n"
|
|
|
|
" <core_client_minor_version>%d</core_client_minor_version>\n"
|
2002-07-15 05:34:32 +00:00
|
|
|
" <work_req_seconds>%f</work_req_seconds>\n",
|
2002-04-30 22:22:54 +00:00
|
|
|
p->authenticator,
|
|
|
|
p->hostid,
|
|
|
|
p->rpc_seqno,
|
2002-08-25 07:54:33 +00:00
|
|
|
platform_name,
|
2002-12-01 06:14:28 +00:00
|
|
|
core_client_major_version,
|
|
|
|
core_client_minor_version,
|
2003-02-06 19:01:49 +00:00
|
|
|
work_req
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2003-02-11 19:41:08 +00:00
|
|
|
if (strlen(p->code_sign_key)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(f, "<code_sign_key>\n%s</code_sign_key>\n", p->code_sign_key);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// insert global preferences if present
|
|
|
|
//
|
|
|
|
FILE* fprefs = fopen(GLOBAL_PREFS_FILE_NAME, "r");
|
|
|
|
if (fprefs) {
|
|
|
|
copy_stream(fprefs, f);
|
|
|
|
fclose(fprefs);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = time_stats.write(f, true);
|
|
|
|
if (retval) return retval;
|
|
|
|
retval = net_stats.write(f, true);
|
|
|
|
if (retval) return retval;
|
|
|
|
retval = host_info.write(f);
|
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2003-02-06 19:01:49 +00:00
|
|
|
rp = results[i];
|
|
|
|
if (rp->project == p && rp->ready_to_ack)
|
|
|
|
rp->write(f, true);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
fprintf(f, "</scheduler_request>\n");
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// find a project with results that are overdue to report,
|
|
|
|
// and which we're allowed to contact.
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::find_project_with_overdue_results() {
|
|
|
|
unsigned int i;
|
|
|
|
RESULT* r;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<results.size(); i++) {
|
2003-02-06 19:01:49 +00:00
|
|
|
r = results[i];
|
2002-08-12 21:54:19 +00:00
|
|
|
// If we've completed computation but haven't finished reporting the
|
|
|
|
// results to the server, return the project for this result
|
2003-02-06 19:01:49 +00:00
|
|
|
if (r->ready_to_ack && (r->project->min_rpc_time < now)) {
|
|
|
|
return r->project;
|
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2003-02-06 01:02:56 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if we're allowed to do a scheduler RPC to at least one project
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::some_project_rpc_ok() {
|
|
|
|
unsigned int i;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
if (projects[i]->min_rpc_time < now) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called from the client's polling loop.
|
|
|
|
// initiate scheduler RPC activity if needed and possible
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::scheduler_rpc_poll() {
|
|
|
|
double work_secs;
|
|
|
|
PROJECT* p;
|
2003-02-26 00:47:57 +00:00
|
|
|
bool action=false, below_work_buf_min, should_get_work;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
switch(scheduler_op->state) {
|
|
|
|
case SCHEDULER_OP_STATE_IDLE:
|
2003-02-12 19:53:46 +00:00
|
|
|
if (exit_when_idle && contacted_sched_server) {
|
|
|
|
should_get_work = false;
|
|
|
|
} else {
|
2003-02-26 00:47:57 +00:00
|
|
|
below_work_buf_min = (current_work_buf_days() <= global_prefs.work_buf_min_days);
|
|
|
|
should_get_work = below_work_buf_min && some_project_rpc_ok();
|
2003-02-12 19:53:46 +00:00
|
|
|
}
|
|
|
|
if (should_get_work) {
|
2002-07-15 05:34:32 +00:00
|
|
|
compute_resource_debts();
|
|
|
|
scheduler_op->init_get_work();
|
2003-02-13 23:02:45 +00:00
|
|
|
action = true;
|
2003-02-14 08:22:55 +00:00
|
|
|
} else if ((p=next_project_master_pending())) {
|
2003-02-13 23:02:45 +00:00
|
|
|
scheduler_op->init_get_work();
|
|
|
|
action = true;
|
2003-02-14 08:22:55 +00:00
|
|
|
} else if ((p=next_project_sched_rpc_pending())) {
|
2003-02-13 23:02:45 +00:00
|
|
|
scheduler_op->init_return_results(p, 0);
|
2002-07-15 05:34:32 +00:00
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
p = find_project_with_overdue_results();
|
|
|
|
if (p) {
|
|
|
|
compute_resource_debts();
|
|
|
|
if (p->debt_order == 0) {
|
|
|
|
work_secs = work_needed_secs();
|
|
|
|
} else {
|
|
|
|
work_secs = 0;
|
|
|
|
}
|
|
|
|
scheduler_op->init_return_results(p, work_secs);
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scheduler_op->poll();
|
|
|
|
if (scheduler_op->state == SCHEDULER_OP_STATE_IDLE) {
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Handle the reply from a scheduler
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2003-01-02 23:12:05 +00:00
|
|
|
int CLIENT_STATE::handle_scheduler_reply(
|
|
|
|
PROJECT* project, char* scheduler_url, int& nresults
|
2002-07-15 05:34:32 +00:00
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REPLY sr;
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
unsigned int i;
|
2002-07-07 20:39:24 +00:00
|
|
|
bool signature_valid;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-01-02 23:12:05 +00:00
|
|
|
nresults = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
contacted_sched_server = true;
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
f = fopen(SCHED_OP_RESULT_FILE, "r");
|
|
|
|
printf("------------- SCHEDULER REPLY ----------\n");
|
|
|
|
copy_stream(f, stdout);
|
|
|
|
fclose(f);
|
|
|
|
printf("------------- END ----------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
f = fopen(SCHED_OP_RESULT_FILE, "r");
|
2003-01-02 23:12:05 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2003-02-08 00:22:38 +00:00
|
|
|
retval = sr.parse(f);
|
2002-08-29 04:19:51 +00:00
|
|
|
fclose(f);
|
2003-02-08 00:22:38 +00:00
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-25 07:54:33 +00:00
|
|
|
if (strlen(sr.project_name)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->project_name, sr.project_name);
|
2002-08-25 07:54:33 +00:00
|
|
|
}
|
2002-08-28 21:50:51 +00:00
|
|
|
if (strlen(sr.user_name)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->user_name, sr.user_name);
|
2002-08-28 21:50:51 +00:00
|
|
|
}
|
2003-02-27 19:42:23 +00:00
|
|
|
if (strlen(sr.team_name)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->team_name, sr.team_name);
|
2003-02-27 19:42:23 +00:00
|
|
|
}
|
2002-10-22 21:44:16 +00:00
|
|
|
project->user_total_credit = sr.user_total_credit;
|
|
|
|
project->user_expavg_credit = sr.user_expavg_credit;
|
|
|
|
project->user_create_time = sr.user_create_time;
|
2002-05-17 22:33:57 +00:00
|
|
|
if (strlen(sr.message)) {
|
2003-03-06 17:42:49 +00:00
|
|
|
int prio = (!strcmp(sr.message_priority, "high"))?MSG_ERROR:MSG_INFO;
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(project, prio, sr.message);
|
2002-05-17 22:33:57 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (sr.request_delay) {
|
2002-07-15 05:34:32 +00:00
|
|
|
project->min_rpc_time = time(0) + sr.request_delay;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
|
2003-01-02 23:12:05 +00:00
|
|
|
project->host_total_credit = sr.host_total_credit;
|
|
|
|
project->host_expavg_credit = sr.host_expavg_credit;
|
2002-04-30 22:22:54 +00:00
|
|
|
if (sr.hostid) {
|
|
|
|
project->hostid = sr.hostid;
|
2002-11-19 22:57:05 +00:00
|
|
|
project->host_create_time = sr.host_create_time;
|
2002-04-30 22:22:54 +00:00
|
|
|
project->rpc_seqno = 0;
|
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// if the scheduler reply includes global preferences,
|
|
|
|
// insert extra elements, write to disk, and parse
|
2002-06-21 06:52:47 +00:00
|
|
|
//
|
2002-09-29 00:32:11 +00:00
|
|
|
if (sr.global_prefs_xml) {
|
|
|
|
f = fopen(GLOBAL_PREFS_FILE_NAME, "w");
|
2003-01-02 23:12:05 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2002-06-21 06:52:47 +00:00
|
|
|
fprintf(f,
|
2002-09-29 00:32:11 +00:00
|
|
|
"<global_preferences>\n"
|
|
|
|
" <source_project>%s</source_project>\n"
|
|
|
|
" <source_scheduler>%s</source_scheduler>\n"
|
|
|
|
"%s"
|
|
|
|
"</global_preferences>\n",
|
2002-06-21 06:52:47 +00:00
|
|
|
project->master_url,
|
2002-09-29 00:32:11 +00:00
|
|
|
scheduler_url,
|
|
|
|
sr.global_prefs_xml
|
2002-06-21 06:52:47 +00:00
|
|
|
);
|
2002-09-29 00:32:11 +00:00
|
|
|
fclose(f);
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(host_venue, sr.host_venue);
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = global_prefs.parse_file(host_venue);
|
|
|
|
if (retval) return retval;
|
2003-02-26 00:47:57 +00:00
|
|
|
install_global_prefs();
|
2003-05-30 17:59:14 +00:00
|
|
|
set_nslots();
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deal with project preferences (should always be there)
|
|
|
|
//
|
|
|
|
if (sr.project_prefs_xml) {
|
2003-05-20 00:03:39 +00:00
|
|
|
if (strcmp(
|
|
|
|
project->project_specific_prefs, sr.project_prefs_xml
|
|
|
|
)) {
|
|
|
|
strcpy(project->project_specific_prefs, sr.project_prefs_xml);
|
|
|
|
retval = project->write_account_file();
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// if the scheduler reply includes a code-signing key,
|
|
|
|
// accept it if we don't already have one from the project.
|
|
|
|
// Otherwise verify its signature, using the key we already have.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (sr.code_sign_key) {
|
2003-02-11 00:52:44 +00:00
|
|
|
if (!strlen(project->code_sign_key)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->code_sign_key, sr.code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
} else {
|
2002-08-25 07:54:33 +00:00
|
|
|
if (sr.code_sign_key_signature) {
|
|
|
|
retval = verify_string2(
|
|
|
|
sr.code_sign_key, sr.code_sign_key_signature,
|
|
|
|
project->code_sign_key, signature_valid
|
|
|
|
);
|
|
|
|
if (!retval && signature_valid) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->code_sign_key, sr.code_sign_key);
|
2002-08-25 07:54:33 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stdout,
|
|
|
|
"New code signing key from %s doesn't validate\n",
|
|
|
|
project->project_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stdout, "Missing code sign key signature\n");
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy new entities to client state
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sr.apps.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.apps[i].name);
|
2003-05-20 22:32:03 +00:00
|
|
|
if (!app) {
|
2002-04-30 22:22:54 +00:00
|
|
|
app = new APP;
|
|
|
|
*app = sr.apps[i];
|
|
|
|
retval = link_app(project, app);
|
|
|
|
if (!retval) apps.push_back(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.file_infos.size(); i++) {
|
|
|
|
if (!lookup_file_info(project, sr.file_infos[i].name)) {
|
|
|
|
FILE_INFO* fip = new FILE_INFO;
|
|
|
|
*fip = sr.file_infos[i];
|
|
|
|
retval = link_file_info(project, fip);
|
|
|
|
if (!retval) file_infos.push_back(fip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.app_versions.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.app_versions[i].app_name);
|
2003-05-20 22:32:03 +00:00
|
|
|
APP_VERSION* avp = lookup_app_version(app, sr.app_versions[i].version_num);
|
|
|
|
if (!avp) {
|
|
|
|
avp = new APP_VERSION;
|
2002-04-30 22:22:54 +00:00
|
|
|
*avp = sr.app_versions[i];
|
|
|
|
retval = link_app_version(project, avp);
|
|
|
|
if (!retval) app_versions.push_back(avp);
|
2003-05-20 22:32:03 +00:00
|
|
|
} else {
|
|
|
|
// The list of file references may have changed.
|
|
|
|
// Copy the list from the reply message,
|
|
|
|
// and link to the FILE_INFOs
|
|
|
|
//
|
|
|
|
avp->app_files = sr.app_versions[i].app_files;
|
|
|
|
link_app_version(project, avp);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.workunits.size(); i++) {
|
|
|
|
if (!lookup_workunit(project, sr.workunits[i].name)) {
|
|
|
|
WORKUNIT* wup = new WORKUNIT;
|
|
|
|
*wup = sr.workunits[i];
|
2002-07-29 00:39:45 +00:00
|
|
|
wup->version_num = latest_version_num(wup->app_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = link_workunit(project, wup);
|
2002-07-29 00:39:45 +00:00
|
|
|
if (!retval) {
|
|
|
|
workunits.push_back(wup);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<sr.results.size(); i++) {
|
|
|
|
if (!lookup_result(project, sr.results[i].name)) {
|
|
|
|
RESULT* rp = new RESULT;
|
|
|
|
*rp = sr.results[i];
|
|
|
|
retval = link_result(project, rp);
|
|
|
|
if (!retval) results.push_back(rp);
|
2002-08-12 21:54:19 +00:00
|
|
|
rp->state = RESULT_NEW;
|
2003-01-02 23:12:05 +00:00
|
|
|
nresults++;
|
2003-01-07 22:49:42 +00:00
|
|
|
} else {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(project, MSG_ERROR, "Already have result %s\n", sr.results[i].name);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update records for ack'ed results
|
|
|
|
//
|
|
|
|
for (i=0; i<sr.result_acks.size(); i++) {
|
|
|
|
RESULT* rp = lookup_result(project, sr.result_acks[i].name);
|
|
|
|
if (log_flags.sched_op_debug) {
|
|
|
|
printf("got ack for result %s\n", sr.result_acks[i].name);
|
|
|
|
}
|
|
|
|
if (rp) {
|
2003-02-06 01:02:56 +00:00
|
|
|
rp->server_ack = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(project, MSG_ERROR, "Got ack for result %s, can't find\n",
|
|
|
|
sr.result_acks[i].name);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-13 23:02:45 +00:00
|
|
|
project->sched_rpc_pending = false;
|
2002-08-22 21:29:58 +00:00
|
|
|
set_client_state_dirty("handle_scheduler_reply");
|
2002-06-21 06:52:47 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("State after handle_scheduler_reply():\n");
|
2003-01-07 22:49:42 +00:00
|
|
|
print_summary();
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2003-01-02 23:12:05 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|