Skip to content

Commit 5a05098

Browse files
authored
Refactor scripts to use shared code (#610)
* JIRA WDT-402 Refactor WLST scripts to use common code * JIRA WDT-402 Refactor discover script to use common code * JIRA WDT-402 Corrected typo * JIRA WDT-402 Refactor update and deploy scripts to use common code * JIRA WDT-402 Refactor create script to use common code * JIRA WDT-402 Refactor UNIX scripts to use common code * JIRA WDT-402 Use common Jython code for createDomain * JIRA WDT-402 Use common Jython code for discover * JIRA WDT-402 Refactor UNIX deploy and update scripts to use common code * JIRA WDT-402 Make domain_type argument optional for create, WLS if not specified
1 parent 6c6b8f4 commit 5a05098

File tree

15 files changed

+383
-2564
lines changed

15 files changed

+383
-2564
lines changed

core/src/main/python/create.py

Lines changed: 16 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
from oracle.weblogic.deploy.deploy import DeployException
1515
from oracle.weblogic.deploy.util import CLAException
1616
from oracle.weblogic.deploy.util import FileUtils
17-
from oracle.weblogic.deploy.util import TranslateException
18-
from oracle.weblogic.deploy.util import VariableException
1917
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
2018
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
21-
from oracle.weblogic.deploy.validate import ValidateException
2219

2320
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
2421

@@ -36,17 +33,14 @@
3633
from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo
3734
from wlsdeploy.tool.create.domain_creator import DomainCreator
3835
from wlsdeploy.tool.create.domain_typedef import CREATE_DOMAIN
39-
from wlsdeploy.tool.util import filter_helper
4036
from wlsdeploy.tool.util import model_context_helper
4137
from wlsdeploy.tool.util.alias_helper import AliasHelper
4238
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
4339
from wlsdeploy.tool.util.wlst_helper import WlstHelper
4440
from wlsdeploy.tool.util import wlst_helper
45-
from wlsdeploy.tool.validate.validator import Validator
4641
from wlsdeploy.util import cla_helper
4742
from wlsdeploy.util import getcreds
4843
from wlsdeploy.util import tool_exit
49-
from wlsdeploy.util import variables
5044
from wlsdeploy.util.cla_utils import CommandLineArgUtil
5145
from wlsdeploy.util.cla_utils import TOOL_TYPE_CREATE
5246
from wlsdeploy.util.weblogic_helper import WebLogicHelper
@@ -62,14 +56,14 @@
6256
__version = WebLogicHelper(__logger).get_actual_weblogic_version()
6357

6458
__required_arguments = [
65-
CommandLineArgUtil.ORACLE_HOME_SWITCH,
66-
CommandLineArgUtil.DOMAIN_TYPE_SWITCH
59+
CommandLineArgUtil.ORACLE_HOME_SWITCH
6760
]
6861

6962
__optional_arguments = [
7063
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
7164
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
7265
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
66+
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
7367
CommandLineArgUtil.JAVA_HOME_SWITCH,
7468
CommandLineArgUtil.MODEL_FILE_SWITCH,
7569
CommandLineArgUtil.RUN_RCU_SWITCH,
@@ -95,42 +89,29 @@ def __process_args(args):
9589
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
9690
cla_util.set_allow_multiple_models(True)
9791
required_arg_map, optional_arg_map = cla_util.process_args(args, TOOL_TYPE_CREATE)
98-
__verify_required_args_present(required_arg_map)
92+
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
9993
__process_java_home_arg(optional_arg_map)
10094
__process_domain_location_args(optional_arg_map)
101-
__process_model_args(optional_arg_map)
95+
96+
# don't verify that the archive is valid until it is needed.
97+
# this requirement is specific to create, other tools will verify it.
98+
cla_helper.validate_model_present(_program_name, optional_arg_map)
99+
cla_helper.validate_variable_file_exists(_program_name, optional_arg_map)
102100

103101
#
104102
# Verify that the domain type is a known type and load its typedef.
105103
#
106-
domain_typedef = model_context_helper.create_typedef(_program_name, required_arg_map)
104+
domain_typedef = model_context_helper.create_typedef(_program_name, optional_arg_map)
107105

108106
__process_rcu_args(optional_arg_map, domain_typedef.get_domain_type(), domain_typedef)
109-
__process_encryption_args(optional_arg_map)
107+
cla_helper.process_encryption_args(optional_arg_map)
110108
__process_opss_args(optional_arg_map)
111109

112110
combined_arg_map = optional_arg_map.copy()
113111
combined_arg_map.update(required_arg_map)
114112
return model_context_helper.create_context(_program_name, combined_arg_map, domain_typedef)
115113

116114

117-
def __verify_required_args_present(required_arg_map):
118-
"""
119-
Verify that the required args are present.
120-
:param required_arg_map: the required arguments map
121-
:raises CLAException: if one or more of the required arguments are missing
122-
"""
123-
_method_name = '__verify_required_args_present'
124-
125-
for req_arg in __required_arguments:
126-
if req_arg not in required_arg_map:
127-
ex = exception_helper.create_cla_exception('WLSDPLY-20005', _program_name, req_arg)
128-
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
129-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
130-
raise ex
131-
return
132-
133-
134115
def __process_java_home_arg(optional_arg_map):
135116
"""
136117
Verify that java_home is set. If not, set it.
@@ -175,22 +156,6 @@ def __process_domain_location_args(optional_arg_map):
175156
return
176157

177158

178-
def __process_model_args(optional_arg_map):
179-
"""
180-
Verify that the specified model_file exists, or there is a model file in the specified archive_file.
181-
Extract the model file if only the archive_file was provided.
182-
:param optional_arg_map: the optional arguments map
183-
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
184-
"""
185-
186-
# don't verify that the archive is valid until it is needed.
187-
# this requirement is specific to create, other tools will verify it.
188-
189-
cla_helper.validate_model_present(_program_name, optional_arg_map)
190-
cla_helper.validate_variable_file_exists(_program_name, optional_arg_map)
191-
return
192-
193-
194159
def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
195160
"""
196161
Determine if the RCU is needed and validate/prompt for any missing information
@@ -246,28 +211,6 @@ def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
246211
return
247212

248213

249-
def __process_encryption_args(optional_arg_map):
250-
"""
251-
Determine if the user is using our encryption and if so, get the passphrase.
252-
:param optional_arg_map: the optional arguments map
253-
:raises CLAException: if getting the passphrase from the user fails
254-
"""
255-
_method_name = '__process_encryption_args'
256-
257-
if CommandLineArgUtil.USE_ENCRYPTION_SWITCH in optional_arg_map and \
258-
CommandLineArgUtil.PASSPHRASE_SWITCH not in optional_arg_map:
259-
try:
260-
passphrase = getcreds.getpass('WLSDPLY-20002')
261-
except IOException, ioe:
262-
ex = exception_helper.create_cla_exception('WLSDPLY-20003', ioe.getLocalizedMessage(),
263-
error=ioe)
264-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
265-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
266-
raise ex
267-
optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase)
268-
return
269-
270-
271214
def __process_opss_args(optional_arg_map):
272215
"""
273216
Determine if the user is using opss wallet and if so, get the passphrase.
@@ -290,27 +233,6 @@ def __process_opss_args(optional_arg_map):
290233
return
291234

292235

293-
def validate_model(model_dictionary, model_context, aliases):
294-
_method_name = 'validate_model'
295-
296-
try:
297-
validator = Validator(model_context, aliases, wlst_mode=__wlst_mode)
298-
299-
# no need to pass the variable file for processing, substitution has already been performed
300-
return_code = validator.validate_in_tool_mode(model_dictionary, variables_file_name=None,
301-
archive_file_name=model_context.get_archive_file_name())
302-
except ValidateException, ex:
303-
__logger.severe('WLSDPLY-20000', _program_name, ex.getLocalizedMessage(), error=ex,
304-
class_name=_class_name, method_name=_method_name)
305-
cla_helper.clean_up_temp_files()
306-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
307-
308-
if return_code == Validator.ReturnCode.STOP:
309-
__logger.severe('WLSDPLY-20001', _program_name, class_name=_class_name, method_name=_method_name)
310-
cla_helper.clean_up_temp_files()
311-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
312-
313-
314236
def validate_rcu_args_and_model(model_context, model, archive_helper, alias_helper):
315237
_method_name = 'validate_rcu_args_and_model'
316238

@@ -397,62 +319,30 @@ def main(args):
397319
model_context = model_context_helper.create_exit_context(_program_name)
398320
tool_exit.end(model_context, exit_code)
399321

400-
variable_map = {}
401-
try:
402-
if model_context.get_variable_file():
403-
variable_map = variables.load_variables(model_context.get_variable_file())
404-
except VariableException, ex:
405-
__logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex,
406-
class_name=_class_name, method_name=_method_name)
407-
cla_helper.clean_up_temp_files()
408-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
409-
410-
model_file_value = model_context.get_model_file()
411-
try:
412-
model = cla_helper.merge_model_files(model_file_value, variable_map)
413-
except TranslateException, te:
414-
__logger.severe('WLSDPLY-20009', _program_name, model_file_value, te.getLocalizedMessage(), error=te,
415-
class_name=_class_name, method_name=_method_name)
416-
cla_helper.clean_up_temp_files()
417-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
418-
419-
try:
420-
variables.substitute(model, variable_map, model_context)
421-
except VariableException, ex:
422-
__logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex,
423-
class_name=_class_name, method_name=_method_name)
424-
cla_helper.clean_up_temp_files()
425-
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
426-
427-
cla_helper.persist_model(model_context, model)
428-
429322
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
430-
alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE)
431-
validate_model(model, model_context, aliases)
432323

433-
if filter_helper.apply_filters(model, "create"):
434-
# if any filters were applied, re-validate the model
435-
validate_model(model, model_context, aliases)
324+
model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "create", __wlst_mode)
436325

437326
try:
438327
archive_helper = None
439328
archive_file_name = model_context.get_archive_file_name()
440329
if archive_file_name:
441-
domain_path = _get_domain_path(model_context, model)
330+
domain_path = _get_domain_path(model_context, model_dictionary)
442331
archive_helper = ArchiveHelper(archive_file_name, domain_path, __logger, ExceptionType.CREATE)
443332

444-
has_atp = validate_rcu_args_and_model(model_context, model, archive_helper, alias_helper)
333+
alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE)
334+
has_atp = validate_rcu_args_and_model(model_context, model_dictionary, archive_helper, alias_helper)
445335

446336
# check if there is an atpwallet and extract in the domain dir
447337
# it is to support non JRF domain but user wants to use ATP database
448338
if not has_atp and archive_helper:
449339
archive_helper.extract_atp_wallet()
450340

451-
creator = DomainCreator(model, model_context, aliases)
341+
creator = DomainCreator(model_dictionary, model_context, aliases)
452342
creator.create()
453343

454344
if has_atp:
455-
rcu_properties_map = model[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO]
345+
rcu_properties_map = model_dictionary[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO]
456346
rcu_db_info = RcuDbInfo(alias_helper, rcu_properties_map)
457347
atp_helper.fix_jps_config(rcu_db_info, model_context)
458348

0 commit comments

Comments
 (0)