Example #1
0
function client_submit()
{
    include 'config/config.php';
    if (!$CDASH_MANAGE_CLIENTS) {
        return 0;
    }
    include_once 'models/clientsite.php';
    include_once 'models/clientos.php';
    include_once 'models/clientjob.php';
    include_once 'models/clientjobschedule.php';
    include_once 'models/clientcmake.php';
    include_once 'models/clientcompiler.php';
    include_once 'models/clientlibrary.php';
    include 'config/config.php';
    require_once 'include/common.php';
    // Client asks for the site id
    if (isset($_GET['getsiteid'])) {
        if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) {
            echo 'ERROR: sitename or systemname not set';
            return 0;
        }
        $sitename = htmlspecialchars(pdo_real_escape_string($_GET['sitename']));
        $systemname = htmlspecialchars(pdo_real_escape_string($_GET['systemname']));
        // Should get the site id
        $ClientSite = new ClientSite();
        $siteid = $ClientSite->GetId($sitename, $systemname);
        echo $siteid;
        return 1;
    } elseif (isset($_GET['getjob'])) {
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJobSchedule = new ClientJobSchedule();
        $ClientJobSchedule->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $jobid = $ClientJobSchedule->HasJob();
        if ($jobid > 0) {
            // if we have something to do
            echo $ClientJobSchedule->GetCTestScript();
        } else {
            echo '0';
            // send zero to let the client know that nothing is there
        }
        return 1;
    } elseif (isset($_GET['submitinfo'])) {
        if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) {
            echo '0';
            return 1;
        }
        $filehandle = 'php://input';
        $contents = file_get_contents($filehandle);
        $xml = new SimpleXMLElement($contents);
        // Add/Update the OS
        $ClientOS = new ClientOS();
        $ClientOS->Name = $ClientOS->GetPlatformFromName($xml->system->platform);
        $ClientOS->Version = $ClientOS->GetVersionFromName($xml->system->version);
        $ClientOS->Bits = $xml->system->bits;
        $ClientOS->Save();
        // Add/Update the site
        $ClientSite = new ClientSite();
        $ClientSite->Name = htmlspecialchars(pdo_real_escape_string($_GET['sitename']));
        $ClientSite->SystemName = htmlspecialchars(pdo_real_escape_string($_GET['systemname']));
        $ClientSite->Host = 'none';
        $ClientSite->OsId = $ClientOS->Id;
        $ClientSite->BaseDirectory = $xml->system->basedirectory;
        $ClientSite->Save();
        $siteid = $ClientSite->Id;
        // Add/Update the compiler(s)
        $compilers = array();
        foreach ($xml->compiler as $compiler) {
            $ClientCompiler = new ClientCompiler();
            $ClientCompiler->Name = $compiler->name;
            $ClientCompiler->Version = $compiler->version;
            $ClientCompiler->Command = $compiler->command;
            $ClientCompiler->Generator = $compiler->generator;
            $ClientCompiler->SiteId = $siteid;
            $ClientCompiler->Save();
            $comp = array();
            $comp['name'] = $compiler->name;
            $comp['version'] = $compiler->version;
            $comp['command'] = $compiler->command;
            $comp['generator'] = $compiler->generator;
            $compilers[] = $comp;
        }
        $ClientCompiler = new ClientCompiler();
        $ClientCompiler->SiteId = $siteid;
        $ClientCompiler->DeleteUnused($compilers);
        // Add/Update CMake(s)
        $cmakes = array();
        foreach ($xml->cmake as $cmake) {
            $ClientCMake = new ClientCMake();
            $ClientCMake->Version = $cmake->version;
            $ClientCMake->Path = $cmake->path;
            $ClientCMake->SiteId = $siteid;
            $ClientCMake->Save();
            $cm = array();
            $cm['path'] = $cmake->path;
            $cm['version'] = $cmake->version;
            $cmakes[] = $cm;
        }
        $ClientCMake = new ClientCMake();
        $ClientCMake->SiteId = $siteid;
        $ClientCMake->DeleteUnused($cmakes);
        // Add/Update Libraries
        $libraries = array();
        foreach ($xml->library as $library) {
            $ClientLibrary = new ClientLibrary();
            $ClientLibrary->Name = $library->name;
            $ClientLibrary->Path = $library->path;
            $ClientLibrary->Include = $library->include;
            $ClientLibrary->Version = $library->version;
            $ClientLibrary->SiteId = $siteid;
            $ClientLibrary->Save();
            $lib = array();
            $lib['name'] = $library->name;
            $lib['path'] = $library->path;
            $lib['version'] = $library->version;
            $lib['include'] = $library->include;
            $libraries[] = $lib;
        }
        $ClientLibrary = new ClientLibrary();
        $ClientLibrary->SiteId = $siteid;
        $ClientLibrary->DeleteUnused($libraries);
        // Add/Update Programs
        $programs = array();
        foreach ($xml->program as $program) {
            $prog = array();
            $prog['name'] = $program->name;
            $prog['path'] = $program->path;
            $prog['version'] = $program->version;
            $programs[] = $prog;
        }
        $ClientSite->UpdatePrograms($programs);
        // Add/Update the list of allowed projects
        $allowedProjects = array();
        foreach ($xml->allowedproject as $allowedProject) {
            $allowedProjects[] = $allowedProject;
        }
        $ClientSite->UpdateAllowedProjects($allowedProjects);
        return 1;
    } elseif (isset($_GET['jobdone'])) {
        // Mark the job has finished
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJob = new ClientJob();
        $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $ClientJob->SetFinished();
        return 1;
    } elseif (isset($_GET['jobfailed'])) {
        // Mark the job has failed
        if (!isset($_GET['siteid'])) {
            echo '0';
            return 1;
        }
        if (!$_GET['siteid']) {
            echo '0';
            return 1;
        }
        $ClientJob = new ClientJob();
        $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']);
        $ClientJob->SetFailed();
        return 1;
    }
    return 0;
}
Example #2
0
 public function GetCTestScript()
 {
     if (!$this->Id || !$this->SiteId) {
         add_log('ClientJobSchedule:GetCTestScript', 'Id not set');
         return;
     }
     include 'config/config.php';
     // Update the current run
     pdo_query("UPDATE client_jobschedule SET lastrun='" . date(FMT_DATETIMESTD) . "' WHERE id=" . qnum($this->Id));
     $ClientSite = new ClientSite();
     $ClientSite->Id = $this->SiteId;
     // Create a job
     $job = new ClientJob();
     $job->ScheduleId = $this->Id;
     $job->StartDate = date('Y-m-d H:i:s');
     $job->EndDate = date('1980-01-01 00:00:00');
     $job->Status = CDASH_JOB_RUNNING;
     $job->SiteId = $this->SiteId;
     $job->OsId = $ClientSite->GetOS();
     // Determine the appropriate CMake id (get the newest version)
     $cmake = pdo_query('SELECT sc.cmakeid FROM client_cmake,client_site2cmake AS sc
                   LEFT JOIN client_jobschedule2cmake AS jc ON (jc.cmakeid=sc.cmakeid)
                   WHERE client_cmake.id=sc.cmakeid AND sc.siteid=' . $this->SiteId . '
                   ORDER BY client_cmake.version DESC LIMIT 1');
     $cmake_array = pdo_fetch_array($cmake);
     $job->CMakeId = $cmake_array[0];
     // Determine the appropriate compiler
     $compiler = pdo_query('SELECT sc.compilerid FROM client_compiler,client_site2compiler AS sc
                      LEFT JOIN client_jobschedule2compiler AS jc ON (jc.compilerid=sc.compilerid)
                      WHERE client_compiler.id=sc.compilerid AND sc.siteid=' . $this->SiteId . '
                      ORDER BY client_compiler.version DESC LIMIT 1');
     $compiler_array = pdo_fetch_array($compiler);
     $job->CompilerId = $compiler_array[0];
     $job->Save();
     $Project = new Project();
     $Project->Id = $this->GetProjectId();
     $Project->Fill();
     $compiler = new ClientCompiler();
     $compiler->Id = $job->CompilerId;
     $os = new ClientOS();
     $os->Id = $job->OsId;
     // Initialize the variables
     $buildtype = 'Experimental';
     //default
     switch ($this->GetType()) {
         case CDASH_JOB_EXPERIMENTAL:
             $buildtype = 'Experimental';
             break;
         case CDASH_JOB_NIGHTLY:
             $buildtype = 'Nightly';
             break;
         case CDASH_JOB_CONTINUOUS:
             $buildtype = 'Continuous';
             break;
     }
     $ctest_script = '#' . $this->Id . "\n";
     $ctest_script .= '#' . $Project->Name . "\n";
     $ctest_script .= 'SET(JOB_BUILDTYPE ' . $buildtype . ')' . "\n";
     $ctest_script .= 'SET(PROJECT_NAME "' . $Project->Name . '")' . "\n";
     if (strlen($this->GetModule()) > 0) {
         $ctest_script .= 'SET(JOB_MODULE "' . $this->GetModule() . '")' . "\n";
     }
     if (strlen($this->GetTag()) > 0) {
         $ctest_script .= 'SET(JOB_TAG "' . $this->GetTag() . '")' . "\n";
     }
     if (strlen($this->GetBuildNameSuffix()) > 0) {
         $ctest_script .= 'SET(JOB_BUILDNAME_SUFFIX "' . $this->GetBuildNameSuffix() . '")' . "\n";
     }
     $ctest_script .= 'SET(JOB_CMAKE_GENERATOR "' . $ClientSite->GetCompilerGenerator($job->CompilerId) . '")' . "\n";
     $ctest_script .= 'SET(JOB_BUILD_CONFIGURATION "' . $this->BuildConfigurations[$this->GetBuildConfiguration()] . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_BASE_DIRECTORY "' . $ClientSite->GetBaseDirectory() . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_CMAKE_PATH "' . $ClientSite->GetCMakePath($job->CMakeId) . '")' . "\n";
     $ctest_script .= 'SET(CLIENT_SITE "' . $ClientSite->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_NAME "' . $os->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_VERSION "' . $os->GetVersion() . '")' . "\n";
     $ctest_script .= 'SET(JOB_OS_BITS "' . $os->GetBits() . '")' . "\n";
     $ctest_script .= 'SET(JOB_COMPILER_NAME "' . $compiler->GetName() . '")' . "\n";
     $ctest_script .= 'SET(JOB_COMPILER_VERSION "' . $compiler->GetVersion() . '")' . "\n";
     $ctest_script .= 'SET(JOB_REPOSITORY "' . $this->GetRepository() . '")' . "\n";
     // Set the program variables
     $programs = $ClientSite->GetPrograms();
     $currentname = '';
     foreach ($programs as $program) {
         $program_name = strtoupper($program['name']);
         $program_version = str_replace('.', '_', strtoupper($program['version']));
         if ($program['name'] != $currentname) {
             $ctest_script .= 'SET(CLIENT_EXECUTABLE_' . $program_name . ' "' . $program['path'] . '")' . "\n";
             $currentname = $program['name'];
         }
         $ctest_script .= 'SET(CLIENT_EXECUTABLE_' . $program_name . '_' . $program_version . ' "' . $program['path'] . '")' . "\n";
     }
     if ($CDASH_USE_HTTPS === true) {
         $ctest_script .= 'set(CTEST_DROP_METHOD "https")' . "\n";
     } else {
         $ctest_script .= 'set(CTEST_DROP_METHOD "http")' . "\n";
     }
     $serverName = $CDASH_SERVER_NAME;
     if (strlen($serverName) == 0) {
         $serverName = $_SERVER['SERVER_NAME'];
     }
     $ctest_script .= 'set(CTEST_DROP_SITE "' . $serverName . '")' . "\n";
     $dropLocation = dirname($_SERVER['PHP_SELF']) . '/submit.php?project=' . urlencode($Project->Name);
     $dropLocation .= '&clientscheduleid=' . $this->Id;
     $ctest_script .= 'set(CTEST_DROP_LOCATION "' . $dropLocation . '")' . "\n";
     $ctest_script .= 'set(JOB_DROP_LOCATION "' . $dropLocation . '")' . "\n";
     $ctest_script .= 'set(JOB_DROP_SITE "' . $serverName . '")' . "\n";
     $ctest_script .= 'set(CTEST_DROP_SITE_CDASH TRUE)' . "\n";
     $ctest_script .= 'set(CTEST_NOTES_FILES ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME})' . "\n";
     // Make the cache available
     $ctest_script .= 'set(JOB_INITIAL_CACHE "' . $this->GetCMakeCache() . '\\n")' . "\n";
     // Set the macro to warn CDash that the script failed
     $ctest_script .= "\n" . 'MACRO(JOB_FAILED)' . "\n";
     $uri = $_SERVER['REQUEST_URI'];
     $pos = strpos($uri, 'submit.php');
     if ($pos !== false) {
         $uri = substr($uri, 0, $pos + 10);
     }
     $ctest_script .= '  file(DOWNLOAD "${CTEST_DROP_METHOD}://${CTEST_DROP_SITE}' . $uri . '?siteid=' . $this->SiteId . '&jobfailed=1" "${CLIENT_BASE_DIRECTORY}/scriptfailed.txt")' . "\n";
     $ctest_script .= '  return()' . "\n";
     $ctest_script .= 'ENDMACRO(JOB_FAILED)' . "\n\n";
     if (strlen(trim($this->GetClientScript())) > 0) {
         $ctest_script .= $this->GetClientScript();
     } elseif (strlen($Project->CTestTemplateScript) > 0) {
         $ctest_script .= $Project->CTestTemplateScript;
     } else {
         $ctest_script .= $Project->getDefaultJobTemplateScript();
     }
     return $ctest_script;
 }
Example #3
0
 }
 // Go through the jobs
 if ($CDASH_MANAGE_CLIENTS) {
     $ClientJobSchedule = new ClientJobSchedule();
     $userJobSchedules = $ClientJobSchedule->getAll($userid, 1000);
     foreach ($userJobSchedules as $scheduleid) {
         $ClientJobSchedule = new ClientJobSchedule();
         $ClientJobSchedule->Id = $scheduleid;
         $projectid = $ClientJobSchedule->GetProjectId();
         $Project = new Project();
         $Project->Id = $projectid;
         $status = "Scheduled";
         $lastrun = "NA";
         $lastjobid = $ClientJobSchedule->GetLastJobId();
         if ($lastjobid) {
             $ClientJob = new ClientJob();
             $ClientJob->Id = $lastjobid;
             switch ($ClientJob->GetStatus()) {
                 case CDASH_JOB_RUNNING:
                     $status = "Running";
                     $ClientSite = new ClientSite();
                     $ClientSite->Id = $ClientJob->GetSite();
                     $status .= " (" . $ClientSite->GetName() . ")";
                     $lastrun = $ClientJob->GetStartDate();
                     break;
                 case CDASH_JOB_FINISHED:
                     $status = "Finished";
                     $ClientSite = new ClientSite();
                     $ClientSite->Id = $ClientJob->GetSite();
                     $status .= " (" . $ClientSite->GetName() . ")";
                     $lastrun = $ClientJob->GetEndDate();
Example #4
0
/** Remove the first builds that are at the beginning of the queue */
function removeFirstBuilds($projectid, $days, $maxbuilds, $force = false)
{
    require 'config/config.php';
    require_once 'include/pdo.php';
    require_once 'include/common.php';
    @set_time_limit(0);
    if (!$force && !isset($CDASH_AUTOREMOVE_BUILDS)) {
        return;
    }
    if (!$force && $CDASH_AUTOREMOVE_BUILDS != '1') {
        return;
    }
    if ($days < 2) {
        return;
    }
    // First remove the builds with the wrong date
    $currentdate = time() - 3600 * 24 * $days;
    $startdate = date(FMT_DATETIME, $currentdate);
    add_log('about to query for builds to remove', 'removeFirstBuilds');
    $builds = pdo_query("SELECT id FROM build\n            WHERE parentid IN (0, -1) AND\n            starttime<'{$startdate}' AND\n            projectid=" . qnum($projectid) . "\n            ORDER BY starttime ASC LIMIT {$maxbuilds}");
    add_last_sql_error('dailyupdates::removeFirstBuilds');
    $buildids = array();
    while ($builds_array = pdo_fetch_array($builds)) {
        $buildids[] = $builds_array['id'];
    }
    $s = 'removing old buildids for projectid: ' . $projectid;
    add_log($s, 'removeFirstBuilds');
    echo '  -- ' . $s . "\n";
    // for "interactive" command line feedback
    remove_build($buildids);
    // Remove any job schedules that are older than our cutoff date
    // and not due to repeat again.
    require_once 'models/constants.php';
    require_once 'models/clientjobschedule.php';
    $sql = 'SELECT scheduleid FROM client_job AS cj
    LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id
    WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n    AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'\n    AND (cjs.repeattime = 0.00 OR\n      (cjs.enddate < '{$startdate}' AND cjs.enddate != '1980-01-01 00:00:00'))";
    $job_schedules = pdo_query($sql);
    while ($job_schedule = pdo_fetch_array($job_schedules)) {
        $ClientJobSchedule = new ClientJobSchedule();
        $ClientJobSchedule->Id = $job_schedule['scheduleid'];
        $ClientJobSchedule->Remove();
    }
    // Remove any jobs that are older than our cutoff date.
    // This occurs when a job schedule is set to continue repeating, but
    // some of its past runs are older than our autoremove threshold.
    require_once 'models/clientjob.php';
    $sql = 'SELECT cj.id FROM client_job AS cj
    LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id
    WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n    AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'";
    $jobs = pdo_query($sql);
    while ($job = pdo_fetch_array($jobs)) {
        $ClientJob = new ClientJob();
        $ClientJob->Id = $job['id'];
        $ClientJob->Remove();
    }
}