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):
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _DB_
|
|
|
|
#define _DB_
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// Structures corresponding to database records.
|
|
|
|
// Some of these types have counterparts in client/types.h,
|
|
|
|
// but don't be deceived - client and server have different variants.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// The parse and write functions are for use in scheduler RPC.
|
|
|
|
// They don't necessarily serialize the entire records.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-07-16 23:37:54 +00:00
|
|
|
// Maximum allowed size for SQL based blobs (Binary Large Object)
|
2002-05-24 04:29:10 +00:00
|
|
|
#define MAX_BLOB_SIZE 4096
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-25 07:54:33 +00:00
|
|
|
struct PROJECT {
|
|
|
|
int id;
|
|
|
|
char name[256];
|
|
|
|
};
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// A compilation target, i.e. a architecture/OS combination.
|
|
|
|
// Currently the core client will be given only applications
|
|
|
|
// that match its platform exactly.
|
|
|
|
// This could be generatlized to allow, say, an app compiled
|
|
|
|
// for AMD to be run on a "generic Intel x86" core client.
|
|
|
|
// In this case we'd need a 1 to N mapping from APP_VERSION to PLATFORM
|
|
|
|
//
|
|
|
|
struct PLATFORM {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
2002-09-25 19:40:19 +00:00
|
|
|
char name[256]; // i.e. "sparc-sun-solaris2.7"
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// An application.
|
|
|
|
// The core client is viewed as an application; its name is "core_client".
|
|
|
|
//
|
|
|
|
struct APP {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
|
|
|
char name[256]; // application name, preferably short
|
2002-09-25 19:40:19 +00:00
|
|
|
int min_version; // don't use app versions before this
|
2002-04-30 22:22:54 +00:00
|
|
|
char result_xml_template[MAX_BLOB_SIZE];
|
|
|
|
// if any workunits have dynamic results,
|
|
|
|
// XML template for results comes from here
|
|
|
|
// The template is processed by the function
|
|
|
|
// process_result_template() from backend_lib.C
|
|
|
|
|
|
|
|
int write(FILE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A version of an application.
|
|
|
|
//
|
|
|
|
struct APP_VERSION {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
|
|
|
int appid;
|
|
|
|
int version_num;
|
|
|
|
int platformid;
|
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
char xml_doc[MAX_BLOB_SIZE];
|
2002-08-26 22:57:17 +00:00
|
|
|
// describes app files. format:
|
|
|
|
// <file_info>...</file_info>
|
|
|
|
// ...
|
|
|
|
// <file_assocs>
|
|
|
|
// <io_file_desc>...</io_file_desc>
|
|
|
|
// ...
|
|
|
|
// </file_assocs>
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// The following defined for apps other than core client.
|
|
|
|
// They let you handle backwards-incompatible changes to
|
|
|
|
// the core client / app interface
|
|
|
|
//
|
|
|
|
int min_core_version; // min core version this will run with
|
|
|
|
int max_core_version; // if <>0, max core version this will run with
|
|
|
|
|
|
|
|
// the following defined for core client
|
|
|
|
//
|
|
|
|
char message[256]; // if we get a request from this version,
|
|
|
|
// send this message
|
|
|
|
bool deprecated; // if we get a request from this version,
|
|
|
|
// don't send it any work.
|
|
|
|
|
|
|
|
int write(FILE*, APP&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct USER {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
|
|
|
char email_addr[256];
|
|
|
|
char name[256];
|
|
|
|
char web_password[256];
|
|
|
|
char authenticator[256];
|
|
|
|
char country[256];
|
|
|
|
char postal_code[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
double total_credit;
|
2002-09-27 06:12:50 +00:00
|
|
|
double expavg_credit; // credit per second, recent average
|
|
|
|
double expavg_time; // when the above was computed
|
|
|
|
char global_prefs[MAX_BLOB_SIZE]; // global preferences
|
2002-09-29 00:32:11 +00:00
|
|
|
// within <global_preferences> tag
|
2002-09-27 06:12:50 +00:00
|
|
|
char project_prefs[MAX_BLOB_SIZE];
|
2002-09-29 00:32:11 +00:00
|
|
|
// within <project_preferences> tag
|
|
|
|
int teamid; // if user is part of a team
|
2002-07-11 20:35:05 +00:00
|
|
|
};
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
#define TEAM_TYPE_COMPANY_SMALL 1
|
|
|
|
#define TEAM_TYPE_COMPANY_MEDIUM 2
|
|
|
|
#define TEAM_TYPE_COMPANY_LARGE 3
|
|
|
|
#define TEAM_TYPE_CLUB 4
|
|
|
|
#define TEAM_TYPE_PRIMARY 5
|
|
|
|
#define TEAM_TYPE_SECONDARY 6
|
|
|
|
#define TEAM_TYPE_UNIVERSITY 7
|
|
|
|
#define TEAM_TYPE_JUNIOR_COLLEGE 8
|
|
|
|
#define TEAM_TYPE_GOVERNMENT 9
|
2002-07-11 20:35:05 +00:00
|
|
|
|
|
|
|
struct TEAM {
|
|
|
|
int id;
|
2002-07-16 23:37:54 +00:00
|
|
|
int userid; // User ID of team founder
|
2002-08-26 22:57:17 +00:00
|
|
|
char name[256];
|
2002-07-16 23:37:54 +00:00
|
|
|
char name_lc[256]; // Team name in lowercase (used for searching)
|
2002-08-26 22:57:17 +00:00
|
|
|
char url[256];
|
|
|
|
int type; // Team type (see above)
|
|
|
|
char name_html[256];
|
2002-07-11 20:35:05 +00:00
|
|
|
char description[256];
|
|
|
|
int nusers;
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct HOST {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
2002-07-16 23:37:54 +00:00
|
|
|
int userid; // ID of user running this host
|
2002-04-30 22:22:54 +00:00
|
|
|
int rpc_seqno; // last seqno received from client
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int rpc_time; // time of last scheduler RPC
|
2002-08-28 21:50:51 +00:00
|
|
|
double total_credit;
|
2002-09-25 19:40:19 +00:00
|
|
|
double expavg_credit; // credit per second, recent average
|
|
|
|
double expavg_time; // last time the above was updated
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// all remaining items are assigned by the client
|
|
|
|
int timezone;
|
|
|
|
char domain_name[256];
|
|
|
|
char serialnum[256];
|
|
|
|
char last_ip_addr[256];
|
|
|
|
int nsame_ip_addr;
|
|
|
|
|
2002-07-16 23:37:54 +00:00
|
|
|
double on_frac; // Fraction of the time (0-1) that the host is on
|
|
|
|
double connected_frac; // Fraction of time that host is connected
|
2002-08-26 22:57:17 +00:00
|
|
|
double active_frac; // Fraction of time that host is enabled to work
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-16 23:37:54 +00:00
|
|
|
int p_ncpus; // Number of CPUs on host
|
2002-08-26 22:57:17 +00:00
|
|
|
char p_vendor[256]; // Vendor name of CPU
|
|
|
|
char p_model[256]; // Model of CPU
|
2002-09-26 05:57:10 +00:00
|
|
|
double p_fpops; // measured floating point ops/sec of CPU
|
|
|
|
double p_iops; // measured integer ops/sec of CPU
|
|
|
|
double p_membw; // measured memory bandwidth (bytes/sec) of CPU
|
|
|
|
double p_calculated; // when the above were calculated
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
char os_name[256]; // Name of operating system
|
|
|
|
char os_version[256]; // Version of operating system
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
double m_nbytes; // Size of memory in bytes
|
2002-07-16 23:37:54 +00:00
|
|
|
double m_cache; // Size of CPU cache in bytes (L1 or L2?)
|
2002-08-26 22:57:17 +00:00
|
|
|
double m_swap; // Size of swap space in bytes
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-16 23:37:54 +00:00
|
|
|
double d_total; // Total disk space
|
2002-04-30 22:22:54 +00:00
|
|
|
double d_free;
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
double n_bwup; // Average upload bandwidth
|
|
|
|
double n_bwdown; // Average download bandwidth
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-25 19:40:19 +00:00
|
|
|
// The following is derived (by server) from other fields
|
|
|
|
double credit_per_cpu_sec;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int parse(FILE*);
|
|
|
|
int parse_time_stats(FILE*);
|
|
|
|
int parse_net_stats(FILE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WORKUNIT {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time; // time of record creation
|
2002-07-16 23:37:54 +00:00
|
|
|
int appid; // ID of APP record tied to this workunit
|
2002-04-30 22:22:54 +00:00
|
|
|
int previous_wuid;
|
|
|
|
bool has_successor;
|
2002-07-16 23:37:54 +00:00
|
|
|
char name[256]; // Name of the workunit
|
2002-04-30 22:22:54 +00:00
|
|
|
char xml_doc[MAX_BLOB_SIZE];
|
|
|
|
int batch;
|
2002-08-26 22:57:17 +00:00
|
|
|
double rsc_fpops; // estimated # of FP operations
|
|
|
|
double rsc_iops; // estimated # of integer operations
|
|
|
|
double rsc_memory; // estimated size of RAM working set (bytes)
|
|
|
|
double rsc_disk; // estimated amount of disk needed (bytes)
|
2002-04-30 22:22:54 +00:00
|
|
|
bool dynamic_results;
|
|
|
|
// whether to create new results on demand
|
2002-08-26 22:57:17 +00:00
|
|
|
int max_results; // 0 if no limit
|
2002-04-30 22:22:54 +00:00
|
|
|
int nresults;
|
|
|
|
int nresults_unsent;
|
|
|
|
int nresults_done;
|
|
|
|
int nresults_fail;
|
2002-09-25 19:40:19 +00:00
|
|
|
bool need_validate; // this WU has at least 1 result in
|
|
|
|
// VALIDATE_STATE_NEED_CHECK state
|
|
|
|
int canonical_resultid; // ID of canonical result, or zero
|
|
|
|
double canonical_credit; // credit that all correct results get
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// the following not used in the DB
|
|
|
|
char app_name[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RESULT_STATE_INACTIVE 1
|
|
|
|
#define RESULT_STATE_UNSENT 2
|
|
|
|
#define RESULT_STATE_IN_PROGRESS 3
|
|
|
|
#define RESULT_STATE_DONE 4
|
|
|
|
#define RESULT_STATE_TIMEOUT 5
|
|
|
|
#define RESULT_STATE_ERROR 6
|
|
|
|
|
2002-09-25 19:40:19 +00:00
|
|
|
#define VALIDATE_STATE_INITIAL 0
|
|
|
|
#define VALIDATE_STATE_NEED_CHECK 1
|
|
|
|
#define VALIDATE_STATE_VALID 2
|
|
|
|
#define VALIDATE_STATE_INVALID 3
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
struct RESULT {
|
|
|
|
int id;
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int create_time;
|
|
|
|
int workunitid;
|
2002-09-26 05:57:10 +00:00
|
|
|
int state; // state (see above)
|
|
|
|
int hostid; // host processing this result
|
2002-08-26 22:57:17 +00:00
|
|
|
unsigned int report_deadline; // deadline for receiving result
|
|
|
|
unsigned int sent_time; // when result was sent to host
|
|
|
|
unsigned int received_time; // when result was received from host
|
|
|
|
char name[256];
|
|
|
|
int exit_status;
|
2002-09-26 05:57:10 +00:00
|
|
|
double cpu_time; // CPU time used to complete result
|
2002-04-30 22:22:54 +00:00
|
|
|
char xml_doc_in[MAX_BLOB_SIZE]; // descriptions of output files
|
|
|
|
char xml_doc_out[MAX_BLOB_SIZE]; // MD5s of output files
|
|
|
|
char stderr_out[MAX_BLOB_SIZE]; // stderr output, if any
|
|
|
|
int batch;
|
|
|
|
int project_state;
|
2002-09-25 19:40:19 +00:00
|
|
|
int validate_state;
|
|
|
|
double claimed_credit; // CPU time times host credit/sec
|
|
|
|
double granted_credit; // == canonical credit of WU
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// the following not used in the DB
|
|
|
|
char wu_name[256];
|
|
|
|
int parse_from_client(FILE*);
|
|
|
|
};
|
|
|
|
|
2002-08-14 05:43:05 +00:00
|
|
|
extern int db_open(char* dbname, char* passwd);
|
2002-04-30 22:22:54 +00:00
|
|
|
extern int db_close();
|
|
|
|
extern void db_print_error(char*);
|
|
|
|
extern int db_insert_id();
|
|
|
|
|
2002-08-25 07:54:33 +00:00
|
|
|
extern int db_project_new(PROJECT& p);
|
|
|
|
extern int db_project_enum(PROJECT& p);
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
extern int db_platform_new(PLATFORM& p);
|
|
|
|
extern int db_platform_enum(PLATFORM& p);
|
|
|
|
extern int db_platform_lookup_name(PLATFORM&);
|
|
|
|
|
|
|
|
extern int db_app_new(APP&);
|
|
|
|
extern int db_app(int, APP&);
|
|
|
|
extern int db_app_enum(APP&);
|
|
|
|
extern int db_app_update(APP&);
|
|
|
|
extern int db_app_lookup_name(APP&);
|
|
|
|
|
|
|
|
extern int db_app_version_new(APP_VERSION&);
|
|
|
|
extern int db_app_version_lookup(
|
|
|
|
int appid, int platformid, int version, APP_VERSION&
|
|
|
|
);
|
|
|
|
extern int db_app_version_enum(APP_VERSION&);
|
|
|
|
|
|
|
|
extern int db_user_new(USER&);
|
|
|
|
extern int db_user(int, USER&);
|
|
|
|
extern int db_user_update(USER&);
|
|
|
|
extern int db_user_lookup_auth(USER&);
|
|
|
|
extern int db_user_lookup_email_addr(USER&);
|
|
|
|
|
2002-07-11 20:35:05 +00:00
|
|
|
extern int db_team(int, TEAM&);
|
|
|
|
extern int db_team_new(TEAM&);
|
|
|
|
extern int db_team_update(TEAM&);
|
|
|
|
extern int db_team_lookup_name(TEAM&);
|
|
|
|
extern int db_team_lookup_name_lc(TEAM&);
|
|
|
|
extern int db_team_enum(TEAM&);
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
extern int db_host_new(HOST& p);
|
|
|
|
extern int db_host(int, HOST&);
|
|
|
|
extern int db_host_update(HOST&);
|
|
|
|
|
|
|
|
extern int db_workunit_new(WORKUNIT& p);
|
|
|
|
extern int db_workunit(int id, WORKUNIT&);
|
|
|
|
extern int db_workunit_update(WORKUNIT& p);
|
|
|
|
extern int db_workunit_lookup_name(WORKUNIT&);
|
2002-09-25 19:40:19 +00:00
|
|
|
//extern int db_workunit_enum_dynamic_to_send(WORKUNIT&, int);
|
|
|
|
extern int db_workunit_enum_app_need_validate(WORKUNIT&);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
extern int db_result_new(RESULT& p);
|
2002-08-28 21:50:51 +00:00
|
|
|
extern int db_result(int id, RESULT&);
|
2002-04-30 22:22:54 +00:00
|
|
|
extern int db_result_update(RESULT& p);
|
|
|
|
extern int db_result_lookup_name(RESULT& p);
|
|
|
|
extern int db_result_enum_to_send(RESULT&, int);
|
2002-09-25 19:40:19 +00:00
|
|
|
extern int db_result_enum_wuid(RESULT&);
|
2002-10-09 04:56:41 +00:00
|
|
|
extern int db_result_count_state(int state, int&);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#endif
|