1
1
"""
2
- Copyright (c) 2017, 2022 , Oracle Corporation and/or its affiliates.
2
+ Copyright (c) 2017, 2023 , Oracle Corporation and/or its affiliates.
3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
5
5
The entry point for the discoverDomain tool.
68
68
69
69
__required_arguments = [
70
70
CommandLineArgUtil .ORACLE_HOME_SWITCH ,
71
- CommandLineArgUtil .DOMAIN_HOME_SWITCH
71
+ CommandLineArgUtil .DOMAIN_HOME_SWITCH ,
72
+ CommandLineArgUtil .MODEL_FILE_SWITCH
72
73
]
73
74
74
75
__optional_arguments = [
75
76
# Used by shell script to locate WLST
76
- CommandLineArgUtil .MODEL_FILE_SWITCH ,
77
77
CommandLineArgUtil .ARCHIVE_FILE_SWITCH ,
78
78
CommandLineArgUtil .SKIP_ARCHIVE_FILE_SWITCH ,
79
79
CommandLineArgUtil .DOMAIN_TYPE_SWITCH ,
@@ -104,7 +104,7 @@ def __process_args(args):
104
104
105
105
__wlst_mode = cla_helper .process_online_args (argument_map )
106
106
target_configuration_helper .process_target_arguments (argument_map )
107
- __process_model_archive_args (argument_map )
107
+ __process_model_arg (argument_map )
108
108
__process_archive_filename_arg (argument_map )
109
109
__process_variable_filename_arg (argument_map )
110
110
__process_java_home (argument_map )
@@ -113,22 +113,20 @@ def __process_args(args):
113
113
return model_context_helper .create_context (_program_name , argument_map )
114
114
115
115
116
- def __process_model_archive_args (argument_map ):
116
+ def __process_model_arg (argument_map ):
117
117
"""
118
- Verify that model file and/or archive file is in the argument map
118
+ Verify that specified model file's parent directory exists.
119
119
:param argument_map: containing the CLA arguments
120
120
"""
121
- _method_name = '__process_model_archive_args'
122
- if CommandLineArgUtil .ARCHIVE_FILE_SWITCH not in argument_map :
123
- if CommandLineArgUtil .SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
124
- CommandLineArgUtil .REMOTE_SWITCH not in argument_map :
125
- ex = exception_helper .create_cla_exception (ExitCode .USAGE_ERROR , 'WLSDPLY-06028' )
126
- __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
127
- raise ex
128
- if CommandLineArgUtil .MODEL_FILE_SWITCH not in argument_map :
129
- ex = exception_helper .create_cla_exception (ExitCode .USAGE_ERROR , 'WLSDPLY-06029' )
130
- __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
131
- raise ex
121
+ _method_name = '__process_model_arg'
122
+
123
+ model_file_name = argument_map [CommandLineArgUtil .MODEL_FILE_SWITCH ]
124
+ model_dir_name = path_utils .get_parent_directory (model_file_name )
125
+ if os .path .exists (model_dir_name ) is False :
126
+ ex = exception_helper .create_cla_exception (ExitCode .ARG_VALIDATION_ERROR ,
127
+ 'WLSDPLY-06037' , model_file_name )
128
+ __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
129
+ raise ex
132
130
133
131
134
132
def __process_archive_filename_arg (argument_map ):
@@ -139,12 +137,19 @@ def __process_archive_filename_arg(argument_map):
139
137
"""
140
138
_method_name = '__process_archive_filename_arg'
141
139
142
- if CommandLineArgUtil .SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil .REMOTE_SWITCH in argument_map :
143
- if CommandLineArgUtil .ARCHIVE_FILE_SWITCH in argument_map :
144
- ex = exception_helper .create_cla_exception (ExitCode .ARG_VALIDATION_ERROR ,
145
- 'WLSDPLY-06033' )
140
+ if CommandLineArgUtil .ARCHIVE_FILE_SWITCH not in argument_map :
141
+ archive_file = None
142
+ if CommandLineArgUtil .SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
143
+ CommandLineArgUtil .REMOTE_SWITCH not in argument_map :
144
+ ex = exception_helper .create_cla_exception (ExitCode .USAGE_ERROR , 'WLSDPLY-06028' )
146
145
__logger .throwing (ex , class_name = _class_name , method_name = _method_name )
147
146
raise ex
147
+ elif CommandLineArgUtil .SKIP_ARCHIVE_FILE_SWITCH in argument_map or \
148
+ CommandLineArgUtil .REMOTE_SWITCH in argument_map :
149
+ ex = exception_helper .create_cla_exception (ExitCode .ARG_VALIDATION_ERROR ,
150
+ 'WLSDPLY-06033' )
151
+ __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
152
+ raise ex
148
153
else :
149
154
archive_file_name = argument_map [CommandLineArgUtil .ARCHIVE_FILE_SWITCH ]
150
155
archive_dir_name = path_utils .get_parent_directory (archive_file_name )
@@ -412,7 +417,7 @@ def __disconnect_domain(helper):
412
417
413
418
def __persist_model (model , model_context ):
414
419
"""
415
- Save the model to the specified model file name or to the archive if the file name was not specified .
420
+ Save the model to the specified model file name.
416
421
:param model: the model to save
417
422
:param model_context: the model context
418
423
:raises DiscoverException: if an error occurs while create a temporary file for the model
@@ -423,47 +428,9 @@ def __persist_model(model, model_context):
423
428
424
429
__logger .entering (class_name = _class_name , method_name = _method_name )
425
430
426
- add_to_archive = False
427
431
model_file_name = model_context .get_model_file ()
428
- if model_file_name is None :
429
- if model_context .skip_archive () or model_context .is_remote ():
430
- ex = exception_helper .create_discover_exception ('WLSDPLY-06032' )
431
- __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
432
- raise ex
433
- add_to_archive = True
434
- try :
435
- domain_name = model_context .get_domain_name ()
436
- model_file = File .createTempFile (domain_name , '.yaml' ).getCanonicalFile ()
437
- model_file_name = model_context .get_domain_name () + '.yaml'
438
- except (IllegalArgumentException , IOException ), ie :
439
- ex = exception_helper .create_discover_exception ('WLSDPLY-06008' , ie .getLocalizedMessage (), error = ie )
440
- __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
441
- raise ex
442
- else :
443
- model_file = FileUtils .getCanonicalFile (File (model_file_name ))
444
-
445
- try :
446
- model_translator .PythonToFile (model .get_model ()).write_to_file (model_file .getAbsolutePath ())
447
- except TranslateException , ex :
448
- # Jython 2.2.1 does not support finally so use this like a finally block...
449
- if add_to_archive and not model_file .delete ():
450
- model_file .deleteOnExit ()
451
- raise ex
452
-
453
- if add_to_archive :
454
- try :
455
- archive_file = model_context .get_archive_file ()
456
- archive_file .addModel (model_file , model_file_name )
457
- if not model_file .delete ():
458
- model_file .deleteOnExit ()
459
- except (WLSDeployArchiveIOException , IllegalArgumentException ), arch_ex :
460
- ex = exception_helper .create_discover_exception ('WLSDPLY-20023' , model_file .getAbsolutePath (),
461
- model_file_name , arch_ex .getLocalizedMessage (),
462
- error = arch_ex )
463
- __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
464
- if not model_file .delete ():
465
- model_file .deleteOnExit ()
466
- raise ex
432
+ model_file = FileUtils .getCanonicalFile (File (model_file_name ))
433
+ model_translator .PythonToFile (model .get_model ()).write_to_file (model_file .getAbsolutePath ())
467
434
468
435
__logger .exiting (class_name = _class_name , method_name = _method_name )
469
436
0 commit comments