Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 985e379

Browse files
authored
WDT-639 consistent exit handling across tools (#1169)
* WDT-639 consistent exit handling across tools * WDT-639 removed some duplicate code
1 parent 72f1f5b commit 985e379

File tree

13 files changed

+89
-135
lines changed

13 files changed

+89
-135
lines changed

‎core/src/main/python/compare_model.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from wlsdeploy.tool.compare.model_comparer import ModelComparer
4242
from wlsdeploy.tool.validate.validator import Validator
4343
from wlsdeploy.util import cla_helper
44+
from wlsdeploy.util import tool_exit
4445
from wlsdeploy.util import validate_configuration
4546
from wlsdeploy.util import variables
4647
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -203,7 +204,7 @@ def compare(self):
203204
except YamlException, ye:
204205
_logger.severe('WLSDPLY-05708', file_name, ye.getLocalizedMessage(),
205206
error=ye, class_name=_class_name, method_name=_method_name)
206-
System.exit(ExitCode.ERROR)
207+
tool_exit.end(None, ExitCode.ERROR)
207208
else:
208209
# write the change model to standard output in YAML format
209210
print(format_message('WLSDPLY-05707'))
@@ -251,6 +252,7 @@ def main():
251252
_logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
252253

253254
_outputdir = None
255+
_exit_code = ExitCode.OK
254256

255257
try:
256258
model_context = __process_args(sys.argv)
@@ -269,7 +271,7 @@ def main():
269271
obj = ModelFileDiffer(model1, model2, model_context, _outputdir)
270272
rc = obj.compare()
271273
if rc == VALIDATION_FAIL:
272-
System.exit(ExitCode.ERROR)
274+
tool_exit.__log_and_exit(_logger, model_context, ExitCode.ERROR, _class_name, _method_name)
273275

274276
if _outputdir:
275277
fos = None
@@ -311,30 +313,25 @@ def main():
311313
index = index + 1
312314
print(BLANK_LINE)
313315

314-
System.exit(0)
315-
316316
except CLAException, ex:
317-
exit_code = ex.getExitCode()
318-
if exit_code != ExitCode.HELP:
317+
_exit_code = ex.getExitCode()
318+
if _exit_code != ExitCode.HELP:
319319
_logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
320320
class_name=_class_name, method_name=_method_name)
321-
cla_helper.clean_up_temp_files()
322-
sys.exit(exit_code)
323321
except CompareException, ce:
324-
cla_helper.clean_up_temp_files()
322+
_exit_code=ExitCode.ERROR
325323
_logger.severe('WLSDPLY-05704', ce.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
326-
System.exit(ExitCode.ERROR)
327324
except PyWLSTException, pe:
328-
cla_helper.clean_up_temp_files()
325+
_exit_code=ExitCode.ERROR
329326
_logger.severe('WLSDPLY-05704', pe.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
330-
System.exit(ExitCode.ERROR)
331327
except:
332328
exc_type, exc_obj, exc_tb = sys.exc_info()
329+
_exit_code = ExitCode.ERROR
333330
ee_string = traceback.format_exception(exc_type, exc_obj, exc_tb)
334-
cla_helper.clean_up_temp_files()
335331
_logger.severe('WLSDPLY-05704', ee_string)
336-
System.exit(ExitCode.ERROR)
337332

333+
cla_helper.clean_up_temp_files()
334+
tool_exit.__log_and_exit(_logger, model_context, _exit_code, _class_name, _method_name)
338335

339336
def format_message(key, *args):
340337
"""

‎core/src/main/python/create.py‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,20 @@ def main(args):
305305

306306
WlstHelper(ExceptionType.CREATE).silence()
307307

308-
exit_code = ExitCode.OK
308+
_exit_code = ExitCode.OK
309309

310310
try:
311311
model_context = __process_args(args)
312312
except CLAException, ex:
313-
exit_code = ex.getExitCode()
314-
if exit_code != ExitCode.HELP:
313+
_exit_code = ex.getExitCode()
314+
if _exit_code != ExitCode.HELP:
315315
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
316316
class_name=_class_name, method_name=_method_name)
317317
cla_helper.clean_up_temp_files()
318318

319319
# create a minimal model for summary logging
320320
model_context = model_context_helper.create_exit_context(_program_name)
321-
tool_exit.end(model_context, exit_code)
321+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
322322

323323
aliases = Aliases(model_context, wlst_mode=__wlst_mode, exception_type=ExceptionType.CREATE)
324324

@@ -350,33 +350,24 @@ def main(args):
350350
rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map)
351351
ssl_helper.fix_jps_config(rcu_db_info, model_context)
352352
except WLSDeployArchiveIOException, ex:
353+
_exit_code = ExitCode.ERROR
353354
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
354355
class_name=_class_name, method_name=_method_name)
355-
cla_helper.clean_up_temp_files()
356-
tool_exit.end(model_context, ExitCode.ERROR)
357-
358356
except CreateException, ex:
357+
_exit_code = ExitCode.ERROR
359358
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
360359
class_name=_class_name, method_name=_method_name)
361-
cla_helper.clean_up_temp_files()
362-
tool_exit.end(model_context, ExitCode.ERROR)
363-
364360
except IOException, ex:
361+
_exit_code = ExitCode.ERROR
365362
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
366363
class_name=_class_name, method_name=_method_name)
367-
cla_helper.clean_up_temp_files()
368-
tool_exit.end(model_context, ExitCode.ERROR)
369-
370364
except DeployException, ex:
365+
_exit_code = ExitCode.ERROR
371366
__logger.severe('WLSDPLY-12410', _program_name, ex.getLocalizedMessage(), error=ex,
372367
class_name=_class_name, method_name=_method_name)
373-
cla_helper.clean_up_temp_files()
374-
tool_exit.end(model_context, ExitCode.ERROR)
375368

376369
cla_helper.clean_up_temp_files()
377-
378-
tool_exit.end(model_context, exit_code)
379-
370+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
380371

381372
if __name__ == '__main__' or __name__ == 'main':
382373
WebLogicDeployToolingVersion.logVersionInfo(_program_name)

‎core/src/main/python/deploy.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,38 +227,35 @@ def main(args):
227227

228228
__wlst_helper.silence()
229229

230-
exit_code = ExitCode.OK
230+
_exit_code = ExitCode.OK
231231

232232
try:
233233
model_context = __process_args(args)
234234
except CLAException, ex:
235-
exit_code = ex.getExitCode()
236-
if exit_code != ExitCode.HELP:
235+
_exit_code = ex.getExitCode()
236+
if _exit_code != ExitCode.HELP:
237237
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
238238
class_name=_class_name, method_name=_method_name)
239239
cla_helper.clean_up_temp_files()
240240

241241
# create a minimal model for summary logging
242242
model_context = model_context_helper.create_exit_context(_program_name)
243-
tool_exit.end(model_context, exit_code)
243+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
244244

245245
aliases = Aliases(model_context, wlst_mode=__wlst_mode, exception_type=ExceptionType.DEPLOY)
246246

247247
model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "deploy", __wlst_mode)
248248

249249
try:
250250
model = Model(model_dictionary)
251-
exit_code = __deploy(model, model_context, aliases)
251+
_exit_code = __deploy(model, model_context, aliases)
252252
except DeployException, ex:
253+
_exit_code = ExitCode.ERROR
253254
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
254255
class_name=_class_name, method_name=_method_name)
255-
cla_helper.clean_up_temp_files()
256-
tool_exit.end(model_context, ExitCode.ERROR)
257256

258257
cla_helper.clean_up_temp_files()
259-
260-
tool_exit.end(model_context, exit_code)
261-
258+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
262259

263260
if __name__ == '__main__' or __name__ == 'main':
264261
WebLogicDeployToolingVersion.logVersionInfo(_program_name)

‎core/src/main/python/discover.py‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ def __clear_archive_file(model_context):
348348
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
349349
raise de
350350

351+
__logger.exiting(class_name=_class_name, method_name=_method_name)
352+
351353

352354
def __close_archive(model_context):
353355
"""
@@ -509,6 +511,7 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
509511
archive_file_name=model_context.get_archive_file_name())
510512
except ValidateException, ex:
511513
__logger.warning('WLSDPLY-06015', ex.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
514+
__logger.exiting(_class_name, _method_name)
512515
return model
513516

514517

@@ -555,19 +558,6 @@ def __remote_report(model_context):
555558
print key, ' ', wls_archive
556559
print ''
557560

558-
559-
def __log_and_exit(model_context, exit_code, class_name, method_name):
560-
"""
561-
Helper method to log the exiting message and call sys.exit()
562-
:param exit_code: the exit code to use
563-
:param class_name: the class name to pass to the logger
564-
:param method_name: the method name to pass to the logger
565-
"""
566-
__logger.exiting(result=exit_code, class_name=class_name, method_name=method_name)
567-
568-
tool_exit.end(model_context, exit_code)
569-
570-
571561
def main(args):
572562
"""
573563
The main entry point for the discoverDomain tool.
@@ -595,14 +585,14 @@ def main(args):
595585

596586
# create a minimal model for summary logging
597587
model_context = model_context_helper.create_exit_context(_program_name)
598-
__log_and_exit(model_context, exit_code, _class_name, _method_name)
588+
tool_exit.__log_and_exit(__logger, model_context, exit_code, _class_name, _method_name)
599589

600590
try:
601591
__clear_archive_file(model_context)
602592
except DiscoverException, ex:
603593
__logger.severe('WLSDPLY-06010', _program_name, model_context.get_archive_file_name(),
604594
ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name)
605-
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
595+
tool_exit.__log_and_exit(__logger, model_context, ExitCode.ERROR, _class_name, _method_name)
606596

607597
aliases = Aliases(model_context, wlst_mode=__wlst_mode, exception_type=ExceptionType.DISCOVER)
608598
model = None
@@ -625,19 +615,19 @@ def main(args):
625615
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
626616
model_context.get_domain_home(), ex.getLocalizedMessage(),
627617
error=ex, class_name=_class_name, method_name=_method_name)
628-
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
618+
tool_exit.__log_and_exit(__logger, model_context, ExitCode.ERROR, _class_name, _method_name)
629619

630620
try:
631621
__persist_model(model, model_context)
632622

633623
except TranslateException, ex:
634624
__logger.severe('WLSDPLY-20024', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(),
635625
error=ex, class_name=_class_name, method_name=_method_name)
636-
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
626+
tool_exit.__log_and_exit(__logger, model_context, ExitCode.ERROR, _class_name, _method_name)
637627

638628
__close_archive(model_context)
639629

640-
__log_and_exit(model_context, exit_code, _class_name, _method_name)
630+
tool_exit.__log_and_exit(__logger, model_context, exit_code, _class_name, _method_name)
641631

642632

643633
if __name__ == '__main__' or __name__ == 'main':
@@ -648,4 +638,4 @@ def main(args):
648638
except exceptions.SystemExit, ex:
649639
raise ex
650640
except (exceptions.Exception, java.lang.Exception), ex:
651-
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
641+
tool_exit.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)

‎core/src/main/python/encrypt.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
from wlsdeploy.exception.expection_types import ExceptionType
2727
from wlsdeploy.logging.platform_logger import PlatformLogger
2828
from wlsdeploy.tool.encrypt import encryption_utils
29+
from wlsdeploy.tool.util import model_context_helper
2930
from wlsdeploy.util import cla_utils
3031
from wlsdeploy.util import getcreds
32+
from wlsdeploy.util import tool_exit
3133
from wlsdeploy.util import variables as variable_helper
3234
from wlsdeploy.util.cla_utils import CommandLineArgUtil
3335
from wlsdeploy.util.exit_code import ExitCode
@@ -216,6 +218,7 @@ def _process_request(args):
216218
if exit_code != ExitCode.HELP:
217219
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
218220
class_name=_class_name, method_name=_method_name)
221+
__logger.exiting(class_name=_class_name, method_name=_method_name, result=exit_code)
219222
return exit_code
220223

221224
if model_context.is_encryption_manual():
@@ -250,9 +253,9 @@ def main(args):
250253
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
251254

252255
exit_code = _process_request(args)
253-
__logger.exiting(class_name=_class_name, method_name=_method_name, result=exit_code)
254-
sys.exit(exit_code)
255-
256+
# create a minimal model for summary logging
257+
model_context=model_context_helper.create_exit_context(_program_name)
258+
tool_exit.__log_and_exit(__logger, model_context, exit_code, _class_name, _method_name)
256259

257260
if __name__ == '__main__' or __name__ == 'main':
258261
WebLogicDeployToolingVersion.logVersionInfo(_program_name)

‎core/src/main/python/extract_resource.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,37 +125,35 @@ def main(args):
125125
for index, arg in enumerate(args):
126126
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
127127

128-
exit_code = ExitCode.OK
128+
_exit_code = ExitCode.OK
129129

130130
try:
131131
model_context = __process_args(args)
132132
except CLAException, ex:
133-
exit_code = ex.getExitCode()
134-
if exit_code != ExitCode.HELP:
133+
_exit_code = ex.getExitCode()
134+
if _exit_code != ExitCode.HELP:
135135
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
136136
class_name=_class_name, method_name=_method_name)
137137
cla_helper.clean_up_temp_files()
138138

139139
# create a minimal model for summary logging
140140
model_context = model_context_helper.create_exit_context(_program_name)
141-
tool_exit.end(model_context, exit_code)
141+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
142142

143143
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
144144

145145
model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "extract", __wlst_mode)
146146

147147
try:
148148
model = Model(model_dictionary)
149-
exit_code = __extract_resource(model, model_context, aliases)
149+
_exit_code = __extract_resource(model, model_context, aliases)
150150
except DeployException, ex:
151+
_exit_code = ExitCode.ERROR
151152
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
152153
class_name=_class_name, method_name=_method_name)
153-
cla_helper.clean_up_temp_files()
154-
tool_exit.end(model_context, ExitCode.ERROR)
155154

156155
cla_helper.clean_up_temp_files()
157-
158-
tool_exit.end(model_context, exit_code)
156+
tool_exit.__log_and_exit(__logger, model_context, _exit_code, _class_name, _method_name)
159157
return
160158

161159

‎core/src/main/python/model_help.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
1414

1515
# Jython tools don't require sys.path modification
16-
1716
from wlsdeploy.aliases.aliases import Aliases
18-
from wlsdeploy.aliases.wlst_modes import WlstModes
1917
from wlsdeploy.exception import exception_helper
2018
from wlsdeploy.logging.platform_logger import PlatformLogger
2119
from wlsdeploy.tool.modelhelp.model_help_printer import ModelHelpPrinter
2220
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
2321
from wlsdeploy.tool.util import model_context_helper
2422
from wlsdeploy.util import cla_helper
2523
from wlsdeploy.util import model
24+
from wlsdeploy.util import tool_exit
2625
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2726
from wlsdeploy.util.exit_code import ExitCode
2827

@@ -436,18 +435,17 @@ def main(args):
436435
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
437436
class_name=_class_name, method_name=_method_name)
438437
cla_helper.clean_up_temp_files()
439-
sys.exit(exit_code)
438+
tool_exit.__log_and_exit(__logger, model_context, exit_code, _class_name, _method_name)
440439

441440
try:
442441
model_path = model_context.get_trailing_argument(0)
443442
exit_code = print_help(model_path, model_context)
444443
except CLAException, ve:
445444
__logger.severe('WLSDPLY-10112', _program_name, ve.getLocalizedMessage(), error=ve,
446445
class_name=_class_name, method_name=_method_name)
447-
sys.exit(ExitCode.ERROR)
446+
exit_code=ExitCode.ERROR
448447

449-
__logger.exiting(result=exit_code, class_name=_class_name, method_name=_method_name)
450-
sys.exit(exit_code)
448+
tool_exit.__log_and_exit(__logger, model_context, exit_code, _class_name, _method_name)
451449

452450

453451
if __name__ == '__main__' or __name__ == 'main':

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /