Chapter 3 Using the Sample Programs
This chapter describes the sample programs provided with
the Solaris WBEM SDK, and includes the following topics:
About the Sample Programs
When you install the Solaris WBEM SDK, a sample Java
applet and several programs are installed in file:/usr/demo/wbem. You can use these samples as a basis for developing your own
programs.
Note –
To use the applet and sample programs, make sure that /usr/java points to at least JDK 1.2.2, and that the program files
are installed in the /usr/demo/wbem directory.
The following samples are provided:
-
Applet –
Enumerates the Solaris software packages that are installed on a system running Solaris WBEM Services,
and connects to the CIM Object Manager running on a local or a remote system.
-
Client programs – Use the Java APIs to make requests to the CIM Object Manager.
-
Provider programs – Communicate with managed objects to access data.
Sample Applet
Note –
For more detailed information on this applet, see file:/usr/demo/wbem/applet/README.
You must run the applet on a machine that has network access to the
CIM Object Manager. In addition, the machine must run one of the following
programs:
For more information on the JDK
appletviewer
or the Java runtime environment, see
http://java.sun.com. For more information on Java Plug-in,
see the
Solaris
Java Plug-in User's Guide
How to Run the Sample Applet Using Appletviewer
-
To run the sample applet using appletviewer,
type the following command:
% appletviewer -JD \
java.security.policy=/usr/demo/wbem/applet/applet.policy \
/usr/demo/wbem/applet/GetPackageInfoAp.html
|
How to Run the Sample Applet in a Web Browser
-
To run the sample applet in a web browser, open the following file in
your web browser:
file:/usr/demo/wbem/applet/GetPackageInfoAp.html
Sample Client Programs
The sample client programs are located in subdirectories of /usr/demo/wbem/client, and are described in the following table.
Table 3–1 Sample Client Programs
|
Directory
|
Program
|
Purpose
|
|
./batching
|
./TestBatch host username password classname [[rmi|http]]
|
Perform enumerateInstanceName, getClass, and enumerateInstances in a single
batching call
|
|
./enumeration
|
./ClientEnum host username password classname [[rmi|http]]
|
Enumerate classes and instances in the specified class
in the default namespace, root\cimv2, on the specified
host
|
|
./events
|
./Subscribe host username password classname
|
Subscribe to lifecycle events for a specified class, print
events that occur within one minute of the subscription, and then unsubscribe
to the events
|
|
./logging
|
./CreateLog host root-username root-password [[rmi|http]]
|
Create a log record on the specified host
|
|
./ReadLog host root-username root-password [[rmi|http]]
|
Read a log record on the specified
host
|
|
./misc
|
./DeleteClass host classname root-username root-password [[rmi|http]]
|
Delete the specified class in the default namespace root\cimv2
on the specified host
|
|
./DeleteInstances host classname root-username root-password [[rmi|http]]
|
Delete instances of the specified class in the default namespace root\cimv2 on the specified host
|
|
./namespace
|
./CreateNameSpace host parentNS childNS root-username root-password [[rmi|http]]
|
Connect to the CIM Object Manager as the
specified user, and create a namespace on the specified host
|
|
./DeleteNameSpace host parentNS childNS root-username root-password [[rmi|http]]
|
Delete the specified namespace on the specified host
|
|
./query
|
./ExampleQuery host username password [[rmi|http]] WQL-query
|
Create a test class with sample
instances, and perform queries on that class
|
|
./TestQuery host username password [[rmi|http]]WQL-query
|
Perform the specified WQL query
|
|
./systeminfo
|
./SystemInfo host username password [[rmi|http]]
|
Display Solaris processor and system
information for the specified host in a separate window
|
Running the Sample Client Programs
You must first set the CLASSPATH to include the
necessary .jar files before you run the client programs.
How to Set the CLASSPATH
-
Set the CLASSPATH environment variable using one of the
following methods:
-
To use the C shell, type:
% setenv CLASSPATH .:/usr/sadm/lib/wbem.jar:/usr/sadm/lib/xml.jar
:/usr/sadm/lib/wbem/sunwbem.jar:/usr/sadm/lib/wbem/extension
|
-
To use the Bourne shell, type:
% setenv CLASSPATH .:/usr/sadm/lib/wbem.jar:/usr/sadm/lib/xml.jar
:/usr/sadm/lib/wbem/sunwbem.jar:/usr/sadm/lib/wbem/extension
|
How to Run the Sample Client Programs
Most of the sample client programs accept an optional parameter that
specifies the protocol to use to connect to the CIM Object Manager. RMI
is the default protocol.
-
Run the sample client programs using the following format:
% java program_name parameters
|
For instance, the following example runs the SystemInfo
program by connecting to myhost as the root user with the secret password
using the HTTP protocol.
% java SystemInfo myhost root secret http
|
Sample Provider Programs
The sample provider programs are located in subdirectories of /usr/demo/wbem/provider, and are described in the following table.
Table 3–2 Sample Provider Programs
|
File Name
|
Purpose
|
|
NativeProvider.java
|
Top-level provider program that fulfills requests
from the CIM Object Manager and routes these requests to the Native_Example provider. This program implements the instanceProvider and methodProvider APIs. This program also declares methods to enumerate instances
and to get an instance of the Native_Example class.
This program also declares a method that invokes a method to print the string “Hello
World.”
|
|
Native_Example.mof
|
Creates a class that registers the NativeProvider provider with the CIM Object Manager. This MOF
file identifies NativeProvider as the provider to service
requests for dynamic data in the Native_Example class.
The file also declares the properties and methods to be implemented by the NativeProvider.
|
|
Native_Example.java
|
The NativeProvider
program calls this provider to enumerate instances and to get an instance
of the Native_Example class. The Native_Example provider uses the APIs to enumerate objects and to create instances
of objects. The Native_Example class declares native
methods, which call C functions in the native.c file
to get system-specific values. Examples of such values include host name,
serial number, release, machine, architecture, and manufacturer.
|
|
native.c
|
This C program implements methods in the Native_Example Java provider in native C code.
|
|
Native_Example.h
|
A machine-generated header file for the Native_Example class. Defines the correspondence between the names of native
method in the Java programming language and the native C functions that execute
those methods.
|
|
libnative.so
|
Binary native C code compiled from the native.c file.
|
How to Run the Sample Provider Programs
You must set up your environment before you can run the sample provider
programs.
-
Set the LD_LIBRARY_PATH environment variable to the
location of the provider class files.
-
To use the C shell, type:
% setenv LD_LIBRARY_PATH /usr/sadm/lib/wbem
|
-
To use the Bourne shell, type:
% LD_LIBRARY_PATH = /usr/sadm/lib/wbem
|
-
Copy the libnative.so shared library file to the
directory specified by the LD_LIBRARY_PATH environment variable.
% cp libnative.so /usr/sadm/lib/wbem
|
-
Move the provider class files to the same path as the package to which
those files belong.
% mv *.class /usr/sadm/lib/wbem
|
-
Become root superuser.
-
Stop the CIM Object Manager in the same shell in which you set the LD_LIBRARY_PATH environment variable.
# /etc/init.d/init.wbem stop
|
Note –
When you set the LD_LIBRARY_PATH environment variable
in a shell, you must stop and restart the CIMOM in the same shell to recognize
the new variable.
-
Start the CIM Object Manager.
# /etc/init.d/init.wbem start
|
-
Exit being superuser.
-
Compile the program's associated .mof file to load
the appropriate class in the CIMOM and to identify the provider.
% mofcomp -u root -p root-password Native_Example.mof
|
-
Start CIM Workshop.
% /usr/sadm/bin/cimworkshop
|
-
In the CIM Workshop toolbar, click the Find Class icon.
-
In the Input dialog box, type the name of the class that you want to
display and then click OK.
The class displays in CIM Workshop.