예제 #1
0
function ResubmitTest($id)
{
    echo "{$id} - Resubmitting...";
    $testPath = './' . GetTestPath($id);
    if (gz_is_file("{$testPath}/testinfo.json")) {
        $test = json_decode(gz_file_get_contents("{$testPath}/testinfo.json"), true);
        if (array_key_exists('job_file', $test) && array_key_exists('location', $test) && is_file("{$testPath}/test.job")) {
            if ($lock = LockLocation($test['location'])) {
                if (copy("{$testPath}/test.job", $test['job_file'])) {
                    $files = scandir($testPath);
                    foreach ($files as $file) {
                        if ($file != '.' && $file != '..' && strncasecmp($file, 'test', 4)) {
                            if (is_file("{$testPath}/{$file}")) {
                                unlink("{$testPath}/{$file}");
                            } elseif (is_dir("{$testPath}/{$file}")) {
                                delTree("{$testPath}/{$file}");
                            }
                        }
                    }
                    AddJobFile($test['workdir'], $test['job'], $test['priority'], false);
                    $test['started'] = time();
                    unset($test['completeTime']);
                    gz_file_put_contents("{$testPath}/testinfo.json", json_encode($test));
                    echo "OK";
                } else {
                    echo "Failed to copy job file";
                }
                UnlockLocation($lock);
            } else {
                echo "Failed to lock location";
            }
        } else {
            echo "Invalid test";
        }
    } else {
        echo "Test not found";
    }
    echo "\n";
}
예제 #2
0
/**
* Write out the actual job file
*/
function WriteJob($location, &$test, &$job, $testId)
{
    $ret = false;
    global $error;
    global $locations;
    if ($locations[$location]['relayServer']) {
        // upload the test to a the relay server
        $test['id'] = $testId;
        $ret = SendToRelay($test, $job);
    } else {
        // make sure the work directory exists
        if (!is_dir($test['workdir'])) {
            mkdir($test['workdir'], 0777, true);
        }
        $workDir = $test['workdir'];
        $locationLock = LockLocation($location);
        if (isset($locationLock)) {
            if (isset($test['affinity'])) {
                $test['job'] = "Affinity{$test['affinity']}.{$test['job']}";
            }
            $fileName = $test['job'];
            $file = "{$workDir}/{$fileName}";
            if (file_put_contents($file, $job)) {
                if (AddJobFile($workDir, $fileName, $test['priority'], $test['queue_limit'])) {
                    // store a copy of the job file with the original test in case the test fails and we need to resubmit it
                    $test['job_file'] = realpath($file);
                    if (ValidateTestId($testId)) {
                        $testPath = GetTestPath($testId);
                        if (strlen($testPath)) {
                            $testPath = './' . $testPath;
                            if (!is_dir($testPath)) {
                                mkdir($testPath, 0777, true);
                            }
                            file_put_contents("{$testPath}/test.job", $job);
                        }
                    }
                    $tests = json_decode(file_get_contents("./tmp/{$location}.tests"), true);
                    if (!$tests) {
                        $tests = array();
                    }
                    $testCount = $test['runs'];
                    if (!$test['fvonly']) {
                        $testCount *= 2;
                    }
                    if (array_key_exists('tests', $tests)) {
                        $tests['tests'] += $testCount;
                    } else {
                        $tests['tests'] = $testCount;
                    }
                    file_put_contents("./tmp/{$location}.tests", json_encode($tests));
                    $ret = true;
                } else {
                    unlink($file);
                    $error = "Sorry, that test location already has too many tests pending.  Pleasy try again later.";
                }
            }
            UnlockLocation($locationLock);
        }
    }
    return $ret;
}