00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _CLIENT_TYPES_
00024 #define _CLIENT_TYPES_
00025
00026 #include "cpp.h"
00027
00028 #if !defined(_WIN32) || defined(__CYGWIN32__)
00029 #include <stdio.h>
00030 #include <sys/time.h>
00031 #endif
00032
00033 #include "md5_file.h"
00034 #include "cert_sig.h"
00035 #include "hostinfo.h"
00036 #include "coproc.h"
00037 #include "miofile.h"
00038
00039 #define P_LOW 1
00040 #define P_MEDIUM 3
00041 #define P_HIGH 5
00042
00043 #define MAX_FILE_INFO_LEN 4096
00044 #define MAX_SIGNATURE_LEN 4096
00045 #define MAX_KEY_LEN 4096
00046
00047
00048
00049
00050
00051
00052 #define FILE_NOT_PRESENT 0
00053 #define FILE_PRESENT 1
00054
00055 class FILE_INFO {
00056 public:
00057 char name[256];
00058 char md5_cksum[33];
00059 double max_nbytes;
00060 double nbytes;
00061 double upload_offset;
00062 bool generated_locally;
00063 int status;
00064 bool executable;
00065 bool uploaded;
00066 bool upload_when_present;
00067 bool sticky;
00068 bool report_on_rpc;
00071 bool marked_for_delete;
00072 bool signature_required;
00073 bool is_user_file;
00074 bool is_project_file;
00075 bool is_auto_update_file;
00077 bool gzip_when_done;
00079 class PERS_FILE_XFER* pers_file_xfer;
00081 struct RESULT* result;
00082 class PROJECT* project;
00083 int ref_cnt;
00084 std::vector<std::string> urls;
00085 int start_url;
00086 int current_url;
00091 char signed_xml[MAX_FILE_INFO_LEN];
00093 char xml_signature[MAX_SIGNATURE_LEN];
00096 char file_signature[MAX_SIGNATURE_LEN];
00098 std::string error_msg;
00099 CERT_SIGS* cert_sigs;
00100
00101 FILE_INFO();
00102 ~FILE_INFO();
00103 void reset();
00104 int set_permissions();
00105 int parse(MIOFILE&, bool from_server);
00106 int write(MIOFILE&, bool to_server);
00107 int write_gui(MIOFILE&);
00109 int delete_file();
00110 const char* get_init_url(bool);
00111 const char* get_next_url(bool);
00112 const char* get_current_url(bool);
00113 bool is_correct_url_type(bool, std::string&);
00114 bool had_failure(int& failnum);
00115 void failure_message(std::string&);
00116 int merge_info(FILE_INFO&);
00117 int verify_file(bool, bool);
00118 bool verify_file_certs();
00120 int gzip();
00121 };
00122
00124
00129
00130 struct FILE_REF {
00132 char file_name[256];
00134 char open_name[256];
00135 bool main_program;
00136 FILE_INFO* file_info;
00138 bool copy_file;
00141 bool optional;
00142 int parse(MIOFILE&);
00143 int write(MIOFILE&);
00144 };
00145
00147
00148 struct DAILY_STATS {
00149 double user_total_credit;
00150 double user_expavg_credit;
00151 double host_total_credit;
00152 double host_expavg_credit;
00153 double day;
00154
00155 void clear();
00156 DAILY_STATS() {clear();}
00157 int parse(FILE*);
00158 };
00159 bool operator < (const DAILY_STATS&, const DAILY_STATS&);
00160
00161 struct RR_SIM_PROJECT_STATUS {
00163 std::vector<RESULT*>active;
00165 std::vector<RESULT*>pending;
00166 int deadlines_missed;
00169 double proc_rate;
00170 double cpu_shortfall;
00171
00172 inline void clear() {
00173 active.clear();
00174 pending.clear();
00175 deadlines_missed = 0;
00176 proc_rate = 0;
00177 cpu_shortfall = 0;
00178 }
00179 inline void activate(RESULT* rp) {
00180 active.push_back(rp);
00181 }
00182 inline void add_pending(RESULT* rp) {
00183 pending.push_back(rp);
00184 }
00185 inline bool none_active() {
00186 return !active.size();
00187 }
00188 inline bool can_run(RESULT*, int ncpus) {
00189 return (int)active.size() < ncpus;
00190 }
00191 inline void remove_active(RESULT* r) {
00192 std::vector<RESULT*>::iterator it = active.begin();
00193 while (it != active.end()) {
00194 if (*it == r) {
00195 it = active.erase(it);
00196 } else {
00197 it++;
00198 }
00199 }
00200 }
00201 inline RESULT* get_pending() {
00202 if (!pending.size()) return NULL;
00203 RESULT* rp = pending[0];
00204 pending.erase(pending.begin());
00205 return rp;
00206 }
00207 inline int cpus_used() {
00208 return (int) active.size();
00209 }
00210 };
00211
00212 class PROJECT {
00213 public:
00214
00215
00216
00218 char master_url[256];
00220 char authenticator[256];
00225 std::string project_prefs;
00228 std::string project_specific_prefs;
00230 std::string gui_urls;
00232 double resource_share;
00236 char host_venue[256];
00237 bool using_venue_specific_prefs;
00238
00239
00240
00241
00242
00244 std::vector<std::string> scheduler_urls;
00246 char project_name[256];
00248 char symstore[256];
00249 char user_name[256];
00250 char team_name[256];
00251 char email_hash[MD5_LEN];
00252 char cross_project_id[MD5_LEN];
00253 double cpid_time;
00254 double user_total_credit;
00255 double user_expavg_credit;
00256 double user_create_time;
00257 int hostid;
00258 double host_total_credit;
00259 double host_expavg_credit;
00260 double host_create_time;
00262 double ams_resource_share;
00263
00264
00265
00266 int rpc_seqno;
00268 int nrpc_failures;
00269 int master_fetch_failures;
00271 double min_rpc_time;
00272 void set_min_rpc_time(double future_time, const char* reason);
00274 bool waiting_until_min_rpc_time();
00276 bool master_url_fetch_pending;
00280 int sched_rpc_pending;
00283 double next_rpc_time;
00288 bool possibly_backed_off;
00290 bool trickle_up_pending;
00292 double last_rpc_time;
00293
00294
00295
00298 bool anonymous_platform;
00299 bool non_cpu_intensive;
00300 bool verify_files_on_app_start;
00301 bool use_symlinks;
00302
00303
00304
00305
00308 bool send_file_list;
00310 int send_time_stats_log;
00312 int send_job_log;
00313
00314 bool suspended_via_gui;
00318 bool dont_request_more_work;
00319 bool attached_via_acct_mgr;
00321 bool detach_when_done;
00323 bool ended;
00324 char code_sign_key[MAX_KEY_LEN];
00325 std::vector<FILE_REF> user_files;
00327 std::vector<FILE_REF> project_files;
00328 int parse_preferences_for_user_files();
00329 int parse_project_files(MIOFILE&, bool delete_existing_symlinks);
00330 void write_project_files(MIOFILE&);
00331 void link_project_files(bool recreate_symlink_files);
00332 int write_symlink_for_project_file(FILE_INFO*);
00334 double project_files_downloaded_time;
00337 void update_project_files_downloaded_time();
00338
00344 double duration_correction_factor;
00345 void update_duration_correction_factor(RESULT*);
00346
00347
00348
00349
00351 bool contactable();
00353 bool runnable();
00355 bool downloading();
00357 bool potentially_runnable();
00359 bool nearly_runnable();
00361 bool overworked();
00363 bool some_download_stalled();
00364 bool some_result_suspended();
00365
00366 RR_SIM_PROJECT_STATUS rr_sim_status;
00367
00368 void set_rrsim_proc_rate(double rrs);
00369
00371 int deadlines_missed;
00372
00373
00374
00377 double short_term_debt;
00382 double long_term_debt;
00383
00385 double anticipated_debt;
00388 double wall_cpu_time_this_debt_interval;
00390 struct RESULT *next_runnable_result;
00393 int nuploading_results;
00394
00402 double work_request;
00403 int work_request_urgency;
00404
00406 int nresults_returned;
00408 const char* get_scheduler_url(int index, double r);
00410 bool checked;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 #define FILE_XFER_FAILURE_LIMIT 3
00424 int file_xfer_failures_up;
00425 int file_xfer_failures_down;
00426 double next_file_xfer_up;
00427 double next_file_xfer_down;
00428
00429 double next_file_xfer_time(const bool);
00430 void file_xfer_failed(const bool);
00431 void file_xfer_succeeded(const bool);
00432
00433 PROJECT();
00434 ~PROJECT(){}
00435 void init();
00436 void copy_state_fields(PROJECT&);
00437 char *get_project_name();
00438 int write_account_file();
00439 int parse_account(FILE*);
00440 int parse_account_file_venue();
00441 int parse_account_file();
00442 int parse_state(MIOFILE&);
00443 int write_state(MIOFILE&, bool gui_rpc=false);
00444
00445
00446 std::vector<DAILY_STATS> statistics;
00447 int parse_statistics(MIOFILE&);
00448 int parse_statistics(FILE*);
00449 int write_statistics(MIOFILE&, bool gui_rpc=false);
00450 int write_statistics_file();
00451 };
00452
00453 struct APP {
00454 char name[256];
00455 char user_friendly_name[256];
00456 PROJECT* project;
00457
00458 int parse(MIOFILE&);
00459 int write(MIOFILE&);
00460 };
00461
00462 struct APP_VERSION {
00463 char app_name[256];
00464 int version_num;
00465 char platform[256];
00466 char plan_class[64];
00467 char api_version[16];
00468 double avg_ncpus;
00469 double max_ncpus;
00470 double flops;
00472 char cmdline[256];
00473 COPROCS coprocs;
00474
00475 APP* app;
00476 PROJECT* project;
00477 std::vector<FILE_REF> app_files;
00478 int ref_cnt;
00479 char graphics_exec_path[512];
00480
00481 APP_VERSION(){}
00482 ~APP_VERSION(){}
00483 int parse(MIOFILE&);
00484 int write(MIOFILE&);
00485 bool had_download_failure(int& failnum);
00486 void get_file_errors(std::string&);
00487 void clear_errors();
00488 int api_major_version();
00489 };
00490
00491 struct WORKUNIT {
00492 char name[256];
00493 char app_name[256];
00496 int version_num;
00497 std::string command_line;
00498 std::vector<FILE_REF> input_files;
00499 PROJECT* project;
00500 APP* app;
00501 int ref_cnt;
00502 double rsc_fpops_est;
00503 double rsc_fpops_bound;
00504 double rsc_memory_bound;
00505 double rsc_disk_bound;
00506
00507 WORKUNIT(){}
00508 ~WORKUNIT(){}
00509 int parse(MIOFILE&);
00510 int write(MIOFILE&);
00511 bool had_download_failure(int& failnum);
00512 void get_file_errors(std::string&);
00513 void clear_errors();
00514 };
00515
00516 struct RESULT {
00517 char name[256];
00518 char wu_name[256];
00519 double report_deadline;
00520 int version_num;
00521 char plan_class[64];
00522 char platform[256];
00523 APP_VERSION* avp;
00524 std::vector<FILE_REF> output_files;
00528 bool ready_to_report;
00530 double completed_time;
00532 bool got_server_ack;
00533 double final_cpu_time;
00534
00535
00536 double fpops_per_cpu_sec;
00537 double fpops_cumulative;
00538 double intops_per_cpu_sec;
00539 double intops_cumulative;
00540
00542 int _state;
00543 inline int state() { return _state; }
00544 void set_state(int, const char*);
00546 int exit_status;
00561 std::string stderr_out;
00562 bool suspended_via_gui;
00563
00564 APP* app;
00566 WORKUNIT* wup;
00567 PROJECT* project;
00568
00569 RESULT(){}
00570 ~RESULT(){}
00571 void clear();
00572 int parse_server(MIOFILE&);
00573 int parse_state(MIOFILE&);
00574 int parse_name(FILE*, const char* end_tag);
00575 int write(MIOFILE&, bool to_server);
00576 int write_gui(MIOFILE&);
00577 bool is_upload_done();
00578 void clear_uploaded_flags();
00579 FILE_REF* lookup_file(FILE_INFO*);
00580 FILE_INFO* lookup_file_logical(const char*);
00582
00585 void abort_inactive(int);
00586 void append_log_record();
00587
00588
00589
00590 double estimated_cpu_time(bool for_work_fetch);
00591 double estimated_cpu_time_uncorrected();
00592 double estimated_cpu_time_remaining(bool for_work_fetch);
00593 bool computing_done();
00595 bool runnable();
00598 bool nearly_runnable();
00600 bool downloading();
00603 bool some_download_stalled();
00604 bool uses_coprocs() {
00605 return (avp->coprocs.coprocs.size() > 0);
00606 }
00607
00608
00609 double rrsim_cpu_left;
00610 double rrsim_finish_delay;
00613 bool already_selected;
00615 double computation_deadline();
00616 bool rr_sim_misses_deadline;
00617 bool last_rr_sim_missed_deadline;
00618
00620 bool edf_scheduled;
00621 };
00622
00624
00625 class MODE {
00626 private:
00627 int perm_mode;
00628 int temp_mode;
00629 double temp_timeout;
00630 public:
00631 MODE();
00632 void set(int mode, double duration);
00633 int get_perm();
00634 int get_current();
00635 double delay();
00636 };
00637
00639
00640 class PLATFORM {
00641 public:
00642 std::string name;
00643 };
00644
00645 #endif