Example #1
0
    def _create_placeholder_coherence_cluster(self, cluster_name):
        """
        Create a placeholder Coherence cluster system resource to be referenced from a topology element.
        The new cluster will be created at the root domain level.
        :param cluster_name: the name of the Coherence cluster system resource to be added
        """
        _method_name = '_create_placeholder_coherence_cluster'
        original_location = self.wlst_helper.get_pwd()
        cluster_location = LocationContext().append_location(
            COHERENCE_CLUSTER_SYSTEM_RESOURCE)
        existing_names = deployer_utils.get_existing_object_list(
            cluster_location, self.alias_helper)

        if cluster_name not in existing_names:
            self.logger.info('WLSDPLY-12230',
                             cluster_name,
                             class_name=self.__class_name,
                             method_name=_method_name)

            cluster_token = self.alias_helper.get_name_token(cluster_location)
            cluster_location.add_name_token(cluster_token, cluster_name)
            deployer_utils.create_and_cd(cluster_location, existing_names,
                                         self.alias_helper)

        self.wlst_helper.cd(original_location)
    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 _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
Example #4
0
    def create_security_configuration(self, location):
        """
        Create the /SecurityConfiguration folder objects, if any.
        
        The SecurityConfiguration should already be configured by create domain, but
        allow the method to create the default security configuration with the default realm if for some reason
        it does not exist.  
        
        :param location: the location to use
        :raises: BundleAwareException of the specified type: if an error occurs
        """
        _method_name = '__create_security_configuration'

        self.logger.entering(str(location), class_name=self.__class_name, method_name=_method_name)
        security_configuration_nodes = dictionary_utils.get_dictionary_element(self._topology, SECURITY_CONFIGURATION)

        # in WLS 11g, the SecurityConfiguration mbean is not created until the domain is written.
        # This is called after the domain is written, but check to make sure the mbean does exist.
        # It missing it will be created to initialize the default realm and security providers.
        config_location = LocationContext(location).append_location(SECURITY_CONFIGURATION)
        existing_names = deployer_utils.get_existing_object_list(config_location, self.alias_helper)
        if len(existing_names) == 0:
            mbean_type, mbean_name = self.alias_helper.get_wlst_mbean_type_and_name(config_location)
            self.wlst_helper.create(mbean_name, mbean_type)

        if len(security_configuration_nodes) > 0:
            self._create_mbean(SECURITY_CONFIGURATION, security_configuration_nodes, location, log_created=True)

        self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
        return
    def create_placeholder_named_elements(self, location, model_type, model_nodes):
        """
        Create a placeholder entry for each element in the specified named element nodes.
        This is necessary when there can be circular references with other elements.
        :param location: the location for the nodes to be added
        :param model_type: the type of the specified model nodes
        :param model_nodes: the model nodes
        :return: a list of names of created placeholders
        """
        _method_name = 'create_placeholder_named_elements'
        holder_names = []
        original_location = self.wlst_helper.get_pwd()
        resource_location = LocationContext(location).append_location(model_type)

        if self.aliases.get_wlst_mbean_type(resource_location) is not None:
            existing_names = deployer_utils.get_existing_object_list(resource_location, self.aliases)

            name_nodes = dictionary_utils.get_dictionary_element(model_nodes, model_type)
            for name in name_nodes.keys():
                if model_helper.is_delete_name(name):
                    # don't create placeholder for delete names
                    continue

                if name not in existing_names:
                    self.logger.info('WLSDPLY-19403', model_type, name, class_name=self.__class_name,
                                     method_name=_method_name)

                    token = self.aliases.get_name_token(resource_location)
                    resource_location.add_name_token(token, name)
                    deployer_utils.create_and_cd(resource_location, existing_names, self.aliases)
                    self._update_placeholder(model_type, name, resource_location)
                    holder_names.append(name)

        self.wlst_helper.cd(original_location)
        return holder_names
Example #6
0
    def _create_placeholder_jms_template(self, template_name,
                                         resource_location):
        """
        :param template_name: the name of the template to be added
        :param resource_location: the location where the template should be added
        """
        _method_name = '_create_placeholder_jms_template'
        original_location = self.wlst_helper.get_pwd()
        template_location = LocationContext(resource_location).append_location(
            TEMPLATE)
        existing_names = deployer_utils.get_existing_object_list(
            template_location, self.aliases)

        if template_name not in existing_names:
            self.logger.info('WLSDPLY-09500',
                             template_name,
                             class_name=self._class_name,
                             method_name=_method_name)

        template_token = self.aliases.get_name_token(template_location)
        template_location.add_name_token(template_token, template_name)
        result = deployer_utils.create_and_cd(template_location,
                                              existing_names, self.aliases)

        self.wlst_helper.cd(original_location)
        return result
    def _delete_mapped_mbean(self, folder_location, folder_token, mbean_type, name_attribute, name):
        """
        Delete the child MBean with an attribute value that matches the specified name.
        This requires looping through the child MBeans for each deletion, since the MBean names change on delete.
        :param folder_location: the WLST location for the folder with named sub-elements
        :param folder_token: the folder token used to iterate through the MBean names
        :param mbean_type: the MBean type of the sub-elements
        :param name_attribute: the attribute for the name in each sub-element
        :param name: the name of the sub-element to be deleted
        """
        _method_name = '_delete_mapped_mbean'

        original_path = self.wlst_helper.get_pwd()
        mapped_folder_name = None

        folder_names = deployer_utils.get_existing_object_list(folder_location, self.alias_helper)
        for folder_name in folder_names:
            folder_location.add_name_token(folder_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(folder_location))
            attribute_value = self.wlst_helper.get(name_attribute)
            if attribute_value == name:
                mapped_folder_name = folder_name
                break

        self.wlst_helper.cd(original_path)

        if mapped_folder_name is None:
            self.logger.warning('WLSDPLY-09109', mbean_type, name,
                                class_name=self._class_name, method_name=_method_name)
        else:
            self.logger.info('WLSDPLY-09110', mbean_type, name,
                             class_name=self._class_name, method_name=_method_name)
            self.wlst_helper.delete(mapped_folder_name, mbean_type)
    def create_placeholder_server_templates(self, topology):
        """
        Create a placeholder server template for each name in the topology.
        This is necessary because there is a circular dependency between clusters and server templates.
        :param topology: the topology model nodes
        """
        _method_name = 'create_placeholder_server_templates'
        original_location = self.wlst_helper.get_pwd()
        template_location = LocationContext().append_location(SERVER_TEMPLATE)

        if self.alias_helper.get_wlst_mbean_type(
                template_location) is not None:
            existing_names = deployer_utils.get_existing_object_list(
                template_location, self.alias_helper)

            template_nodes = dictionary_utils.get_dictionary_element(
                topology, SERVER_TEMPLATE)
            for template_name in template_nodes:
                if template_name not in existing_names:
                    self.logger.info('WLSDPLY-19400',
                                     template_name,
                                     class_name=self.__class_name,
                                     method_name=_method_name)

                    template_token = self.alias_helper.get_name_token(
                        template_location)
                    template_location.add_name_token(template_token,
                                                     template_name)
                    deployer_utils.create_and_cd(template_location,
                                                 existing_names,
                                                 self.alias_helper)

        self.wlst_helper.cd(original_location)
    def create_placeholder_jdbc_resources(self, resources):
        """
        Create a placeholder JDBC resource for each name in the resources section.
        This is necessary because cluster attributes may reference JDBC resources.
        :param resources: the resource model nodes
        """
        _method_name = 'create_placeholder_jdbc_resources'
        original_location = self.wlst_helper.get_pwd()
        resource_location = LocationContext().append_location(
            JDBC_SYSTEM_RESOURCE)

        if self.alias_helper.get_wlst_mbean_type(
                resource_location) is not None:
            existing_names = deployer_utils.get_existing_object_list(
                resource_location, self.alias_helper)

            jdbc_nodes = dictionary_utils.get_dictionary_element(
                resources, JDBC_SYSTEM_RESOURCE)
            for jdbc_name in jdbc_nodes:
                if jdbc_name not in existing_names:
                    self.logger.info('WLSDPLY-19401',
                                     jdbc_name,
                                     class_name=self.__class_name,
                                     method_name=_method_name)

                    jdbc_token = self.alias_helper.get_name_token(
                        resource_location)
                    resource_location.add_name_token(jdbc_token, jdbc_name)
                    deployer_utils.create_and_cd(resource_location,
                                                 existing_names,
                                                 self.alias_helper)

        self.wlst_helper.cd(original_location)
    def create_security_configuration(self, location):
        """
        Create the /SecurityConfiguration folder objects, if any.
        :param location: the location to use
        :raises: BundleAwareException of the specified type: if an error occurs
        """
        _method_name = '__create_security_configuration'

        self.logger.entering(str(location),
                             class_name=self.__class_name,
                             method_name=_method_name)
        security_configuration_nodes = dictionary_utils.get_dictionary_element(
            self._topology, SECURITY_CONFIGURATION)

        # in WLS 11g, the SecurityConfiguration mbean is not created until the domain is written.
        # if missing, we will create it to initialize realm and default security providers.
        config_location = LocationContext(location).append_location(
            SECURITY_CONFIGURATION)
        existing_names = deployer_utils.get_existing_object_list(
            config_location, self.alias_helper)
        if len(existing_names) == 0:
            mbean_type, mbean_name = self.alias_helper.get_wlst_mbean_type_and_name(
                config_location)
            self.wlst_helper.create(mbean_name, mbean_type)

        self.__handle_default_security_providers(location,
                                                 security_configuration_nodes)
        if len(security_configuration_nodes) > 0:
            self._create_mbean(SECURITY_CONFIGURATION,
                               security_configuration_nodes,
                               location,
                               log_created=True)
        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name)
        return
Example #11
0
    def _create_mbean(self, type_name, model_nodes, base_location, log_created=False):
        """
        Create the specified type of MBean that support a single instance in the specified location.
        :param type_name: the model folder type
        :param model_nodes: the model dictionary of the specified model folder type
        :param base_location: the base location object to use to create the MBean
        :param log_created: whether or not to log created at INFO level, by default it is logged at the FINE level
        :raises: CreateException: if an error occurs
        """
        _method_name = '_create_mbean'

        self.logger.entering(type_name, str(base_location), log_created,
                             class_name=self.__class_name, method_name=_method_name)
        if model_nodes is None or len(model_nodes) == 0 or not self._is_type_valid(base_location, type_name):
            return

        location = LocationContext(base_location).append_location(type_name)
        result, message = self.alias_helper.is_version_valid_location(location)
        if result == ValidationCodes.VERSION_INVALID:
            self.logger.warning('WLSDPLY-12123', message,
                                class_name=self.__class_name, method_name=_method_name)
            return

        create_path = self.alias_helper.get_wlst_create_path(location)
        existing_folder_names = self._get_existing_folders(create_path)

        mbean_type, mbean_name = self.alias_helper.get_wlst_mbean_type_and_name(location)

        token_name = self.alias_helper.get_name_token(location)
        if token_name is not None:
            if self.alias_helper.requires_unpredictable_single_name_handling(location):
                existing_subfolder_names = deployer_utils.get_existing_object_list(location, self.alias_helper)
                if len(existing_subfolder_names) > 0:
                    mbean_name = existing_subfolder_names[0]

            location.add_name_token(token_name, mbean_name)

        self._process_flattened_folder(location)
        if mbean_type not in existing_folder_names:
            if log_created:
                self.logger.info('WLSDPLY-12102', type_name, class_name=self.__class_name, method_name=_method_name)
            else:
                self.logger.fine('WLSDPLY-12102', type_name, class_name=self.__class_name, method_name=_method_name)

            self.wlst_helper.create_and_cd(self.alias_helper, mbean_type, mbean_name, location, create_path)
        else:
            if log_created:
                self.logger.info('WLSDPLY-20013', type_name, class_name=self.__class_name, method_name=_method_name)
            else:
                self.logger.fine('WLSDPLY-12102', type_name, class_name=self.__class_name, method_name=_method_name)

            attribute_path = self.alias_helper.get_wlst_attributes_path(location)
            self.wlst_helper.cd(attribute_path)

        self.logger.finest('WLSDPLY-12111', self.alias_helper.get_model_folder_path(location),
                           self.wlst_helper.get_pwd(), class_name=self.__class_name, method_name=_method_name)
        self._set_attributes(location, model_nodes)
        self._create_subfolders(location, model_nodes)
        self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
        return
Example #12
0
    def __get_default_realm_location(self):
        """
        Ensure that the default realm exists and get the location object for it.
        :return: the location object to use to work on the default realm while creating a domain.
        """
        location = LocationContext().append_location(SECURITY_CONFIGURATION)

        # SecurityConfiguration is special since the subfolder name does not change when
        # you change the domain name.  It only changes once the domain is written and re-read...
        token_name = self.alias_helper.get_name_token(location)
        if token_name is not None:
            existing_names = deployer_utils.get_existing_object_list(location, self.alias_helper)
            if len(existing_names) > 0:
                domain_name = existing_names[0]
                location.add_name_token(token_name, domain_name)

        wlst_create_path = self.alias_helper.get_wlst_create_path(location)
        self.wlst_helper.cd(wlst_create_path)
        existing_folder_names = self.wlst_helper.get_existing_object_list(wlst_create_path)

        wlst_type, wlst_name = self.alias_helper.get_wlst_mbean_type_and_name(location)
        wlst_attribute_path = self.alias_helper.get_wlst_attributes_path(location)
        if wlst_type not in existing_folder_names:
            self.wlst_helper.create_and_cd(self.alias_helper, wlst_type, wlst_name, location, wlst_create_path)
        else:
            self.wlst_helper.cd(wlst_attribute_path)

        existing_folder_names = self.wlst_helper.get_existing_object_list(wlst_attribute_path)
        location.append_location(REALM)
        wlst_type = self.alias_helper.get_wlst_mbean_type(location)
        token_name = self.alias_helper.get_name_token(location)

        default_security_realm_name = self.wls_helper.get_default_security_realm_name()
        if wlst_type not in existing_folder_names:
            if token_name is not None:
                location.add_name_token(token_name, default_security_realm_name)
            wlst_name = self.alias_helper.get_wlst_mbean_name(location)
            self.wlst_helper.create_and_cd(self.alias_helper, wlst_type, wlst_name, location)
        else:
            if token_name is not None:
                location.add_name_token(token_name, default_security_realm_name)
            wlst_attribute_path = self.alias_helper.get_wlst_attributes_path(location)
            self.wlst_helper.cd(wlst_attribute_path)
        return location, default_security_realm_name
    def remove_deleted_clusters_and_servers(self, domain_location, model_topology):
        """
        Remove clusters, servers, server templates, and migratable targets that were flagged for deletion
        in the model. The deletions are intentionally skipped when these elements are first created.
        :param domain_location: the location for the root of the domain
        :param model_topology: the topology folder from the model
        """
        _method_name = 'remove_deleted_clusters_and_servers'
        self.logger.entering(str(domain_location), class_name=self.__class_name, method_name=_method_name)

        for folder_name in [CLUSTER, SERVER_TEMPLATE, SERVER, MIGRATABLE_TARGET]:
            location = LocationContext(domain_location).append_location(folder_name)
            existing_names = deployer_utils.get_existing_object_list(location, self.aliases)
            folder_nodes = dictionary_utils.get_dictionary_element(model_topology, folder_name)

            for mbean_name in folder_nodes:
                if model_helper.is_delete_name(mbean_name):
                    deployer_utils.delete_named_element(location, mbean_name, existing_names, self.aliases)

        self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
    def _build_folder_map(self, folder_location, folder_token, name_attribute):
        """
        Build a map of existing sub-element names to folders.
        :param folder_location: the WLST location for the folder with named sub-elements
        :param folder_token: the folder token used to set the mbean name
        :param name_attribute: the attribute for the name in each sub-element
        :return: a map of existing sub-element names to folder names
        """
        original_path = self.wlst_helper.get_pwd()

        folder_names = deployer_utils.get_existing_object_list(folder_location, self.alias_helper)
        folder_map = OrderedDict()

        for folder_name in folder_names:
            folder_location.add_name_token(folder_token, folder_name)
            self.wlst_helper.cd(self.alias_helper.get_wlst_attributes_path(folder_location))
            name = self.wlst_helper.get(name_attribute)
            folder_map[name] = folder_name

        self.wlst_helper.cd(original_path)
        return folder_map