summaryrefslogtreecommitdiffstats
path: root/funcweb
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-08-06 01:14:59 +0300
committermakkalot <makkalot@gmail.com>2008-08-06 01:14:59 +0300
commita0e4e882492882dcfb1edb8e87e980fdc17e863a (patch)
tree2d13e54c255c941d62dc01ea0db01c4442982d14 /funcweb
parent747f583b33a6ee863aeae404d701113bba7a5f5e (diff)
downloadfunc-a0e4e882492882dcfb1edb8e87e980fdc17e863a.tar.gz
func-a0e4e882492882dcfb1edb8e87e980fdc17e863a.tar.xz
func-a0e4e882492882dcfb1edb8e87e980fdc17e863a.zip
some try except blocks we dont want to crash everytime we have some errors :)
Diffstat (limited to 'funcweb')
-rw-r--r--funcweb/funcweb/controllers.py148
1 files changed, 102 insertions, 46 deletions
diff --git a/funcweb/funcweb/controllers.py b/funcweb/funcweb/controllers.py
index d884720..bc6206d 100644
--- a/funcweb/funcweb/controllers.py
+++ b/funcweb/funcweb/controllers.py
@@ -7,10 +7,13 @@ from funcweb.widget_automation import WidgetListFactory,RemoteFormAutomation,Rem
from funcweb.widget_validation import WidgetSchemaFactory
from funcweb.async_tools import AsyncResultManager
from func.jobthing import purge_old_jobs,JOB_ID_RUNNING,JOB_ID_FINISHED,JOB_ID_PARTIAL
-
+from func.utils import is_error
# it is assigned into method_display on every request
global_form = None
+####**NOTE : All flash messages are used for error and some weird sitaution's reporting be careful when using
+#that turbogears functionality !
+
def validate_decorator_updater(validator_value=None):
"""
When we pass the global_form directly to
@@ -58,9 +61,13 @@ class Funcweb(object):
minions = self.func_cache['minions']
else:
#we dont have it it is for first time so lets pull it
- minions=Minions(glob).get_all_hosts()
- self.func_cache['glob']=glob
- self.func_cache['minions']=minions
+ try:
+ minions=Minions(glob).get_all_hosts()
+ self.func_cache['glob']=glob
+ self.func_cache['minions']=minions
+ except Exception,e:
+ #TODO log here
+ minions = []
return minions
@@ -69,7 +76,6 @@ class Funcweb(object):
def minions(self, glob='*',submit=None):
""" Return a list of our minions that match a given glob """
#make the cache thing
-
minions = self.get_current_minion_list(glob)
if not submit:
return dict(minions=minions,submit_adress="/funcweb/minions",tg_template="funcweb.templates.index")
@@ -79,7 +85,7 @@ class Funcweb(object):
index = minions # start with our minion view, for now
- @expose(template="funcweb.templates.modules")
+ @expose(allow_json = True)
@identity.require(identity.not_anonymous())
def minion(self, name="*", module=None, method=None):
""" Display module or method details for a specific minion.
@@ -105,14 +111,29 @@ class Funcweb(object):
if not module:
if not self.func_cache['modules']:
- modules = fc.system.list_modules()
+ try :
+ modules = fc.system.list_modules()
+ if modules.has_key(name) and is_error(modules[name]):
+ #TODO put logger here!
+ flash("Some exception while getting the module list for %s minion"%(name))
+ return dict()
+
+ except Exception,e:
+ flash("Some exception while getting the module list for %s minion"%(name))
+ #it is an error case
+ return dict()
display_modules = []
for module in modules.itervalues():
for mod in module:
#if it is not empty
- if getattr(fc,mod).get_method_args()[name]:
- display_modules.append(mod)
+ try :
+ if getattr(fc,mod).get_method_args()[name]:
+ display_modules.append(mod)
+ except Exception,e:
+ #TODO logger
+ flash("Some exception while getting the argument list for %s module"%(mod))
+ return dict()
#put it into the cache to make that slow thing faster
self.func_cache['modules']=display_modules
@@ -124,8 +145,8 @@ class Funcweb(object):
modules = {}
modules[name]=display_modules
-
- return dict(modules=modules)
+
+ return dict(modules=modules,tg_template = "funcweb.templates.modules")
else: # a module is specified
if not method: # return a list of methods for specified module
#first check if we have it into the cache
@@ -136,8 +157,13 @@ class Funcweb(object):
else:
self.func_cache['module_name']= module
#display the list only that is registered with register_method template !
- registered_methods=getattr(fc,module).get_method_args()[name].keys()
- modules = getattr(fc, module).list_methods()
+ try:
+ registered_methods=getattr(fc,module).get_method_args()[name].keys()
+ modules = getattr(fc, module).list_methods()
+ except Exception,e:
+ flash("Some error in getting method list for %s module "%(module))
+ return dict()
+
for mods in modules.itervalues():
from copy import copy
cp_mods = copy(mods)
@@ -174,8 +200,16 @@ class Funcweb(object):
self.func_cache['methods']=None
#get the method args
- method_args = getattr(fc,module).get_method_args()
-
+ try:
+ method_args = getattr(fc,module).get_method_args()
+ if method_args.has_key(minion) and is_error(method_args[minion]):
+ flash("We encountered some error when getting method args for %s.%s.%s"%(minion,module,method))
+ return dict()
+
+ except Exception,e:
+ flash("We encountered some error when getting method args for %s.%s.%s"%(minion,module,method))
+ return dict()
+
if not method_args.values():
#print "Not registered method here"
return dict(minion_form = None,minion=minion,module=module,method=method)
@@ -187,19 +221,23 @@ class Funcweb(object):
else:
description = None
if minion_arguments:
- wlist_object = WidgetListFactory(minion_arguments,minion=minion,module=module,method=method)
- wlist_object = wlist_object.get_widgetlist_object()
- #create the validation parts for the remote form
- wf = WidgetSchemaFactory(minion_arguments)
- schema_man=wf.get_ready_schema()
-
- #create the final form
- minion_form = RemoteFormAutomation(wlist_object,schema_man)
- global_form = minion_form.for_widget
- #print global_form
- #i use that when something goes wrong to check the problem better to stay here ;)
- #self.minion_form =RemoteFormFactory(wlist_object,schema_man).get_remote_form()
-
+ try:
+ wlist_object = WidgetListFactory(minion_arguments,minion=minion,module=module,method=method)
+ wlist_object = wlist_object.get_widgetlist_object()
+ #create the validation parts for the remote form
+ wf = WidgetSchemaFactory(minion_arguments)
+ schema_man=wf.get_ready_schema()
+
+ #create the final form
+ minion_form = RemoteFormAutomation(wlist_object,schema_man)
+ global_form = minion_form.for_widget
+ #print global_form
+ #i use that when something goes wrong to check the problem better to stay here ;)
+ #self.minion_form =RemoteFormFactory(wlist_object,schema_man).get_remote_form()
+ except Exception,e:
+ flash("We got some exception when rendering the %s.%s.%s"%(minion,module,method))
+ return dict()
+
del wlist_object
del minion_arguments
@@ -289,7 +327,15 @@ class Funcweb(object):
#get again the method args to get their order :
- arguments=getattr(fc,module).get_method_args()
+ try:
+ arguments=getattr(fc,module).get_method_args()
+ if arguments.has_key(minion) and is_error(arguments[minion]):
+ flash("Encountered some error when trying to get method arguments for %s.%s.%s"%(minion,module,method))
+ return dict()
+
+ except Exception,e:
+ flash("Encountered some error when trying to get method arguments for %s.%s.%s"%(minion,module,method))
+ return dict()
#so we know the order just allocate and put them there
cmd_args=['']*(len(kw.keys()))
@@ -302,25 +348,30 @@ class Funcweb(object):
#at the final execute it as a multiple if the glob suits for that
#if not (actually there shouldnt be an option like that but who knows :))
#it will run as a normal single command to clicked minion
- if self.func_cache['glob']:
- fc_async = Overlord(self.func_cache['glob'],async=True)
+ try:
+ if self.func_cache['glob']:
+ fc_async = Overlord(self.func_cache['glob'],async=True)
- result_id = getattr(getattr(fc_async,module),method)(*cmd_args)
- result = "".join(["The id for current job is :",str(result_id)," You will be notified when there is some change about that command !"])
+ result_id = getattr(getattr(fc_async,module),method)(*cmd_args)
+ result = "".join(["The id for current job is :",str(result_id)," You will be notified when there is some change about that command !"])
- #that part gives a chance for short methods to finish their jobs and display them
- #immediately so user will not wait for new notifications for that short thing
- import time
- time.sleep(4)
- tmp_as_res = fc_async.job_status(result_id)
- if tmp_as_res[0] == JOB_ID_FINISHED:
- result = tmp_as_res[1]
+ #that part gives a chance for short methods to finish their jobs and display them
+ #immediately so user will not wait for new notifications for that short thing
+ import time
+ time.sleep(4)
+ tmp_as_res = fc_async.job_status(result_id)
+ if tmp_as_res[0] == JOB_ID_FINISHED:
+ result = tmp_as_res[1]
- if not self.async_manager:
- #cleanup tha database firstly
- purge_old_jobs()
- self.async_manager = AsyncResultManager()
- self.async_manager.refresh_list()
+ if not self.async_manager:
+ #cleanup tha database firstly
+ purge_old_jobs()
+ self.async_manager = AsyncResultManager()
+ self.async_manager.refresh_list()
+
+ except Exception,e:
+ flash("We got some error while trying to send command for %s.%s.%s"%(module,minion,method))
+ return dict()
#TODO reformat that returning string to be more elegant to display :)
return str(result)
@@ -351,7 +402,12 @@ class Funcweb(object):
self.func_cache['methods']=None
#i assume that they are long enough so dont poll here
- result_id = getattr(getattr(fc,module),method)()
+ try:
+ result_id = getattr(getattr(fc,module),method)()
+ except Exception,e:
+ flash("Error when executing link command for %s.%s.%s"%(minion,module,method))
+ return dict()
+
result = "".join(["The id for current id is :",str(result_id)," You will be notified when there is some change about that command !"])
return dict(result=str(result))