Skip to content

Commit 8785680

Browse files
authored
WDT_CUSTOM_CONFIG variable, alternate config dir (#638)
* Issue #371 - Allow alternate configuration dir for typedefs * Issue #371 - Allow alternate configuration dir for model filters definition; log when custom file is used * Issue #371 - Allow alternate configuration dir for injectors; modify unit test to use WDT_CUSTOM_CONFIG variable * Issue #371 - Clarify which injector files are used at INFO logging level * Issue #371 - Use custom configuration dir for target model filters; fixed error checks and messages * Issue #371 - Use custom configuration dir for target configuration file
1 parent fcb8cdc commit 8785680

File tree

15 files changed

+193
-167
lines changed

15 files changed

+193
-167
lines changed

core/src/main/python/discover.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from wlsdeploy.tool.util.wlst_helper import WlstHelper
4545
from wlsdeploy.tool.validate.validator import Validator
4646
from wlsdeploy.util import cla_helper
47+
from wlsdeploy.util import dictionary_utils
4748
from wlsdeploy.util import model_translator
4849
from wlsdeploy.util import path_utils
4950
from wlsdeploy.util import tool_exit
@@ -105,12 +106,11 @@ def __process_target_arg(optional_arg_map):
105106

106107
if CommandLineArgUtil.TARGET_SWITCH in optional_arg_map:
107108
# if -target is specified -output_dir is required
108-
output_dir = optional_arg_map[CommandLineArgUtil.OUTPUT_DIR_SWITCH]
109-
if output_dir is None or os.path.isdir(output_dir) is False:
110-
if not os.path.isdir(output_dir):
111-
ex = exception_helper.create_cla_exception('WLSDPLY-01642', output_dir)
112-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
113-
raise ex
109+
output_dir = dictionary_utils.get_element(optional_arg_map, CommandLineArgUtil.OUTPUT_DIR_SWITCH)
110+
if (output_dir is None) or (not os.path.isdir(output_dir)):
111+
ex = exception_helper.create_cla_exception('WLSDPLY-01642', output_dir)
112+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
113+
raise ex
114114

115115
# Set the -variable_file parameter if not present with default
116116

core/src/main/python/variable_inject.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
_class_name = 'variable_inject'
3434
__logger = PlatformLogger('wlsdeploy.tool.util')
3535
__wlst_mode = WlstModes.OFFLINE
36-
__kwargs = dict()
37-
__inserted = False
38-
__tmp_model_dir = None
3936

4037
__required_arguments = [
4138
CommandLineArgUtil.ORACLE_HOME_SWITCH
@@ -64,50 +61,25 @@ def __process_args(args):
6461

6562
# determine if the model file was passed separately or requires extraction from the archive.
6663
cla_helper.validate_model_present(_program_name, argument_map)
67-
__process_injector_file(argument_map)
68-
__process_keywords_file(argument_map)
69-
__process_properties_file(argument_map)
7064

7165
return model_context_helper.create_context(_program_name, argument_map)
7266

7367

74-
def __process_injector_file(optional_arg_map):
75-
_method_name = '__process_injector_file'
76-
if CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH in optional_arg_map:
77-
injector = optional_arg_map[CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH]
78-
__logger.fine('WLSDPLY-19600', injector, class_name=_class_name, method_name=_method_name)
79-
__kwargs[variable_injector.VARIABLE_INJECTOR_FILE_NAME_ARG] = injector
80-
81-
82-
def __process_keywords_file(optional_arg_map):
83-
_method_name = '__process_keywords_file'
84-
if CommandLineArgUtil.VARIABLE_KEYWORDS_FILE_SWITCH in optional_arg_map:
85-
keywords = optional_arg_map[CommandLineArgUtil.VARIABLE_KEYWORDS_FILE_SWITCH]
86-
__logger.fine('WLSDPLY-19601', keywords, class_name=_class_name, method_name=_method_name)
87-
__kwargs[variable_injector.VARIABLE_KEYWORDS_FILE_NAME_ARG] = keywords
88-
89-
90-
def __process_properties_file(optional_arg_map):
91-
_method_name = '__process_properties_file'
92-
if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in optional_arg_map:
93-
properties = optional_arg_map[CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH]
94-
__logger.fine('WLSDPLY-19602', properties, class_name=_class_name, method_name=_method_name)
95-
__kwargs[variable_injector.VARIABLE_FILE_NAME_ARG] = properties
96-
97-
9868
def __inject(model, model_context):
9969
"""
10070
Inject variables into the model file that is loaded into the model_context.
10171
:param model_context: the model context
10272
:return: True if variables were inserted into model: The updated model
10373
"""
104-
__kwargs[variable_injector.VARIABLE_FILE_APPEND_ARG] = variable_injector.VARIABLE_FILE_UPDATE
105-
inserted, variable_model, variable_file_name = VariableInjector(_program_name, model, model_context,
106-
WebLogicHelper(
107-
__logger).get_actual_weblogic_version()). \
108-
inject_variables_keyword_file(**__kwargs)
74+
version = WebLogicHelper(__logger).get_actual_weblogic_version()
75+
injector = VariableInjector(_program_name, model, model_context, version)
76+
77+
inserted, variable_model, variable_file_name =\
78+
injector.inject_variables_keyword_file(append_option=variable_injector.VARIABLE_FILE_UPDATE)
79+
10980
if inserted:
11081
model = Model(variable_model)
82+
11183
return inserted, model
11284

11385

core/src/main/python/wlsdeploy/tool/create/domain_typedef.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import os
@@ -13,6 +13,7 @@
1313
from wlsdeploy.json.json_translator import JsonToPython
1414
from wlsdeploy.logging.platform_logger import PlatformLogger
1515
from wlsdeploy.tool.util.targeting_types import TargetingType
16+
from wlsdeploy.util import path_utils
1617
from wlsdeploy.util.cla_utils import CommandLineArgUtil
1718
from wlsdeploy.util.weblogic_helper import WebLogicHelper
1819

@@ -27,7 +28,6 @@ class DomainTypedef(object):
2728
"""
2829
__class_name = 'DomainTypedef'
2930

30-
__domain_typedefs_location = os.path.join(os.environ.get('WLSDEPLOY_HOME'), 'lib', 'typedefs')
3131
__domain_typedef_extension = '.json'
3232

3333
JRF_TEMPLATE_REGEX = "^(.*jrf_template[0-9._]*\\.jar)|(Oracle JRF WebServices Asynchronous services)$"
@@ -47,8 +47,9 @@ def __init__(self, program_name, domain_type):
4747
self._domain_type = domain_type
4848
self.wls_helper = WebLogicHelper(self._logger)
4949

50-
self._domain_typedef_filename = \
51-
os.path.join(self.__domain_typedefs_location, domain_type + self.__domain_typedef_extension)
50+
file_name = domain_type + self.__domain_typedef_extension
51+
self._domain_typedef_filename = path_utils.find_config_path(os.path.join('typedefs', file_name))
52+
5253
# No need to explicitly validate the filename since the JsonToPython constructor does that...
5354
try:
5455
json_parser = JsonToPython(self._domain_typedef_filename)
@@ -360,7 +361,7 @@ def __resolve_paths(self):
360361
self._domain_typedef['serverGroupsToTarget'] = []
361362

362363
if 'dynamicClusterServerGroupsToTarget' not in self._domain_typedef:
363-
self._domain_typedef['dynamicClusterServerGroupsToTarget'] = [ ]
364+
self._domain_typedef['dynamicClusterServerGroupsToTarget'] = []
364365

365366
if 'rcuSchemas' not in self._domain_typedef:
366367
self._domain_typedef['rcuSchemas'] = []

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
from wlsdeploy.logging.platform_logger import PlatformLogger
1010
from wlsdeploy.util import dictionary_utils
11+
from wlsdeploy.util import path_utils
1112
from wlsdeploy.util.model_translator import FileToPython
1213

1314
__class_name = 'filter_helper'
1415
__logger = PlatformLogger('wlsdeploy.tool.util')
15-
__filter_file_location = os.path.join(os.environ.get('WLSDEPLOY_HOME', ''), 'lib', 'model_filters.json')
16+
17+
TARGET_CONFIG_TOKEN = '@@TARGET_CONFIG_DIR@@'
1618

1719
__id_filter_map = {
1820
# 'filterId': filter_method
@@ -24,29 +26,36 @@ def apply_filters(model, tool_type, model_context=None):
2426
Apply any filters configured for the specified tool type to the specified model.
2527
:param model: the model to be filtered
2628
:param tool_type: the name of the filter tool type
29+
:param model_context: optional, used to find target filters
2730
:return: True if any filter was applied, False otherwise
2831
:raises: BundleAwareException of the specified type: if an error occurs
2932
"""
3033
_method_name = 'apply_filters'
34+
global __filter_file_location
3135

36+
__filter_file_location = path_utils.find_config_path('model_filters.json')
3237
filter_applied = False
33-
configuration = None
34-
38+
target_configuration = None
3539

3640
try:
37-
if model_context:
38-
configuration = model_context.get_target_configuration()
3941
filters_dictionary = {}
40-
if configuration and 'model_filters' in configuration:
41-
filters_dictionary = configuration['model_filters']
42-
target_filter_path = os.path.join(os.environ.get('WLSDEPLOY_HOME', ''), 'lib', 'targets',
43-
model_context.get_target())
42+
43+
# if target specified in model context, use the filters from target config
44+
if model_context:
45+
target_configuration = model_context.get_target_configuration()
46+
47+
if target_configuration and 'model_filters' in target_configuration:
48+
filters_dictionary = target_configuration['model_filters']
49+
target_path = os.path.join('targets', model_context.get_target())
50+
4451
# Fix the tokenized path in the filter path
4552
for filter_list in filters_dictionary:
4653
for current_filter in filters_dictionary[filter_list]:
47-
if 'path' in current_filter and current_filter['path'].startswith("@@TARGET_CONFIG_DIR@@/"):
48-
current_filter['path'] = current_filter['path'].replace("@@TARGET_CONFIG_DIR@@",
49-
target_filter_path)
54+
filter_path = dictionary_utils.get_element(current_filter, 'path')
55+
if (filter_path is not None) and filter_path.startswith(TARGET_CONFIG_TOKEN):
56+
filter_path = target_path + filter_path.replace(TARGET_CONFIG_TOKEN, '')
57+
current_filter['path'] = path_utils.find_config_path(filter_path)
58+
5059
elif os.path.isfile(__filter_file_location):
5160
filters_dictionary = FileToPython(__filter_file_location).parse()
5261
else:
@@ -70,11 +79,13 @@ def _apply_filter(model, the_filter):
7079
"""
7180
Apply the specified filter to the specified model.
7281
:param model: the model to be filtered
73-
:param filter: a dictionary containing the filter parameters
82+
:param the_filter: a dictionary containing the filter parameters
7483
:return: True if the specified filter was applied, False otherwise
7584
:raises: BundleAwareException of the specified type: if an error occurs
7685
"""
7786
_method_name = '_apply_filter'
87+
global __filter_file_location
88+
7889
id = dictionary_utils.get_element(the_filter, 'id')
7990
if id is not None:
8091
return _apply_id_filter(model, id)

0 commit comments

Comments
 (0)