歡迎您光臨本站 註冊首頁

高效構建 CIM 事件模型

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  
在公共信息模型(Common Information Model,CIM)中,客戶機應用程序可以訂閱 CIM 事件通知。通常,應用程序可以通過不同的連接埠用多個事件處理程序創建事件過濾器,但是這將消耗大量網路資源並增加維護複雜度。在本文中,查看如何用一個特定連接埠註冊多個 CIM 事件處理程序。另請查看如何用 SBLIM CIM 客戶機庫編寫代碼的一些提示。

讓我們首先來查看一些關鍵詞。分散式管理任務工作組(Distributed Management Task Force,DMTF)公共信息模型(Common Information Model,CIM)是描述企業環境和 Internet 環境中的計算實體和業務實體的概念信息模型。它將提供一致的使用面向對象技術的數據定義和結構。

CIM 事件 是一種有趣的現象,可以按照生命周期 或警告 分類。CIM 事件十分複雜並且涉及到範圍廣泛的主題和場景。在 CIM 架構中,客戶機應用程序可以訂閱 CIM 事件的通知。通常,應用程序可以通過多個連接埠用相關事件處理程序創建事件過濾器。

在本文中,我們將展示如何用一個特定的連接埠註冊 CIM 事件處理程序以避免增加複雜度。這將使您可以更輕鬆地用最少的網路資源實現和維護一個具體的、可操作的 CIM 事件模型。

CIM 事件模型概覽

CIM 事件模型將定義與事件相關的抽象。它將描述 CIM 表示層次結構及如何將表示用於模型事件。事件模型還將描述如何使用訂閱進行註冊,以便您可以接收表示。

表示可以有零個或多個事件觸發器,這些觸發器可以識別狀態更改。例如,如果由於卷創建而觸動觸發器,此事件將得到一個卷創建的生命周期表示。另舉一例,如果由於拔出磁碟而觸動觸發器,此事件將得到磁碟已拔出的警告表示。

基於 HTTP 的 CIM 操作規範(有關鏈接,請參閱 參考資料)將描述發送和接收 CIM 表示的 CIM-XML 標準。圖 1 中顯示了 CIM 事件模型的全部工作流程:


圖 1. CIM 事件模型的工作流程

整個操作流程包括以下步驟:

  • CIM 客戶機將發出 CIM 伺服器過程請求,該請求將創建基於網路的訂閱;過程的主要函數將註冊以接收表示。
  • CIM Object Manager(CIMOM)將接收請求並檢查其驗證。隨後,CIMOM 將在 CIMOM Repository 中創建 CIM 表示過濾器、CIM 表示處理程序和 CIM 表示訂閱。
  • CIMOM 將聯繫 CIM Indication Provider,請求提供程序響應 CIMOM 所發出的請求來生成適當的表示。
  • 當提供程序生成表示時,CIMOM 將把表示路由到 CIM 表示處理程序實例所指定的 CIM Indication Listener 中。這些實例是由 CIMOM Repository 中的訂閱者創建的。

從技術上講,當客戶註冊以接收 CIM 事件模型中的表示時,需要創建三類 CIM 實例:

  1. CIM Indication Filter:CIM_IndicationFilter 實例,用於定義表示使用者感興趣的表示集合。
  2. CIM Indication Handler:CIM_ListenerDestination 實例,用於描述表示使用者的位置、編碼和傳輸協議。
  3. CIM Indication Subscription:CIM_IndicationSubscription 實例,用於描述表示流程。該流程是由引用的表示過濾器指定並且定向到引用目標或在表示處理程序中處理。

CIM 表示類層次結構用於描述在正確定義了表示訂閱后可以檢測到的事件類型。CIM_Indication 實例表示事件的出現。通常,表示是生命周期非常短暫的對象,用於從表示生成器到零個或多個表示使用者之間傳遞信息。下面是 CIM 事件模型中定義的相關 CIM 表示類:

  • Root 類
    • CIM_Indication
  • 超類
    • CIM_ClassIndication
    • CIM_InstIndication
    • CIM_ProcessIndication
  • 子類
    • CIM_ClassCreation
    • CIM_ClassDeletion
    • CIM_ClassModification
    • CIM_InstCreation
    • CIM_InstDeletion
    • CIM_InstMethodCall
    • CIM_InstModification
    • CIM_InstRead
    • CIM_AlertIndication
    • CIM_J2eeNotification
    • CIM_SNMPTrapIndication

當您在 CIM 事件模型中註冊 CIM 事件處理程序時可以使用所有類,這取決於具體要求。我們將在下面的小節中給您提供一些代碼示例並且在最後提供實驗結果。





創建事件過濾器

事件過濾器將描述要交付的事件類型及交付條件。要創建事件過濾器,需要創建 CIM_IndicationFilter 類的實例並定義其屬性值。可以設置這些屬性以惟一識別過濾器、指定查詢字元串和指定解析查詢字元串的查詢語言。注意,屬性是不是強制屬性取決於目標 CIM 伺服器中的 CIM 提供程序的實現;不同的 CIM 提供程序之間的字元串屬性格式會略有不同。

清單 1 顯示了用 SBLIM CIM 客戶機庫創建事件過濾器的示例:


清單 1. 創建事件過濾器的樣例代碼
// Define the name of CIM class to be created    String   filterClassName = "CIM_IndicationFilter";    // Define the filter string for CIM_IndicationFilter instance    String   filterString = "SELECT * FROM CIM_InstCreation WHERE SourceInstance   ISA CIM_StorageVolume";    // Get the CIM class definition from the CIMOM    CIMClass filterClass = _client.getClass(new CIMObjectPath(filterClassName));    // Create an instance of the CIM_IndicationFilter class    CIMInstance filterInstance = filterClass.newInstance();    // Set the name of the filter    filterInstance.setProperty("Name",                              new CIMValue("PCL_Event",                              new CIMDataType(CIMDataType.STRING)));    // Set the filter string to select CIM events    filterInstance.setProperty("Query",                              new CIMValue(filterString,                              new CIMDataType(CIMDataType.STRING)));    // Set the query language (WQL) to parse the query string    filterInstance.setProperty("QueryLanguage",                              new CIMValue("WQL",                              new CIMDataType(CIMDataType.STRING)));    // Set the source name space of the filter    filterInstance.setProperty("SourceNamespace",                              new CIMValue(_namespace,                              new CIMDataType(CIMDataType.STRING)));    // Create an instance of CIM_IndicationFilter on the target CIM server    CIMObjectPath filterCOP = _client.createInstance(new CIMObjectPath(),                                                   filterInstance);  





用一個連接埠創建事件處理程序

通常,應用程序可以通過多個連接埠用事件處理程序創建事件偵聽程序,但是這在網路資源和維護方面花費較大。

通過使用兩個類 —SBLIM CIM Client Library 中定義的 CIMEventDispatcher 和 HttpServerConnection — 可以用一個特定的連接埠註冊 CIM 事件處理程序。圖 2 中顯示了整個過程。


圖 2. 用一個連接埠將事件分發給事件處理程序

下面是用同一個埠創建事件處理程序的兩個步驟:

  1. 在客戶端註冊偵聽程序。
  2. 在提供程序端用目標信息創建偵聽程序實例。

清單 2 和 3 顯示了創建方法:


清單 2. 在客戶端註冊偵聽程序
// Create a CIMIndicationListenertList instance    CIMIndicationListenertList _indicationClient =   new CIMIndicationListenertList();            /*   * Add a inner listener to the list, because if there is only one listener in  * CIMIndicationListenertList, it will get all event no matter the event is the  * certain listener registered to listen or not, we need to add a InnerListener  * which implements CIMListener and doing nothing  */    _indicationClient.addListener(new InnerListener());    /*  * Add IndicationListenerList to a dispatcher, CIMEvent will be dispatched to  * target listener according to the hash code of one listener  */    CIMEventDispatcher dispatcher = new CIMEventDispatcher(_indicationClient);    // Create an new CIMIndicationHandler instance which wraps the dispatcher    CIMIndicationHandler indicationHdlr = new CIMIndicationHandler(dispatcher);    // Create a HttpServerConnection with the specified port  // NOTE: This target port is shared by all the event handlers    HttpServerConnection _serverConn = new HttpServerConnection(                       new HttpConnectionHandler(indicationHdlr), targetPort);  _serverConn.setName("CIMListener - Http Server");  _serverConn.start();    // You can also add listener after HttpServerConnection has started  


清單 3. 在提供程序端創建偵聽程序實例
// Create internal listener, InternalListener should implement CIMListener and  // have its own function    InternalListener internalListener = new InternalListener();    // Add internal listener to CIMIndicationListenertList instance    _indicationClient.addListener(internalListener);    // Create a listener destination instance    CIMClass    indicationDestinationClass = _client.getClass(                    new CIMObjectPath("CIM_ListenerDestinationCIMXML"), false);  CIMInstance cimListener = indicationDestinationClass.newInstance();    // Set the properties of CIM instance, and which properties are mandatory are  // highly depending on the implementation of CIM providers  // Set the creation class name of the listener    cimListener.updateProperty(new CIMProperty("CreationClassName",                         new CIMValue("CIM_ListenerDestinationCIMXML",                         CIMDataType.getPredefinedType(CIMDataType.STRING))));    // Set the system creation class name of the listener    cimListener.updateProperty(new CIMProperty("SystemCreationClassName",                         new CIMValue(null,                          CIMDataType.getPredefinedType(CIMDataType.STRING))));    // Set the system name of the listener    cimListener.updateProperty(new CIMProperty("SystemName",                         new CIMValue(null,                          CIMDataType.getPredefinedType(CIMDataType.STRING))));    // Set the name of the listener    cimListener.updateProperty(new CIMProperty("Name",                         new CIMValue(listenerName,                          CIMDataType.getPredefinedType(CIMDataType.STRING))));    // Set destination value, it should be combined with IP address of client and  // hash code of the listener object    cimListener.updateProperty(new CIMProperty("Destination",                              new CIMValue(IPAddress +                                           "/" +                                           internalListener.hashCode(),                        CIMDataType.getPredefinedType(CIMDataType.STRING))));    // Register the listener destination on the target CIM server    CIMObjectPath listenerCOP = _client.createInstance(new CIMObjectPath(),                                                      cimListener);  





將事件過濾器綁定到事件處理程序

事件過濾器將定義過濾器的條件。事件處理程序將描述在發生特定事件后採取的操作。

因此,綁定事件過濾器與事件處理程序意味著設置在特定事件發生時採取特定操作的情形。

CIM 類 CIM_IndicationSubscription 中有兩個屬性:

  • Filter 指一個事件過濾器實例的對象路徑。
  • Handler 指一個事件處理程序實例的對象路徑。

在綁定事件過濾器與事件處理程序時,您是在創建 CIM_IndicationSubscription 類的實例並設置該實例的 Filter 和 Handler 屬性。在創建該類的表示時,將交付事件過濾器所指定的事件表示。

在 CIM 事件模型下,事件過濾器與事件處理程序之間的關係可以表示為 m:n,這意味著一個事件過濾器可以綁定到多個事件處理程序上,或者一個事件處理程序可以綁定到多個事件過濾器。圖 3 和 4 演示了這兩種情況。


圖 3. 向多個事件處理程序註冊一個事件過濾器


圖 4. 為一個事件處理程序註冊多個事件過濾器

清單 4 顯示了如何用 SBLIM CIM 客戶機庫綁定事件處理程序與事件過濾器。


清單 4. 綁定事件過濾器與事件處理程序的樣例代碼
// Define class name of indication subscription    String subscriptionClassName = "CIM_IndicationSubscription";    // Construct object path of CIM_IndicationSubscription     CIMObjectPath cop = new CIMObjectPath(subscriptionClassName, _namespace);    // Get the  CIMClass object for subscription    CIMClass subscriptionClass = _client.getClass(cop);    // Create CIM_IndicationSubscription instance and set properties    CIMInstance subscriptionInstance = subscriptionClass.newInstance();    // Set object path of event filter instance as the value of "Filter" property    subscriptionInstance.setProperty("Filter",                                  new CIMValue(filterInstance.getObjectPath(),                                   new CIMDataType(CIMDataType.REFERENCE)));    // Set object path of event handler instance as the value of "Handler" property    subscriptionInstance.setProperty("Handler",                                 new CIMValue(handlerInstance.getObjectPath(),                                  new CIMDataType(CIMDataType.REFERENCE)));    // Create CIM_IndicationSubscription instance on the target CIM server    CIMObjectPath sop = _client.createInstance(new CIMObjectPath(),                                            subscriptionInstance);  





Linux 中的測試結果

我們在 Linux® 中部署了實現並且執行了一些測試。當在目標 CIM 伺服器上註冊 CIM 事件處理程序時,我們能夠獲得每個建立的偵聽程序的連接信息。

圖 5 顯示了典型網路狀態;每個偵聽程序都有自己的通信埠。


圖 5. 典型的註冊 CIM 事件處理程序

圖 6 顯示了我們的實現使用的網路狀態。您可以看到所有偵聽程序都共享同一個通信埠。


圖 6. 我們實現的註冊 CIM 事件處理程序
 (責任編輯:A6)



[火星人 ] 高效構建 CIM 事件模型已經有831次圍觀

http://coctec.com/docs/linux/show-post-69131.html