Tutorial 4: Monitor an Activity on a Resource
This tutorial describes how to create a registered EGO client that monitors an activity on a resource.
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
- Register the client with Platform EGO and print out the registration response
- Request a resource allocation
- Check for notification of resource allocation
- Create an activity that will run on the requested resource
- Calculate the activity load on the resource and print it out
- Monitor the activity
- Locate the client and print out the client info
- Unregister the client
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 and Resource information
Refer to Tutorial 1: Step 2: Retrieve cluster information and Step 3: Retrieve resource information.
Step 3: Register the client
Refer to Tutorial 2: Step 3: Register the client.
Step 4: Make a resource allocation request
Refer to Tutorial 3: Step 4: Make a resource allocation request.
Step 5: Check for notification of resource allocation
Refer to Tutorial 3: Step 5: Check the allocation status.
Step 6: Create an activity that will run on a requested resource
Refer to Tutorial 3: Step 6: Create and start an activity on a resource.
Step 7: Calculate the activity load on the resource
In order to determine if a resource is too busy to receive jobs, a load index value is calculated and compared to a corresponding load threshold parameter. The following code retrieves and processes the load index value for r1m, the 1-minute CPU run queue length.
The main method contains a While loop that retrieves the average resource load every 30 seconds. This update interval is implemented by a sleep method prior to collecting the information. This cycle is repeated four times and then the loop exits.
Pass the activity ID to the getActivityResourceLoad() method. This method collects the resource names associated with the activity ID. Pass the resource names array to the calculateActivityLoad() method, which cycles through the array and retrieves the load attribute index associated with each resource. The getLoadAttributeIndex() method cycles through the list of resource attributes looking for the r1m load index. (The r1m load index represents the average number of processes ready to use the CPU during a one-minute interval.) This method returns the attribute array index corresponding to load index r1m. The value for r1m is retrieved and converted to a double data type. This value is stored in a variable (total), which is used as an accumulator. The total sum is then divided by the number of resources to yield the average load index value of r1m. The activity ID and the average load index value are printed out.
public double getActivityResourceLoad(String activityId) { double load = 0; // for all the resources in this activity compute the average load ActivityResources activityResources = activityidToResourcesMap.get(activityId); String [] resourceNames = activityResources.getResources(); Resource [] resources = this.resourceInfo(resourceNames); load = calculateActivityLoad(resources); return load; } public double calculateActivityLoad(Resource [] resources) { double total=0; for(int i=0; i<resources.length; i++) { Resource resource = resources[i]; int index = getLoadAttributeIndex(resource); total += getDoubleValue(resource.getAttributeArray(index)); } return total/resources.length; } public int getLoadAttributeIndex(Resource res) { int rv = -1; Attribute [] attrs = res.getAttributeArray(); for(int i=0; i<attrs.length; i++) { Attribute attr = attrs[i]; if(attr.getName().equals("r1m")) { return i; } } return rv; }Step 8: Monitor the activity
Activity information describes the state of an activity within Platform EGO. There is both EGO meta data described (activity ID, activity state, allocation ID, consumer name, and activity specification) as well as run time state (start time, end time, resource name, exit status, exit reason, resource usage, and activity resource usage).
Pass the activity ID to the monitorActivity() method. Check if the activity ID is valid and that the client can connect to the MonitoringPortType endpoint. If successful, call the getActivityInfos() method and pass the activity ID as an argument.
Use the getActivityInfos() method to create an activity information request object (aiReq). Call the ActivityInfo() method with the activity info request document (aiReqDoc) and the logon document (logonDoc) as input arguments. The response message for ActivityInfo (aiRes) contains the activity state information for the associated activity ID, as described above. Print out the activity and resource load information, and return control to the monitorActivity() method.
Create a For loop that checks the state information for each activity. Once an activity has been accepted and assigned an activity ID, it can be in one of the following states: null, start, run, suspend, finish, and unknown. If the activity state is "run", the loop will be repeated after one minute. Print out the activity information.
public void monitorActivity(String[] activityIds) { if (activityIds == null) { return; } // use ActivityInfo from the MonitoringPort if (monitor == null) { try { monitor = new MonitoringPortTypeStub(null, targetURL); } catch (Exception ex) { ex.printStackTrace(); return; } } boolean done = false; while(!done) { // as long as the activity is running ActivityInfo [] infos = getActivityInfos(activityIds); done = true; for (int i=0; i<infos.length; i++) { ActivityInfo info = infos[i]; ActivityState.Enum state = info.getActivityState(); if(state == ActivityState.RUN) { done = false; } print(info); } // wait for a minute try { Thread.sleep(60000); } catch(InterruptedException ie) { ie.printStackTrace(); } } }
public ActivityInfo [] getActivityInfos(String [] activityIds) { if (activityIds == null) { return null; } // use ActivityInfo from the MonitoringPort if (monitor == null) { try { monitor = new MonitoringPortTypeStub(null, targetURL); } catch (Exception ex) { ex.printStackTrace(); return null; } } // as long as the activity is running ActivityInfoRequestDocument aiReqDoc = ActivityInfoRequestDocument.Factory .newInstance(); ActivityInfoRequest aiReq = aiReqDoc.addNewActivityInfoRequest(); aiReq.setActivityIDArray(activityIds); aiReq.setOptionArray(null); ActivityInfoResponseDocument aiResDoc; ActivityInfoResponse aiRes; try { aiResDoc = monitor.ActivityInfo(aiReqDoc, logonDoc); aiRes = aiResDoc.getActivityInfoResponse(); print(aiRes.getActivityInfoArray()); } catch (RemoteException rex) { rex.printStackTrace(); return null; } ActivityInfo[] infos = aiRes.getActivityInfoArray(); return infos; }Step 9: Locate the client
Refer to Tutorial 2: Step 4: Locate the client.
Step 10: Unregister the client
Refer to Tutorial 2: Step 5: Unregister the client.
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.