Skip to content

Commit 0b915f6

Browse files
authored
Allow multiple variable files for create, update, deploy and extract (#669)
* JIRA WDT-374 - Allow multiple variable files for some tools * JIRA WDT-374 - Update script usage to allow multiple variable files * JIRA WDT-374 - Corrected logging parameters * JIRA WDT-374 - Handle case where variable file can't be written; show summary logging * JIRA WDT-374 - Use absolute paths to build variable file list
1 parent a501d14 commit 0b915f6

File tree

11 files changed

+92
-65
lines changed

11 files changed

+92
-65
lines changed

core/src/main/python/prepare_model.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from wlsdeploy.exception.expection_types import ExceptionType
3737
from wlsdeploy.logging.platform_logger import PlatformLogger
3838
from wlsdeploy.tool.util import filter_helper
39+
from wlsdeploy.tool.util import model_context_helper
3940
from wlsdeploy.tool.util import variable_injector_functions
4041
from wlsdeploy.tool.util.alias_helper import AliasHelper
4142
from wlsdeploy.tool.util.variable_injector import VariableInjector
@@ -44,6 +45,7 @@
4445
from wlsdeploy.util import cla_helper
4546
from wlsdeploy.util import model
4647
from wlsdeploy.util import target_configuration_helper
48+
from wlsdeploy.util import tool_exit
4749
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4850
from wlsdeploy.util.model import Model
4951
from wlsdeploy.util.model_context import ModelContext
@@ -455,8 +457,10 @@ def _apply_filter_and_inject_variable(self, model, model_context, validator):
455457
variable_map = validator.load_variables(self.model_context.get_variable_file())
456458
self.cache.update(variable_map)
457459

458-
variable_injector.inject_variables_keyword_file()
459-
return model
460+
inserted, variable_model, variable_file_name = variable_injector.inject_variables_keyword_file()
461+
# return variable_model - if writing the variables file failed, this will be the original model.
462+
# a warning is issued in inject_variables_keyword_file() if that was the case.
463+
return variable_model
460464

461465
def debug(format_string, *arguments):
462466
"""
@@ -480,6 +484,8 @@ def main():
480484
for index, arg in enumerate(sys.argv):
481485
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
482486

487+
# create a minimal model for summary logging
488+
model_context = model_context_helper.create_exit_context(_program_name)
483489
_outputdir = None
484490

485491
try:
@@ -495,29 +501,29 @@ def main():
495501

496502
obj = PrepareModel(model1, model_context, __logger, _outputdir)
497503
rc = obj.walk()
498-
System.exit(rc)
504+
tool_exit.end(model_context, rc)
499505

500506
except CLAException, ex:
501507
exit_code = 2
502508
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
503509
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
504510
class_name=_class_name, method_name=_method_name)
505511
cla_helper.clean_up_temp_files()
506-
sys.exit(exit_code)
512+
tool_exit.end(model_context, exit_code)
507513
except CompareException, ce:
508514
cla_helper.clean_up_temp_files()
509515
__logger.severe('WLSDPLY-05704', ce.getLocalizedMessage())
510-
System.exit(2)
516+
tool_exit.end(model_context, 2)
511517
except PyWLSTException, pe:
512518
cla_helper.clean_up_temp_files()
513519
__logger.severe('WLSDPLY-05704', pe.getLocalizedMessage())
514-
System.exit(2)
520+
tool_exit.end(model_context, 2)
515521
except:
516522
exc_type, exc_obj, exc_tb = sys.exc_info()
517523
eeString = traceback.format_exception(exc_type, exc_obj, exc_tb)
518524
cla_helper.clean_up_temp_files()
519525
__logger.severe('WLSDPLY-05704', eeString)
520-
System.exit(2)
526+
tool_exit.end(model_context, 2)
521527

522528
def format_message(key, *args):
523529
"""

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,30 @@ def validate_model_present(program_name, optional_arg_map):
117117
return
118118

119119

120-
def validate_variable_file_exists(program_name, optional_arg_map):
121-
method_name = '_validate_variable_file_arg'
122-
if CommandLineArgUtil.VARIABLE_FILE_SWITCH in optional_arg_map:
123-
value = optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
124-
try:
125-
variable_file = FileUtils.validateExistingFile(value)
126-
except IllegalArgumentException, iae:
127-
ex = exception_helper.create_cla_exception('WLSDPLY-20031', program_name, value,
128-
iae.getLocalizedMessage(), error=iae)
129-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
130-
__logger.throwing(ex, class_name=_class_name, method_name=method_name)
131-
raise ex
132-
optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = variable_file.getAbsolutePath()
120+
def validate_variable_file_exists(program_name, argument_map):
121+
"""
122+
Validate that the variable file(s) exist.
123+
Assume that the caller allows multiple variables files.
124+
:param program_name: the name of the tool
125+
:param argument_map: the program arguments
126+
"""
127+
method_name = 'validate_variable_file_exists'
128+
if CommandLineArgUtil.VARIABLE_FILE_SWITCH in argument_map:
129+
result_files = [] # type: list
130+
value = argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
131+
files = value.split(CommandLineArgUtil.MODEL_FILES_SEPARATOR)
132+
for file in files:
133+
try:
134+
variable_file = FileUtils.validateExistingFile(file)
135+
result_files.append(variable_file.getAbsolutePath())
136+
except IllegalArgumentException, iae:
137+
ex = exception_helper.create_cla_exception('WLSDPLY-20031', program_name, file,
138+
iae.getLocalizedMessage(), error=iae)
139+
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
140+
__logger.throwing(ex, class_name=_class_name, method_name=method_name)
141+
raise ex
142+
143+
argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = ",".join(result_files)
133144
return
134145

135146

@@ -204,7 +215,8 @@ def load_model(program_name, model_context, aliases, filter_type, wlst_mode):
204215
variable_map = {}
205216
try:
206217
if model_context.get_variable_file():
207-
variable_map = variables.load_variables(model_context.get_variable_file())
218+
# callers of this method allow multiple variable files
219+
variable_map = variables.load_variables(model_context.get_variable_file(), allow_multiple_files=True)
208220
except VariableException, ex:
209221
__logger.severe('WLSDPLY-20004', program_name, ex.getLocalizedMessage(), error=ex,
210222
class_name=_class_name, method_name=_method_name)

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from wlsdeploy.exception import exception_helper
2222
from wlsdeploy.logging import platform_logger
2323
from wlsdeploy.util import dictionary_utils
24+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2425

2526
_class_name = "variables"
2627
_logger = platform_logger.PlatformLogger('wlsdeploy.variables')
@@ -39,33 +40,41 @@
3940
_secret_token_map = None
4041

4142

42-
def load_variables(file_path):
43+
def load_variables(file_path, allow_multiple_files=False):
4344
"""
44-
Load a dictionary of variables from the specified file.
45+
Load a dictionary of variables from the specified file(s).
4546
:param file_path: the file from which to load properties
47+
:param allow_multiple_files: if True, allow a comma-separated list of variable files
4648
:return the dictionary of variables
4749
:raises VariableException if an I/O error occurs while loading the variables from the file
4850
"""
4951
method_name = "load_variables"
5052

53+
if allow_multiple_files:
54+
paths = file_path.split(CommandLineArgUtil.MODEL_FILES_SEPARATOR)
55+
else:
56+
paths = [file_path]
57+
5158
variable_map = {}
52-
props = Properties()
53-
input_stream = None
54-
try:
55-
input_stream = FileInputStream(file_path)
56-
props.load(input_stream)
57-
input_stream.close()
58-
except IOException, ioe:
59-
ex = exception_helper.create_variable_exception('WLSDPLY-01730', file_path,
60-
ioe.getLocalizedMessage(), error=ioe)
61-
_logger.throwing(ex, class_name=_class_name, method_name=method_name)
62-
if input_stream is not None:
63-
input_stream.close()
64-
raise ex
6559

66-
for key in props.keySet():
67-
value = props.getProperty(key)
68-
variable_map[key] = value
60+
for path in paths:
61+
props = Properties()
62+
input_stream = None
63+
try:
64+
input_stream = FileInputStream(path)
65+
props.load(input_stream)
66+
input_stream.close()
67+
except IOException, ioe:
68+
ex = exception_helper.create_variable_exception('WLSDPLY-01730', path, ioe.getLocalizedMessage(),
69+
error=ioe)
70+
_logger.throwing(ex, class_name=_class_name, method_name=method_name)
71+
if input_stream is not None:
72+
input_stream.close()
73+
raise ex
74+
75+
for key in props.keySet():
76+
value = props.getProperty(key)
77+
variable_map[key] = value
6978

7079
return variable_map
7180

@@ -105,8 +114,8 @@ def write_ordered_variables(program_name, variable_map, file_path, append=False)
105114
pw.println(formatted)
106115
pw.close()
107116
except IOException, ioe:
108-
_logger.fine('WLSDPLY-20007', file_path, ioe.getLocalizedMessage())
109-
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
117+
_logger.fine('WLSDPLY-20007', program_name, file_path, ioe.getLocalizedMessage())
118+
ex = exception_helper.create_variable_exception('WLSDPLY-20007', program_name, file_path,
110119
ioe.getLocalizedMessage(), error=ioe)
111120
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
112121
if pw is not None:

installer/src/main/bin/createDomain.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ ECHO model_file - the location of the model file to use. This can
116116
ECHO comma-separated list of model locations, where each successive model
117117
ECHO layers on top of the previous ones.
118118
ECHO.
119-
ECHO variable_file - the location of the property file containing
120-
ECHO the variable values for all variables used in
121-
ECHO the model
119+
ECHO variable_file - the location of the property file containing the values for variables used in
120+
ECHO the model. This can also be specified as a comma-separated list of property files,
121+
ECHO where each successive set of properties layers on top of the previous ones.
122122
ECHO.
123123
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
124124
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa).

installer/src/main/bin/createDomain.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ usage() {
7777
echo " comma-separated list of model locations, where each successive model layers on top"
7878
echo " of the previous ones."
7979
echo ""
80-
echo " variable_file - the location of the property file containing"
81-
echo " the variable values for all variables used in"
82-
echo " the model"
80+
echo " variable_file - the location of the property file containing the values for variables used in"
81+
echo " the model. This can also be specified as a comma-separated list of property files,"
82+
echo " where each successive set of properties layers on top of the previous ones."
8383
echo ""
8484
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
8585
echo " script to use (e.g., <ORACLE_HOME>/soa)."

installer/src/main/bin/deployApps.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ ECHO model_file - the location of the model file to use. This can
9999
ECHO comma-separated list of model locations, where each successive model
100100
ECHO layers on top of the previous ones.
101101
ECHO.
102-
ECHO variable_file - the location of the property file containing
103-
ECHO the variable values for all variables used in
104-
ECHO the model
102+
ECHO variable_file - the location of the property file containing the values for variables used in
103+
ECHO the model. This can also be specified as a comma-separated list of property files,
104+
ECHO where each successive set of properties layers on top of the previous ones.
105105
ECHO.
106106
ECHO domain_type - the type of domain (e.g., WLS, JRF).
107107
ECHO Used to locate wlst.cmd if -wlst_path not specified

installer/src/main/bin/deployApps.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ usage() {
6060
echo " comma-separated list of model locations, where each successive model layers"
6161
echo " on top of the previous ones."
6262
echo ""
63-
echo " variable_file - the location of the property file containing"
64-
echo " the variable values for all variables used in"
65-
echo " the model"
63+
echo " variable_file - the location of the property file containing the values for variables used in"
64+
echo " the model. This can also be specified as a comma-separated list of property files,"
65+
echo " where each successive set of properties layers on top of the previous ones."
6666
echo ""
6767
echo " domain_type - the type of domain (e.g., WLS, JRF)."
6868
echo " Used to locate wlst.cmd if -wlst_path not specified"

installer/src/main/bin/extractDomainResource.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ ECHO model_file - the location of the model file to use. This can
9595
ECHO comma-separated list of model locations, where each successive model
9696
ECHO layers on top of the previous ones.
9797
ECHO.
98-
ECHO variable_file - the location of the property file containing
99-
ECHO the variable values for all variables used in
100-
ECHO the model
98+
ECHO variable_file - the location of the property file containing the values for variables used in
99+
ECHO the model. This can also be specified as a comma-separated list of property files,
100+
ECHO where each successive set of properties layers on top of the previous ones.
101101
ECHO.
102102
ECHO The -use_encryption switch tells the program that one or more of the
103103
ECHO passwords in the model or variables files are encrypted. The program will

installer/src/main/bin/extractDomainResource.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ usage() {
5656
echo " comma-separated list of model locations, where each successive model layers"
5757
echo " on top of the previous ones."
5858
echo ""
59-
echo " variable_file - the location of the property file containing"
60-
echo " the variable values for all variables used in"
61-
echo " the model"
59+
echo " variable_file - the location of the property file containing the values for variables used in"
60+
echo " the model. This can also be specified as a comma-separated list of property files,"
61+
echo " where each successive set of properties layers on top of the previous ones."
6262
echo ""
6363
echo " The -use_encryption switch tells the program that one or more of the"
6464
echo " passwords in the model or variables files are encrypted. The program will"

installer/src/main/bin/updateDomain.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ ECHO model_file - the location of the model file to use. This can
9999
ECHO comma-separated list of model locations, where each successive model
100100
ECHO layers on top of the previous ones.
101101
ECHO.
102-
ECHO variable_file - the location of the property file containing
103-
ECHO the variable values for all variables used in
104-
ECHO the model
102+
ECHO variable_file - the location of the property file containing the values for variables used in
103+
ECHO the model. This can also be specified as a comma-separated list of property files,
104+
ECHO where each successive set of properties layers on top of the previous ones.
105105
ECHO.
106106
ECHO domain_type - the type of domain (e.g., WLS, JRF).
107107
ECHO Used to locate wlst.cmd if -wlst_path not specified

0 commit comments

Comments
 (0)