Skip to content

Commit aa19eb6

Browse files
Add managedserver keyword
1 parent 6f9f06d commit aa19eb6

File tree

5 files changed

+120
-17
lines changed

5 files changed

+120
-17
lines changed

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

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import oracle.weblogic.deploy.json.JsonException as JsonException
1313
import oracle.weblogic.deploy.util.VariableException as VariableException
1414

15+
import wlsdeploy.tool.util.variable_injector_functions as variable_injector_functions
1516
import wlsdeploy.util.model as model_sections
1617
import wlsdeploy.util.variables as variables
1718
from wlsdeploy.aliases.aliases import Aliases
@@ -22,6 +23,8 @@
2223
from wlsdeploy.logging.platform_logger import PlatformLogger
2324

2425
WEBLOGIC_DEPLOY_HOME_TOKEN = '@@WLSDEPLOY@@'
26+
27+
# KWARGS to modify how files are found and loaded on the inject_variables_keyword_file(..) function
2528
VARIABLE_INJECTOR_FILE_NAME = 'model_variable_injector.json'
2629
VARIABLE_KEYWORDS_FILE_NAME = 'variable_keywords.json'
2730
VARIABLE_INJECTOR_PATH_NAME_ARG = 'variable_injector_path_name'
@@ -35,6 +38,8 @@
3538
VARIABLE_FILE_APPEND = 'append'
3639
VARIABLE_FILE_UPDATE = 'update'
3740
VARIABLE_FILE_APPEND_VALS = [VARIABLE_FILE_APPEND, VARIABLE_FILE_UPDATE]
41+
42+
3843
# custom keyword in model injector file
3944
CUSTOM_KEYWORD = 'CUSTOM'
4045
KEYWORD_FILES = 'file-list'
@@ -49,6 +54,17 @@
4954

5055
VARIABLE_SEP = '.'
5156
SUFFIX_SEP = '--'
57+
58+
MANAGED_SERVERS = 'MANAGED_SERVERS'
59+
ADMIN_SERVER = 'ADMIN_SERVER'
60+
61+
# This could be changed into a loaded file so that others can add their own bits of code to
62+
# selectively identify which names in an mbean list should be injected with properties
63+
USER_KEYWORD_DICT = {
64+
MANAGED_SERVERS: 'managed_server_list',
65+
ADMIN_SERVER: 'admin_server_list'
66+
}
67+
# global variables for functions in VariableInjector
5268
_find_special_names_pattern = re.compile('[\[).+\]]')
5369
_fake_name_marker = 'fakename'
5470
_fake_name_replacement = re.compile('.' + _fake_name_marker)
@@ -179,7 +195,7 @@ def __inject_variable(self, location, injector, injector_values):
179195
def _traverse_variables(model_section, mbean_list):
180196
if mbean_list:
181197
mbean = mbean_list.pop(0)
182-
mbean, mbean_name_list = _find_special_name(mbean)
198+
mbean, mbean_name_list = self._find_special_name(mbean)
183199
_logger.finer('WLSDPLY-19523', mbean, location.get_folder_path(), class_name=_class_name,
184200
method_name=_method_name)
185201
if mbean in model_section:
@@ -221,7 +237,7 @@ def _traverse_variables(model_section, mbean_list):
221237
section = self.__model
222238
if start_mbean_list:
223239
# Find out in what section is the mbean top folder so can move to that section in the model
224-
top_mbean, __ = _find_special_name(start_mbean_list[0])
240+
top_mbean, __ = self._find_special_name(start_mbean_list[0])
225241
for entry in self.__section_keys:
226242
if entry in self.__model and top_mbean in self.__model[entry]:
227243
section = self.__model[entry]
@@ -442,7 +458,7 @@ def _log_mbean_not_found(self, mbean, replacement, location):
442458
else:
443459
_logger.finer('WLSDPLY-19516', mbean, replacement, location.get_folder_path(),
444460
class_name=_class_name, method_name=_method_name)
445-
461+
446462
def _get_variable_file_name(self, variables_injector_dictionary, **kwargs):
447463
_method_name = '_get_variable_file_name'
448464
if VARIABLE_FILE_NAME_ARG in kwargs:
@@ -475,13 +491,38 @@ def _write_variables_file(self, variables_dictionary, variables_file_name, appen
475491
_logger.exiting(class_name=_class_name, method_name=_method_name, result=written)
476492
return written
477493

494+
def _find_special_name(self, mbean):
495+
mbean_name = mbean
496+
mbean_name_list = []
497+
name_list = _find_special_names_pattern.split(mbean)
498+
if name_list and len(name_list) > 1:
499+
mbean_name = name_list[0]
500+
mbean_name_list = name_list[1].split(',')
501+
if mbean_name_list:
502+
new_list = []
503+
for entry in mbean_name_list:
504+
if entry in USER_KEYWORD_DICT:
505+
_logger.fine('WLSDPLY-19538', entry, mbean)
506+
try:
507+
method = getattr(variable_injector_functions, USER_KEYWORD_DICT[entry])
508+
append_list = method(self.__model)
509+
new_list.extend(append_list)
510+
except AttributeError, e:
511+
_logger.warning('WLSDPLY-19539', entry, USER_KEYWORD_DICT[entry], e)
512+
new_list = mbean_name_list
513+
break
514+
else:
515+
new_list.append(entry)
516+
mbean_name_list = new_list
517+
return mbean_name, mbean_name_list
518+
478519

479520
def _load_variable_file(variable_file_location, **kwargs):
480521
_method_name = '_load_variable_file'
481522
append = False
482523
variable_dictionary = dict()
483524
if VARIABLE_FILE_APPEND_ARG in kwargs and kwargs[VARIABLE_FILE_APPEND_ARG] in VARIABLE_FILE_APPEND_VALS:
484-
_logger.fine('append argument found {0}', kwargs[VARIABLE_FILE_APPEND_ARG] )
525+
_logger.fine('append argument found {0}', kwargs[VARIABLE_FILE_APPEND_ARG])
485526
if kwargs[VARIABLE_FILE_APPEND_ARG] == VARIABLE_FILE_APPEND:
486527
_logger.fine('WLSDPLY-19536', variable_file_location, class_name=_class_name, method_name=_method_name)
487528
append = True
@@ -605,8 +646,6 @@ def _get_append_to_variable_file(**kwargs):
605646
return False
606647

607648

608-
609-
610649
def _format_variable_value(value):
611650
if type(value) == bool:
612651
if value:
@@ -667,16 +706,6 @@ def _split_injector(injector_path):
667706
return ml, attr
668707

669708

670-
def _find_special_name(mbean):
671-
mbean_name = mbean
672-
mbean_name_list = []
673-
name_list = _find_special_names_pattern.split(mbean)
674-
if name_list and len(name_list) > 1:
675-
mbean_name = name_list[0]
676-
mbean_name_list = name_list[1].split(',')
677-
return mbean_name, mbean_name_list
678-
679-
680709
def __temporary_fix(injector_dictionary):
681710
# this is very dangerous - for now, if you want to escape a backslash, need to do 4 backslash.
682711
_method_name = '__temporary_fix'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
The Universal Permissive License (UPL), Version 1.0
4+
"""
5+
from wlsdeploy.logging.platform_logger import PlatformLogger
6+
7+
import wlsdeploy.aliases.model_constants as model_constants
8+
import wlsdeploy.util.model as model_sections
9+
10+
_class_name = 'variable_injector'
11+
_logger = PlatformLogger('wlsdeploy.tool.util')
12+
13+
14+
def managed_server_list(model):
15+
"""
16+
Return a managed server name list from the provided model.
17+
:param model: to process for managed server list
18+
:return: list of managed server names or empty list if no managed servers
19+
"""
20+
_method_name = 'managed_server_list'
21+
_logger.entering(class_name=_class_name, method_name=_method_name)
22+
ms_name_list = []
23+
topology_constant = model_sections.get_model_topology_key()
24+
if topology_constant in model:
25+
topology = model[topology_constant]
26+
if model_constants.SERVER in topology:
27+
ms_name_list = topology[model_constants.SERVER].keys()
28+
if model_constants.ADMIN_SERVER_NAME in topology:
29+
admin_server = topology[model_constants.ADMIN_SERVER_NAME]
30+
if admin_server in ms_name_list:
31+
ms_name_list.remove(admin_server)
32+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=ms_name_list)
33+
return ms_name_list
34+
35+
36+
def admin_server_list(model):
37+
"""
38+
Return the domain admin server in list format
39+
:param model: to process for admin server list
40+
:return: admin server in list format
41+
"""
42+
_method_name = 'admin_server_list'
43+
_logger.entering(class_name=_class_name, method_name=_method_name)
44+
as_name_list = []
45+
topology_constant = model_sections.get_model_topology_key()
46+
if topology_constant in model:
47+
topology = model[topology_constant]
48+
if topology and model_constants.ADMIN_SERVER_NAME in topology:
49+
as_name_list.append(topology[model_constants.ADMIN_SERVER_NAME])
50+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=as_name_list)
51+
return as_name_list

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ WLSDPLY-19534=Update existing variable file {0} with injected variables
11671167
WLSDPLY-19535=Create new variable file {0} for injected variables
11681168
WLSDPLY-19536=Append existing variable file {0} with injected variables
11691169
WLSDPLY-19537=Unable to load variables from existing file {0} and will overwrite the file : {1}
1170+
WLSDPLY-19538=Found name keyword {0} for mbean {1}
1171+
WLSDPLY-19539=Unable to locate and call mbean name keyword {0} method {1} : {2}. Will inject variables using \
1172+
full mbean name list
11701173

11711174
# wlsdeploy/tool/variable_inject.py
11721175
WLSDPLY-19600=Use model variable injector file {0} from command line arguments

core/src/test/python/variable_injector_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,25 @@ def testWithListMBeanName(self):
210210
actual = self._helper.inject_variables(replacement_dict)
211211
self._compare_to_expected_dictionary(expected, actual)
212212

213+
def testWithManagedServerKeyword(self):
214+
expected = dict()
215+
expected['Server.m1.SSL.Enabled'] = 'True'
216+
expected['Server.m2.SSL.Enabled'] = 'True'
217+
replacement_dict = dict()
218+
replacement_dict['Server[MANAGED_SERVERS].SSL.Enabled'] = dict()
219+
actual = self._helper.inject_variables(replacement_dict)
220+
self._compare_to_expected_dictionary(expected, actual)
221+
222+
def testWithMultiKeyword(self):
223+
expected = dict()
224+
expected['Server.AdminServer.SSL.Enabled'] = 'True'
225+
expected['Server.m1.SSL.Enabled'] = 'True'
226+
expected['Server.m2.SSL.Enabled'] = 'True'
227+
replacement_dict = dict()
228+
replacement_dict['Server[MANAGED_SERVERS,ADMIN_SERVER].SSL.Enabled'] = dict()
229+
actual = self._helper.inject_variables(replacement_dict)
230+
self._compare_to_expected_dictionary(expected, actual)
231+
213232
def testWithVariableHelperKeywords(self):
214233
expected = dict()
215234
expected['JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.ConnectionURL'] \

installer/src/main/samples/custom_injector.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"suffix": "Host"
1212
}
1313
]
14-
}
14+
},
15+
"Server[MANAGED_SERVERS].SSL.Enabled": {}
1516
}

0 commit comments

Comments
 (0)