5.7. Writing Your Own Job Manager

If the job managers provided by the Opal toolkit are not sufficient for your purposes, you can write your own job managers to submit jobs to your favorite scheduler. This section presents a brief tutorial on how to do so.

To write your own Opal job manager, you must implement the edu.sdsc.nbcr.opal.manager.OpalJobManager interface. One job manager is instantiated per job instance - i.e. for every run of an application, a new job manager is created. The OpalJobManager interface that 6 methods that must be implemented:

  1. The initialize method initializes the job manager, by setting a list of properties (key/value pairs), application configuration, and an optional handle. All job manager specific properties should be put inside $OPAL_HOME/etc/opal.properties. Opal will parse all the properties from opal.properties and make them available to the job manager.

        /**
         * @param props the properties file containing the value to configure this plugin
         * @param config the opal configuration for this application
         * @param handle manager specific handle to bind to, if this is a resumption. 
         *               NULL,if this manager is being initialized for the first time.
         * 
         * @throws JobManagerException if there is an error during initialization
         */
        public void initialize(Properties props,
    			   AppConfigType config,
    			   String handle)
    	throws JobManagerException;
  2. The destroyJobManager is for cleanup when the job manager is destroyed - all resources held should be freed here.

        /**
         * @throws JobManagerException if there is an error during destruction
         */
        public void destroyJobManager()
    	throws JobManagerException;
  3. The launchJob method is for launching a job with the given arguments. The input files are already staged in by the service implementation, and the job manager implementation can assume that they are already in the right location.

        /**
         * Launch a job with the given arguments. 
         *
         * @param argList a string containing the command line used to launch the application
         * @param numproc the number of processors requested. Null, if it is a serial job
         * @param workingDir String representing the working dir of this job on the local system
         * 
         * @return a plugin specific job handle to be persisted by the service implementation
         * @throws JobManagerException if there is an error during job launch
         */
        public String launchJob(String argList, 
    			    Integer numproc, 
    			    String workingDir)
    	throws JobManagerException;
  4. The waitForActivation method should block until the job has begun execution. Opal uses this information to collect job statistics.

        /**
         * @return status for this job after blocking
         * @throws JobManagerException if there is an error while waiting for the job to be ACTIVE
         */
        public StatusOutputType waitForActivation() 
    	throws JobManagerException;
  5. The waitForCompletion method should block until the application has finished execution.

        /**
         * @return final job status
         * @throws JobManagerException if there is an error while waiting for the job to finish
         */
        public StatusOutputType waitForCompletion() 
    	throws JobManagerException;
  6. The destroyJob method should kill an executing job.

        /**
         * @return final job status
         * @throws JobManagerException if there is an error during job destruction
         */
        public StatusOutputType destroyJob()
    	throws JobManagerException;

More information about the Java classes can be obtained from the Javadocs, which you can generate from $OPAL_HOME as follows:

    ant api-docs

This will generate documentation of the Opal API, which will be available in HTML form at $OPAL_HOME/docs/api/index.html.

We recommend that you implement your particular job manager inside the directory $OPAL_HOME/src/edu/sdsc/nbcr/opal/manager. There you will find other job managers that are available by default - you might want to look at the ForkJobManager as an example. You can compile your job manager with the rest of Opal, and install it within Tomcat by running the following commands:

    ant compile
    ant install