def _validate_update_mode(self, roles_map, validation_result):
        """
        Check that the UpdateMode value of a role is one of append, prepend or replace
        Provide a warning for other values as these will be treated as the default of replace
        """
        _method_name = '_validate_update_mode'
        self.logger.entering(class_name=self.__class_name,
                             method_name=_method_name)

        for role_name in roles_map.keys():
            role_map = roles_map[role_name]
            if UPDATE_MODE in role_map:
                mode = role_map[UPDATE_MODE]
                if not string_utils.is_empty(mode):
                    mode = mode.lower()
                    if APPEND == mode or PREPEND == mode or REPLACE == mode:
                        continue
                    self.logger.finer('WLSDPLY-12503',
                                      role_name,
                                      class_name=self.__class_name,
                                      method_name=_method_name)
                    if validation_result is not None:
                        validation_result.add_warning('WLSDPLY-12503',
                                                      role_name)

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name)
        return
Esempio n. 2
0
    def tokenize_path(self, path):
        """
        Replace known directories that will be different in the target with tokens denoting the type
        of directory

        :param path: to check for directories to be tokenized
        :return: tokenized path or original path
        """
        my_path = path_utils.fixup_path(path)
        wl_home = path_utils.fixup_path(self.get_wl_home())
        domain_home = path_utils.fixup_path(self.get_domain_home())
        oracle_home = path_utils.fixup_path(self.get_oracle_home())
        java_home = path_utils.fixup_path(self.get_java_home())
        tmp_dir = path_utils.fixup_path(tempfile.gettempdir())
        cwd = path_utils.fixup_path(os.path.dirname(os.path.abspath(__file__)))

        # decide later what is required to be in context home for appropriate exception prevention
        result = my_path
        if not string_utils.is_empty(my_path):
            if wl_home is not None and my_path.startswith(wl_home):
                result = my_path.replace(wl_home, self.__WL_HOME_TOKEN)
            elif domain_home is not None and my_path.startswith(domain_home):
                result = my_path.replace(domain_home, self.__DOMAIN_HOME_TOKEN)
            elif oracle_home is not None and my_path.startswith(oracle_home):
                result = my_path.replace(oracle_home, self.__ORACLE_HOME_TOKEN)
            elif java_home is not None and my_path.startswith(java_home):
                result = my_path.replace(java_home, self.__JAVA_HOME_TOKEN)
            elif my_path.startswith(cwd):
                result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
            elif my_path.startswith(tmp_dir):
                result = my_path.replace(tmp_dir, self.__TEMP_DIRECTORY_TOKEN)

        return result
    def _add_keystore_file_to_archive(self, model_name, model_value, location):
        """
        Add the custom trust or identity keystore file to the archive.
        :param model_name: attribute name in the model
        :param model_value: converted model value for the attribute
        :param location: context containing the current location information
        :return: modified location and name for the model keystore file
        """
        _method_name = '_add_keystore_file_to_archive'
        _logger.entering(model_name,
                         str(location),
                         class_name=_class_name,
                         method_name=_method_name)
        new_name = None
        if not string_utils.is_empty(model_value):
            server_name = self._get_server_name_from_location(location)
            archive_file = self._model_context.get_archive_file()
            file_path = self._convert_path(model_value)
            if server_name:
                new_name = self._add_server_keystore_file_to_archive(
                    server_name, archive_file, file_path)
            else:
                new_name = self._add_node_manager_keystore_file_to_archive(
                    archive_file, file_path)

        _logger.exiting(class_name=_class_name,
                        method_name=_method_name,
                        result=new_name)
        return new_name
Esempio n. 4
0
    def _process_roles_map(self, roles_map):
        """
        Loop through the WebLogic roles listed in the domainInfo and create a map of the role to the expression 
        """
        _method_name = '_process_roles_map'
        self.logger.entering(class_name=self.__class_name,
                             method_name=_method_name)
        result = {}
        for role in roles_map.keys():
            # Get the role expression and if the role should be an update to the default set of roles
            expression = self._get_role_expression(role, roles_map)
            if string_utils.is_empty(expression):
                self.logger.warning('WLSDPLY-12501',
                                    role,
                                    class_name=self.__class_name,
                                    method_name=_method_name)
                continue
            update_role = self._is_role_update_mode(role, roles_map)
            if update_role and role not in WLS_GLOBAL_ROLES:
                self.logger.warning('WLSDPLY-12502',
                                    role,
                                    class_name=self.__class_name,
                                    method_name=_method_name)
                update_role = False
            # Add the role and expression to the map of roles to be processed
            if update_role:
                expression = self._update_role_epression(
                    role, expression, roles_map)
            result[role] = expression

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name)
        return result
    def _get_clusters_and_members_map(self):
        """
        Get a map keyed by cluster name with values that are a list of member server names
        :return: the cluster name to member server names map
        :raises: BundleAwareException of the specified type: is an error occurs reading from the aliases or WLST
        """
        _method_name = '_get_clusters_and_members_map'

        self.logger.entering(class_name=self.__class_name,
                             method_name=_method_name)
        server_location = LocationContext().append_location(SERVER)
        server_list_path = self.aliases.get_wlst_list_path(server_location)
        server_names = self.wlst_helper.get_existing_object_list(
            server_list_path)
        server_token = self.aliases.get_name_token(server_location)
        cluster_map = OrderedDict()
        for server_name in server_names:
            server_location.add_name_token(server_token, server_name)
            server_attributes_path = self.aliases.get_wlst_attributes_path(
                server_location)
            self.wlst_helper.cd(server_attributes_path)

            server_attributes_map = self.wlst_helper.lsa()
            cluster_name = dictionary_utils.get_element(
                server_attributes_map, CLUSTER)
            if string_utils.is_empty(cluster_name):
                # if server is not part of a cluster, continue with the next server
                continue

            if cluster_name not in cluster_map:
                cluster_map[cluster_name] = list()
            cluster_map[cluster_name].append(server_name)

        clusters_location = LocationContext().append_location(CLUSTER)
        cluster_list_path = self.aliases.get_wlst_list_path(clusters_location)
        cluster_names = self.wlst_helper.get_existing_object_list(
            cluster_list_path)
        cluster_token = self.aliases.get_name_token(clusters_location)
        # Add the cluster with dynamic servers, if not already in the cluster member list.
        # A cluster may contain both dynamic and configured servers (referred to as mixed cluster).
        # Add a token marking DYNAMIC SERVERS in the member list.
        for cluster_name in cluster_names:
            cluster_location = LocationContext(clusters_location)
            cluster_location.add_name_token(cluster_token, cluster_name)
            cluster_attributes_path = self.aliases.get_wlst_attributes_path(
                cluster_location)
            self.wlst_helper.cd(cluster_attributes_path)
            cluster_location.append_location(DYNAMIC_SERVERS)
            wlst_subfolder_name = self.aliases.get_wlst_mbean_type(
                cluster_location)
            if self.wlst_helper.subfolder_exists(wlst_subfolder_name):
                if cluster_name not in cluster_map:
                    cluster_map[cluster_name] = list()
                cluster_map[cluster_name].append(DYNAMIC_SERVERS)

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name,
                            result=cluster_map)
        return cluster_map
    def get_library_versioned_name(self, source_path, model_name, from_archive=False):
        """
        Get the proper name of the deployable library that WLST requires in the target domain.  This method is
        primarily needed for shared libraries in the Oracle Home where the implementation version may have
        changed.  Rather than requiring the modeller to have to know/adjust the shared library name, we extract
        the information from the target domain's archive file (e.g., war file) and compute the correct name.
        :param source_path: the SourcePath value of the shared library
        :param model_name: the model name of the library
        :param from_archive: if True, use the manifest from the archive, otherwise from the file system
        :return: the updated shared library name for the target environment
        :raises: DeployException: if an error occurs
        """
        _method_name = 'get_library_versioned_name'

        self.logger.entering(source_path, model_name, class_name=self._class_name, method_name=_method_name)

        old_name_tuple = deployer_utils.get_library_name_components(model_name)
        try:
            versioned_name = old_name_tuple[self._EXTENSION_INDEX]
            manifest = self.__get_manifest(source_path, from_archive)
            if manifest is not None:
                attributes = manifest.getMainAttributes()

                extension_name = attributes.getValue(EXTENSION_NAME)
                if not string_utils.is_empty(extension_name):
                    versioned_name = extension_name

                specification_version = attributes.getValue(SPECIFICATION_VERSION)
                if not string_utils.is_empty(specification_version):
                    versioned_name += '#' + specification_version

                    # Cannot specify an impl version without a spec version
                    implementation_version = attributes.getValue(IMPLEMENTATION_VERSION)
                    if not string_utils.is_empty(implementation_version):
                        versioned_name += '@' + implementation_version

                self.logger.info('WLSDPLY-09324', model_name, versioned_name,
                                 class_name=self._class_name, method_name=_method_name)

        except (IOException, FileNotFoundException, ZipException, IllegalStateException), e:
            ex = exception_helper.create_deploy_exception('WLSDPLY-09325', model_name, source_path, str(e), error=e)
            self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
            raise ex
 def _is_role_update_mode(self, role_name, roles_map):
     """
     Determine if the role update mode indicates that a role update is specified
     :return: True if the update mode value is present and set to append or prepend mode
     """
     result = False
     role_map = roles_map[role_name]
     if UPDATE_MODE in role_map:
         mode = role_map[UPDATE_MODE]
         if not string_utils.is_empty(mode):
             mode = mode.lower()
             if APPEND == mode or PREPEND == mode:
                 result = True
     return result
    def __get_manifest(self, source_path, from_archive):
        """
        Returns the manifest object for the specified path.
        The source path may be a jar, or an exploded path.
        :param source_path: the source path to be checked
        :param from_archive: if True, use the manifest from the archive, otherwise from the file system
        :return: the manifest, or None if it is not present
        :raises: IOException: if there are problems reading an existing manifest
        """
        manifest = None
        if string_utils.is_empty(source_path):
            return manifest

        source_path = self.model_context.replace_token_string(source_path)

        if from_archive and deployer_utils.is_path_into_archive(source_path):
            return self.archive_helper.get_manifest(source_path)

        else:
            if not os.path.isabs(source_path):
                # if this was in archive, it has been expanded under domain home.
                # or it may be a relative file intentionally placed under domain home.
                source_file = File(File(self.model_context.get_domain_home()), source_path)
            else:
                source_file = File(source_path)

            if source_file.isDirectory():
                # read the manifest directly from the file system
                manifest_file = File(source_file, MANIFEST_NAME)
                if manifest_file.exists():
                    stream = None
                    try:
                        stream = FileInputStream(manifest_file)
                        manifest = Manifest(stream)
                    finally:
                        if stream is not None:
                            try:
                                stream.close()
                            except IOException:
                                # nothing to report
                                pass
            else:
                # read the manifest from the deployable ear/jar/war on the file system
                archive = JarFile(source_file.getAbsolutePath())
                manifest = archive.getManifest()

        return manifest
 def _update_role_epression(self, role_name, expression_value, roles_map):
     """
     Lookup the default role definition and logically OR the expression
     Based on the update mode the expression is appended or prepended
     :return: the updated role expression
     """
     result = expression_value
     role_map = roles_map[role_name]
     if UPDATE_MODE in role_map:
         mode = role_map[UPDATE_MODE]
         if not string_utils.is_empty(mode):
             mode = mode.lower()
             if APPEND == mode:
                 result = WLS_GLOBAL_ROLES[
                     role_name] + WLS_ROLE_UPDATE_OPERAND + expression_value
             elif PREPEND == mode:
                 result = expression_value + WLS_ROLE_UPDATE_OPERAND + WLS_GLOBAL_ROLES[
                     role_name]
     return result
Esempio n. 10
0
 def _add_keystore_file_to_archive(self, model_name, model_value, location):
     """
     Add the Server custom trust or identity keystore file to the archive.
     :param model_name: attribute name in the model
     :param model_value: converted model value for the attribute
     :param location: context containing the current location information
     :return: modified location and name for the model keystore file
     """
     _method_name = '_add_keystore_file_to_archive'
     _logger.entering(model_name,
                      str(location),
                      class_name=_class_name,
                      method_name=_method_name)
     new_name = None
     if not string_utils.is_empty(model_value):
         server_name = self._get_server_name_from_location(location)
         archive_file = self._model_context.get_archive_file()
         file_path = self._convert_path(model_value)
         _logger.finer('WLSDPLY-06623',
                       file_path,
                       server_name,
                       class_name=_class_name,
                       method_name=_method_name)
         try:
             new_name = archive_file.addServerKeyStoreFile(
                 server_name, File(file_path))
         except IllegalArgumentException, iae:
             _logger.warning('WLSDPLY-06624',
                             server_name,
                             file_path,
                             iae.getLocalizedMessage(),
                             class_name=_class_name,
                             method_name=_method_name)
         except WLSDeployArchiveIOException, wioe:
             de = exception_helper.create_discover_exception(
                 'WLSDPLY-06625', server_name, file_path,
                 wioe.getLocalizedMessage())
             _logger.throwing(class_name=_class_name,
                              method_name=_method_name,
                              error=de)
             raise de
Esempio n. 11
0
    def _get_clusters_and_members_map(self):
        """
        Get a map keyed by cluster name with values that are a list of member server names
        :return: the cluster name to member server names map
        :raises: BundleAwareException of the specified type: is an error occurs reading from the aliases or WLST
        """
        _method_name = '_get_clusters_and_members_map'

        self.logger.entering(class_name=self.__class_name,
                             method_name=_method_name)
        server_location = LocationContext().append_location(SERVER)
        server_list_path = self.alias_helper.get_wlst_list_path(
            server_location)
        server_names = self.wlst_helper.get_existing_object_list(
            server_list_path)
        server_token = self.alias_helper.get_name_token(server_location)
        cluster_map = OrderedDict()
        for server_name in server_names:
            server_location.add_name_token(server_token, server_name)
            server_attributes_path = self.alias_helper.get_wlst_attributes_path(
                server_location)
            self.wlst_helper.cd(server_attributes_path)

            server_attributes_map = self.wlst_helper.lsa()
            cluster_name = dictionary_utils.get_element(
                server_attributes_map, CLUSTER)
            if string_utils.is_empty(cluster_name):
                # if server is not part of a cluster, continue with the next server
                continue

            if cluster_name not in cluster_map:
                cluster_map[cluster_name] = list()
            cluster_map[cluster_name].append(server_name)

        self.logger.exiting(class_name=self.__class_name,
                            method_name=_method_name,
                            result=cluster_map)
        return cluster_map