コード例 #1
0
def merge_model_and_existing_properties(model_props, existing_props, string_props_separator_char=','):
    """
    Merge the two properties objects so that the resulting properties contains all of the elements in both properties.
    :param model_props: the model properties
    :param existing_props: the existing properties
    :param string_props_separator_char: the property delimiter
    :return: the merged properties object as a java.util.Properties or a string,
             depending on the type of the model_props
    :raises: DeployException: if either properties is not either a string or a java.util.Properties object
    """
    _method_name = 'merge_model_and_existing_lists'

    _logger.entering(model_props, existing_props, string_props_separator_char,
                     class_name=_class_name, method_name=_method_name)
    if existing_props is None or len(existing_props) == 0:
        result = model_props
    elif model_props is None or len(model_props) == 0:
        result = existing_props
        if isinstance(model_props, basestring) and isinstance(existing_props, basestring):
            result = _properties_to_string(existing_props, string_props_separator_char)
    else:
        model_props_is_string = False
        if type(model_props) is str:
            model_props_is_string = True
            model_properties = _string_to_properties(model_props, string_props_separator_char)
        elif TypeUtils.isInstanceOfClass(Properties().getClass(), model_props):
            model_properties = model_props
        else:
            ex = exception_helper.create_deploy_exception('WLSDPLY-08002', str(type(model_props)))
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex

        if type(existing_props) is str:
            existing_properties = _string_to_properties(existing_props, string_props_separator_char)
        elif TypeUtils.isInstanceOfClass(Properties().getClass(), existing_props):
            existing_properties = existing_props
        else:
            ex = exception_helper.create_deploy_exception('WLSDPLY-08003', str(type(existing_props)))
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex

        for entry_set in model_properties.entrySet():
            key = entry_set.getKey()
            value = entry_set.getValue()
            existing_properties.setProperty(key, value)
        if model_props_is_string:
            result = _properties_to_string(existing_properties, string_props_separator_char)
        else:
            result = existing_properties

    _logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
    return result
コード例 #2
0
    def set_wldf_action_mbeans(self, location, key, value, wlst_value):
        """
        Set the WLDF Action/Notification MBean.
        :param location: the location
        :param key: the attribute name
        :param value: the string value
        :param wlst_value: the existing value of the attribute from WLST
        :raises BundleAwareException of the specified type: if the WLDF Action/Notification is not found
        """
        watch_location = self.__get_parent_location(location, WATCH_NOTIFICATION)
        action_names = TypeUtils.convertToType(List, value)  # type: list of str
        action_names = self.__merge_existing_items(action_names, wlst_value)

        action_mbeans = []
        for action_name in action_names:
            action_mbean = self.__find_wldf_action(watch_location, action_name)
            action_mbeans.append(action_mbean)

        if self.__wlst_mode == WlstModes.ONLINE:
            # for online, call the current location's add method for each action mbean
            location_mbean = self.__wlst_helper.cd(self.__wlst_helper.get_pwd())
            for action_mbean in action_mbeans:
                location_mbean.addNotification(action_mbean)
        else:
            self.set_attribute(location, key, action_mbeans, wlst_merge_value=wlst_value, use_raw_value=True)
        return
コード例 #3
0
def convert_to_type(data_type, value, subtype=None, delimiter=None):
    """
    Convert the value to the specified type.
    :param data_type: the type
    :param value: the value
    :param subtype: optional subtype for jarray type
    :param delimiter: optional delimiter to use for parsing
    :return: the value converted to the specified type
    """
    _method_name = 'convert_to_type'
    #
    # TypeUtils.convertToType doesn't work for passwords...
    #
    if value is not None and data_type == 'password':
        # The password is an array of bytes coming back from the WLST get() method and only
        # java.lang.String() is able to properly convert it to the cipher text string.  However,
        # we don't really want to return a java.lang.String to the caller so convert that Java
        # String back to a Python string...ugly but effective.
        new_value = str(String(value))
    else:
        try:
            new_value = TypeUtils.convertToType(data_type, value, delimiter)
        except NumberFormatException, nfe:
            ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter,
                                                         nfe.getLocalizedMessage(), error=nfe)
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex

        if new_value is not None:
            try:
                if data_type == LONG:
                    new_value = Long(new_value)
                elif data_type == JAVA_LANG_BOOLEAN:
                    new_value = Boolean(new_value)
                elif data_type == JARRAY:
                    if subtype is None or subtype == 'java.lang.String':
                        new_value = _create_string_jarray(new_value)
                    else:
                        new_value = _create_mbean_array(new_value, subtype)
                elif data_type == LIST:
                    new_value = list(new_value)
                elif data_type in ALIAS_DELIMITED_TYPES:
                    #
                    # This code intentionally ignores the delimiter value passed in and computes it from the data type.
                    # This is required to handle the special case where the value we read from WLST might have a
                    # different delimiter than the model value.  In this use case, the value passed into the method
                    # is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
                    # model delimiter from the data_type directly.
                    #
                    delimiter = compute_delimiter_from_data_type(data_type, new_value)
                    new_value = delimiter.join(new_value)
            except TypeError, te:
                ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te)
                _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
                raise ex
コード例 #4
0
    def _get_local_users(self, mapping_type, mapping_name, mapping):
        """
        Get the local users list, based on the mapping element from the model.
        :param mapping_type: the type of the mapping, such as 'CrossDomain'
        :param mapping_name: the mapping name from the model, such as 'map1'
        :param mapping: the mapping element from the model
        :return: a list of local users
        """
        if mapping_type == CROSS_DOMAIN:
            return [CROSS_DOMAIN_USER]

        local_user_value = self._get_required_attribute(
            mapping, USER, mapping_type, mapping_name)
        return TypeUtils.convertToType(list, local_user_value)
コード例 #5
0
def _convert_value_to_model_type(data_type, value, delimiter):
    """
    Convert WLST value to model representation type.
    Assumes that empty values and password data types have been converted elsewhere.
    :param data_type: the target data type for the model
    :param value: value to be converted
    :param delimiter: the delimiter for parsing the WLST representation of the data value (optional)
    :return: converted value
    """
    _method_name = '_convert_value_to_model_type'
    try:
        converted = TypeUtils.convertToType(data_type, value, delimiter)
    except NumberFormatException, nfe:
        ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter,
                                                     nfe.getLocalizedMessage(), error=nfe)
        _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
コード例 #6
0
    def __build_server_mbean_list(self, value, wlst_value):
        """
        Construct the server MBean list.
        :param value: the value
        :param wlst_value: the existing value from WLST
        :return: the Java array of MBeans ObjectNames
        :raises BundleAwareException of the specified type: if an error occurs
        """
        server_names = TypeUtils.convertToType(List, value)  # type: list of str
        server_names = self.__merge_existing_items(server_names, wlst_value)

        name_list = []
        for server_name in server_names:
            mbean = self.__find_in_location(LocationContext(), SERVER, server_name, required=True)
            name_list.append(mbean.getObjectName())

        return jarray.array(name_list, ObjectName)
コード例 #7
0
    def __merge_existing_items(self, items, existing_value):
        """
        Merge the specified items with the items represented by existing value, and return the result.
        :param items: the attribute name
        :param existing_value: the value representing the existing items (may be a string or list)
        :return: the merged list of items
        :raises BundleAwareException of the specified type: if the WLDF Action/Notification is not found
        """
        _method_name = '__merge_existing_items'
        self.__logger.entering(str(items), str(existing_value), class_name=self._class_name, method_name=_method_name)

        existing_items = TypeUtils.convertToType(List, existing_value)  # type: list of str
        no_existing_items = (existing_items is None) or (len(existing_items) == 0)
        if no_existing_items:
            result = items
        else:
            result = list(Set(items).union(Set(existing_items)))
        return result
コード例 #8
0
    def __build_target_mbean_list(self, target_value, wlst_value, location, include_jms=False):
        """
        Construct the target MBean list.
        :param target_value: the target value
        :param wlst_value: the existing value from WLST
        :param include_jms: whether or not to include JMS targets, the default is False
        :return: the Java array of MBeans ObjectNames
        :raises BundleAwareException of the specified type: if an error occurs
        """
        target_names = TypeUtils.convertToType(List, target_value)  # type: list of str
        target_names = self.__merge_existing_items(target_names, wlst_value)

        name_list = []
        for target_name in target_names:
            target_mbean = self.__find_target(target_name, location, include_jms=include_jms)
            name_list.append(target_mbean.getObjectName())

        return jarray.array(name_list, ObjectName)
コード例 #9
0
    def __build_virtual_target_mbean_list(self, target_value, wlst_value):
        """
        Construct the virtual target MBean list.
        :param target_value: the target value
        :param wlst_value: the existing value from WLST
        :return: for offline, a list of MBeans; for online, a jarray of MBean ObjectNames
        :raises BundleAwareException of the specified type: if an error occurs
        """
        target_names = TypeUtils.convertToType(List, target_value)  # type: list of str
        target_names = self.__merge_existing_items(target_names, wlst_value)

        if self.__wlst_mode == WlstModes.ONLINE:
            name_list = []
            for target_name in target_names:
                target_mbean = self.__find_in_location(LocationContext(), VIRTUAL_TARGET, target_name, required=True)
                name_list.append(target_mbean.getObjectName())
            return jarray.array(name_list, ObjectName)
        else:
            mbean_list = []
            for target_name in target_names:
                target_mbean = self.__find_in_location(LocationContext(), VIRTUAL_TARGET, target_name, required=True)
                mbean_list.append(target_mbean)
            return mbean_list