示例#1
0
    def _is_alias_folder(self, path):
        """
        Check if the delimited path is a folder or attribute
        :param path: '|' delimited path
        :return: true if it is a folder otherwise false
        """
        debug("DEBUG: Entering is_alias_folder %s", path)
        path_tokens = path.split(PATH_TOKEN)
        model_context = ModelContext("test", {})
        aliases = Aliases(model_context=model_context,
                          wlst_mode=WlstModes.OFFLINE)
        location = LocationContext()
        last_token = path_tokens[-1]
        alias_helper = AliasHelper(aliases, __logger, ExceptionType.COMPARE)

        found = True
        name_token_next = False
        for path_token in path_tokens[1:]:
            if name_token_next:
                token_name = aliases.get_name_token(location)
                location.add_name_token(token_name, path_token)
                name_token_next = False
            else:
                location.append_location(path_token)
                if last_token == path_token:
                    break
                name_token_next = alias_helper.supports_multiple_mbean_instances(
                    location)
            attrib_names = alias_helper.get_model_attribute_names(location)
            if last_token in attrib_names:
                found = False

        debug("DEBUG: is_alias_folder %s %s", path, found)

        return found
class Deployer(object):
    """
    The base class for deployers.
    Maintains model, model context, WLST mode, etc.
    Has common methods for deployers.
    """
    _class_name = "Deployer"

    _mbean_interface = Class.forName('weblogic.management.configuration.ConfigurationMBean')
    _object_name_class = Class.forName('javax.management.ObjectName')
    _list_interface = Class.forName('java.util.List')

    def __init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE):
        self.name = self._class_name
        self.model = model
        self.wlst_mode = wlst_mode
        self.model_context = model_context
        self.aliases = aliases
        self.logger = PlatformLogger('wlsdeploy.deploy')
        self.alias_helper = AliasHelper(aliases, self.logger, ExceptionType.DEPLOY)
        self.wls_helper = WebLogicHelper(self.logger)
        self.wlst_helper = WlstHelper(self.logger, ExceptionType.DEPLOY)
        self.attribute_setter = AttributeSetter(self.aliases, self.logger, ExceptionType.DEPLOY, wlst_mode=wlst_mode)

        self.archive_helper = None
        archive_file_name = self.model_context.get_archive_file_name()
        if archive_file_name is not None:
            self.archive_helper = ArchiveHelper(archive_file_name, self.model_context.get_domain_home(), self.logger,
                                                exception_helper.ExceptionType.DEPLOY)
        return

    def _add_named_elements(self, type_name, model_nodes, location):
        """
        Add each named element from the specified nodes in WLST and set its attributes.
        Sub-folders are processed in a generic manner if present.
        It is assumed that there are no attributes or sub-folders with special processing.
        :param type_name: the type name of the child nodes
        :param model_nodes: the child nodes of a model element
        :param location: the location where elements should be added
        """
        _method_name = '_add_named_elements'

        if len(model_nodes) == 0:
            return

        parent_type, parent_name = self.get_location_type_and_name(location)
        location = LocationContext(location).append_location(type_name)
        if not self._check_location(location):
            return

        deployer_utils.check_flattened_folder(location, self.alias_helper)
        existing_names = deployer_utils.get_existing_object_list(location, self.alias_helper)

        token = self.alias_helper.get_name_token(location)
        for name in model_nodes:
            is_add = name not in existing_names
            log_helper.log_updating_named_folder(type_name, name, parent_type, parent_name, is_add, self._class_name,
                                                 _method_name)

            if token is not None:
                location.add_name_token(token, name)
            deployer_utils.create_and_cd(location, existing_names, self.alias_helper)

            child_nodes = dictionary_utils.get_dictionary_element(model_nodes, name)
            self._set_attributes_and_add_subfolders(location, child_nodes)
        return

    def _add_subfolders(self, model_nodes, location, excludes=None):
        """
        Add each model sub-folder from the specified nodes and set its attributes.
        :param model_nodes: the child nodes of a model element
        :param location: the location where sub-folders should be added
        :param excludes: optional list of sub-folder names to be excluded from processing
        """
        location = LocationContext(location)
        model_subfolder_names = self.alias_helper.get_model_subfolder_names(location)

        for subfolder in model_nodes:
            key_excluded = (excludes is not None) and (subfolder in excludes)
            if subfolder in model_subfolder_names and not key_excluded:
                subfolder_nodes = model_nodes[subfolder]
                if len(subfolder_nodes) != 0:
                    sub_location = LocationContext(location).append_location(subfolder)
                    if self.alias_helper.supports_multiple_mbean_instances(sub_location):
                        self._add_named_elements(subfolder, subfolder_nodes, location)
                    else:
                        self._add_model_elements(subfolder, subfolder_nodes, location)
        return

    def _add_model_elements(self, type_name, model_nodes, location):
        """
        Add each model element from the specified nodes at the specified location and set its attributes.
        :param model_nodes: the child nodes of a model element
        :param location: the location where sub-folders should be added
        :param type_name: the name of the model folder to add
        """
        _method_name = '_add_model_elements'

        parent_type, parent_name = self.get_location_type_and_name(location)
        location = LocationContext(location).append_location(type_name)
        if not self._check_location(location):
            return

        deployer_utils.check_flattened_folder(location, self.alias_helper)
        existing_subfolder_names = deployer_utils.get_existing_object_list(location, self.alias_helper)

        mbean_name = deployer_utils.get_mbean_name(location, existing_subfolder_names, self.alias_helper)
        is_add = mbean_name not in existing_subfolder_names
        log_helper.log_updating_folder(type_name, parent_type, parent_name, is_add, self._class_name, _method_name)

        deployer_utils.create_and_cd(location, existing_subfolder_names, self.alias_helper)

        self._set_attributes_and_add_subfolders(location, model_nodes)
        return

    def _set_attributes_and_add_subfolders(self, location, model_nodes):
        """
        Set the attributes and add sub-folders for the specified location.
        This method can be overridden for finer control of the ordering
        :param location: the location of the attributes and sub-folders
        :param model_nodes: a map of model nodes including attributes and sub-folders
        :raise: DeployException: if an error condition is encountered
        """
        self.set_attributes(location, model_nodes)
        self._add_subfolders(model_nodes, location)
        return

    def set_attributes(self, location, model_nodes, excludes=None):
        """
        Set all the attributes in the model_nodes list. Exclude items that are sub-folders.
        :param location: the location of the attributes to be set
        :param model_nodes: a map of model nodes with attributes to be set
        :param excludes: a list of items that should not be set
        :raise: DeployException: if an error condition is encountered
        """
        _method_name = 'set_attributes'
        attribute_names = self.alias_helper.get_model_attribute_names(location)
        uses_path_tokens_attribute_names = self.alias_helper.get_model_uses_path_tokens_attribute_names(location)
        restart_attribute_names = self.alias_helper.get_model_restart_required_attribute_names(location)
        merge_attribute_names = self.alias_helper.get_model_merge_required_attribute_names(location)
        lsa_required_attribute_names = self.aliases.get_model_lsa_required_attribute_names(location)
        set_method_map = self.alias_helper.get_model_mbean_set_method_attribute_names_and_types(location)

        for key in model_nodes:
            key_excluded = (excludes is not None) and (key in excludes)
            if key in attribute_names and not key_excluded:
                value = model_nodes[key]
                if key in uses_path_tokens_attribute_names:
                    self._extract_from_archive_if_needed(location, key, value)

                wlst_merge_value = None
                if key in merge_attribute_names:
                    wlst_merge_value = self._get_existing_wlst_value(location, key, lsa_required_attribute_names)

                if not self._skip_setting_attribute(key, value, wlst_merge_value, restart_attribute_names) and \
                        (not self.set_special_attribute(location, key, value, wlst_merge_value, set_method_map)):
                    try:
                        self.attribute_setter.set_attribute(location, key, value, wlst_merge_value)
                    except PyWLSTException, pwe:
                        loc_type, loc_name = self.get_location_type_and_name(location)
                        ex = exception_helper.create_deploy_exception('WLSDPLY-09200', key, loc_type, loc_name,
                                                                      pwe.getLocalizedMessage(), error=pwe)
                        self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
                        raise ex
        return