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


Ignore:
Timestamp:
Jan 12, 2017, 12:03:09 PM (8 years ago)
Author:
Nicklas Nordborg
Comment:

Started to write the "How to use" documentation

Legend:

Unmodified
Added
Removed
Modified
  • net.sf.basedb.opengrid/using

    v1 v1  
     1= How to use the Open Grid Scheduler package API =
     2
     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.
     4
     5== Enumerating Open Grid Clusters ==
     6
     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.
     8
     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, `griduser@grid.example.com:22`). 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.
     10
     11'''Java code in a servlet running on the BASE web server'''
     12{{{
     13DbControl dc = ... // We need an open DbControl from BASE
     14
     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();
     18options.enable(JSONOption.CLUSTER_INFO);
     19options.enable(JSONOption.NODE_INFO);
     20
     21OpenGridService service = OpenGridService.getInstance();
     22JSONArray jsonHosts = new JSONArray();
     23
     24// Enumerates all clusters that the current user has access to
     25for (OpenGridCluster host : service.getClusters(dc, Include.ALL))
     26{
     27   jsonHosts.add(host.asJSONObject(options));
     28}
     29
     30return jsonHosts; // This is what we transfer to the web client via AJAX
     31}}}
     32
     33'''!JavaScript code running in the web browser the current user is using'''
     34{{{
     35// In the web client use the JSON data to populate a <select> list
     36var list = document.getElementById('cluster-list');
     37list.length = 0;
     38
     39var clusters = response; // Response contains an array with cluster information
     40for (var i = 0; i < clusters.length; i++)
     41{
     42   var cluster = clusters[i];
     43   var option = new Option(cluster.connection.name, cluster.id);
     44   option.cluster = cluster;
     45   list[list.length] = option;
     46}
     47}}}
     48
     49Note that there is no need to use the `OpenGridCluster.connect()` method yet.
     50
     51== Creating a job script ==
     52
     53== Submitting a job ==
     54
     55== Getting notified when a job completes ==
     56
     57== Aborting jobs ==
     58
     59== Advanced usage ==
     60