GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Job.java

Go to the documentation of this file.
00001 package org.gridlab.gat.resources;
00002 
00003 import java.io.IOException;
00004 import java.util.Map;
00005 
00006 import org.gridlab.gat.GATContext;
00007 import org.gridlab.gat.Preferences;
00008 import org.gridlab.gat.advert.Advertisable;
00009 import org.gridlab.gat.engine.GATEngine;
00010 import org.gridlab.gat.monitoring.Monitorable;
00011 import org.gridlab.gat.net.RemoteException;
00012 import org.gridlab.gat.resources.cpi.JobCpi;
00013 
00014 /**
00015  * An instance of this class represents a monitorable simple job, a job which
00016  * requires the start of a single executable and is monitorable.
00017  * <p>
00018  * A simple job is what one normally considers when referring to a starting a
00019  * program. Thus, a simple job is primarily described by the software which is
00020  * to execute during this simple job. The description of the software which is
00021  * to execute during this simple job is given by an instance of the class
00022  * SoftwareResourceDescription. As detailed in the description section of the
00023  * documentation for the class SoftwareResourceDescription, an instance of the
00024  * class SoftwareResourceDescription describes a software component. 
00025  * uses this description to describe the software which is to execute during
00026  * this simple job.
00027  * <p>
00028  * Upon creating an instance of the class  the associated physical job
00029  * is not immediately running. An instance of the class  has various
00030  * states which it can be in, only one of which maps to a running physical job.
00031  * In particular the various state are as follows
00032  * <ul>
00033  * <li><em>Constructed</em></li>
00034  * <li><em>Submitted</em></li>
00035  * <li><em>Running</em></li>
00036  * <li><em>Stopped</em></li>
00037  * </ul>
00038  * A description of the various states diagrammed in figure below is as follows:
00039  * <center><img src="doc-files/SimpleJob.jpg" height="600" width="150">
00040  * </center> <em>Constructed</em> An instance of the class  has been
00041  * constructed, but the method Submit has not yet been successfully called on
00042  * this instance.
00043  * <p>
00044  * <em>Submitted</em> The method Submit has been successfully called on an
00045  * instance of  while the instance was in the Constructed state.
00046  * <p>
00047  * <em>Running</em> The physical job corresponding to an instance of a
00048  *  is running.
00049  * <p>
00050  * <em>Stopped</em> The physical job corresponding to an instance of a
00051  *  was running but is not currently running due to a successful call
00052  * to the method Stop, or the physical job corresponding to an instance of a
00053  *  was running but is not currently running due to the physical job
00054  * completing.
00055  * <p>
00056  * In addition a  allows one or more Metrics to be monitored.
00057  */
00058 public abstract class Job implements Monitorable, Advertisable {
00059 
00060     /** Constructed state indicator */
00061     public static final int CONSTRUCTED = 1;
00062 
00063     /** Submitted state indicator */
00064     public static final int SUBMITTED = 2;
00065 
00066     /** Running state indicator */
00067     public static final int RUNNING = 4;
00068 
00069     /** Stopped state indicator */
00070     public static final int STOPPED = 8;
00071 
00072     /** Checkpointing state indicator */
00073     public static final int CHECKPOINTING = 16;
00074 
00075     private GATContext gatContext;
00076     private Preferences preferences;
00077     protected SoftwareResourceDescription softwareResourceDescription;
00078 
00079     /**
00080      * Constructs a  instance corresponding to the passed
00081      * SoftwareResourceDescription and GATContext
00082      * 
00083      * @param gatContext
00084      *            A GATContext used to broker resources
00085      * @param softwareResourceDescription
00086      *            A SoftwareResourceDescription describing the simple job's
00087      *            executable
00088      * @param preferences
00089      *            The Preferences for this instance
00090      * @throws java.lang.Exception
00091      *             Thrown upon creation problems
00092      */
00093     protected Job (GATContext gatContext, Preferences preferences, 
00094             SoftwareResourceDescription softwareResourceDescription) throws Exception {
00095         this.gatContext = gatContext;
00096         this.preferences = preferences;
00097         this.softwareResourceDescription = softwareResourceDescription;
00098     }
00099     
00100     /**
00101      * Constructs a  instance corresponding to the passed
00102      * SoftwareResourceDescription and GATContext
00103      * 
00104      * @param gatContext
00105      *            A GATContext used to broker resources
00106      * @param softwareResourceDescription
00107      *            A SoftwareResourceDescription describing the simple job's
00108      *            executable
00109      * @throws java.lang.Exception
00110      *             Thrown upon creation problems
00111      */
00112     public Job create(GATContext gatContext,
00113             SoftwareResourceDescription softwareResourceDescription)
00114             throws Exception {
00115         return create(gatContext, null, softwareResourceDescription);
00116     }
00117 
00118     /**
00119      * Constructs a  instance corresponding to the passed
00120      * SoftwareResourceDescription and GATContext
00121      * 
00122      * @param gatContext
00123      *            A GATContext used to broker resources
00124      * @param softwareResourceDescription
00125      *            A SoftwareResourceDescription describing the simple job's
00126      *            executable
00127      * @param preferences
00128      *            The Preferences for this instance
00129      * @throws java.lang.Exception
00130      *             Thrown upon creation problems
00131      */
00132     public Job create(GATContext gatContext, Preferences preferences, 
00133             SoftwareResourceDescription softwareResourceDescription) throws Exception {
00134         GATEngine gatEngine = GATEngine.getGATEngine();
00135 
00136         Object[] array = new Object[1];
00137         array[0] = softwareResourceDescription;
00138 
00139         JobCpi jobCpi = (JobCpi) gatEngine.getAdaptor(
00140                 JobCpi.class, gatContext, preferences, array);
00141         
00142         return jobCpi;
00143     }
00144 
00145     /**
00146      * Submits the associated physical job to a job queue, an ordered list of
00147      * jobs which will eventually be run. Eventually the associated physical job
00148      * will be taken off of the job queue and begin running. This method can
00149      * only be called on a  in the Constructed or Stopped state or an
00150      * error will occur.
00151      * 
00152      * @throws java.rmi.RemoteException
00153      *             Thrown upon problems accessing the remote instance
00154      * @throws java.io.IOException
00155      *             Upon non-remote IO problem
00156      */
00157     public abstract void submit() throws RemoteException, IOException;
00158 
00159     /**
00160      * Stops the associated physical job. Upon a successful call to this method
00161      * the associated physical job is forcibly terminated. This method can only
00162      * be called on a  in the Running state.
00163      * 
00164      * @throws java.rmi.RemoteException
00165      *             Thrown upon problems accessing the remote instance
00166      * @throws java.io.IOException
00167      *             Upon non-remote IO problem
00168      */
00169     public abstract void stop() throws RemoteException, IOException;
00170 
00171     /**
00172      * This method returns the state of the associated . This is one of
00173      * the associated public member member variables CONSTRUCTED, SUBMITTED,
00174      * RUNNING, or STOPPED.
00175      * 
00176      * @return This method returns the state of the associated , one of
00177      *         the associated member variables
00178      * @throws java.rmi.RemoteException
00179      *             Thrown upon problems accessing the remote instance
00180      * @throws java.io.IOException
00181      *             Upon non-remote IO problem
00182      */
00183     public abstract int getState() throws RemoteException, IOException;
00184 
00185     /**
00186      * This method returns an instance of the class java.util.Map which contains
00187      * information about the associated . This java.util.Map contains a
00188      * set of key/value pairs the key, a java.lang.String, being the name of the
00189      * information and the value being the value of the associated named
00190      * information. The minimum set of keys which the returned java.util.Map
00191      * contains is as follows:
00192      * <ul>
00193      * <li><em>hostname</em></li>
00194      * <li><em>submissiontime</em></li>
00195      * <li><em>starttime</em></li>
00196      * <li><em>stoptime</em></li>
00197      * </ul>
00198      * <p>
00199      * <em>hostname</em> The key hostname corresponds to a java.lang.String
00200      * value which is the name of the host on which the physical job is running,
00201      * if  is in the Running state, or will be running on, if 
00202      * is in the Submitted state. If the associated  is not in the
00203      * Running or Submitted state, then the value is null.
00204      * <p>
00205      * <em>submissiontime</em> The key submissiontime corresponds to a long
00206      * value which is the number of milliseconds after January 1, 1970, 00:00:00
00207      * GMT when the associated physical job was submitted. This value is null
00208      * for a  in the Constructed state otherwise it is not null.
00209      * <p>
00210      * <em>starttime</em> The key starttime corresponds to a long value which
00211      * is the number of milliseconds after January 1, 1970, 00:00:00 GMT when
00212      * the associated physical job was started. This value is null for a
00213      *  in the Submitted or Constructed states otherwise it is not
00214      * null.
00215      * <p>
00216      * <em>stoptime<em>
00217      * The key stoptime corresponds to a long value which is the
00218      * number of milliseconds after January 1, 1970, 00:00:00 GMT when the
00219      * associated physical job stopped. This value is not null for a
00220      *  in the Stopped state otherwise it is null.
00221      * <p>
00222      * Other key/value pairs will be in future added to the list of key/value
00223      * pairs returned in this java.util.Map as the need develops.
00224      *
00225      * @return An instance of the class java.util.Map which presents 
00226      * information about the associated .
00227      * @throws java.rmi.RemoteException Thrown upon problems 
00228      * accessing the remote instance
00229      * @throws java.io.IOException Upon non-remote IO problem
00230      */
00231     public abstract Map getInfo() throws RemoteException, IOException;
00232 
00233     /**
00234      * This method returns the job id, a globally unique identifier for the
00235      * physical job corresponding to this instance. This method should be called
00236      * on an instance of this class only when the instance is in a Running or
00237      * Submitted state or an error will be returned.
00238      * 
00239      * @return An instance of the class java.lang.String which represents the
00240      *         job ID
00241      * @throws java.rmi.RemoteException
00242      *             Thrown upon problems accessing the remote instance
00243      * @throws java.io.IOException
00244      *             Upon non-remote IO problem
00245      */
00246     public abstract String getJobID() throws RemoteException, IOException;
00247 
00248 
00249     /**
00250      * Checkpoints the associated physical job. A physical job is said to be
00251      * checkpointed when it writes its current state information to a long term
00252      * storage medium. A physical job when checkpointing must write its current
00253      * state information to a long term storage medium in such a manner so that
00254      * it can, at a later date, by using the state information stored in the
00255      * long term storage medium continue running "from the same point" it was at
00256      * before checkpointing. This is useful for physical jobs which involve
00257      * significant data processing and can not, for any number of reasons,
00258      * process all of this data in a single run; also, it is useful for physical
00259      * jobs which involve significant data processing and are, for any number of
00260      * reasons unstable. In both of these cases checkpointing allows the
00261      * physical job to process some data now, then, at a later date, continue
00262      * running. This method can only be called on a Job in
00263      * the Running state or an error will occur.
00264      * 
00265      * @throws java.rmi.RemoteException
00266      *             Thrown upon problems accessing the remote instance
00267      * @throws java.io.IOException
00268      *             Upon non-remote IO problem
00269      */
00270     public abstract void checkpoint() throws RemoteException, IOException;
00271 
00272     /**
00273      * This method is equivalent to calling Checkpoint, Stop, then Submit on
00274      * this instance of Job.
00275      * 
00276      * @throws java.rmi.RemoteException
00277      *             Thrown upon problems accessing the remote instance
00278      * @throws java.io.IOException
00279      *             Upon non-remote IO problem
00280      */
00281     public abstract void migrate() throws RemoteException, IOException;
00282 
00283     /**
00284      * This method is equivalent to calling Checkpoint then Stop on this
00285      * instance of Job, then calling Submit on an instance
00286      * of Job identical to this instance except that
00287      * <ul>
00288      * <li>The Job when it first enters the Running state
00289      * will be in the state specified by the state information stored during the
00290      * previous call to the Checkpoint method.</li>
00291      * <li>The Job when it first enters the Running state
00292      * will be running on a hardware resource described in the passed
00293      * HardwareResourceDescription.</li>
00294      * </ul>
00295      * 
00296      * @param hardwareResourceDescription
00297      *            A description of the hardware resource to which the physical
00298      *            job corresponding to this Job should be
00299      *            migrated, a HardwareResourceDescription
00300      * @throws java.rmi.RemoteException
00301      *             Thrown upon problems accessing the remote instance
00302      * @throws java.io.IOException
00303      *             Upon non-remote IO problem
00304      */
00305     public abstract void migrate(HardwareResourceDescription hardwareResourceDescription)
00306             throws RemoteException, IOException;
00307 }