Invalid property? A Trick With vSphere PropertyCollector

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.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? 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.

This entry was posted in vSphere API and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. getPropertiesByPaths
    Posted September 2, 2010 at 3:32 pm | Permalink

    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
    Posted September 2, 2010 at 3:34 pm | Permalink

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

    Regards,
    Tulsi

  3. Tulsi
    Posted September 2, 2010 at 3:54 pm | Permalink

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

  4. Posted September 3, 2010 at 10:15 am | Permalink

    Hi Tulsi,

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

    Steve

  5. Tulsi
    Posted September 3, 2010 at 2:03 pm | Permalink

    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. Posted September 5, 2010 at 1:25 am | Permalink

    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
    Posted September 6, 2010 at 2:06 am | Permalink

    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
    Posted September 6, 2010 at 10:36 am | Permalink

    Hi Steve,

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

    Thank you.

    Regards,
    Tulsi

  9. amogh
    Posted January 14, 2013 at 3:26 am | Permalink

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  • NEED HELP?


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.