Ejemplo n.º 1
0
        __release_edit_session_and_disconnect()
        raise ex

    model_deployer.deploy_applications(model,
                                       model_context,
                                       aliases,
                                       wlst_mode=__wlst_mode)

    try:
        __wlst_helper.disconnect()
    except BundleAwareException, ex:
        # All the changes are made and active so don't raise an error that causes the program
        # to indicate a failure...just log the error since the process is going to exit anyway.
        __logger.warning('WLSDPLY-09009',
                         _program_name,
                         ex.getLocalizedMessage(),
                         error=ex,
                         class_name=_class_name,
                         method_name=_method_name)
    return exit_code


def __deploy_offline(model, model_context, aliases):
    """
    Offline deployment orchestration
    :param model: the model
    :param model_context: the model context
    :param aliases: the aliases object
    :raises: DeployException: if an error occurs
    """
    _method_name = '__deploy_offline'
Ejemplo n.º 2
0
                     class_name=_class_name,
                     method_name=_method_name)
    injector_dictionary = dict()
    if os.path.isfile(injector_file_name):
        try:
            injector_dictionary = JsonToPython(injector_file_name).parse()
            __temporary_fix(injector_dictionary)
        except (IllegalArgumentException, JsonException), e:
            _logger.warning('WLDPLY-19409',
                            injector_file_name,
                            e.getLocalizedMessage(),
                            class_name=_class_name,
                            method_name=_method_name)
    else:
        _logger.warning('WLSDPLY-19510',
                        injector_file_name,
                        class_name=_class_name,
                        method_name=_method_name)

    _logger.exiting(class_name=_class_name, method_name=_method_name)
    return injector_dictionary


def _get_append_to_variable_file(**kwargs):
    if VARIABLE_FILE_APPEND_ARG in kwargs:
        return kwargs[VARIABLE_FILE_APPEND_ARG]
    return False


def _format_variable_value(value):
    if type(value) == bool:
        if value:
Ejemplo n.º 3
0
    exit_code = 0

    try:
        # First we enable the stdout again and then redirect the stdoout to a string output stream
        # call isRestartRequired to get the output, capture the string and then silence wlst output again
        #
        __wlst_helper.enable_stdout()
        sostream = StringOutputStream()
        System.setOut(PrintStream(sostream))
        restart_required = __wlst_helper.is_restart_required()
        is_restartreq_output = sostream.get_string()
        __wlst_helper.silence()
        if model_context.is_rollback_if_restart_required(
        ) and restart_required:
            __wlst_helper.cancel_edit()
            __logger.warning('WLSDPLY_09015', is_restartreq_output)
            exit_code = CommandLineArgUtil.PROG_ROLLBACK_IF_RESTART_EXIT_CODE
            deployer_utils.list_rollback_changes(model_context,
                                                 is_restartreq_output)
        else:
            __wlst_helper.save()
            __wlst_helper.activate(
                model_context.get_model_config().get_activate_timeout())
            if restart_required:
                exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED
                exit_code = deployer_utils.list_restarts(
                    model_context, exit_code)
    except BundleAwareException, ex:
        __release_edit_session_and_disconnect()
        raise ex
class OnlineGenerator(GeneratorHelper):
    """
    Generate MBean and attribute information into a dictionary from the online wlst session.
    The data is traversed using the registered mbean information for the online session.
    """

    def __init__(self, model_context, dictionary):
        GeneratorHelper.__init__(self,  model_context, dictionary)
        self.__class_name__ = self.__class__.__name__
        self._domain_home = None
        self.__logger = PlatformLogger('test.aliases.generate', resource_bundle_name='aliastest_rb')
        self.__logger.set_level(Level.FINER)

    def generate(self):
        """
        Generate the mbean dictionary for weblogic in wlst online mode.
        :return: the domain home of the connected session
        """
        _method_name = 'generate'
        self.__logger.entering(class_name=self.__class_name__, method_name=_method_name)
        if generator_wlst.connect(self._helper.admin_user(), self._helper.admin_password(), self._helper.admin_url()):
            try:
                self.__folder_hierarchy(self._dictionary, '/')
            finally:
                generator_wlst.disconnect()
        self.__logger.exiting(class_name=self.__class_name__, method_name=_method_name)
        return

    def __folder_hierarchy(self, mbean_dictionary, mbean_path):
        _method_name = '__folder_hierarchy'
        self.__logger.entering(mbean_path, class_name=self.__class_name__, method_name=_method_name)

        mbean_instance = generator_wlst.get_mbean_proxy(mbean_path)

        mbean_dictionary[all_utils.ATTRIBUTES] = self.__get_attributes(mbean_instance)

        mbean_map = self.__create_any_subfolders()

        info_helper = MBeanInfoHelper(mbean_instance, mbean_path)
        mbean_info_map = info_helper.get_child_mbeans()
        mbean_info_list = mbean_info_map.keys()

        mbi_helper = MBIHelper(mbean_instance, mbean_path)
        mbean_mbi_map = mbi_helper.get_child_mbeans()
        for mbean_type, attribute_helper in mbean_mbi_map.iteritems():
            mbean_name = None
            # mbean_type is the name of the child MBean attribute in the mbean Helper attribute list
            if mbean_type in mbean_map:
                mbean_name = mbean_map[mbean_type]
                del mbean_map[mbean_type]
            if mbean_type in mbean_info_list:
                mbean_info_list.remove(mbean_type)
                self.__logger.finest('Child MBean {0} is in both the MBI information and the MBeanInfo information',
                                   mbean_type, class_name=self.__class_name__, method_name=_method_name)
            else:
                self.__logger.fine('Child MBean {0} is in the MBI information but not the MBeanInfo information',
                                   mbean_type, class_name=self.__class_name__, method_name=_method_name)

            if attribute_helper.is_reference_only():
                mbean_dictionary[mbean_type] = all_utils.dict_obj()
                # This non-attribute might have been added as a folder, which it is not
                mbean_dictionary[mbean_type][all_utils.ONLINE_REFERENCE_ONLY] = all_utils.TRUE
                continue

            if self._is_valid_folder(attribute_helper):
                self.__logger.fine('WLSDPLYST-01115', mbean_type, generator_wlst.current_path(),
                                   class_name=self.__class_name__, method_name=_method_name)
                mbean_dictionary[mbean_type] = all_utils.dict_obj()
                attribute_helper.generate_mbean(mbean_dictionary[mbean_type])
                if mbean_name is None:
                    mbean_name = generator_wlst.get_singleton_name(mbean_type)
                if mbean_name is not None:
                    if mbean_type in generator_wlst.child_mbean_types():
                        mbean_dictionary[mbean_type][all_utils.INSTANCE_TYPE] = all_utils.MULTIPLE
                    else:
                        mbean_dictionary[mbean_type][all_utils.INSTANCE_TYPE] = all_utils.SINGLE
                    bean_dir = mbean_type + '/' + mbean_name
                    if not generator_wlst.cd_mbean(bean_dir):
                        self.__logger.fine('WLSDPLYST-01117', mbean_type, generator_wlst.current_path(), '',
                                           class_name=self.__class_name__, method_name=_method_name)
                        mbean_dictionary[mbean_type][all_utils.RECHECK] = \
                            'cd to mbean and mbean name returned exception'
                        continue

                    self.__folder_hierarchy(mbean_dictionary[mbean_type], generator_wlst.current_path())
                    generator_wlst.cd_mbean('../..')
            else:
                # make this a real message
                self.__logger.warning('Ignore invalid MBean folder {0} containment : {1}, deprecated : {2}',
                                      mbean_type, all_utils.str_bool(attribute_helper.is_containment()),
                                      all_utils.str_bool(attribute_helper.is_deprecated()),
                                      class_name=self.__class_name__, method_name=_method_name)

        if len(mbean_map) > 0:
            mbeans_only = [leftover for leftover in mbean_map if leftover not in mbi_helper.get_all_attributes()]
            if len(mbeans_only) > 0:
                for mbean_type in mbeans_only:
                    # If it is in the attribute list, its a reference
                    if mbi_helper.get_all_attribute(mbean_type).is_attribute_found() is False:
                        self.__logger.fine('MBean {0} was not found in the MBI map but is in the LSC map',
                                           mbean_type, class_name=self.__class_name__, method_name=_method_name)
                        info_attribute_helper = info_helper.get_child_mbean(mbean_type)
                        if info_attribute_helper.is_attribute_found():
                            self.__logger.fine('Child MBean {0} is in the MBeanInfo information but not'
                                               ' the MBI information',
                                               class_name=self.__class_name__, method_name=_method_name)
                        mbean_name = mbean_map[mbean_type]
                        if mbean_name is not None:
                            bean_dir = mbean_type + '/' + mbean_name
                            mbean_dictionary[mbean_type] = all_utils.dict_obj()
                            if generator_wlst.cd_mbean(bean_dir) is False:
                                self.__logger.fine('WLSDPLYST-01117', mbean_type, generator_wlst.current_path(), '',
                                                   class_name=self.__class_name__, method_name=_method_name)
                                mbean_dictionary[mbean_type][all_utils.RECHECK] = \
                                    'cd to mbean and mbean name returned exception'
                                continue

                            self.__folder_hierarchy(mbean_dictionary[mbean_type], generator_wlst.current_path())
                            generator_wlst.cd_mbean('../..')
        self.__logger.exiting(class_name=self.__class_name__, method_name=_method_name)
        return

    def __get_attributes(self, mbean_instance):
        _method_name = '__get_attributes'
        mbean_path = generator_wlst.current_path()
        self.__logger.entering(mbean_instance, mbean_path, class_name=self.__class_name__, method_name=_method_name)
        lsa_map = generator_wlst.lsa_map_modified()
        not_found_mbean_list = list()
        if len(lsa_map) > 0:
            not_found_mbean_list = lsa_map.keys()
            not_found_mbean_list.sort()

        mbean_instance = generator_wlst.get_mbean_proxy(mbean_path)
        operation_list = generator_wlst.ls_operations()
        info_helper = MBeanInfoHelper(mbean_instance, mbean_path)
        mbean_type = info_helper.get_mbean_type()
        mbean_info_map = info_helper.get_attributes()
        mbean_info_list = mbean_info_map.keys()
        self.__logger.finest('MBean {0} LSA map attributes are {1} at location {2} mbean_path',
                             mbean_type, not_found_mbean_list, mbean_path,
                             class_name=self.__class_name__, method_name=_method_name)

        method_helper = MBeanMethodHelper(mbean_instance, mbean_path)
        method_map = method_helper.get_attributes()

        # The main driver must have all attributes in the map
        mbi_helper = MBIHelper(mbean_instance, mbean_path)
        mbean_mbi_map = mbi_helper.get_all_attributes()

        attributes = all_utils.dict_obj()
        for attribute, attribute_helper in mbean_mbi_map.iteritems():
            self.__logger.finer('Processing MBean {0} attribute {1} from MBI map', mbean_type, attribute,
                                class_name=self.__class_name__, method_name=_method_name)
            info_attribute_helper = None
            if attribute in mbean_info_list:
                info_attribute_helper = mbean_info_map[attribute]
                mbean_info_list.remove(attribute)

            method_helper = None
            if attribute in method_map:
                method_helper = method_map[attribute]

            if attribute not in lsa_map:
                if self._is_valid_cmo_attribute(attribute_helper, info_attribute_helper):
                    self.__logger.fine('Adding MBean {0} attribute {1} from location {2} '
                                       'that is in MBI map and not in LSA map', mbean_type, attribute, mbean_path,
                                       class_name=self.__class_name__, method_name=_method_name)
                    holder = all_utils.dict_obj()
                    self.add_default_value(holder, lsa_map, attribute_helper, method_helper)
                    attribute_helper.generate_attribute(holder)
                    attributes[attribute] = all_utils.sort_dict(holder)
            else:
                not_found_mbean_list.remove(attribute)
                if self._is_valid_attribute(attribute, attribute_helper, info_attribute_helper):
                    self.__logger.finer('Adding MBean {0} attribute {1} from location {2} which is in LSA and MBI maps',
                                        mbean_type, attribute, mbean_path,
                                        class_name=self.__class_name__, method_name=_method_name)
                    holder = all_utils.dict_obj()
                    self.add_default_value(holder, lsa_map, attribute_helper, method_helper)
                    attribute_helper.generate_attribute(holder)
                    attributes[attribute] = all_utils.sort_dict(holder)

        for attribute in mbean_info_list:
            self.__logger.finer('Processing MBean {0} attribute {1} from MBeanInfo map',
                                mbean_type, attribute,
                                class_name=self.__class_name__, method_name=_method_name)
            if attribute in not_found_mbean_list:
                not_found_mbean_list.remove(attribute)
            attribute_helper = mbean_info_map[attribute]
            method_helper = None
            if attribute in method_map:
                method_helper = method_map[attribute]
            if self._is_valid_cmo_attribute(attribute_helper, method_helper):
                self.__logger.fine('Adding MBean {0} attribute {1} found in MBeanInfo but not MBI',
                                   mbean_type, attribute,
                                   class_name=self.__class_name__, method_name=_method_name)
                holder = all_utils.dict_obj()
                self.add_default_value(holder, lsa_map, attribute_helper, method_helper)
                attribute_helper.generate_attribute(holder)
                attributes[attribute] = all_utils.sort_dict(holder)

        for lsa_only in not_found_mbean_list:
            self.__logger.finer('Processing MBean {0} attribute {1} from LSA map', mbean_type, lsa_only,
                                class_name=self.__class_name__, method_name=_method_name)
            if lsa_only in operation_list:
                continue

            method_helper = None
            if lsa_only in method_map:
                method_helper = method_map[lsa_only]

            if lsa_only in mbean_info_map:
                attribute_helper = mbean_info_map[lsa_only]
                mbean_info_list.remove(lsa_only)
            elif method_helper is not None:
                attribute_helper = method_helper
            else:
                # Fake one up
                attribute_helper = mbi_helper.get_attribute(lsa_only)
            if self._is_valid_lsa(attribute_helper):
                self.__logger.fine('MBean {0} attribute {1} that is in LSA and not MBI is found in the MBeanInfo : {2}',
                                   mbean_type, lsa_only, Boolean(info_helper.get_attribute(lsa_only) is not None),
                                   class_name=self.__class_name__, method_name=_method_name)
                holder = all_utils.dict_obj()
                # Not all LSA with -rw- really are -rw-. Might need to add in a physical attempt to set
                # if to find attributes without a set method that CAN be set in offline.
                # However, I suspect that if no set method, then cannot RW
                self.add_default_value(holder, lsa_map, attribute_helper, method_helper)
                if attribute_helper.is_attribute_found():
                    self.__logger.finer('MBean {0} attribute {1} in LSA map will generate attribute info '
                                        'from additional helper', mbean_type, lsa_only,
                                        class_name=self.__class_name__, method_name=_method_name)
                    attribute_helper.generate_attribute(holder)
                else:
                    self.__logger.fine('MBean {0} attribute {1} is found only in the LSA map', mbean_type, lsa_only,
                                       class_name=self.__class_name__, method_name=_method_name)
                attributes[lsa_only] = all_utils.sort_dict(holder)

        self.__logger.exiting(class_name=self.__class_name__, method_name=_method_name)
        return all_utils.sort_dict(attributes)

    def __create_any_subfolders(self):
        _method_name = 'create_any_subfolders'
        subfolder_list = all_utils.dict_obj()
        operation_map = generator_wlst.ls_operations()
        # create_by_operation_list = HashSet(operation_map.keySet())
        # for operation in operation_map.keySet():
        #     if operation.startswith(CREATE) and not operation.endswith('FromBuiltin'):
        #         mbean_type = operation[len(CREATE):]
        #         name1, name2 = helper.mbean_name(mbean_type)
        #         if not do_operation(name1, operation) and not do_operation(name2, operation):
        #             create_by_operation_list.remove(operation)

        checklist = generator_wlst.lsc_modified()
        if checklist is None:
            self.__logger.fine('WLSDPLYST-01320', generator_wlst.current_path(), '',
                               class_name=self.__class_name__, method_name=_method_name)
            return subfolder_list

        for check in checklist:
            if check not in operation_map:
                name_list = generator_wlst.ls_mbean_names(check)
                if name_list is None:
                    self.__logger.finer('WLSDPLYST-01121', check, '',
                                       class_name=self.__class_name__, method_name=_method_name)
                    continue
                    # if empty, it returns a str

                if name_list and len(str(name_list).strip()) > 0:
                    subfolder_list[check] = name_list[0]

        child_types = generator_wlst.child_mbean_types()
        if child_types is not None:
            for child_type in child_types:
                if child_type not in subfolder_list:
                    name1, name2 = all_utils.mbean_name(child_type)
                    if generator_wlst.created(child_type, name1) or generator_wlst.created(child_type, name2):
                        name_list = generator_wlst.ls_mbean_names(child_type)
                        if name_list is not None and len(str(name_list).strip()) > 0:
                            subfolder_list[child_type] = name_list[0]

        return subfolder_list
    online_wlst_exception = _load_global('WLSTException')
    local_ls = _load_global('ls')
    try:
        name_list = local_ls(mbean_type, returnMap='true')
    except (offlineWLSTException, online_wlst_exception), we:
        __logger.warning('Unable to ls({0}) at location {1} : {2}',
                         mbean_type,
                         current_path(),
                         str(we),
                         class_name=__class_name,
                         method_name=_method_name)
        return None
    if len(name_list) == 0:
        __logger.warning(
            'No MBean instance found for {0} at location {1} and was not in listChildTypes',
            mbean_type,
            current_path(),
            class_name=__class_name,
            method_name=_method_name)
        return None
    if len(name_list) > 1:
        __logger.warning(
            'Singleton MBean {0} has more than one instance at location {1}',
            mbean_type,
            current_path(),
            class_name=__class_name,
            method_name=_method_name)
    return name_list[0]


def read_domain(domain_home):
    """