Property Provider
Adapters
Queries to a
Property Provider Adapter accept one or more specific vSphere objects, and
return one or more properties for those objects. A Property Provider Adapter
registers with the Data Service to advertise which types of properties it can
return. When the Data Service receives a query for one of the registered
property types, the Data Service routes the query to the appropriate Property
Provider Adapter for processing.
You may not register a
provider for an existing VMware property or object type. For example, if your
solution needs to identify a host by an alternate name, you may create an
adapter to implement a property such as
alt_name
, but it may not modify the original
name
property.
PropertyProviderAdapter
Interface
PropertyProviderAdapter
InterfaceA Property Provider Adapter
must implement the
PropertyProviderAdapter
interface of the
com.vmware.vise.data.query
package. The
PropertyProviderAdapter
interface publishes a single method named
getProperties()
. Your
Property Provider Adapter service must provide an implementation of this
method. The Data Service calls the
getProperties()
method
of your adapter in response to an appropriate query for the properties your
adapter is registered to provide.
The method implementation in
your service must accept as its parameter an object of type
com.vmware.vise.data.query.PropertyRequestSpec
,
and must return an object of type
com.vmware.vise.data.query.ResultSet
.
public ResultSet getProperties(PropertyRequestSpec propertyRequest)
Your service implementation of
the
getProperties()
method
can retrieve and format data in any way you choose. However, your
implementation must return the results as a
ResultSet
object. You
use the
PropertyRequestSpec
object to obtain the query list of target vSphere objects and desired
properties. The
PropertyRequestSpec
object contains an objects array and a properties array, which respectively
contain the target vSphere objects and requested properties.
For additional information on
ResultSet
,
PropertyRequestSpec
,
and other features in the
com.vmware.vise.data.query
package, see the Java API reference included in the SDK.
Registering a Property
Provider Adapter
You must register your
Property Provider Adapter for the adapter to work with the Data Service. You
register your Property Provider Adapter with the Data Service by using the
DataServiceExtensionRegistry
service. The
DataServiceExtensionRegistry
service contains a method named
registerDataAdapter()
that you must call to register your Property Provider Adapter.
A best practice for
registering your adapter is to pass
DataServiceExtensionRegistry
as a parameter to your Property Provider Adapter class constructor, and call
registerDataAdapter()
from that constructor.
Property Provider
Adapter
The following example shows a
Property Provider Adapter class. The class constructor method registers the
adapter with the Data Service.
The class constructor method
MyAdapter()
constructs an array of property types that the adapter can supply to the Data
Service in the array named
providerTypes
. The
constructor then calls the Data Service Extension Registry method named
registerDataAdapter
to
register the Property Provider Adapter with the Data Service. The Data Service
calls the override method
getProperties()
when the Data
Service receives a query for the kinds of properties that were specified at
registration. The
getProperties()
method must
retrieve the necessary properties, format them as a
ResultSet
object, and return that
ResultSet
.
package com.myAdapter.PropertyProvider; import com.vmware.vise.data.query; import com.vmware.vise.data.query.PropertyProviderAdapter; import com.vmware.vise.data.query.ResultSet; import com.vmware.vise.data.query.type; public class MyAdapter implements PropertyProviderAdapter { public MyAdapter(DataServiceExtensionRegistry extensionRegistry) { TypeInfo vmTypeInfo = new TypeInfo(); vmTypeInfo.type = "VirtualMachine"; vmTypeInfo.properties = new String[] { "myVMdata" }; TypeInfo[] providerTypes = new TypeInfo[] {vmTypeInfo}; extensionRegistry.registerDataAdapter(this, providerTypes); } @Override public ResultSet getProperties(PropertyRequestSpec propertyRequest) { // Logic to retrieve properties and return as result set ... } }