Changes between Initial Version and Version 1 of net.sf.basedb.opengrid/using

Jan 12, 2017, 12:03:09 PM (5 years ago)
Nicklas Nordborg

Started to write the "How to use" documentation


  • net.sf.basedb.opengrid/using

    v1 v1  
     1= How to use the Open Grid Scheduler package API =
     3In this document we will try to describe the main aspects of the programmatic API that other extensions can use in order to access and use Open Grid Clusters.
     5== Enumerating Open Grid Clusters ==
     7The `OpenGridService` class is typically the starting point for a lot of actions. From this class it is possible to get information about and access all cluster that has been defined in the `opengrid-config.xml` file. The service is a singleton instance. Use the `OpenGridService.getInstance()` method to get the object. Note! It is important that the service is actually running inside BASE. Check the '''Administrate->Services''' page that this is the case.
     9To enumerate the available Open Grid Clusters use one of the `OpenGridService.getClusters()` methods. This will return a collection of `OpenGridCluster` instances. Most methods in this class are used for getting configuration information from the `opengrid-config.xml` file. The `OpenGridCluster.getId()` method returns the internal ID of the cluster definition. It is created by combining the username, address and port of the cluster (for example, ``). The ID can the be used with `OpenGridService.getClusterById()` to directly access the same cluster later on. Other useful information can be found in the objects returned by calling `OpenGridCluster.getConnectionInfo()` and `OpenGridCluster.getConfig()`. The `OpenGridCluster.asJSONObject()` contains more or less the same information wrapped up as JSON data. This is useful for transferring information a web interface to allow a user to select a cluster to work with.
     11'''Java code in a servlet running on the BASE web server'''
     13DbControl dc = ... // We need an open DbControl from BASE
     15// Options specifying which (extra) information that we want to return
     16// Use JSONOptions.DEFAULT to only return the minimal information
     17JSONOptions options = new JSONOptions();
     21OpenGridService service = OpenGridService.getInstance();
     22JSONArray jsonHosts = new JSONArray();
     24// Enumerates all clusters that the current user has access to
     25for (OpenGridCluster host : service.getClusters(dc, Include.ALL))
     27   jsonHosts.add(host.asJSONObject(options));
     30return jsonHosts; // This is what we transfer to the web client via AJAX
     33'''!JavaScript code running in the web browser the current user is using'''
     35// In the web client use the JSON data to populate a <select> list
     36var list = document.getElementById('cluster-list');
     37list.length = 0;
     39var clusters = response; // Response contains an array with cluster information
     40for (var i = 0; i < clusters.length; i++)
     42   var cluster = clusters[i];
     43   var option = new Option(,;
     44   option.cluster = cluster;
     45   list[list.length] = option;
     49Note that there is no need to use the `OpenGridCluster.connect()` method yet.
     51== Creating a job script ==
     53== Submitting a job ==
     55== Getting notified when a job completes ==
     57== Aborting jobs ==
     59== Advanced usage ==