1212from java .lang import IllegalArgumentException
1313from java .lang import IllegalStateException
1414from java .lang import String
15-
1615from oracle .weblogic .deploy .aliases import AliasException
1716from oracle .weblogic .deploy .discover import DiscoverException
1817from oracle .weblogic .deploy .util import CLAException
1918from oracle .weblogic .deploy .util import FileUtils
2019from oracle .weblogic .deploy .util import PyWLSTException
2120from oracle .weblogic .deploy .util import TranslateException
22- from oracle .weblogic .deploy .util import WebLogicDeployToolingVersion
2321from oracle .weblogic .deploy .util import WLSDeployArchive
2422from oracle .weblogic .deploy .util import WLSDeployArchiveIOException
23+ from oracle .weblogic .deploy .util import WebLogicDeployToolingVersion
2524from oracle .weblogic .deploy .validate import ValidateException
2625
2726sys .path .append (os .path .dirname (os .path .realpath (sys .argv [0 ])))
2827
2928from wlsdeploy .aliases import model_constants
3029from wlsdeploy .aliases .aliases import Aliases
3130from wlsdeploy .aliases .location_context import LocationContext
31+ import wlsdeploy .tool .util .variable_injector as variable_injector
32+
3233from wlsdeploy .aliases .wlst_modes import WlstModes
3334from wlsdeploy .exception import exception_helper
3435from wlsdeploy .logging .platform_logger import PlatformLogger
3940from wlsdeploy .tool .discover .multi_tenant_discoverer import MultiTenantDiscoverer
4041from wlsdeploy .tool .discover .resources_discoverer import ResourcesDiscoverer
4142from wlsdeploy .tool .discover .topology_discoverer import TopologyDiscoverer
42- from wlsdeploy .tool .validate .validator import Validator
4343from wlsdeploy .tool .util import filter_helper
44+ from wlsdeploy .tool .util .variable_injector import VariableInjector
45+ from wlsdeploy .tool .validate .validator import Validator
4446from wlsdeploy .util import wlst_helper
4547from wlsdeploy .util import model_translator
4648from wlsdeploy .util .cla_utils import CommandLineArgUtil
6163
6264__optional_arguments = [
6365 # Used by shell script to locate WLST
64- CommandLineArgUtil .DOMAIN_TYPE_SWITCH ,
6566 CommandLineArgUtil .MODEL_FILE_SWITCH ,
67+ CommandLineArgUtil .DOMAIN_TYPE_SWITCH ,
68+ CommandLineArgUtil .VARIABLE_PROPERTIES_FILE_SWITCH ,
6669 CommandLineArgUtil .ADMIN_URL_SWITCH ,
6770 CommandLineArgUtil .ADMIN_USER_SWITCH ,
6871 CommandLineArgUtil .ADMIN_PASS_SWITCH
@@ -83,6 +86,7 @@ def __process_args(args):
8386 __verify_required_args_present (required_arg_map )
8487 __wlst_mode = __process_online_args (optional_arg_map )
8588 __process_archive_filename_arg (required_arg_map )
89+ __process_variable_filename_arg (optional_arg_map )
8690
8791 combined_arg_map = optional_arg_map .copy ()
8892 combined_arg_map .update (required_arg_map )
@@ -162,6 +166,28 @@ def __process_archive_filename_arg(required_arg_map):
162166 return
163167
164168
169+ def __process_variable_filename_arg (optional_arg_map ):
170+ """
171+ If the variable filename argument is present, the required model variable injector json file must exist in
172+ the WLSDEPLOY lib directory.
173+ :param optional_arg_map: containing the variable file name
174+ :raises: CLAException: if this argument is present but the model variable injector json does not exist
175+ """
176+ _method_name = '__process_variable_filename_arg'
177+
178+ if CommandLineArgUtil .VARIABLE_PROPERTIES_FILE_SWITCH in optional_arg_map :
179+ variable_injector_file_name = variable_injector .get_default_variable_injector_file_name ()
180+ try :
181+ FileUtils .validateExistingFile (variable_injector_file_name )
182+ except IllegalArgumentException , ie :
183+ ex = exception_helper .create_cla_exception ('WLSDPLY-06021' , optional_arg_map [
184+ CommandLineArgUtil .VARIABLE_PROPERTIES_FILE_SWITCH ], variable_injector_file_name ,
185+ ie .getLocalizedMessage (), error = ie )
186+ __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
187+ raise ex
188+ return
189+
190+
165191def __discover (model_context , aliases ):
166192 """
167193 Populate the model from the domain.
@@ -210,7 +236,7 @@ def _add_domain_name(location, aliases):
210236 location .add_name_token (aliases .get_name_token (location ), domain_name )
211237 __logger .info ('WLSDPLY-06022' , domain_name , class_name = _class_name , method_name = _method_name )
212238 else :
213- de = exception_helper .create_discover_exception ('WLSDPLY-WLSDPLY-06021 ' )
239+ de = exception_helper .create_discover_exception ('WLSDPLY-WLSDPLY-06023 ' )
214240 __logger .throwing (class_name = _class_name , method_name = _method_name , error = de )
215241 raise de
216242
@@ -370,7 +396,7 @@ def __persist_model(model, model_context):
370396 if not model_file .delete ():
371397 model_file .deleteOnExit ()
372398 except (WLSDeployArchiveIOException , IllegalArgumentException ), arch_ex :
373- ex = exception_helper .create_discover_exception ('WLSDPLY-06009 ' , model_file .getAbsolutePath (),
399+ ex = exception_helper .create_discover_exception ('WLSDPLY-20023 ' , model_file .getAbsolutePath (),
374400 model_file_name , arch_ex .getLocalizedMessage (),
375401 error = arch_ex )
376402 __logger .throwing (ex , class_name = _class_name , method_name = _method_name )
@@ -394,14 +420,21 @@ def __check_and_customize_model(model, model_context, aliases):
394420 if filter_helper .apply_filters (model .get_model (), "discover" ):
395421 __logger .info ('WLSDPLY-06014' , _class_name = _class_name , method_name = _method_name )
396422
423+ inserted , variable_model , variable_file_name = VariableInjector (_program_name , model .get_model (), model_context ,
424+ WebLogicHelper (
425+ __logger ).get_actual_weblogic_version ()).\
426+ inject_variables_keyword_file ()
427+ if inserted :
428+ model = Model (variable_model )
397429 try :
398430 validator = Validator (model_context , wlst_mode = __wlst_mode , aliases = aliases )
399431
400432 # no variables are generated by the discover tool
401- validator .validate_in_tool_mode (model .get_model (), variables_file_name = None ,
433+ validator .validate_in_tool_mode (model .get_model (), variables_file_name = variable_file_name ,
402434 archive_file_name = model_context .get_archive_file_name ())
403435 except ValidateException , ex :
404436 __logger .warning ('WLSDPLY-06015' , ex .getLocalizedMessage (), class_name = _class_name , method_name = _method_name )
437+ return model
405438
406439
407440def __log_and_exit (exit_code , class_name , method_name ):
@@ -412,6 +445,7 @@ def __log_and_exit(exit_code, class_name, method_name):
412445 :param method_name: the method name to pass to the logger
413446 """
414447 __logger .exiting (result = exit_code , class_name = class_name , method_name = method_name )
448+
415449 sys .exit (exit_code )
416450
417451
@@ -458,13 +492,14 @@ def main(args):
458492 model_context .get_domain_home (), ex .getLocalizedMessage (),
459493 error = ex , class_name = _class_name , method_name = _method_name )
460494 __log_and_exit (CommandLineArgUtil .PROG_ERROR_EXIT_CODE , _class_name , _method_name )
461-
462- __check_and_customize_model (model , model_context , aliases )
463-
495+
496+ model = __check_and_customize_model (model , model_context )
497+
464498 try :
465499 __persist_model (model , model_context )
500+
466501 except TranslateException , ex :
467- __logger .severe ('WLSDPLY-06012 ' , _program_name , model_context .get_archive_file_name (), ex .getLocalizedMessage (),
502+ __logger .severe ('WLSDPLY-20024 ' , _program_name , model_context .get_archive_file_name (), ex .getLocalizedMessage (),
468503 error = ex , class_name = _class_name , method_name = _method_name )
469504 __log_and_exit (CommandLineArgUtil .PROG_ERROR_EXIT_CODE , _class_name , _method_name )
470505
0 commit comments