def delete_named_element(location, delete_name, existing_names, aliases):
    """
    Delete the specified named element if present. If the name is not present, log a warning and return.
    :param location: the location of the element to be deleted
    :param delete_name: the name of the element to be deleted, assumed to include the "!" prefix
    :param existing_names: a list of names to check against
    :param aliases: alias helper for lookups
    """
    _method_name = 'delete_named_element'

    name = model_helper.get_delete_item_name(delete_name)
    type_name = aliases.get_wlst_mbean_type(location)

    if name not in existing_names:
        _logger.warning('WLSDPLY-09109',
                        type_name,
                        name,
                        class_name=_class_name,
                        method_name=_method_name)
    else:
        _logger.info('WLSDPLY-09110',
                     type_name,
                     name,
                     class_name=_class_name,
                     method_name=_method_name)
        type_path = aliases.get_wlst_create_path(location)
        _wlst_helper.cd(type_path)
        _wlst_helper.delete(name, type_name)
    def _add_group_params(self, group_name_nodes, location):
        """
        Add each group param entry from group name nodes and set its attributes.
        A two-pass approach is required since the new folder's name does not always match the group name.
        Special processing for error destination attributes (build mbean)
        :param group_name_nodes: the nodes containing group parameter names
        :param location: the WLST location where the parameters should be added
        """
        _method_name = '_add_group_params'
        if len(group_name_nodes) == 0:
            return

        # use a copy of the dictionary to remove items as they are deleted
        remaining_name_nodes = group_name_nodes.copy()

        parent_type, parent_name = self.get_location_type_and_name(location)
        template_path = self.alias_helper.get_wlst_subfolders_path(location)
        groups_location = LocationContext(location)
        groups_location.append_location(GROUP_PARAMS)
        groups_token = self.alias_helper.get_name_token(groups_location)
        name_attribute = self.alias_helper.get_wlst_attribute_name(groups_location, SUB_DEPLOYMENT_NAME)
        mbean_type = self.alias_helper.get_wlst_mbean_type(groups_location)

        for group_name in group_name_nodes:
            if model_helper.is_delete_name(group_name):
                group_nodes = group_name_nodes[group_name]
                name = model_helper.get_delete_item_name(group_name)
                sub_name = self._get_subdeployment_name(group_nodes, name)
                self._delete_mapped_mbean(groups_location, groups_token, mbean_type, name_attribute, sub_name)
                del remaining_name_nodes[group_name]

        # loop once to create and name any missing folders.
        folder_map = self._build_folder_map(groups_location, groups_token, name_attribute)

        for group_name in remaining_name_nodes:
            group_nodes = remaining_name_nodes[group_name]
            sub_deployment_name = self._get_subdeployment_name(group_nodes, group_name)
            folder_name = dictionary_utils.get_element(folder_map, sub_deployment_name)
            if folder_name is None:
                self.wlst_helper.cd(template_path)
                group = self.wlst_helper.create(sub_deployment_name, mbean_type)
                group.setSubDeploymentName(sub_deployment_name)

        # loop a second time to set attributes
        new_folder_map = self._build_folder_map(groups_location, groups_token, name_attribute)

        for group_name in remaining_name_nodes:
            group_nodes = remaining_name_nodes[group_name]
            sub_deployment_name = self._get_subdeployment_name(group_nodes, group_name)
            is_add = sub_deployment_name not in folder_map
            log_helper.log_updating_named_folder(GROUP_PARAMS, group_name, parent_type, parent_name, is_add,
                                                 self._class_name, _method_name)

            folder_name = dictionary_utils.get_element(new_folder_map, sub_deployment_name)
            groups_location.add_name_token(groups_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(groups_location))
            self.set_attributes(groups_location, group_nodes)
    def _add_jndi_properties(self, property_name_nodes, location):
        """
        Add each property entry from property nodes and set its attributes.
        A two-pass approach is required since the new folder's name does not always match the property name.
        :param property_name_nodes: the nodes containing property names
        :param location: the WLST location where the properties should be added
        """
        _method_name = '_add_jndi_properties'
        if len(property_name_nodes) == 0:
            return

        # use a copy of the dictionary to remove items as they are deleted
        remaining_name_nodes = property_name_nodes.copy()

        parent_type, parent_name = self.get_location_type_and_name(location)
        is_online = self.wlst_mode == WlstModes.ONLINE
        if is_online and deployer_utils.is_in_resource_group_or_template(location):
            self.logger.info('WLSDPLY-09501', JNDI_PROPERTY, parent_type, parent_name, class_name=self._class_name,
                             method_name=_method_name)
            return

        foreign_server_path = self.alias_helper.get_wlst_subfolders_path(location)
        properties_location = LocationContext(location).append_location(JNDI_PROPERTY)
        properties_token = self.alias_helper.get_name_token(properties_location)
        name_attribute = self.alias_helper.get_wlst_attribute_name(properties_location, KEY)
        mbean_type = self.alias_helper.get_wlst_mbean_type(properties_location)

        for property_name in property_name_nodes:
            if model_helper.is_delete_name(property_name):
                name = model_helper.get_delete_item_name(property_name)
                self._delete_mapped_mbean(properties_location, properties_token, mbean_type, name_attribute, name)
                del remaining_name_nodes[property_name]

        # loop once to create and name any missing folders.
        folder_map = self._build_folder_map(properties_location, properties_token, name_attribute)

        for property_name in remaining_name_nodes:
            folder_name = dictionary_utils.get_element(folder_map, property_name)
            if folder_name is None:
                self.wlst_helper.cd(foreign_server_path)
                new_property = self.wlst_helper.create(property_name, mbean_type)
                new_property.setKey(property_name)

        # loop a second time to set attributes
        new_folder_map = self._build_folder_map(properties_location, properties_token, name_attribute)

        for property_name in remaining_name_nodes:
            is_add = property_name not in folder_map
            log_helper.log_updating_named_folder(JNDI_PROPERTY, property_name, parent_type, parent_name, is_add,
                                                 self._class_name, _method_name)

            folder_name = dictionary_utils.get_element(new_folder_map, property_name)
            properties_location.add_name_token(properties_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(properties_location))

            property_nodes = remaining_name_nodes[property_name]
            self.set_attributes(properties_location, property_nodes)
def _get_merge_match_key(key, variable_map):
    """
    Get the key name to use for matching in model merge.
    This includes resolving any variables, and removing delete notation if present.
    :param key: the key to be examined
    :param variable_map: variable map to use for substitutions
    :return: the key to use for matching
    """

    match_key = variables.substitute_key(key, variable_map)

    if model_helper.is_delete_name(match_key):
        match_key = model_helper.get_delete_item_name(match_key)
    return match_key
def merge_model_and_existing_lists(model_list, existing_list, location_path="(unknown)", attribute_name="(unknown)"):
    """
    Merge the two lists so that the resulting list contains all of the elements in both lists one time.
    :param model_list: the list to merge, possibly a string or None
    :param existing_list: the existing list, possibly a string or None
    :param location_path: optional, the path of the attribute location, for logging
    :param attribute_name: optional, the attribute name, for logging
    :return: the merged list as a list or a string, depending on the type of the model_list
    :raises: DeployException: if either list is not either a string or a list
    """
    _method_name = 'merge_model_and_existing_lists'

    _logger.entering(model_list, existing_list, location_path, attribute_name, class_name=_class_name,
                     method_name=_method_name)

    if model_list is None:
        result_is_string = isinstance(existing_list, basestring)
    else:
        result_is_string = isinstance(model_list, basestring)

    result = create_list(existing_list, 'WLSDPLY-08001')
    model_iterator = create_list(model_list, 'WLSDPLY-08000')

    for item in model_iterator:
        if model_helper.is_delete_name(item):
            item_name = model_helper.get_delete_item_name(item)
            if item_name in result:
                result.remove(item_name)
            else:
                _logger.warning('WLSDPLY-08022', item_name, attribute_name, location_path, class_name=_class_name,
                                method_name=_method_name)

        elif item not in result:
            result.append(item)

    if result_is_string:
        result = MODEL_LIST_DELIMITER.join(result)

    _logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
    return result
Exemplo n.º 6
0
def __delete_online_targets(app_deployments, model_type, aliases):
    """
    For online deploy and update, remove any deleted targets from existing objects of the specified type.
    Objects may be applications or libraries.
    :param app_deployments: the APP_DEPLOYMENTS dictionary from the model
    :param model_type: map of library targets to be deleted
    :param aliases: the parent location of the apps and libraries
    """
    _method_name = '__delete_online_targets'

    location = LocationContext().append_location(model_type)
    wlst_path = aliases.get_wlst_list_path(location)
    wlst_names = _wlst_helper.get_existing_object_list(wlst_path)
    name_token = aliases.get_name_token(location)

    deploy_dict = dictionary_utils.get_dictionary_element(app_deployments, model_type)
    for deploy_name in deploy_dict.keys():
        if deploy_name in wlst_names:
            value_dict = deploy_dict[deploy_name]

            delete_names = []
            model_targets = dictionary_utils.get_element(value_dict, TARGET)
            targets = alias_utils.create_list(model_targets, 'WLSDPLY-08000')
            for target in targets:
                if model_helper.is_delete_name(target):
                    delete_names.append(model_helper.get_delete_item_name(target))

            location.add_name_token(name_token, deploy_name)
            mbean_path = aliases.get_wlst_attributes_path(location)
            mbean = _wlst_helper.get_mbean_for_wlst_path(mbean_path)
            mbean_targets = mbean.getTargets()
            for mbean_target in mbean_targets:
                mbean_name = mbean_target.getName()
                if mbean_name in delete_names:
                    _logger.info('WLSDPLY-09114', mbean_name, model_type, deploy_name, class_name=_class_name,
                                 method_name=_method_name)
                    mbean.removeTarget(mbean_target)