8
8
import sys
9
9
from java .io import IOException
10
10
from java .lang import IllegalArgumentException
11
- from java .lang import IllegalStateException
12
11
from java .lang import String
13
12
from java .lang import System
14
13
from oracle .weblogic .deploy .create import CreateException
39
38
from wlsdeploy .tool .util import filter_helper
40
39
from wlsdeploy .tool .util .alias_helper import AliasHelper
41
40
from wlsdeploy .tool .validate .validator import Validator
41
+ from wlsdeploy .util import cla_helper
42
42
from wlsdeploy .util import getcreds
43
43
from wlsdeploy .util import tool_exit
44
44
from wlsdeploy .util import variables
58
58
__logger = PlatformLogger ('wlsdeploy.create' )
59
59
__wlst_mode = WlstModes .OFFLINE
60
60
__version = WebLogicHelper (__logger ).get_actual_weblogic_version ()
61
- __tmp_model_dir = None
62
61
63
62
__required_arguments = [
64
63
CommandLineArgUtil .ORACLE_HOME_SWITCH ,
@@ -89,6 +88,7 @@ def __process_args(args):
89
88
:raises CLAException: if an error occurs while validating and processing the command-line arguments
90
89
"""
91
90
cla_util = CommandLineArgUtil (_program_name , __required_arguments , __optional_arguments )
91
+ cla_util .set_allow_multiple_models (True )
92
92
required_arg_map , optional_arg_map = cla_util .process_args (args , True )
93
93
__verify_required_args_present (required_arg_map )
94
94
__process_java_home_arg (optional_arg_map )
@@ -159,7 +159,6 @@ def __process_domain_location_args(optional_arg_map):
159
159
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
160
160
"""
161
161
_method_name = '__process_domain_location_args'
162
- global __tmp_model_dir
163
162
164
163
has_home = CommandLineArgUtil .DOMAIN_HOME_SWITCH in optional_arg_map
165
164
has_parent = CommandLineArgUtil .DOMAIN_PARENT_SWITCH in optional_arg_map
@@ -176,53 +175,16 @@ def __process_domain_location_args(optional_arg_map):
176
175
177
176
def __process_model_args (optional_arg_map ):
178
177
"""
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 .
180
179
Extract the model file if only the archive_file was provided.
181
180
:param optional_arg_map: the optional arguments map
182
181
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
183
182
"""
184
- _method_name = '__process_model_args'
185
- global __tmp_model_dir
186
183
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.
189
186
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 )
226
188
return
227
189
228
190
@@ -303,17 +265,6 @@ def __process_encryption_args(optional_arg_map):
303
265
return
304
266
305
267
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
-
317
268
def validate_model (model_dictionary , model_context , aliases ):
318
269
_method_name = 'validate_model'
319
270
@@ -326,12 +277,12 @@ def validate_model(model_dictionary, model_context, aliases):
326
277
except ValidateException , ex :
327
278
__logger .severe ('WLSDPLY-20000' , _program_name , ex .getLocalizedMessage (), error = ex ,
328
279
class_name = _class_name , method_name = _method_name )
329
- __clean_up_temp_files ()
280
+ cla_helper . clean_up_temp_files ()
330
281
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
331
282
332
283
if return_code == Validator .ReturnCode .STOP :
333
284
__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 ()
335
286
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
336
287
337
288
@@ -365,15 +316,15 @@ def validateRCUArgsAndModel(model_context, model, alias_helper):
365
316
else :
366
317
__logger .severe ('WLSDPLY-12411' , error = None ,
367
318
class_name = _class_name , method_name = "validateRCUArgsAndModel" )
368
- __clean_up_temp_files ()
319
+ cla_helper . clean_up_temp_files ()
369
320
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
370
321
371
322
else :
372
323
if model_context .get_domain_typedef ().required_rcu ():
373
324
if not model_context .get_rcu_database () or not model_context .get_rcu_prefix ():
374
325
__logger .severe ('WLSDPLY-12408' , model_context .get_domain_type (), CommandLineArgUtil .RCU_DB_SWITCH ,
375
326
CommandLineArgUtil .RCU_PREFIX_SWITCH )
376
- __clean_up_temp_files ()
327
+ cla_helper . clean_up_temp_files ()
377
328
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
378
329
379
330
return has_atpdbinfo
@@ -403,19 +354,19 @@ def main(args):
403
354
if exit_code != CommandLineArgUtil .HELP_EXIT_CODE :
404
355
__logger .severe ('WLSDPLY-20008' , _program_name , ex .getLocalizedMessage (), error = ex ,
405
356
class_name = _class_name , method_name = _method_name )
406
- __clean_up_temp_files ()
357
+ cla_helper . clean_up_temp_files ()
407
358
408
359
# create a minimal model for summary logging
409
360
model_context = ModelContext (_program_name , dict ())
410
361
tool_exit .end (model_context , exit_code )
411
362
412
- model_file = model_context .get_model_file ()
363
+ model_file_value = model_context .get_model_file ()
413
364
try :
414
- model = FileToPython ( model_file , True ). parse ( )
365
+ model = cla_helper . merge_model_files ( model_file_value )
415
366
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 ,
417
368
class_name = _class_name , method_name = _method_name )
418
- __clean_up_temp_files ()
369
+ cla_helper . clean_up_temp_files ()
419
370
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
420
371
421
372
try :
@@ -426,7 +377,7 @@ def main(args):
426
377
except VariableException , ex :
427
378
__logger .severe ('WLSDPLY-20004' , _program_name , ex .getLocalizedMessage (), error = ex ,
428
379
class_name = _class_name , method_name = _method_name )
429
- __clean_up_temp_files ()
380
+ cla_helper . clean_up_temp_files ()
430
381
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
431
382
432
383
aliases = Aliases (model_context , wlst_mode = __wlst_mode )
@@ -460,27 +411,28 @@ def main(args):
460
411
except WLSDeployArchiveIOException , ex :
461
412
__logger .severe ('WLSDPLY-12409' , _program_name , ex .getLocalizedMessage (), error = ex ,
462
413
class_name = _class_name , method_name = _method_name )
463
- __clean_up_temp_files ()
414
+ cla_helper . clean_up_temp_files ()
464
415
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
465
416
466
417
except CreateException , ex :
467
418
__logger .severe ('WLSDPLY-12409' , _program_name , ex .getLocalizedMessage (), error = ex ,
468
419
class_name = _class_name , method_name = _method_name )
469
- __clean_up_temp_files ()
420
+ cla_helper . clean_up_temp_files ()
470
421
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
471
422
472
423
except IOException , ex :
473
424
__logger .severe ('WLSDPLY-12409' , _program_name , ex .getLocalizedMessage (), error = ex ,
474
425
class_name = _class_name , method_name = _method_name )
475
- __clean_up_temp_files ()
426
+ cla_helper . clean_up_temp_files ()
476
427
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
428
+
477
429
except DeployException , ex :
478
430
__logger .severe ('WLSDPLY-12410' , _program_name , ex .getLocalizedMessage (), error = ex ,
479
431
class_name = _class_name , method_name = _method_name )
480
- __clean_up_temp_files ()
432
+ cla_helper . clean_up_temp_files ()
481
433
tool_exit .end (model_context , CommandLineArgUtil .PROG_ERROR_EXIT_CODE )
482
434
483
- __clean_up_temp_files ()
435
+ cla_helper . clean_up_temp_files ()
484
436
485
437
tool_exit .end (model_context , exit_code )
486
438
return
0 commit comments