vSphere Java API Architecture Deep Dive

In my previous blog, I talked about the object model of the vSphere API. Many people like the UML diagram that illustrates how the managed objects are inherited from each other.

Following that blog, I will introduce the object model of the open source Java API that is built on top of the Web Services, as well as some key design decisions I made while designing the API.

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.

The following UML diagram is extracted from the overall model but adds much more details with properties and methods. If you can understand this diagram, you can then easily understand all other managed object types.

The ManagedObject class is not part of vSphere API, but added to vSphere Java API. It holds two private properties:

  • mor of type ManagedObjectReference — pointing to the ManagedObjectReference object that is used to represent a managed object in VI SDK.
  • serverConnection of type ServerConnection — pointing to the ServerConnection object I will cover later.

Besides accessors, the class has getCurrentProperty() method defined to encapsulate the PropertyCollector. This method gets called in subclasses to get a property. For example, the getName() in ManagedEntity called it like (String) getCurrentProperty(“name”); In most of cases, you don’t need to use it at all, I already provide explicit getter methods like getName() in concrete subclasses.

The ServerConnection, not part of vSphere API, is used to represent a connection to the server under a specific login user. It holds information like URL to the server, the userSession with username etc., and vimService which is the JUMBO interfaces with 300+ methods. For convenience, ServerConnection also has a reference to a ServiceInstance object.

Now let us take a look at the ServiceInstance type. It’s a special managed object and the first managed object you will have in a typical application logic flow. You can create a new ServiceInstance object by providing url/username/password, or url/sessionID combination. The later is not used as much as the first constructor, but very helpful when you develop a VI client plugin in Java.

According to the API Reference, the ServiceInstance has a ServiceContent object as its property, which holds all the ManagedObjectReferences to various “manager” attached to it, and an AboutInfo data object. Unlike Web Service interface, you can get any of them with a single call in Java API. ServiceContent object is, therefore, no long needed.

At the right side of the diagram are the ExtensibleManagedObject and its subclass ManagedEnity. ExtensibleManagedObject doesn’t have methods defined at all, but three properties. Therefore it only has three corresponding getters. As you will find in the overall UML diagram, it has many other subclasses, but I only list the ManagedEntity here.

ManagedEntity is one of the most important managed object type given that VirtualMachine, HostSystem etc. are all inherited from it. To search the inventory, I also provide a utility like class InventoryNavigator to group all the search methods to retrieve items in the inventory tree from a specified node. For example, you can easily find all the Virtual in one single call.

The above UML diagram and the overall diagram in previous blog should give you a pretty good picture about the object model and how key types are related to each other. If you really need to know more details about the Java API, please give it a try as described in the Getting Started Tutorial. There are also about 50 samples for you to continue learning.

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

2 Comments

  1. kim
    Posted February 11, 2013 at 5:08 am | Permalink

    i want to retrive monitors data,and attributes for one vm using vi java api, wt is the code for it?plz plz help me

  2. Posted February 11, 2013 at 2:03 pm | Permalink

    Hi Kim, you want to start with the Get Started tutorial on vijava.sf.net. My book is also a good starting point. Good luck!
    Steve

One Trackback

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.