Skip to content

Commit ca0b400

Browse files
authored
refactor exit codes to separate module to prevent circular imports for CommandLineArgUtil (#1162)
1 parent b8fe11f commit ca0b400

22 files changed

+212
-195
lines changed

core/src/main/python/compare_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from wlsdeploy.util import validate_configuration
4545
from wlsdeploy.util import variables
4646
from wlsdeploy.util.cla_utils import CommandLineArgUtil
47+
from wlsdeploy.util.exit_code import ExitCode
4748
from wlsdeploy.util.model_context import ModelContext
4849
from wlsdeploy.util.model_translator import FileToPython
4950
from wlsdeploy.yaml.yaml_translator import PythonToYaml
@@ -317,7 +318,7 @@ def main():
317318

318319
except CLAException, ex:
319320
exit_code = 2
320-
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
321+
if exit_code != ExitCode.HELP:
321322
_logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
322323
class_name=_class_name, method_name=_method_name)
323324
cla_helper.clean_up_temp_files()

core/src/main/python/create.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from wlsdeploy.util import tool_exit
4444
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4545
from wlsdeploy.util.cla_utils import TOOL_TYPE_CREATE
46+
from wlsdeploy.util.exit_code import ExitCode
4647
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4748
from wlsdeploy.tool.create import atp_helper
4849
from wlsdeploy.tool.create import ssl_helper
@@ -128,7 +129,7 @@ def __process_java_home_arg(optional_arg_map):
128129
try:
129130
java_home = FileUtils.validateExistingDirectory(java_home_name)
130131
except IllegalArgumentException, iae:
131-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
132+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
132133
'WLSDPLY-12400', _program_name, java_home_name,
133134
iae.getLocalizedMessage(), error=iae)
134135
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
@@ -149,7 +150,7 @@ def __process_domain_location_args(optional_arg_map):
149150
has_parent = CommandLineArgUtil.DOMAIN_PARENT_SWITCH in optional_arg_map
150151

151152
if (has_home and has_parent) or (not has_home and not has_parent):
152-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE,
153+
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR,
153154
'WLSDPLY-20025', _program_name,
154155
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
155156
CommandLineArgUtil.DOMAIN_HOME_SWITCH)
@@ -183,7 +184,7 @@ def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
183184
try:
184185
password = getcreds.getpass('WLSDPLY-12403')
185186
except IOException, ioe:
186-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
187+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
187188
'WLSDPLY-12404', ioe.getLocalizedMessage(),
188189
error=ioe)
189190
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
@@ -193,14 +194,14 @@ def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
193194
try:
194195
password = getcreds.getpass('WLSDPLY-12405')
195196
except IOException, ioe:
196-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
197+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
197198
'WLSDPLY-12406', ioe.getLocalizedMessage(),
198199
error=ioe)
199200
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
200201
raise ex
201202
optional_arg_map[CommandLineArgUtil.RCU_SCHEMA_PASS_SWITCH] = String(password)
202203
else:
203-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE,
204+
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR,
204205
'WLSDPLY-12407', _program_name,
205206
CommandLineArgUtil.RCU_DB_SWITCH,
206207
CommandLineArgUtil.RCU_PREFIX_SWITCH)
@@ -223,7 +224,7 @@ def __process_opss_args(optional_arg_map):
223224
try:
224225
passphrase = getcreds.getpass('WLSDPLY-20027')
225226
except IOException, ioe:
226-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
227+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
227228
'WLSDPLY-20028', ioe.getLocalizedMessage(), error=ioe)
228229
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
229230
raise ex
@@ -259,15 +260,15 @@ def validate_rcu_args_and_model(model_context, model, archive_helper, aliases):
259260
else:
260261
__logger.severe('WLSDPLY-12411', error=None, class_name=_class_name, method_name=_method_name)
261262
cla_helper.clean_up_temp_files()
262-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
263+
tool_exit.end(model_context, ExitCode.ERROR)
263264

264265
else:
265266
if model_context.get_domain_typedef().required_rcu():
266267
if not model_context.get_rcu_database() or not model_context.get_rcu_prefix():
267268
__logger.severe('WLSDPLY-12408', model_context.get_domain_type(), CommandLineArgUtil.RCU_DB_SWITCH,
268269
CommandLineArgUtil.RCU_PREFIX_SWITCH)
269270
cla_helper.clean_up_temp_files()
270-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
271+
tool_exit.end(model_context, ExitCode.ERROR)
271272

272273
return has_atpdbinfo, has_ssldbinfo
273274

@@ -303,13 +304,13 @@ def main(args):
303304

304305
WlstHelper(ExceptionType.CREATE).silence()
305306

306-
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
307+
exit_code = ExitCode.OK
307308

308309
try:
309310
model_context = __process_args(args)
310311
except CLAException, ex:
311312
exit_code = ex.getExitCode()
312-
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
313+
if exit_code != ExitCode.HELP:
313314
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
314315
class_name=_class_name, method_name=_method_name)
315316
cla_helper.clean_up_temp_files()
@@ -351,25 +352,25 @@ def main(args):
351352
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
352353
class_name=_class_name, method_name=_method_name)
353354
cla_helper.clean_up_temp_files()
354-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
355+
tool_exit.end(model_context, ExitCode.ERROR)
355356

356357
except CreateException, ex:
357358
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
358359
class_name=_class_name, method_name=_method_name)
359360
cla_helper.clean_up_temp_files()
360-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
361+
tool_exit.end(model_context, ExitCode.ERROR)
361362

362363
except IOException, ex:
363364
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
364365
class_name=_class_name, method_name=_method_name)
365366
cla_helper.clean_up_temp_files()
366-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
367+
tool_exit.end(model_context, ExitCode.ERROR)
367368

368369
except DeployException, ex:
369370
__logger.severe('WLSDPLY-12410', _program_name, ex.getLocalizedMessage(), error=ex,
370371
class_name=_class_name, method_name=_method_name)
371372
cla_helper.clean_up_temp_files()
372-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
373+
tool_exit.end(model_context, ExitCode.ERROR)
373374

374375
cla_helper.clean_up_temp_files()
375376

core/src/main/python/deploy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from wlsdeploy.util import cla_helper
3030
from wlsdeploy.util import tool_exit
3131
from wlsdeploy.util.cla_utils import CommandLineArgUtil
32+
from wlsdeploy.util.exit_code import ExitCode
3233
from wlsdeploy.util.model import Model
3334
from wlsdeploy.util.weblogic_helper import WebLogicHelper
3435

@@ -148,7 +149,7 @@ def __deploy_online(model, model_context, aliases):
148149

149150
exit_code = deployer_utils.online_check_save_activate(model_context)
150151

151-
if exit_code != CommandLineArgUtil.PROG_CANCEL_CHANGES_IF_RESTART_EXIT_CODE:
152+
if exit_code != ExitCode.CANCEL_CHANGES_IF_RESTART:
152153
model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
153154

154155
try:
@@ -225,13 +226,13 @@ def main(args):
225226

226227
__wlst_helper.silence()
227228

228-
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
229+
exit_code = ExitCode.OK
229230

230231
try:
231232
model_context = __process_args(args)
232233
except CLAException, ex:
233234
exit_code = ex.getExitCode()
234-
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
235+
if exit_code != ExitCode.HELP:
235236
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
236237
class_name=_class_name, method_name=_method_name)
237238
cla_helper.clean_up_temp_files()
@@ -251,7 +252,7 @@ def main(args):
251252
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
252253
class_name=_class_name, method_name=_method_name)
253254
cla_helper.clean_up_temp_files()
254-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
255+
tool_exit.end(model_context, ExitCode.ERROR)
255256

256257
cla_helper.clean_up_temp_files()
257258

core/src/main/python/discover.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from wlsdeploy.util import tool_exit
5656
from wlsdeploy.util.cla_utils import CommandLineArgUtil
5757
from wlsdeploy.util.cla_utils import TOOL_TYPE_DISCOVER
58+
from wlsdeploy.util.exit_code import ExitCode
5859
from wlsdeploy.util.model import Model
5960
from wlsdeploy.util.weblogic_helper import WebLogicHelper
6061
from wlsdeploy.util import target_configuration_helper
@@ -124,11 +125,11 @@ def __process_model_archive_args(argument_map):
124125
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
125126
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
126127
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
127-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE, 'WLSDPLY-06028')
128+
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06028')
128129
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
129130
raise ex
130131
if CommandLineArgUtil.MODEL_FILE_SWITCH not in argument_map:
131-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE, 'WLSDPLY-06029')
132+
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06029')
132133
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
133134
raise ex
134135

@@ -144,22 +145,22 @@ def __process_archive_filename_arg(argument_map):
144145
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
145146
archive_file = WLSDeployArchive.noArchiveFile()
146147
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in argument_map:
147-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
148+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
148149
'WLSDPLY-06033')
149150
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
150151
raise ex
151152
else:
152153
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
153154
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
154155
if os.path.exists(archive_dir_name) is False:
155-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
156+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
156157
'WLSDPLY-06026', archive_file_name)
157158
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
158159
raise ex
159160
try:
160161
archive_file = WLSDeployArchive(archive_file_name)
161162
except (IllegalArgumentException, IllegalStateException), ie:
162-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
163+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
163164
'WLSDPLY-06013', _program_name, archive_file_name,
164165
ie.getLocalizedMessage(), error=ie)
165166
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
@@ -182,7 +183,7 @@ def __process_variable_filename_arg(optional_arg_map):
182183
try:
183184
FileUtils.validateWritableFile(variable_injector_file_name)
184185
except IllegalArgumentException, ie:
185-
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
186+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
186187
'WLSDPLY-06021',
187188
optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH],
188189
variable_injector_file_name,
@@ -581,13 +582,13 @@ def main(args):
581582
helper = WlstHelper(ExceptionType.DISCOVER)
582583
helper.silence()
583584

584-
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
585+
exit_code = ExitCode.OK
585586

586587
try:
587588
model_context = __process_args(args)
588589
except CLAException, ex:
589590
exit_code = ex.getExitCode()
590-
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
591+
if exit_code != ExitCode.HELP:
591592
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
592593
class_name=_class_name, method_name=_method_name)
593594

@@ -600,7 +601,7 @@ def main(args):
600601
except DiscoverException, ex:
601602
__logger.severe('WLSDPLY-06010', _program_name, model_context.get_archive_file_name(),
602603
ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name)
603-
__log_and_exit(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
604+
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
604605

605606
aliases = Aliases(model_context, wlst_mode=__wlst_mode, exception_type=ExceptionType.DISCOVER)
606607
model = None
@@ -623,15 +624,15 @@ def main(args):
623624
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
624625
model_context.get_domain_home(), ex.getLocalizedMessage(),
625626
error=ex, class_name=_class_name, method_name=_method_name)
626-
__log_and_exit(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
627+
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
627628

628629
try:
629630
__persist_model(model, model_context)
630631

631632
except TranslateException, ex:
632633
__logger.severe('WLSDPLY-20024', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(),
633634
error=ex, class_name=_class_name, method_name=_method_name)
634-
__log_and_exit(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
635+
__log_and_exit(model_context, ExitCode.ERROR, _class_name, _method_name)
635636

636637
__close_archive(model_context)
637638

0 commit comments

Comments
 (0)