From: <mar...@us...> - 2008-03-31 00:27:18
|
Revision: 166 http://gridsim.svn.sourceforge.net/gridsim/?rev=166&view=rev Author: marcos_dias Date: 2008-03-30 17:27:24 -0700 (Sun, 30 Mar 2008) Log Message: ----------- This update contains small updates in the policies such as improvement in the descriptions. 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/TurboARCBMultipleQueuesExample01.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample02.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample03.java branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExampleWithCancellation01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfile.java branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/MPProfileEntry.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java Modified: branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/ar/ARTest.java 2008-03-31 00:27:24 UTC (rev 166) @@ -1,9 +1,10 @@ /* * Author Marcos Dias de Assuncao * Date: September 2007 + * * Description: A simple program to demonstrate of how to use basic - * advanced reservation functionalities, such as create, commit - * and status. + * advanced reservation functionalities, such as create, commit, + * get status of advance reservations and submit gridlets. */ package examples.ar; Modified: branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/ar/SimpleARExample01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -1,9 +1,10 @@ /* * Author: Marcos Dias de Assuncao * Date: September 2007 + * * Description: A simple program to demonstrate of how to use basic - * advanced reservation functionalities, such as create, commit - * and status. + * advanced reservation functionalities, such as create, commit, + * get status of advance reservations and submit gridlets. */ package examples.ar; Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: February 2008 * - * Description: This example shows how to create a resource with a conservative + * Description: This example shows how to create a resource using a conservative * backfilling policy with advance reservation features and with multiple * partitions. The jobs are read from a trace file. To test this example, * you can use one of the traces included in the workloads directory. Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -1,3 +1,12 @@ +/* + * Author Marcos Dias de Assuncao + * Date: February 2008 + * + * Description: This example shows how to create a resource using an aggressive + * backfilling policy with advance reservation features and with multiple + * partitions. The jobs are read from a trace file. To test this example, + * you can use one of the traces included in the workloads directory. + */ package examples.workload.ar; Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,12 +2,12 @@ * Author Marcos Dias de Assuncao * Date: September 2007 * - * Description: This example shows how to create a resource with a + * Description: This example shows how to create a resource using a * conservative backfilling policy with advance reservation features. The jobs are * read from a trace file. To test this example, you can use one of the traces * included in the workloads directory. The jobs generated by this class are not * advance reservations, however. This example has been created for debugging - * purposes. + * purposes in order to test the normal job scheduling by the policy. */ package examples.workload.ar; Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample02.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample02.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample02.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: September 2007 * - * Description: This example shows how to create a resource with a + * Description: This example shows how to create a resource using a * conservative backfilling policy with advance reservation features. The jobs are * read from a trace file. To test this example, you can use one of the traces * included in the workloads directory. Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample03.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample03.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExample03.java 2008-03-31 00:27:24 UTC (rev 166) @@ -5,8 +5,8 @@ * Description: This example creates three resources and three workload * objects. The workloads make advance reservations and submit gridlets * to the resources. The policy used by the resources is conservative - * backfilling with advance reservation. To test this example, you can use - * one of the traces included in the workloads directory. + * backfilling with advance reservation features. To test this example, + * you can use one of the traces included in the workloads directory. */ package examples.workload.ar; Modified: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExampleWithCancellation01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExampleWithCancellation01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARExampleWithCancellation01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: September 2007 * - * Description: This example shows how to create a resource with a + * Description: This example shows how to create a resource using a * conservative backfilling policy with advance reservation features. The jobs are * read from a trace file. The workload object cancels some of the gridlets * submitted to the resource. This example has been implemented to test Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,8 +2,8 @@ * Author Marcos Dias de Assuncao * Date: September 2007 * - * Description: This example shows how to create a resource with a - * conservative backfilling policy without advance reservation features. The jobs are + * Description: This example shows how to create a resource using a conservative + * backfilling policy without advance reservation features. The jobs are * read from a trace file. To test this example, you can use one of the traces * included in the workloads directory. */ Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: February 2008 * - * Description: This example shows how to create a resource with a conservative + * Description: This example shows how to create a resource using a conservative * backfilling policy without advance reservation features but with multiple * partitions. The jobs are read from a trace file. To test this example, * you can use one of the traces included in the workloads directory. Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: February 2008 * - * Description: This example shows how to create a resource with an aggressive + * Description: This example shows how to create a resource using an aggressive * backfilling policy without advance reservation features but with multiple * partitions. This example creates the policy with only one partition, however. * This has been done for debugging purposes. The policy should behave like a Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: February 2008 * - * Description: This example shows how to create a resource with an aggressive + * Description: This example shows how to create a resource using an aggressive * backfilling policy without advance reservation features but with multiple * partitions. The jobs are read from a trace file. To test this example, * you can use one of the traces included in the workloads directory. Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: February 2008 * - * Description: This example shows how to create a resource with an aggressive + * Description: This example shows how to create a resource using an aggressive * backfilling policy without advance reservation features. The jobs are * read from a trace file. To test this example, you can use one of the traces * included in the workloads directory. Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java 2008-03-31 00:27:24 UTC (rev 166) @@ -2,7 +2,7 @@ * Author Marcos Dias de Assuncao * Date: September 2007 * - * Description: This example shows how to create a resource with a + * Description: This example shows how to create a resource using a * conservative backfilling policy without advance reservation features. * This example has beenn implemented to test the job cancellation. The workload * object created in this example cancels some of the gridlets submitted. The Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfile.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfile.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfile.java 2008-03-31 00:27:24 UTC (rev 166) @@ -19,7 +19,8 @@ * @since GridSim Turbo Alpha 0.1 */ -public class AvailabilityProfile extends ArrayList<AvailabilityProfileEntry> { +public class AvailabilityProfile extends ArrayList<AvailabilityProfileEntry> + implements Cloneable { private static final long serialVersionUID = -1853610061073508770L; @@ -31,7 +32,7 @@ } /** - * Returns a clone of this object.<br> + * Returns shallow copy of this object.<br> * <b>NOTE:</b> this method does not clone the entries * @return the cloned object */ @@ -44,6 +45,19 @@ } /** + * Returns copy of this object.<br> + * <b>NOTE:</b> this method clones the entries + * @return the copy object + */ + public AvailabilityProfile copy() { + AvailabilityProfile copy = new AvailabilityProfile(); + for(AvailabilityProfileEntry entry : this){ + copy.add(entry.clone()); + } + return copy; + } + + /** * Returns the entry whose time is closest to the <tt>time</tt> given but * smaller, or whose time is equals to <tt>time</tt> * @param time the time to be used to search for the entry Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-03-31 00:27:24 UTC (rev 166) @@ -15,7 +15,7 @@ * @since GridSim Turbo Alpha 0.1 */ -public class AvailabilityProfileEntry { +public class AvailabilityProfileEntry implements Cloneable { private PERangeList ranges_; // the ranges available private double time_; // the time when the ranges will be available @@ -25,16 +25,26 @@ * Creates an instance of @link{ProfileEntry}. * @param time the time associated with this event */ - public AvailabilityProfileEntry(double time){ + public AvailabilityProfileEntry(double time) { time_ = time; ranges_ = new PERangeList(); } /** + * Creates an instance of @link{ProfileEntry}. + * @param time the time associated with this event + * @param ranges the ranges to be used by this entry + */ + public AvailabilityProfileEntry(double time, PERangeList ranges) { + time_ = time; + ranges_ = ranges; + } + + /** * Returns the ranges of free PEs associated with this entry * @return the ranges of free PEs associated with this entry */ - public PERangeList getPERanges(){ + public PERangeList getPERanges() { return ranges_; } @@ -42,14 +52,14 @@ * Adds a range of PEs to the list * @param list the range of PEs */ - public void setPERangeList(PERangeList list){ + public void setPERangeList(PERangeList list) { ranges_ = list; } /** * Clears the list of PE ranges */ - public void clearPERangeList(){ + public void clearPERangeList() { ranges_.clear(); } @@ -57,7 +67,7 @@ * Returns the time associated with this entry * @return the time associated */ - public double getTime(){ + public double getTime() { return time_; } @@ -65,7 +75,7 @@ * Gets the number of PEs associated with this entry * @return the number of PEs */ - public int getNumPE(){ + public int getNumPE() { if(ranges_ == null) return 0; else @@ -76,7 +86,7 @@ * Sets the time associated with this event * @param time the time to be set */ - public void setTime(double time){ + public void setTime(double time) { time_ = time; } @@ -84,7 +94,7 @@ * Increases the number of Gridlets that rely on this entry to mark * their expected completion time or their anchor point */ - public void increaseGridlet(){ + public void increaseGridlet() { numGridlets_++; } @@ -92,7 +102,7 @@ * Decreases the number of Gridlets that rely on this entry to mark * their expected completion time or their anchor point */ - public void decreaseGridlet(){ + public void decreaseGridlet() { numGridlets_--; } @@ -101,14 +111,26 @@ * their expected completion time or their anchor point * @return the number of Gridlets that use this entry */ - public int getNumGridlets(){ + public int getNumGridlets() { return numGridlets_; } /** + * Returns a clone of this object. + * @return a clone of this object. + */ + public AvailabilityProfileEntry clone() { + PERangeList ranges = ranges_ == null ? null : ranges_.clone(); + AvailabilityProfileEntry entry = + new AvailabilityProfileEntry(time_, ranges); + entry.numGridlets_ = numGridlets_; + return entry; + } + + /** * Creates a string representation of this entry */ - public String toString(){ + public String toString() { return "ProfileEntry={time="+ time_ + "; gridlets=" + numGridlets_ + "; " + ( (ranges_!=null) ? ranges_ : "{[]}") + "}"; } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-03-31 00:27:24 UTC (rev 166) @@ -17,6 +17,7 @@ import java.util.Calendar; import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; @@ -113,8 +114,8 @@ // The rating of one PE protected int ratingPE_; - // to order gridlets by potential start time - private OrderGridletByStartTime orderStartTime_; + // heuristic used to order the jobs for backfilling + protected Comparator<SSGridlet> jobOrderHeuristic_; // the last time when the schedule updated was called private double lastScheduleUpdate_; @@ -150,7 +151,7 @@ runningGridlets_ = new LinkedList<SSGridlet>(); queuedGridlets_ = new LinkedList<SSGridlet>(); availProfile_ = new AvailabilityProfile(); - orderStartTime_ = new OrderGridletByStartTime(); + jobOrderHeuristic_ = null; lastScheduleUpdate_ = 0.0D; ratingPE_ = 0; } @@ -203,6 +204,22 @@ } /** + * Sets the heuristic used to order the jobs considered for backfilling + * or when a cancellation takes place + * @param comparator a comparator implementation that defines + * how gridlets are ordered. + * @return <tt>true</tt> if the heuristic was set correctly; + * <tt>false</tt> otherwise. + */ + public boolean setJobOrderingHeuristic(Comparator<SSGridlet> comparator) { + if(comparator == null) + return false; + + jobOrderHeuristic_ = comparator; + return true; + } + + /** * Schedules a new <tt>Gridlet</tt> received by the * <tt>GridResource</tt> entity. * @param gridlet a Gridlet object to be executed @@ -330,7 +347,7 @@ * back to sender, i.e. the <tt>userId</tt>. * * <li> If a Gridlet cannot be found in either execution and - * paused list, then a <tt>null</tt> Gridlet will be send back + * waiting lists, then a <tt>null</tt> Gridlet will be send back * to sender, i.e. the <tt>userId</tt>. * * <li> Once a Gridlet is cancelled, the availability profile @@ -402,6 +419,10 @@ null, gridletId, userId); return; } + + // check whether the Gridlet is running + boolean isRunning = sgl.getStatus() == Gridlet.INEXEC; + sgl.setStatus(Gridlet.CANCELED); //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- @@ -411,7 +432,7 @@ //---------------------------------------------------------------------- // remove/update entries of the gridlet in the profile - removeGridlet(sgl); + removeGridlet(isRunning, sgl); // compress the schedule, that is, moves the gridlets forwards if(!sgl.hasReserved()) @@ -425,7 +446,6 @@ //---------------------------------------------------------------------- // sends the Gridlet back to user - sgl.setStatus(Gridlet.CANCELED); sgl.finalizeGridlet(); super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, sgl.getGridlet(), gridletId, userId); @@ -511,7 +531,8 @@ // iterates the waiting queue and for each gridlet, put the ranges // used back in the profile. That is, updates the entries - Collections.sort(queuedGridlets_, orderStartTime_); + if(jobOrderHeuristic_ != null) + Collections.sort(queuedGridlets_, jobOrderHeuristic_); Iterator<SSGridlet> iterQueue = queuedGridlets_.iterator(); while(iterQueue.hasNext()) { @@ -1206,15 +1227,15 @@ /** * This method removes/updates all the entries of a gridlet from the profile * and updates the ranges of current free PEs if the gridlet was in execution. + * @param wasRunning <tt>true</tt> if the gridlet was running; + * <tt>false</tt> otherwise. * @param gridlet the Gridlet to be removed */ - private void removeGridlet(SSGridlet gridlet) { + private void removeGridlet(boolean wasRunning, SSGridlet gridlet) { if(!gridlet.hasReserved()) { - // check whether the Gridlet is running - boolean isRunning = gridlet.getStatus() == Gridlet.INEXEC; // removes the gridlet from the profile - updateEntriesAtProfile(isRunning, gridlet); + updateEntriesAtProfile(wasRunning, gridlet); } } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-31 00:27:24 UTC (rev 166) @@ -16,7 +16,6 @@ import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; @@ -74,9 +73,6 @@ // Pivot jobs (i.e. the first n jobs in the queue) protected LinkedList<SSGridlet> pivotGridlets_; - - // heuristic used to order the jobs for backfilling - protected Comparator<SSGridlet> jobOrderHeuristic_; // Similarly to the aggressive backfilling in MAUI, the user // can specify how many pivots can be considered when scheduling a job. @@ -110,7 +106,6 @@ super(resourceName, entityName); // initialises local variables pivotGridlets_ = new LinkedList<SSGridlet>(); - jobOrderHeuristic_ = null; maxPivots_ = 1; // default number of pivots is one } @@ -155,21 +150,6 @@ } /** - * Sets the heuristic used to order the jobs considered for backfilling - * @param comparator a comparator implementation that defines - * how gridlets are ordered. - * @return <tt>true</tt> if the heuristic was set correctly; - * <tt>false</tt> otherwise. - */ - public boolean setJobOrderingHeuristic(Comparator<SSGridlet> comparator) { - if(comparator == null) - return false; - - jobOrderHeuristic_ = comparator; - return true; - } - - /** * Sets the maximum number of pivot jobs. Similarly to the aggressive * backfilling in MAUI, the system administrator can specify how many * pivots can be considered when scheduling a job. That is, a job can @@ -240,17 +220,124 @@ } } - /** - * Cancels a Gridlet running or in the waiting queue.<br> - * <b>NOTE: Not implemented YET.</b> + /** + * Cancels a Gridlet running or in the waiting queue. + * This method will search the running and waiting queues. + * The User ID is important as many users might have the same + * Gridlet ID in the lists. If a Gridlet is cancelled and the gridlet was + * either running or was a pivot, then the availability profile is updated. + * After that, the backfilling algorithm is called to check which + * gridlets can be started or scheduled. + * <b>NOTE:</b> + * <ul> + * <li> Before cancelling a Gridlet, this method updates when + * the expected completion time of the Gridlet is. If the + * completion time is smaller than the current time, then + * the Gridlet is considered to be <tt>finished</tt>. + * Therefore the Gridlet cannot be cancelled. + * + * <li> Once a Gridlet has been cancelled, it cannot be resumed + * to execute again since this method will pass the Gridlet + * back to sender, i.e. the <tt>userId</tt>. + * + * <li> If a Gridlet cannot be found in either execution and + * waiting lists, then a <tt>null</tt> Gridlet will be send back + * to sender, i.e. the <tt>userId</tt>. + * </ul> * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet * @pre gridletId > 0 * @pre userId > 0 */ public void gridletCancel(int gridletId, int userId) { - System.out.println(super.get_name() + - ".gridletCancel(): not supported at the moment."); + double currentTime = GridSim.clock(); + + // stores the gridlet if found + SSGridlet sgl = null; + boolean found = false; + boolean updateProfile = false; + + // Look for the Gridlet in the running queue + sgl = findSSGridlet(runningGridlets_, gridletId, userId); + if (sgl != null) { + found = true; + + // if the Gridlet's finish time is smaller than the current + // time or the status is FINISHED, it means that the Gridlet + // has finished, but has not been removed from the running + // queue yet. It will probably be done shortly, + // so just send a null to the user. + if(sgl.getStatus() == Gridlet.SUCCESS || + sgl.getActualFinishTime() <= currentTime){ + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + null, gridletId, userId); + return; // return as it is impossible to cancel the Gridlet + } + else{ + // remove from the queue before compressing the schedule + runningGridlets_.remove(sgl); + updateProfile = true; + } + } + + if(!found) { + // Look for the gridlet in the waiting queue + sgl = findSSGridlet(queuedGridlets_, gridletId, userId); + if (sgl != null) { + found = true; + + // Get the Gridlet from the waiting queue and + // remove from the queue before compressing the schedule + queuedGridlets_.remove(sgl); + + // if start time has been set, then it means that gridlet is + // a pivot. So, we need to remove it from the pivot list + if(sgl.getStartTime() > 0) { + pivotGridlets_.remove(sgl); + updateProfile = true; + } + } + } + + // If the Gridlet could not be found in neither queue, then send a null + // Gridlet to the user and return because there is no need to + // compress the schedule + if(!found) { + System.out.println(super.get_name() + ".gridletCancel():" + + " Cannot find Gridlet #" + gridletId + " for User #" + userId); + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + null, gridletId, userId); + return; + } + + // check whether the Gridlet is running + boolean isRunning = sgl.getStatus() == Gridlet.INEXEC; + sgl.setStatus(Gridlet.CANCELED); + + //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- + + // If a gridlet has been cancelled, then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); + + //---------------------------------------------------------------------- + + // remove/update entries of the gridlet in the profile + if(updateProfile) { + removeGridlet(isRunning, sgl); + backfillGridlets(currentTime); + + //------------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- + + // Inform the listeners about the new schedule + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //---------------------------------------------------------------------- + } + + // sends the Gridlet back to user + sgl.finalizeGridlet(); + super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL, + sgl.getGridlet(), gridletId, userId); } /** @@ -393,8 +480,8 @@ // order jobs according to the ordering heuristic provided. // That is, if one was provided by the user. - if(jobOrderHeuristic_ != null) - Collections.sort(queuedGridlets_, jobOrderHeuristic_); + if(super.jobOrderHeuristic_ != null) + Collections.sort(queuedGridlets_, super.jobOrderHeuristic_); // Start the execution of Gridlets that are queued iter = queuedGridlets_.iterator(); @@ -427,4 +514,21 @@ return gridletStarted; } + + // ------------------------- PRIVATE METHODS ---------------------------- + + /** + * This method removes/updates all the entries of a gridlet from the profile + * and updates the ranges of current free PEs if the gridlet was in execution. + * @param wasRunning <tt>true</tt> if the gridlet was running; + * <tt>false</tt> otherwise. + * @param gridlet the Gridlet to be removed + */ + private void removeGridlet(boolean wasRunning, SSGridlet gridlet) { + if(!gridlet.hasReserved()) { + + // removes the gridlet from the profile + updateEntriesAtProfile(wasRunning, gridlet); + } + } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPProfileEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MPProfileEntry.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPProfileEntry.java 2008-03-31 00:27:24 UTC (rev 166) @@ -10,7 +10,7 @@ * @author Marcos Dias de Assuncao * @since GridSim Turbo Alpha 0.1 */ -public class MPProfileEntry { +public class MPProfileEntry implements Cloneable { // the ranges available private HashMap <Integer, PERangeList> ranges_; // the time when the ranges will be available Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERange.java 2008-03-31 00:27:24 UTC (rev 166) @@ -16,6 +16,7 @@ * @since GridSim Turbo Alpha 0.1 * @see PERangeList * @see CBParallelSpaceShared + * @see EBParallelSpaceShared */ public class PERange implements Cloneable, Comparable<PERange> { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-03-31 00:27:24 UTC (rev 166) @@ -22,6 +22,7 @@ * * @see PERange * @see CBParallelSpaceShared + * @see EBParallelSpaceShared * @see ARParallelSpaceShared */ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java 2008-03-31 00:27:24 UTC (rev 166) @@ -15,7 +15,7 @@ private QueuePartitionPredicate predicate_; /** - * Creates a new <tt>Queuepartition</tt> object. + * Creates a new <tt>QueuePartition</tt> object. * @param queueId the partition ID * @param numPE the number of PEs initially assigned to the partition * @param predicate the queue predicate Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-03-30 03:49:36 UTC (rev 165) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-03-31 00:27:24 UTC (rev 166) @@ -23,6 +23,7 @@ * @see SSGridlet * @see Reservation * @see CBParallelSpaceShared + * @see EBParallelSpaceShared * @see ARParallelSpaceShared */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |