Generate dummy CIM indications for testing on Linux

How to create CIM indications using OpenPegasus to test your indication listener

Hardware management using the Common Information Model standard often means that the management application must be capable of listening to and handling the indications that occur at the hardware level. To test the indication listener component of the management application when the planned system hardware is not available during development, you will need dummy indications. This article explains how to generate dummy indications on OpenPegasus CIMOM (Common Information Model Object Manager) using a provider shipped with the OpenPegasus source code.

Share your expertise:  Do you have another clever way to generate dummy indications? Add your comments below.

Share:

Srikanth Guttula (sguttula@in.ibm.com), System Software Engineer, IBM

author photo-Srikanth GuttulaSrikanth Guttula is a System Software Engineer with IBM Systems and Technology Group Labs in Pune, India. He has been working with IBM since February 2007. He is currently working on the IBM Systems Director, and he was previously involved in the development of the BladeCenter server Storage Configuration Manager. He holds a bachelor's degree in computer science and engineering.



26 January 2010

Also available in Japanese Portuguese

If you're going to be involved in hardware management using the Common Information Model standard, the management application you're using (or developing) will often require the ability to listen to and process hardware-level indications. In a perfect world, you've already got the hardware system you will be using up and running—of course, it is never a perfect world.

So, if you don't have the hardware handy, what do you do? Create dummy hardware-level indications to test the listener component of your management application. I'll show you how to generate dummy indications on OpenPegasus CIMOM (Common Information Model Object Manager) using a provider shipped with the OpenPegasus source code.

Overview of CIM, the Common Information Model

CIM, the Common Information Model, is a model for describing management information in a network or enterprise environment. CIM is composed of a specification and a schema. The specification defines how to integrate with other management models; the schema provides the actual model descriptions.

The Managed Object Format (MOF) is often used to represent the CIM schema because the MOF can be directly compiled to a CIMOM repository. CIMOM is a mediator (server) that uses compiled information models in its repository to direct requests and responses between clients and providers. CIMOM sits between the client and the provider.

The provider sits at the back end of CIMOM; it is actually responsible for communicating with managed resources such as disk drives and CPUs to access data. The provider sends this data to CIMOM, which forwards it to the client. When CIMOM receives a request from a client and the required data is not in its repository, then CIMOM forwards this request to the appropriate provider.

The client is often a management application that sends requests to CIMOM and receives the response. Most of the time, the indication listener is a part of the client, and it can only receive information—it cannot send any requests. A simple representation of the overall model is shown in Figure 1.

Figure 1. Overview of the CIMOM model
Overview of the CIMOM model

Steps for generating indications

Three major steps are involved in generating indications:

  1. Compile and install the RT_Indication provider shipped with the OpenPegasus source code.
  2. Develop a small Java™ program for generating indications by sending a request to CIMOM.
  3. Develop a small Java program for listening to the indications generated.

Step 1. Compile and install the RT_Indication provider

Start this process by downloading and installing OpenPegasus from OpenPegasus.org (see Resources for a link). For this article, I used the OpenPegasus source build pegasus-2.9.0.tar.gz; the same procedure should work fine for any OpenPegasus release. You can either install OpenPegasus from the appropriate binary release or compile and install from the source code. There is a doc included with the source code that contains the prerequisites and compiling instructions.

After installing OpenPegasus, populate the basic schema repository.

Installing a provider on CIMOM involves three steps:

  • Compile the provider MOF to the CIMOM repository.
  • Register the provider with CIMOM.
  • Compile the non-MOF-related source code to the CIMOM's shared library.

Compile the provider MOF

Extract pegasus-2.9.0.tar.gz to any directory (if you haven't already done this as part of installing OpenPegasus). Create an environment variable PEGASUS_ROOT. Set PEGASUS_ROOT to the base directory of the extracted pegasus-2.9.0.tar.gz file. Export PEGASUS_ROOT.

The base directory should contain the following directories immediately under it: cgi, doc, Dummy, installs, InterfaceArchive, mak, rpm, Schemas, src, test and files Configure, Makefile, etc....

The environment variable PEGASUS_HOME should be set to the base directory where OpenPegasus is already installed. Set the environment variable PEGASUS_PLATFORM to LINUX_IX86_GNU. Export PEGASUS_HOME and PEGASUS_PLATFORM.

Start the CIM server as shown in Listing 1:

Listing 1. Starting CIMOM
LinuxMint:/ # cimserver

This assumes $PEGASUS_HOME/bin is already included in the PATH.

Now it's time to compile the provider MOF to a namespace SDKExamples/DefaultCXX, but the provider MOF is derived from the base CIM schema MOF, so first compile the base CIM schema MOF and then the provider MOF. The compiling order should be followed strictly.

Change to the "/" directory (not really required). Issue the following commands as shown in Listing 2 (assuming that the base schema is compiled from $PEGASUS_ROOT/Schemas/CIM217):

Listing 2. Compiling base schema to SDKExamples namespace

Click to see code listing

Listing 2. Compiling base schema to SDKExamples namespace

LinuxMint:/ # cimmof -n SDKExamples/DefaultCXX \$PEGASUS_ROOT/Schemas/CIM217/DMTF/qualifiers.mof

LinuxMint:/ # cimmof -n SDKExamples/DefaultCXX \$PEGASUS_ROOT/Schemas/CIM217/DMTF/Core/CIM_ManagedElement.mof

LinuxMint:/ # cimmof -n SDKExamples/DefaultCXX \$PEGASUS_ROOT/Schemas/CIM217/CIM_Event.mof

Compile the provider MOF as shown in Listing 3:

Listing 3. Compiling provider MOF to SDKExamples namespace

Click to see code listing

Listing 3. Compiling provider MOF to SDKExamples namespace

LinuxMint:/ # cimmof -n SDKExamples/DefaultCXX \$PEGASUS_ROOT/src/SDK/samples/Providers/Load/SampleProviderSchema.mof

Register the provider

Issue the following command for registering the provider with CIMOM:

Listing 4. Registering provider with CIMOM

Click to see code listing

Listing 4. Registering provider with CIMOM

LinuxMint:/ # cimmof -n root/PG_InterOp \$PEGASUS_ROOT/src/SDK/samples/Providers/Load/IndicationProviderR.mof

Compile the shared library

The shared library can be compiled to CIMOM using a C++ compiler. In this example, the shared library will be compiled using g++ and GNU make, as shown in Listing 5. Change to the directory $PEGASUS_ROOT/src/SDK/samples/Providers/DefaultC++/IndicationProvider, then type make and return.

Listing 5. Compiling shared library
LinuxMint:/pegasus/src/SDK/samples/Providers/DefaultC++/IndicationProvider # make
g++ -c -o /cimserver/pegasus/obj/sdk/IndicationProviderMain.o -O2 -W -Wall -Wno-
unused -D_GNU_SOURCE -DTHREAD_SAFE -D_REENTRANT -fPIC -m32 -I /pegasus/src -DPEG
ASUS_PLATFORM_LINUX_IX86_GNU IndicationProviderMain.cpp

g++ -c -o /cimserver/pegasus/obj/sdk/IndicationProvider.o  -O2 -W -Wall -Wno-unu
sed -D_GNU_SOURCE -DTHREAD_SAFE -D_REENTRANT -fPIC -m32 -I /pegasus/src -DPEGASU
S_PLATFORM_LINUX_IX86_GNU IndicationProvider.cpp

g++ -shared -Xlinker -rpath -Xlinker /cimserver/pegasus/lib -m32 -DPEGASUS_PLATF
ORM_LINUX_IX86_GNU -o/cimserver/pegasus/lib/sdk/libSDKIndicationProvider.so /cim
server/pegasus/obj/sdk/IndicationProviderMain.o /cimserver/pegasus/obj/sdk/Indic
ationProvider.o -ldl -lpthread -lcrypt -L/cimserver/pegasus/lib -lpegcommon -L/c
imserver/pegasus/lib -lpegprovider

make -i unlink

make[1]: Entering directory `/pegasus/src/SDK/samples/Providers/DefaultC++/Indic
ationProvider'

rm -f /cimserver/pegasus/lib/libSDKIndicationProvider.so

make[1]: Leaving directory `/pegasus/src/SDK/samples/Providers/DefaultC++/Indica
tionProvider'

ln -f -s /cimserver/pegasus/lib/sdk/libSDKIndicationProvider.so /cimserver/pegas
us/lib/libSDKIndicationProvider.so

The shared library libSDKIndicationProvider.so is added to $PEGASUS_HOME/lib/sdk and a link to it is added to $PEGASUS_HOME/lib.

Shut down the CIMOM using cimserver -s, then start it again using cimserver (as in Listing 1). A snapshot of the SDKExamples/DefaultCXX namespace, taken from UltimateCIM Explorer (see Resources), looks like Figure 2.

Figure 2. Snapshot taken from UltimateCIM
Snapshot taken from UltimateCIM

Step 2. Develop a Java program to generate indications

An instance of RT_TestIndication can be generated by invoking the method SendTestIndication of RT_TestIndication on CIMOM. The SBLIM (pronounced "sublime") CIM client library can be used to invoke the method. (SBLIM is an umbrella project for a collection of systems management tools to enable Web-Based Enterprise Management (WBEM) on Linux®.)

Download the SBLIM CIM client library (see Resources for a link), extract it, get the JAR lib/sblim-cim-client2-2.1.1.jar, and include it in your CLASSPATH. SendTestIndication can be invoked as shown in Listing 6.

Listing 6. Client code invoking SendTestIndication
// Creating a CIM client instance

WBEMClient cli = WBEMClientFactory.getClient("CIM-XML");

CIMObjectPath cop = new CIMObjectPath("http", "cimomIP", "cimomPort", 
                                      "SDKExamples/DefaultCXX", null, null);

Principal principal = new UserPrincipal("username");
PasswordCredential password = new PasswordCredential("userPassword");
Subject subject = new Subject(false,Collections.singleton(principal),
                              Collections.singleton(password),Collections.EMPTY_SET);

cli.initialize(cop, subject, null);

CIMArgument<?>[] input = new CIMArgument[10];
CIMArgument<?>[] output = new CIMArgument[10];

// Invoking SendTestIndication on RT_TestIndication

Object obj = cli.invokeMethod(new CIMObjectPath(
      "/SDKExamples/DefaultCXX:RT_TestIndication"), "SendTestIndication", input, output);

if (obj.toString().equals("0")) 
{
    System.out.println("Indication generated successfully...");
}

Alternately, RT_TestIndication can be generated by compiling a client program included with the pegasus-2.9.0.tar.gz. This client code can be compiled using g++ and GNU make as shown in Listing 7:

Listing 7. Compiling the client
LinuxMint:/pegasus/src/SDK/samples/Clients/DefaultC++/SendTestIndications # make
g++ -O2 -W -Wall -Wno-unused -D_GNU_SOURCE -DTHREAD_SAFE -D_REENTRANT -fPIC -m32
 -c -o /cimserver/pegasus/obj/sdk/SendTestIndications.o -I /pegasus/src -DPEGASU
S_PLATFORM_LINUX_IX86_GNU SendTestIndications.cpp

g++ -Xlinker -rpath -Xlinker /cimserver/pegasus/lib -m32 -o/cimserver/pegasus/bi
n/sdk/SendTestIndications /cimserver/pegasus/obj/sdk/SendTestIndications.o -L/ci
mserver/pegasus/lib -lpegcommon -L/cimserver/pegasus/lib -lpegclient -ldl -lpthr
ead -lcrypt

An executable, SendTestIndications, is added to the directory $PEGASUS_HOME/bin/sdk.


Step 3. Develop a Java program to listen to indications

The indication listener I cover in this section will be capable of listening to RT_TestIndication. Basically, RT_TestIndication is derived from CIM_Indication. The listener program has to register for RT_TestIndication.

There are three steps involved in creating and registering a listener. The following three code listings should be created as a part of a separate thread so that the listener can listen to the indications continuously:

  • Creating a CIM indication filter instance
  • Creating a CIM indication handler instance
  • Creating a CIM indication subscription instance

Creating the filter instance

A CIM indication filter filters the kind of indications to be delivered to the listener. A CIM indication filter can be created by getting an instance of the CIM_IndicationFilter class and then setting appropriate properties for it. It is always safe to find out if there are any existing filters with the same filter name. If the filter name already exists, then you should delete that filter instance or create the current filter instance with a new name. Listing 8 shows how to create a filter instance.

Listing 8. Creating a filter instance
// Setting property values to the filter instance
CIMProperty<?> name = new CIMProperty<String>("Name", CIMDataType.STRING_T,
                                   "TestFilter");

CIMProperty<?> namespace = new CIMProperty<String>("SourceNamespace",
                                        CIMDataType.STRING_T, "SDKExamples/DefaultCXX");
CIMProperty<?> query = new CIMProperty<String>("Query", CIMDataType.STRING_T, 
                                    "SELECT * FROM RT_TestIndication");
CIMProperty<?> language = new CIMProperty<String>("QueryLanguage",
                                       CIMDataType.STRING_T, "WQL");

CIMProperty<?>[] properties = new CIMProperty[] {name, namespace, query, language};
CIMObjectPath path = new CIMObjectPath("/SDKExamples/DefaultCXX:CIM_IndicationFilter");

// Creating an instance of CIM_IndicationFilter

CIMObjectPath copFilter = cli.createInstance(new CIMInstance(path, properties));

Creating the handler instance

When the CIMOM invokes a handler, it will pass it an instance of the indication and an instance of CIM_ListenerDestination. The handler then can pass this indication instance, in proper export format, to the Listener program. Listing 9 shows you how to create a handler instance.

Listing 9. Creating a handler instance
WBEMListener listener = WBEMListenerFactory.getListener("CIM-XML");
int port = listener.addListener(new IndicationListener()
            {
              public void indicationOccured(String indicationURL, CIMInstance indication)
                                       	{ System.out.println(indication.toString()); }
            }, 0, "http");

String host = "http://"+InetAddress.getLocalHost().getHostAddress()+":"+port+"/create";

CIMProperty<?> name = new CIMProperty<String>("Name", CIMDataType.STRING_T,
                                   "TestListener");
CIMProperty<?> creationClassName = new CIMProperty<String>
            ("CreationClassName", CIMDataType.STRING_T, "CIM_ListenerDestinationCIMXML");
CIMProperty<?> destination = new CIMProperty<String>("Destination",
                                          CIMDataType.STRING_T, host);

CIMProperty<?>[] properties = new CIMProperty[] { name, creationClassName,
                                           destination };
CIMObjectPath path = new CIMObjectPath(
                                "/SDKExamples/DefaultCXX:CIM_ListenerDestinationCIMXML");

CIMObjectPath copHandler = cli.createInstance(new CIMInstance(path, properties));

Creating a subscription instance

The listener program here, subscribing for RT_TestIndication, describes the kind of indications in which it is interested and the handler to which the CIMOM delivers the indication. Listing 10 demonstrates subscribing to RT_TestIndication.

Listing 10. Creating a subscription instance
CIMProperty<?> filter = new CIMProperty<CIMObjectPath>("Filter", 
                         new CIMDataType("CIM_IndicationFilter"), copFilter);

CIMProperty<?> handler = new CIMProperty<CIMObjectPath>("Handler", 
                          new CIMDataType("CIM_ListenerDestinationCIMXML"), copHandler);

CIMProperty<?>[] properties = new CIMProperty[] { filter, handler };
CIMObjectPath path = new CIMObjectPath("/root/PG_InterOp:CIM_IndicationSubscription");

CIMObjectPath copSubscription = cli.createInstance(new CIMInstance(path, properties));

Testing the listener with your dummy CIM indication

Finally, you're ready to test with your dummy indication. Start the cimserver if it is not already running. Start the indication listener program. Now generate an indication using the indication-generating program. See the indication listener console for output. A snapshot of the output taken from our implementation is shown in Figure 3.

Figure 3. Sample output
Sample output

That's it! You've successfully created dummy hardware-level indicators and used them to test the listener component of your CIM management application.

Resources

Learn

Get products and technologies

Discuss

  • Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Linux on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux, Open source
ArticleID=464846
ArticleTitle=Generate dummy CIM indications for testing on Linux
publish-date=01262010