This section of the tutorial deals with Starting the Agent and the Shopping Cart Application and testing the Agent using the Manager tools bundled with Agent Toolkit.
Starting the Agent and Application
Please follow the steps given below to run the Agent. This will also start the Shopping Cart Application.
Go to <Agent Toolkit Home>/reference/jmx/agent/bin directory from the command prompt.
Set the JAVA_HOME path in the run.bat/sh file
Now execute run.bat/.sh file.
This will start the Agent at the default port numbers specified below.
Once the Agent is started, the Shoppping Cart application UI also gets opened.
The different adaptors gets started in Multi-Protocol agent at the default port numbers listed below:
SNMP Adaptor - 8001
RMI Adaptor - 1099
CORBA Adaptor - 1050
HTTP Adaptor - 8050
Testing the Agent
The Multi-Protocol agent is now running at the port numbers specified above. The Shopping cart application is started and you can find the UI of the Shopping Cart Application displayed, as shown below:
As seen in the above image, you will find the Item count which refers to the Total number of items ordered and the Total Price which refers to the total price of the items ordered. The UI will have all the details about the items sold and the rice of each item items. To order an item, click on the Add button which displays a Pop Up window with a Combo Box listing the Pets that are available in the shop. Specifying the Pet and the Quantity required , a row can be added. On adding a Item, the Item count and Total Price columns will get updated.
Say for example, you add an entry in the Shopping Cart application as follows and click OK,
The entry gets added as below in the UI.
Now in the Agent side, if you are going to do a query for the ShoppingCartTable in the ShoppingCartMib at any point of time, the value that is available in the Application will be received from the Agent. As this is a Multiprotocol Agent you can access the Agent or the Application which are coupled, by means of the supported protocols (SNMP, HTTP, RMI, CORBA, HTML).
The Shopping Cart Agent can be managed through SNMP Manager using the MIB Browser tool. This application creates a Manager environment.
Go to <Agent Toolkit Home>/bin directory and start the MIB Browser application using MibBrowser.bat/.sh file.
Load the ShoppingCartMib.mib from <Agent Toolkit Home>/mibs directory either using the Load MIB Module toolbar icon or File -> Load MIB menu bar.
A Load MIB Dialog opens up wherein you have to go to the URL using the Browse button. Various Load options are available. Let us leave them to be with the default settings.
Click OK and the MIB gets loaded.
Start querying the following groups :
The tables can be queried by doing a GET / GET_NEXT/SET request.
The Scalars can be queried with GET / GET-NEXT requests alone as they are read-only variables.
You can find the Agent responding with the values present in the shopping cart. For example, you add an entry using the Shopping Cart application UI for Pet Name "Parrot" and quantity ordered as 1.
On querying the Table columns from the MIB Browser, the following results gets displayed :
PetName : Parrot
Unit Price : $20
Quantity : 1
The scalar group responds with total Item Count as 1 and Price 20.
You can also add/modify/delete entries from the Manager (MIB browser ) . The UI application gets updated with these values.
Say, if the pet "dog" needs to be purchased, the ascii values of d-o-g has to be given as an instance in the MIB Browser object field and a Multivarbind request has to be sent to the Table column. This will add a row and the Shopping Cart Application UI also gets updated with these values. The screenshot given below depicts the scenario :
Even if the row is deleted or modified in the Shopping Cart Application , the values are removed/modified accordingly when queried from MIB Browser. This happens vice versa also.
On Updating a row (Modifying the Quantity of a Pet that is required) or adding a row (ordering one more Pet that is available in the Shop) or deleting a Pet requirement, through the Agent, you will find that the Application gets updated with the requests.
Thus, the Agent can be coupled easily with any of the Application data which in turn can be remotely accessed and managed. To know more about the UserStorageModel instrumentation part have a look at the Instrumenting Tables section. This will give you a clear idea about how to couple your Application and the Generated Agent.
To know more on Testing the Agent using MIB Browser, please refer to Testing the Agent section in Building SNMP Agents of Product Help documentation.
The Shopping Cart application can be managed through the RMI /CORBA/HTTP using MBean Browser.
Go to <Agent Toolkit Home>/bin directory and start the MBean Browser application using MBeanBrowser.bat/.sh file
Select "RMI Client" in the MBean browser and click Operations -> Connect. It gets connected to the Multi-Protocol agent using the RMI protocol. You can see the MBeans defined in the ShoppingCartMibModule listed in the left hand frame of the remote browser. The MBeans are listed under the domain name ShoppingCartAgent.
The following operations can be performed :
GET/SET Scalar Attributes
You can GET and SET scalar attribute values if the attribute is of type read-write. For read only attributes, you can only get the values. In the Shopping Cart application, the scalar attributes TotalItemcount and TotalPrice are read only attributes and hence their values cannot be modified. To access the Scalar attributes of the application,
Select Attributes for type=ShoppingCartSummaryInstrument. When this query is made, the Agent will fetch the value available with the application. You can also get the attribute values by selecting Operations for type=ShoppingCartSummaryInstrument.
GET Table values
Now, let us assume that we have ordered one quantity of each item using the Shopping Cart Application UI. On the Agent side, if you are going to do a query for the ShoppingCartTable at any point of time, the value that is available in the Application will be received from the Agent.
To access the table values, select Attributes for type=ShoppingCartTable. You will now find the values displayed as shown in the screen-shot below. You can also get the attribute values by selecting Operations for type=ShoppingCartTable.
Add / Modify / Delete Row
The customer can also place an order through the Manager application (MBean Browser) by adding an entry using the Add Row option . The Modify Row option can be used to modify an existing entry. The Delete Row option can be used to delete an existing item added by the user. These changes will get reflected in the ShoppingCartTable.
Similarly you can access the value available in the application and add entries by selecting CORBA/HTTP client from the Client Menu. For example, access the scalar attribute values TotalItemCount and TotalPrice using HTTP client. You will find the values displayed as shown in the screen-shot below:
The Shopping Cart application can be tested through the HTML Adaptor using any Web Browser for example Netscape, IE etc.
Start the Browser and specify the URL as : http://localhost:8030. The HTTP Console Login page is displayed.
Specify the User name and password for authentication and select Login. The default User Name is jmx and password is root.
On successful authentication, the JSP Home page is displayed. It has a left side tree view in which all the MBeans are grouped under their respective domains. These are the domain names with which the MBeans are registered in the MBean server. Clicking a domain, the MBeans registered under this domain are listed in the left side tree.
Select a Domain name, for example ShoppingCartAgent. MBeans in the selected domain are listed in a separate page.
MBeans are grouped under different domains. Select the MBean whose attribute you want to view, for example ShoppingCartTableAttributes of tabular data type are displayed as a table .
The following operations can be performed :
Modify Row/Add Row/Delete Row :
To modify a row, select the check box of the corresponding row and modify the value. For example, in the ShoppingCartTable, modify the quantity of Parrot purchased from 1 to 2 and select the Save button. The new values will be saved as shown in the screen-shot below:
New rows can be added using the New Row button at the bottom of the page. The Delete button can be used to delete a row from the table.
Get Scalar Values
The attributes of the selected scalar MBeans ShoppingCartSummaryInstrument are listed in table format with the following information: Attribute name, Attribute type, Attribute access, Attribute value, and Attribute Description. Values of Read-Write attributes are presented in editable text field.
The JavaServer pages also allow you to perform operations on MBeans. If operations can be performed on an MBean, then the Operations button is displayed at the right-top corner of the the MBean attribute page. Clicking this button presents a page with the list of operations. Selecting an operations hyperlink displays the following information pertaining to the MBean operation:
Operation Name: The name of the MBean operation.
Description: Short description about the operation.
Apart from these, SET operations are provided with text fields to specify the attribute values. Further chapters will discuss the implementation details of Scalar group and Tabular group.