function RPCisAvailable($imageid, $start, $end, $userid) { #FIXME this function doesn't properly handle cluster reservations global $requestInfo; $images = getImages(); $requestInfo["start"] = $start; $requestInfo["end"] = $end; $requestInfo["imageid"] = $imageid; $allocatedcompids = array(0); if ($requestInfo["start"] <= time()) { $now = 1; } else { $now = 0; } # get list of schedules $starttime = minuteOfWeek($start); $endtime = minuteOfWeek($end); # request is within a single week if (weekOfYear($start) == weekOfYear($end)) { $query = "SELECT scheduleid " . "FROM scheduletimes " . "WHERE start <= {$starttime} AND " . "end >= {$endtime}"; } elseif ($end - $start >= SECINDAY * 7) { $query = "SELECT scheduleid " . "FROM scheduletimes " . "WHERE start = 0 AND " . "end = 10080"; } else { $query = "SELECT s1.scheduleid " . "FROM scheduletimes s1, " . "scheduletimes s2 " . "WHERE s1.scheduleid = s2.scheduleid AND " . "s1.start <= {$starttime} AND " . "s1.end = 10080 AND " . "s2.start = 0 AND " . "s2.end >= {$endtime}"; } $scheduleids = array(); $qh = doQuery($query, 127); while ($row = mysql_fetch_row($qh)) { array_push($scheduleids, $row[0]); } $requestInfo["computers"] = array(); $requestInfo["computers"][0] = 0; $requestInfo["images"][0] = $imageid; # loop to check for available computers for all needed images if ($images[$imageid]["imagemetaid"] != NULL) { $count = 1; foreach ($images[$imageid]["subimages"] as $imgid) { $requestInfo['computers'][$count] = 0; $requestInfo['images'][$count] = $imgid; $count++; } } // get semaphore lock if (!semLock()) { abort(3); } $startstamp = unixToDatetime($start); $endstamp = unixToDatetime($end + 900); foreach ($requestInfo["images"] as $key => $imageid) { #$osid = getOSid($os); # check for max concurrent usage of image if ($images[$imageid]['maxconcurrent'] != NULL) { $query = "SELECT COUNT(rs.imageid) AS currentusage " . "FROM reservation rs, " . "request rq " . "WHERE '{$startstamp}' < rq.end AND " . "'{$endstamp}' > (rq.start - INTERVAL 900 SECOND) AND " . "rs.requestid = rq.id AND " . "rs.imageid = {$imageid} AND " . "rq.stateid NOT IN (1,5,11,12,16,17)"; $qh = doQuery($query, 101); if (!($row = mysql_fetch_assoc($qh))) { semUnlock(); return 0; } if ($row['currentusage'] >= $images[$imageid]['maxconcurrent']) { semUnlock(); return -1; } } # get platformid that matches $imageid $query = "SELECT platformid FROM image WHERE id = {$imageid}"; $qh = doQuery($query, 125); if (!($row = mysql_fetch_row($qh))) { semUnlock(); return 0; } $platformid = $row[0]; # get computers $imageid maps to $tmp = getMappedResources($imageid, "image", "computer"); if (!count($tmp)) { semUnlock(); return 0; } $mappedcomputers = implode(',', $tmp); # get computers for available schedules and platforms $computerids = array(); $currentids = array(); $blockids = array(); # get list of available computers $resources = getUserResources(array("imageAdmin", "imageCheckOut"), array("available"), 0, 0, $userid); $computers = implode("','", array_keys($resources["computer"])); $computers = "'{$computers}'"; $alloccompids = implode(",", $allocatedcompids); $schedules = implode(',', $scheduleids); $query = "SELECT DISTINCT c.id, " . "c.currentimageid " . "FROM computer c, " . "image i, " . "state s " . "WHERE c.scheduleid IN ({$schedules}) AND " . "c.platformid = {$platformid} AND " . "c.stateid = s.id AND " . "s.name != 'maintenance' AND " . "s.name != 'vmhostinuse' AND " . "s.name != 'hpc' AND " . "s.name != 'failed' AND "; if ($now) { $query .= "s.name != 'reloading' AND " . "s.name != 'timeout' AND " . "s.name != 'inuse' AND "; } $query .= "i.id = {$imageid} AND " . "c.RAM >= i.minram AND " . "c.procnumber >= i.minprocnumber AND " . "c.procspeed >= i.minprocspeed AND " . "c.network >= i.minnetwork AND " . "c.id IN ({$computers}) AND " . "c.id IN ({$mappedcomputers}) AND " . "c.id NOT IN ({$alloccompids}) " . "ORDER BY (c.procspeed * c.procnumber) DESC, " . "RAM DESC, " . "network DESC"; $qh = doQuery($query, 129); while ($row = mysql_fetch_assoc($qh)) { array_push($computerids, $row['id']); if ($row['currentimageid'] == $imageid) { array_push($currentids, $row['id']); } } # get computer ids available from block reservations $blockids = getAvailableBlockComputerids($imageid, $start, $end, $allocatedcompids); # remove computers from list that are already scheduled $usedComputerids = array(); $query = "SELECT DISTINCT rs.computerid " . "FROM reservation rs, " . "request rq, " . "user u " . "WHERE '{$startstamp}' < rq.end AND " . "'{$endstamp}' > (rq.start - INTERVAL 900 SECOND) AND " . "rs.requestid = rq.id AND " . "rq.stateid != 1 AND " . "rq.stateid != 5 AND " . "rq.stateid != 12 AND " . "rq.userid = u.id AND " . "u.unityid != 'vclreload'"; $qh = doQuery($query, 130); while ($row = mysql_fetch_row($qh)) { array_push($usedComputerids, $row[0]); } $computerids = array_diff($computerids, $usedComputerids); $currentids = array_diff($currentids, $usedComputerids); $blockids = array_diff($blockids, $usedComputerids); if (count($currentids)) { $return = array_shift($currentids); } elseif (count($computerids)) { $return = array_shift($computerids); } else { $return = 0; } } semUnlock(); return $return; }
function submitEditRequest() { global $user, $submitErr, $viewmode, $mode; $data = getContinuationVar(); $request = getRequestInfo($data["requestid"]); print "<H2>Modify Reservation</H2>\n"; $hour = $data["hour"]; if ($data["hour"] == 12) { if ($data["meridian"] == "am") { $hour = 0; } } elseif ($data["meridian"] == "pm") { $hour = $data["hour"] + 12; } $tmp = explode('/', $data["day"]); $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]); if ($data['openend'] && $data['ending'] == 'date') { $end = datetimeToUnix($data['enddate']); } else { if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) { $end = $start + $data["length"] * 60 + 900; } else { $end = $start + $data["length"] * 60; } } // get semaphore lock if (!semLock()) { abort(3); } $max = getMaxOverlap($user['id']); if (checkOverlap($start, $end, $max, $data["requestid"])) { if ($max == 0) { print "<font color=\"#ff0000\">The time you requested overlaps with "; print "another reservation you currently have. You are only allowed "; print "to have a single reservation at any given time. Please select "; print "another time to use the application.</font><br><br>\n"; } else { print "<font color=\"#ff0000\">The time you requested overlaps with "; print "another reservation you currently have. You are allowed "; print "to have {$max} overlapping reservations at any given time. "; print "Please select another time to use the application.</font><br>"; print "<br>\n"; } $submitErr = 1; editRequest(); return; } $rc = isAvailable(getImages(), $data["imageid"], $start, $end, $data["os"], $data["requestid"]); if ($rc == -1) { print "You have requested an environment that is limited in the number "; print "of concurrent reservations that can be made. No further "; print "reservations for the environment can be made for the time you "; print "have selected. Please select another time to use the "; print "environment.<br>"; addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0); } elseif ($rc > 0) { updateRequest($data["requestid"]); if ($data["started"]) { if ($data['openend'] && $data['ending'] == 'date') { print "Your request to change the ending of your reservation for <b>"; print "{$data["prettyimage"]}</b> to {$data['enddate']} "; print "has been accepted.<br><br>\n"; } else { $remaining = ($end - time()) / 60; print "Your request to extend your reservation for <b>"; print "{$data["prettyimage"]}</b> by " . prettyLength($data["extend"]); print " has been accepted.<br><br>\n"; print "You now have " . prettyLength($remaining) . " remaining for "; print "your reservation<br>\n"; } } else { print "Your request to use <b>" . $data["prettyimage"] . "</b> on "; if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) { print prettyDatetime($request["daterequested"]); } else { print prettyDatetime($start); } if ($data['openend'] && $data['ending'] == 'date') { print " until " . prettyDatetime($end); } else { print " for " . prettyLength($data["length"]); } print " has been accepted.<br>\n"; } } else { $cdata = array('imageid' => $data['imageid'], 'length' => $data['length'], 'requestid' => $data['requestid']); $cont = addContinuationsEntry('selectTimeTable', $cdata); print "The time you have requested is not available. You may "; print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">"; print "view a timetable</a> of free and reserved times to find "; print "a time that will work for you.<br>\n"; addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0); } }
function submitCreateImage() { global $submitErr, $user, $viewmode, $HTMLheader, $printedHTMLheader, $mode; if ($mode == 'submitCreateTestProd') { $data = getContinuationVar(); $data["revisionid"] = processInputVar("revisionid", ARG_MULTINUMERIC); # TODO check for valid revisionid } else { $data = processRequestInput(0); $data['length'] = getContinuationVar('length'); } $showrevisions = 0; $subimages = 0; $images = getImages(); $revcount = count($images[$data['imageid']]['imagerevision']); if ($revcount > 1) { $showrevisions = 1; } if ($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) { $subimages = 1; foreach ($images[$data['imageid']]['subimages'] as $subimage) { $revcount = count($images[$subimage]['imagerevision']); if ($revcount > 1) { $showrevisions = 1; } } } if ($data["time"] == "now") { $nowArr = getdate(); if ($nowArr["minutes"] == 0) { $subtract = 0; $add = 0; } elseif ($nowArr["minutes"] < 15) { $subtract = $nowArr["minutes"] * 60; $add = 900; } elseif ($nowArr["minutes"] < 30) { $subtract = ($nowArr["minutes"] - 15) * 60; $add = 900; } elseif ($nowArr["minutes"] < 45) { $subtract = ($nowArr["minutes"] - 30) * 60; $add = 900; } elseif ($nowArr["minutes"] < 60) { $subtract = ($nowArr["minutes"] - 45) * 60; $add = 900; } $start = time() - $subtract; $start -= $start % 60; $nowfuture = "now"; } else { $add = 0; $hour = $data["hour"]; if ($data["hour"] == 12) { if ($data["meridian"] == "am") { $hour = 0; } } elseif ($data["meridian"] == "pm") { $hour = $data["hour"] + 12; } $tmp = explode('/', $data["day"]); $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]); if ($start < time()) { print $HTMLheader; print "<H2>Create / Update an Image</H2>\n"; print "<font color=\"#ff0000\">The time you requested is in the past."; print " Please select \"Now\" or use a time in the future.</font><br>\n"; $submitErr = 1; createSelectImage(); return; } $nowfuture = "future"; } // FIXME hard code length to 8 hours $data["length"] = 480; $end = $start + $data["length"] * 60 + $add; // get semaphore lock if (!semLock()) { abort(3); } $max = getMaxOverlap($user['id']); if (checkOverlap($start, $end, $max)) { $printedHTMLheader = 1; print $HTMLheader; print "<H2>New Reservation</H2>\n"; if ($max == 0) { print "<font color=\"#ff0000\">The time you requested overlaps with "; print "another reservation you currently have. You are only allowed "; print "to have a single reservation at any given time. Please select "; print "another time to use the application. If you are finished with "; print "an active reservation, click \"Current Reservations\", "; print "then click the \"End\" button of your active reservation."; print "</font><br><br>\n"; } else { print "<font color=\"#ff0000\">The time you requested overlaps with "; print "another reservation you currently have. You are allowed "; print "to have {$max} overlapping reservations at any given time. "; print "Please select another time to use the application. If you are "; print "finished with an active reservation, click \"Current "; print "Reservations\", then click the \"End\" button of your active "; print "reservation.</font><br><br>\n"; } $submitErr = 1; createSelectImage(); return; } // if user is owner of the image and there is a test revision of the image # available, ask user if production or test image desired if ($mode != "submitCreateTestProd" && $showrevisions && $images[$data["imageid"]]["ownerid"] == $user["id"]) { $printedHTMLheader = 1; print $HTMLheader; print "<H2>New Reservation</H2>\n"; if ($subimages) { print "This is a cluster environment. At least one image in the "; print "cluster has more than one revision available. Please select "; print "the revision you desire for each image listed below:<br>\n"; } else { print "There are multiple revisions of this environment available. Please "; print "select the revision you would like to check out:<br>\n"; } print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post><br>\n"; if (!array_key_exists('subimages', $images[$data['imageid']])) { $images[$data['imageid']]['subimages'] = array(); } array_unshift($images[$data['imageid']]['subimages'], $data['imageid']); foreach ($images[$data['imageid']]['subimages'] as $subimage) { print "{$images[$subimage]['prettyname']}:<br>\n"; print "<table summary=\"lists revisions of the selected environment, one must be selected to continue\">\n"; print " <TR>\n"; print " <TD></TD>\n"; print " <TH>Revision</TH>\n"; print " <TH>Creator</TH>\n"; print " <TH>Created</TH>\n"; print " <TH>Currently in Production</TH>\n"; print " </TR>\n"; foreach ($images[$subimage]['imagerevision'] as $revision) { print " <TR>\n"; if (array_key_exists($subimage, $data['revisionid']) && $data['revisionid'][$subimage] == $revision['id']) { print " <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n"; } elseif ($revision['production']) { print " <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n"; } else { print " <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']}></TD>\n"; } print " <TD align=center>{$revision['revision']}</TD>\n"; print " <TD align=center>{$revision['user']}</TD>\n"; print " <TD align=center>{$revision['prettydate']}</TD>\n"; if ($revision['production']) { print " <TD align=center>Yes</TD>\n"; } else { print " <TD align=center>No</TD>\n"; } print " </TR>\n"; } print "</TABLE>\n"; } addContinuationsEntry('submitCreateImage', array(), SECINDAY, 1, 0); // we add this continuation back // so the currently displayed // page can be reloaded $cont = addContinuationsEntry('submitCreateTestProd', $data); print "<br><INPUT type=hidden name=continuation value=\"{$cont}\">\n"; print "<INPUT type=submit value=Submit>\n"; print "</FORM>\n"; return; } $rc = isAvailable($images, $data["imageid"], $start, $end, $data["os"], 0, 0, 0, 1); if ($rc == -1) { $printedHTMLheader = 1; print $HTMLheader; print "<H2>Create / Update an Image</H2>\n"; print "You have requested an environment that is limited in the number "; print "of concurrent reservations that can be made. No further "; print "reservations for the environment can be made for the time you "; print "have selected. Please select another time to use the "; print "environment.<br>"; } elseif ($rc > 0) { $requestid = addRequest(1, $data['revisionid']); if ($data["time"] == "now") { header("Location: " . BASEURL . SCRIPT . "?mode=viewRequests"); dbDisconnect(); exit; } else { $time = prettyLength($data["length"]); if ($data["minute"] == 0) { $data["minute"] = "00"; } $printedHTMLheader = 1; print $HTMLheader; print "<H2>Create / Update an Image</H2>\n"; print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"]; print "</b> on " . prettyDatetime($start) . " for {$time} has been "; print "accepted.<br><br>\n"; print "When your reservation time has been reached, the "; print "<b>Current Reservations</b> page will give you more "; print "information on connecting to the reserved computer. If you "; print "would like to modify your reservation, you can do that from "; print "the <b>Current Reservations</b> page as well.<br>\n"; } } else { $printedHTMLheader = 1; print $HTMLheader; $cdata = array('imageid' => $data['imageid'], 'length' => $data['length']); $cont = addContinuationsEntry('selectTimeTable', $cdata); print "<H2>Create / Update an Image</H2>\n"; print "The reservation you have requested is not available. You may "; print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">"; print "view a timetable</a> of free and reserved times to find "; print "a time that will work for you.<br>\n"; #addLogEntry($nowfuture, unixToDatetime($start), # unixToDatetime($end), 0, $data["imageid"]); } }
function submitCompStateChange() { global $user; print "<H2>Change State of Computers</H2>\n"; $data = getContinuationVar(); $computers = getComputers(1); # switching to available if ($data['stateid'] == 2) { $compids = implode(',', $data['computerids']); $query = "UPDATE computer " . "SET stateid = 2, " . "notes = '' " . "WHERE id IN ({$compids})"; doQuery($query, 101); print "The following computers were changed to the available state:\n"; print "<TABLE>\n"; foreach ($data['computerids'] as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; } elseif ($data['stateid'] == 10) { $data['notes'] = processInputVar('notes', ARG_STRING); if (get_magic_quotes_gpc()) { $data['notes'] = stripslashes($data['notes']); } $data['notes'] = mysql_escape_string($data['notes']); $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; $vclreloadid = getUserlistID('vclreload@Local'); // get semaphore lock if (!semLock()) { abort(3); } $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'maintenance') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } $passes = array(); $fails = array(); foreach ($changeasap as $compid) { # TODO what about blockComputers? # try to move future reservations off of computer moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); # create a really long reservation starting at that time in state tomaintenance if ($row = mysql_fetch_assoc($qh)) { $start = $row['end']; $changetimes[$compid] = $start; $end = datetimeToUnix($start) + SECINWEEK; // hopefully keep future reservations off of it $end = unixToDatetime($end); if (simpleAddRequest($compid, 4, 3, $start, $end, 18, $vclreloadid)) { $passes[] = $compid; } else { $fails[] = $compid; } } else { $query = "UPDATE computer " . "SET stateid = 10, " . "notes = '{$data['notes']}' " . "WHERE id = {$compid}"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if (count($noaction) || count($changeasap)) { $comparr = array_merge($noaction, $changeasap); $compids = implode(',', $comparr); $query = "UPDATE computer " . "SET notes = '{$data['notes']}' " . "WHERE id IN ({$compids})"; doQuery($query, 101); } if (count($changenow)) { print "The following computers were immediately placed into the "; print "maintenance state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($passes)) { print "The following computers currently have reservations on them "; print "and will be placed in the maintenance state at the time listed "; print "for each computer:\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH>Computer</TH>\n"; print " <TH>Maintenance time</TH>\n"; print " </TR>\n"; foreach ($passes as $compid) { print " <TR>\n"; print " <TD align=center><font color=\"ff8c00\">{$computers[$compid]['hostname']}</font></TD>\n"; $time = date('n/j/y g:i a', datetimeToUnix($changetimes[$compid])); print " <TD align=center>{$time}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($fails)) { print "The following computers currently have reservations on them "; print "but no functional management node was found for them. Nothing "; print "be done with them at this time:\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH>Computer</TH>\n"; print " </TR>\n"; foreach ($passes as $compid) { print " <TR>\n"; print " <TD align=center><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the maintenance "; print "state and had their notes on being in the maintenance state "; print "updated:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } elseif ($data['stateid'] == 20) { $profileid = processInputVar('profileid', ARG_NUMERIC); if (!array_key_exists($profileid, $data['profiles'])) { $keys = array_keys($data['profiles']); $profileid = $keys[0]; } $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'vmhostinuse') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } if (!semLock()) { abort(3); } foreach ($changeasap as $compid) { # TODO what about blockComputers? moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } else { # create a reload reservation to load machine with image # corresponding to selected vm profile $start = getReloadStartTime(); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $start = unixToDatetime($start); $end = unixToDatetime($end); $imagerevisionid = getProductionRevisionid($data['profiles'][$profileid]['imageid']); $vclreloadid = getUserlistID('vclreload@Local'); simpleAddRequest($compid, $data['profiles'][$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid); unset_by_val($compid, $changeasap); array_push($changenow, $compid); # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = {$compid}"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { if ($row['vmprofileid'] != $profileid) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = {$profileid} " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ({$compid}, " . "2, " . "{$profileid})"; doQuery($query, 101); } } } // release semaphore lock semUnlock(); if (count($changenow)) { print "The following computers were placed into the "; print "vmhostinuse state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the vmhostinuse state at this time:\n"; print "<TABLE>\n"; foreach ($changeasap as $compid) { print " <TR>\n"; print " <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the vmhostinuse "; print "state:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } elseif ($data['stateid'] == 23) { $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'hpc') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } if (!semLock()) { abort(3); } foreach ($changeasap as $compid) { # TODO what about blockComputers? moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } else { $query = "UPDATE computer " . "SET stateid = 23 " . "WHERE id = {$compid}"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if (count($changenow)) { print "The following computers were placed into the "; print "hpc state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the hpc state at this time:\n"; print "<TABLE>\n"; foreach ($changeasap as $compid) { print " <TR>\n"; print " <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the hpc "; print "state:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } else { abort(50); } }