3030import requests
3131
3232import application_creator
33- from exceptiondef import ConflictingState , NotFound , ExceptionThatShouldBeDisplayedToCaller
33+ from exceptiondef import ConflictingState , NotFound
3434from package_parser import PackageParser
3535from async_dispatcher import AsyncDispatcher
3636from lifecycle_states import ApplicationState , PackageDeploymentState
@@ -151,7 +151,6 @@ def deploy_package(self, package):
151151 # this function will be executed in the background:
152152 def _do_deploy ():
153153 # if this value is not changed, then it is assumed that the operation never completed
154- deploy_status = {"state" : PackageDeploymentState .NOTDEPLOYED , "information" : "Error deploying " + package }
155154 try :
156155 package_file = package + '.tar.gz'
157156 logging .info ("deploy: %s" , package )
@@ -165,12 +164,9 @@ def _do_deploy():
165164 deploy_status = {"state" : PackageDeploymentState .DEPLOYED ,
166165 "information" : "Deployed " + package + " at " + self .utc_string ()}
167166 logging .info ("deployed: %s" , package )
168- except ExceptionThatShouldBeDisplayedToCaller as ex :
169- # log error to screen:
170- logging .error (ex .msg )
171- # prepare human readable message
172- error_message = package + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (ex .msg )
173- # set the status:
167+ except Exception as ex :
168+ logging .error (str (ex ))
169+ error_message = "Error deploying " + package + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (str (ex ))
174170 deploy_status = {"state" : PackageDeploymentState .NOTDEPLOYED , "information" : error_message }
175171 raise
176172 finally :
@@ -190,26 +186,21 @@ def utc_string(self):
190186 def undeploy_package (self , package ):
191187 # this function will be executed in the background:
192188 def do_undeploy ():
193- undeploy_failed = True
194- # this will be the default error message if it is not clear what the error was:
195- deploy_status = {"state" : PackageDeploymentState .DEPLOYED , "information" : "Error undeploying " + package }
189+ deploy_status = None
196190 try :
197-
198191 logging .info ("undeploy: %s" , package )
199192 self ._package_registrar .delete_package (package )
200193 logging .info ("undeployed: %s" , package )
201- deploy_status = None
202- undeploy_failed = False
203- except ExceptionThatShouldBeDisplayedToCaller as ex :
194+ except Exception as ex :
204195 # log error to screen:
205- logging .error (ex . msg )
196+ logging .error (str ( ex ) )
206197 # prepare human readable message
207- error_message = package + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (ex . msg )
198+ error_message = "Error undeploying " + package + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (str ( ex ) )
208199 # set the status:
209- deploy_status = {"state" : PackageDeploymentState .NOTDEPLOYED , "information" : error_message }
200+ deploy_status = {"state" : PackageDeploymentState .DEPLOYED , "information" : error_message }
210201 raise
211202 finally :
212- if undeploy_failed :
203+ if deploy_status is not None :
213204 # persist any errors in the database, but still throw them:
214205 self ._package_registrar .set_package_deploy_status (package , deploy_status )
215206
@@ -303,15 +294,9 @@ def do_work():
303294 create_data = self ._application_registrar .get_create_data (application )
304295 self ._application_creator .start_application (application , create_data )
305296 self ._application_registrar .set_application_status (application , ApplicationState .STARTED )
306- except ExceptionThatShouldBeDisplayedToCaller as ex :
307- self ._handle_application_error (application , ex , ApplicationState .CREATED )
308- raise
309297 except Exception as ex :
310- # report the error:
311- self ._application_registrar .set_application_status (application , ApplicationState .CREATED ,
312- "Error starting application: " + application )
313- # re-throw the exception after reporting it
314- raise Exception (ex )
298+ self ._handle_application_error (application , ex , ApplicationState .CREATED , "starting" )
299+ raise
315300 finally :
316301 self ._clear_package_progress (application )
317302 self ._state_change_event_application (application )
@@ -331,15 +316,9 @@ def do_work():
331316 create_data = self ._application_registrar .get_create_data (application )
332317 self ._application_creator .stop_application (application , create_data )
333318 self ._application_registrar .set_application_status (application , ApplicationState .CREATED )
334- except ExceptionThatShouldBeDisplayedToCaller as ex :
335- self ._handle_application_error (application , ex , ApplicationState .STARTED )
336- raise
337319 except Exception as ex :
338- # report the error:
339- self ._application_registrar .set_application_status (application , ApplicationState .STARTED ,
340- "Error stopping application: " + application )
341- # re-throw the exception after reporting it
342- raise Exception (ex )
320+ self ._handle_application_error (application , ex , ApplicationState .STARTED , "stopping" )
321+ raise
343322 finally :
344323 self ._clear_package_progress (application )
345324 self ._state_change_event_application (application )
@@ -388,14 +367,10 @@ def do_work():
388367 package_data_path , package_metadata , application , overrides )
389368 self ._application_registrar .set_create_data (application , create_data )
390369 self ._application_registrar .set_application_status (application , ApplicationState .CREATED )
391- except ExceptionThatShouldBeDisplayedToCaller as ex :
392- self ._handle_application_error (application , ex , ApplicationState .NOTCREATED )
393- raise
394370 except Exception as ex :
395- self ._application_registrar .set_application_status (application , ApplicationState .NOTCREATED ,
396- "Error creating application: " + application )
371+ self ._handle_application_error (application , ex , ApplicationState .NOTCREATED , "creating" )
397372 logging .error (traceback .format_exc (ex ))
398- raise ex
373+ raise
399374 finally :
400375 # clear inner locks:
401376 self ._clear_package_progress (application )
@@ -404,7 +379,7 @@ def do_work():
404379
405380 self .dispatcher .run_as_asynch (task = do_work )
406381
407- def _handle_application_error (self , application , ex , app_status ):
382+ def _handle_application_error (self , application , ex , app_status , operation ):
408383 """
409384 Use to handle application exceptions which should be relayed back to the user
410385 Sets the application state to an error
@@ -413,9 +388,9 @@ def _handle_application_error(self, application, ex, app_status):
413388 :param app_status: The status the app should be at following the error.
414389 """
415390 # log error to screen:
416- logging .error (ex . msg )
391+ logging .error (str ( ex ) )
417392 # prepare human readable message
418- error_message = application + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (ex . msg )
393+ error_message = "Error %s " % operation + application + " " + str (type (ex ).__name__ ) + ", details: " + json .dumps (str ( ex ) )
419394 # set the status:
420395 self ._application_registrar .set_application_status (application , app_status , error_message )
421396
@@ -432,15 +407,9 @@ def do_work():
432407 create_data = self ._application_registrar .get_create_data (application )
433408 self ._application_creator .destroy_application (application , create_data )
434409 self ._application_registrar .delete_application (application )
435- except ExceptionThatShouldBeDisplayedToCaller as ex :
436- self ._handle_application_error (application , ex , ApplicationState .STARTED )
437- raise
438410 except Exception as ex :
439- # report the error:
440- self ._application_registrar .set_application_status (application , ApplicationState .STARTED ,
441- "Error deleting application: " + application )
442- # re-throw the exception after reporting it
443- raise Exception (ex )
411+ self ._handle_application_error (application , ex , ApplicationState .STARTED , "deleting" )
412+ raise
444413 finally :
445414 self ._clear_package_progress (application )
446415 self ._state_change_event_application (application )
0 commit comments