Skip to content

Commit 058e8f2

Browse files
changes for review suggestions
1 parent e6b3f27 commit 058e8f2

File tree

8 files changed

+77
-45
lines changed

8 files changed

+77
-45
lines changed

core/src/main/python/discover.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
2727

28+
import wlsdeploy.tool.util.variable_injector as variable_injector
2829
from wlsdeploy.aliases.wlst_modes import WlstModes
2930
from wlsdeploy.exception import exception_helper
3031
from wlsdeploy.logging.platform_logger import PlatformLogger
@@ -60,6 +61,7 @@
6061
# Used by shell script to locate WLST
6162
CommandLineArgUtil.MODEL_FILE_SWITCH,
6263
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
64+
CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH,
6365
CommandLineArgUtil.ADMIN_URL_SWITCH,
6466
CommandLineArgUtil.ADMIN_USER_SWITCH,
6567
CommandLineArgUtil.ADMIN_PASS_SWITCH
@@ -80,6 +82,7 @@ def __process_args(args):
8082
__verify_required_args_present(required_arg_map)
8183
__wlst_mode = __process_online_args(optional_arg_map)
8284
__process_archive_filename_arg(required_arg_map)
85+
__process_variable_filename_arg(optional_arg_map)
8386

8487
combined_arg_map = optional_arg_map.copy()
8588
combined_arg_map.update(required_arg_map)
@@ -159,6 +162,28 @@ def __process_archive_filename_arg(required_arg_map):
159162
return
160163

161164

165+
def __process_variable_filename_arg(optional_arg_map):
166+
"""
167+
If the variable filename argument is present, the required model variable injector json file must exist in
168+
the WLSDEPLOY lib directory.
169+
:param optional_arg_map: containing the variable file name
170+
:raises: CLAException: if this argument is present but the model variable injector json does not exist
171+
"""
172+
_method_name = '__process_variable_filename_arg'
173+
174+
if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in optional_arg_map:
175+
variable_injector_file_name = variable_injector.get_default_variable_injector_file_name()
176+
try:
177+
FileUtils.validateExistingFile(variable_injector_file_name)
178+
except IllegalArgumentException, ie:
179+
ex = exception_helper.create_cla_exception('WLSDPLY-06021', optional_arg_map[
180+
CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH], variable_injector_file_name,
181+
ie.getLocalizedMessage(), error=ie)
182+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
183+
raise ex
184+
return
185+
186+
162187
def __discover(model_context):
163188
"""
164189
Populate the model from the domain.

core/src/main/python/wlsdeploy/tool/util/variable_injector.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
VARIABLE_KEYWORDS_FILE_NAME_ARG = 'variable_keywords_file_name'
3535
VARIABLE_INJECTOR_FILES_PATH_ARG = 'variable_injector_files_path_name'
3636
VARIABLE_FILE_NAME_ARG = 'variable_file_name'
37-
VARIABLE_FILE_NAME = 'variables.json'
37+
VARIABLE_FILE_NAME = 'variable.properties'
3838
VARIABLE_FILE_APPEND_ARG = 'append_to_variables'
3939
VARIABLE_FILE_APPEND = 'append'
4040
VARIABLE_FILE_UPDATE = 'update'
@@ -123,7 +123,7 @@ def inject_variables_keyword_file(self, **kwargs):
123123
return_model = self.__original
124124
variable_file_location = None
125125
if variables_injector_dictionary and keywords_dictionary:
126-
variable_file_location = self._get_variable_file_name(variables_injector_dictionary, **kwargs)
126+
variable_file_location = self._get_variable_file_name(**kwargs)
127127
if not variable_file_location:
128128
_logger.warning('WLSDPLY-19520', variable_injector_location_file, class_name=_class_name,
129129
method_name=_method_name)
@@ -471,17 +471,11 @@ def _log_mbean_not_found(self, mbean, replacement, location):
471471
_logger.finer('WLSDPLY-19516', mbean, replacement, location.get_folder_path(),
472472
class_name=_class_name, method_name=_method_name)
473473

474-
def _get_variable_file_name(self, variables_injector_dictionary, **kwargs):
474+
def _get_variable_file_name(self, **kwargs):
475475
_method_name = '_get_variable_file_name'
476476
if VARIABLE_FILE_NAME_ARG in kwargs:
477477
variable_file_location = kwargs[VARIABLE_FILE_NAME_ARG]
478478
_logger.finer('WLSDPLY-19522', variable_file_location, class_name=_class_name, method_name=_method_name)
479-
if VARIABLE_FILE_NAME_ARG in variables_injector_dictionary:
480-
del variables_injector_dictionary[VARIABLE_FILE_NAME_ARG]
481-
elif VARIABLE_FILE_NAME_ARG in variables_injector_dictionary:
482-
variable_file_location = variables_injector_dictionary[VARIABLE_FILE_NAME_ARG]
483-
del variables_injector_dictionary[VARIABLE_FILE_NAME_ARG]
484-
_logger.finer('WLSDPLY-19521', variable_file_location, class_name=_class_name, method_name=_method_name)
485479
else:
486480
variable_file_location = variables.get_default_variable_file_name(self.__model_context)
487481
if variable_file_location:
@@ -554,6 +548,15 @@ def _check_replace_variable_value(self, location, attribute, variable_value, inj
554548
return variable_value
555549

556550

551+
def get_default_variable_injector_file_name(variable_injector_file_name=VARIABLE_INJECTOR_FILE_NAME):
552+
"""
553+
Return the default name and location of the model variable injector json file
554+
:param variable_injector_file_name: if different than the default name
555+
:return: file path in the wlsdeploy location and file name
556+
"""
557+
return os.path.join(_wlsdeploy_location, DEFAULT_FILE_LOCATION, variable_injector_file_name)
558+
559+
557560
def _load_variable_file(variable_file_location, **kwargs):
558561
_method_name = '_load_variable_file'
559562
append = False
@@ -581,7 +584,7 @@ def _get_variable_injector_file_name(**kwargs):
581584
if VARIABLE_INJECTOR_PATH_NAME_ARG in kwargs:
582585
return os.path.join(kwargs[VARIABLE_INJECTOR_PATH_NAME_ARG], variable_injector_file_name)
583586
else:
584-
return os.path.join(_wlsdeploy_location, DEFAULT_FILE_LOCATION, variable_injector_file_name)
587+
return get_default_variable_injector_file_name(variable_injector_file_name)
585588

586589

587590
def _get_variable_keywords_file_name(**kwargs):

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ WLSDPLY-06018=Please enter the WebLogic administrator password
421421
WLSDPLY-06019=Failed to read the WebLogic administrator password input from the user: {0}
422422
WLSDPLY-06020=Discover of domain is not currently supported in online mode. Ignoring Admin credential arguments which \
423423
are present for FUTURE TBD release.
424+
WLSDPLY-06021=The variables file command line argument {0} was used but the model variables injector file \
425+
{1} does not exist : {2}
424426

425427
# discoverer.py
426428
WLSDPLY-06100=Find attributes at location {0}
@@ -1133,13 +1135,12 @@ WLSDPLY-19512=CUSTOM keyword was found in variables injector list but no files w
11331135
keyword
11341136
WLSDPLY-19513=Variables were located and inserted in the model using injector file {0}
11351137
WLSDPLY-19514=Located mbean {0} in the model file
1136-
WLSDPLY-19515=Invalid mbean {0} found in replacement property {1} at location {2}
1137-
WLSDPLY-19516=MBean {0} not found in the model for replacement property {1} at location (2}
1138-
WLSDPLY-19517=Attribute {0} not found in the model for replacement property {1} at location {2}
1138+
WLSDPLY-19515=Invalid mbean {0} found in injector directive {1} at location {2}
1139+
WLSDPLY-19516=MBean {0} not found in the model for injector directive {1} at location {2}
1140+
WLSDPLY-19517=Attribute {0} not found in the model for injector directive {1} at location {2}
11391141
WLSDPLY-19518=Variables were inserted into the model and written to the variables file {0}
11401142
WLSDPLY-19519=No variables were inserted into the model during variable replacement
11411143
WLSDPLY-19520=Variable injector file was found at location {0} but no variable properties file name was provided
1142-
WLSDPLY-19521=Variables property file name {0} extracted from model injector json file
11431144
WLSDPLY-19522=Variables property file name {0} was passed as an argument to the variable injector
11441145
WLSDPLY-19523=MBean {0} from injector path represents a named MBean folder at location {1}
11451146
WLSDPLY-19524=Segment {0} for attribute {1} not found in model value {2} at location {3}

core/src/test/python/variable_injector_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def testWithVariableHelperKeywords(self):
239239
expected['Machine.machine1.NodeManager.PasswordEncrypted'] = '--FIX ME--'
240240
expected['Machine.machine1.NodeManager.UserName'] = 'admin'
241241
inserted, model, variable_file_name = self._helper.inject_variables_keyword_file(
242+
variable_file_name=self._variable_file,
242243
variable_injector_path_name=self._resources_dir,
243244
variable_injector_file_name=self._variable_injector_keyword,
244245
variable_keywords_path_name=self._resources_dir, variable_keywords_file_name=self._keywords_file)

core/src/test/resources/variable_injector_keyword.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"variable_file_name": "../../test-classes/variable.injector.test.properties",
32
"PORT": {},
43
"URL": {},
54
"CREDENTIALS": {}

installer/src/main/bin/discoverDomain.cmd

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ IF %JVM_VERSION% LSS 7 (
115115
ECHO JDK version is %JVM_FULL_VERSION%, setting JAVA_VENDOR to Sun...
116116
SET JAVA_VENDOR=Sun
117117
)
118+
@rem
119+
@rem Check to see if no args were given and print the usage message
120+
@rem
121+
IF "%~1" == "" (
122+
SET RETURN_CODE=0
123+
GOTO usage
124+
)
118125

119126
@rem
120127
@rem Find the args required to determine the WLST script to run
@@ -125,6 +132,10 @@ SET DOMAIN_TYPE=
125132
SET WLST_PATH_DIR=
126133

127134
:arg_loop
135+
IF "%1" == "-help" (
136+
SET RETURN_CODE=0
137+
GOTO usage
138+
)
128139
IF "%1" == "-oracle_home" (
129140
SET ORACLE_HOME=%2
130141
SHIFT
@@ -295,8 +306,6 @@ ECHO.
295306
ECHO discoverDomain.cmd failed ^(exit code = %RETURN_CODE%^) >&2
296307
GOTO exit_script
297308

298-
:usage
299-
ECHO.
300309
:usage
301310
ECHO.
302311
ECHO Usage: %~nx0 -oracle_home ^<oracle-home^>

installer/src/main/bin/injectVariables.cmd

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -312,45 +312,40 @@ GOTO exit_script
312312
ECHO.
313313
ECHO Usage: %~nx0 [-help]
314314
ECHO -oracle_home ^<oracle-home^>
315-
ECHO -model_file ^<model-file^> | -archive_file ^<archive-file^>
315+
ECHO [-model_file ^<model-file^>]
316+
ECHO [-archive_file ^<archive-file^>]
316317
ECHO [-variable_injector_file ^<variable-injector-file^>]
317-
ECHO [-variable_keywords_file ^<variable-keywords-file^>]
318318
ECHO [-variable_properties_file ^<variable-file^>]
319319
ECHO [-domain_type ^<domain-type^>]
320320
ECHO [-wlst_path ^<wlst-path^>]
321321
ECHO.
322322
ECHO where:
323-
ECHO oracle-home - the existing Oracle Home directory with the correct version for the model
323+
ECHO oracle-home - the existing Oracle Home directory with the correct version for the model
324324
ECHO.
325-
ECHO model-file - the location of the model file in which variables will be injected.
326-
ECHO If not specified, the tool will look for the model
327-
ECHO in the archive file. Either the model_file or the archive_file argument must be provided.
325+
ECHO model-file - the location of the model file in which variables will be injected.
326+
ECHO If not specified, the tool will look for the model
327+
ECHO in the archive file. Either the model_file or the archive_file argument
328+
ECHO must be provided.
328329
ECHO.
329-
ECHO archive-file - the path to the archive file that contains a model in which the variables
330-
ECHO will be injected. If the model-file argument is used, this argument will be
331-
ECHO ignored. The archive file must contain a valid model.
330+
ECHO archive-file - the path to the archive file that contains a model in which the variables
331+
ECHO will be injected. If the model-file argument is used, this argument will be
332+
ECHO ignored. The archive file must contain a valid model.
332333
ECHO.
333-
ECHO variable-injector-file - the location of the variable injector file which contains the variable
334-
ECHO injector keywords for this model injection run. If this argument is not provided,
335-
ECHO the model_variable_injector.json file must exist in the lib directory in the
336-
ECHO WLSDEPLOY_HOME location.
334+
ECHO variable_properties_file - the location of the property file in which to store any variable names injected
335+
ECHO into the model. If this command line argument is not specified, the variable
336+
ECHO will be located and named based on the model file or archive file name and
337+
ECHO location. If the file exists, the file will be updated with new variable values.
337338
ECHO.
338-
ECHO variable-keywords-file - this argument overrides the INSTALLED version of the allowed variable keywords
339-
ECHO for the variable injector. This argument is for advanced usage only. The installed
340-
ECHO keywords file is located in the lib directory of WLSDEPLOY_HOME location.
339+
ECHO variable-injector-file - the location of the variable injector file which contains the variable
340+
ECHO injector keywords for this model injection run. If this argument is not provided,
341+
ECHO the model_variable_injector.json file must exist in the lib directory in the
342+
ECHO WLSDEPLOY_HOME location.
341343
ECHO.
342-
ECHO variable-file - the location of the property file in which to store any variable names injected
343-
ECHO into the model. This argument overrides the value in the model injector file.
344-
ECHO If the variable file is not listed in the model injector file, and this command
345-
ECHO line argument is not used, the variable properties will be located and named
346-
ECHO based on the model file or archive file name and location.
347-
ECHO If the variable file exists, new variable values will be appended to the file.
344+
ECHO domain-type - the type of domain (e.g., WLS, JRF).
345+
ECHO Used to locate wlst.cmd if wlst-path not specified
348346
ECHO.
349-
ECHO domain-type - the type of domain (e.g., WLS, JRF).
350-
ECHO Used to locate wlst.cmd if wlst-path not specified
351-
ECHO.
352-
ECHO wlst-path - the Oracle Home subdirectory of the wlst.cmd
353-
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa)
347+
ECHO wlst-path - the Oracle Home subdirectory of the wlst.cmd
348+
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa)
354349
ECHO.
355350

356351
:exit_script

installer/src/main/samples/model_variable_injector.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"variable_file_name": "@@WLSDEPLOY@@/samples/variables.properties",
32
"CREDENTIALS": {},
43
"CUSTOM": {
54
"file-list": [ "@@WLSDEPLOY@@/samples/custom_injector.json" ]

0 commit comments

Comments
 (0)