diff --git a/core/src/main/python/compare_model.py b/core/src/main/python/compare_model.py index 9d793343c..d92c01a9c 100644 --- a/core/src/main/python/compare_model.py +++ b/core/src/main/python/compare_model.py @@ -11,6 +11,7 @@ # # If the flag is not provided then all output is written to the standard out. # +import exceptions import os import sets import sys @@ -348,4 +349,9 @@ def format_message(key, *args): if __name__ == "__main__": - main() + try: + main() + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, _logger) diff --git a/core/src/main/python/create.py b/core/src/main/python/create.py index 6daff2c07..40871764a 100644 --- a/core/src/main/python/create.py +++ b/core/src/main/python/create.py @@ -4,8 +4,10 @@ The main module for the WLSDeploy tool to create empty domains. """ +import exceptions import os import sys + from java.io import IOException from java.lang import IllegalArgumentException from java.lang import String @@ -376,4 +378,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/deploy.py b/core/src/main/python/deploy.py index 80cc1156c..169a3f3bb 100644 --- a/core/src/main/python/deploy.py +++ b/core/src/main/python/deploy.py @@ -4,6 +4,7 @@ The entry point for the deployApps tool. """ +import exceptions import os import sys @@ -17,6 +18,7 @@ # imports from local packages start here from wlsdeploy.aliases.aliases import Aliases from wlsdeploy.aliases.wlst_modes import WlstModes +from wlsdeploy.exception import exception_helper from wlsdeploy.exception.expection_types import ExceptionType from wlsdeploy.logging.platform_logger import PlatformLogger from wlsdeploy.tool.deploy import deployer_utils @@ -258,4 +260,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/discover.py b/core/src/main/python/discover.py index fca2f1549..dbbef950d 100644 --- a/core/src/main/python/discover.py +++ b/core/src/main/python/discover.py @@ -4,6 +4,7 @@ The entry point for the discoverDomain tool. """ +import exceptions import os import sys @@ -234,6 +235,7 @@ def __discover(model_context, aliases, credential_injector, helper): model = Model() base_location = LocationContext() __connect_to_domain(model_context, helper) + try: _add_domain_name(base_location, aliases, helper) DomainInfoDiscoverer(model_context, model.get_model_domain_info(), base_location, wlst_mode=__wlst_mode, @@ -367,6 +369,7 @@ def __disconnect_domain(helper): _method_name = '__disconnect_domain' __logger.entering(class_name=_class_name, method_name=_method_name) + if __wlst_mode == WlstModes.ONLINE: try: helper.disconnect() @@ -571,7 +574,6 @@ def main(args): :return: """ _method_name = 'main' - __logger.entering(class_name=_class_name, method_name=_method_name) for index, arg in enumerate(args): __logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name) @@ -638,4 +640,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/encrypt.py b/core/src/main/python/encrypt.py index f76b972a9..35545af2f 100644 --- a/core/src/main/python/encrypt.py +++ b/core/src/main/python/encrypt.py @@ -4,6 +4,7 @@ The main module for the WLSDeploy tool to encrypt passwords. """ +import exceptions import sys from java.io import IOException @@ -253,4 +254,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/extract_resource.py b/core/src/main/python/extract_resource.py index 091cb33c8..0e62280e9 100644 --- a/core/src/main/python/extract_resource.py +++ b/core/src/main/python/extract_resource.py @@ -4,6 +4,7 @@ The entry point for the extractDomainResource tool. """ +import exceptions import sys from oracle.weblogic.deploy.deploy import DeployException @@ -158,4 +159,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/model_help.py b/core/src/main/python/model_help.py index 972adca88..610eea7cf 100644 --- a/core/src/main/python/model_help.py +++ b/core/src/main/python/model_help.py @@ -4,8 +4,10 @@ The entry point for the modelHelp tool. """ +import exceptions import os import sys + from oracle.weblogic.deploy.util import CLAException from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion @@ -133,4 +135,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/prepare_model.py b/core/src/main/python/prepare_model.py index 33a552992..e32abad68 100644 --- a/core/src/main/python/prepare_model.py +++ b/core/src/main/python/prepare_model.py @@ -7,14 +7,16 @@ # # This code prepare a list of models for deploying to WebLogic Kubernetes Operator Environment. +import exceptions +import sys import traceback -import sys from oracle.weblogic.deploy.util import CLAException from oracle.weblogic.deploy.util import PyWLSTException from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion from oracle.weblogic.deploy.prepare import PrepareException +from wlsdeploy.exception import exception_helper from wlsdeploy.logging.platform_logger import PlatformLogger from wlsdeploy.tool.prepare.model_preparer import ModelPreparer from wlsdeploy.tool.util import model_context_helper @@ -109,4 +111,9 @@ def main(): if __name__ == "__main__" or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main() + try: + main() + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/update.py b/core/src/main/python/update.py index 970719bb4..2cb67676b 100644 --- a/core/src/main/python/update.py +++ b/core/src/main/python/update.py @@ -4,6 +4,7 @@ The entry point for the updateDomain tool. """ +import exceptions import os import sys @@ -309,4 +310,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/validate.py b/core/src/main/python/validate.py index 1080d9c29..6495750fd 100644 --- a/core/src/main/python/validate.py +++ b/core/src/main/python/validate.py @@ -4,8 +4,11 @@ The WLS Deploy tooling entry point for the validateModel tool. """ + import copy +import exceptions import sys + from java.util.logging import Level from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler @@ -196,4 +199,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/variable_inject.py b/core/src/main/python/variable_inject.py index 29822804c..961d292af 100644 --- a/core/src/main/python/variable_inject.py +++ b/core/src/main/python/variable_inject.py @@ -4,6 +4,7 @@ The entry point for the injectVariables tool. """ +import exceptions import sys from java.io import File @@ -204,4 +205,9 @@ def main(args): if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) - main(sys.argv) + try: + main(sys.argv) + except exceptions.SystemExit, ex: + raise ex + except (exceptions.Exception, java.lang.Exception), ex: + exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger) diff --git a/core/src/main/python/wlsdeploy/exception/exception_helper.py b/core/src/main/python/wlsdeploy/exception/exception_helper.py index af98462f4..a85a8bbc5 100644 --- a/core/src/main/python/wlsdeploy/exception/exception_helper.py +++ b/core/src/main/python/wlsdeploy/exception/exception_helper.py @@ -31,6 +31,8 @@ import oracle.weblogic.deploy.yaml.YamlException as JYamlException from wlsdeploy.exception.expection_types import ExceptionType +from wlsdeploy.util.cla_utils import CommandLineArgUtil +from wlsdeploy.util import tool_exit _EXCEPTION_TYPE_MAP = { ExceptionType.ALIAS: 'create_alias_exception', @@ -462,3 +464,35 @@ def _return_exception_params(*args, **kwargs): arg_list = list(args) error = kwargs.pop('error', None) return arg_list, error + +def __log_and_exit(logger, exit_code, class_name): + """ + Helper method to log the exiting message and call sys.exit() + :param logger: the logger to use + :param exit_code: the exit code to use + :param class_name: the class name to pass to the logger + """ + logger.exiting(result=exit_code, class_name=class_name, method_name=None) + tool_exit.end(None, exit_code) + +def __handle_unexpected_exception(ex, program_name, class_name, logger): + """ + Helper method to log and unexpected exception with exiting message and call sys.exit() + Note that the user sees the 'Unexpected' message along with the exception, but no stack trace. + The stack trace goes to the log + :param ex: the exception thrown + :param program_name: the program where it occurred + :param class_name: the class where it occurred + :param logger: the logger to use + """ + logger.severe('WLSDPLY-20035', program_name, sys.exc_info()[0]) + + if hasattr(ex, 'stackTrace'): + # this works best for java exceptions, and gets the full stacktrace all the way back to weblogic.WLST + logger.finer('WLSDPLY-20036', program_name, ex.stackTrace) + else: + # this is for Python exceptions + # Note: since this is Python 2, it seems we can only get the traceback object via sys.exc_info, and of course only + # while in the except block handling code + logger.finer('WLSDPLY-20036', program_name, traceback.format_exception(type(ex), ex, sys.exc_info()[2])) + __log_and_exit(logger, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, class_name) diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index a4a43c212..8cfffbe3e 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1671,6 +1671,8 @@ WLSDPLY-20031={0} specified Variable File {1} is not a valid file: {2} WLSDPLY-20032=No model specified and no model in archive, no validation performed WLSDPLY-20033=Applying filter with name "{0}" WLSDPLY-20034=Applying filter with ID "{0}" +WLSDPLY-20035={0} encountered an unexpected runtime exception. Please file an issue on GitHub and attach the log file and stdout. Exception: {1} +WLSDPLY-20036={0} encountered an unexpected runtime exception. Stacktrace: {1} # Messages for internal filters WLSDPLY-20201=Unsupported attribute {0} at location {1} removed from model