[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions cluster_adapte ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-11-10 17:59:58

Modified files:
	luci/site/luci/Extensions: cluster_adapters.py 

Log message:
	cleanups for setting busy flags

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.158&r2=1.159

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/09 22:30:39	1.158
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/10 17:59:58	1.159
@@ -236,24 +236,33 @@
 	response.redirect(request['URL'] + "?pagetype=" + CLUSTER_CONFIG + "&clustername=" + clusterName + '&busyfirst=true')
 
 def buildClusterCreateFlags(self, batch_map, clusterName):
-  path = str(CLUSTER_FOLDER_PATH + clusterName)
-  clusterfolder = self.restrictedTraverse(path)
-  for key in batch_map.keys():
-    key = str(key)
-    batch_id = batch_map[key]
-    batch_id = str(batch_id)
-    objname = str(key + "____flag") #This suffix needed to avoid name collision
-    clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-    #now designate this new object properly
-    objpath = str(path + "/" + objname)
-    flag = self.restrictedTraverse(objpath)
-    #flag[BATCH_ID] = batch_id
-    #flag[TASKTYPE] = CLUSTER_ADD
-    #flag[FLAG_DESC] = "Creating node " + key + " for cluster " + clusterName
-    flag.manage_addProperty(BATCH_ID, batch_id, "string")
-    flag.manage_addProperty(TASKTYPE, CLUSTER_ADD, "string")
-    flag.manage_addProperty(FLAG_DESC, "Creating node " + key + " for cluster " + clusterName, "string")
-    flag.manage_addProperty(LAST_STATUS, 0, "int")
+	path = str(CLUSTER_FOLDER_PATH + clusterName)
+
+	try:
+		clusterfolder = self.restrictedTraverse(path)
+	except Exception, e:
+		luci_log.debug_verbose('buildCCF0: no cluster folder at %s' % path)
+		return None
+
+	for key in batch_map.keys():
+		try:
+			key = str(key)
+			batch_id = str(batch_map[key])
+			#This suffix needed to avoid name collision
+			objname = str(key + "____flag")
+
+			clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
+			#now designate this new object properly
+			objpath = str(path + "/" + objname)
+			flag = self.restrictedTraverse(objpath)
+
+			flag.manage_addProperty(BATCH_ID, batch_id, "string")
+			flag.manage_addProperty(TASKTYPE, CLUSTER_ADD, "string")
+			flag.manage_addProperty(FLAG_DESC, "Creating node " + key + " for cluster " + clusterName, "string")
+			flag.manage_addProperty(LAST_STATUS, 0, "int")
+		except Exception, e:
+			luci_log.debug_verbose('buildCCF1: error creating flag for %s: %s' \
+				% (key, str(e)))
 
 def validateAddClusterNode(self, request):
 	errors = list()
@@ -1770,22 +1779,27 @@
 	return child_depth + 1
 
 def serviceStart(self, rc, req):
+	svcname = None
 	try:
 		svcname = req['servicename']
-	except KeyError, e:
+	except:
 		try:
 			svcname = req.form['servicename']
 		except:
-			luci_log.debug_verbose('serviceStart error: no service name')
-			return None
+			pass
 
+	if svcname is None:
+		luci_log.debug_verbose('serviceStart0: no service name')
+		return None
+
+	nodename = None
 	try:
 		nodename = req['nodename']
-	except KeyError, e:
+	except:
 		try:
 			nodename = req.form['nodename']
 		except:
-			nodename = None
+			pass
 
 	cluname = None
 	try:
@@ -1797,52 +1811,38 @@
 			pass
 
 	if cluname is None:
-		luci_log.debug_verbose('serviceStart error: %s no service name' \
+		luci_log.debug_verbose('serviceStart2: no cluster name for svc %s' \
 			% svcname)
 		return None
 
-	ricci_agent = rc.hostname()
-
 	batch_number, result = startService(rc, svcname, nodename)
 	if batch_number is None or result is None:
-		luci_log.debug_verbose('startService %s call failed' \
-			% svcname)
+		luci_log.debug_verbose('startService3: SS(%s,%s,%s) call failed' \
+			% (svcname, cluname, nodename))
 		return None
 
-	#Now we need to create a DB flag for this system.
-	path = str(CLUSTER_FOLDER_PATH + cluname)
-	batch_id = str(batch_number)
-	objname = str(ricci_agent + "____flag")
-
 	try:
-		clusterfolder = self.restrictedTraverse(path)
-		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-		#Now we need to annotate the new DB object
-		objpath = str(path + "/" + objname)
-		flag = self.restrictedTraverse(objpath)
-		flag.manage_addProperty(BATCH_ID, batch_id, "string")
-		flag.manage_addProperty(TASKTYPE, SERVICE_START, "string")
-		flag.manage_addProperty(FLAG_DESC, "Starting service \'" + svcname + "\'", "string")
+		set_node_flag(self, cluname, rc.hostname(), str(batch_number), SERVICE_START, "Starting service \'%s\'" % svcname)
 	except Exception, e:
-		luci_log.debug_verbose('Error creating flag at %s: %s' % (objpath, str(e)))
+		luci_log.debug_verbose('startService4: error setting flags for service %s at node %s for cluster %s' % (svcname, nodename, cluname))
 
 	response = req.RESPONSE
 	response.redirect(req['HTTP_REFERER'] + "&busyfirst=true")
 
 def serviceRestart(self, rc, req):
+	svcname = None
 	try:
 		svcname = req['servicename']
-	except KeyError, e:
+	except:
 		try:
 			svcname = req.form['servicename']
 		except:
-			luci_log.debug_verbose('no service name for serviceRestart')
-			return None
-	except:
-		luci_log.debug_verbose('no service name for serviceRestart')
+			pass
+
+	if svcname is None:
+		luci_log.debug_verbose('serviceRestart0: no service name')
 		return None
 
-	#Now we need to create a DB flag for this system.
 	cluname = None
 	try:
 		cluname = req['clustername']
@@ -1853,51 +1853,36 @@
 			pass
 
 	if cluname is None:
-		luci_log.debug_verbose('unable to determine cluser name for serviceRestart %s' % svcname)
+		luci_log.debug_verbose('serviceRestart1: no cluster for %s' % svcname)
 		return None
 
 	batch_number, result = restartService(rc, svcname)
 	if batch_number is None or result is None:
-		luci_log.debug_verbose('restartService for %s failed' % svcname)
+		luci_log.debug_verbose('serviceRestart2: %s failed' % svcname)
 		return None
 				
-	ricci_agent = rc.hostname()
-
-	path = str(CLUSTER_FOLDER_PATH + cluname)
-	batch_id = str(batch_number)
-	objname = str(ricci_agent + "____flag")
-
 	try:
-		clusterfolder = self.restrictedTraverse(path)
-		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-
-		#Now we need to annotate the new DB object
-		objpath = str(path + "/" + objname)
-		flag = self.restrictedTraverse(objpath)
-		flag.manage_addProperty(BATCH_ID, batch_id, "string")
-		flag.manage_addProperty(TASKTYPE, SERVICE_RESTART, "string")
-		flag.manage_addProperty(FLAG_DESC, "Restarting service " + svcname, "string")
+		set_node_flag(self, cluname, rc.hostname(), str(batch_number), SERVICE_RESTART, "Restarting service \'%s\'" % svcname)
 	except Exception, e:
-		luci_log.debug_verbose('Error creating flag in restartService %s: %s' \
-			% (svcname, str(e)))
+		luci_log.debug_verbose('serviceRestart3: error setting flags for service %s for cluster %s' % (svcname, cluname))
 
 	response = req.RESPONSE
 	response.redirect(req['HTTP_REFERER'] + "&busyfirst=true")
 
 def serviceStop(self, rc, req):
+	svcname = None
 	try:
 		svcname = req['servicename']
-	except KeyError, e:
+	except:
 		try:
 			svcname = req.form['servicename']
 		except:
-			luci_log.debug_verbose('no service name for serviceStop')
-			return None
-	except:
-		luci_log.debug_verbose('no service name for serviceStop')
+			pass
+
+	if svcname is None:
+		luci_log.debug_verbose('serviceStop0: no service name')
 		return None
 
-	#Now we need to create a DB flag for this system.
 	cluname = None
 	try:
 		cluname = req['clustername']
@@ -1908,34 +1893,18 @@
 			pass
 
 	if cluname is None:
-		luci_log.debug_verbose('unable to determine cluser name for serviceStop %s' % svcname)
+		luci_log.debug_verbose('serviceStop1: no cluster name for %s' % svcname)
 		return None
 
 	batch_number, result = stopService(rc, svcname)
 	if batch_number is None or result is None:
-		luci_log.debug_verbose('stopService for %s failed' % svcname)
+		luci_log.debug_verbose('serviceStop2: stop %s failed' % svcname)
 		return None
 
-	ricci_agent = rc.hostname()
-
-	path = str(CLUSTER_FOLDER_PATH + cluname)
-	batch_id = str(batch_number)
-	objname = str(ricci_agent + "____flag")
-
 	try:
-		clusterfolder = self.restrictedTraverse(path)
-		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-		#Now we need to annotate the new DB object
-		objpath = str(path + "/" + objname)
-		flag = self.restrictedTraverse(objpath)
-
-		flag.manage_addProperty(BATCH_ID, batch_id, "string")
-		flag.manage_addProperty(TASKTYPE, SERVICE_STOP, "string")
-		flag.manage_addProperty(FLAG_DESC, "Stopping service " + svcname, "string")
-		time.sleep(2)
+		set_node_flag(self, cluname, rc.hostname(), str(batch_number), SERVICE_STOP, "Stopping service \'%s\'" % svcname)
 	except Exception, e:
-		luci_log.debug_verbose('Error creating flags for stopService %s: %s' \
-			% (svcname, str(e)))
+		luci_log.debug_verbose('serviceStop3: error setting flags for service %s for cluster %s' % (svcname, cluname))
 
 	response = req.RESPONSE
 	response.redirect(req['HTTP_REFERER'] + "&busyfirst=true")
@@ -2301,7 +2270,7 @@
 		return None
 
 	try:
-		set_node_flag(self, clustername, rc.hostname(), batch_number, NODE_LEAVE_CLUSTER, "Node \'%s\' leaving cluster" % nodename_resolved)
+		set_node_flag(self, clustername, rc.hostname(), str(batch_number), NODE_LEAVE_CLUSTER, "Node \'%s\' leaving cluster" % nodename_resolved)
 	except Exception, e:
 		luci_log.debug_verbose('NL4: failed to set flags: %s' % str(e))
 	return True
@@ -2313,7 +2282,7 @@
 		return None
 
 	try:
-		set_node_flag(self, clustername, rc.hostname(), batch_number, NODE_JOIN_CLUSTER, "Node \'%s\' joining cluster" % nodename_resolved)
+		set_node_flag(self, clustername, rc.hostname(), str(batch_number), NODE_JOIN_CLUSTER, "Node \'%s\' joining cluster" % nodename_resolved)
 	except Exception, e:
 		luci_log.debug_verbose('NJ1: failed to set flags: %s' % str(e))
 	return True
@@ -2391,7 +2360,7 @@
 		return None
 
 	try:
-		set_node_flag(self, clustername, rc.hostname(), batch_number, NODE_REBOOT, "Node \'%s\' is being rebooted" % nodename_resolved)
+		set_node_flag(self, clustername, rc.hostname(), str(batch_number), NODE_REBOOT, "Node \'%s\' is being rebooted" % nodename_resolved)
 	except Exception, e:
 		luci_log.debug_verbose('FNR1: failed to set flags: %s' % str(e))
 	return True
@@ -2457,7 +2426,7 @@
 		return None
 
 	try:
-		set_node_flag(self, clustername, rc.hostname(), batch_number, NODE_FENCE, "Node \'%s\' is being fenced" % nodename_resolved)
+		set_node_flag(self, clustername, rc.hostname(), str(batch_number), NODE_FENCE, "Node \'%s\' is being fenced" % nodename_resolved)
 	except Exception, e:
 		luci_log.debug_verbose('FNF4: failed to set flags: %s' % str(e))
 	return True
@@ -2577,7 +2546,7 @@
 			% (del_path, str(e)))
 
 	try:
-		set_node_flag(self, clustername, rc2.hostname(), batch_number, NODE_DELETE, "Deleting node \'%s\'" % nodename_resolved)
+		set_node_flag(self, clustername, rc2.hostname(), str(batch_number), NODE_DELETE, "Deleting node \'%s\'" % nodename_resolved)
 	except Exception, e:
 		luci_log.debug_verbose('ND10: failed to set flags: %s' % str(e))
 	return True
@@ -3686,41 +3655,47 @@
 				continue
 
 def delResource(self, rc, request):
-	errstr = 'An error occurred in while attempting to set the cluster.conf'
+	errstr = 'An error occurred while attempting to set the new cluster.conf'
 
 	try:
 		modelb = request.SESSION.get('model')
-	except:
-		luci_log.debug_verbose('delRes unable to extract model from SESSION')
+	except Exception, e:
+		luci_log.debug_verbose('delResource0: no model: %s' % str(e))
 		return errstr
 
+	name = None
 	try:
 		name = request['resourcename']
-	except KeyError, e:
+	except:
 		try:
 			name = request.form['resourcename']
 		except:
-			luci_log.debug_verbose('delRes missing resname %s' % str(e))
-			return errstr + ': ' + str(e)
-	except:
-		luci_log.debug_verbose('delRes missing resname')
-		return errstr + ': ' + str(e)
+			pass
+
+	if name is None:
+		luci_log.debug_verbose('delResource1: no resource name')
+		return errstr + ': no resource name was provided.'
 
+	clustername = None
 	try:
 		clustername = request['clustername']
-	except KeyError, e:
+	except:
 		try:
 			clustername = request.form['clustername']
 		except:
-			luci_log.debug_verbose('delRes missing cluster name')
-			return errstr + ': could not determine the cluster name.'
+			pass
+
+	if clustername is None:
+		luci_log.debug_verbose('delResource2: no cluster name for %s' % name)
+		return errstr + ': could not determine the cluster name.'
 
 	try:
 		ragent = rc.hostname()
 		if not ragent:
-			raise
-	except:
-		return errstr
+			raise Exception, 'unable to determine the hostname of the ricci agent'
+	except Exception, e:
+		luci_log.debug_verbose('delResource3: %s: %s' % (errstr, str(e)))
+		return errstr + ': could not determine the ricci agent hostname'
 
 	resPtr = modelb.getResourcesPtr()
 	resources = resPtr.getChildren()
@@ -3733,7 +3708,7 @@
 			break
 
 	if not found:
-		luci_log.debug_verbose('delRes cant find res %s' % name)
+		luci_log.debug_verbose('delResource4: cant find res %s' % name)
 		return errstr + ': the specified resource was not found.'
 
 	try:
@@ -3741,32 +3716,19 @@
 		if not conf:
 			raise Exception, 'model string is blank'
 	except Exception, e:
-		luci_log.debug_verbose('delRes: exportModelAsString failed: %s' % str(e))
+		luci_log.debug_verbose('delResource5: exportModelAsString failed: %s' \
+			% str(e))
 		return errstr
 
 	batch_number, result = setClusterConf(rc, str(conf))
 	if batch_number is None or result is None:
-		luci_log.debug_verbose('delRes: missing batch and/or result from setClusterConf')
+		luci_log.debug_verbose('delResource6: missing batch and/or result')
 		return errstr
 
-	path = CLUSTER_FOLDER_PATH + str(clustername)
-	clusterfolder = self.restrictedTraverse(path)
-	batch_id = str(batch_number)
-	objname = str(ragent) + '____flag'
-	objpath = str(path + '/' + objname)
-
 	try:
-		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-		#Now we need to annotate the new DB object
-		flag = self.restrictedTraverse(objpath)
-		flag.manage_addProperty(BATCH_ID, batch_id, "string")
-		flag.manage_addProperty(TASKTYPE, RESOURCE_REMOVE, "string")
-		flag.manage_addProperty(FLAG_DESC, "Removing Resource \'" + request['resourcename'] + "\'", "string")
+		set_node_flag(self, clustername, ragent, str(batch_number), RESOURCE_REMOVE, "Removing Resource \'%s\'" % request['resourcename'])
 	except Exception, e:
-		luci_log.debug('delRes: An error occurred while setting flag %s: %s' \
-			% (objname, str(e)))
-	except:
-		luci_log.debug('delRes: An error occurred while setting flag %s' % objname)
+		luci_log.debug_verbose('delResource7: failed to set flags: %s' % str(e))
 
 	response = request.RESPONSE
 	response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
@@ -4427,57 +4389,52 @@
 def addResource(self, request, modelb, res, res_type):
 	clustername = modelb.getClusterName()
 	if not clustername:
-		raise Exception, 'cluster name from modelb.getClusterName() is blank'
+		luci_log.debug_verbose('addResource0: no cluname from mb')
+		return 'Unable to determine cluster name'
 
 	rc = getRicciAgent(self, clustername)
 	if not rc:
-		raise Exception, 'Unable to find a ricci agent for the %s cluster' % clustername
+		luci_log.debug_verbose('addResource1: unable to find a ricci agent for cluster %s' % clustername)
+		return 'Unable to find a ricci agent for the %s cluster' % clustername
 
-	modelb.getResourcesPtr().addChild(res)
+	try:
+		modelb.getResourcesPtr().addChild(res)
+	except Exception, e:
+		luci_log.debug_verbose('addResource2: adding the new resource failed: %s' % str(e))
+		return 'Unable to add the new resource'
 
 	try:
 		conf = modelb.exportModelAsString()
 		if not conf:
 			raise Exception, 'model string for %s is blank' % clustername
 	except Exception, e:
-		luci_log.debug_verbose('addResource: exportModelAsString err: %s' % str(e))
+		luci_log.debug_verbose('addResource3: exportModelAsString : %s' \
+			% str(e))
 		return 'An error occurred while adding this resource'
 
 	try:
 		ragent = rc.hostname()
 		if not ragent:
-			luci_log.debug_verbose('missing hostname')
+			luci_log.debug_verbose('addResource4: missing ricci hostname')
 			raise Exception, 'unknown ricci agent hostname'
-		luci_log.debug_verbose('SENDING NEW CLUSTER CONF: %s' % conf)
+
 		batch_number, result = setClusterConf(rc, str(conf))
 		if batch_number is None or result is None:
-			luci_log.debug_verbose('missing batch_number or result')
-			raise Exception, 'batch_number or results is None from setClusterConf'
+			luci_log.debug_verbose('addResource5: missing batch_number or result')
+			raise Exception, 'unable to save the new cluster configuration.'
 	except Exception, e:
+		luci_log.debug_verbose('addResource6: %s' % str(e))
 		return 'An error occurred while propagating the new cluster.conf: %s' % str(e)
 
-	path = str(CLUSTER_FOLDER_PATH + clustername)
-	clusterfolder = self.restrictedTraverse(path)
-	batch_id = str(batch_number)
-	objname = str(ragent + '____flag')
-	objpath = str(path + '/' + objname)
+	if res_type != 'ip':
+		res_name = res.attr_hash['name']
+	else:
+		res_name = res.attr_hash['address']
 
 	try:
-		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-		#Now we need to annotate the new DB object
-		flag = self.restrictedTraverse(objpath)
-		flag.manage_addProperty(BATCH_ID, batch_id, "string")
-		flag.manage_addProperty(TASKTYPE, RESOURCE_ADD, "string")
-
-		if res_type != 'ip':
-			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['name'] + "\'", "string")
-		else:
-			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
+		set_node_flag(self, clustername, ragent, str(batch_number), RESOURCE_ADD, "Creating New Resource \'%s\'" % res_name)
 	except Exception, e:
-		try:
-			luci_log.info('Unable to create flag %s: %s' % (objpath, str(e)))
-		except:
-			pass
+		luci_log.debug_verbose('addResource7: failed to set flags: %s' % str(e))
 
 	response = request.RESPONSE
 	response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]