Skip to content

Commit 8a3d177

Browse files
authored
Separate validate -print_usage into separate tool (#587)
* JIRA WDT-388 Corrected typos for 10.3 and 12.1 server directories * JIRA WDT-388 Initial commit for modelHelp tool * JIRA WDT-388 Clean up code; use CLA exception throughout; fix recursive * JIRA WDT-388 Disable -print_usage in validate, remove from usage, fix shared argument check * JIRA WDT-388 Remove -print_usage option from validate tool * JIRA WDT-388 Revised error message * JIRA WDT-388 Rename ModelHelpPrinter * JIRA WDT-388 Moved unit tests out of validate, revised to verify output * JIRA WDT-388 Corrected message
1 parent 0a213e4 commit 8a3d177

File tree

17 files changed

+1011
-1006
lines changed

17 files changed

+1011
-1006
lines changed

core/src/main/python/model_help.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""
2+
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
The entry point for the modelHelp tool.
6+
"""
7+
import os
8+
import sys
9+
from oracle.weblogic.deploy.util import CLAException
10+
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
11+
12+
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
13+
14+
from wlsdeploy.aliases.aliases import Aliases
15+
from wlsdeploy.exception import exception_helper
16+
from wlsdeploy.logging.platform_logger import PlatformLogger
17+
from wlsdeploy.tool.modelhelp.model_help_printer import ModelHelpPrinter
18+
from wlsdeploy.tool.util import model_context_helper
19+
from wlsdeploy.util import cla_helper
20+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
21+
22+
_program_name = 'modelHelp'
23+
_class_name = 'model_help'
24+
__logger = PlatformLogger('wlsdeploy.modelhelp')
25+
26+
__required_arguments = [
27+
CommandLineArgUtil.ORACLE_HOME_SWITCH,
28+
CommandLineArgUtil.PATH_SWITCH
29+
]
30+
31+
__optional_arguments = [
32+
CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH,
33+
CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
34+
CommandLineArgUtil.RECURSIVE_SWITCH
35+
]
36+
37+
__output_types = [
38+
CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH,
39+
CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
40+
CommandLineArgUtil.RECURSIVE_SWITCH
41+
]
42+
43+
44+
def __process_args(args):
45+
"""
46+
Process the command-line arguments.
47+
:param args: the command-line arguments list
48+
:raises CLAException: if an error occurs while validating and processing the command-line arguments
49+
"""
50+
_method_name = '__process_args'
51+
52+
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
53+
required_arg_map, optional_arg_map = cla_util.process_args(args)
54+
55+
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
56+
57+
combined_arg_map = optional_arg_map.copy()
58+
combined_arg_map.update(required_arg_map)
59+
60+
# zero or one output type arguments should be set
61+
found = False
62+
for key in __output_types:
63+
if key in combined_arg_map:
64+
if found:
65+
types_text = ', '.join(__output_types)
66+
ex = exception_helper.create_cla_exception('WLSDPLY-10100', types_text)
67+
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
68+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
69+
raise ex
70+
found = True
71+
72+
return model_context_helper.create_context(_program_name, combined_arg_map)
73+
74+
75+
def print_help(model_path, model_context):
76+
"""
77+
Prints the folders and/or attributes for the specified given model_path,
78+
using control_option to filter what is output
79+
:param model_path: the model path to print help for
80+
:param model_context: the model context, used to determine print options
81+
:return: an exit code
82+
"""
83+
_method_name = 'print_help'
84+
85+
__logger.entering(model_path, class_name=_class_name, method_name=_method_name)
86+
87+
# default to NORMAL
88+
control_option = ModelHelpPrinter.ControlOptions.NORMAL
89+
90+
# determine control option using the model_context
91+
if model_context.get_recursive_control_option():
92+
control_option = ModelHelpPrinter.ControlOptions.RECURSIVE
93+
elif model_context.get_attributes_only_control_option():
94+
control_option = ModelHelpPrinter.ControlOptions.ATTRIBUTES_ONLY
95+
elif model_context.get_folders_only_control_option():
96+
control_option = ModelHelpPrinter.ControlOptions.FOLDERS_ONLY
97+
98+
aliases = Aliases(model_context)
99+
printer = ModelHelpPrinter(aliases, __logger)
100+
printer.print_model_help(model_path, control_option)
101+
102+
__logger.exiting(class_name=_class_name, method_name=_method_name)
103+
return CommandLineArgUtil.PROG_OK_EXIT_CODE
104+
105+
106+
def main(args):
107+
"""
108+
The main entry point for the discoverDomain tool.
109+
:param args: the command-line arguments
110+
"""
111+
_method_name = 'main'
112+
113+
__logger.entering(class_name=_class_name, method_name=_method_name)
114+
for index, arg in enumerate(args):
115+
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
116+
117+
try:
118+
model_context = __process_args(args)
119+
except CLAException, ex:
120+
exit_code = ex.getExitCode()
121+
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
122+
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
123+
class_name=_class_name, method_name=_method_name)
124+
cla_helper.clean_up_temp_files()
125+
sys.exit(exit_code)
126+
127+
try:
128+
model_path = model_context.get_path()
129+
exit_code = print_help(model_path, model_context)
130+
except CLAException, ve:
131+
__logger.severe('WLSDPLY-10112', _program_name, ve.getLocalizedMessage(), error=ve,
132+
class_name=_class_name, method_name=_method_name)
133+
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
134+
135+
__logger.exiting(result=exit_code, class_name=_class_name, method_name=_method_name)
136+
sys.exit(exit_code)
137+
138+
139+
if __name__ == '__main__' or __name__ == 'main':
140+
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
141+
main(sys.argv)

core/src/main/python/validate.py

Lines changed: 21 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@
4646
CommandLineArgUtil.DOMAIN_TYPE_SWITCH, # Used by shell script to locate WLST
4747
CommandLineArgUtil.MODEL_FILE_SWITCH,
4848
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
49-
CommandLineArgUtil.PRINT_USAGE_SWITCH,
5049
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
5150
CommandLineArgUtil.TARGET_VERSION_SWITCH,
5251
CommandLineArgUtil.TARGET_MODE_SWITCH,
53-
CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH,
54-
CommandLineArgUtil.FOLDERS_ONLY_SWITCH,
55-
CommandLineArgUtil.RECURSIVE_SWITCH,
5652
CommandLineArgUtil.VALIDATION_METHOD
5753
]
5854

@@ -69,7 +65,6 @@ def __process_args(args):
6965

7066
__verify_required_args_present(required_arg_map)
7167
__process_model_args(optional_arg_map)
72-
__process_print_usage_args(optional_arg_map)
7368

7469
combined_arg_map = optional_arg_map.copy()
7570
combined_arg_map.update(required_arg_map)
@@ -101,63 +96,8 @@ def __process_model_args(optional_arg_map):
10196
"""
10297
_method_name = '__process_model_args'
10398

104-
if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
105-
# nothing to do since we are printing help information rather than validating supplied artifacts...
106-
return
107-
10899
cla_helper.validate_optional_archive(_program_name, optional_arg_map)
109100
cla_helper.validate_model_present(_program_name, optional_arg_map)
110-
111-
something_to_validate = False
112-
if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
113-
something_to_validate = True
114-
115-
if not something_to_validate:
116-
ex = exception_helper.create_cla_exception('WLSDPLY-05400', _program_name,
117-
CommandLineArgUtil.PRINT_USAGE_SWITCH,
118-
CommandLineArgUtil.MODEL_FILE_SWITCH,
119-
CommandLineArgUtil.ARCHIVE_FILE_SWITCH)
120-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
121-
raise ex
122-
return
123-
124-
125-
def __process_print_usage_args(optional_arg_map):
126-
"""
127-
Validate the -print_usage related arguments.
128-
:param optional_arg_map: the optional argument map
129-
:raises: CLAException: if the arguments are not valid
130-
"""
131-
_method_name = '__process_print_usage_args'
132-
133-
if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
134-
print_usage_path = optional_arg_map[CommandLineArgUtil.PRINT_USAGE_SWITCH]
135-
found_controller_arg = None
136-
if CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH in optional_arg_map:
137-
found_controller_arg = CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH
138-
139-
if CommandLineArgUtil.FOLDERS_ONLY_SWITCH in optional_arg_map:
140-
if found_controller_arg is None:
141-
found_controller_arg = CommandLineArgUtil.FOLDERS_ONLY_SWITCH
142-
else:
143-
ex = exception_helper.create_cla_exception('WLSDPLY-05401', _program_name,
144-
CommandLineArgUtil.PRINT_USAGE_SWITCH,
145-
CommandLineArgUtil.FOLDERS_ONLY_SWITCH, found_controller_arg)
146-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
147-
raise ex
148-
149-
if CommandLineArgUtil.RECURSIVE_SWITCH in optional_arg_map:
150-
if found_controller_arg is None:
151-
found_controller_arg = CommandLineArgUtil.RECURSIVE_SWITCH
152-
else:
153-
ex = exception_helper.create_cla_exception('WLSDPLY-05401', _program_name,
154-
CommandLineArgUtil.PRINT_USAGE_SWITCH,
155-
CommandLineArgUtil.RECURSIVE_SWITCH, found_controller_arg)
156-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
157-
raise ex
158-
if found_controller_arg is not None:
159-
__logger.fine('WLSDPLY-05402', _program_name, CommandLineArgUtil.PRINT_USAGE_SWITCH, print_usage_path,
160-
found_controller_arg, class_name=_class_name, method_name=_method_name)
161101
return
162102

163103

@@ -222,40 +162,29 @@ def main(args):
222162
cla_helper.clean_up_temp_files()
223163
sys.exit(exit_code)
224164

225-
print_usage = model_context.get_print_usage()
226-
227-
if print_usage is not None:
228-
try:
229-
model_validator = Validator(model_context, logger=__logger)
230-
model_validator.print_usage(print_usage)
231-
except ValidateException, ve:
232-
__logger.severe('WLSDPLY-05404', _program_name, ve.getLocalizedMessage(), error=ve,
233-
class_name=_class_name, method_name=_method_name)
234-
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
235-
else:
236-
try:
237-
model_file_name = model_context.get_model_file()
238-
239-
if model_file_name is not None:
240-
__perform_model_file_validation(model_file_name, model_context)
241-
242-
summary_handler = SummaryHandler.findInstance()
243-
if summary_handler is not None:
244-
summary_level = summary_handler.getMaximumMessageLevel()
245-
if summary_level == Level.SEVERE:
246-
exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE
247-
elif summary_level == Level.WARNING:
248-
exit_code = CommandLineArgUtil.PROG_WARNING_EXIT_CODE
249-
250-
except ValidateException, ve:
251-
__logger.severe('WLSDPLY-20000', _program_name, ve.getLocalizedMessage(), error=ve,
252-
class_name=_class_name, method_name=_method_name)
253-
cla_helper.clean_up_temp_files()
254-
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
255-
165+
try:
166+
model_file_name = model_context.get_model_file()
167+
168+
if model_file_name is not None:
169+
__perform_model_file_validation(model_file_name, model_context)
170+
171+
summary_handler = SummaryHandler.findInstance()
172+
if summary_handler is not None:
173+
summary_level = summary_handler.getMaximumMessageLevel()
174+
if summary_level == Level.SEVERE:
175+
exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE
176+
elif summary_level == Level.WARNING:
177+
exit_code = CommandLineArgUtil.PROG_WARNING_EXIT_CODE
178+
179+
except ValidateException, ve:
180+
__logger.severe('WLSDPLY-20000', _program_name, ve.getLocalizedMessage(), error=ve,
181+
class_name=_class_name, method_name=_method_name)
256182
cla_helper.clean_up_temp_files()
183+
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
184+
185+
cla_helper.clean_up_temp_files()
257186

258-
tool_exit.end(model_context, exit_code)
187+
tool_exit.end(model_context, exit_code)
259188
return
260189

261190

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""

0 commit comments

Comments
 (0)