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/12/12 21:55:15 UTC

svn commit: r1645069 - in /vcl/trunk/web: .ht-inc/computer.php .ht-inc/image.php .ht-inc/managementnode.php .ht-inc/resource.php .ht-inc/schedule.php js/resources.js

Author: jfthomps
Date: Fri Dec 12 20:55:14 2014
New Revision: 1645069

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

added a function to all resources (except computer) to check for resource usage before prompting to confirm deleting it

computer.php: modified AJdeleteComputers: added query to check usage in blockComputers

image.php: added checkResourceInUse: checks for image usage in reservation, blockComputers, blockRequest, serverprofile, subimages, and vmprofile

managementnode.php: added checkResourceInUse: check for managment node usage in reservations and blockRequest

resource.php:
-modified AJpromptToggleDeleteResource: added call to checkResourceInUse before prompting to confirm deleting resource
-added checkResourceInUse stub function

schedule.php: added checkResourceInUse: check for schedule usage in computer table

resources.js: modified toggleDeleteResourceCB: if status is 'inuse' create dialog to display message to user about resource being in use

Modified:
    vcl/trunk/web/.ht-inc/computer.php
    vcl/trunk/web/.ht-inc/image.php
    vcl/trunk/web/.ht-inc/managementnode.php
    vcl/trunk/web/.ht-inc/resource.php
    vcl/trunk/web/.ht-inc/schedule.php
    vcl/trunk/web/js/resources.js

Modified: vcl/trunk/web/.ht-inc/computer.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/computer.php?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/computer.php (original)
+++ vcl/trunk/web/.ht-inc/computer.php Fri Dec 12 20:55:14 2014
@@ -3014,6 +3014,19 @@ class Computer extends Resource {
 		$qh = doQuery($query);
 		while($row = mysql_fetch_assoc($qh))
 			$skipcompids[] = $row['computerid'];
+		$query = "SELECT DISTINCT bc.computerid "
+		       . "FROM blockTimes bt, "
+		       .      "blockComputers bc, "
+		       .      "blockRequest br "
+		       . "WHERE bc.computerid in ($allids) AND "
+		       .       "bc.blockTimeid = bt.id AND "
+		       .       "bt.blockRequestid = br.id AND "
+		       .       "bt.end > NOW() AND "
+		       .       "bt.skip = 0 AND "
+		       .       "br.status = 'accepted'";
+		$qh = doQuery($query);
+		while($row = mysql_fetch_assoc($qh))
+			$skipcompids[] = $row['computerid'];
 		$delids = array_diff($compids, $skipcompids);
 		$msg = '';
 		if(count($delids)) {

Modified: vcl/trunk/web/.ht-inc/image.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/image.php?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/image.php (original)
+++ vcl/trunk/web/.ht-inc/image.php Fri Dec 12 20:55:14 2014
@@ -147,6 +147,111 @@ class Image extends Resource {
 
 	/////////////////////////////////////////////////////////////////////////////
 	///
+	/// \fn checkResourceInUse($rscid)
+	///
+	/// \return empty string if not being used; string of where resource is
+	/// being used if being used
+	///
+	/// \brief checks to see if an image is being used
+	///
+	/////////////////////////////////////////////////////////////////////////////
+	function checkResourceInUse($rscid) {
+		$msgs = array();
+
+		# check reservations
+		$query = "SELECT rq.end "
+		       . "FROM request rq, "
+		       .      "reservation rs "
+		       . "WHERE rs.requestid = rq.id AND "
+		       .       "rs.imageid = $rscid AND "
+		       .       "rq.stateid NOT IN (1, 12) AND "
+		       .       "rq.end > NOW() "
+		       . "ORDER BY rq.end DESC "
+		       . "LIMIT 1";
+		$qh = doQuery($query);
+		if($row = mysql_fetch_assoc($qh))
+			$msgs[] = "There is at least one <strong>reservation</strong> for this image. The latest end time is " . prettyDatetime($row['end'], 1) . '.';
+
+		# check blockComputers
+		$query = "SELECT br.name, "
+		       .        "bt.end " 
+		       . "FROM blockRequest br, " 
+		       .      "blockTimes bt, "
+		       .      "blockComputers bc "
+		       . "WHERE bc.imageid = $rscid AND "
+		       .       "bc.blockTimeid = bt.id AND "
+		       .       "bt.blockRequestid = br.id AND "
+		       .       "bt.end > NOW() AND "
+		       .       "bt.skip = 0 AND "
+		       .       "br.status = 'accepted' "
+		       . "ORDER BY bt.end DESC "
+		       . "LIMIT 1";
+		$qh = doQuery($query);
+		if($row = mysql_fetch_assoc($qh))
+			$msgs[] = "There is at least one <strong>Block Allocation</strong> with computers currently allocated with this image. Block Allocation \"{$row['name']}\" has the latest end time which is " . prettyDatetime($row['end'], 1) . '.';
+
+		# check blockRequest
+		$query = "SELECT br.name, "
+		       .        "bt.end " 
+		       . "FROM blockRequest br, " 
+		       .      "blockTimes bt "
+		       . "WHERE br.imageid = $rscid AND "
+		       .       "bt.blockRequestid = br.id AND "
+		       .       "bt.end > NOW() AND "
+		       .       "bt.skip = 0 AND "
+		       .       "br.status = 'accepted' "
+		       . "ORDER BY bt.end DESC "
+		       . "LIMIT 1";
+		$qh = doQuery($query);
+		if($row = mysql_fetch_assoc($qh))
+			$msgs[] = "There is at least one <strong>Block Allocation</strong> configured to use this image. Block Allocation \"{$row['name']}\" has the latest end time which is " . prettyDatetime($row['end'], 1) . '.';
+
+		# check serverprofile
+		$query = "SELECT name "
+		       . "FROM serverprofile "
+		       . "WHERE imageid = $rscid";
+		$qh = doQuery($query);
+		$profiles = array();
+		while($row = mysql_fetch_assoc($qh))
+			$profiles[] = $row['name'];
+		if(count($profiles))
+			$msgs[] = "The following <strong>Server Profiles</strong> are configured to use this image:<br><br>\n" . implode("<br>\n", $profiles);
+
+		# check subimages
+		$query = "SELECT DISTINCT i.prettyname "
+		       . "FROM image i, "
+		       .      "imagemeta im, "
+		       .      "subimages s "
+		       . "WHERE i.imagemetaid = im.id AND "
+		       .       "im.subimages = 1 AND "
+		       .       "s.imagemetaid = im.id AND "
+		       .       "s.imageid = $rscid";
+		$images = array();
+		while($row = mysql_fetch_assoc($qh))
+			$images[] = $row['prettyname'];
+		if(count($images))
+			$msgs[] = "The following <strong>images</strong> have the selected image assigned as a <strong>subimage</strong>:<br><br>\n" . implode("<br>\n", $images);
+
+		# check vmprofile
+		$query = "SELECT profilename "
+		       . "FROM vmprofile "
+		       . "WHERE imageid = $rscid";
+		$profiles = array();
+		while($row = mysql_fetch_assoc($qh))
+			$profiles[] = $row['profilename'];
+		if(count($profiles))
+			$msgs[] = "The following <strong>VM Host Profiles</strong> have the this image selected:<br><br>\n" . implode("<br>\n", $profiles);
+
+		if(empty($msgs))
+			return '';
+
+		$msg = "The selected image is currently being used in the following ways and cannot be deleted at this time.<br><br>\n";
+		$msg .= implode("<br><br>\n", $msgs) . "<br><br>\n";
+		return $msg;
+	}
+
+	/////////////////////////////////////////////////////////////////////////////
+	///
 	/// \fn submitToggleDeleteResourceExtra($rscid, $deleted)
 	///
 	/// \param $rscid - id of a resource (from image table)

Modified: vcl/trunk/web/.ht-inc/managementnode.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/managementnode.php?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/managementnode.php (original)
+++ vcl/trunk/web/.ht-inc/managementnode.php Fri Dec 12 20:55:14 2014
@@ -172,6 +172,58 @@ class ManagementNode extends Resource {
 
 	/////////////////////////////////////////////////////////////////////////////
 	///
+	/// \fn checkResourceInUse($rscid)
+	///
+	/// \return empty string if not being used; string of where resource is
+	/// being used if being used
+	///
+	/// \brief checks to see if a management node is being used
+	///
+	/////////////////////////////////////////////////////////////////////////////
+	function checkResourceInUse($rscid) {
+		$msgs = array();
+
+		# check reservations
+		$query = "SELECT rq.end "
+		       . "FROM request rq, "
+		       .      "reservation rs "
+		       . "WHERE rs.requestid = rq.id AND "
+		       .       "rs.managementnodeid = $rscid AND "
+		       .       "rq.stateid NOT IN (1, 12) AND "
+		       .       "rq.end > NOW() "
+		       . "ORDER BY rq.end DESC "
+		       . "LIMIT 1";
+		$qh = doQuery($query);
+		if($row = mysql_fetch_assoc($qh))
+			$msgs[] = "There is at least one <strong>reservation</strong> being processed by this management node. The latest end time is " . prettyDatetime($row['end'], 1) . '.';
+
+		# check blockRequest
+		$query = "SELECT br.name, "
+		       .        "bt.end " 
+		       . "FROM blockRequest br, " 
+		       .      "blockTimes bt "
+		       . "WHERE br.managementnodeid = $rscid AND "
+		       .       "bt.blockRequestid = br.id AND "
+		       .       "bt.end > NOW() AND "
+		       .       "bt.skip = 0 AND "
+		       .       "br.status = 'accepted' "
+		       . "ORDER BY bt.end DESC "
+		       . "LIMIT 1";
+		$qh = doQuery($query);
+		if($row = mysql_fetch_assoc($qh))
+			$msgs[] = "There is at least one <strong>Block Allocation</strong> being handled by this management node. Block Allocation \"{$row['name']}\" has the latest end time which is " . prettyDatetime($row['end'], 1) . '.';
+
+
+		if(empty($msgs))
+			return '';
+
+		$msg = "The selected management node is currently being used in the following ways and cannot be deleted at this time.<br><br>\n";
+		$msg .= implode("<br><br>\n", $msgs) . "<br><br>\n";
+		return $msg;
+	}
+
+	/////////////////////////////////////////////////////////////////////////////
+	///
 	/// \fn toggleDeleteResource($rscid)
 	///
 	/// \param $rscid - id of a resource (from managementnode table)

Modified: vcl/trunk/web/.ht-inc/resource.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/resource.php?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/resource.php (original)
+++ vcl/trunk/web/.ht-inc/resource.php Fri Dec 12 20:55:14 2014
@@ -623,6 +623,15 @@ class Resource {
 			sendJSON($rt);
 			return;
 		}
+		# check usage of resource
+		$msg = $this->checkResourceInUse($rscid);
+		if($msg != '') {
+			$rt = array('status' => 'inuse',
+			            'msg' => $msg,
+			            'rscid' => $rscid);
+			sendJSON($rt);
+			return;
+		}
 		$rt = array('title' => "Confirm Delete {$this->restypename}",
 		            'question' => "Delete the following {$this->restype}?",
 		            'btntxt' => "Delete {$this->restypename}",
@@ -1592,6 +1601,21 @@ class Resource {
 	/////////////////////////////////////////////////////////////////////////////
 	function extraSelectAdminOptions() {
 	}
+
+	/////////////////////////////////////////////////////////////////////////////
+	///
+	/// \fn checkResourceInUse($rscid)
+	///
+	/// \return empty string if not being used; string of where resource is
+	/// being used if being used
+	///
+	/// \brief checks to see if a resource is being used; must be implemented in
+	/// inheriting class
+	///
+	/////////////////////////////////////////////////////////////////////////////
+	function checkResourceInUse($rscid) {
+		return '';
+	}
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/web/.ht-inc/schedule.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/schedule.php?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/schedule.php (original)
+++ vcl/trunk/web/.ht-inc/schedule.php Fri Dec 12 20:55:14 2014
@@ -166,6 +166,33 @@ class Schedule extends Resource {
 
 	/////////////////////////////////////////////////////////////////////////////
 	///
+	/// \fn checkResourceInUse($rscid)
+	///
+	/// \return empty string if not being used; string of where resource is
+	/// being used if being used
+	///
+	/// \brief checks to see if a schedule is being used
+	///
+	/////////////////////////////////////////////////////////////////////////////
+	function checkResourceInUse($rscid) {
+		$msg = '';
+
+		$query = "SELECT hostname "
+		       . "FROM computer "
+		       . "WHERE scheduleid = $rscid AND "
+		       .       "deleted = 0";
+		$qh = doQuery($query);
+		$comps = array();
+		while($row = mysql_fetch_assoc($qh))
+			$comps[] = $row['hostname'];
+		if(count($comps))
+			$msg = "This schedule cannot be deleted because the following <strong>computers</strong> have it selected as their schedule:<br><br>\n" . implode("<br>\n", $comps);
+
+		return $msg;
+	}
+
+	/////////////////////////////////////////////////////////////////////////////
+	///
 	/// \fn AJsaveResource()
 	///
 	/// \brief saves changes to resource

Modified: vcl/trunk/web/js/resources.js
URL: http://svn.apache.org/viewvc/vcl/trunk/web/js/resources.js?rev=1645069&r1=1645068&r2=1645069&view=diff
==============================================================================
--- vcl/trunk/web/js/resources.js (original)
+++ vcl/trunk/web/js/resources.js Fri Dec 12 20:55:14 2014
@@ -261,6 +261,25 @@ function toggleDeleteResourceCB(data, io
 	else if(data.items.status == 'noaccess') {
 		alert(data.items.msg);
 	}
+	else if(data.items.status == 'inuse') {
+		var btn = new dijit.form.Button({
+			label: 'Close'
+		});
+		var div = document.createElement('DIV');
+		div.style = 'text-align: center;';
+		var dlg = new dijit.Dialog({
+			id: 'resourceinusedlg',
+			title: 'Resource In Use',
+			content: data.items.msg,
+			style: 'width: 400px;',
+			autofocus: false,
+			hide: function() {this.destroy();}
+		});
+		div.appendChild(btn.domNode);
+		dlg.containerNode.appendChild(div);
+		dojo.connect(btn, "onClick", function () {dlg.destroy();});
+		dlg.show();
+	}
 }
 
 function submitToggleDeleteResource() {