Registering a Data Provider Adapter

You must register your Data Provider Adapter for the adapter to work with the Data Service. You can register an adapter implicitly by declaring the Java service as an OSGi bundle, or you can register an adapter explicitly by using the Data Service Extension Registry service.

Registering Implicitly

You can register your Data Provider Adapter implicitly when you add the adapter to the application server framework. To use implicit registration, you must declare the Java service that implements your Data Provider Adapter as an OSGi bundle when you add the service to the application server framework. The
vSphere Web Client
and the
vSphere Client
detect new OSGi bundles as they are added and register the Data Provider Adapters with the Data Service. You must also annotate the adapter class with the object types that the adapter supports.

Declaring the Service as an OSGi Bundle

To declare the service as an OSGi bundle, you must define Java service of your adapter as a Java Bean in the
bundle-context.xml
file. You can find the
bundle-context.xml
file in the
src/main/resources/META-INF/spring
folder of your plug-in module.
To define the Java Bean, you must add the following XML element to the
bundle-context.xml
file.
<bean name="MyDataProviderImpl" class="com.example.MyDataProviderAdapter"> </bean>
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 the
src/main/resources/META-INF/spring
folder of your plug-in module.
You must add the following XML element to the
bundle-context-osgi.xml
file.
<osgi:service id="MyDataProvider" ref="MyDataProviderImpl" interface="com.vmware.vise.data.query.DataProviderAdapter" />
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 SDK that your Data Provider Adapter imports. You add the imported packages to the
Import-Package
manifest header of the
MANIFEST.MF
file.
In Data Provider Adapter Example, the example Data Provider Adapter imports the packages
com.vmware.vise.data.uri
and
com.vmware.data.query
. The packages are listed by using the
Import-Package
OSGi manifest header in the
MANIFEST.MF
file.
Import-Package: org.apache.commons.logging, com.vmware.vise.data, com.vmware.vise.data.query, com.vmware.vise.data.uri

Annotating the Adapter Class

You must annotate your Data Provider Adapter class with the object types for which the adapter processes queries. The
vSphere Web Client
and the
vSphere Client
use these annotations to route queries for the specific types to the correct adapters. You use the
@type
annotation to define the vSphere object type for which the adapter processes queries.
For example, if you have a custom object of type
WhatsIt
, you annotate the class in the following way.
@type("samples:WhatsIt") // declares the supported object types public class MyAdapter implements DataProviderAdapter { ...

Passing Arguments to Your Class Constructor

Most Data Provider Adapters use other OSGi services that the SDK provides. These services include the base Data Service, the Resource Type Resolver Registry, and the vSphere Object Reference Service. You can pass these OSGi services to your Data Provider Adapter as arguments to the Data Provider Adapter class constructor method.
All Data Provider Adapters can include the Data Service. To include the Data Service as an argument to your Data Provider Adapter class constructor, you add the following element to the
bundle-context-osgi.xml
file of your service.
<osgi:reference id="dataService" interface="com.vmware.vise.data.query.DataService" />
Making Data Service queries from within a Data Service provider can impact the performance of your provider. A best practice is to use the vSphere Web Services API to fetch data from vCenter Server, because it is more efficient than Data Services.
If your Data Provider Adapter handles queries for multiple custom object types, you must include the Resource Type Resolver Registry OSGi service and register a Resource Type Resolver. To include the Resource Type Resolver Registry OSGi service as an argument to your Data Provider Adapter class constructor, you add the following element to the
bundle-context-osgi.xml
file of your service.
<osgi:reference id="uriRefTypeAdapter" interface="com.vmware.vise.data.uri.ResourceTypeResolverRegistry" />
If your Data Provider Adapter handles queries for built-in vSphere object types, such as Hosts or Virtual Machines, you can include the vSphere Object Reference Service. To pass the vSphere Object Reference Service as an argument to your Data Provider Adapter class constructor, you add the following element to the
bundle-context-osgi.xml
file of your service.
<osgi:reference id="vimObjectReferenceService" interface="com.vmware.vise.vim.data.VimObjectReferenceService" />
Your Data Provider Adapter can use the User Session Service to get information about the current user session. To pass the User Session Service as an argument to your Data Provider Adapter class constructor, you add the following element to the
bundle-context-osgi.xml
file of your service.
<osgi: reference id="userSessionService" interface="com.vmware.vise.usersession.UserSessionService" />
If you pass OSGi services to your Data Provider Adapter class constructor, you must include those constructor arguments when you declare your Data Provider Adapter as a Java Bean in the
bundle-context.xml file
. See Declaring the Service as an OSGi Bundle.
For each service your Data Provider Adapter includes, you must add a
<constructor-arg>
element to the Bean definition of your adapter. 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.
If your Data Provider Adapter uses the Data Service, vSphere Object Reference Service, Resource Type Resolver Registry, and User Session Service, the Bean definition might appear as follows.
<bean name="MyDataProviderImpl" class="com.example.MyDataProviderAdapter"> <constructor-arg ref="dataService"/> <constructor-arg ref="uriRefTypeAdapter"/> <constructor-arg ref="vimObjectReferenceService"/> <constructor-arg ref="userSessionService"/> </bean>

Registering Explicitly

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.