Пример #1
0
function submit_batch($r)
{
    xml_start_tag("submit_batch");
    $app = get_submit_app((string) $r->batch->app_name);
    list($user, $user_submit) = authenticate_user($r, $app);
    $template = read_input_template($app, $r);
    $jobs = xml_get_jobs($r);
    validate_batch($jobs, $template);
    stage_files($jobs, $template);
    $njobs = count($jobs);
    $now = time();
    $batch_id = (int) $r->batch->batch_id;
    if ($batch_id) {
        $batch = BoincBatch::lookup_id($batch_id);
        if (!$batch) {
            xml_error(-1, "BOINC server: no batch {$batch_id}");
        }
        if ($batch->user_id != $user->id) {
            xml_error(-1, "BOINC server: not owner of batch");
        }
        if ($batch->state != BATCH_STATE_INIT) {
            xml_error(-1, "BOINC server: batch not in init state");
        }
    }
    // - compute batch FLOP count
    // - run adjust_user_priorities to increment user_submit.logical_start_time
    // - use that for batch logical end time and job priority
    //
    $total_flops = 0;
    foreach ($jobs as $job) {
        if ($job->rsc_fpops_est) {
            $total_flops += $job->rsc_fpops_est;
        } else {
            $x = (double) $template->workunit->rsc_fpops_est;
            if ($x) {
                $total_flops += $x;
            } else {
                xml_error(-1, "BOINC server: no rsc_fpops_est given");
            }
        }
    }
    $cmd = "cd " . project_dir() . "/bin; ./adjust_user_priority --user {$user->id} --flops {$total_flops} --app {$app->name}";
    $x = exec($cmd);
    if (!is_numeric($x) || (double) $x == 0) {
        xml_error(-1, "BOINC server: {$cmd} returned {$x}");
    }
    $let = (double) $x;
    if ($batch_id) {
        $njobs = count($jobs);
        $ret = $batch->update("njobs={$njobs}, logical_end_time={$let}");
        if (!$ret) {
            xml_error(-1, "BOINC server: batch->update() failed");
        }
    } else {
        $batch_name = (string) $r->batch->batch_name;
        $batch_name = BoincDb::escape_string($batch_name);
        $batch_id = BoincBatch::insert("(user_id, create_time, njobs, name, app_id, logical_end_time, state) values ({$user->id}, {$now}, {$njobs}, '{$batch_name}', {$app->id}, {$let}, " . BATCH_STATE_INIT . ")");
        if (!$batch_id) {
            xml_error(-1, "BOINC server: Can't create batch: " . BoincDb::error());
        }
        $batch = BoincBatch::lookup_id($batch_id);
    }
    if ($r->batch->result_template_file) {
        $result_template_file = $r->batch->result_template_file;
    } else {
        $result_template_file = null;
    }
    if ($r->batch->workunit_template_file) {
        $workunit_template_file = $r->batch->workunit_template_file;
    } else {
        $workunit_template_file = null;
    }
    submit_jobs($jobs, $template, $app, $batch_id, $let, $result_template_file, $workunit_template_file);
    // set state to IN_PROGRESS only after creating jobs;
    // otherwise we might flag batch as COMPLETED
    //
    $ret = $batch->update("state= " . BATCH_STATE_IN_PROGRESS);
    if (!$ret) {
        xml_error(-1, "BOINC server: batch->update() failed");
    }
    echo "<batch_id>{$batch_id}</batch_id>\n        </submit_batch>\n    ";
}
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";
}