Creating Data View Extensions

When you create data view extensions for the
vSphere Client
user interface layer, follow these general recommendations:
  • You do not need to change the Data Adapter services running in the service layer.
  • You can use the generic
    DataAccessController
    Java class provided with each generated plug-in project to handle HTTP JSON
    GET
    data requests.
  • You must access data through the
    vSphere Client
    server and avoid calling directly your back end services or database.

Common Data Access Pattern

You can use the pattern demonstrated in the
html-sample
in the SDK to access data from the
vCenter Server
system from your plug-ins:
  • The Ajax
    GET
    request created in your JavaScript code has the following format:
    /
    plugin_context_path
    /rest/data/properties/
    objectId
    ?properties=
    properties-list
    , where
    objectId
    is the object ID of the currently selected vSphere object, and
    properties-list
    is the comma-separated list of properties that must be retrieved for that object.
  • The
    web.xml
    deployment descriptor located in the
    WEB-INF
    folder of the UI bundle of your plug-in contains the
    <servlet-mapping>
    element that defines the
    /rest/*
    URL pattern for invoking the
    springServlet
    servlet.
    <servlet-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
  • The
    bundle-context.xml
    file located in the
    WEB-INF\spring
    folder declares the
    dataAccessController
    bean for the
    DataAccessController
    class that is available in the Java service bundle of your plug-in.
    <bean name="dataAccessController" class="com.vmware.samples.vspherewssdk.mvc.DataAccessController" />
  • The
    DataAccessController
    class included in the Java service bundle of your plug-in has the
    @RequestMapping
    annotation set to process the HTTP JSON
    GET
    for the
    /data
    endpoint. The
    getProperties()
    generic method has the
    @RequestMapping
    annotation set to the
    /properties/{objectId}
    value to handle the Ajax
    GET
    requests created in your JavaScript code.
    ... @Controller @RequestMapping(value = "/data", method = RequestMethod.GET) public class DataAccessController { ... @RequestMapping(value = "/properties/{objectId}") @ResponseBody public Map<String, Object> getProperties( @PathVariable("objectId") String encodedObjectId, @RequestParam(value = "properties", required = true) String properties) ...
  • The
    getProperties()
    generic method uses the
    QueryUtil
    class to create a Data Service query for the requested list of vSphere object properties. The query results are returned to the Web browser as JSON data.
    ... Object ref = getDecodedReference(encodedObjectId); String objectId = _objectReferenceService.getUid(ref); String[] props = properties.split(","); PropertyValue[] pvs = QueryUtil.getProperties(_dataService, ref, props); Map<String, Object> propsMap = new HashMap<String, Object>(); propsMap.put(OBJECT_ID, objectId); for (PropertyValue pv : pvs) { propsMap.put(pv.propertyName, pv.value); } return propsMap; }
  • The JavaScript code can display the data returned by the Ajax
    GET
    request as needed.