com.vmware.apputils.vim25
Class ServiceUtil

java.lang.Object
  extended by com.vmware.apputils.vim25.ServiceUtil

public class ServiceUtil
extends java.lang.Object

Utility wrapper methods for the vimService methods


Constructor Summary
ServiceUtil()
           
 
Method Summary
 com.vmware.vim25.SelectionSpec[] buildFullTraversal()
          This method creates a SelectionSpec[] to traverses the entire inventory tree starting at a Folder
 com.vmware.vim25.PropertySpec[] buildPropertySpecArray(java.lang.String[][] typeinfo)
          This code takes an array of [typename, property, property, ...] and converts it into a PropertySpec[].
 void clientConnect()
          Connect to the service
 void clientDisconnect()
          Disconnect from the service
 void clientLoadSession(java.lang.String cookieString)
           
 void clientSaveSession(java.lang.String fileName)
           
static ServiceUtil CreateServiceUtil()
           
 com.vmware.vim25.ObjectContent[] getAllContainerContents()
          Retrieve Container contents for all containers recursively from root
 com.vmware.vim25.ObjectContent[] getContentsRecursively(com.vmware.vim25.ManagedObjectReference root, boolean recurse)
          Retrieve container contents from specified root recursively if requested.
 com.vmware.vim25.ObjectContent[] getContentsRecursively(com.vmware.vim25.ManagedObjectReference collector, com.vmware.vim25.ManagedObjectReference root, java.lang.String[][] typeinfo, boolean recurse)
          Retrieve content recursively with multiple properties.
 com.vmware.vim25.ManagedObjectReference getDecendentMoRef(com.vmware.vim25.ManagedObjectReference root, java.lang.String type, java.lang.String name)
          Get the ManagedObjectReference for an item under the specified root folder that has the type and name specified.
 java.util.ArrayList getDecendentMoRefs(com.vmware.vim25.ManagedObjectReference root, java.lang.String type)
          Retrieve all the ManagedObjectReferences of the type specified.
 java.util.ArrayList getDecendentMoRefs(com.vmware.vim25.ManagedObjectReference root, java.lang.String type, java.lang.String[][] filter)
           
 java.lang.Object getDynamicProperty(com.vmware.vim25.ManagedObjectReference mor, java.lang.String propertyName)
          Retrieve a single object
 com.vmware.vim25.ManagedObjectReference getFirstDecendentMoRef(com.vmware.vim25.ManagedObjectReference root, java.lang.String type)
          Get the first ManagedObjectReference from a root of the specified type
 com.vmware.vim25.ManagedObjectReference getMoRefProp(com.vmware.vim25.ManagedObjectReference objMor, java.lang.String propName)
          Get a MORef from the property returned.
 com.vmware.vim25.ObjectContent[] getObjectProperties(com.vmware.vim25.ManagedObjectReference collector, com.vmware.vim25.ManagedObjectReference mobj, java.lang.String[] properties)
          Retrieve contents for a single object based on the property collector registered with the service.
 void init(AppUtil cb, ServiceConnection svc)
           
protected  void updateValues(java.lang.String[] props, java.lang.Object[] vals, com.vmware.vim25.PropertyChange propchg)
           
 java.lang.String waitForTask(com.vmware.vim25.ManagedObjectReference taskmor)
           
 java.lang.Object[] waitForValues(com.vmware.vim25.ManagedObjectReference objmor, java.lang.String[] filterProps, java.lang.String[] endWaitProps, java.lang.Object[][] expectedVals)
          Handle Updates for a single object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceUtil

public ServiceUtil()
Method Detail

CreateServiceUtil

public static ServiceUtil CreateServiceUtil()

init

public void init(AppUtil cb,
                 ServiceConnection svc)
          throws java.lang.Exception
Throws:
java.lang.Exception

clientConnect

public void clientConnect()
                   throws java.lang.Exception
Connect to the service

Throws:
java.lang.Exception

clientLoadSession

public void clientLoadSession(java.lang.String cookieString)
                       throws java.lang.Exception
Throws:
java.lang.Exception

clientSaveSession

public void clientSaveSession(java.lang.String fileName)
                       throws java.lang.Exception
Throws:
java.lang.Exception

clientDisconnect

public void clientDisconnect()
                      throws java.lang.Exception
Disconnect from the service

Throws:
java.lang.Exception

getDecendentMoRef

public com.vmware.vim25.ManagedObjectReference getDecendentMoRef(com.vmware.vim25.ManagedObjectReference root,
                                                                 java.lang.String type,
                                                                 java.lang.String name)
                                                          throws java.lang.Exception
Get the ManagedObjectReference for an item under the specified root folder that has the type and name specified.

Parameters:
root - a root folder if available, or null for default
type - type of the managed object
name - name to match
Returns:
First ManagedObjectReference of the type / name pair found
Throws:
java.lang.Exception

getFirstDecendentMoRef

public com.vmware.vim25.ManagedObjectReference getFirstDecendentMoRef(com.vmware.vim25.ManagedObjectReference root,
                                                                      java.lang.String type)
                                                               throws java.lang.Exception
Get the first ManagedObjectReference from a root of the specified type

Parameters:
root - a root folder if available, or null for default
type - the type of the entity - e.g. VirtualMachine
Returns:
managed object reference available
Throws:
java.lang.Exception

getDecendentMoRefs

public java.util.ArrayList getDecendentMoRefs(com.vmware.vim25.ManagedObjectReference root,
                                              java.lang.String type)
                                       throws java.lang.Exception
Retrieve all the ManagedObjectReferences of the type specified.

Parameters:
root - a root folder if available, or null for default
type - type of container refs to retrieve
Returns:
List of MORefs
Throws:
java.lang.Exception

getDecendentMoRefs

public java.util.ArrayList getDecendentMoRefs(com.vmware.vim25.ManagedObjectReference root,
                                              java.lang.String type,
                                              java.lang.String[][] filter)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

getAllContainerContents

public com.vmware.vim25.ObjectContent[] getAllContainerContents()
                                                         throws java.lang.Exception
Retrieve Container contents for all containers recursively from root

Returns:
retrieved object contents
Throws:
java.lang.Exception

getContentsRecursively

public com.vmware.vim25.ObjectContent[] getContentsRecursively(com.vmware.vim25.ManagedObjectReference root,
                                                               boolean recurse)
                                                        throws java.lang.Exception
Retrieve container contents from specified root recursively if requested.

Parameters:
root - a root folder if available, or null for default
recurse - retrieve contents recursively from the root down
Returns:
retrieved object contents
Throws:
java.lang.Exception

getContentsRecursively

public com.vmware.vim25.ObjectContent[] getContentsRecursively(com.vmware.vim25.ManagedObjectReference collector,
                                                               com.vmware.vim25.ManagedObjectReference root,
                                                               java.lang.String[][] typeinfo,
                                                               boolean recurse)
                                                        throws java.lang.Exception
Retrieve content recursively with multiple properties. the typeinfo array contains typename + properties to retrieve.

Parameters:
collector - a property collector if available or null for default
root - a root folder if available, or null for default
typeinfo - 2D array of properties for each typename
recurse - retrieve contents recursively from the root down
Returns:
retrieved object contents
Throws:
java.lang.Exception

getMoRefProp

public com.vmware.vim25.ManagedObjectReference getMoRefProp(com.vmware.vim25.ManagedObjectReference objMor,
                                                            java.lang.String propName)
                                                     throws java.lang.Exception
Get a MORef from the property returned.

Parameters:
objMor - Object to get a reference property from
propName - name of the property that is the MORef
Returns:
ManagedObjectReference.
Throws:
java.lang.Exception

getObjectProperties

public com.vmware.vim25.ObjectContent[] getObjectProperties(com.vmware.vim25.ManagedObjectReference collector,
                                                            com.vmware.vim25.ManagedObjectReference mobj,
                                                            java.lang.String[] properties)
                                                     throws java.lang.Exception
Retrieve contents for a single object based on the property collector registered with the service.

Parameters:
collector - Property collector registered with service
mobj - Managed Object Reference to get contents for
properties - names of properties of object to retrieve
Returns:
retrieved object contents
Throws:
java.lang.Exception

getDynamicProperty

public java.lang.Object getDynamicProperty(com.vmware.vim25.ManagedObjectReference mor,
                                           java.lang.String propertyName)
                                    throws java.lang.Exception
Retrieve a single object

Parameters:
mor - Managed Object Reference to get contents for
propertyName - of the object to retrieve
Returns:
retrieved object
Throws:
java.lang.Exception

waitForTask

public java.lang.String waitForTask(com.vmware.vim25.ManagedObjectReference taskmor)
                             throws java.lang.Exception
Throws:
java.lang.Exception

waitForValues

public java.lang.Object[] waitForValues(com.vmware.vim25.ManagedObjectReference objmor,
                                        java.lang.String[] filterProps,
                                        java.lang.String[] endWaitProps,
                                        java.lang.Object[][] expectedVals)
                                 throws java.lang.Exception
Handle Updates for a single object. waits till expected values of properties to check are reached Destroys the ObjectFilter when done.

Parameters:
objmor - MOR of the Object to wait for
filterProps - Properties list to filter
endWaitProps - Properties list to check for expected values these be properties of a property in the filter properties list
expectedVals - values for properties to end the wait
Returns:
true indicating expected values were met, and false otherwise
Throws:
java.lang.Exception

updateValues

protected void updateValues(java.lang.String[] props,
                            java.lang.Object[] vals,
                            com.vmware.vim25.PropertyChange propchg)

buildFullTraversal

public com.vmware.vim25.SelectionSpec[] buildFullTraversal()
This method creates a SelectionSpec[] to traverses the entire inventory tree starting at a Folder

Returns:
The SelectionSpec[]

buildPropertySpecArray

public com.vmware.vim25.PropertySpec[] buildPropertySpecArray(java.lang.String[][] typeinfo)
This code takes an array of [typename, property, property, ...] and converts it into a PropertySpec[]. handles case where multiple references to the same typename are specified.

Parameters:
typeinfo - 2D array of type and properties to retrieve
Returns:
Array of container filter specs