Skip to content

Commit 85dd57d

Browse files
rakillenrobertpatrick
authored andcommitted
Use -variable-file argument for injector tool; update documentation
1 parent 03cbb37 commit 85dd57d

File tree

10 files changed

+42
-67
lines changed

10 files changed

+42
-67
lines changed

core/src/main/python/variable_inject.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
The entry point for the injectVariables tool.
66
"""
7+
import os
78
import sys
89

910
from java.io import File
@@ -14,11 +15,13 @@
1415
import wlsdeploy.tool.util.variable_injector as variable_injector
1516
from wlsdeploy.aliases.aliases import Aliases
1617
from wlsdeploy.aliases.wlst_modes import WlstModes
18+
from wlsdeploy.exception import exception_helper
1719
from wlsdeploy.logging.platform_logger import PlatformLogger
1820
from wlsdeploy.tool.util import model_context_helper
1921
from wlsdeploy.tool.util.credential_injector import CredentialInjector
2022
from wlsdeploy.tool.util.variable_injector import VariableInjector
2123
from wlsdeploy.util import model_translator, cla_helper, tool_main
24+
from wlsdeploy.util import path_helper
2225
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2326
from wlsdeploy.util.exit_code import ExitCode
2427
from wlsdeploy.util.model import Model
@@ -36,7 +39,7 @@
3639

3740
__optional_arguments = [
3841
CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH,
39-
CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH,
42+
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
4043
CommandLineArgUtil.DOMAIN_TYPE_SWITCH
4144
]
4245

@@ -53,10 +56,26 @@ def __process_args(args):
5356
argument_map = cla_util.process_args(args)
5457

5558
cla_helper.validate_required_model(_program_name, argument_map)
59+
__process_variable_filename_arg(argument_map)
5660

5761
return model_context_helper.create_context(_program_name, argument_map)
5862

5963

64+
def __process_variable_filename_arg(argument_map):
65+
_method_name = '__process_variable_filename_arg'
66+
67+
if CommandLineArgUtil.VARIABLE_FILE_SWITCH in argument_map:
68+
variable_file_name = argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
69+
path_helper_obj = path_helper.get_path_helper()
70+
variable_dir_name = path_helper_obj.get_local_parent_directory(variable_file_name)
71+
if not os.path.exists(variable_dir_name):
72+
ex = exception_helper.create_cla_exception(
73+
ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-19606', CommandLineArgUtil.VARIABLE_FILE_SWITCH,
74+
variable_dir_name)
75+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
76+
raise ex
77+
78+
6079
def __inject(model, model_context):
6180
"""
6281
Inject variables into the model file that is loaded into the model_context.

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,12 @@ def inject_variables_from_configuration(self, model_dictionary, append_option=No
172172

173173
injector_file_list, injector_config_location = self._load_injector_file_list()
174174

175-
# discover may have passed -variable_file; inject variables may have passed -variable_properties_file
175+
# discover or injector tool may have passed -variable_file
176176
variable_file_override = self._model_context.get_variable_file()
177-
properties_file_override = self._model_context.get_variable_properties_file()
178177

179178
if variable_file_override is not None:
180179
variable_file_location = variable_file_override
181-
elif properties_file_override is not None:
182-
variable_file_location = properties_file_override
183-
_logger.info('WLSDPLY-19602', properties_file_override,
180+
_logger.info('WLSDPLY-19602', variable_file_override,
184181
class_name=_class_name, method_name=_method_name)
185182
else:
186183
variable_file_location = variables.get_default_variable_file_name(self._model_context)

core/src/main/python/wlsdeploy/util/cla_utils.py

-24
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class CommandLineArgUtil(object):
8989
REMOTE_SWITCH = '-remote'
9090
# overrides for the variable injector
9191
VARIABLE_INJECTOR_FILE_SWITCH = '-variable_injector_file'
92-
VARIABLE_PROPERTIES_FILE_SWITCH = '-variable_properties_file'
9392
OUTPUT_DIR_SWITCH = "-output_dir"
9493
WAIT_FOR_EDIT_LOCK_SWITCH = "-wait_for_edit_lock"
9594
TARGET_SWITCH = '-target'
@@ -314,10 +313,6 @@ def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT, trailing_arg_count=0):
314313
value, idx = self._get_arg_value(args, idx)
315314
full_path = self._validate_variable_injector_file_arg(value)
316315
self._add_arg(key, full_path, True)
317-
elif self.is_variable_properties_file_key(key):
318-
value, idx = self._get_arg_value(args, idx)
319-
full_path = self._validate_variable_properties_file_arg(value)
320-
self._add_arg(key, full_path, True)
321316
elif self.is_boolean_switch(key):
322317
self._add_arg(key, True)
323318
elif self.is_compare_model_output_dir_switch(key):
@@ -975,25 +970,6 @@ def _validate_variable_injector_file_arg(self, value):
975970
raise ex
976971
return injector.getAbsolutePath()
977972

978-
# use this argument switch for the injector as the variables file does not have to exist
979-
def get_variable_properties_file_key(self):
980-
return self.VARIABLE_PROPERTIES_FILE_SWITCH
981-
982-
def is_variable_properties_file_key(self, key):
983-
return self.VARIABLE_PROPERTIES_FILE_SWITCH == key
984-
985-
def _validate_variable_properties_file_arg(self, value):
986-
method_name = '_validate_variable_properties_file_arg'
987-
988-
try:
989-
variables = JFileUtils.validateFileName(value)
990-
except JIllegalArgumentException, iae:
991-
ex = create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
992-
'WLSDPLY-01620', value, iae.getLocalizedMessage(), error=iae)
993-
_logger.throwing(ex, class_name=self._class_name, method_name=method_name)
994-
raise ex
995-
return variables.getAbsolutePath()
996-
997973
def is_boolean_switch(self, key):
998974
return key in self.BOOLEAN_SWITCHES
999975

core/src/main/python/wlsdeploy/util/model_context.py

-13
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def __init__(self, program_name, arg_map=None):
9999
self._target = None
100100
self._target_configuration = None # lazy load
101101
self._variable_injector_file = None
102-
self._variable_properties_file = None
103102
self._discard_current_edit = False
104103
self._wait_for_edit_lock = False
105104
self._remote = False
@@ -314,9 +313,6 @@ def __copy_from_args(self, arg_map):
314313
if CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH in arg_map:
315314
self._variable_injector_file = arg_map[CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH]
316315

317-
if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in arg_map:
318-
self._variable_properties_file = arg_map[CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH]
319-
320316
def __copy__(self):
321317
arg_map = dict()
322318
if self._oracle_home is not None:
@@ -418,8 +414,6 @@ def __copy__(self):
418414
arg_map[CommandLineArgUtil.OUTPUT_DIR_SWITCH] = self._output_dir
419415
if self._variable_injector_file is not None:
420416
arg_map[CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH] = self._variable_injector_file
421-
if self._variable_properties_file is not None:
422-
arg_map[CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH] = self._variable_properties_file
423417

424418
new_context = ModelContext(self._program_name, arg_map)
425419
if not new_context.is_initialization_complete():
@@ -835,13 +829,6 @@ def get_variable_injector_file(self):
835829
"""
836830
return self._variable_injector_file
837831

838-
def get_variable_properties_file(self):
839-
"""
840-
Get the variable properties file override.
841-
:return: the variable properties file
842-
"""
843-
return self._variable_properties_file
844-
845832
def get_trailing_arguments(self):
846833
"""
847834
Return an array of trailing arguments.

core/src/main/python/wlsdeploy/util/variables.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def write_sorted_variables(program_name, variable_map, file_path, append=False):
129129
def get_default_variable_file_name(model_context):
130130
"""
131131
Generate location and file name for the variable file.
132-
If model file is present, use the model file name and location;
133-
else, use the archive file name and location.
132+
Use the model file name and location.
134133
:param model_context: contains the model and archive file arguments
135134
:return: location and file name of variable properties file.
136135
"""
@@ -146,8 +145,6 @@ def get_default_variable_file_name(model_context):
146145
class_name=_class_name, method_name=_method_name)
147146
else:
148147
extract_file_name = model_context.get_model_file()
149-
if not extract_file_name:
150-
extract_file_name = model_context.get_archive_file_name()
151148
default_variable_file = _path_helper.get_local_filename_no_ext_from_path(extract_file_name)
152149
_logger.finer('WLSDPLY-01748', extract_file_name, default_variable_file,
153150
class_name=_class_name, method_name=_method_name)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1985,10 +1985,11 @@ WLSDPLY-19547=Unrecognized key {0} in injector configuration file {1}, valid key
19851985

19861986
# wlsdeploy/tool/variable_inject.py
19871987
WLSDPLY-19600=Use model variable injector file {0} from command line arguments
1988-
WLSDPLY-19602=Use variable properties file {0} from command line arguments
1988+
WLSDPLY-19602=Use variable file {0} from command line arguments
19891989
WLSDPLY-19603=Archive file {0} was provided but does not contain a model file
19901990
WLSDPLY-19604=Update model with injected variables
19911991
WLSDPLY-19605=
1992+
WLSDPLY-19606=Directory for {0} argument {1} does not exist
19921993

19931994
# wlsdeploy/tool/util/credential_injector.py
19941995
WLSDPLY-19650=Unused credential variables will not be filtered for target credentials method {0}

core/src/test/python/variable_injector_test.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from wlsdeploy.aliases.model_constants import ADMIN_PASSWORD
1616
from wlsdeploy.tool.util.variable_injector import STANDARD_PASSWORD_INJECTOR
1717
from wlsdeploy.tool.util.variable_injector import VariableInjector
18+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
1819
from wlsdeploy.util.model_context import ModelContext
1920
from wlsdeploy.util.model_translator import FileToPython
2021

@@ -33,7 +34,9 @@ def setUp(self):
3334
BaseTestCase.setUp(self)
3435
self.name = 'VariableFileHelperTest'
3536
self._model = FileToPython(self._model_file).parse()
36-
self._model_context = ModelContext(self.name, {})
37+
self._model_context = ModelContext(self.name, {
38+
CommandLineArgUtil.VARIABLE_FILE_SWITCH: self._variable_file
39+
})
3740
aliases = Aliases(self._model_context, wls_version='12.2.1.3')
3841
self._helper = VariableInjector(self.name, self._model_context, aliases)
3942

@@ -264,7 +267,6 @@ def testWithVariableHelperKeywords(self):
264267
expected[short_name + '.machine1.ListenPort'] = '5557'
265268

266269
self._establish_directory(self.OUTPUT_DIR)
267-
self._model_context._variable_properties_file = self._variable_file
268270

269271
# Define custom configuration path for WDT, with custom injector files
270272
config_dir = self._set_custom_config_dir('injector-wdt-config')

documentation/4.0/content/userguide/tools/variable_injection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ In addition to variable injector processing, the tool will automatically tokeniz
2121
| `-model_file` | The location of the model file in which variables will be injected. If not specified, the tool will look for the model in the archive file. Either the `-model_file` or the `-archive_file` argument must be provided. | |
2222
| `-oracle_home` | Home directory for the Oracle WebLogic installation. This is required unless the `ORACLE_HOME` environment variable is set. | |
2323
| `-variable_injector_file` | The location of the variable injector file which contains the variable injector list for this model injection run. If this argument is not provided, the `model_variable_injector.json` file must exist in the `lib` directory in the `$WLSDEPLOY_HOME` location. | |
24-
| `-variable_properties_file` | The location of the property file in which to store any variable names injected into the model. If this command-line argument is not specified, the variable will be located and named based on the model file or archive file name and location. If the file exists, the file will be updated with new variable values. | |
24+
| `-variable_file` | The location of the property file in which to store any variable names injected into the model. If this command-line argument is not specified, the variable will be located and named based on the model file name and location. If the file exists, the file will be updated with new variable values. | |

installer/src/main/bin/injectVariables.cmd

+6-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ ECHO the model_variable_injector.json file must exist
8181
ECHO the lib directory in the WLSDEPLOY_HOME location.
8282
ECHO.
8383
ECHO variable_file - the location of the property file in which to store
84-
ECHO any variable names injected into the model. This
85-
ECHO argument overrides the value in the model injector
86-
ECHO file. If the variable file is not listed in the
87-
ECHO model injector file, and this command-line argument
88-
ECHO is not used, the variable properties will be located
89-
ECHO and named based on the model file or archive file name
90-
ECHO and location. If the variable file exists, new
91-
ECHO variable values will be appended to the file.
84+
ECHO any variable names injected into the model.
85+
ECHO If this command-line argument is not used,
86+
ECHO the variable properties will be located and named
87+
ECHO based on the model file name and location.
88+
ECHO If the variable file exists, new variable values
89+
ECHO will be appended to the file.
9290
ECHO.
9391

9492
:exit_script

installer/src/main/bin/injectVariables.sh

+6-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ usage() {
4747
echo " the lib directory in the WLSDEPLOY_HOME location."
4848
echo ""
4949
echo " variable_file - the location of the property file in which to store"
50-
echo " any variable names injected into the model. This"
51-
echo " argument overrides the value in the model injector"
52-
echo " file. If the variable file is not listed in the"
53-
echo " model injector file, and this command-line argument"
54-
echo " is not used, the variable properties will be located"
55-
echo " and named based on the model file or archive file name"
56-
echo " and location. If the variable file exists, new"
57-
echo " variable values will be appended to the file."
50+
echo " any variable names injected into the model."
51+
echo " If this command-line argument is not used,"
52+
echo " the variable properties will be located and named"
53+
echo " based on the model file name and location."
54+
echo " If the variable file exists, new variable values"
55+
echo " will be appended to the file."
5856
echo ""
5957
}
6058

0 commit comments

Comments
 (0)