Skip to content

Commit 880e6c1

Browse files
committed
Issue #147 - Correct exception type in catch statements; perform undo on save/activate failure
1 parent 3c03b0a commit 880e6c1

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

core/src/main/python/deploy.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from oracle.weblogic.deploy.exception import BundleAwareException
1717
from oracle.weblogic.deploy.util import CLAException
1818
from oracle.weblogic.deploy.util import FileUtils
19-
from oracle.weblogic.deploy.util import PyWLSTException
2019
from oracle.weblogic.deploy.util import TranslateException
2120
from oracle.weblogic.deploy.util import VariableException
2221
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
@@ -283,10 +282,7 @@ def __deploy_online(model, model_context, aliases):
283282
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions()
284283
__wlst_helper.edit()
285284
__wlst_helper.start_edit()
286-
except PyWLSTException, pwe:
287-
ex = exception_helper.create_deploy_exception('WLSDPLY-09006', _program_name, admin_url,
288-
pwe.getLocalizedMessage(), error=pwe)
289-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
285+
except BundleAwareException, ex:
290286
raise ex
291287

292288
__logger.info("WLSDPLY-09007", admin_url, method_name=_method_name, class_name=_class_name)
@@ -300,20 +296,18 @@ def __deploy_online(model, model_context, aliases):
300296
try:
301297
__wlst_helper.save()
302298
__wlst_helper.activate()
303-
except PyWLSTException, pwe:
304-
ex = exception_helper.create_deploy_exception('WLSDPLY-09008', pwe.getLocalizedMessage(), error=pwe)
305-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
299+
except BundleAwareException, ex:
306300
__release_edit_session_and_disconnect()
307301
raise ex
308302

309303
model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
310304

311305
try:
312306
__wlst_helper.disconnect()
313-
except PyWLSTException, pwe:
307+
except BundleAwareException, ex:
314308
# All the changes are made and active so don't raise an error that causes the program
315309
# to indicate a failure...just log the error since the process is going to exit anyway.
316-
__logger.warning('WLSDPLY-09009', _program_name, pwe.getLocalizedMessage(), error=pwe,
310+
__logger.warning('WLSDPLY-09009', _program_name, ex.getLocalizedMessage(), error=ex,
317311
class_name=_class_name, method_name=_method_name)
318312
return
319313

@@ -357,6 +351,7 @@ def __release_edit_session_and_disconnect():
357351
"""
358352
_method_name = '__release_edit_session_and_disconnect'
359353
try:
354+
__wlst_helper.undo()
360355
__wlst_helper.stop_edit()
361356
__wlst_helper.disconnect()
362357
except BundleAwareException, ex:
@@ -374,10 +369,10 @@ def __close_domain_on_error():
374369
_method_name = '__close_domain_on_error'
375370
try:
376371
__wlst_helper.close_domain()
377-
except PyWLSTException, pwe:
372+
except BundleAwareException, ex:
378373
# This method is only used for cleanup after an error so don't mask
379374
# the original problem by throwing yet another exception...
380-
__logger.warning('WLSDPLY-09013', pwe.getLocalizedMessage(), error=pwe,
375+
__logger.warning('WLSDPLY-09013', ex.getLocalizedMessage(), error=ex,
381376
class_name=_class_name, method_name=_method_name)
382377
return
383378

@@ -478,6 +473,7 @@ def main(args):
478473
__clean_up_temp_files()
479474
return
480475

476+
481477
if __name__ == "main":
482478
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
483479
main(sys.argv)

core/src/main/python/update.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from oracle.weblogic.deploy.exception import BundleAwareException
1717
from oracle.weblogic.deploy.util import CLAException
1818
from oracle.weblogic.deploy.util import FileUtils
19-
from oracle.weblogic.deploy.util import PyWLSTException
2019
from oracle.weblogic.deploy.util import TranslateException
2120
from oracle.weblogic.deploy.util import VariableException
2221
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
@@ -294,10 +293,7 @@ def __update_online(model, model_context, aliases):
294293
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions()
295294
__wlst_helper.edit()
296295
__wlst_helper.start_edit()
297-
except PyWLSTException, pwe:
298-
ex = exception_helper.create_deploy_exception('WLSDPLY-09006', _program_name, admin_url,
299-
pwe.getLocalizedMessage(), error=pwe)
300-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
296+
except BundleAwareException, ex:
301297
raise ex
302298

303299
__logger.info("WLSDPLY-09007", admin_url, method_name=_method_name, class_name=_class_name)
@@ -314,20 +310,18 @@ def __update_online(model, model_context, aliases):
314310
try:
315311
__wlst_helper.save()
316312
__wlst_helper.activate()
317-
except PyWLSTException, pwe:
318-
ex = exception_helper.create_deploy_exception('WLSDPLY-09008', pwe.getLocalizedMessage(), error=pwe)
319-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
313+
except BundleAwareException, ex:
320314
__release_edit_session_and_disconnect()
321315
raise ex
322316

323317
model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
324318

325319
try:
326320
__wlst_helper.disconnect()
327-
except PyWLSTException, pwe:
321+
except BundleAwareException, ex:
328322
# All the changes are made and active so don't raise an error that causes the program
329323
# to indicate a failure...just log the error since the process is going to exit anyway.
330-
__logger.warning('WLSDPLY-09009', _program_name, pwe.getLocalizedMessage(), error=pwe,
324+
__logger.warning('WLSDPLY-09009', _program_name, ex.getLocalizedMessage(), error=ex,
331325
class_name=_class_name, method_name=_method_name)
332326
return
333327

@@ -374,6 +368,7 @@ def __release_edit_session_and_disconnect():
374368
"""
375369
_method_name = '__release_edit_session_and_disconnect'
376370
try:
371+
__wlst_helper.undo()
377372
__wlst_helper.stop_edit()
378373
__wlst_helper.disconnect()
379374
except BundleAwareException, ex:
@@ -391,10 +386,10 @@ def __close_domain_on_error():
391386
_method_name = '__close_domain_on_error'
392387
try:
393388
__wlst_helper.close_domain()
394-
except PyWLSTException, pwe:
389+
except BundleAwareException, ex:
395390
# This method is only used for cleanup after an error so don't mask
396391
# the original problem by throwing yet another exception...
397-
__logger.warning('WLSDPLY-09013', pwe.getLocalizedMessage(), error=pwe,
392+
__logger.warning('WLSDPLY-09013', ex.getLocalizedMessage(), error=ex,
398393
class_name=_class_name, method_name=_method_name)
399394
return
400395

core/src/main/python/wlsdeploy/tool/util/wlst_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,22 @@ def stop_edit(self):
520520
raise ex
521521
return
522522

523+
def undo(self):
524+
"""
525+
Revert all unsaved or unactivated edits.
526+
:raises: BundleAwareException of the specified type: if an error occurs
527+
"""
528+
_method_name = 'undo'
529+
530+
try:
531+
wlst_helper.undo()
532+
except PyWLSTException, pwe:
533+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19142',
534+
pwe.getLocalizedMessage(), error=pwe)
535+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
536+
raise ex
537+
return
538+
523539
def save(self):
524540
"""
525541
Save the outstanding Weblogic Server configuration changes for the current edit session.

core/src/main/python/wlsdeploy/util/wlst_helper.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,23 @@ def stop_edit():
692692
_logger.exiting(class_name=_class_name, method_name=_method_name)
693693

694694

695+
def undo():
696+
"""
697+
Revert all unsaved or unactivated edits.
698+
:raises: PyWLSTException: if a WLST error occurs
699+
"""
700+
_method_name = 'undo'
701+
_logger.entering(class_name=_class_name, method_name=_method_name)
702+
703+
try:
704+
wlst.undo('true', 'y')
705+
except wlst.WLSTException, e:
706+
pwe = exception_helper.create_pywlst_exception('WLSDPLY-00069', _format_exception(e), error=e)
707+
_logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
708+
raise pwe
709+
_logger.exiting(class_name=_class_name, method_name=_method_name)
710+
711+
695712
def save():
696713
"""
697714
Save the outstanding Weblogic Server configuration changes for the current edit session.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ WLSDPLY-00065=Failed to switch to the serverConfig MBean tree: {0}
7373
WLSDPLY-00066=Failed to switch to the domainRuntime MBean tree: {0}
7474
WLSDPLY-00067=Failed to switch to the custom MBean tree: {0}
7575
WLSDPLY-00068=Failed to change directories back to the original location {0}: {1}
76+
WLSDPLY-00069=wlst.undo() failed : {0}
7677

7778
###############################################################################
7879
# Util messages (1000 - 3999) #
@@ -1098,6 +1099,7 @@ WLSDPLY-19138=Failed to redeploy application {0}:{1}
10981099
WLSDPLY-19139=Failed to start application {0}: {1}
10991100
WLSDPLY-19140=Failed to stop application {0}: {1}
11001101
WLSDPLY-19141=Failed to undeploy application {0}:{1}
1102+
WLSDPLY-19142=Failed to undo changes: {0}
11011103

11021104
# wlsdeploy/tool/util/attribute_setter.py
11031105
WLSDPLY-19200=No target found with name {0}

0 commit comments

Comments
 (0)