From: <mar...@us...> - 2007-10-12 09:02:46
|
Revision: 68 http://gridsim.svn.sourceforge.net/gridsim/?rev=68&view=rev Author: marcos_dias Date: 2007-10-12 02:02:49 -0700 (Fri, 12 Oct 2007) Log Message: ----------- This commit includes the advance reservation framework and some improvements in the graphical user interface. Modified Paths: -------------- branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/GridInformationService.java branches/gridsim4.0-branch3/source/gridsim/Gridlet.java branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/Reservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/util/Workload.java Added Paths: ----------- branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample02.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExampleWithCancellation01.java branches/gridsim4.0-branch3/source/eduni/simjava/Evqueue.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java branches/gridsim4.0-branch3/source/gridsim/ResourceCharacteristics.java branches/gridsim4.0-branch3/source/gridsim/filter/FilterCreateAR.java branches/gridsim4.0-branch3/source/gridsim/turbo/OrderGridletbyStartTime.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java Removed Paths: ------------- branches/gridsim4.0-branch3/examples/examples/workload/parallel/WorkloadWithCancellation.java branches/gridsim4.0-branch3/source/gridsim/gui/ItemPanel.java branches/gridsim4.0-branch3/source/gridsim/gui/ScheduleItem.java Copied: branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java (from rev 64, branches/gridsim4.0-branch3/examples/examples/workload/parallel/WorkloadWithCancellation.java) =================================================================== --- branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java (rev 0) +++ branches/gridsim4.0-branch3/examples/examples/WorkloadWithCancellation.java 2007-10-12 09:02:49 UTC (rev 68) @@ -0,0 +1,250 @@ +/* Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package examples; + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.IO_data; +import gridsim.ParameterException; +import gridsim.net.Link; +import gridsim.util.Workload; + +import java.util.ArrayList; + +/** + * This class is an extended version of {@link Workload}. This class + * cancels some gridlets submitted. + * + * @author Marcos Dias de Assuncao + * @since GridSim Turbo Alpha 0.1 + * + * @see Workload + */ +public class WorkloadWithCancellation extends Workload { + private final int NUM_GRIDLETS_BETWEEN_CANCELLATIONS = 50; + // value of 1, means that the cancellation will be sent + // at the gridlet's submission time + (gridlet duration * 1) + private final double TIME_CANCELLATION = 0.5; + + /** + * Create a new {@link WorkloadWithCancellation} object <b>without</b> using + * the network extension. This means this entity directly sends Gridlets + * to a resource destination without going through a wired network. <br> + * <tt>NOTE:</tt> + * You can not use this constructor in an experiment that uses a wired + * network topology. + * + * @param name this entity name + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithCancellation(String name, String fileName, String resourceName, + int rating) throws ParameterException, Exception { + + super(name, fileName, resourceName, rating); + } + + /** + * Create a new {@link WorkloadWithCancellation} object <b>with</b> the network extension. + * This means this entity directly sends Gridlets to a destination resource + * through a link. The link is automatically created by this constructor. + * + * @param name this entity name + * @param baudRate baud rate of this link (bits/s) + * @param propDelay Propagation delay of the Link in milliseconds + * @param MTU Maximum Transmission Unit of the Link in bytes. + * Packets which are larger than the MTU should be split + * up into MTU size units. + * For example, a 1024 byte packet trying to cross a 576 + * byte MTU link should get split into 2 packets of 576 + * bytes and 448 bytes. + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li> baudRate <= 0 + * <li> propDelay <= 0 + * <li> MTU <= 0 + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre baudRate > 0 + * @pre propDelay > 0 + * @pre MTU > 0 + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithCancellation(String name, double baudRate, double propDelay, int MTU, + String fileName, String resourceName, int rating) + throws ParameterException, Exception { + + super( name, baudRate, propDelay, MTU, fileName, resourceName, rating ); + } + + /** + * Create a new Workload object <b>with</b> the network extension. + * This means this entity directly sends Gridlets to a destination resource + * through a link. The link is automatically created by this constructor. + * + * @param name this entity name + * @param link the link that will be used to connect this Workload + * to another entity or a Router. + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li>the link is empty + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre link != null + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithCancellation(String name, Link link, String fileName, + String resourceName, int rating) + throws ParameterException, Exception { + + super(name, link, fileName, resourceName, rating); + } + + //////////////////////// PRIVATE METHODS /////////////////////// + + /** + * Collects Gridlets sent and stores them into a list. + * @pre $none + * @post $none + */ + protected void collectGridlet() { + System.out.println(super.get_name() + ": Collecting Gridlets ..."); + list_ = new ArrayList(gridletID_ + 1); + + Object data = null; + Gridlet gl = null; + + int counter = 1; // starts at 1, since gridletID_ starts at 1 too + Sim_event ev = new Sim_event(); + while ( Sim_system.running() ) { + + super.sim_get_next(ev); // get the next available event + data = ev.get_data(); // get the event's data + + // handle ping request + if (ev.get_tag() == GridSimTags.INFOPKT_SUBMIT) { + processPingRequest(ev); + continue; + } + + // get the Gridlet data + if (data != null && data instanceof Gridlet) { + gl = (Gridlet) data; + +// if(gl.getGridletStatus() == Gridlet.FAILED) +// System.out.println("Gridlet failed"); +// +// if(gl.getGridletStatus() == Gridlet.CANCELED) +// System.out.println("Gridlet cancelled"); + + list_.add(gl); + counter++; + } + + // if all the Gridlets have been collected + if (counter == gridletID_) { + break; + } + } + } + + /** + * Creates a Gridlet with the given information, then submit it to a + * resource + * @param id a Gridlet ID + * @param submitTime Gridlet's submit time + * @param runTime Gridlet's run time + * @param numProc number of processors + * @pre id >= 0 + * @pre submitTime >= 0 + * @pre runTime >= 0 + * @pre numProc > 0 + * @post $none + */ + protected void submitGridlet(int id, long submitTime, int runTime, int numProc) { + + // create the gridlet + int len = runTime * rating_; // calculate a job length for each PE + Gridlet gl = new Gridlet(id, len, size_, size_); + gl.setUserID( super.get_id() ); // set the owner ID + gl.setNumPE(numProc); // set the requested num of proc + + // printing to inform user + if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) { + System.out.println(super.get_name() + ": Submitting Gridlets to " + + resName_ + " ..."); + } + + // check the submit time + if (submitTime < 0) { + submitTime = 0; + } + + gridletID_++; // increment the counter + + // submit a gridlet to resource + super.send(super.output, submitTime, GridSimTags.GRIDLET_SUBMIT, + new IO_data(gl, gl.getGridletFileSize(), resID_) ); + + // check whether a cancellation has to be scheduled or not + int result = gridletID_ % NUM_GRIDLETS_BETWEEN_CANCELLATIONS; + if(result == 0) { + super.send(super.output, (submitTime + (TIME_CANCELLATION * runTime)), GridSimTags.GRIDLET_CANCEL, + new IO_data(gl, 0, resID_) ); + gridletID_++; + } + } + +} // end class + Added: branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java (rev 0) +++ branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java 2007-10-12 09:02:49 UTC (rev 68) @@ -0,0 +1,1077 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + */ + +package examples; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Enumeration; +import java.util.Random; +import java.util.zip.GZIPInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; + +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.IO_data; +import gridsim.ParameterException; +import gridsim.net.InfoPacket; +import gridsim.net.Link; +import gridsim.net.SimpleLink; +import gridsim.turbo.Reservation; +import gridsim.turbo.ReservationRequester; + +/** + * The main purpose of this class is to create a realistic simulation + * environment where your jobs or Gridlets are competing with others. + * In other words, the grid resource might not be available at certain times. + * In addition, the arrival time of jobs are also captured in the trace file. + * <p> + * This workload class has been modified to simulate advance reservations. + * Some parameters where included to indicate the frequency in which + * advance reservations are made. Additionally, it is possible to specify how + * long in advance the advance reservations are made. + * <p> + * This class is responsible for reading resource traces from a file and + * sends Gridlets to only <tt>one</tt> destinated resource. <br> + * <b>NOTE:</b> + * <ul> + * <li> This class can only take <tt>one</tt> trace file of the following + * format: <i>ASCII text, zip, gz.</i> + * <li> This class can be classified as <b>one grid user entity</b>. + * Hence, you need to incorporate this entity into <tt>numUser</tt> + * during {@link gridsim.GridSim#init(int, Calendar, boolean)} + * <li> If you need to use multiple trace files to submit Gridlets to + * same or different resources, then you need to create multiple + * instances of this class <tt>each with a unique entity name</tt>. + * <li> If size of the trace file is huge or contains lots of traces + * please increase the JVM heap size accordingly by using + * <tt>java -Xmx</tt> option when running the simulation. + * <li> If you are running an experiment using the network extension, + * i.e. the gridsim.net package, then you need to use + * {@link #Workload(String, double, double, int, String, String, int)} + * instead. + * <li> The default job file size for sending to and receiving from + * a resource is {@link gridsim.net.Link#DEFAULT_MTU}. + * However, you can specify + * the file size by using {@link #setGridletFileSize(int)}. + * <li> A job run time is only for 1 PE <tt>not</tt> the total number of + * allocated PEs. + * Therefore, a Gridlet length is also calculated for 1 PE.<br> + * For example, job #1 in the trace has a run time of 100 seconds + * for 2 processors. This means each processor runs + * job #1 for 100 seconds, if the processors have the same + * specification. + * </ul> + * <p> + * By default, this class follows the standard workload format as specified + * in <a href="http://www.cs.huji.ac.il/labs/parallel/workload/"> + * http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br> + * However, you can use other format by calling the below methods before + * running the simulation: + * <ul> + * <li> {@link #setComment(String)} + * <li> {@link #setField(int, int, int, int, int)} + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean) + * @author Marcos Dias de Assuncao (the most of the code came + * from {@link Workload} class) + * @since GridSim Turbo Alpha 0.1 + * @invariant $none + */ + +public class WorkloadWithReservation extends ReservationRequester { + + protected String fileName_; // file name + protected String resName_; // resource name + protected int resID_; // resource ID + protected int rating_; // a PE rating + protected int gridletID_; // gridletID + protected int size_; // job size for sending it through a network + protected ArrayList list_; // a list for getting all the Gridlets + + // constant + private int JOB_NUM; // job number + private int SUBMIT_TIME; // submit time of a Gridlet + private int RUN_TIME; // running time of a Gridlet + private int NUM_PROC; // number of processors needed for a Gridlet + private int REQ_NUM_PROC; // required number of processors + private int REQ_RUN_TIME; // required running time + private int MAX_FIELD; // max number of field in the trace file + private String COMMENT; // a string that denotes the start of a comment + private final int IRRELEVANT = -1; // irrelevant number + protected final int INTERVAL = 10; // number of intervals + private String[] fieldArray_; // a temp array storing all the fields + + // ADVANCE RESERVATION PROPERTIES + private double reservProbability_; + private double timeInAdvance_; + private Random numGen_; + private long seed_ = 11L*13*17*19*23+1; + + // TAGS FOR INTERNAL EVENTS + private final int GRIDLET_SUBMIT = 10; + private final int RESERVE_RESOURCES = 11; + + /** + * Create a new Workload object <b>without</b> using the network extension. + * This means this entity directly sends Gridlets to a destination resource + * without going through a wired network. <br> + * <tt>NOTE:</tt> + * You can not use this constructor in an experiment that uses a wired + * network topology. + * + * @param name this entity name + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithReservation(String name, String fileName, String resourceName, + int rating) throws ParameterException, Exception { + super(name, GridSimTags.DEFAULT_BAUD_RATE); + + // check the input parameters first + String msg = name + "(): Error - "; + if (fileName == null || fileName.length() == 0) { + throw new ParameterException(msg + "invalid trace file name."); + } + else if (resourceName == null || resourceName.length() == 0) { + throw new ParameterException(msg + "invalid resource name."); + } + else if (rating <= 0) { + throw new ParameterException(msg+"resource PE rating must be > 0."); + } + + System.out.println(name + ": Creating a workload object ..."); + init(fileName, resourceName, rating); + } + + /** + * Create a new Workload object <b>with</b> the network extension. + * This means this entity directly sends Gridlets to a destination resource + * through a link. The link is automatically created by this constructor. + * + * @param name this entity name + * @param baudRate baud rate of this link (bits/s) + * @param propDelay Propagation delay of the Link in milliseconds + * @param MTU Maximum Transmission Unit of the Link in bytes. + * Packets which are larger than the MTU should be split + * up into MTU size units. + * For example, a 1024 byte packet trying to cross a 576 + * byte MTU link should get split into 2 packets of 576 + * bytes and 448 bytes. + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li> baudRate <= 0 + * <li> propDelay <= 0 + * <li> MTU <= 0 + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre baudRate > 0 + * @pre propDelay > 0 + * @pre MTU > 0 + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithReservation(String name, double baudRate, double propDelay, int MTU, + String fileName, String resourceName, int rating) + throws ParameterException, Exception { + super( name, new SimpleLink(name+"_link", baudRate, propDelay, MTU) ); + + // check the input parameters first + String msg = name + "(): Error - "; + if (fileName == null || fileName.length() == 0) { + throw new ParameterException(msg + "invalid trace file name."); + } + else if (resourceName == null || resourceName.length() == 0) { + throw new ParameterException(msg + "invalid resource name."); + } + else if (rating <= 0) { + throw new ParameterException(msg+"resource PE rating must be > 0."); + } + + System.out.println(name + ": Creating a workload object ..."); + init(fileName, resourceName, rating); + } + + /** + * Create a new Workload object <b>with</b> the network extension. + * This means this entity directly sends Gridlets to a destination resource + * through a link. The link is automatically created by this constructor. + * + * @param name this entity name + * @param link the link that will be used to connect this Workload + * to another entity or a Router. + * @param fileName the workload trace filename in one of the following + * format: <i>ASCII text, zip, gz.</i> + * @param resourceName the resource name + * @param rating the resource's PE rating + * @throws Exception This happens when creating this entity before + * initialising GridSim package or this entity name is + * <tt>null</tt> or empty + * @throws ParameterException This happens for the following conditions: + * <ul> + * <li>the entity name is null or empty + * <li>the link is empty + * <li>the workload trace file name is null or empty + * <li>the resource entity name is null or empty + * <li>the resource PE rating <= 0 + * </ul> + * @pre name != null + * @pre link != null + * @pre fileName != null + * @pre resourceName != null + * @pre rating > 0 + * @post $none + */ + public WorkloadWithReservation(String name, Link link, String fileName, + String resourceName, int rating) + throws ParameterException, Exception { + super(name, link); + + // check the input parameters first + String msg = name + "(): Error - "; + if (fileName == null || fileName.length() == 0) { + throw new ParameterException(msg + "invalid trace file name."); + } + else if (resourceName == null || resourceName.length() == 0) { + throw new ParameterException(msg + "invalid resource name."); + } + else if (rating <= 0) { + throw new ParameterException(msg+"resource PE rating must be > 0."); + } + + System.out.println(name + ": Creating a workload object ..."); + init(fileName, resourceName, rating); + } + + /** + * Gets the probability of a job in the workload + * be an advance reservation + * @return the reservation probability + */ + public double getReservationProbability() { + return reservProbability_; + } + + /** + * Sets the probability of a job in the workload + * be an advance reservation + * @param probability the reservation probability + */ + public void setReservationProbability(double probability) { + reservProbability_ = probability; + } + + /** + * Gets how long in advance an advance reservation has to + * be made. The time in advance is how long in advance to + * the submission time included in the log the reservation + * has to be made + * @return the time in advance + */ + public double getARTimeInAdvance() { + return timeInAdvance_; + } + + /** + * Sets how long in advance an advance reservation has to + * be made. The time in advance is how long in advance to + * the submission time included in the log the reservation + * has to be made + * @param time the time in advance + */ + public void setARTimeInAdvance(double time) { + timeInAdvance_ = time; + } + + /** + * Initialises all the attributes + * @param fileName trace file name + * @param resourceName resource entity name + * @param rating resource PE rating + * @pre $none + * @post $none + */ + private void init(String fileName, String resourceName, int rating) + { + fileName_ = fileName; + resName_ = resourceName; + resID_ = GridSim.getEntityId(resName_); + rating_ = rating; + gridletID_ = 1; // starts at 1 to make it the same as in a trace file + list_ = null; + size_ = Link.DEFAULT_MTU; + + timeInAdvance_ = 60 * 60; // one hour + reservProbability_ = 0D; + numGen_ = new Random(seed_); + + // if using Standard Workload Format -- don't forget to substract by 1 + // since an array starts at 0, but the field in a trace starts at 1 + JOB_NUM = 1 - 1; + SUBMIT_TIME = 2 - 1; + RUN_TIME = 4 - 1; + NUM_PROC = 5 - 1; + REQ_NUM_PROC = 8 - 1; + REQ_RUN_TIME = 9 - 1; + + COMMENT = ";"; // semicolon means the start of a comment + MAX_FIELD = 18; // standard workload format has 18 fields + fieldArray_ = null; + } + + /** + * Sets a Gridlet file size (in byte) for sending to/from a resource. + * @param size a Gridlet file size (in byte) + * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise + * @pre size > 0 + * @post $none + */ + public boolean setGridletFileSize(int size) { + if (size < 0) { + return false; + } + + size_ = size; + return true; + } + + /** + * Identifies the start of a comment line. Hence, a line that starts + * with a given comment will be ignored. + * @param comment a character that denotes the start of a comment, + * e.g. ";" or "#" + * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise + * @pre comment != null + * @post $none + */ + public boolean setComment(String comment) + { + boolean success = false; + if (comment != null && comment.length() > 0) + { + COMMENT = comment; + success = true; + } + return success; + } + + /** + * Tells this class what to look in the trace file. + * This method should be called before the start of the simulation. + * <p> + * By default, this class follows the standard workload format as specified + * in <a href="http://www.cs.huji.ac.il/labs/parallel/workload/"> + * http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br> + * However, you can use other format by calling this method. + * <p> + * The parameters must be a positive integer number starting from 1. + * A special case is where <tt>jobNum == -1</tt>, meaning the job or + * gridlet ID starts at 1. + * + * @param maxField max. number of field/column in one row + * @param jobNum field/column number for locating the job ID + * @param submitTime field/column number for locating the job submit time + * @param runTime field/column number for locating the job run time + * @param numProc field/column number for locating the number of PEs + * required to run a job + * @return <tt>true</tt> if successful, <tt>false</tt> otherwise + * @pre maxField > 0 + * @pre submitTime > 0 + * @pre runTime > 0 + * @pre numProc > 0 + * @post $none + */ + public boolean setField(int maxField, int jobNum, int submitTime, + int runTime, int numProc) + { + // need to substract by 1 since array starts at 0. Need to convert, + // position in a field into the index of the array + if (jobNum > 0) { + JOB_NUM = jobNum - 1; + } + else if (jobNum == 0) + { + System.out.println(super.get_name() + + ".setField(): Invalid job number field."); + return false; + } + else { + JOB_NUM = -1; + } + + // get the max. number of field + if (maxField > 0) { + MAX_FIELD = maxField; + } + else + { + System.out.println(super.get_name() + + ".setField(): Invalid max. number of field."); + return false; + } + + // get the submit time field + if (submitTime > 0) { + SUBMIT_TIME = submitTime - 1; + } + else + { + System.out.println(super.get_name() + + ".setField(): Invalid submit time field."); + return false; + } + + // get the run time field + if (runTime > 0) { + REQ_RUN_TIME = runTime - 1; + } + else + { + System.out.println(super.get_name() + + ".setField(): Invalid run time field."); + return false; + } + + // get the number of processors field + if (numProc > 0) { + REQ_NUM_PROC = numProc - 1; + } + else + { + System.out.println(super.get_name() + + ".setField(): Invalid number of processors field."); + return false; + } + + return true; + } + + /** + * Gets a list of completed Gridlets + * @return a list of Gridlets + * @pre $none + * @post $none + */ + public ArrayList getGridletList() { + return list_; + } + + /** + * Prints the Gridlet objects + * @param history <tt>true</tt> means printing each Gridlet's history, + * <tt>false</tt> otherwise + * @pre $none + * @post $none + */ + public void printGridletList(boolean history) + { + String name = super.get_name(); + int size = list_.size(); + Gridlet gridlet; + + String indent = " "; + System.out.println(); + System.out.println("========== OUTPUT for " + name + " =========="); + System.out.println("Gridlet_ID" + indent + "STATUS" + indent + + "Resource_ID" + indent + "Cost"); + + int i = 0; + for (i = 0; i < size; i++) + { + gridlet = (Gridlet) list_.get(i); + System.out.print(indent + gridlet.getGridletID() + indent + + indent); + + // get the status of a Gridlet + System.out.print( gridlet.getGridletStatusString() ); + System.out.println( indent + indent + gridlet.getResourceID() + + indent + indent + gridlet.getProcessingCost() ); + } + + System.out.println(); + if (history == true) + { + // a loop to print each Gridlet's history + System.out.println(); + for (i = 0; i < size; i++) + { + gridlet = (Gridlet) list_.get(i); + System.out.println( gridlet.getGridletHistory() ); + + System.out.print("Gridlet #" + gridlet.getGridletID() ); + System.out.println(", length = " + gridlet.getGridletLength() + + ", finished so far = " + + gridlet.getGridletFinishedSoFar() ); + System.out.println("========================================="); + System.out.println(); + } + } + } + + /** + * Reads from a given file when the simulation starts running. + * Then submits Gridlets to a resource and collects them before exiting. + * To collect the completed Gridlets, use {@link #getGridletList()} + * @pre $none + * @post $none + */ + public void body() { + System.out.println(); + System.out.println(super.get_name() + ".body() :%%%% Start ..."); + + // create a temp array + fieldArray_ = new String[MAX_FIELD]; + + // get the resource id + if (resID_ < 0) + { + System.out.println(super.get_name() + + ".body(): Error - invalid resource name: " + resName_); + return; + } + + boolean success = false; + + // read the gz file + if (fileName_.endsWith(".gz") == true) { + success = readGZIPFile(fileName_); + } + // read the zip file + else if (fileName_.endsWith(".zip") == true) { + success = readZipFile(fileName_); + } + // read from uncompressed file as well + else { + success = readFile(fileName_); + } + + // if all the gridlets have been submitted + if (!success ) { + System.out.println(super.get_name() + + ".body(): Error - unable to parse from a file."); + return; + } + + System.out.println(super.get_name() + ": Collecting Gridlets ..."); + list_ = new ArrayList(gridletID_ + 1); + + Object data = null; + Gridlet gl = null; + + int counter = 1; // starts at 1, since gridletID_ starts at 1 too + Sim_event ev = new Sim_event(); + Object[] reservObj = null; + + while ( Sim_system.running() + && counter < gridletID_ ) { + + super.sim_get_next(ev); // get the next available event + data = ev.get_data(); // get the event's data + + // handle ping request + if (ev.get_tag() == GridSimTags.INFOPKT_SUBMIT) { + processPingRequest(ev); + continue; + } + else if (ev.get_tag() == RESERVE_RESOURCES) { + + reservObj = (Object[])ev.get_data(); + + double startTime = (Double)reservObj[0]; + int duration = (Integer)reservObj[1]; + Gridlet resGl = (Gridlet)reservObj[2]; + + // creates a new reservation + Reservation reservation = null; + reservation = super.createReservation(startTime, duration, resGl.getNumPE(), resID_); + + success = true; + if(reservation == null) { + success = false; + } + + // commit the reservation + if(success) { + // for a reservation with an even number, commits straightaway + // without sending any Gridlets yet + success = super.commitReservation(reservation.getID()); + + // submit the gridlet if success + if(success) { + + // sets the reservation id of this gridlet + resGl.setReservationID(reservation.getID()); + + // submit the gridlet to the resource + super.send(super.output, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDLET_SUBMIT, + new IO_data(resGl, resGl.getGridletFileSize(), resID_) ); + } + // if the reservation fails, then sets the status of the + // gridlet to failed and adds the gridlet to the list + else { + try { + resGl.setGridletStatus(Gridlet.FAILED); + } + catch(Exception ex) { + + } + list_.add(resGl); + } + } + counter++; + } + + // get the Gridlet data + else if (data != null && data instanceof Gridlet) { + gl = (Gridlet) data; + list_.add(gl); + counter++; + } + + // if all the Gridlets have been collected + if (counter == gridletID_) { + break; + } + } + + // shut down all the entities, including GridStatistics entity since + // we used it to record certain events. + shutdownGridStatisticsEntity(); + shutdownUserEntity(); + terminateIOEntities(); + + System.out.println(super.get_name() + ".body() : %%%% Exit ..."); + } + + //////////////////////// PROTECTED METHODS /////////////////////// + + /** + * Processes a ping request. + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + protected void processPingRequest(Sim_event ev) + { + InfoPacket pkt = (InfoPacket) ev.get_data(); + pkt.setTag(GridSimTags.INFOPKT_RETURN); + pkt.setDestID( pkt.getSrcID() ); + + // sends back to the sender + super.send(super.output, GridSimTags.SCHEDULE_NOW, + GridSimTags.INFOPKT_RETURN, + new IO_data(pkt, pkt.getSize(), pkt.getSrcID()) ); + } + + //////////////////////// PRIVATE METHODS /////////////////////// + + /** + * Breaks a line of string into many fields. + * @param line a line of string + * @param lineNum a line number + * @pre line != null + * @pre lineNum > 0 + * @post $none + */ + private void parseValue(String line, int lineNum) + { + // skip a comment line + if (line.startsWith(COMMENT) == true) { + return; + } + + String[] sp = line.split("\\s+"); // split the fields based on a space + int i; // a counter + int len = 0; // length of a string + int index = 0; // the index of an array + + // check for each field in the array + for (i = 0; i < sp.length; i++) + { + len = sp[i].length(); // get the length of a string + + // if it is empty then ignore + if (len == 0) { + continue; + } + // if not, then put into the array + else + { + fieldArray_[index] = sp[i]; + index++; + } + } + + if (index == MAX_FIELD) { + extractField(fieldArray_, lineNum); + } + } + + /** + * Extracts relevant information from a given array + * @param array an array of String + * @param line a line number + * @pre array != null + * @pre line > 0 + */ + private void extractField(String[] array, int line) + { + try + { + Integer obj = null; + + // get the job number + int id = 0; + if (JOB_NUM == IRRELEVANT) { + id = gridletID_; + } + else + { + obj = new Integer( array[JOB_NUM].trim() ); + id = obj.intValue(); + } + + // get the submit time + Long l = new Long( array[SUBMIT_TIME].trim() ); + long submitTime = l.intValue(); + + // get the run time + obj = new Integer( array[REQ_RUN_TIME].trim() ); + int runTime = obj.intValue(); + + // if the required run time field is ignored, then use + // the actual run time + if (runTime == IRRELEVANT) + { + obj = new Integer( array[RUN_TIME].trim() ); + runTime = obj.intValue(); + } + + // according to the SWF manual, runtime of 0 is possible due + // to rounding down. E.g. runtime is 0.4 seconds -> runtime = 0 + if (runTime == 0) { + runTime = 1; // change to 1 second + } + + // get the number of allocated processors + obj = new Integer( array[REQ_NUM_PROC].trim() ); + int numProc = obj.intValue(); + + // if the required num of allocated processors field is ignored + // or zero, then use the actual field + if (numProc == IRRELEVANT || numProc == 0) + { + obj = new Integer( array[NUM_PROC].trim() ); + numProc = obj.intValue(); + } + + // finally, check if the num of PEs required is valid or not + if (numProc <= 0) + { + System.out.println(super.get_name() + ": Warning - job #" + + id + " at line " + line + " requires " + numProc + + " CPU. Change to 1 CPU."); + numProc = 1; + } + + // creates a submission/reservation event + submitGridlet(id, submitTime, runTime, numProc); + } + catch (Exception e) + { + System.out.println(super.get_name() + + ": Exception in reading file at line #" + line); + e.printStackTrace(); + } + } + + /** + * Creates a Gridlet with the given information, then submit it to a + * resource + * @param id a Gridlet ID + * @param submitTime Gridlet's submit time + * @param runTime Gridlet's run time + * @param numProc number of processors + * @pre id >= 0 + * @pre submitTime >= 0 + * @pre runTime >= 0 + * @pre numProc > 0 + * @post $none + */ + protected void submitGridlet(int id, long submitTime, int runTime, int numProc) { + // create the gridlet + int len = runTime * rating_; // calculate a job length for each PE + Gridlet gridlet = new Gridlet(id, len, size_, size_); + gridlet.setUserID( super.get_id() ); // set the owner ID + gridlet.setNumPE(numProc); // set the requested num of proc + + // check the probability of creating an advance reservation + double probAR = Math.abs(numGen_.nextDouble()); + + // check the submit time + if (submitTime < 0) { + submitTime = 0; + } + + if(probAR <= reservProbability_) { + + // calculate how long in advance the reservation is made + double timeInAdvance = timeInAdvance_ * numGen_.nextDouble(); + + // convert to seconds + double timeToReserve = submitTime - timeInAdvance; + + // if the time the reservation would be done has already + // past, then consider now as the submission time + if(timeToReserve <= 0.0D) { + timeToReserve = GridSimTags.SCHEDULE_NOW; + } + + //TODO To check the duration of the advance reservation later + Object[] reservObj = new Object[3]; + reservObj[0] = new Double(submitTime); // start time of the reservation + reservObj[1] = (int) runTime + 1; // the advance reservation duration + reservObj[2] = gridlet; // the gridlet to be submitted + + // submit an internal event to create a reservation for this gridlet + super.send(super.get_id(), timeToReserve, RESERVE_RESOURCES, reservObj); + } + else { + // printing to inform user + if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) { + System.out.println(super.get_name() + ": Submitting Gridlets to " + + resName_ + " ..."); + } + + // submit a gridlet to resource + super.send(super.output, submitTime, GridSimTags.GRIDLET_SUBMIT, + new IO_data(gridlet, gridlet.getGridletFileSize(), resID_) ); + } + + gridletID_++; // increment the counter + } + + /** + * Reads a text file one line at the time + * @param fileName a file name + * @return <tt>true</tt> if reading a file is successful, <tt>false</tt> + * otherwise. + * @pre fileName != null + * @post $none + */ + private boolean readFile(String fileName) + { + boolean success = false; + BufferedReader reader = null; + try + { + FileInputStream file = new FileInputStream(fileName); + InputStreamReader input = new InputStreamReader(file); + reader = new BufferedReader(input); + + // read one line at the time + int line = 1; + while ( reader.ready() ) + { + parseValue(reader.readLine(), line); + line++; + } + + reader.close(); // close the file + success = true; + } + catch (FileNotFoundException f) + { + System.out.println(super.get_name() + + ": Error - the file was not found: " + f.getMessage()); + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + finally + { + if (reader != null) + { + try { + reader.close(); // close the file + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + } + } + + return success; + } + + /** + * Reads a gzip file one line at the time + * @param fileName a gzip file name + * @return <tt>true</tt> if reading a file is successful, <tt>false</tt> + * otherwise. + * @pre fileName != null + * @post $none + */ + private boolean readGZIPFile(String fileName) + { + boolean success = false; + BufferedReader reader = null; + try + { + FileInputStream file = new FileInputStream(fileName); + GZIPInputStream gz = new GZIPInputStream(file); + InputStreamReader input = new InputStreamReader(gz); + reader = new BufferedReader(input); + + // read one line at the time + int line = 1; + while ( reader.ready() ) + { + parseValue(reader.readLine(), line); + line++; + } + + reader.close(); // close the file + success = true; + } + catch (FileNotFoundException f) + { + System.out.println(super.get_name() + + ": Error - the file was not found: " + f.getMessage()); + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + finally + { + if (reader != null) + { + try { + reader.close(); // close the file + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + } + } + + return success; + } + + /** + * Reads a Zip file. Iterating through each entry and reading it one line + * at the time. + * @param fileName a zip file name + * @return <tt>true</tt> if reading a file is successful, <tt>false</tt> + * otherwise. + * @pre fileName != null + * @post $none + */ + private boolean readZipFile(String fileName) + { + boolean success = false; + ZipFile zipFile = null; + try + { + InputStreamReader input = null; + BufferedReader reader = null; + + // ZipFile offers an Enumeration of all the files in the Zip file + zipFile = new ZipFile(fileName); + for (Enumeration e = zipFile.entries(); e.hasMoreElements();) + { + success = false; // reset the value again + ZipEntry zipEntry = (ZipEntry) e.nextElement(); + + input = new InputStreamReader(zipFile.getInputStream(zipEntry)); + reader = new BufferedReader(input); + + // read one line at the time + int line = 1; + while ( reader.ready() ) + { + parseValue(reader.readLine(), line); + line++; + } + + reader.close(); // close the file + success = true; + } + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + finally + { + if (zipFile != null) + { + try { + zipFile.close(); // close the file + } + catch (IOException e) + { + System.out.println(super.get_name() + + ": Error - an IOException occurred: " + e.getMessage()); + } + } + } + + return success; + } +} Modified: branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java 2007-10-04 06:05:40 UTC (rev 67) +++ branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java 2007-10-12 09:02:49 UTC (rev 68) @@ -50,8 +50,7 @@ * <tt>null</tt> or empty * @see gridsim.GridSim#init(int, Calendar, boolean) */ - public ARTest(String name, double baud_rate, double timeZone, - int totalJob) throws Exception { + public ARTest(String name, double baud_rate, int totalJob) throws Exception { super(name, baud_rate); this.receiveList_ = new GridletList(); this.failReservation_ = 0; @@ -108,8 +107,7 @@ // double check whether a resource supports AR or not. // In this example, all resources support AR. - if (GridSim.resourceSupportAR(intObj) == true) - { + if (GridSim.resourceSupportAR(intObj) == true) { // gets the name of a resource name = GridSim.getEntityName( intObj.intValue() ); @@ -155,11 +153,11 @@ */ private void sendReservation(ArrayList resARList, ArrayList resNameList) { // total reservation made. 1 reservation reserves 1 PE. - int totalPE = 2; - int totalReservation = list_.size(); // total number of Gridlets + int totalPE = 3; + int totalReservation = list_.size() + 2; // total number of Gridlets - // wants to reserve 1 day after the init simulation time - long time = 1 * DAY; + // wants to reserve 1 hour after the init simulation time + long time = 1 * HOUR; // each reservation requires around 10 minutes int duration = 10 * MIN; @@ -189,22 +187,25 @@ time = 1 * HOUR + duration; } - // creates a new or immediate reservation + // creates a new reservation Reservation reservation = null; boolean success = false; reservation = super.createReservation(time, duration, totalPE, resID); if(reservation != null) { - System.out.println(super.get_name() + ": reservation has been returned from "+ + System.out.println(super.get_name() + ": reservation has been accepted by "+ resName + " at time = " + GridSim.clock()); + success = true; } else { - System.out.println(super.get_name() + ": no reservation has been returned from "+ + System.out.println(super.get_name() + ": reservation has not been accepted by "+ resName + " at time = " + GridSim.clock()); failReservation_++; + success = false; } - if(reservation != null) { + // commit the reservation + if(success) { // for a reservation with an even number, commits straightaway // without sending any Gridlets yet success = super.commitReservation(reservation.getID()); @@ -218,6 +219,13 @@ " has NOT been committed successfully."); } } + + if(success && i<list_.size()) { + // then sends a gridlet to use the reservation + Gridlet grl = this.list_.get(i); + grl.setReservationID(reservation.getID()); + super.gridletSubmit(grl, resID); + } } } @@ -238,7 +246,7 @@ private GridletList createGridlet(int size, int userID) { // Creates a container to store Gridlets GridletList list = new GridletList(); - int length = 5000; + int length = 500000; for (int i = 0; i < size; i++) { // creates a new Gridlet object Gridlet gridlet = new Gridlet(i, length, 1000, 5000); Modified: branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java 2007-10-04 06:05:40 UTC (rev 67) +++ branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java 2007-10-12 09:02:49 UTC (rev 68) @@ -51,33 +51,14 @@ // Second step: Creates one or more GridResource objects // given resource name, total PE, number of Machine, time zone // and MIPS Rating. - -// // R0: vpac Compaq AlphaServer -// ARTGridResource resource0 = -// createGridResource("Resource_0", 4, 1, 10.0, 515); - - // R1: Manjra Linux PC ARTGridResource resource1 = createGridResource("Resource_1", 13, 1, 10.0, 684); -// // R2: Germany -// ARTGridResource resource2 = -// createGridResource("Resource_2", 16, 1, 1.0, 410); -// -// // R3: Czech -// ARTGridResource resource3 = -// createGridResource("Resource_3", 6, 1, 1.0, 410); -// -// // R4: Chichago -// ARTGridResource resource4 = -// createGridResource("Resource_4", 8, 1, -6.0, 377); - //------------------------------------------------ // Third step: Creates grid users ARTest[] userList = new ARTest[num_user]; ARTest user = null; // a user entity double bandwidth = 1000; // bandwidth of this user - double timeZone = 0.0; // user's time zone int totalJob = 0; // total Gridlets owned int i = 0; @@ -85,18 +66,16 @@ for (i = 0; i < num_user; i++) { // users with an even number have their time zone to GMT+8 if (i % 2 == 0) { - timeZone = 8.0; // with respect to GMT or UTC totalJob = 4; } // users with an odd number have their time zone to GMT-3 else { - timeZone = -3.0; // with respect to GMT or UTC totalJob = 5; } // creates a user entity - user = new ARTest("User_" + i, bandwidth, timeZone, totalJob); + user = new ARTest("User_" + i, bandwidth, totalJob); // put the entity into an array userList[i] = user; Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java 2007-10-04 06:05:40 UTC (rev 67) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java 2007-10-12 09:02:49 UTC (rev 68) @@ -17,7 +17,8 @@ /** - * Test Driver class for this example + * Test Driver class for this example. This example just tests + * the same features provided by the ParallelSpaceShared policy */ public class TurboAREx... [truncated message content] |