Пример #1
0
 /**
  * @requestParam browserSet string: Show useragents from a specific
  * browserset only.
  * @requestParam onlyactive bool: If true, only user agents that
  * have online clients and/or pending runs are included.
  * If both "browserSet" and "onlyactive" are used, the overlaping
  * subset will be output.
  */
 public function doAction()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $showOnlyactive = $request->hasKey("onlyactive");
     $filterBrowserSet = $request->getVal("browserSet", false);
     $data = array("userAgents" => array());
     $uaIndex = BrowserInfo::getSwarmUAIndex();
     foreach ($uaIndex as $uaID => $uaData) {
         if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$filterBrowserSet})) {
             continue;
         }
         // Count online clients with this UA
         $clients = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(id)\n\t\t\t\tFROM clients\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   updated > %s", $uaID, swarmdb_dateformat(strtotime('1 minute ago'))));
         $clients = intval($clients);
         // Count pending runs for this UA
         $pendingRuns = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   status = 0;", $uaID));
         $pendingRuns = intval($pendingRuns);
         // Count past runs that can still be re-run to
         // possibly fix non-passing results
         $pendingReRuns = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   runs < max\n\t\t\t\tAND   completed > 0;", $uaID));
         $pendingReRuns = intval($pendingReRuns);
         if ($showOnlyactive && !$clients && !$pendingRuns && !$pendingReRuns) {
             continue;
         }
         $data["userAgents"][$uaID] = array("data" => $uaData, "stats" => array("onlineClients" => $clients, "pendingRuns" => $pendingRuns, "pendingReRuns" => $pendingReRuns));
     }
     $this->setData($data);
 }
Пример #2
0
    /**
     * @requestParam browserSet string: Show useragents from a specific
     * browserset only.
     * @requestParam onlyactive bool: If true, only user agents that
     * have online clients and/or pending runs are included.
     * If both "browserSet" and "onlyactive" are used, the overlaping
     * subset will be output.
     */
    public function doAction()
    {
        $conf = $this->getContext()->getConf();
        $db = $this->getContext()->getDB();
        $request = $this->getContext()->getRequest();
        $showOnlyactive = $request->getBool('onlyactive');
        $filterBrowserSet = $request->getVal('browserSet', false);
        $data = array('userAgents' => array());
        $uaIndex = BrowserInfo::getSwarmUAIndex();
        foreach ($uaIndex as $uaID => $uaData) {
            if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$filterBrowserSet})) {
                continue;
            }
            // Count online clients with this UA
            $clients = $db->getOne(str_queryf('SELECT
					COUNT(id)
				FROM clients
				WHERE useragent_id = %s
				AND   updated > %s', $uaID, swarmdb_dateformat(time() - ($conf->client->pingTime + $conf->client->pingTimeMargin))));
            $clients = intval($clients);
            // Count active runs for this UA
            $activeRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 1;', $uaID));
            $activeRuns = intval($activeRuns);
            // Count pending runs for this UA
            $pendingRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed = 0;', $uaID));
            $pendingRuns = intval($pendingRuns);
            // Count past runs that can still be re-run to
            // possibly fix non-passing results
            $pendingReRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed > 0;', $uaID));
            $pendingReRuns = intval($pendingReRuns);
            if ($showOnlyactive && !$clients && !$activeRuns && !$pendingRuns && !$pendingReRuns) {
                continue;
            }
            $data['userAgents'][$uaID] = array('data' => $uaData, 'stats' => array('onlineClients' => $clients, 'activeRuns' => $activeRuns, 'pendingRuns' => $pendingRuns, 'pendingReRuns' => $pendingReRuns));
        }
        $this->setData($data);
    }
Пример #3
0
 protected function execute()
 {
     $conf = $this->getContext()->getConf();
     $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
     // Output
     $set = $this->getOption('set');
     if ($set) {
         if (isset($conf->browserSets->{$set})) {
             $this->out("{$set}:\n* " . implode("\n* ", $conf->browserSets->{$set}));
         } else {
             $this->error("Browser set `{$set}` does not exist.");
         }
     } else {
         foreach ($conf->browserSets as $set => $browsers) {
             $this->out("\n{$set}:\n* " . implode("\n* ", $browsers));
         }
         $this->out("\n(everything):\n* " . implode("\n* ", array_keys(get_object_vars($swarmUaIndex))));
     }
 }
Пример #4
0
}
$defaultSettings = json_decode(file_get_contents($defaultSettingsFile));
$localSettings = json_decode(file_get_contents($localSettingsFile));
if (!$defaultSettings) {
    echo "<b>TestSwarm Fatal:</b> Default settings file contains invalid JSON.\n";
    exit;
}
if (!$localSettings) {
    echo "<b>TestSwarm Fatal:</b> Local settings file contains invalid JSON.\n";
    exit;
}
$swarmConfig = object_merge($defaultSettings, $localSettings);
unset($defaultSettingsFile, $localSettingsFile, $defaultSettings, $localSettings);
// Validate browserSets
// Must be after AutoLoad
$swarmUaIndex = BrowserInfo::getSwarmUAIndex();
foreach ($swarmConfig->browserSets as $set => $browsers) {
    foreach ($browsers as $browser) {
        if (!isset($swarmUaIndex->{$browser})) {
            echo "<b>TestSwarm Fatal</b>: Invalid browser ID \"<code>{$browser}</code>\" in browser set \"<code>{$set}</code>\" !\n";
            exit;
        }
    }
}
// Timezone
date_default_timezone_set($swarmConfig->general->timezone);
// Auto-populate web.server
if ($swarmConfig->web->server === null) {
    $server = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
    if (isset($_SERVER["HTTP_HOST"])) {
        $server .= $_SERVER["HTTP_HOST"];
Пример #5
0
    protected function getAddjobFormHtml()
    {
        $conf = $this->getContext()->getConf();
        $request = $this->getContext()->getRequest();
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $addjobPageUrl = htmlspecialchars(swarmpath("addjob"));
        $userName = $request->getSessionData("username") && $request->getSessionData("auth") == "yes" ? htmlspecialchars($request->getSessionData("username")) : "";
        $formHtml = <<<HTML
<form action="{$addjobPageUrl}" method="post" class="form-horizontal">

\t<fieldset>
\t\t<legend>Authentication</legend>

\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-authUsername">User name:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="authUsername" value="{$userName}" id="form-authUsername">
\t\t\t</div>
\t\t</div>
\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-authToken">Auth token:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="authToken" id="form-authToken" class="input-xlarge">
\t\t\t</div>
\t\t</div>
\t</fieldset>

\t<fieldset>
\t\t<legend>Job information</legend>

\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-jobName">Job name:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="jobName" id="form-jobName" class="input-xlarge" maxlength="255">
\t\t\t\t<span class="help-inline">HTML, up to 255 characters</span>
\t\t\t</div>
\t\t</div>
\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-runMax">Run max:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="number" size="5" name="runMax" id="form-runMax" value="2" min="1" max="99">
\t\t\t\t<p class="help-block">This is the maximum number of times a run is ran in a user agent. If a run passes
\t\t\t\twithout failures then it is only ran once. If it does not pass, TestSwarm will re-try the run
\t\t\t\t(up to "Run max" times) for that useragent to avoid error pollution due to time-outs, slow
\t\t\t\tcomputers or other unrelated conditions that can cause the server to not receive a success report.</p>
\t\t\t</div>
\t\t</div>
\t</fieldset>

\t<fieldset>
\t\t<legend>Browsers</legend>

\t\t<p>Choose which groups of user agents this job should be ran in. Some of the groups may
\t\toverlap each other, TestSwarm will detect and remove duplicate entries in the resulting set.</p>

HTML;
        foreach ($conf->browserSets as $set => $browsers) {
            $set = htmlspecialchars($set);
            $browsersHtml = '';
            $last = count($browsers) - 1;
            foreach ($browsers as $i => $browser) {
                if ($i !== 0) {
                    $browsersHtml .= $i === $last ? '<br> and ' : ',<br>';
                } else {
                    $browsersHtml .= '<br>';
                }
                $browsersHtml .= htmlspecialchars($swarmUaIndex->{$browser}->displaytitle);
            }
            $formHtml .= <<<HTML
\t\t<div class="control-group">
\t\t\t<label class="checkbox" for="form-browserset-{$set}">
\t\t\t\t<input type="checkbox" name="browserSets[]" value="{$set}" id="form-browserset-{$set}">
\t\t\t\t<strong>{$set}</strong>: {$browsersHtml}.
\t\t\t</label>
\t\t</div>
HTML;
        }
        $formHtml .= <<<HTML
\t</fieldset>

\t<fieldset>
\t\t<legend>Runs</legend>

\t\t<p>Each job consists of several runs. Every run has a name and a url to where that test suite can be ran. All the test suites should probably have the same common code base or some other grouping characteristic, where each run is part of the larger test suite. As example, for a QUnit test suite the <code>filter</code> url parameter can be used to only run one of the "modules" so every run would be the name of that module and the URL to the testsuite with <code>?filter=modulename</code> appended to it.</p>

\t\t<div id="runs-container" class="well">
\t\t\t<fieldset>
\t\t\t\t<legend>Run 1</legend>

\t\t\t\t<label for="form-runNames1">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames1" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls1">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls1">
\t\t\t</fieldset>
\t\t\t<fieldset>
\t\t\t\t<legend>Run 2</legend>

\t\t\t\t<label for="form-runNames2">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames2" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls2">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls2">
\t\t\t</fieldset>
\t\t\t<fieldset>
\t\t\t\t<legend>Run 3</legend>

\t\t\t\t<label for="form-runNames3">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames3" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls3">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls3">
\t\t\t</fieldset>
\t\t</div>
\t</fieldset>

\t<div class="form-actions">
\t\t<input type="submit" value="Create job" class="btn btn-primary btn-large">
\t</div>
</form>
HTML;
        return $formHtml;
    }
Пример #6
0
    protected function getAddjobFormHtml()
    {
        $conf = $this->getContext()->getConf();
        $request = $this->getContext()->getRequest();
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $addjobPageUrl = htmlspecialchars(swarmpath("adddevboxjob"));
        $userName = $request->getSessionData("username") && $request->getSessionData("auth") == "yes" ? htmlspecialchars($request->getSessionData("username")) : "";
        // fields to be taken from the querystring:
        $jobName = $request->getVal('jobName');
        $runMax = $request->getVal('runMax') ?: 3;
        $runNames = $request->getArray('runNames');
        $runUrls = $request->getArray('runUrls');
        $selectedBrowsers = $request->getArray('browsers');
        if ($runNames && !$runUrls || !$runNames && $runUrls || $runNames && $runUrls && count($runNames) != count($runUrls)) {
            throw new SwarmException("runNames and runUrls must have the same number of elements in the array");
            return;
        }
        $formHtml = <<<HTML
\t\t\t
<form action="{$addjobPageUrl}" method="post" class="form-horizontal">
\t<div class="row">
\t\t<div class="span6">
HTML;
        $formHtml .= $this->getBrowsers($conf, $swarmUaIndex, $selectedBrowsers);
        $formHtml .= <<<HTML
\t\t</div>
\t\t<div class="span6">
\t\t\t
HTML;
        $formHtml .= <<<HTML

\t\t\t<fieldset>
\t\t\t\t<legend>Runs <i class="icon-question-sign po" data-title="Runs" data-content='Each job consists of several runs. Every run has a name and a url to where that test suite can be ran. All the test suites should probably have the same common code base or some other grouping characteristic, where each run is part of the larger test suite. As example, for a QUnit test suite the <code>filter</code> url parameter can be used to only run one of the "modules" so every run would be the name of that module and the URL to the testsuite with <code>?filter=modulename</code> appended to it.'></i></legend>

\t\t\t\t<label class="control-label" for="button-TickRuns">Ticked runs: &nbsp;</label>

\t\t\t\t<div class="btn-group" data-toggle="buttons-radio" id="button-TickRuns">
\t\t\t\t\t<button class="btn all" type="button">all</button>
\t\t\t\t\t<button class="btn none" type="button">none</button>
\t\t\t\t\t<button class="btn same" type="button">same as last time</button>
\t\t\t\t\t<i class="icon-question-sign po" data-title="Same as last time" data-content='Restores runMax, browserSets and runNames fields from the cookie. runMax value is put into the form field. browserSets are ticked. Runs from the cookie are matched against runs in the html form value.'></i>
\t\t\t\t</div>
\t\t\t\t<div id="runs-container" class="well">
HTML;
        if ($runNames && count($runNames) > 0) {
            for ($i = 0; $i < count($runNames); $i++) {
                $formHtml .= $this->getRun($i + 1, $runNames[$i], $runUrls[$i]);
            }
        } else {
            for ($i = 0; $i < 3; $i++) {
                $formHtml .= $this->getRun($i + 1, $runNames[$i], $runUrls[$i]);
            }
        }
        $formHtml .= <<<HTML
\t\t\t\t</div>
\t\t\t</fieldset>
\t\t\t
\t\t\t<button class="btn" id="btnOtherInformation" type="button">Other information</button>
\t\t\t
\t\t\t<div class="well hide" id="otherInformation">
\t\t\t\t<fieldset>
\t\t\t\t\t<legend>Other information</legend>

\t\t\t\t\t<div class="control-group">
\t\t\t\t\t\t<label class="control-label" for="form-authUsername">User name:</label>
\t\t\t\t\t\t<div class="controls">
\t\t\t\t\t\t\t<input type="text" value="{$userName}" id="form-authUsername" disabled="disabled">
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="control-group">
\t\t\t\t\t\t<label class="control-label" for="form-runMax">Run max:</label>
\t\t\t\t\t\t<div class="controls">
\t\t\t\t\t\t\t<input type="number" size="5" name="runMax" id="form-runMax" value="{$runMax}" min="1" max="99">
\t\t\t\t\t\t\t<i class="icon-question-sign po" data-title="Run max" data-content='This is the maximum number of times a run is ran in a user agent. If a run passes
\t\t\t\t\t\t\twithout failures then it is only ran once. If it does not pass, TestSwarm will re-try the run
\t\t\t\t\t\t\t(up to "Run max" times) for that useragent to avoid error pollution due to time-outs, slow
\t\t\t\t\t\t\tcomputers or other unrelated conditions that can cause the server to not receive a success report.'></i>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</fieldset>
\t\t\t\t<input type="hidden" name="jobName" id="form-jobName" maxlength="255" value="{$jobName}">
\t\t\t</div>
\t\t</div>
\t</div>
\t
\t<div class="form-actions">
\t\t<input type="submit" value="Create job" class="btn btn-primary btn-large">
\t</div>
</form>
HTML;
        return $formHtml;
    }
Пример #7
0
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $userName = $request->getVal("item");
     if (!$userName) {
         $this->setError("missing-parameters");
         return;
     }
     $userID = $db->getOne(str_queryf("SELECT id FROM users WHERE name = %s;", $userName));
     $userID = intval($userID);
     if (!$userID) {
         $this->setError("invalid-input", "User does not exist");
         return;
     }
     $uaIndex = BrowserInfo::getSwarmUAIndex();
     // Active clients
     $activeClients = array();
     $clientRows = $db->getRows(str_queryf("SELECT\n\t\t\t\tuseragent_id,\n\t\t\t\tuseragent,\n\t\t\t\tcreated\n\t\t\tFROM\n\t\t\t\tclients\n\t\t\tWHERE user_id = %u\n\t\t\tAND   updated > %s\n\t\t\tORDER BY created DESC;", $userID, swarmdb_dateformat(strtotime("1 minutes ago"))));
     if ($clientRows) {
         foreach ($clientRows as $clientRow) {
             $bi = BrowserInfo::newFromContext($this->getContext(), $clientRow->useragent);
             $activeClient = array("uaID" => $clientRow->useragent_id, "uaRaw" => $bi->getRawUA(), "uaData" => $bi->getSwarmUaItem(), "uaBrowscap" => $bi->getBrowscap());
             self::addTimestampsTo($activeClient, $clientRow->created, "connected");
             $activeClients[] = $activeClient;
         }
     }
     // Recent jobs
     $recentJobs = array();
     // List of all user agents used in recent jobs
     // This is as helper allow creating proper gaps when iterating
     // over jobs.
     $userAgents = array();
     $jobRows = $db->getRows(str_queryf("SELECT\n\t\t\t\tid,\n\t\t\t\tname\n\t\t\tFROM\n\t\t\t\tjobs\n\t\t\tWHERE jobs.user_id = %u\n\t\t\tORDER BY jobs.created DESC\n\t\t\tLIMIT 15;", $userID));
     if ($jobRows) {
         $uaRunStatusStrength = array_flip(array("passed", "new", "progress", "failed", "timedout", "error"));
         foreach ($jobRows as $jobRow) {
             $jobID = intval($jobRow->id);
             $jobActionContext = $this->getContext()->createDerivedRequestContext(array("action" => "job", "item" => $jobID), "GET");
             $jobAction = JobAction::newFromContext($jobActionContext);
             $jobAction->doAction();
             if ($jobAction->getError()) {
                 $this->setError($jobAction->getError());
                 return;
             }
             $jobActionData = $jobAction->getData();
             // Add user agents array of this job to the overal user agents list.
             // php array+ automatically fixes clashing keys. The values are always the same
             // so it doesn't matter whether or not it overwrites.
             $userAgents += $jobActionData["userAgents"];
             // The summerized status for each user agent run
             // of this job. e.g. if all are new except one,
             // then it will be on "progress", if all are complete
             // then the worst failure is put in the summary
             $uaSummary = array();
             $uaNotNew = array();
             $uaHasIncomplete = array();
             $uaStrongestStatus = array();
             foreach ($jobActionData["runs"] as $run) {
                 foreach ($run["uaRuns"] as $uaID => $uaRun) {
                     if ($uaRun["runStatus"] !== "new" && !in_array($uaID, $uaNotNew)) {
                         $uaNotNew[] = $uaID;
                     }
                     if ($uaRun["runStatus"] === "new" || $uaRun["runStatus"] === "progress") {
                         if (!in_array($uaID, $uaHasIncomplete)) {
                             $uaHasIncomplete[] = $uaID;
                         }
                     }
                     if (!isset($uaStrongestStatus[$uaID]) || $uaRunStatusStrength[$uaRun["runStatus"]] > $uaRunStatusStrength[$uaStrongestStatus[$uaID]]) {
                         $uaStrongestStatus[$uaID] = $uaRun["runStatus"];
                     }
                     $uaSummary[$uaID] = !in_array($uaID, $uaNotNew) ? "new" : (in_array($uaID, $uaHasIncomplete) ? "progress" : $uaStrongestStatus[$uaID]);
                 }
             }
             $recentJobs[] = array("id" => $jobID, "name" => $jobRow->name, "url" => swarmpath("job/{$jobID}", "fullurl"), "uaSummary" => $uaSummary);
         }
     }
     natcaseksort($userAgents);
     $this->setData(array("userName" => $userName, "activeClients" => $activeClients, "recentJobs" => $recentJobs, "uasInJobs" => $userAgents));
 }
Пример #8
0
    /**
     * @param Database $db
     * @param array $runRows: one or more rows from the `runs` table.
     * @return array with properties 'runs' and 'userAgents'
     */
    public static function getDataFromRunRows(Database $db, $runRows)
    {
        $userAgentIDs = array();
        $runs = array();
        foreach ($runRows as $runRow) {
            $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url);
            $runUaRuns = array();
            // Get list of useragents that this run is scheduled for
            $runUaRows = $db->getRows(str_queryf('SELECT
					status,
					useragent_id,
					results_id
				FROM
					run_useragent
				WHERE run_useragent.run_id = %u;', $runRow->id));
            if ($runUaRows) {
                foreach ($runUaRows as $runUaRow) {
                    // Add UA ID to the list. After we've collected
                    // all the UA IDs we'll perform one query for all of them
                    // to gather the info from the useragents table
                    $userAgentIDs[] = $runUaRow->useragent_id;
                    if (!$runUaRow->results_id) {
                        $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new');
                    } else {
                        $runresultsRow = $db->getRow(str_queryf('SELECT
								client_id,
								status,
								total,
								fail,
								error
							FROM runresults
							WHERE id = %u;', $runUaRow->results_id));
                        if (!$runresultsRow) {
                            $this->setError('data-corrupt');
                            return;
                        }
                        $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total)));
                    }
                }
                natcaseksort($runUaRuns);
                $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns);
            }
        }
        // Get information for all encounted useragents
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $userAgents = array();
        foreach ($userAgentIDs as $userAgentID) {
            if (!isset($swarmUaIndex->{$userAgentID})) {
                throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`.");
            } else {
                $userAgents[$userAgentID] = (array) $swarmUaIndex->{$userAgentID};
            }
        }
        natcaseksort($userAgents);
        return array('runs' => $runs, 'userAgents' => $userAgents);
    }
Пример #9
0
 /**
  * @actionParam item int: Job ID.
  */
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $jobID = $request->getInt("item");
     if (!$jobID) {
         $this->setError("missing-parameters");
         return;
     }
     // Get job information
     $jobRow = $db->getRow(str_queryf("SELECT\n\t\t\t\tjobs.id as job_id,\n\t\t\t\tjobs.name as job_name,\n\t\t\t\tjobs.created as job_created,\n\t\t\t\tusers.name as user_name\n\t\t\tFROM\n\t\t\t\tjobs, users\n\t\t\tWHERE jobs.id = %u\n\t\t\tAND   users.id = jobs.user_id;", $jobID));
     if (!$jobRow) {
         $this->setError("invalid-input", "Job not found");
         return;
     }
     if (!$jobRow->job_id || !$jobRow->job_name || !$jobRow->user_name) {
         $this->setError("data-corrupt");
         return;
     }
     // Get runs for this job
     $runRows = $db->getRows(str_queryf("SELECT\n\t\t\t\truns.id as run_id,\n\t\t\t\truns.url as run_url,\n\t\t\t\truns.name as run_name\n\t\t\tFROM\n\t\t\t\truns\n\t\t\tWHERE runs.job_id = %u\n\t\t\tORDER BY run_id;", $jobID));
     // Start of response data
     $respData = array("jobInfo" => array("id" => $jobID, "name" => $jobRow->job_name, "ownerName" => $jobRow->user_name, "creationTimestamp" => $jobRow->job_created), "runs" => array(), "userAgents" => array());
     $userAgentIDs = array();
     foreach ($runRows as $runRow) {
         $runInfo = array("id" => $runRow->run_id, "name" => $runRow->run_name, "url" => $runRow->run_url);
         $runUaRuns = array();
         // Get list of useragents that this run is scheduled for
         $runUaRows = $db->getRows(str_queryf("SELECT\n\t\t\t\t\truns,\n\t\t\t\t\tmax,\n\t\t\t\t\tstatus,\n\t\t\t\t\tuseragent_id\n\t\t\t\tFROM\n\t\t\t\t\trun_useragent\n\t\t\t\tWHERE run_useragent.run_id = %u;", $runRow->run_id));
         if ($runUaRows) {
             foreach ($runUaRows as $runUaRow) {
                 // Create array for this ua run,
                 // If it has been run or is currently running,
                 // this array will be re-created in the loop over $clientRunRows
                 $runUaRuns[$runUaRow->useragent_id] = array("runStatus" => self::resolveStatusID((int) $runUaRow->status), "runRuns" => (int) $runUaRow->runs, "runMax" => (int) $runUaRow->max);
                 // Add UA ID to the list. After we've collected
                 // all the UA IDs we'll perform one query for all of them
                 // to gather the info from the useragents table
                 $userAgentIDs[] = $runUaRow->useragent_id;
             }
         }
         // Get client results for this run
         $clientRunRows = $db->getRows(str_queryf("SELECT\n\t\t\t\t\trun_client.client_id as client_id,\n\t\t\t\t\trun_client.status as status,\n\t\t\t\t\trun_client.fail as fail,\n\t\t\t\t\trun_client.error as error,\n\t\t\t\t\trun_client.total as total,\n\t\t\t\t\tclients.useragent_id as useragent_id\n\t\t\t\tFROM\n\t\t\t\t\trun_client, clients\n\t\t\t\tWHERE run_client.run_id = %u\n\t\t\t\tAND   run_client.client_id = clients.id\n\t\t\t\tORDER BY useragent_id;", $runRow->run_id));
         if ($clientRunRows) {
             foreach ($clientRunRows as $clientRunRow) {
                 $runUaRuns[$clientRunRow->useragent_id] = array_merge($runUaRuns[$clientRunRow->useragent_id], array("useragentID" => $clientRunRow->useragent_id, "clientID" => $clientRunRow->client_id, "failedTests" => $clientRunRow->fail, "totalTests" => $clientRunRow->total, "errors" => $clientRunRow->error, "runStatus" => self::getStatusFromClientRunRow($clientRunRow), "runResultsUrl" => swarmpath("index.php", "fullurl") . "?" . http_build_query(array("action" => "runresults", "run_id" => $runRow->run_id, "client_id" => $clientRunRow->client_id)), "runResultsLabel" => $clientRunRow->status < 2 ? "" : ($clientRunRow->total < 0 ? "" : ($clientRunRow->error > 0 ? $clientRunRow->error : ($clientRunRow->fail > 0 ? $clientRunRow->fail : $clientRunRow->total)))));
             }
             natcaseksort($runUaRuns);
         }
         $respData["runs"][] = array("info" => $runInfo, "uaRuns" => $runUaRuns);
     }
     // Get information for all encounted useragents
     $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
     foreach ($userAgentIDs as $userAgentID) {
         if (!isset($swarmUaIndex->{$userAgentID})) {
             throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`.");
         } else {
             $respData["userAgents"][$userAgentID] = (array) $swarmUaIndex->{$userAgentID};
         }
     }
     natcaseksort($respData["userAgents"]);
     // Save data
     $this->setData($respData);
 }
Пример #10
0
 /**
  * @actionMethod POST: Required.
  * @actionParam jobName string: May contain HTML.
  * @actionParam runMax int
  * @actionParam runNames array
  * @actionParam runUrls array
  * @actionParam browserSets array
  * @actionParam string authUsername
  * @actionParam string authToken
  * @actionAuth: Yes.
  */
 public function doAction()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $userId = $this->doRequireAuth();
     if (!$userId) {
         return;
     }
     $jobName = $request->getVal("jobName");
     $runMax = $request->getInt("runMax");
     $runNames = $request->getArray("runNames");
     $runUrls = $request->getArray("runUrls");
     $browserSets = $request->getArray("browserSets");
     if (!$jobName || !$runNames || !count($runNames) || !$runUrls || !count($runUrls) || !$browserSets || !count($browserSets)) {
         $this->setError("missing-parameters");
         return;
     }
     if ($runMax < 1 || $runMax > 99) {
         $this->setError("invalid-input", "runMax must be a number between 1 and 99.");
         return;
     }
     $runs = array();
     // Loop through runNames / runUrls to validate them ahead of time,
     // and filter out empty ones from the AddjobPage.
     foreach ($runNames as $runNr => $runName) {
         if (!isset($runUrls[$runNr])) {
             $this->setError("invalid-input", "One or more runs is missing a URL.");
             return;
         }
         $runUrl = $runUrls[$runNr];
         // Filter out empty submissions,
         // AddjobPage may submit more input fields then filled in
         if ($runUrl == '' && $runName == '') {
             continue;
         }
         if ($runUrl == '' || $runName == '') {
             $this->setError("invalid-input", "Run names and urls must be non-empty.");
             return;
         }
         if (strlen($runName) > 255) {
             $formRunNr = $runNr + 1;
             // offset 0
             $this->setError("invalid-input", "Run #{$formRunNr} name was too long (up to 255 characters).");
             return;
         }
         $runs[] = array("name" => $runName, "url" => $runUrl);
     }
     if (!count($runs)) {
         $this->setError('missing-parameters', 'Job must have atleast 1 run.');
         return;
     }
     // Generate a list of user agent IDs based on the selected browser sets
     $browserSetsCnt = count($browserSets);
     $browserSets = array_unique($browserSets);
     if ($browserSetsCnt !== count($browserSets)) {
         $this->setError("invalid-input", "Duplicate entries in browserSets parameter.");
         return;
     }
     $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
     $uaIDs = array();
     foreach ($browserSets as $browserSet) {
         if (!isset($conf->browserSets->{$browserSet})) {
             $this->setError("invalid-input", "Unknown browser set: {$browserSet}.");
             return;
         }
         // Merge the arrays, and re-index with unique (also prevents duplicate entries)
         $uaIDs = array_unique(array_merge($uaIDs, $conf->browserSets->{$browserSet}));
     }
     if (!count($uaIDs)) {
         $this->setError("data-corrupt", "No user agents matched the generated browserset filter.");
         return;
     }
     // Verify job name maxlength (otherwise MySQL will crop it, which might
     // result in incomplete html, screwing up the JobPage).
     if (strlen($jobName) > 255) {
         $this->setError("invalid-input", "Job name too long (up to 255 characters).");
     }
     // Create job
     $isInserted = $db->query(str_queryf("INSERT INTO jobs (user_id, name, created)\n\t\t\tVALUES (%u, %s, %s);", $userId, $jobName, swarmdb_dateformat(SWARM_NOW)));
     $newJobId = $db->getInsertId();
     if (!$isInserted || !$newJobId) {
         $this->setError("internal-error", "Insertion of job into database failed.");
         return;
     }
     // Create all runs and schedule them for the wanted browsersets in run_useragent
     foreach ($runs as $run) {
         // Create this run
         $isInserted = $db->query(str_queryf("INSERT INTO runs (job_id, name, url, created)\n\t\t\t\tVALUES(%u, %s, %s, %s);", $newJobId, $run['name'], $run['url'], swarmdb_dateformat(SWARM_NOW)));
         $newRunId = $db->getInsertId();
         if (!$isInserted || !$newRunId) {
             $this->setError("internal-error", "Insertion of job into database failed.");
             return;
         }
         // Schedule run_useragent entries for all user agents matching
         // the browerset(s) for this job.
         foreach ($uaIDs as $uaID) {
             $isInserted = $db->query(str_queryf("INSERT INTO run_useragent (run_id, useragent_id, max, updated, created)\n\t\t\t\t\tVALUES(%u, %s, %u, %s, %s);", $newRunId, $uaID, $runMax, swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
         }
     }
     $this->setData(array("id" => $newJobId, "runTotal" => count($runs), "uaTotal" => count($uaIDs)));
 }