Show Table of Contents
B.2. Red Hat Enterprise Virtualization 用户界面插件的生命周期
B.2.1. Red Hat Enterprise Virtualization 用户界面插件的生命周期
一个用户界面插件的基本生命周期可以被分为 3 个阶段:
- 插件发现(plug-in discovery)。
- 插件加载(plug-in loading)。
- 插件引导(plug-in bootstrapping)。
B.2.2. Red Hat Enterprise Virtualization 用户界面插件的发现
创建插件的描述符(descriptor)是插件发现阶段的第一步。插件描述符包括了重要的插件元数据和默认的插件配置。
作为处理管理门户 HTML 页请求(
HTTP GET)的一部分,用户界面插件系统会尝试从您的本地系统上发现并加载插件描述符。 对于每一个插件描述符,系统会尝试使用相应的插件用户配置来覆盖插件的默认配置,并调整插件运行时的行为。插件的用户配置是可选的。在插件描述符和用户额配置被加载后,oVirt 引擎会把所有的用户界面插件的数据进行综合,并把它们加入到管理门户的 HTML 页中。
在默认的情况下,插件的描述符位于
$ENGINE_USR/ui-plug-ins 中,ENGINE_USR=/usr/share/ovirt-engine 是 oVirt 引擎本地配置的默认值。插件的描述符需要符合 JSON 格式的规则,但它同时也支持 Java/C++ 语言的注释风格(/* 和 //)。
在默认的情况下,插件的用户配置文件位于
$ENGINE_ETC/ui-plug-ins 中,ENGINE_ETC=/etc/ovirt-engine 是 oVirt 引擎本地配置的默认值。插件的用户配置文件的格式规则和插件描述符的格式规则相同。
注意
插件的用户配置文件通常使用
<descriptorFileName>-config.json 的命名规则。
B.2.3. Red Hat Enterprise Virtualization 用户界面插件加载
在一个插件被发现并被加入到管理门户的 HTML 页后,管理门户会把这个插件作为应用程序启动的一部分进行加载(除非您把它设置为不作为应用程序启动的一部分进行加载)。
当插件被发现后,管理门户会创建一个 HTML iframe 项来加载它的主页。插件的引导过程需要这个插件的主页(插件主页会在插件 iframe 项的环境中检查插件代码)。用户界面的插件系统支持本地文件系统提供的插件源文件(如插件的主页)。插件的主页被加载到 iframe 项中,它的代码会被检查。在代码检查完成后,插件使用插件 API 和管理门户进行交流。
B.2.4. Red Hat Enterprise Virtualization 用户界面插件引导
一个典型的插件引导过程包括以下步骤:
过程 B.1. 插件引导过程
- 为插件获得 pluginApi 项
- 获得运行时的插件配置项(可选)
- 注册相关的 event handler 函数
- 通知 UI 插件系统来处理插件的初始化
下面的一段代码显示以上步骤的实现:
// Access plug-in API using 'parent' due to this code being evaluated within the context of an iframe element.
// As 'parent.pluginApi' is subject to Same-Origin Policy, this will only work when WebAdmin HTML page and plug-in
// host page are served from same origin. WebAdmin HTML page and plug-in host page will always be on same origin
// when using UI plug-in infrastructure support to serve plug-in resource files.
var api = parent.pluginApi('MyPlugin');
// Runtime configuration object associated with the plug-in (or an empty object).
var config = api.configObject();
// Register event handler function(s) for later invocation by UI plug-in infrastructure.
api.register({
// UiInit event handler function.
UiInit: function() {
// Handle UiInit event.
window.alert('Favorite music band is ' + config.band);
}
});
// Notify UI plug-in infrastructure to proceed with plug-in initialization.
api.ready();
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.