[ovirt-devel] oVirt.js GWT wrapper prototype

Vojtech Szocs vszocs at redhat.com
Tue Jun 24 11:29:26 UTC 2014


Hello everyone,

following the announcement of oVirt.js prototype, I've developed a sample
GWT wrapper that provides Java API to oVirt.js for all GWT applications.

Please find the GWT wrapper patch attached. It bundles oVirt.js & Lo-Dash
libraries via GWT module (SdkGwtWrapper) providing Java-like API based on
oVirt.js.

In order for WebAdmin to use oVirt.js GWT wrapper, all we have to do is
add following into WebAdmin.gwt.xml (GWT module descriptor):

  <inherits name="org.ovirt.engine.sdk.gwt.SdkGwtWrapper" />

and add following into pom.xml (Maven project descriptor):

  <dependency>
    <groupId>${engine.groupId}</groupId>
    <artifactId>ovirt-js-gwt-wrapper</artifactId>
    <version>${engine.version}</version>
    <scope>provided</scope>
  </dependency>

and that's it.

The Java API takes inspiration from oVirt.js API. For example, to add
new DataCenter:

  // Create data object template, 'name' and 'local' are required.
  DataCenterTemplate dcTemplate = DataCenterTemplate.create(
    "test-dc", // name
    false // local
  );
  // Set optional parameters such as 'description', if necessary.
  dcTemplate.setDescription("my-desc");

  // Obtain DataCenter resource collection.
  ResourceCollection<DataCenter> dcColl = Sdk.get().api().getDataCenters();

  // Add new DataCenter by running 'add' operation on 'dcColl'.
  dcColl.add(dcTemplate).success(new SuccessCallback<DataCenter>() {
    @Override
    public void onSuccess(DataCenter dc) {
      Window.alert("Added: " + dc.getName());
    }
  }).run();

The concept of resource, resource collection and operation is the same
as presented in oVirt.js.

  dc.setName("test-dc-updated");
  dc.setDescription("test")
  dc.update().run(); // we could register 'success' callback here

You can see the full example by looking at SdkGwtWrapperTest class,
located in WebAdmin codebase (org.ovirt.engine.ui.webadmin.sdk_test).

Note that 'DataCenter' and 'DataCenterTemplate' will probably be
auto-generated from oVirt Engine REST API definition (XSD/RSDL).

As mentioned in my previous email, oVirt.js GWT wrapper ("overlay")
can be initially part of ovirt-engine repo, while oVirt.js project
deserves (in my opinion) a separate repo on its own.

Regards,
Vojtech
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oVirt.js-GWT-wrapper-prototype.patch
Type: text/x-patch
Size: 284491 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20140624/1c467d2c/attachment-0001.bin>


More information about the Devel mailing list