Tutorial 1: Request Information About Hosts in a Cluster
This tutorial describes the minimum amount of code required to create an unregistered EGO client that connects to a host cluster.
Using this tutorial, you will ...
- Open a connection to the EGO Web Service endpoint
- Retrieve and print out cluster info
- Retrieve and print out resource info
Step 1: Import class references
Import the necessary classes and interfaces that are required by the client to invoke the Web Service.
Step 2: Retrieve cluster information
Check if the client can connect to the MonitoringPortType endpoint in the Web Service. If successful, the next step is to create an XML document for requesting cluster information.
public void clusterInfo() { if (monitor == null) { System.err.println("Could not find MonitorPort..."); return; } ClusterInfoRequestDocument requestDoc = ClusterInfoRequestDocument.Factory .newInstance(); ClusterInfoRequest request = requestDoc.addNewClusterInfoRequest(); ClusterInfoResponseDocument responseDoc; ClusterInfoResponse response; // no security check needed for cluster info SecurityDocument sdoc1 = SecurityDocument.Factory.newInstance(); SecurityHeaderType sec1 = sdoc1.addNewSecurity(); SecurityDocument sdoc2 = SecurityDocument.Factory.newInstance(); SecurityHeaderType sec2 = sdoc2.addNewSecurity(); SecurityDocument sdoc3 = SecurityDocument.Factory.newInstance(); SecurityHeaderType sec3 = sdoc3.addNewSecurity(); SecurityDocument sdoc4 = SecurityDocument.Factory.newInstance(); SecurityHeaderType sec4 = sdoc4.addNewSecurity(); try { responseDoc = monitor.ClusterInfo(requestDoc, sdoc1, sdoc2, sdoc3, sdoc4); response = responseDoc.getClusterInfoResponse(); print(response); } catch (RemoteException rex) { rex.printStackTrace(); return; } }The ClusterInfoRequestDocument and ClusterInfoResponseDocument classes represent XML and the ClusterInfoRequest and ClusterInfoResponse classes represent the data.
Since client registration is not required for querying host information, security is not an issue. The Web Service, however, expects security documents so they are simply instantiated without any security information.
An object of type ClusterInfoRequestDocument is passed to the local proxy method, ClusterInfo(). The Web Service returns the cluster information and the result is printed out to the console using the overloaded print() method.
Step 3: Retrieve resource information
The code required to retrieve resource information is similar to retrieving cluster information. Check if the client can connect to the MonitoringPortType endpoint in the Web Service. If successful, create a ResourceInfoRequestDocument object and a ResourceInfoRequest object to hold the request data. Since we want to retrieve the information from all resources, the ResourceInfoRequest object is empty.
Create the security documents but leave them empty since security information is not required for resource queries.
Next, we pass the ResourceInfoRequestDocument and the security documents to the local proxy method, ResourceInfo(). The result of the operation is returned to the ResourceInfoResponseDocument object. The data is extracted from the document into the ResourceInfoResponse object and then printed out to the console using the overloaded print() method.
public Resource [] resourceInfo(String[] resourceNames) { if (monitor == null) { System.err.println("Could not find MonitorPort..."); return null; } try { ResourceInfoRequestDocument rreqDoc = ResourceInfoRequestDocument.Factory .newInstance(); ResourceInfoRequest rreq = rreqDoc.addNewResourceInfoRequest(); rreq.setResourceNameArray(resourceNames); ResourceInfoResponseDocument rresDoc = monitor.ResourceInfo( rreqDoc); ResourceInfoResponse rres = rresDoc.getResourceInfoResponse(); print(rres); Resource [] resources = rres.getResourceArray(); return resources; catch (RemoteException rex) { rex.printStackTrace(); return null; } }Step 4: Print the resource information
public void print(ClusterInfoResponse response) { ClusterInfo [] cinfos = response.getClusterInfoArray(); for(int i=0; i<cinfos.length; i++) { ClusterInfo cinfo = cinfos[i]; System.out.printf("%-12s\t\t%-12s\t\t%-12s%n", cinfo.getClusterName(), cinfo.getVersion()); } } public void print(ResourceInfoResponse response) { Resource[] resources = response.getResourceArray(); if(resources != null) { // print header System.out.printf("%-12s\t\t", "Attribute"); for(int i=0; i<resources.length; i++) { System.out.printf("%-12s\t\t", resources[i].getResourceName()); } System.out.println(); System.out.printf("%-12s\t\t", "Type"); for(int i=0; i<resources.length; i++) { System.out.printf("%-12s\t\t", resources[i].getResourceType()); } System.out.println(); System.out.printf("%-12s\t\t", "State"); for(int i=0; i<resources.length; i++) { System.out.printf("%-12s\t\t", resources[i].getResourceState()); } System.out.println(); } // assumes all resources have same attributes Attribute [] attributes = resources[0].getAttributeArray(); int numAttrs = attributes.length; for(int j=0; j<numAttrs; j++) { System.out.printf("%-12s\t\t", attributes[j].getName()); for (int i = 0; i < resources.length; i++) { Resource r = resources[i]; System.out.printf("%-12s\t\t", r.getAttributeArray(j).getStringValue()); } System.out.println(); } }
public void print(Resource res) { String name = res.getResourceName(); String type = res.getResourceType(); Enum state = res.getResourceState(); System.out.printf("%-12s%n%-12s%n%-12s%n", name, type, state.toString()); Attribute[] attributes = res.getAttributeArray(); for (int i = 0; i < attributes.length; i++) { Attribute attr = attributes[i]; print(attr); } } public void print(Attribute a) { String name = a.getName(); String value = a.getStringValue(); System.out.printf("%-12s\t\t%-12s%n", name, value); } public void print(ClientInfo cinfo) { System.out.printf("%-12s\t%-12s\t%-12s%n", cinfo.getClientName(), cinfo.getClientDescription(), cinfo.getClientLocation()); }Step 5: Call the sample program
In this step, we simply create an EGOClient object and call its serviceInfo() method from the main method.
... public static void main(String[] args) throws Exception { if(args==null || args.length <1) { throw new Exception("Incorrect Arguments"); } EGOclient client = new EGOclient(args[0]); client.serviceInfo(); }Run the client application
- Select Run > Run.
The Run dialog appears.
- In the Configurations list, either select a Java Application or click New for a new configuration.
For a new configuration, enter the configuration name.
- Enter the project name and Main class.
- Click the Arguments tab and enter the following arguments in the given order:
- URL of the web service gateway
- Port number (string) for the notification interface
- Client ID (string)
- Client description (string).
note:
Arguments must be separated by a space.
![]()
- Click Apply and then Run.
Sample Output
![]()
[ Top ]
[ Platform Documentation ]
Date Modified: July 12, 2006
Platform Computing: www.platform.com
Platform Support: support@platform.com
Platform Information Development: doc@platform.com
Copyright © 1994-2006 Platform Computing Corporation. All rights reserved.