예제 #1
0
 function AJsubmitReloadComputers()
 {
     $data = getContinuationVar();
     # imageid, compids, imagename
     $start = getReloadStartTime();
     $end = $start + 1200;
     // + 20 minutes
     $startstamp = unixToDatetime($start);
     $endstamp = unixToDatetime($end);
     $imagerevisionid = getProductionRevisionid($data['imageid']);
     $computers = $this->getData($this->defaultGetDataArgs);
     $reloadnow = array();
     $reloadasap = array();
     $fails = array();
     $passes = array();
     foreach ($data['compids'] as $compid) {
         if ($computers[$compid]['state'] == 'available' || $computers[$compid]['state'] == 'failed') {
             $mn = findManagementNode($compid, unixToDatetime($start), 1);
             if ($mn == 0) {
                 $fails[] = $compid;
                 continue;
             }
             if (getSemaphore($data['imageid'], $imagerevisionid, $mn, $compid, $startstamp, $endstamp)) {
                 $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs, " . "state s " . "WHERE rs.requestid = rq.id AND " . "rq.stateid = s.id AND " . "rs.computerid = {$compid} AND " . "rq.start < '{$endstamp}' AND " . "rq.end > '{$startstamp}' AND " . "s.name NOT IN ('complete', 'deleted', 'failed', 'timeout')";
                 $qh = doQuery($query);
                 if (!mysql_num_rows($qh)) {
                     $reloadnow[] = $compid;
                 } else {
                     $reloadasap[] = $compid;
                 }
             } else {
                 $reloadasap[] = $compid;
             }
         }
     }
     $vclreloadid = getUserlistID('vclreload@Local');
     foreach ($reloadnow as $compid) {
         if (simpleAddRequest($compid, $data['imageid'], $imagerevisionid, $startstamp, $endstamp, 19, $vclreloadid)) {
             $passes[] = $compid;
         } else {
             $fails[] = $compid;
         }
     }
     // release semaphore lock on nodes
     cleanSemaphore();
     if (count($reloadasap)) {
         $compids = implode(',', $reloadasap);
         $query = "UPDATE computer " . "SET nextimageid = {$data['imageid']} " . "WHERE id IN ({$compids})";
         doQuery($query, 101);
     }
     $msg = '';
     if (count($passes)) {
         $msg .= "The following computers are being immediately reloaded with ";
         $msg .= "<strong>{$data['imagename']}</strong>:<br>\n";
         foreach ($passes as $compid) {
             $msg .= "<span class=\"ready\">{$computers[$compid]['hostname']}</span><br>\n";
         }
     }
     if (count($reloadasap)) {
         if (count($passes)) {
             $msg .= "<br>";
         }
         $msg .= "The following computers have <strong>{$data['imagename']}</strong> ";
         $msg .= "set as a priority for reloading at the end of their existing ";
         $msg .= "reservations:<br>\n";
         foreach ($reloadasap as $compid) {
             $msg .= "<span class=\"wait\">{$computers[$compid]['hostname']}</span><br>\n";
         }
     }
     if (count($fails)) {
         if (count($passes) || count($reloadasap)) {
             $msg .= "<br>";
         }
         $msg .= "No functional management node was found for the following ";
         $msg .= "computers. They could not be reloaded at this time:<br>\n";
         foreach ($fails as $compid) {
             $msg .= "<span class=\"rederrormsg\">{$computers[$compid]['hostname']}</span><br>\n";
         }
     }
     $ret = array('status' => 'success', 'title' => "Reload Computers", 'refreshcount' => 4, 'msg' => $msg);
     sendJSON($ret);
 }
예제 #2
0
function moveReservationsOffVMs($compid, $sem = 0)
{
    if (!is_array($sem)) {
        $sem = array();
        $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
        $tmp = array_keys($resources['image']);
        $sem['imageid'] = $tmp[0];
        $sem['revid'] = getProductionRevisionid($sem['imageid']);
        $tmp = array_keys($resources['managementnode']);
        $sem['mnid'] = $tmp[0];
        $sem['start'] = unixToDatetime(time());
        $sem['end'] = '2038-01-01 00:00:00';
    }
    $query = "SELECT vm.id " . "FROM computer vm, " . "vmhost v " . "WHERE v.computerid = {$compid} AND " . "vm.vmhostid = v.id";
    $qh = doQuery($query);
    while ($row = mysql_fetch_assoc($qh)) {
        $rc = moveReservationsOffComputer($row['id']);
        if ($rc != 0) {
            # lock computer so that reservations on other VMs on this host do not get moved to it
            getSemaphore($sem['imageid'], $sem['revid'], $sem['mnid'], $row['id'], $sem['start'], $sem['end']);
        }
    }
}