A Property Provider Adapter must implement the PropertyProviderAdapter interface in the
com.vmware.vise.data.query Java SDK 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 your adapter’s
getProperties() method 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.
Your service’s 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’s 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 vSphere Web Client SDK.
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.
Example 11-46, on page 97, shows an example of a Property Provider Adapter class. The class constructor method registers the adapter with the Data Service.
In Example: Example Property Provider Adapter Class, 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.
A Data Provider Adapter must implement the DataProviderAdapter interface in the
com.vmware.vise.data.query Java SDK package. The
DataProviderAdapter interface publishes a single method named
getData(). Your Data Provider Adapter service must provide an implementation of this method. The Data Service calls your adapter’s
getData() method in response to the queries your adapter is registered to process.
Your implementation of the getData() method must accept an object of type
com.vmware.vise.data.query.RequestSpec as a parameter, and must return an object of type
com.vmware.vise.data.query.Response.
The RequestSpec object parameter to the
getData() method contains an array of Data Service query objects. Each query contains a target object and one or more constraints that define the information that the client requests, as well as the expected format for results.
Your getData() method determines what information it must fetch by processing each Data Service query and handling the included constraints. The
getData() method must then retrieve that information, through whatever means your data source provides, such as a database query or a remote device method.
Your getData() method must format the retrieved information as a specific result type for each query, and then return those results as an array, packaged in a
Response object.
Data Service queries are passed to your Data Service Adapter through the com.vmware.data.query.RequestSpec object parameter. A
RequestSpec object consists of an array of objects of type
com.vmware.data.query.QuerySpec, each of which represents an individual query.
Each QuerySpec object defines the query target, the query constraints, and the expected formatting for the query results.
The query target is the object for which your getData() method must retrieve information. In the QuerySpec object, the target is represented as an object of type
com.vmware.data.query.ResourceSpec
Your getData() method can determine what information it must retrieve by using the values in the
ResourceSpec object. The
ResourceSpec object specifies the target object as a
String type, which contains a URI for the target object. The requested properties are contained in an object of type
com.vmware.data.query.PropertySpec.
Within the QuerySpec object, the query constraints are represented as an object of type
com.vmware.data.query.Constraint. A query can specify the following types of constraints, each of which is a subclass of the base
Constraint class.
■
|
ObjectIdentityConstraint. Queries based on this constraint retrieve the properties of a known target object. For example, a query might retrieve the powered-on state of a given virtual machine. The object identifier can be any type that implements the IResourceReference interface.
|
■
|
PropertyConstraint. Queries based on this constraint retrieve all objects with a given property value. For example, a query might retrieve all virtual machine objects with a power state of on. This constraint accepts the property name and comparator as strings, and the property value as an Object. PropertyConstraint is roughly analogous to a SELECT statement in a database query.
|
■
|
RelationalConstraint. Queries based on this constraint retrieve all objects that match the specified relationship with a given object. For example, a query might retrieve all virtual machine objects related to a given host object. RelationalConstraint is roughly analogous to a JOIN statement in a database query.
|
■
|
CompositeConstraint. Composite queries allow the combination of multiple constraints using the and or or operator, passed as a string. The combined subconstraints in CompositeConstraint are contained in an array of Constraint objects.
|
In the QuerySpec object, the expected formatting for the query results are included in an object of type
com.vmware.data.query.ResultSpec. The properties of the
ResultSpec object specify a maximum number of results for the query to return, provide an offset into the returned results, and set ordering for the returned results. Your
getData() method must use the values of the
ResultSpec properties to format the information it has retrieved.
The class you create to implement ResourceTypeResolver must support the following methods.
The getResourceType() method must parse a URI and return a
String containing the type of custom object to which the URI pertains. For example, for a URI that referred to a custom Chassis object, the
getResourceType() method must return the
String samples:Chassis.
The getServerGuid() method must parse a URI and return a
String containing the server global unique identifier for the URI target object. For example, for the URI string
urn:cr:samples:Chassis:server1/ch-2, the
getServerGuid() method must return the string
server1.
Example: Example Data Provider Adapter Class, shows an example of how to register a Resource Type Resolver.
To declare the service as an OSGI bundle, you must define your adapter’s Java service as a Java Bean in the bundle-context.xml file. You can find the
bundle-context.xml file your plug-in module’s
src/main/resources/META-INF/spring folder.
The name attribute is an identifier that you choose for the Java Bean. You must set the value of the
class attribute to the fully qualified class name of the Java class you have created that implements the
DataProviderAdapter interface.
After you define your Data Provider Adapter as a Java Bean, you must modify the bundle-context-osgi.xml file to include the Java Bean as an OSGI service. The
bundle-context-osgi.xml file is in your plug-in module’s
src/main/resources/META-INF/spring folder.
The id attribute is an identifier that you choose for the Data Provider Adapter. You must set the value of the
ref attribute to the same value as the
name attribute that you defined when declaring your Java Bean. The
interface attribute must be set to the fully qualified class name of the
DataProviderAdapter interface.
You must update the src/main/resources/META-INF/MANIFEST.MF file to reflect any Java packages from the vSphere Web Client SDK that your Data Provider Adapter imports. You add the imported packages to the
import-packages section of the
MANIFEST.MF file.
In Example 11-47, on page 102, the example Data Provider Adapter imports the packages
com.vmware.vise.data.uri and
com.vmware.data.query. For the example, the
MANIFEST.MF file must list those packages in the
import-package section.
For example, if you have a custom object of type WhatsIt, you annotate the class like the following example:
For each service your Data Provider Adapter includes, you must add a <constructor-arg> element to your adapter’s Bean definition. In each
<constructor-arg> element, you set the
ref attribute to the same value as the
id attribute in the
<osgi:reference> element in the
bundle-context-osgi.xml file.
You can register your Data Provider Adapter with the Data Service by using the DataServiceExtensionRegistry service.
DataServiceExtensionRegistry contains a
registerDataAdapter() method that you must call to register your Data Provider Adapter.
A common way to register your adapter is to pass DataServiceExtensionRegistry as a parameter to your Data Provider Adapter class constructor, and call
registerDataAdapter() from within that constructor.
Example 11-47, on page 102, presents an example of a Data Provider Adapter class that supports hypothetical
WhatsIt objects. In the example, the class constructor method initializes the class member variables for the Data Service and registers a Resource Type Resolver. The example assumes that the Data Provider Adapter is registered implicitly by registering the service as an OSGI bundle. The Data Service and Resource Type Resolver Registry services are passed as arguments to the class constructor.
The getData() method is called by the vSphere Web Client Data Service when it receives a query for one of the objects or properties specified at registration. In the
getData() method, your Data Provider Adapter must parse the query, compute the results, and return that result data as a
Response object. For a more complete example, see the
ChassisDataAdapter class in the SDK.