def __init__(self, aliases, logger, model_context, exception_type, variable_injector=None): global _logger self._exception_type = exception_type self._model_context = model_context if logger is not None: _logger = logger self._alias_helper = AliasHelper(aliases, _logger, self._exception_type) self._weblogic_helper = WebLogicHelper(_logger) self._wlst_helper = WlstHelper(_logger, self._exception_type) self._info_helper = MBeanUtils(self._model_context, self._alias_helper, self._exception_type) self._variable_injector = variable_injector
def __init__(self, model_context, base_location, wlst_mode, aliases=None, variable_injector=None): """ :param model_context: context about the model for this instance of discover domain :param base_location: to look for common weblogic resources. By default this is the global path or '/' """ self._model_context = model_context self._base_location = base_location self._wlst_mode = wlst_mode if aliases: self._aliases = aliases else: self._aliases = Aliases(self._model_context, wlst_mode=self._wlst_mode) self._alias_helper = AliasHelper(self._aliases, _logger, ExceptionType.DISCOVER) self._variable_injector = variable_injector self._att_handler_map = OrderedDict() self._custom_folder = CustomFolderHelper(self._aliases, _logger, self._model_context, ExceptionType.DISCOVER, self._variable_injector) self._weblogic_helper = WebLogicHelper(_logger) self._wlst_helper = WlstHelper(ExceptionType.DISCOVER) self._mbean_utils = MBeanUtils(self._model_context, self._alias_helper, ExceptionType.DISCOVER) self._wls_version = self._weblogic_helper.get_actual_weblogic_version()
def __init__(self, aliases, logger, model_context, exception_type, credential_injector=None): global _logger self._exception_type = exception_type self._model_context = model_context if logger is not None: _logger = logger self._weblogic_helper = WebLogicHelper(_logger) self._wlst_helper = WlstHelper(self._exception_type) self._info_helper = MBeanUtils(self._model_context, aliases, self._exception_type) self._credential_injector = credential_injector
def __init__(self, model_context, base_location, wlst_mode, aliases=None, credential_injector=None): """ :param model_context: context about the model for this instance of discover domain :param base_location: to look for common weblogic resources. By default this is the global path or '/' :param wlst_mode: offline or online :param aliases: optional, aliases object to use :param credential_injector: optional, injector to collect credentials """ self._model_context = model_context self._base_location = base_location self._wlst_mode = wlst_mode if aliases: self._aliases = aliases else: self._aliases = Aliases(self._model_context, wlst_mode=self._wlst_mode, exception_type=ExceptionType.DISCOVER) self._credential_injector = credential_injector self._att_handler_map = OrderedDict() self._custom_folder = CustomFolderHelper(self._aliases, _logger, self._model_context, ExceptionType.DISCOVER, self._credential_injector) self._weblogic_helper = WebLogicHelper(_logger) self._wlst_helper = WlstHelper(ExceptionType.DISCOVER) self._mbean_utils = MBeanUtils(self._model_context, self._aliases, ExceptionType.DISCOVER) self._wls_version = self._weblogic_helper.get_actual_weblogic_version()
class CustomFolderHelper(object): """ Helper for locating the custom MBeans and its attributes. These require special handling, since they do not have alias definitions. Discover the MBean attributes using the information provided by the MBeanAttributes wrapper class. """ def __init__(self, aliases, logger, model_context, exception_type, variable_injector=None): global _logger self._exception_type = exception_type self._model_context = model_context if logger is not None: _logger = logger self._alias_helper = AliasHelper(aliases, _logger, self._exception_type) self._weblogic_helper = WebLogicHelper(_logger) self._wlst_helper = WlstHelper(_logger, self._exception_type) self._info_helper = MBeanUtils(self._model_context, self._alias_helper, self._exception_type) self._variable_injector = variable_injector def discover_custom_mbean(self, base_location, model_type, mbean_name): """ Discover the Custom MBean attributes using its MBeanInfo. :param base_location: the current context for the location :param model_type: The parent type of the custom MBean :param mbean_name: the name of the custom MBean instance :raises: BundleAwareException of the specified type: if an error occurs """ _method_name = 'discover_custom_mbean' _logger.entering(base_location.get_folder_path(), model_type, mbean_name, class_name=_class_name, method_name=_method_name) location = LocationContext(base_location) subfolder_result = PyOrderedDict() attribute_helper = self._info_helper.get_info_attribute_helper(location) if attribute_helper is None: _logger.warning('WLSDPLY-06753', model_type, str(attribute_helper), mbean_name, class_name=_class_name, method_name=_method_name) else: subfolder_result[mbean_name] = PyOrderedDict() _logger.finer('WLSDPLY-06757', attribute_helper.mbean_string(), class_name=_class_name, method_name=_method_name) short_name = attribute_helper.get_mbean_name() # This is not like other custom interface names and should be changed to be more flexible interface_name = security_provider_interface_name(attribute_helper.get_mbean_instance(), attribute_helper.get_mbean_interface_name()) subfolder_result[mbean_name][interface_name] = PyOrderedDict() _logger.info('WLSDPLY-06751', model_type, short_name, class_name=_class_name, method_name=_method_name) _logger.info('WLSDPLY-06752', mbean_name, model_type, short_name, class_name=_class_name, method_name=_method_name) subfolder_result[mbean_name][interface_name] = self.get_model_attribute_map(location, attribute_helper) _logger.exiting(class_name=_class_name, method_name=_method_name) return subfolder_result def get_model_attribute_map(self, location, attribute_helper): """ Return a map of the MBean's attributes, in model format, which do not have default values. :param location: location context for the current MBean :param attribute_helper: context for the current MBean :return: model ready dictionary of the discovered MBean """ _method_name = 'get_model_attribute_map' _logger.entering(str(attribute_helper), class_name=_class_name, method_name=_method_name) mbean_attributes = PyOrderedDict() for attribute_name in attribute_helper.get_mbean_attributes(): model_value = self.get_model_attribute_value(attribute_helper, attribute_name) if model_value is not None: mbean_attributes[attribute_name] = model_value self.__inject_token(location, mbean_attributes, attribute_name) _logger.exiting(class_name=_class_name, method_name=_method_name) return mbean_attributes def get_model_attribute_value(self, attribute_helper, attribute_name, wlst_value='unknown'): """ Retrieve the WLST value for the attribute and convert the value into a model appropriate format. If the attribute is read only, or the value is empty, or the value is the default, return None :param attribute_helper: context for the current MBean :param attribute_name: current MBean attribute being processed :param wlst_value: if provided, use this WLST value for the attribute instead of from the MBean instance :return: Converted model attribute value """ _method_name = 'get_model_attribute_value' add_value = None mbean_string = attribute_helper.mbean_string() if attribute_helper.is_read_only(attribute_name): _logger.finer('WLDSPLY-06776', mbean_string, attribute_name, class_name=_class_name, method_name=_method_name) else: model_type, model_value = self.__convert_to_type(attribute_helper, attribute_name, wlst_value) if model_type is not None: print_conv = model_value if model_type == alias_constants.PASSWORD: print_orig = alias_constants.MASKED print_conv = print_orig _logger.finer('WLSDPLY-06770', mbean_string, attribute_name, model_type, str(print_conv), class_name=_class_name, method_name=_method_name) default_value = self.__get_default_value(attribute_helper, attribute_name) if not is_empty(model_value): if is_empty(default_value) or not self.is_default(model_value, model_type, default_value): add_value = model_value if add_value is not None and model_type == alias_constants.PASSWORD: add_value = alias_constants.PASSWORD_TOKEN else: _logger.finer('WLSDPLY-06771', mbean_string, attribute_name, attribute_helper.get_type(attribute_name), class_name=_class_name, method_name=_method_name) return add_value def convert(self, value, value_type): """ Public function to convert the value with value_type to a model compatible value. :param value: Value to be converted into the appropriate model data type :param value_type: data type of the value :return: converted data type and value """ _method_name = 'convert_method' converted_type = None converted = None try: if value_type == '[B': converted_type = alias_constants.PASSWORD converted = convert_byte_buffer(value) elif value_type == 'int' or value_type == 'java.lang.Integer': converted_type = alias_constants.INTEGER converted = convert_numeric(Integer, value) elif value_type == 'long' or value_type == 'java.lang.Long': converted_type = alias_constants.LONG converted = convert_numeric(Long, value) elif value_type == 'double' or value_type == 'java.lang.Double': converted_type = alias_constants.DOUBLE converted = convert_numeric(Double, value) elif value_type == 'float' or value_type == 'java.lang.Float': _logger.info('WLSDPLY-06766', value_type, class_name=_class_name, method_name=_method_name) elif value_type == 'java.math.BigInteger': converted_type, converted = convert_big_integer(value) _logger.fine('WLSDPLY-06767', converted, converted_type, class_name=_class_name, method_name=_method_name) elif value_type == 'str' or value_type == 'java.lang.String' or value_type == 'string': converted_type = alias_constants.STRING converted = convert_string(value) elif value_type == 'bool' or value_type == 'boolean' or value_type == 'java.lang.Boolean': converted_type = alias_constants.BOOLEAN converted = convert_boolean(value) elif value_type == 'dict' or value_type == 'java.util.Properties' or value_type == 'java.util.Map': converted_type = alias_constants.PROPERTIES converted = create_dictionary(value) elif value_type.endswith('Enum'): converted_type = alias_constants.STRING if value is not None: converted = value.toString() elif value_type == 'PyArray' or value_type.startswith('[L'): converted = create_array(value) if converted is not None: converted_type = alias_constants.JARRAY elif value_type == 'list': converted = create_array(value) if converted is not None: converted_type = alias_constants.LIST else: converted_type, converted = convert_value(value) _logger.fine('WLSDPLY-06768', value_type, converted_type, class_name=_class_name, method_name=_method_name) except Exception, e: _logger.fine('WLSDPLY-06769', value_type, converted_type, str(e), class_name=_class_name, method_name=_method_name) return converted_type, converted