|
12 | 12 | import oracle.weblogic.deploy.json.JsonException as JsonException |
13 | 13 | import oracle.weblogic.deploy.util.VariableException as VariableException |
14 | 14 |
|
| 15 | +import wlsdeploy.tool.util.variable_injector_functions as variable_injector_functions |
15 | 16 | import wlsdeploy.util.model as model_sections |
16 | 17 | import wlsdeploy.util.variables as variables |
17 | 18 | from wlsdeploy.aliases.aliases import Aliases |
|
22 | 23 | from wlsdeploy.logging.platform_logger import PlatformLogger |
23 | 24 |
|
24 | 25 | WEBLOGIC_DEPLOY_HOME_TOKEN = '@@WLSDEPLOY@@' |
| 26 | + |
| 27 | +# KWARGS to modify how files are found and loaded on the inject_variables_keyword_file(..) function |
25 | 28 | VARIABLE_INJECTOR_FILE_NAME = 'model_variable_injector.json' |
26 | 29 | VARIABLE_KEYWORDS_FILE_NAME = 'variable_keywords.json' |
27 | 30 | VARIABLE_INJECTOR_PATH_NAME_ARG = 'variable_injector_path_name' |
|
35 | 38 | VARIABLE_FILE_APPEND = 'append' |
36 | 39 | VARIABLE_FILE_UPDATE = 'update' |
37 | 40 | VARIABLE_FILE_APPEND_VALS = [VARIABLE_FILE_APPEND, VARIABLE_FILE_UPDATE] |
| 41 | + |
| 42 | + |
38 | 43 | # custom keyword in model injector file |
39 | 44 | CUSTOM_KEYWORD = 'CUSTOM' |
40 | 45 | KEYWORD_FILES = 'file-list' |
|
49 | 54 |
|
50 | 55 | VARIABLE_SEP = '.' |
51 | 56 | 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 |
52 | 68 | _find_special_names_pattern = re.compile('[\[).+\]]') |
53 | 69 | _fake_name_marker = 'fakename' |
54 | 70 | _fake_name_replacement = re.compile('.' + _fake_name_marker) |
@@ -179,7 +195,7 @@ def __inject_variable(self, location, injector, injector_values): |
179 | 195 | def _traverse_variables(model_section, mbean_list): |
180 | 196 | if mbean_list: |
181 | 197 | mbean = mbean_list.pop(0) |
182 | | - mbean, mbean_name_list = _find_special_name(mbean) |
| 198 | + mbean, mbean_name_list = self._find_special_name(mbean) |
183 | 199 | _logger.finer('WLSDPLY-19523', mbean, location.get_folder_path(), class_name=_class_name, |
184 | 200 | method_name=_method_name) |
185 | 201 | if mbean in model_section: |
@@ -221,7 +237,7 @@ def _traverse_variables(model_section, mbean_list): |
221 | 237 | section = self.__model |
222 | 238 | if start_mbean_list: |
223 | 239 | # 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]) |
225 | 241 | for entry in self.__section_keys: |
226 | 242 | if entry in self.__model and top_mbean in self.__model[entry]: |
227 | 243 | section = self.__model[entry] |
@@ -442,7 +458,7 @@ def _log_mbean_not_found(self, mbean, replacement, location): |
442 | 458 | else: |
443 | 459 | _logger.finer('WLSDPLY-19516', mbean, replacement, location.get_folder_path(), |
444 | 460 | class_name=_class_name, method_name=_method_name) |
445 | | - |
| 461 | + |
446 | 462 | def _get_variable_file_name(self, variables_injector_dictionary, **kwargs): |
447 | 463 | _method_name = '_get_variable_file_name' |
448 | 464 | if VARIABLE_FILE_NAME_ARG in kwargs: |
@@ -475,13 +491,38 @@ def _write_variables_file(self, variables_dictionary, variables_file_name, appen |
475 | 491 | _logger.exiting(class_name=_class_name, method_name=_method_name, result=written) |
476 | 492 | return written |
477 | 493 |
|
| 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 | + |
478 | 519 |
|
479 | 520 | def _load_variable_file(variable_file_location, **kwargs): |
480 | 521 | _method_name = '_load_variable_file' |
481 | 522 | append = False |
482 | 523 | variable_dictionary = dict() |
483 | 524 | 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]) |
485 | 526 | if kwargs[VARIABLE_FILE_APPEND_ARG] == VARIABLE_FILE_APPEND: |
486 | 527 | _logger.fine('WLSDPLY-19536', variable_file_location, class_name=_class_name, method_name=_method_name) |
487 | 528 | append = True |
@@ -605,8 +646,6 @@ def _get_append_to_variable_file(**kwargs): |
605 | 646 | return False |
606 | 647 |
|
607 | 648 |
|
608 | | - |
609 | | - |
610 | 649 | def _format_variable_value(value): |
611 | 650 | if type(value) == bool: |
612 | 651 | if value: |
@@ -667,16 +706,6 @@ def _split_injector(injector_path): |
667 | 706 | return ml, attr |
668 | 707 |
|
669 | 708 |
|
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 | | - |
680 | 709 | def __temporary_fix(injector_dictionary): |
681 | 710 | # this is very dangerous - for now, if you want to escape a backslash, need to do 4 backslash. |
682 | 711 | _method_name = '__temporary_fix' |
|
0 commit comments