88import sys
99from java .io import IOException
1010from java .lang import IllegalArgumentException
11- from java .lang import IllegalStateException
1211from java .lang import String
1312from java .lang import System
1413from oracle .weblogic .deploy .create import CreateException
3938from wlsdeploy .tool .util import filter_helper
4039from wlsdeploy .tool .util .alias_helper import AliasHelper
4140from wlsdeploy .tool .validate .validator import Validator
41+ from wlsdeploy .util import cla_helper
4242from wlsdeploy .util import getcreds
4343from wlsdeploy .util import tool_exit
4444from wlsdeploy .util import variables
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
177176def __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-
317268def 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
0 commit comments