Home > vSphere API > Invalid property? A Trick With vSphere PropertyCollector

Invalid property? A Trick With vSphere PropertyCollector

April 14th, 2010 Leave a comment Go to comments

As I discussed extensively in my book, the PropertyCollector is very powerful yet not easy to use. There was a question posted at vSphere Java API forum related to the property collector which I think worths sharing here. Although it’s found using vSphere Java API, but it really goes beyond the API to the vSphere API itself.

The problem was not able to retrieve the info.vmfs property of a Datastore managed object using vSphere Java API, but OK with others like info.freeSpace, info.maxFileSize, info.name, etc. If MOB is used, the info.vmfs can be retrieved without any problem.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

HTML5 App

vSphere Java API wraps up the PropertyCollector using getter methods for all the direct properties in very managed object. Mostly you don’t need to touch the PropertyCollector at all.

In some cases, you do want to get hold of the sub properties directly to save CPU cycle and bandwidth. That is why I decided to open up the getPropertyByPath() method with which you can provide the property path and get the value in one call.

Now, what is the cause of the problem?

It’s related the typing of the property. The info property is typed as DatastoreInfo. It does NOT have a sub property called vmfs. But DatastoreInfo is an abstract type which is extended to VmfsDatastoreInfo which does have vmfs sub property. There are other possibilities, for example, DatastoreInfo to NasDatastoreInfo which does NOT have vmfs sub property at all. So before being certain about the real type, we cannot request for info.vmfs.

How to solve this issue?

It’s pretty easy. You want to get the info with getInfo() method, and check the instance type before casting it to VmfsDatastoreInfo. Once it’s casted, you can use the vmfs as easy as one getVmfs() call.

For future tricks and tips, feel free to subscribe to this feed, and follow me at Twitter.

  1. getPropertiesByPaths
    September 2nd, 2010 at 15:32 | #1

    Hi Steve,

    Thanks for the wonderful API. I’m still reading your VMware VI and vSphere SDK book.

    I was going through the PropertyCollector and especially liked the getPropertiesByPaths method. I tried to get multiple properties in one go (and in my observation) it came out throwing InvalidProperty exception when one of the property paths was incorrect. I didn’t get values for the other valid ones as well. Is there a way to check if a “property path is valid” before we call getPropertiesByPaths? or Is there a way to get the valid property paths for a given ManagedEntity?

    Thanks you.

    Regards,
    Tulsi (Thulasinathan Kandasamy)

  2. Tulsi
    September 2nd, 2010 at 15:34 | #2

    Oops. I pasted the method-name (getPropertiesByPaths) instead of my name. :)

    Regards,
    Tulsi

  3. Tulsi
    September 2nd, 2010 at 15:54 | #3

    I got another question. Is there a way to get specific types of ManagedEntities that have given values for the given properties?

  4. September 3rd, 2010 at 10:15 | #4

    Hi Tulsi,

    Do you want to get type information or a collection of instances of a specific type?

    Steve

  5. Tulsi
    September 3rd, 2010 at 14:03 | #5

    Hi Steve,

    I want to get the type information. Say, for a ManagedEntity type like “HostSystem” I want to know all the supported/valid property-paths like below
    name
    summary.config.product.apiType
    summary.hardware.numNics
    etc.,

    Regards,
    Tulsi

  6. September 5th, 2010 at 01:25 | #6

    Hi Tulsi,

    There is no API for this metadata. You can however get these information by using vijava + Java reflection API. For HostSystem type, you can find methods like “getSummary().” For each of these methods, you get the property names like summary, and the types as return of the methods. Further inspecting these property types, you can get all the sub-properties.

    Hope it helps.

    -Steve

  7. Tulsi
    September 6th, 2010 at 02:06 | #7

    Hi Steve,

    Thank you for your response.

    I did that already. However after building the String array of property paths, when I tried to retrieve the property values using PropertyCollectorUtil.retrieveProperties(…) or getPropertiesByPaths(…) it throws InvalidProperty Exception. It may be due to some value related problem (null?) or the version mismatch between the API and server.

    That’s why I got the question to see if we can validate whether a given property-path is valid or not. So that, we can avoid asking the value for that property-path when we make a call (to get the retrieveProperties or getPropertiesByPath/s).

    In order to do this validation, if we use something like getPropertyByPath to see if it does/doesn’t throw exception then decide that it is a invalid/valid property then that will lot of calls to the server.

    In short, I’m trying to do the following

    Step-1: /* build property paths array using VI Java + Java-Reflection API */
    Step-2: /* send the property paths for HostSystem or VirtualMachine etc., and get the values in one go */
    Step-3: /* process the values */

    I keep getting InvalidProperty exceptions in Step-2

    Regards,
    Tulsi

  8. Tulsi
    September 6th, 2010 at 10:36 | #8

    Hi Steve,

    The project was referring to an older version of the API. It is working now.

    Thank you.

    Regards,
    Tulsi

  9. amogh
    January 14th, 2013 at 03:26 | #9

    Hi Steve,
    i want to retrive the resourcepool uuid.. what is the code for it?
    and how to exceute propertycollector util class?

  1. No trackbacks yet.