Skip to content

Commit 1486e54

Browse files
Add commandline injector tool
1 parent 64779d1 commit 1486e54

File tree

9 files changed

+542
-370
lines changed

9 files changed

+542
-370
lines changed

core/src/main/python/discover.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from wlsdeploy.tool.discover.topology_discoverer import TopologyDiscoverer
4040
from wlsdeploy.tool.validate.validator import Validator
4141
from wlsdeploy.tool.util import filter_helper
42-
from wlsdeploy.util import path_utils
4342
from wlsdeploy.util import wlst_helper
4443
from wlsdeploy.util import model_translator
4544
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -137,7 +136,7 @@ def __process_online_args(optional_arg_map):
137136
raise ex
138137
optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
139138

140-
__logger.info('WLSDPLY-06020')
139+
__logger.info('WLSDPLY-06020', class_name=_class_name, method_name=_method_name)
141140
return mode
142141

143142

@@ -346,7 +345,7 @@ def __persist_model(model, model_context):
346345
if not model_file.delete():
347346
model_file.deleteOnExit()
348347
except (WLSDeployArchiveIOException, IllegalArgumentException), arch_ex:
349-
ex = exception_helper.create_discover_exception('WLSDPLY-06009', model_file.getAbsolutePath(),
348+
ex = exception_helper.create_discover_exception('WLSDPLY-20023', model_file.getAbsolutePath(),
350349
model_file_name, arch_ex.getLocalizedMessage(),
351350
error=arch_ex)
352351
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
@@ -371,8 +370,7 @@ def __check_and_customize_model(model, model_context):
371370
__logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)
372371

373372
inserted, variable_model, variable_file_name = VariableInjector(model.get_model(), model_context, WebLogicHelper(
374-
__logger).get_actual_weblogic_version()).inject_variables_keyword_file(
375-
variable_file_name=__get_default_variable_file(model_context))
373+
__logger).get_actual_weblogic_version()).inject_variables_keyword_file()
376374
if inserted:
377375
model = Model(variable_model)
378376
try:
@@ -386,17 +384,6 @@ def __check_and_customize_model(model, model_context):
386384
return model
387385

388386

389-
def __get_default_variable_file(model_context):
390-
extract_file_name = model_context.get_model_file()
391-
if not extract_file_name:
392-
extract_file_name = model_context.get_archive_file_name()
393-
default_variable_file = path_utils.get_filename_no_ext_from_path(extract_file_name)
394-
if default_variable_file:
395-
default_variable_file = os.path.join(path_utils.get_pathname_from_path(extract_file_name),
396-
default_variable_file + '.properties')
397-
return default_variable_file
398-
399-
400387
def __log_and_exit(exit_code, _class_name, _method_name):
401388
"""
402389
Helper method to log the exiting message and call sys.exit()
@@ -456,7 +443,7 @@ def main(args):
456443
__persist_model(model, model_context)
457444

458445
except TranslateException, ex:
459-
__logger.severe('WLSDPLY-06012', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(),
446+
__logger.severe('WLSDPLY-20024', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(),
460447
error=ex, class_name=_class_name, method_name=_method_name)
461448
__log_and_exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
462449

core/src/main/python/variable_inject.py

Lines changed: 112 additions & 263 deletions
Large diffs are not rendered by default.

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

Lines changed: 73 additions & 60 deletions
Large diffs are not rendered by default.

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
5+
import os
56
import re
67

8+
from java.lang import Boolean
79
from java.io import BufferedReader
10+
from java.io import File
811
from java.io import FileInputStream
912
from java.io import FileOutputStream
1013
from java.io import FileReader
@@ -13,6 +16,7 @@
1316

1417
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
1518

19+
from wlsdeploy.util import path_utils
1620
from wlsdeploy.exception import exception_helper
1721
from wlsdeploy.logging import platform_logger
1822

@@ -54,14 +58,16 @@ def load_variables(file_path):
5458
return variable_map
5559

5660

57-
def write_variables(variable_map, file_path):
61+
def write_variables(variable_map, file_path, append=False):
5862
"""
5963
Write the dictionary of variables to the specified file.
6064
:param variable_map: the dictionary of variables
6165
:param file_path: the file to which to write the properties
66+
:param append: defaults to False. Append properties to the end of file
6267
:raises VariableException if an error occurs while storing the variables in the file
6368
"""
64-
method_name = 'write_variables'
69+
_method_name = 'write_variables'
70+
_logger.entering(file_path, append, class_name=_class_name, method_name=_method_name)
6571
props = Properties()
6672
for key in variable_map:
6773
value = variable_map[key]
@@ -70,19 +76,40 @@ def write_variables(variable_map, file_path):
7076
comment = exception_helper.get_message('WLSDPLY-01731')
7177
output_stream = None
7278
try:
73-
output_stream = FileOutputStream(file_path)
79+
output_stream = FileOutputStream(File(file_path), Boolean(append))
7480
props.store(output_stream, comment)
7581
output_stream.close()
7682
except IOException, ioe:
7783
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
7884
ioe.getLocalizedMessage(), error=ioe)
79-
_logger.throwing(ex, class_name=_class_name, method_name=method_name)
85+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
8086
if output_stream is not None:
8187
output_stream.close()
8288
raise ex
89+
_logger.exiting(class_name=_class_name, method_name=_method_name)
8390
return
8491

8592

93+
def get_default_variable_file_name(model_context):
94+
"""
95+
Generate location and file name for the variable file.
96+
If model file is present, use the model file name and location;
97+
else, use the archive file name and location.
98+
:param model_context: contains the model and archive file arguments
99+
:return: location and file name of variable properties file.
100+
"""
101+
_method_name = 'get_default_variable_file_name'
102+
extract_file_name = model_context.get_model_file()
103+
if not extract_file_name:
104+
extract_file_name = model_context.get_archive_file_name()
105+
default_variable_file = path_utils.get_filename_no_ext_from_path(extract_file_name)
106+
if default_variable_file:
107+
default_variable_file = os.path.join(path_utils.get_pathname_from_path(extract_file_name),
108+
default_variable_file + '.properties')
109+
_logger.finer('WLSDPLY-01736', default_variable_file, class_name=_class_name, method_name=_method_name)
110+
return default_variable_file
111+
112+
86113
def get_variable_names(text):
87114
"""
88115
Get the list of variable names in the supplied text.

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,12 @@ WLSDPLY-01720=to_boolean() method called with non-boolean value {0} so returning
247247

248248
# wlsdeploy/util/variables.py
249249
WLSDPLY-01730=Failed to load variables file {0}: {1}
250-
WLSDPLY-01731=Variables updated after encryption
250+
WLSDPLY-01731=Variables updated
251251
WLSDPLY-01732=Variable {0} is not found in properties file
252252
WLSDPLY-01733=Variable file {0} cannot be read: {1}
253253
WLSDPLY-01734=No value in variable file {0}
254254
WLSDPLY-01735=Variable substitution for {0} is deprecated, use @@PROP:{1}@@
255+
WLSDPLY-01736=Default variable file name {0}
255256

256257
# wlsdeploy/util/weblogic_helper.py
257258
WLSDPLY-01740=Encryption failed: Unable to locate SerializedSystemIni
@@ -414,10 +415,10 @@ WLSDPLY-06005=Unable to clear the existing archive file. Correct the problem bef
414415
WLSDPLY-06006=Disconnect from the administration server failed: {0}
415416
WLSDPLY-06007=Closing the domain failed: {0}
416417
WLSDPLY-06008=Unable to create temporary file for writing the model: {0}
417-
WLSDPLY-06009=Unable to add model file {0} to archive as {1}: {2}
418+
418419
WLSDPLY-06010={0} failed to clear the existing archive file at {1} of binaries: {2}
419420
WLSDPLY-06011={0} failed to discover domain {1} at {2} : {3}
420-
WLSDPLY-06012={0} failed to persist the model to the archive file {1}: {2}
421+
421422
WLSDPLY-06013={0} failed to create the archive file at {1}: {2}
422423
WLSDPLY-06014=Filters applied to the model
423424
WLSDPLY-06015=Unable to run validation against the discovered model : {0}
@@ -1163,6 +1164,12 @@ WLSDPLY-19532=No model variable injector file {0}
11631164
WLSDPLY-19533=Will inject variable replacement strings into model using keyword directions found in model \
11641165
variable injector file {0}
11651166

1167+
# wlsdeploy/tool/variable_inject.py
1168+
WLSDPLY-19600=Use model variable injector file {0} from command line arguments
1169+
WLSDPLY-19601=Use variable injector keywords file {0} from command line arguments
1170+
WLSDPLY-19602=Use variable properties file {0} from command line arguments
1171+
WLSDPLY-19603=Archive file {0} was provided but does not contain a model file
1172+
WLSDPLY-19604=Update model with injected variables
11661173

11671174
# Common tooling messages used by multiple tools
11681175
WLSDPLY-20000={0} encountered an unexpected validation error: {1}
@@ -1188,3 +1195,5 @@ WLSDPLY-20019=Filter entry in {0} has neither ID or path
11881195
WLSDPLY-20020=Filter ID {0} is invalid
11891196
WLSDPLY-20021=Filter path {0} does not exist
11901197
WLSDPLY-20022=Error loading filter path {0}
1198+
WLSDPLY-20023={0} unable to add model file {1} to archive as {2}: {3}
1199+
WLSDPLY-20024={0} failed to persist the model to the archive file {1}: {2}

installer/src/main/bin/injectVariables.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
SETLOCAL
5454

55-
SET WLSDEPLOY_PROGRAM_NAME=validateModel
55+
SET WLSDEPLOY_PROGRAM_NAME=injectVariables
5656

5757
SET SCRIPT_PATH=%~dp0
5858
FOR %%i IN ("%SCRIPT_PATH%") DO SET SCRIPT_PATH=%%~fsi

0 commit comments

Comments
 (0)