echo $query_response; } } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { // Verify the username in the attached JSON actually matches // the user in the auth header $body = file_get_contents('php://input'); $json_vars = json_decode($body, true); if (isset($json_vars['user'])) { if ($json_vars['user'] != $_SERVER['PHP_AUTH_USER']) { $msg = "User name in request body doesn't match user name in authorization header"; throw new MwsAuthorizationException($msg); } } else { throw new MwsErrorCodeException("JSON body must contain a user field."); } list($http_code, $response_body) = submit_job($body); // Success codes are 201 and 202. Errors are 4xx... if ($http_code == 201 || $http_code == 202) { // Add the job id, user and output file to the database $json_vars = json_decode($response_body, true); $jobID = $json_vars['id']; $outfile = $_GET['outfile']; $pdo = open_db(); add_row($pdo, $jobID, $_SERVER['PHP_AUTH_USER'], $outfile); # TODO: Should we enforce the existance of outfile? } if ($http_code == 201) { header('HTTP/1.1 201 Created'); } elseif ($http_code == 202) { header('HTTP/1.1 202 Accepted'); } else {
function submit_batch($user, $app) { $tmpfile = get_str('tmpfile'); $x = file_get_contents("{$tmpfile}"); $info = unserialize($x); $njobs = 0; $cmdlines = file($info->cmdline_file_path); foreach ($cmdlines as $cmdline) { if (preg_match("/^\\s*-var/", $cmdline)) { $njobs++; } } $now = time(); $batch_name = $info->area . "_" . date("Y-M-d D H:i:s"); $batch_id = BoincBatch::insert("(user_id, create_time, njobs, name, app_id, state) values ({$user->id}, {$now}, {$njobs}, '{$batch_name}', {$app->id}, " . BATCH_STATE_IN_PROGRESS . ")"); // $batch_id=99; $i = 0; foreach ($cmdlines as $cmdline) { if (preg_match("/^\\s*-var/", $cmdline)) { submit_job($app, $batch_id, $info, $cmdline, $i); $i++; } } }
function submit_batch($r) { $app = get_app($r); list($user, $user_submit) = authenticate_user($r, $app); $template = read_input_template($app); $jobs = xml_get_jobs($r); validate_batch($jobs, $template); stage_files($jobs, $template); $njobs = count($jobs); $now = time(); $batch_name = (string) $r->batch->batch_name; $batch_id = BoincBatch::insert("(user_id, create_time, njobs, name, app_id) values ({$user->id}, {$now}, {$njobs}, '{$batch_name}', {$app->id})"); $i = 0; foreach ($jobs as $job) { submit_job($job, $template, $app, $batch_id, $i++); } $batch = BoincBatch::lookup_id($batch_id); $batch->update("state=" . BATCH_STATE_IN_PROGRESS); echo "<batch_id>{$batch_id}</batch_id>\n"; }