From: <sul...@us...> - 2007-09-01 02:32:05
|
Revision: 52 http://gridsim.svn.sourceforge.net/gridsim/?rev=52&view=rev Author: sulistio Date: 2007-08-31 19:32:02 -0700 (Fri, 31 Aug 2007) Log Message: ----------- add resource failures functionality to this trunk or merging from branches/gridsim4.0-branch1 dir. Modified Paths: -------------- trunk/source/gridsim/ARPolicy.java trunk/source/gridsim/AllocPolicy.java trunk/source/gridsim/GridInformationService.java trunk/source/gridsim/GridResource.java trunk/source/gridsim/GridSim.java trunk/source/gridsim/GridSimCore.java trunk/source/gridsim/GridSimTags.java trunk/source/gridsim/Gridlet.java trunk/source/gridsim/Machine.java trunk/source/gridsim/MachineList.java trunk/source/gridsim/PE.java trunk/source/gridsim/PEList.java trunk/source/gridsim/ResourceCharacteristics.java trunk/source/gridsim/index/AbstractGIS.java Added Paths: ----------- trunk/source/gridsim/resFailure/ trunk/source/gridsim/resFailure/AllocPolicyWithFailure.java trunk/source/gridsim/resFailure/AvailabilityInfo.java trunk/source/gridsim/resFailure/FailureMsg.java trunk/source/gridsim/resFailure/GridResourceWithFailure.java trunk/source/gridsim/resFailure/RegionalGISWithFailure.java trunk/source/gridsim/resFailure/SpaceSharedWithFailure.java trunk/source/gridsim/resFailure/TimeSharedWithFailure.java trunk/source/gridsim/resFailure/package.html trunk/source/gridsim/util/HyperExponential.java trunk/source/gridsim/util/LCGRandom.java trunk/source/gridsim/util/Variate.java trunk/source/gridsim/util/Weibull.java Modified: trunk/source/gridsim/ARPolicy.java =================================================================== --- trunk/source/gridsim/ARPolicy.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/ARPolicy.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: ARPolicy.java,v 1.18 2005/10/21 12:29:09 anthony Exp $ + * $Id: ARPolicy.java,v 1.19 2007/08/10 01:50:34 anthony Exp $ */ package gridsim; @@ -486,9 +486,9 @@ } /** - * Gets the current time. Time calculates from simulation init time + - * (GridSim.clock * MILLI_SEC). MILLI_SEC = 1000. - * @return current time in seconds + * Gets the current time. Time is calculated from simulation init time + + * (GridSim.clock() * MILLI_SEC), where MILLI_SEC = 1000. + * @return current time in milliseconds * @pre $none * @post $result > 0 */ Modified: trunk/source/gridsim/AllocPolicy.java =================================================================== --- trunk/source/gridsim/AllocPolicy.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/AllocPolicy.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: AllocPolicy.java,v 1.44 2006/03/09 05:56:31 anthony Exp $ + * $Id: AllocPolicy.java,v 1.45 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -32,8 +32,7 @@ * Advanced Reservation functionalities need to extend from * {@link gridsim.ARPolicy} class instead. * - * @author Manzur Murshed and Rajkumar Buyya - * @author Anthony Sulistio (re-written this class) + * @author Anthony Sulistio * @since GridSim Toolkit 2.2 * @see gridsim.ARPolicy * @see gridsim.GridSim Modified: trunk/source/gridsim/GridInformationService.java =================================================================== --- trunk/source/gridsim/GridInformationService.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/GridInformationService.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: GridInformationService.java,v 1.31 2005/03/28 06:15:47 anthony Exp $ + * $Id: GridInformationService.java,v 1.32 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -69,6 +69,7 @@ * </ul> * * @author Manzur Murshed and Rajkumar Buyya + * @author Anthony Sulistio (re-design this class) * @since GridSim Toolkit 1.0 * @invariant $none * @see gridsim.GridSimTags Modified: trunk/source/gridsim/GridResource.java =================================================================== --- trunk/source/gridsim/GridResource.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/GridResource.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: GridResource.java,v 1.61 2006/03/09 05:56:31 anthony Exp $ + * $Id: GridResource.java,v 1.62 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -85,7 +85,7 @@ * connecting this entity to a router, etc. See the examples for more details. * * @author Manzur Murshed and Rajkumar Buyya - * @author Anthony Sulistio (re-written this class) + * @author Anthony Sulistio (re-design and re-written this class) * @since GridSim Toolkit 1.0 * @see gridsim.GridSimCore * @see gridsim.ResourceCharacteristics Modified: trunk/source/gridsim/GridSim.java =================================================================== --- trunk/source/gridsim/GridSim.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/GridSim.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: GridSim.java,v 1.65 2006/03/09 05:56:12 anthony Exp $ + * $Id: GridSim.java,v 1.67 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -56,6 +56,7 @@ * </ul> * * @author Manzur Murshed and Rajkumar Buyya + * @author Anthony Sulistio (re-design this class) * @since GridSim Toolkit 1.0 * @see eduni.simjava.Sim_entity * @see gridsim.GridSimCore @@ -502,7 +503,7 @@ /** * Sets a <tt>GridInformationService</tt> (GIS) entity. - * This method is useful is you write a different type of GIS entity. + * This method is useful when you want a different type of GIS entity. * This method must be called before {@link #startGridSimulation()} method. * @param gis a GIS object * @return <tt>true</tt> if successful, <tt>false</tt> otherwise @@ -512,7 +513,8 @@ */ public static boolean setGIS(GridInformationService gis) { - if (gis == null) { + // ignore if an existing GIS object has already been created + if (gis == null || gis_ != null) { return false; } Modified: trunk/source/gridsim/GridSimCore.java =================================================================== --- trunk/source/gridsim/GridSimCore.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/GridSimCore.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: GridSimCore.java,v 1.13 2006/03/09 05:56:31 anthony Exp $ + * $Id: GridSimCore.java,v 1.14 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -163,8 +163,7 @@ * </code> * </ul> * - * @author Manzur Murshed and Rajkumar Buyya - * @author Anthony Sulistio (re-written this class) + * @author Anthony Sulistio * @since GridSim Toolkit 3.0 * @see eduni.simjava.Sim_entity * @see gridsim.net.Output Modified: trunk/source/gridsim/GridSimTags.java =================================================================== --- trunk/source/gridsim/GridSimTags.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/GridSimTags.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: GridSimTags.java,v 1.46 2006/02/16 01:39:26 anthony Exp $ + * $Id: GridSimTags.java,v 1.49 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -17,6 +17,7 @@ * numbers, 0 - 299, and 9600. * * @author Manzur Murshed and Rajkumar Buyya + * @author Anthony Sulistio * @since GridSim Toolkit 1.0 * @invariant $none */ @@ -240,6 +241,48 @@ public static final int GRIDLET_MOVE_ACK = BASE + 30; + ///////////////////////////////////////////////////////////// + // NOTE: below are new tags needed for the resource failure functionality + // added by Agustin Caminero, Universidad de Castilla La Mancha (UCLM), + // Spain. Nov 2006. + + /** + * Denotes a request to get the total number of machines of a resource. + * This tag is normally used between GridSim and GridResource entity. + */ + public static final int RESOURCE_NUM_MACHINES = BASE + 31; + + /** + * This tag is used to simulate a resource failure. + * A RegionalGIS object sends an event to itself by using this tag, + * so it can send a failure message to resources in the future. + * This tag is also used when a failed resource receives a ping request. + * In this case, the resource will use this tag in the ping response. + */ + public static final int GRIDRESOURCE_FAILURE = BASE + 32; + + /** + * This tag is used to tell a resource, which is currently failed or down, + * to come back to life. + */ + public static final int GRIDRESOURCE_RECOVERY = BASE + 33; + + /** + * This tag is used by a user to poll a resource to find out whether + * it is out of order or not. + */ + public static final int GRIDRESOURCE_FAILURE_INFO = BASE + 34; + + /** This tag is used by a user to poll a resource. */ + public static final int GRIDRESOURCE_POLLING = BASE + 35; + + /** The polling interval for users. */ + public static final int POLLING_TIME_USER = BASE + 36; + + /** The polling interval for the GIS entities. */ + public static final int POLLING_TIME_GIS = BASE + 37; + + /////////////////////////////////////////////////////////////// // The below tags are sent by AdvanceReservation to ARGridResource class @@ -667,7 +710,7 @@ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_5_SECS = -12; /** - * New request of a reservation fails due to full in 10 seconds. + * New request of a reservation fails due to a resource full in 10 seconds. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ @@ -709,7 +752,7 @@ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_5_MINS = -18; /** - * New request of a reservation fails due to full in 10 hours. + * New request of a reservation fails due to a resource full in 10 minutes. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ @@ -737,42 +780,42 @@ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_45_MINS = -22; /** - * New request of a reservation fails due to full in 1 hour. + * New request of a reservation fails due to a resource full in 1 hour. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_1_HOUR = -23; /** - * New request of a reservation fails due to full in 5 hours. + * New request of a reservation fails due to a resource full in 5 hours. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_5_HOURS = -24; /** - * New request of a reservation fails due to full in 10 hours. + * New request of a reservation fails due to a resource full in 10 hours. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_10_HOURS = -25; /** - * New request of a reservation fails due to full in 15 hours. + * New request of a reservation fails due to a resource full in 15 hours. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_15_HOURS = -26; /** - * New request of a reservation fails due to full in 30 hours. + * New request of a reservation fails due to a resource full in 30 hours. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ public static final int AR_CREATE_FAIL_RESOURCE_FULL_IN_30_HOURS = -27; /** - * New request of a reservation fails due to full in 45 hours onwards. + * New request of a reservation fails due to a resource full in 45 hours onwards. * This tag is sent by a resource or allocation policy to * AdvanceReservation entity. */ Modified: trunk/source/gridsim/Gridlet.java =================================================================== --- trunk/source/gridsim/Gridlet.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/Gridlet.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: Gridlet.java,v 1.35 2005/09/20 07:04:34 anthony Exp $ + * $Id: Gridlet.java,v 1.37 2007/08/30 02:18:10 anthony Exp $ */ package gridsim; @@ -47,6 +47,7 @@ * {@link #Gridlet(int, double, long, long, boolean)} constructor instead. * * @author Manzur Murshed and Rajkumar Buyya + * @author Anthony Sulistio * @since GridSim Toolkit 1.0 * @invariant $none */ @@ -120,6 +121,10 @@ /** The Gridlet has been resumed from <tt>PAUSED</tt> state. */ public static final int RESUMED = 8; + /** The gridlet has failed due to a resource failure */ + public static final int FAILED_RESOURCE_UNAVAILABLE = 9; + + ///////////////////////////////////////////////////////////// /** @@ -879,7 +884,7 @@ } // throws an exception if the new status is outside the range - if (newStatus < Gridlet.CREATED || newStatus > Gridlet.RESUMED) + if (newStatus < Gridlet.CREATED || newStatus > Gridlet.FAILED_RESOURCE_UNAVAILABLE) { throw new Exception("Gridlet.setGridletStatus() : Error - " + "Invalid integer range for Gridlet status."); @@ -992,6 +997,10 @@ statusString = "Resumed"; break; + case Gridlet.FAILED_RESOURCE_UNAVAILABLE : + statusString = "Failed_resource_unavailable"; + break; + default: break; } Modified: trunk/source/gridsim/Machine.java =================================================================== --- trunk/source/gridsim/Machine.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/Machine.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: Machine.java,v 1.13 2004/11/01 02:52:36 anthony Exp $ + * $Id: Machine.java,v 1.14 2007/08/20 02:13:29 anthony Exp $ */ @@ -27,7 +27,10 @@ private PEList PEList_; private int id_; + // tells whether this machine is working properly or has failed. + private boolean failed_; + /** * Allocates a new Machine object * @param id the machine ID @@ -40,6 +43,7 @@ { this.id_ = id; this.PEList_ = list; + failed_ = false; } /** @@ -210,5 +214,45 @@ return totalInt + PEList_.getByteSize(); } + /** + * Sets the PEs of this machine to a FAILED status. + * NOTE: <tt>resName</tt> is used for debugging purposes, + * which is <b>ON</b> by default. + * Use {@link #setFailed(boolean)} if you do not want + * this information. + * + * @param resName the name of the resource + * @param fail true if this machine fails or false otherwise + * @return <tt>true</tt> if successful, <tt>false</tt> otherwise + */ + public boolean setFailed(String resName, boolean fail) + { + // all the PEs are failed (or recovered, depending on fail) + failed_ = fail; + PEList_.setStatusFailed(resName, id_, failed_); + return true; + } + + /** + * Sets the PEs of this machine to a FAILED status. + * @param fail true if this machine fails or false otherwise + * @return <tt>true</tt> if successful, <tt>false</tt> otherwise + */ + public boolean setFailed(boolean fail) + { + // all the PEs are failed (or recovered, depending on fail) + failed_ = fail; + PEList_.setStatusFailed(failed_); + return true; + } + + /** + * Checks whether this machine is failed or not. + * @return <tt>true</tt> if this machine is failed, <tt>false</tt> otherwise + */ + public boolean getFailed() { + return failed_; + } + } // end class Modified: trunk/source/gridsim/MachineList.java =================================================================== --- trunk/source/gridsim/MachineList.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/MachineList.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: MachineList.java,v 1.14 2004/11/01 02:52:36 anthony Exp $ + * $Id: MachineList.java,v 1.15 2007/08/20 02:13:29 anthony Exp $ */ package gridsim; @@ -171,11 +171,22 @@ while ( it.hasNext() ) { obj = (Machine) it.next(); - PEList myPElist = obj.getPEList(); - if (myPElist.getNumFreePE() >= numPE) { - return obj; // a machine with Free ID is found. + // If the machine is failed, do nothing. Otherwise... + if (obj.getFailed() == false) + { + PEList myPElist = obj.getPEList(); + if (myPElist.getNumFreePE() >= numPE) { + return obj; // a machine with Free ID is found. + } } + /************** + // Uncomment this if you want more info on the progress of sims + else + { + System.out.println("MachineList.getMachineWithFreePE(). MachineID: " + + obj.getMachineID() + ". Machine is failed. Try other machine."); + }*/ } return null; // none of the machines have free PE. @@ -234,5 +245,25 @@ return bSize; } + /** + * Gets the machine in a given position in the list. + * @param index a position index in the list + * @return the Machine object + */ + public Machine getMachineInPos(int index) + { + Machine obj = null; + Iterator it = super.iterator(); + int count = 0; + while ( (it.hasNext()) && (count <= index) ) + { + count++; + obj = (Machine) it.next(); + } + + return obj; + + } + } // end class Modified: trunk/source/gridsim/PE.java =================================================================== --- trunk/source/gridsim/PE.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/PE.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: PE.java,v 1.14 2005/03/28 07:10:14 anthony Exp $ + * $Id: PE.java,v 1.15 2007/08/30 01:20:19 anthony Exp $ */ package gridsim; @@ -26,13 +26,22 @@ // FOR SPACE SHARED RESOURCE: Jan 21 private boolean status_; // Status of PE: FREE or BUSY + // TODO: this is obviously clash BUSY with FAILED !!! So, change from the status + // of boolean to integer !! + /** Denotes PE is FREE for allocation */ public static final boolean FREE = true; /** Denotes PE is allocated and hence busy in processing Gridlet */ public static final boolean BUSY = false; + /** Denotes PE is failed and hence it can't process any Gridlet at this moment. + * This PE is failed because it belongs to a machine which is also failed. + */ + public static final boolean FAILED = false; + + /** * Allocates a new PE object * @param id the PE ID @@ -211,5 +220,14 @@ return totalInt; } + /** + * Sets this PE to FAILED. + * @pre $none + * @post $none + */ + public void setStatusFailed() { + status_ = FAILED; + } + } // end class Modified: trunk/source/gridsim/PEList.java =================================================================== --- trunk/source/gridsim/PEList.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/PEList.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: PEList.java,v 1.13 2004/11/01 02:52:36 anthony Exp $ + * $Id: PEList.java,v 1.14 2007/08/20 02:13:52 anthony Exp $ */ package gridsim; @@ -182,5 +182,47 @@ return super.size() * PE.getByteSize(); } + /** + * Sets the status of PEs of this machine to FAILED. + * NOTE: <tt>resName</tt> and <tt>machineID</tt> are used for debugging + * purposes, which is <b>ON</b> by default. + * Use {@link #setStatusFailed(boolean)} if you do not want + * this information. + * + * @param resName the name of the resource + * @param machineID the id of this machine + * @param fail the new value for the "failed" parameter + */ + public void setStatusFailed(String resName, int machineID, boolean fail) + { + String status = null; + if (fail == true) + status = "FAILED"; + else + status = "WORKING"; + + System.out.println(resName + " - Machine: " + machineID + + " is " + status); + + this.setStatusFailed(fail); + } + + /** + * Sets the status of PEs of this machine to FAILED. + * @param fail the new value for the "failed" parameter + */ + public void setStatusFailed(boolean fail) + { + // a loop to set the status of all the PEs in this machine + Iterator it = super.iterator(); + while ( it.hasNext() ) + { + PE obj = (PE) it.next(); + if (fail == true) + obj.setStatus(PE.FAILED); + else + obj.setStatus(PE.FREE); + } + } + } // end class - Modified: trunk/source/gridsim/ResourceCharacteristics.java =================================================================== --- trunk/source/gridsim/ResourceCharacteristics.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/ResourceCharacteristics.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: ResourceCharacteristics.java,v 1.22 2004/11/01 02:52:37 anthony Exp $ + * $Id: ResourceCharacteristics.java,v 1.23 2007/08/20 02:14:24 anthony Exp $ */ package gridsim; @@ -599,5 +599,47 @@ return totalSize; } + /** + * Gets the total number of machines. + * @return total number of machines this resource has. + */ + public int getNumMachines() { + return machineList_.size(); + } + + /** + * Gets the current number of failed machines. + * @return current number of failed machines this resource has. + */ + public int getNumFailedMachines() + { + int numFailedMachines = 0; + int numMach = machineList_.size(); + Machine mach; + + for (int i = 0; i < numMach; i++) + { + mach = machineList_.getMachineInPos(i); + if (mach.getFailed() == true) + numFailedMachines++; + } + + return numFailedMachines; + } + + /** + * Checks whether all machines of this resource are working properly or not. + * @return <tt>true</tt> if all machines are working, + * <tt>false</tt> otherwise + */ + public boolean isWorking() + { + boolean result = false; + if (this.getNumFailedMachines() == 0) + result = true; + + return result; + } + } // end class Modified: trunk/source/gridsim/index/AbstractGIS.java =================================================================== --- trunk/source/gridsim/index/AbstractGIS.java 2007-09-01 02:27:16 UTC (rev 51) +++ trunk/source/gridsim/index/AbstractGIS.java 2007-09-01 02:32:02 UTC (rev 52) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: AbstractGIS.java,v 1.6 2005/10/21 10:22:39 anthony Exp $ + * $Id: AbstractGIS.java,v 1.8 2007/08/30 01:38:43 anthony Exp $ */ package gridsim.index; @@ -26,8 +26,6 @@ */ public abstract class AbstractGIS extends GridSimCore { - private final int NUM_FORM = 2; // size of registration array - /** System GIS or {@link gridsim.GridInformationService} entity ID. */ protected int systemGIS_ = -1; @@ -93,20 +91,25 @@ * This tag should be called from a Regional GIS to a sender Regional GIS. */ public static final int GIS_INQUIRY_RESOURCE_RESULT = GIS_BASE + 10; - + /** Denotes an inquiry regarding to a list of local resources, * which supports advanced reservation. * This tag should be called from a Regional GIS to another. */ public static final int GIS_INQUIRY_RESOURCE_AR_LIST = GIS_BASE + 11; - + /** Denotes a result regarding to a list of local resources, * which supports advanced reservation. * This tag should be called from a Regional GIS to a sender Regional GIS. */ public static final int GIS_INQUIRY_RESOURCE_AR_RESULT = GIS_BASE + 12; + /** Denotes an inquiry regarding to a resource failure. + * The user sends this tag to the GIS to update its list of resources. + */ + public static final int NOTIFY_GIS_RESOURCE_FAILURE = GIS_BASE + 13; + /** * Creates a new regional GIS entity * @param name this regional GIS name Added: trunk/source/gridsim/resFailure/AllocPolicyWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/AllocPolicyWithFailure.java (rev 0) +++ trunk/source/gridsim/resFailure/AllocPolicyWithFailure.java 2007-09-01 02:32:02 UTC (rev 52) @@ -0,0 +1,37 @@ +/* + * 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 + * + * Author: Agustin Caminero + * Organization: Universidad de Castilla La Mancha (UCLM), Spain. + * Created on: Nov 2006. + */ + +package gridsim.resFailure; + +/** + * The structure of an allocation policy supporting resource failure. + * Use this class in addition to {@link gridsim.AllocPolicy} class. + * @author Agustin Caminero + * @since GridSim Toolkit 4.1 + * @see gridsim.AllocPolicy + */ + +public interface AllocPolicyWithFailure +{ + /** + * Sets the status of all Gridlets in this resource to <tt>FAILED</tt>. + * Then sends them back to users, and clean up the relevant lists. + */ + public abstract void setGridletsFailed(); + + /** + * Sets the status of all Gridlets in this machine to <tt>FAILED</tt>. + * Then sends them back to users, and clean up the relevant lists. + * @param failedMachID the id of the failed machine + */ + public abstract void setGridletsFailed(int failedMachID); + +} // end class Added: trunk/source/gridsim/resFailure/AvailabilityInfo.java =================================================================== --- trunk/source/gridsim/resFailure/AvailabilityInfo.java (rev 0) +++ trunk/source/gridsim/resFailure/AvailabilityInfo.java 2007-09-01 02:32:02 UTC (rev 52) @@ -0,0 +1,89 @@ +/* + * 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 + * + * Author: Agustin Caminero + * Organization: Universidad de Castilla La Mancha (UCLM), Spain. + * Created on: Nov 2006. + */ + + +package gridsim.resFailure; + +/** + * This class is used by GridSim users to check whether a particular resource + * is working or is totally failed. + * + * @author Agustin Caminero + * @since GridSim Toolkit 4.1 + */ + +public class AvailabilityInfo +{ + private int resID; + private int srcID; + private boolean availability; + + /** + * Creates a new object of this class + * @param res a resource id + * @param src the sender id + */ + public AvailabilityInfo(int res, int src) + { + resID = res; + srcID = src; + availability = true; // by default, true + } + + /** + * Gets the source or sender id + * @return sender id + */ + public int getSrcID() { + return srcID; + } + + /** + * Gets the resource id + * @return resource id + */ + public int getResID() { + return resID; + } + + /** + * Checks the availability of this resource + * @return <tt>true</tt> if available, <tt>false</tt> otherwise + */ + public boolean getAvailability() { + return availability; + } + + /** + * Sets the source or sender id + * @param src the sender id + */ + public void setSrcID(int src) { + srcID = src; + } + + /** + * Sets the resource id + * @param res a resource id + */ + public void setResID(int res) { + resID = res; + } + + /** + * Sets the resource availability + * @param av <tt>true</tt> if available, <tt>false</tt> otherwise + */ + public void setAvailability(boolean av) { + availability = av; + } + +} // end class Added: trunk/source/gridsim/resFailure/FailureMsg.java =================================================================== --- trunk/source/gridsim/resFailure/FailureMsg.java (rev 0) +++ trunk/source/gridsim/resFailure/FailureMsg.java 2007-09-01 02:32:02 UTC (rev 52) @@ -0,0 +1,103 @@ +/* + * 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 + * + * Author: Agustin Caminero + * Organization: Universidad de Castilla La Mancha (UCLM), Spain. + * Created on: Nov 2006. + */ + + +package gridsim.resFailure; + +/** + * This class is used by + * {@link gridsim.resFailure.RegionalGISWithFailure} to commnunicate with + * {@link gridsim.resFailure.GridResourceWithFailure} + * for simulating a resource failure. + * + * @author Agustin Caminero + * @since GridSim Toolkit 4.1 + */ + +public class FailureMsg +{ + /** The time that the failure will last */ + private double time; + + /** The id of the resource */ + private int res_id; + + /** The number of machines that will fail in this resource */ + private int numMachines; + + + /** + * Creates a new failure message + * @param time the time that the failure will last + * @param rid the resource id + */ + public FailureMsg(double time, int rid) { + this.time = time; + res_id = rid; + numMachines = 0; + } + + /** + * This method sets the time atribute of the ResourceFailure object + * @param time the time that the failure will last + */ + public void setTime(double time) + { + this.time = time; + } + + /** + * This method returns the time atribute of the ResourceFailure object + * @return time + */ + public double getTime() + { + return time; + } + + /** + * This method sets the res_id atribute of the ResourceFailure object + * @param r the resource id of the resource + */ + public void setRes(int r) + { + res_id = r; + } + + /** + * This method returns the res_id atribute of the ResourceFailure object + * @return the resource id + */ + public int getRes() + { + return res_id; + } + + /** + * This method sets the numMachines atribute of the ResourceFailure object + * @param n the number of machines which will fail in this resource + */ + public void setNumMachines(int n) + { + numMachines = n; + } + + /** + * This method returns the number of machines which will fail + * in this resource + * @return number of failed machines + */ + public double getNumMachines() + { + return numMachines; + } + +} // end class Added: trunk/source/gridsim/resFailure/GridResourceWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/GridResourceWithFailure.java (rev 0) +++ trunk/source/gridsim/resFailure/GridResourceWithFailure.java 2007-09-01 02:32:02 UTC (rev 52) @@ -0,0 +1,1386 @@ +/* + * 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 + * + * Author: Agustin Caminero and Anthony Sulistio + * Organization: Universidad de Castilla La Mancha (UCLM), Spain. + * Created on: Nov 2006. + */ + +package gridsim.resFailure; + +import gridsim.resFailure.*; +import gridsim.*; +import gridsim.net.*; +import gridsim.index.*; +import java.util.LinkedList; +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; +import gridsim.resFailure.FailureMsg; +import java.io.FileWriter; + + +/** + * GridResourceWithFailure is based on {@link gridsim.GridResource}, but with + * added failure functionalities. + * GridResourceWithFailure extends the {@link gridsim.GridSimCore} class for + * gaining communication and concurrent entity capabilities. + * An instance of this class stimulates a resource + * with properties defined in an object of + * {@link gridsim.ResourceCharacteristics} class. + * + * @author Agustin Caminero and Anthony Sulistio + * @since GridSim Toolkit 4.1 + * @see gridsim.GridResource + * @see gridsim.ResourceCharacteristics + * @see gridsim.resFailure.AllocPolicyWithFailure + * @invariant $none + */ +public class GridResourceWithFailure extends GridSimCore +{ + /** Characteristics of this resource */ + protected ResourceCharacteristics resource_; + + /** a ResourceCalendar object */ + protected ResourceCalendar resCalendar_; + + /** A resource's scheduler. This object is reponsible in scheduling and + * and executing submitted Gridlets. + */ + protected AllocPolicy policy_; + + /** A scheduler type of this resource, such as FCFS, Round Robin, etc */ + protected int policyType_; + + /** Integer object size, including its overhead */ + protected final int SIZE = 12; + + /** Regional GIS entity name */ + protected String regionalGISName_; + + // a flag to denote whether to record events into a file or not + private boolean record_ = false; + + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use + * {@link #GridResourceWithFailure(String, double, ResourceCharacteristics, + * ResourceCalendar, AllocPolicyWithFailure)} + * and then overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param baud_rate network communication or bandwidth speed + * @param seed the initial seed + * @param resource an object of ResourceCharacteristics + * @param peakLoad the load during peak times + * @param offPeakLoad the load during off peak times + * @param relativeHolidayLoad the load during holiday times + * @param weekends a linked-list contains the weekend days + * @param holidays a linked-list contains the public holidays + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @see gridsim.GridSim#init(int, Calendar, boolean) + * @see #GridResourceWithFailure(String, double, + * ResourceCharacteristics, ResourceCalendar, AllocPolicyWithFailure) + * @pre name != null + * @pre baud_rate > 0 + * @pre resource != null + * @post $none + */ + public GridResourceWithFailure(String name, double baud_rate, long seed, + ResourceCharacteristics resource, double peakLoad, + double offPeakLoad, double relativeHolidayLoad, + LinkedList weekends, LinkedList holidays) throws Exception + { + super(name, baud_rate); + resource_ = resource; + + resCalendar_ = new ResourceCalendar(resource_.getResourceTimeZone(), + peakLoad, offPeakLoad, relativeHolidayLoad, weekends, + holidays, seed); + + policy_ = null; + + init(); + } + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use + * {@link #GridResourceWithFailure(String, double, ResourceCharacteristics, + * ResourceCalendar, AllocPolicyWithFailure)} + * and then overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param baud_rate network communication or bandwidth speed + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @see gridsim.GridSim#init(int, Calendar, boolean) + * @see #GridResourceWithFailure(String, double, + * ResourceCharacteristics, ResourceCalendar, AllocPolicyWithFailure) + * @pre name != null + * @pre baud_rate > 0 + * @pre resource != null + * @pre calendar != null + * @post $none + */ + public GridResourceWithFailure(String name, double baud_rate, + ResourceCharacteristics resource, ResourceCalendar calendar) + throws Exception + { + super(name, baud_rate); + resource_ = resource; + + resCalendar_ = calendar; + policy_ = null; + init(); + } + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use this constructor and then + * overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param baud_rate network communication or bandwidth speed + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @param policy a scheduling policy for this Grid resource. If no + * scheduling policy is defined, the default one is + * <tt>SpaceShared</tt> + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @see gridsim.GridSim#init(int, Calendar, boolean) + * @see gridsim.resFailure.AllocPolicyWithFailure + * @pre name != null + * @pre baud_rate > 0 + * @pre resource != null + * @pre calendar != null + * @pre policy != null + * @post $none + */ + public GridResourceWithFailure(String name, double baud_rate, + ResourceCharacteristics resource, ResourceCalendar calendar, + AllocPolicyWithFailure policy) throws Exception + { + super(name, baud_rate); + resource_ = resource; + resCalendar_ = calendar; + + // the order between policy and init() is important + policy_ = (AllocPolicy) policy; + init(); + } + + //////////////////////////////////////////// + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use + * {@link #GridResourceWithFailure(String, Link, ResourceCharacteristics, + * ResourceCalendar, AllocPolicyWithFailure)} + * and then overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param link the link that will be used to connect this + * GridResourceWithFailure to another Entity or Router. + * @param seed the initial seed + * @param resource an object of ResourceCharacteristics + * @param peakLoad the load during peak times + * @param offPeakLoad the load during off peak times + * @param relativeHolidayLoad the load during holiday times + * @param weekends a linked-list contains the weekend days + * @param holidays a linked-list contains the public holidays + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @pre name != null + * @pre link != null + * @pre resource != null + * @post $none + */ + public GridResourceWithFailure(String name, Link link, long seed, + ResourceCharacteristics resource, double peakLoad, + double offPeakLoad, double relativeHolidayLoad, + LinkedList weekends, LinkedList holidays) throws Exception + { + super(name, link); + resource_ = resource; + + resCalendar_ = new ResourceCalendar(resource_.getResourceTimeZone(), + peakLoad, offPeakLoad, relativeHolidayLoad, weekends, + holidays, seed); + + policy_ = null; + init(); + } + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use + * {@link #GridResourceWithFailure(String, Link, ResourceCharacteristics, + * ResourceCalendar, AllocPolicyWithFailure)} + * and then overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param link the link that will be used to connect this + * GridResourceWithFailure to another Entity or Router. + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @pre name != null + * @pre link != null + * @pre resource != null + * @pre calendar != null + * @post $none + */ + public GridResourceWithFailure(String name, Link link, + ResourceCharacteristics resource, ResourceCalendar calendar) + throws Exception + { + super(name, link); + resource_ = resource; + + resCalendar_ = calendar; + policy_ = null; + init(); + } + + /** + * Allocates a new GridResourceWithFailure object. When making a different + * type of GridResourceWithFailure object, use this constructor and then + * overrides {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param link the link that will be used to connect this + * GridResourceWithFailure to another Entity or Router. + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @param policy a scheduling policy for this Grid resource. If no + * scheduling policy is defined, the default one is + * <tt>SpaceShared</tt> + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResourceWithFailure must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @see gridsim.resFailure.AllocPolicyWithFailure + * @pre name != null + * @pre link != null + * @pre resource != null + * @pre calendar != null + * @pre policy != null + * @post $none + */ + public GridResourceWithFailure(String name, Link link, + ResourceCharacteristics resource, ResourceCalendar calendar, + AllocPolicyWithFailure policy) throws Exception + { + super(name,link); + resource_ = resource; + resCalendar_ = calendar; + + // the order between policy and init() is important + policy_ = (AllocPolicy) policy; + init(); + } + + ///////////////////////////////////////////////// + + /** + * Sets a regional GridInformationService (GIS) entity for this resource + * to communicate with. This resource will then register its ID to the + * regional GIS entity, rather than {@link GridInformationService} or + * <tt>system GIS</tt>. + * @param regionalGIS name of regional GIS entity + * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise + * @pre regionalGIS != null + * @post $none + */ + public boolean setRegionalGIS(String regionalGIS) + { + if (regionalGIS == null || GridSim.getEntityId(regionalGIS) == -1) { + return false; + } + + regionalGISName_ = regionalGIS; + return true; + } + + /** + * Sets a regional GridInformationService (GIS) entity for this resource + * to communicate with. This resource will then register its ID to the + * regional GIS entity, rather than {@link GridInformationService} or + * <tt>system GIS</tt>. + * @param gis regional GIS entity object + * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise + * @pre gis != null + * @post $none + */ + public boolean setRegionalGIS(AbstractGIS gis) + { + if (gis == null) { + return false; + } + + return setRegionalGIS( gis.get_name() ); + } + + /** + * Asks this resource to record its activities. <br> + * NOTE: this method should be called <b>BEFORE</b> the simulation starts. + * If an existing file exists, the new activities will be appended at the + * end. The file name is this entity name. + * + * @param trace <tt>true</tt> if you want to record this resource's + * activities, <tt>false</tt> otherwise + */ + public void setTrace(boolean trace) { + record_ = trace; + initializeReportFile(); + } + + /** + * Handles external events that are coming to this GridResourceWithFailure + * entity. This method also registers the identity of this + * GridResourceWithFailure entity to <tt>GridInformationService</tt> class. + * <p> + * The services or tags available for this resource are: + * <ul> + * <li> {@link gridsim.GridSimTags#RESOURCE_CHARACTERISTICS} </li> + * <li> {@link gridsim.GridSimTags#RESOURCE_DYNAMICS} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_SUBMIT} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_CANCEL} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_PAUSE} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_RESUME} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_MOVE} </li> + * <li> {@link gridsim.GridSimTags#GRIDLET_STATUS} </li> + * </ul> + * <br> + * This method also calls these methods in the following order: + * <ol> + * <li> {@link #registerOtherEntity()} method + * <li> {@link #processOtherEvent(Sim_event)} method + * </ol> + * + * @pre $none + * @post $none + */ + public void body() + { + // send the registration to GIS + int register = 0; + if (policyType_ == ResourceCharacteristics.ADVANCE_RESERVATION) { + register = GridSimTags.REGISTER_RESOURCE_AR; + } + else { + register = GridSimTags.REGISTER_RESOURCE; + } + + // this resource should register to regional GIS. + // However, if not specified, then register to system GIS (the + // default GridInformationService) entity. + int gisID = GridSim.getEntityId(regionalGISName_); + if (gisID == -1) { + gisID = GridSim.getGridInfoServiceEntityId(); + } + // need to wait for few seconds before registering to a regional GIS. + // This is because to allow all routers to fill in their routing tables + else + { + super.sim_pause(GridSim.PAUSE); + System.out.println(super.get_name() + ".body(): wait for " + + GridSim.PAUSE + " seconds before registering to " + + regionalGISName_); + } + + // send the registration to GIS + super.send(super.output, GridSimTags.SCHEDULE_NOW, register, + new IO_data(new Integer(super.get_id()), SIZE, gisID) ); + + // Below method is for a child class to override + registerOtherEntity(); + + // Process events until END_OF_SIMULATION is received from the + // GridSimShutdown Entity + Sim_event ev = new Sim_event(); + while ( Sim_system.running() ) + { + super.sim_get_next(ev); + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) + { + System.out.println(get_name()+ ": end of simulation..."); + policy_.setEndSimulation(); + break; + } + + // process the received event + processEvent(ev); + } + + // remove I/O entities created during construction of this entity + super.terminateIOEntities(); + } + + + //////////////////// PROTECTED METHODS /////////////////////////////////// + + /** + * Overrides this method when making a new and different type of resource. + * This method is called by {@link #body()} for incoming unknown tags. + * <p> + * Another approach is to override the + * {@link gridsim.AllocPolicy#processOtherEvent(Sim_event)} method. + * This approach is desirable if you do not want to create a new type of + * grid resource. + * + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + protected void processOtherEvent(Sim_event ev) + { + if (ev == null) + { + System.out.println(super.get_name() + ".processOtherEvent(): " + + "Error - an event is null."); + return; + } + + /**** // NOTE: now a resource passes a new event to the scheduler + System.out.println(super.get_name()+".processOtherEvent(): Unable to " + + "handle request from GridSimTags with tag number " + + ev.get_tag() ); + *****/ + + policy_.processOtherEvent(ev); + } + + /** + * Overrides this method when making a new and different type of resource. + * This method is called by {@link #body()} to register other type to + * {@link gridsim.GridInformationService} entity. In doing so, you + * need to create a new child class extending from + * {@link gridsim.GridInformationService}. + * <br> + * <b>NOTE:</b> You do not need to override {@link #body()} method, if + * you use this method. + * + * @pre $none + * @post $none + * @see gridsim.GridInformationService + */ + protected void registerOtherEntity() { + // empty. This should be override by a child class + } + + //////////////////// PRIVATE METHODS /////////////////////////////////// + + /** + * Initializes the resource allocation policy + * @throws Exception If number of PEs is zero + * @pre $none + * @post $none + */ + private void init() throws Exception + { + // If this resource doesn't have any PEs then no useful at all + if (resource_.getNumPE() == 0) + { + throw new Exception(super.get_name() + " : Error - this entity " + + "has no PEs. Therefore, can't process any Gridlets."); + } + + // stores id of this class + resource_.setResourceID( super.get_id() ); + + // if internal allocation policy is used + policyType_ = resource_.getResourceAllocationPolicy(); + if (policy_ == null) + { + switch (policyType_) + { + case ResourceCharacteristics.TIME_SHARED: + policy_ = new TimeSharedWithFailure(super.get_name(), "TimeShared"); + break; + + case ResourceCharacteristics.SPACE_SHARED: + policy_ = new SpaceSharedWithFailure(super.get_name(), "SpaceShared"); + break; + + default: + throw new Exception(super.get_name()+" : Error - supports"+ + " only TimeShared or SpaceShared policy."); + } + } + + policy_.init(resource_, resCalendar_, super.output); + record_ = false; + } + + /** + * Processes events or services that are available for this + * GridResourceWithFailure + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + private void processEvent(Sim_event ev) + { + int src_id = -1; + + // GRIDRESOURCE_RECOVERY and GRIDRESOURCE_FAILURE_INFO (polling request) + // are ALWAYS processed. + if (ev.get_tag() == GridSimTags.GRIDRESOURCE_RECOVERY) + { + processRecovery(ev); + } + else if (ev.get_tag() == GridSimTags.GRIDRESOURCE_FAILURE_INFO) + { + processPolling(ev); + } + + // Only if the resource is not failed, then process other events + if (getResourceFailed() == false) + { + switch (ev.get_tag()) + { + + // Resource characteristics inquiry + case GridSimTags.RESOURCE_CHARACTERISTICS: + src_id = ((Integer) ev.get_data()).intValue(); + super.send(super.output, 0.0, ev.get_tag(), + new IO_data(resource_, resource_.getByteSize(), src_id)); + + break; + + // Resource dynamic info inquiry + case GridSimTags.RESOURCE_DYNAMICS: + src_id = ((Integer) ev.get_data()).intValue(); + super.send(super.output, 0.0, ev.get_tag(), + new IO_data(policy_.getTotalLoad(), + Accumulator.getByteSize(), src_id)); + break; + + case GridSimTags.RESOURCE_NUM_PE: + src_id = ((Integer) ev.get_data()).intValue(); + int numPE = resource_.getNumPE(); + super.send(super.output, 0.0, ev.get_tag(), + new IO_data(new Integer(numPE), SIZE, src_id)); + break; + + case GridSimTags.RESOURCE_NUM_FREE_PE: + src_id = ((Integer) ev.get_data()).intValue(); + ... [truncated message content] |