From ad2fe67886b7b6ec3a05648000fb091752132f85 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 16 Oct 2007 17:12:48 +0000 Subject: [PATCH] - Initial checkin of Bossa code. This isn't part of BOINC and eventually it should go in a different repository, but for now I'm putting it here. svn path=/trunk/boinc/; revision=13851 --- checkin_notes | 14 +++++ html/inc/bossa_db.inc | 83 ++++++++++++++++++++++++++++ html/ops/bossa_make_jobs_example.php | 31 +++++++++++ html/ops/bossa_setup_example.php | 21 +++++++ html/user/bossa_get_job.php | 30 ++++++++++ 5 files changed, 179 insertions(+) create mode 100644 html/inc/bossa_db.inc create mode 100644 html/ops/bossa_make_jobs_example.php create mode 100644 html/ops/bossa_setup_example.php create mode 100644 html/user/bossa_get_job.php diff --git a/checkin_notes b/checkin_notes index 4fe0dd23e4..1e4fcb984d 100644 --- a/checkin_notes +++ b/checkin_notes @@ -9520,3 +9520,17 @@ Bruce 15 Oct 2007 inc/ db_ops.inc +David 16 Oct 2007 + - Initial checkin of Bossa code. + This isn't part of BOINC and eventually + it should go in a different repository, + but for now I'm putting it here. + + html/ + inc/ + bossa_db.inc + ops/ + bossa_make_jobs_example.php + bossa_setup_example.php + user/ + bossa_get_job.php diff --git a/html/inc/bossa_db.inc b/html/inc/bossa_db.inc new file mode 100644 index 0000000000..e700aa7cab --- /dev/null +++ b/html/inc/bossa_db.inc @@ -0,0 +1,83 @@ +long_jobs) $app->long_jobs = 0; + $now = time(); + $query = "insert into bossa_app (create_time, name, user_friendly_name, long_jobs, start_url, finish_url) values ($now, '$app->name', '$app->user_friendly_name', $app->long_jobs, '$app->start_url', '$app->finish_url')"; + echo $query; + $result = mysql_query($query); + if (!$result) return false; + $app->id = mysql_insert_id(); + return true; + } + + function app_lookup_name($name) { + $result = mysql_query("select * from bossa_app where name='$name'"); + if (!$result) return null; + $app = mysql_fetch_object($result); + mysql_free_result($result); + return $app; + } + + function app_lookup_id($id) { + $result = mysql_query("select * from bossa_app where id='$id'"); + if (!$result) return null; + $app = mysql_fetch_object($result); + mysql_free_result($result); + return $app; + } + + function insert_job(&$job) { + $now = time(); + $query = "insert into bossa_job (create_time, name, app_id, info, batch, time_estimate, time_limit, more_needed, npending, nsuccess, nsuccess_needed) values ($now, '$job->name', $job->app_id, '$job->info', $job->batch, $job->time_estimate, $job->time_limit, 1, 0, 0, $job->nsuccess_needed)"; + $result = mysql_query($query); + if (!$result) { + echo "$query\n"; + return false; + } + $job->id = mysql_insert_id(); + return true; + } + + function insert_job_inst(&$ji) { + $now = time(); + $query = "insert into bossa_job_inst (create_time, job_id, user_id) values ($now, $ji->job_id, $ji->user_id)"; + $result = mysql_query($query); + if (!$result) { + echo "$query\n"; + return false; + } + $ji->id = mysql_insert_id(); + return true; + } + + // Assign a job from the given app to the given user. + // Returns the job instance or NULL. + // + function assign_job($app, $user) { + // this query skips jobs for which this user + // has already been assigned an instance + // + $query = "select bossa_job.* from bossa_job left join bossa_job_inst on bossa_job_inst.job_id = bossa_job.id where bossa_job.more_needed<>0 and bossa_job_inst.user_id is null limit 1"; + echo "$query\n"; + $result = mysql_query($query); + if (!$result) return null; + $job = mysql_fetch_object($result); + mysql_free_result($result); + + echo "
"; + print_r($job); + echo "
"; + $ji->user_id = $user->id; + $ji->job_id = $job->id; + + if (!Bossa::insert_job_inst($ji)) { + echo mysql_error(); + return null; + } + return $ji; + } +} + +?> diff --git a/html/ops/bossa_make_jobs_example.php b/html/ops/bossa_make_jobs_example.php new file mode 100644 index 0000000000..50abbbf086 --- /dev/null +++ b/html/ops/bossa_make_jobs_example.php @@ -0,0 +1,31 @@ +app_id = $app->id; + $job->batch = 0; + $job->time_estimate = 30; + $job->time_limit = 600; + $job->nsuccess_needed = 3; + for ($i=0; $i<10; $i++) { + $job->name = "job_$i"; + $job->job_info = "$i"; + if (!Bossa::insert_job($job)) { + echo "failed: ", mysql_error(); + exit(1); + } + } +} + +make_jobs(); + +?> diff --git a/html/ops/bossa_setup_example.php b/html/ops/bossa_setup_example.php new file mode 100644 index 0000000000..eb1a1217c4 --- /dev/null +++ b/html/ops/bossa_setup_example.php @@ -0,0 +1,21 @@ +name = 'bossa_test'; +$ba->user_friendly_name = 'Simple pattern recognition'; +$ba->start_url = 'test_start.php'; + +if (Bossa::insert_app($ba)) { + echo "success\n"; +} else { + echo "failed ", mysql_error(); +} + +?> diff --git a/html/user/bossa_get_job.php b/html/user/bossa_get_job.php new file mode 100644 index 0000000000..9ed1e8c8c0 --- /dev/null +++ b/html/user/bossa_get_job.php @@ -0,0 +1,30 @@ +start_url."&job_info=".$job->job_info; + Header("Location: $url"); +} else { + page_head("No jobs available"); + echo " + Sorry, no jobs are available right not. + Please try again later. + "; + page_tail(); +} +?>