Skip to content

Commit 54f215d

Browse files
authored
Jira wdt 341 multi model support (#382)
* JIRA WDT-341 - Allow multiple models to be specified for create, update, deploy, and validate * JIRA WDT-341 - Update script usage for multiple model support
1 parent eacf884 commit 54f215d

File tree

14 files changed

+288
-323
lines changed

14 files changed

+288
-323
lines changed

core/src/main/python/create.py

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
from java.io import IOException
1010
from java.lang import IllegalArgumentException
11-
from java.lang import IllegalStateException
1211
from java.lang import String
1312
from java.lang import System
1413
from oracle.weblogic.deploy.create import CreateException
@@ -39,6 +38,7 @@
3938
from wlsdeploy.tool.util import filter_helper
4039
from wlsdeploy.tool.util.alias_helper import AliasHelper
4140
from wlsdeploy.tool.validate.validator import Validator
41+
from wlsdeploy.util import cla_helper
4242
from wlsdeploy.util import getcreds
4343
from wlsdeploy.util import tool_exit
4444
from wlsdeploy.util import variables
@@ -58,7 +58,6 @@
5858
__logger = PlatformLogger('wlsdeploy.create')
5959
__wlst_mode = WlstModes.OFFLINE
6060
__version = WebLogicHelper(__logger).get_actual_weblogic_version()
61-
__tmp_model_dir = None
6261

6362
__required_arguments = [
6463
CommandLineArgUtil.ORACLE_HOME_SWITCH,
@@ -89,6 +88,7 @@ def __process_args(args):
8988
:raises CLAException: if an error occurs while validating and processing the command-line arguments
9089
"""
9190
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
91+
cla_util.set_allow_multiple_models(True)
9292
required_arg_map, optional_arg_map = cla_util.process_args(args, True)
9393
__verify_required_args_present(required_arg_map)
9494
__process_java_home_arg(optional_arg_map)
@@ -159,7 +159,6 @@ def __process_domain_location_args(optional_arg_map):
159159
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
160160
"""
161161
_method_name = '__process_domain_location_args'
162-
global __tmp_model_dir
163162

164163
has_home = CommandLineArgUtil.DOMAIN_HOME_SWITCH in optional_arg_map
165164
has_parent = CommandLineArgUtil.DOMAIN_PARENT_SWITCH in optional_arg_map
@@ -176,53 +175,16 @@ def __process_domain_location_args(optional_arg_map):
176175

177176
def __process_model_args(optional_arg_map):
178177
"""
179-
Verify that either the model_file or archive_file was provided and exists.
178+
Verify that the specified model_file exists, or there is a model file in the specified archive_file.
180179
Extract the model file if only the archive_file was provided.
181180
:param optional_arg_map: the optional arguments map
182181
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
183182
"""
184-
_method_name = '__process_model_args'
185-
global __tmp_model_dir
186183

187-
if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
188-
model_file_name = optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
184+
# don't verify that the archive is valid until it is needed.
185+
# this requirement is specific to create, other tools will verify it.
189186

190-
try:
191-
FileUtils.validateExistingFile(model_file_name)
192-
except IllegalArgumentException, iae:
193-
ex = exception_helper.create_cla_exception('WLSDPLY-20006', _program_name, model_file_name,
194-
iae.getLocalizedMessage(), error=iae)
195-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
196-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
197-
raise ex
198-
elif CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
199-
archive_file_name = optional_arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
200-
201-
try:
202-
archive_file = WLSDeployArchive(archive_file_name)
203-
__tmp_model_dir = FileUtils.createTempDirectory(_program_name)
204-
tmp_model_raw_file = archive_file.extractModel(__tmp_model_dir)
205-
if not tmp_model_raw_file:
206-
ex = exception_helper.create_cla_exception('WLSDPLY-20026', _program_name, archive_file_name,
207-
CommandLineArgUtil.MODEL_FILE_SWITCH)
208-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
209-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
210-
raise ex
211-
212-
tmp_model_file = FileUtils.fixupFileSeparatorsForJython(tmp_model_raw_file.getAbsolutePath())
213-
except (IllegalArgumentException, IllegalStateException, WLSDeployArchiveIOException), archex:
214-
ex = exception_helper.create_cla_exception('WLSDPLY-20010', _program_name, archive_file_name,
215-
archex.getLocalizedMessage(), error=archex)
216-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
217-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
218-
raise ex
219-
optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = FileUtils.fixupFileSeparatorsForJython(tmp_model_file)
220-
else:
221-
ex = exception_helper.create_cla_exception('WLSDPLY-20015', _program_name, CommandLineArgUtil.MODEL_FILE_SWITCH,
222-
CommandLineArgUtil.ARCHIVE_FILE_SWITCH)
223-
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
224-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
225-
raise ex
187+
cla_helper.validate_model_present(_program_name, optional_arg_map)
226188
return
227189

228190

@@ -303,17 +265,6 @@ def __process_encryption_args(optional_arg_map):
303265
return
304266

305267

306-
def __clean_up_temp_files():
307-
"""
308-
If a temporary directory was created to extract the model from the archive, delete the directory and its contents.
309-
"""
310-
global __tmp_model_dir
311-
312-
if __tmp_model_dir is not None:
313-
FileUtils.deleteDirectory(__tmp_model_dir)
314-
__tmp_model_dir = None
315-
316-
317268
def validate_model(model_dictionary, model_context, aliases):
318269
_method_name = 'validate_model'
319270

@@ -326,12 +277,12 @@ def validate_model(model_dictionary, model_context, aliases):
326277
except ValidateException, ex:
327278
__logger.severe('WLSDPLY-20000', _program_name, ex.getLocalizedMessage(), error=ex,
328279
class_name=_class_name, method_name=_method_name)
329-
__clean_up_temp_files()
280+
cla_helper.clean_up_temp_files()
330281
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
331282

332283
if return_code == Validator.ReturnCode.STOP:
333284
__logger.severe('WLSDPLY-20001', _program_name, class_name=_class_name, method_name=_method_name)
334-
__clean_up_temp_files()
285+
cla_helper.clean_up_temp_files()
335286
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
336287

337288

@@ -365,15 +316,15 @@ def validateRCUArgsAndModel(model_context, model, alias_helper):
365316
else:
366317
__logger.severe('WLSDPLY-12411', error=None,
367318
class_name=_class_name, method_name="validateRCUArgsAndModel")
368-
__clean_up_temp_files()
319+
cla_helper.clean_up_temp_files()
369320
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
370321

371322
else:
372323
if model_context.get_domain_typedef().required_rcu():
373324
if not model_context.get_rcu_database() or not model_context.get_rcu_prefix():
374325
__logger.severe('WLSDPLY-12408', model_context.get_domain_type(), CommandLineArgUtil.RCU_DB_SWITCH,
375326
CommandLineArgUtil.RCU_PREFIX_SWITCH)
376-
__clean_up_temp_files()
327+
cla_helper.clean_up_temp_files()
377328
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
378329

379330
return has_atpdbinfo
@@ -403,19 +354,19 @@ def main(args):
403354
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
404355
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
405356
class_name=_class_name, method_name=_method_name)
406-
__clean_up_temp_files()
357+
cla_helper.clean_up_temp_files()
407358

408359
# create a minimal model for summary logging
409360
model_context = ModelContext(_program_name, dict())
410361
tool_exit.end(model_context, exit_code)
411362

412-
model_file = model_context.get_model_file()
363+
model_file_value = model_context.get_model_file()
413364
try:
414-
model = FileToPython(model_file, True).parse()
365+
model = cla_helper.merge_model_files(model_file_value)
415366
except TranslateException, te:
416-
__logger.severe('WLSDPLY-20009', _program_name, model_file, te.getLocalizedMessage(), error=te,
367+
__logger.severe('WLSDPLY-20009', _program_name, model_file_value, te.getLocalizedMessage(), error=te,
417368
class_name=_class_name, method_name=_method_name)
418-
__clean_up_temp_files()
369+
cla_helper.clean_up_temp_files()
419370
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
420371

421372
try:
@@ -426,7 +377,7 @@ def main(args):
426377
except VariableException, ex:
427378
__logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex,
428379
class_name=_class_name, method_name=_method_name)
429-
__clean_up_temp_files()
380+
cla_helper.clean_up_temp_files()
430381
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
431382

432383
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
@@ -460,27 +411,28 @@ def main(args):
460411
except WLSDeployArchiveIOException, ex:
461412
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
462413
class_name=_class_name, method_name=_method_name)
463-
__clean_up_temp_files()
414+
cla_helper.clean_up_temp_files()
464415
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
465416

466417
except CreateException, ex:
467418
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
468419
class_name=_class_name, method_name=_method_name)
469-
__clean_up_temp_files()
420+
cla_helper.clean_up_temp_files()
470421
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
471422

472423
except IOException, ex:
473424
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
474425
class_name=_class_name, method_name=_method_name)
475-
__clean_up_temp_files()
426+
cla_helper.clean_up_temp_files()
476427
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
428+
477429
except DeployException, ex:
478430
__logger.severe('WLSDPLY-12410', _program_name, ex.getLocalizedMessage(), error=ex,
479431
class_name=_class_name, method_name=_method_name)
480-
__clean_up_temp_files()
432+
cla_helper.clean_up_temp_files()
481433
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
482434

483-
__clean_up_temp_files()
435+
cla_helper.clean_up_temp_files()
484436

485437
tool_exit.end(model_context, exit_code)
486438
return

core/src/main/python/deploy.py

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from wlsdeploy.tool.validate.validator import Validator
3737
from wlsdeploy.tool.util import filter_helper
3838
from wlsdeploy.tool.util.wlst_helper import WlstHelper
39+
from wlsdeploy.util import cla_helper
3940
from wlsdeploy.util import getcreds
4041
from wlsdeploy.util import tool_exit
4142
from wlsdeploy.util import variables
@@ -55,7 +56,6 @@
5556
__wls_helper = WebLogicHelper(__logger)
5657
__wlst_helper = WlstHelper(__logger, ExceptionType.DEPLOY)
5758
__wlst_mode = WlstModes.OFFLINE
58-
__tmp_model_dir = None
5959

6060
__required_arguments = [
6161
CommandLineArgUtil.ORACLE_HOME_SWITCH,
@@ -86,6 +86,7 @@ def __process_args(args):
8686
global __wlst_mode
8787

8888
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
89+
cla_util.set_allow_multiple_models(True)
8990
required_arg_map, optional_arg_map = cla_util.process_args(args)
9091

9192
__verify_required_args_present(required_arg_map)
@@ -143,60 +144,8 @@ def __process_model_args(optional_arg_map):
143144
:param optional_arg_map: the optional arguments map
144145
:raises CLAException: If an error occurs validating the arguments or extracting the model from the archive
145146
"""
146-
_method_name = '__process_model_args'
147-
global __tmp_model_dir
148-
149-
archive_file_name = None
150-
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
151-
archive_file_name = optional_arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
152-
153-
try:
154-
FileUtils.validateExistingFile(archive_file_name)
155-
except IllegalArgumentException, iae:
156-
ex = exception_helper.create_cla_exception('WLSDPLY-20014', _program_name, archive_file_name,
157-
iae.getLocalizedMessage(), error=iae)
158-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
159-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
160-
raise ex
161-
162-
if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
163-
model_file_name = optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
164-
165-
try:
166-
FileUtils.validateExistingFile(model_file_name)
167-
except IllegalArgumentException, iae:
168-
ex = exception_helper.create_cla_exception('WLSDPLY-20006', _program_name, model_file_name,
169-
iae.getLocalizedMessage(), error=iae)
170-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
171-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
172-
raise ex
173-
elif archive_file_name is not None:
174-
try:
175-
archive_file = WLSDeployArchive(archive_file_name)
176-
__tmp_model_dir = FileUtils.createTempDirectory(_program_name)
177-
tmp_model_raw_file = archive_file.extractModel(__tmp_model_dir)
178-
if not tmp_model_raw_file:
179-
ex = exception_helper.create_cla_exception('WLSDPLY-20026', _program_name, archive_file_name,
180-
CommandLineArgUtil.MODEL_FILE_SWITCH)
181-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
182-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
183-
raise ex
184-
185-
model_file_name = FileUtils.fixupFileSeparatorsForJython(tmp_model_raw_file.getAbsolutePath())
186-
except (IllegalArgumentException, IllegalStateException, WLSDeployArchiveIOException), archex:
187-
ex = exception_helper.create_cla_exception('WLSDPLY-20010', _program_name, archive_file_name,
188-
archex.getLocalizedMessage(), error=archex)
189-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
190-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
191-
raise ex
192-
optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name
193-
else:
194-
ex = exception_helper.create_cla_exception('WLSDPLY-20015', _program_name,
195-
CommandLineArgUtil.MODEL_FILE_SWITCH,
196-
CommandLineArgUtil.ARCHIVE_FILE_SWITCH)
197-
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
198-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
199-
raise ex
147+
cla_helper.validate_optional_archive(_program_name, optional_arg_map)
148+
cla_helper.validate_model_present(_program_name, optional_arg_map)
200149
return
201150

202151

@@ -389,17 +338,6 @@ def __close_domain_on_error():
389338
return
390339

391340

392-
def __clean_up_temp_files():
393-
"""
394-
If a temporary directory was created to extract the model from the archive, delete the directory and its contents.
395-
"""
396-
global __tmp_model_dir
397-
398-
if __tmp_model_dir is not None:
399-
FileUtils.deleteDirectory(__tmp_model_dir)
400-
__tmp_model_dir = None
401-
402-
403341
def validate_model(model_dictionary, model_context, aliases):
404342
_method_name = 'validate_model'
405343

@@ -412,12 +350,12 @@ def validate_model(model_dictionary, model_context, aliases):
412350
except ValidateException, ex:
413351
__logger.severe('WLSDPLY-20000', _program_name, ex.getLocalizedMessage(), error=ex,
414352
class_name=_class_name, method_name=_method_name)
415-
__clean_up_temp_files()
353+
cla_helper.clean_up_temp_files()
416354
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
417355

418356
if return_code == Validator.ReturnCode.STOP:
419357
__logger.severe('WLSDPLY-20001', _program_name, class_name=_class_name, method_name=_method_name)
420-
__clean_up_temp_files()
358+
cla_helper.clean_up_temp_files()
421359
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
422360

423361

@@ -445,19 +383,19 @@ def main(args):
445383
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
446384
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
447385
class_name=_class_name, method_name=_method_name)
448-
__clean_up_temp_files()
386+
cla_helper.clean_up_temp_files()
449387

450388
# create a minimal model for summary logging
451389
model_context = ModelContext(_program_name, dict())
452390
tool_exit.end(model_context, exit_code)
453391

454-
model_file = model_context.get_model_file()
392+
model_file_value = model_context.get_model_file()
455393
try:
456-
model_dictionary = FileToPython(model_file, True).parse()
394+
model_dictionary = cla_helper.merge_model_files(model_file_value)
457395
except TranslateException, te:
458-
__logger.severe('WLSDPLY-09014', _program_name, model_file, te.getLocalizedMessage(), error=te,
396+
__logger.severe('WLSDPLY-09014', _program_name, model_file_value, te.getLocalizedMessage(), error=te,
459397
class_name=_class_name, method_name=_method_name)
460-
__clean_up_temp_files()
398+
cla_helper.clean_up_temp_files()
461399
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
462400

463401
try:
@@ -468,7 +406,7 @@ def main(args):
468406
except VariableException, ex:
469407
__logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex,
470408
class_name=_class_name, method_name=_method_name)
471-
__clean_up_temp_files()
409+
cla_helper.clean_up_temp_files()
472410
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
473411

474412
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
@@ -484,10 +422,10 @@ def main(args):
484422
except DeployException, ex:
485423
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
486424
class_name=_class_name, method_name=_method_name)
487-
__clean_up_temp_files()
425+
cla_helper.clean_up_temp_files()
488426
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
489427

490-
__clean_up_temp_files()
428+
cla_helper.clean_up_temp_files()
491429

492430
tool_exit.end(model_context, exit_code)
493431
return

0 commit comments

Comments
 (0)