You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2014/11/10 19:30:33 UTC

svn commit: r1637954 - /vcl/trunk/web/.ht-inc/computer.php

Author: jfthomps
Date: Mon Nov 10 18:30:33 2014
New Revision: 1637954

URL: http://svn.apache.org/r1637954
Log:
VCL-776 - rework resource code to have a base class for all resources and inheriting classes for each resource type

fixed problem where changing state of computer to maintenance could insert a tomaintenance reservation at the end of an indefinite server reservation

computer.php:
-modified AJsaveResource: moved adding update of notes field to after conditionals for state change - this prevents the "your changes have been saved but" text from showing up when the only thing changed was setting the notes field due to a state change when the state change was not allowed; added check for $reloadstart being '2038-01-01 00:00:00', if true, notify user that cannot schedule computer to be moved to maintenance state
-modified AJsubmitCompStateChange: added checks for $reloadstart being '2038-01-01 00:00:00', if true, add computer to $fails array and continue to next computer

Modified:
    vcl/trunk/web/.ht-inc/computer.php

Modified: vcl/trunk/web/.ht-inc/computer.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/computer.php?rev=1637954&r1=1637953&r2=1637954&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/computer.php (original)
+++ vcl/trunk/web/.ht-inc/computer.php Mon Nov 10 18:30:33 2014
@@ -876,30 +876,6 @@ class Computer extends Resource {
 					$updates[] = "`$field` = '{$data[$field]}'";
 			}
 
-			# notes
-			# staying in maintenance
-			if($olddata['stateid'] == 10 && $data['stateid'] == 10) {
-				$testnotes = $olddata['notes'];
-				# check for notes being changed
-				if(strpos($testnotes, '@') === true) {
-					$tmp = explode('@', $olddata['notes']);
-					$testnotes = $tmp[1];
-				}
-				if($testnotes != $data['notes']) {
-					$ts = unixToDatetime(time());
-					$updates[] = "notes = '{$user['unityid']} $ts@{$data['notes']}'";
-				}
-			}
-			# changing to maintenance
-			elseif($data['stateid'] == 10) {
-				$ts = unixToDatetime(time());
-				$updates[] = "notes = '{$user['unityid']} $ts@{$data['notes']}'";
-			}
-			# removing from maintenance
-			elseif($olddata['stateid'] == 10 && $data['stateid'] != 10) {
-				$updates[] = "notes = ''";
-			}
-
 			# stateid - if moving from vmhostinuse or reloading with a new image,
 			#           make sure no reservations for VMs
 			if($olddata['stateid'] == 10 && $data['stateid'] == 20) {
@@ -1221,31 +1197,47 @@ class Computer extends Resource {
 				}
 				elseif($reloadstart > 0) {
 					cleanSemaphore();
-					$end = date('n/j/y g:i a', $reloadstart);
-					$msg = '';
-					if(count($updates))
-						$msg .= "Computer information changes saved.<br>\nHowever, this ";
-					else
-					$msg .= "This ";
-					$msg .= "computer currently has VMs with reservations on them until ";
-					$msg .= "$end and cannot be moved to the maintenance state until then. ";
-					$msg .= "You can:\n";
-					$msg .= "<ul><li>Cancel and do nothing</li>\n";
-					$msg .= "<li>Schedule the computer and VMs to be moved into the ";
-					$msg .= "maintenance state at $end</li></ul>\n";
-					$msg = preg_replace("/(.{1,76}([ \n]|$))/", '\1<br>', $msg);
-					$msg = preg_replace("|$end|", "<strong>$end</strong>", $msg, 1);
-					$promptuser = 1;
-					$cdata = $this->basecdata;
-					$cdata['reloadstart'] = $reloadstart;
-					$cdata['imageid'] = getImageId('noimage');
-					$cdata['compid'] = $data['rscid'];
-					$cdata['newstateid'] = $data['stateid'];
-					$cdata['oldstateid'] = $olddata['stateid'];
-					$promptcont = addContinuationsEntry('AJsubmitComputerStateLater', $cdata, SECINDAY, 1, 0);
-					$btntxt = 'Schedule State Change';
-					$title = 'Delayed State Change';
-					$data['stateid'] = $olddata['stateid']; # prevent state from being updated yet
+					if(unixToDatetime($reloadstart) == '2038-01-01 00:00:00') {
+						$msg = '';
+						if(count($updates))
+							$msg .= "Computer information changes saved.<br>\nHowever, this ";
+						else
+							$msg .= "This ";
+						$msg .= "computer currently has VMs assigned to it that have server ";
+						$msg .= "reservations with indefinite endings. The computer cannot ";
+						$msg .= "be moved to the maintenance state while these reservations exist.";
+						$msg = preg_replace("/(.{1,76}([ \n]|$))/", '\1<br>', $msg);
+						$promptuserfail = 1;
+						$title = 'Change to Maintenance Failed';
+						$data['stateid'] = $olddata['stateid']; # prevent state from being updated
+					}
+					else {
+						$end = date('n/j/y g:i a', $reloadstart);
+						$msg = '';
+						if(count($updates))
+							$msg .= "Computer information changes saved.<br>\nHowever, this ";
+						else
+							$msg .= "This ";
+						$msg .= "computer currently has VMs with reservations on them until ";
+						$msg .= "$end and cannot be moved to the maintenance state until then. ";
+						$msg .= "You can:\n";
+						$msg .= "<ul><li>Cancel and do nothing</li>\n";
+						$msg .= "<li>Schedule the computer and VMs to be moved into the ";
+						$msg .= "maintenance state at $end</li></ul>\n";
+						$msg = preg_replace("/(.{1,76}([ \n]|$))/", '\1<br>', $msg);
+						$msg = preg_replace("|$end|", "<strong>$end</strong>", $msg, 1);
+						$promptuser = 1;
+						$cdata = $this->basecdata;
+						$cdata['reloadstart'] = $reloadstart;
+						$cdata['imageid'] = getImageId('noimage');
+						$cdata['compid'] = $data['rscid'];
+						$cdata['newstateid'] = $data['stateid'];
+						$cdata['oldstateid'] = $olddata['stateid'];
+						$promptcont = addContinuationsEntry('AJsubmitComputerStateLater', $cdata, SECINDAY, 1, 0);
+						$btntxt = 'Schedule State Change';
+						$title = 'Delayed State Change';
+						$data['stateid'] = $olddata['stateid']; # prevent state from being updated yet
+					}
 				}
 				else {
 					$query = "UPDATE computer c "
@@ -1459,6 +1451,31 @@ class Computer extends Resource {
 				# else let UPDATE move it to maintenance
 			}
 
+			# notes (do these at the end because we don't want to update notes if
+			#    state prevented from being changed)
+			# staying in maintenance
+			if($olddata['stateid'] == 10 && $data['stateid'] == 10) {
+				$testnotes = $olddata['notes'];
+				# check for notes being changed
+				if(strpos($testnotes, '@') === true) {
+					$tmp = explode('@', $olddata['notes']);
+					$testnotes = $tmp[1];
+				}
+				if($testnotes != $data['notes']) {
+					$ts = unixToDatetime(time());
+					$updates[] = "notes = '{$user['unityid']} $ts@{$data['notes']}'";
+				}
+			}
+			# changing to maintenance
+			elseif($data['stateid'] == 10) {
+				$ts = unixToDatetime(time());
+				$updates[] = "notes = '{$user['unityid']} $ts@{$data['notes']}'";
+			}
+			# removing from maintenance
+			elseif($olddata['stateid'] == 10 && $data['stateid'] != 10) {
+				$updates[] = "notes = ''";
+			}
+
 			# stateid
 			if($data['stateid'] != $olddata['stateid'])
 				$updates[] = "stateid = {$data['stateid']}";
@@ -3449,6 +3466,11 @@ class Computer extends Resource {
 						continue;
 					}
 					elseif($reloadstart > 0) {
+						if(unixToDatetime($reloadstart) == '2038-01-01 00:00:00') {
+							# host has a VM reserved indefintely
+							$fails[] = $compid;
+							continue;
+						}
 						# schedule tomaintenance/tohpc reservations for VMs and host
 						$noimageid = getImageId('noimage');
 						$revid = getProductionRevisionid($noimageid);
@@ -3531,6 +3553,11 @@ class Computer extends Resource {
 					}
 				}
 				elseif($reloadstart) {
+					if(unixToDatetime($reloadstart) == '2038-01-01 00:00:00') {
+						# node is reserved indefintely
+						$fails[] = $compid;
+						continue;
+					}
 					# computer has reservations, schedule tomaintenance
 					$noimageid = getImageId('noimage');
 					$revid = getProductionRevisionid($noimageid);